Skip to content

Commit

Permalink
fix(compiler): Passing closures with abilities [LNG-314] (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
DieMyst authored Jan 9, 2024
1 parent d5cd77b commit 5241f52
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sbt-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
apps: sbt

- name: Run tests
run: sbt test
run: env JAVA_OPTS="-Xmx4G" sbt test
26 changes: 23 additions & 3 deletions aqua-src/antithesis.aqua
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
func arr() -> string:
n = "str"
<- n
aqua M

export bugLng314

ability WorkerJob:
runOnSingleWorker(w: string) -> string

func disjoint_run{WorkerJob}() -> -> string:
run = func () -> string:
r <- WorkerJob.runOnSingleWorker()
<- r
<- run

func runJob(j: -> string) -> string:
<- j()

func bugLng314() -> string:
job2 = () -> string:
<- "strstrstr"
worker_job = WorkerJob(runOnSingleWorker = job2)
subnet_job <- disjoint_run{worker_job}()
res <- runJob(subnet_job)
<- res
23 changes: 23 additions & 0 deletions integration-tests/aqua/examples/abilitiesClosure.aqua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
aqua M

export bugLNG314

ability WorkerJob:
runOnSingleWorker(w: string) -> string

func disjoint_run{WorkerJob}() -> -> string:
run = func () -> string:
r <- WorkerJob.runOnSingleWorker()
<- r
<- run

func runJob(j: -> string) -> string:
<- j()

func bugLNG314() -> string:
job2 = () -> string:
<- "strstrstr"
worker_job = WorkerJob(runOnSingleWorker = job2)
subnet_job <- disjoint_run{worker_job}()
res <- runJob(subnet_job)
<- res
8 changes: 8 additions & 0 deletions integration-tests/src/__test__/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import {
multipleAbilityWithClosureCall,
returnSrvAsAbilityCall,
} from "../examples/abilityCall.js";
import {
bugLNG314Call,
} from "../examples/abilityClosureCall.js";
import {
nilLengthCall,
nilLiteralCall,
Expand Down Expand Up @@ -666,6 +669,11 @@ describe("Testing examples", () => {
expect(result).toStrictEqual(["default-id", "resolved-id"]);
});

it("abilitiesClosure.aqua bug LNG-314", async () => {
let result = await bugLNG314Call();
expect(result).toEqual("strstrstr");
});

it("functors.aqua LNG-119 bug", async () => {
let result = await bugLng119Call();
expect(result).toEqual([1]);
Expand Down
7 changes: 7 additions & 0 deletions integration-tests/src/examples/abilityClosureCall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {
bugLNG314
} from "../compiled/examples/abilitiesClosure.js";

export async function bugLNG314Call(): Promise<string> {
return await bugLNG314();
}
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ object ArrowInliner extends Logging {
exports <- Exports[S].exports
streams <- getOutsideStreamNames
arrows = passArrows ++ arrowsFromAbilities

inlineResult <- Exports[S].scope(
Arrows[S].scope(
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ object MakeAbilityRawInliner extends RawInliner[AbilityRaw] {
varModel = VarModel(name, raw.baseType)
valsInline = foldedFields.toList.foldMap { case (_, inline) => inline }.desugar
_ <- updateFields(name, foldedFields)
_ <- Exports[S].resolved(name, varModel)
} yield {
(
varModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait Arrows[S] extends Scoped[S] {
for {
arrs <- arrows
capturedVars <- Exports[S].gather(arrow.capturedVars.toSeq)
capturedArrows = arrs.filterKeys(arrow.capturedVars).toMap ++
capturedArrows = arrs.view.filterKeys(arrow.capturedVars).toMap ++
Arrows.arrowsByValues(arrs, capturedVars)
funcArrow = FuncArrow.fromRaw(arrow, capturedArrows, capturedVars, topology)
_ <- save(arrow.name, funcArrow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ object Exports {
(fieldName, _) = field
} yield AbilityType.fullName(variable, fieldName)

state.filterKeys(names.toSet ++ related).toMap
state.view.filterKeys(names.toSet ++ related).toMap
}

// Get last linked VarModel
Expand Down

0 comments on commit 5241f52

Please sign in to comment.