From d7fef3db5fda6c2dfeacac84c3cff2188538a35a Mon Sep 17 00:00:00 2001 From: Dima Date: Thu, 29 Feb 2024 12:23:34 +0300 Subject: [PATCH] fix(compiler): Bug in renaming [LNG-346] (#1094) --- aqua-src/antithesis.aqua | 54 +++++++++++++++---- aqua-src/declare.aqua | 2 +- .../aqua/examples/abilitiesClosureRename.aqua | 48 +++++++++++++++++ .../src/__test__/examples.spec.ts | 6 +++ .../src/examples/abilityClosureRenameCall.ts | 8 +++ .../aqua/model/inline/ArrowInliner.scala | 4 +- 6 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 integration-tests/aqua/examples/abilitiesClosureRename.aqua create mode 100644 integration-tests/src/examples/abilityClosureRenameCall.ts diff --git a/aqua-src/antithesis.aqua b/aqua-src/antithesis.aqua index 0f3ce6a5..7d07de39 100644 --- a/aqua-src/antithesis.aqua +++ b/aqua-src/antithesis.aqua @@ -1,12 +1,48 @@ -aqua Job declares * +aqua Main -import someString from "hack" -use timeout, someString from "hack.aqua" as P +export bugLNG346 -export timeout +ability Promise: + yield() -> string -func timeout() -> string: - res <- P.timeout() - b = someString() - a = P.someString() - <- res \ No newline at end of file +func done_nil() -> string: + <- "" + +func done() -> Promise: + <- Promise(yield = done_nil) + +ability Compute: + yield() -> string + +alias WorkerYield: -> string +alias Yield: WorkerYield -> Promise + +func wait_for() -> Yield: + wait = func (cb: -> string) -> Promise: + yield = func () -> string: + e <- cb() + <- e + <- Promise(yield = yield) + <- wait + +ability Function: + run(dealId: string) -> string + +func simple{Compute}(yield: Yield) -> Function: + deal_run = func () -> string: + c_yield = func () -> string: + <- Compute.yield() + yieeld <- yield(c_yield) + res <- yieeld.yield() + <- res + <- Function(run = deal_run) + +func bugLNG346() -> string: + res: *string + yieeld = func () -> string: + res <<- "hello" + <- "" + c = Compute(yield = yieeld) + fn = simple{c}(wait_for()) + r <- fn.run("") + <- res! \ No newline at end of file diff --git a/aqua-src/declare.aqua b/aqua-src/declare.aqua index e2048ef7..5b38ae38 100644 --- a/aqua-src/declare.aqua +++ b/aqua-src/declare.aqua @@ -1,4 +1,4 @@ -module DeclareModule declares decl_foo, decl_bar, SuperFoo, DECLARE_CONST, DECLARE_CONST2 +aqua DeclareModule declares decl_foo, decl_bar, SuperFoo, DECLARE_CONST, DECLARE_CONST2 export SuperFoo const DECLARE_CONST = "declare_const" diff --git a/integration-tests/aqua/examples/abilitiesClosureRename.aqua b/integration-tests/aqua/examples/abilitiesClosureRename.aqua new file mode 100644 index 00000000..6081ae9f --- /dev/null +++ b/integration-tests/aqua/examples/abilitiesClosureRename.aqua @@ -0,0 +1,48 @@ +aqua AbilitiesClosureRename + +export bugLNG346 + +ability Promise: + yield() -> string + +func done_nil() -> string: + <- "" + +func done() -> Promise: + <- Promise(yield = done_nil) + +ability Compute: + yield() -> string + +alias WorkerYield: -> string +alias Yield: WorkerYield -> Promise + +func wait_for() -> Yield: + wait = func (cb: -> string) -> Promise: + yield = func () -> string: + e <- cb() + <- e + <- Promise(yield = yield) + <- wait + +ability Function: + run(dealId: string) -> string + +func simple{Compute}(yield: Yield) -> Function: + deal_run = func () -> string: + c_yield = func () -> string: + <- Compute.yield() + yieeld <- yield(c_yield) + res <- yieeld.yield() + <- res + <- Function(run = deal_run) + +func bugLNG346() -> string: + res: *string + yieeld = func () -> string: + res <<- "hello" + <- "" + c = Compute(yield = yieeld) + fn = simple{c}(wait_for()) + r <- fn.run("") + <- res! \ No newline at end of file diff --git a/integration-tests/src/__test__/examples.spec.ts b/integration-tests/src/__test__/examples.spec.ts index 4fa629d0..5d40b16a 100644 --- a/integration-tests/src/__test__/examples.spec.ts +++ b/integration-tests/src/__test__/examples.spec.ts @@ -41,6 +41,7 @@ import { returnSrvAsAbilityCall, } from "../examples/abilityCall.js"; import { bugLNG314Call, bugLNG338Call } from "../examples/abilityClosureCall.js"; +import { bugLNG346Call } from "../examples/abilityClosureRenameCall.js"; import { nilLengthCall, nilLiteralCall, @@ -670,6 +671,11 @@ describe("Testing examples", () => { expect(result).toEqual("job done"); }); + it("abilitiesClosureRename.aqua bug LNG-346", async () => { + let result = await bugLNG346Call(); + expect(result).toEqual("hello"); + }); + it("functors.aqua LNG-119 bug", async () => { let result = await bugLng119Call(); expect(result).toEqual([1]); diff --git a/integration-tests/src/examples/abilityClosureRenameCall.ts b/integration-tests/src/examples/abilityClosureRenameCall.ts new file mode 100644 index 00000000..e5769e42 --- /dev/null +++ b/integration-tests/src/examples/abilityClosureRenameCall.ts @@ -0,0 +1,8 @@ +import { + bugLNG346 +} from "../compiled/examples/abilitiesClosureRename.js"; + +export async function bugLNG346Call(): Promise { + return await bugLNG346(); +} + diff --git a/model/inline/src/main/scala/aqua/model/inline/ArrowInliner.scala b/model/inline/src/main/scala/aqua/model/inline/ArrowInliner.scala index 0287394d..be3ebd27 100644 --- a/model/inline/src/main/scala/aqua/model/inline/ArrowInliner.scala +++ b/model/inline/src/main/scala/aqua/model/inline/ArrowInliner.scala @@ -507,9 +507,7 @@ object ArrowInliner extends Logging { * are prohibited because they are used inside **this function**. */ defineNames <- StateT.liftF( - fn.body.definesVarNames.map( - _ -- argNames -- capturedNames - ) + fn.body.definesVarNames ) defineRenames <- Mangler[S].findAndForbidNames(defineNames) canonStreamsWithNames <- canonStreamVariables(args)