Skip to content

Commit

Permalink
use arrow in ability with <- symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
DieMyst committed Oct 18, 2023
1 parent 9b65c1e commit 4a037ee
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
6 changes: 3 additions & 3 deletions aqua-src/antithesis.aqua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func create() -> TestAb:
<- 42, 76
<- TestAb(inner = InnerAb(arrow = arrow))

func test() -> i8:
func test() -> i8, i8:
ababab <- create()
res <- ababab.inner.arrow()
<- res
res1, res2 <- ababab.inner.arrow()
<- res1, res2
6 changes: 4 additions & 2 deletions integration-tests/aqua/examples/abilities.aqua
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ ability CCCC:
arrow(x: i8) -> bool
simple: SSS

func checkAbCalls() -> bool, bool:
func checkAbCalls() -> bool, bool, bool:
closure = (x: i8) -> bool:
<- x > 20

MySSS = SSS(arrow = closure)
MyCCCC = CCCC(simple = MySSS, arrow = MySSS.arrow)
res1 <- MySSS.arrow(42)
res2 = MyCCCC.arrow(12)

<- MySSS.arrow(42), MyCCCC.arrow(12)
<- res1, res2, MySSS.arrow(50)
2 changes: 1 addition & 1 deletion integration-tests/src/__test__/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ describe("Testing examples", () => {

it("ability.aqua ability calls", async () => {
let result = await checkAbCallsCall();
expect(result).toStrictEqual([true, false]);
expect(result).toStrictEqual([true, false, true]);
});

it("functors.aqua LNG-119 bug", async () => {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/examples/abilityCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export async function complexAbilityCall(): Promise<[boolean, boolean]> {
return await bug214();
}

export async function checkAbCallsCall(): Promise<[boolean, boolean]> {
export async function checkAbCallsCall(): Promise<[boolean, boolean, boolean]> {
return await checkAbCalls();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package aqua.model.inline.raw

import aqua.errors.Errors.internalError
import aqua.model.*
import aqua.model.inline.RawValueInliner.{callToModel, valueToModel}
import aqua.model.inline.RawValueInliner.callToModel
import aqua.model.inline.state.{Arrows, Exports, Mangler}
import aqua.model.inline.{ArrowInliner, Inline, TagInliner}
import aqua.model.inline.{ArrowInliner, Inline, RawValueInliner}
import aqua.raw.ops.Call
import aqua.raw.value.CallArrowRaw

import aqua.types.AbilityType
import cats.data.{Chain, State}
import cats.syntax.traverse.*
import scribe.Logging
Expand All @@ -28,7 +28,16 @@ object CallArrowRawInliner extends RawInliner[CallArrowRaw] with Logging {
val funcName = value.ability.fold(value.name)(_ + "." + value.name)
logger.trace(s" $funcName")

resolveArrow(funcName, call)
value.abValue.map { v =>
// inline var to get the left side of the ability call's name
RawValueInliner.unfold(v, false).flatMap {
case (VarModel(name, _, _), _) =>
resolveArrow(AbilityType.fullName(name, funcName), call)
case l =>
internalError(s"Ability cannot be a literal ($l)")
}
}.getOrElse(resolveArrow(funcName, call))

}

private def resolveFuncArrow[S: Mangler: Exports: Arrows](
Expand Down
4 changes: 3 additions & 1 deletion model/raw/src/main/scala/aqua/raw/value/ValueRaw.scala
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ case class CallArrowRaw(
ability: Option[String],
name: String,
arguments: List[ValueRaw],
baseType: ArrowType
baseType: ArrowType,
// left part of an ability (what calls arrow)
abValue: Option[ValueRaw] = None
) extends ValueRaw {
override def `type`: Type = baseType.codomain.headOption.getOrElse(baseType)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ class ValuesAlgebra[S[_], Alg[_]: Monad](using
valueToRaw(v).flatMap(
_.flatTraverse {
case ca: CallArrowRaw => ca.some.pure[Alg]
case ApplyPropertyRaw(value, IntoArrowRaw(name, arrowType, arguments)) =>
// IntoArrow can be only last in a properties chain
// Store left part of the value and properties into CallArrowRaw to inline it later
CallArrowRaw(None, name, arguments, arrowType, Some(value)).some.pure[Alg]
// TODO: better error message (`raw` formatting)
case raw => report.error(v, s"Expected arrow call, got $raw").as(none)
}
Expand Down

0 comments on commit 4a037ee

Please sign in to comment.