Skip to content

fix(compiler): Correct mutation bug in dead branch optimization - #2400

Open
spotandjake wants to merge 1 commit into
grain-lang:mainfrom
spotandjake:spotandjake/bug_2399
Open

fix(compiler): Correct mutation bug in dead branch optimization#2400
spotandjake wants to merge 1 commit into
grain-lang:mainfrom
spotandjake:spotandjake/bug_2399

Conversation

@spotandjake

Copy link
Copy Markdown
Member

This pr corrects a small bug related to our dead branch optimization.

Programs that contained a let bind inside of constant if statement, inside of another let mut bind would lose the mut_flag of the outer binding.

This pr corrects that by properly propagating the mut_flag.

Issue: #2399

Thanks to @Kara-Zor-El for the help.

This pr corrects a small bug related to our dead branch optimization.

Programs that contained a `let` bind inside of constant `if` statement, inside of another `let mut` bind would lose the mut_flag of the outer binding.

This pr corrects that by properly propagating the mut_flag.

Issue: grain-lang#2399
Comment on lines 53 to 62
@@ -59,7 +58,7 @@ module BranchArg: Anf_mapper.MapArgument = {
recursive,
mutable_,
binds,
relinearize(id, global, body, cont),
relinearize(id, global, body, mut_flag, cont),
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and it seems to fix the issue reported. However, turns out that there's another where:

let mut x = if (true) {
  let mut y = 1
  y
} else {
  2
}

let z = () => x

x = 3
print(z())

produces 1 instead of 3.

This should fix be:

-    | AELet(global, recursive, mutable_, binds, body) => {
+    | AELet(inner_global, recursive, mutable_, binds, body) => {
        ...a,
        anf_desc:
          AELet(
-            global,
+            inner_global,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants