Port JS scoped-blocks and remove definedVars#400
Conversation
There was a problem hiding this comment.
Pull request overview
Ports JSBuilder-style scoped-block local allocation to the Wasm text backend by removing reliance on definedVars and adding new coverage for scoped locals behavior in the Wasm tests.
Changes:
- Add
ScopedLocals.mlsWasm tests covering local allocation across top-level lets, chaining, if/else branches, and match arms. - Update
WatBuilderto (a) handleAssign(State.noSymbol, ...)by evaluating and dropping results, and (b) switch block-local allocation to scope-/Scoped-driven allocation viawithLocalDelta+nonNestedScoped.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| hkmc2/shared/src/test/mlscript/wasm/ScopedLocals.mls | Adds new Wasm test cases validating scoped-local allocation semantics (and some WAT snapshots). |
| hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala | Implements scope-driven local allocation, removes definedVars dependency, and adds a noSymbol assignment handling path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
LPTK
left a comment
There was a problem hiding this comment.
Following the change proposed by Copilot, I realize that there's a bunch of junk in the WatBuilder that was mindlessly copied from JSBuilder, such as def body now being unused. As a more serious example, it doesn't make any sense to use things like scope.nestRebindThis, as this deals with details of how JavaScript deals with the this keyword (which doesn't even exist in Wasm) in nested definitions (which aren't even possible in Wasm).
Please make a pass to remove and simplify this unnecessary logic.
|
There is no test to accompany this change. There should be at least one WASM test that uses |
|
Added two new test cases to |
LPTK
left a comment
There was a problem hiding this comment.
Thanks, LGTM now. Except for this one small question.
This PR ports JSBuilder scoped-block local allocation semantics to wasm backend. It removes
definedVarslocal collection and switches to scope-driven allocation.