perf: disable pushDeclarationsDownTheInnerScope (#136)#137
Merged
Conversation
The rule moved let-bound work from partial application into every call of the returned function: sharing was lost (the goldens show type-class dictionary resolution re-running per call) and evaluation was delayed past its strict-semantics point. Disabled until it is superseded by an IR-level float-in pass; the rule definition and its spec stay in place. All eval goldens pass unchanged; the 16 golden.lua diffs all hoist dictionary resolution back out of the inner functions.
There was a problem hiding this comment.
Pull request overview
Disables the Lua AST optimizer rule pushDeclarationsDownTheInnerScope (while keeping its implementation and spec) to avoid turning let-bound sharing into per-call work and to preserve strict evaluation timing, as described in issue #136.
Changes:
- Removed
pushDeclarationsDownTheInnerScopefromrewriteRulesInOrder, with an explanatory comment pointing at #136. - Regenerated affected Lua structural goldens, showing
localbindings staying in the outer function (so they run once per partial application rather than once per full application).
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/Language/PureScript/Backend/Lua/Optimizer.hs | Stops applying pushDeclarationsDownTheInnerScope in the expression optimizer and documents why (issue #136). |
| test/ps/output/Golden.TailRecM2Shadow.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.StringCodePoints.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.ProfunctorDictLens.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.MaybeChain.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.LongStateBind.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.LongStackBind.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.LongExceptBind.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.LongDoBlock.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.Issue37.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.HelloPrelude.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.GenericEqTwoTypes.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.DerivedFunctor.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.CharLiterals.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.BugListGenericEq.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.ArrayPatternMatch.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
| test/ps/output/Golden.ArrayOfUnits.Test/golden.lua | Structural golden updated to reflect hoisting locals out of inner lambdas. |
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.
First step of #136: take the rule out of
rewriteRulesInOrderwhile keeping its definition and spec in place, until the IR-level float-in pass supersedes it.The rule pushed
localdeclarations from an outer function into the returned inner function, which moves the work from partial application into every call. The regenerated goldens show what that cost in practice: 16golden.luafiles change, all hoisting type-class dictionary resolution back out of the inner function, e.g.With the rule on,
bindwas resolved on every call of the partially appliedapply; now once. Delayed evaluation was also observable in strict semantics (anerrorin a let RHS fired at full application instead of partial application).All eval goldens (the hand-verified runtime oracle, never auto-accepted) pass unchanged; the structural golden churn is the 16 files above plus the comment in
rewriteRulesInOrder.