Skip to content

Commit

Permalink
fix(compiler): Bug in renaming [LNG-346] (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
DieMyst authored Feb 29, 2024
1 parent 6e96899 commit d7fef3d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 13 deletions.
54 changes: 45 additions & 9 deletions aqua-src/antithesis.aqua
Original file line number Diff line number Diff line change
@@ -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
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!
2 changes: 1 addition & 1 deletion aqua-src/declare.aqua
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
48 changes: 48 additions & 0 deletions integration-tests/aqua/examples/abilitiesClosureRename.aqua
Original file line number Diff line number Diff line change
@@ -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!
6 changes: 6 additions & 0 deletions integration-tests/src/__test__/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]);
Expand Down
8 changes: 8 additions & 0 deletions integration-tests/src/examples/abilityClosureRenameCall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {
bugLNG346
} from "../compiled/examples/abilitiesClosureRename.js";

export async function bugLNG346Call(): Promise<string> {
return await bugLNG346();
}

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d7fef3d

Please sign in to comment.