Skip to content

Remove unused to_ir.Var.GlobalVar constructor#663

Open
mvanhorn wants to merge 1 commit intopallene-lang:masterfrom
mvanhorn:osc/662-remove-globalvar
Open

Remove unused to_ir.Var.GlobalVar constructor#663
mvanhorn wants to merge 1 commit intopallene-lang:masterfrom
mvanhorn:osc/662-remove-globalvar

Conversation

@mvanhorn
Copy link
Copy Markdown

@mvanhorn mvanhorn commented May 1, 2026

Summary

Removes the to_ir.Var.GlobalVar constructor from the to_ir.Var union and the two elseif var_info._tag == "to_ir.Var.GlobalVar" arms in to_ir.lua that referenced it. Per issue #662 these are residual after the rest of the global-handling rewrite.

Why this matters

Issue #662 says to_ir.Var.GlobalVar is residual code. Confirmed by reading the function that produces to_ir.Var values:

ToIR:resolve_variable (src/pallene/to_ir.lua:237) only ever constructs to_ir.Var.LocalVar (line 255) inside its initial loop, then optionally promotes that value to to_ir.Var.Upvalue (line 288) when the declaration is captured by an enclosing function. There is no code path that constructs to_ir.Var.GlobalVar. The function asserts var is set, so it always returns either LocalVar or Upvalue.

That means the two elseif var_info._tag == "to_ir.Var.GlobalVar" arms in exp_to_value (line 1066) and exp_to_assignment (line 1314) are unreachable. The first arm contains only a -- Fallthrough to default comment; the second arm contains bb:append_cmd(ir.Cmd.GetGlobal(loc, dst, var_info.id)) which can never execute. The else branch with tagged_union.error(var_info._tag) still catches any future tag the compiler might add.

Changes

src/pallene/to_ir.lua: 5 lines removed across 3 spots.

  • Line 31: GlobalVar = {"id"}, removed from the define_union("Var", { ... }) block.
  • Lines 1066-1067 in exp_to_value: drop the elseif ... GlobalVar arm whose body is just a comment.
  • Lines 1314-1315 in exp_to_assignment: drop the elseif ... GlobalVar arm whose bb:append_cmd(ir.Cmd.GetGlobal(...)) body is unreachable.

The two else branches that follow each removed elseif continue to call tagged_union.error(var_info._tag), so any new variant would still be caught loudly at runtime.

Testing

After the change, grep -rn 'GlobalVar' src/pallene/ returns no matches.

I do not have a Lua / busted toolchain in this environment, so I did not run the test suite locally. The change is mechanical removal of dead code; no logic flow is altered.

Closes #662

@hugomg
Copy link
Copy Markdown
Member

hugomg commented May 1, 2026

Is this AI generated?

Please do not submit AI-generated code to pallene

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove unused GlobalVar constructor

2 participants