Avoid IIFE wrapping in IR.Abs lowering - #170
Merged
Merged
Conversation
# Conflicts: # lib/Language/PureScript/Backend/Lua/Optimizer.hs # test/Language/PureScript/Backend/Lua/Optimizer/Spec.hs
3 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes an avoidable (function() ... end)() scope-IIFE introduced during lowering of IR.Abs when its body lowers to a statement chunk (e.g., Let / IfThenElse). By making IR.Abs lowering chunk-aware, it prevents the redundant wrap-then-unwrap cycle and allows deleting the optimizer rule that previously stripped that pattern.
Changes:
- Update
IR.Abslowering to emitLua.functionDefdirectly when the body lowers toLeft chunk, only usingreturnforRight expr. - Delete the now-dead optimizer rewrite rule
removeScopeWhenInsideEmptyFunction(and its unit test). - Add a targeted regression spec ensuring
Lua.fromUberModuledoesn’t emit the scope-IIFE forAbsbodies that areLet/IfThenElse.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
lib/Language/PureScript/Backend/Lua.hs |
Makes IR.Abs lowering chunk-aware to avoid generating scope-IIFEs for chunk bodies. |
lib/Language/PureScript/Backend/Lua/Optimizer.hs |
Removes the rewrite rule that stripped the now-avoided scope-IIFE pattern. |
test/Language/PureScript/Backend/Lua/Optimizer/Spec.hs |
Deletes the unit test for the removed optimizer rule. |
test/Language/PureScript/Backend/Lua/Spec.hs |
Adds regression tests asserting no (function() scope-IIFE appears for Abs over Let/IfThenElse. |
test/Main.hs |
Wires the new Lua spec into the Hspec test runner. |
pslua.cabal |
Registers the new test module in the spec test-suite build list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IR.Abslowering was routing every body throughasExpression, so aLetorIfThenElsebody became(function() chunk end)()inside areturn.removeScopeWhenInsideEmptyFunctionthen had to undo that on every such lambda.Changes:
lib/Language/PureScript/Backend/Lua.hs—IR.Absnow uses the chunk-awaregopath. When the body lowers toLeft chunk, it emitsLua.functionDef luaParams chunkdirectly; onlyRight exprfalls back to[Lua.return e].lib/Language/PureScript/Backend/Lua/Optimizer.hs— removed the now-deadremoveScopeWhenInsideEmptyFunctionrule and itsReturnimport.test/Language/PureScript/Backend/Lua/Optimizer/Spec.hs— removed the test for the deleted rule.Before:
After:
Summary
Checklist
changelog.d/fragment for any user-facing change (scriv createin the dev shell), or this change ships nothing releasable (CI, docs, or an
internal refactor).
nix develop),fourmolu -i lib/ exe/ test/andhlint lib/ exe/ test/are clean.cabal test allpasses; structural goldens werere-accepted on purpose if codegen moved (
PSLUA_GOLDEN_ACCEPT=1), andeval/golden.txtstill holds.Fixes #158.
Supersedes #160: same commits, reopened as a maintainer-authored PR so the required workflow runs are created (runs on PRs authored by the Copilot agent require manual approval and were never created for the follow-up pushes).