fix(compiler): Passing closures with abilities [LNG-314] (#1035)

This commit is contained in:
Dima 2024-01-09 19:31:37 +03:00 committed by GitHub
parent d5cd77bb86
commit 5241f522d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 66 additions and 7 deletions

View File

@ -29,4 +29,4 @@ jobs:
apps: sbt
- name: Run tests
run: sbt test
run: env JAVA_OPTS="-Xmx4G" sbt test

View File

@ -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

View File

@ -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

View File

@ -40,6 +40,9 @@ import {
multipleAbilityWithClosureCall,
returnSrvAsAbilityCall,
} from "../examples/abilityCall.js";
import {
bugLNG314Call,
} from "../examples/abilityClosureCall.js";
import {
nilLengthCall,
nilLiteralCall,
@ -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]);

View File

@ -0,0 +1,7 @@
import {
bugLNG314
} from "../compiled/examples/abilitiesClosure.js";
export async function bugLNG314Call(): Promise<string> {
return await bugLNG314();
}

View File

@ -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,

View File

@ -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)

View File

@ -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