Skip to content

perf: disable pushDeclarationsDownTheInnerScope (#136)#137

Merged
Unisay merged 1 commit into
mainfrom
chore/disable-push-declarations
Jul 2, 2026
Merged

perf: disable pushDeclarationsDownTheInnerScope (#136)#137
Unisay merged 1 commit into
mainfrom
chore/disable-push-declarations

Conversation

@Unisay

@Unisay Unisay commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

First step of #136: take the rule out of rewriteRulesInOrder while keeping its definition and spec in place, until the IR-level float-in pass supersedes it.

The rule pushed local declarations 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: 16 golden.lua files change, all hoisting type-class dictionary resolution back out of the inner function, e.g.

     apply = (function()
+      local bind = M.Control_Bind_bind(M.Effect_monadEffect.Bind1())
       return function(f)
-        local bind = M.Control_Bind_bind(M.Effect_monadEffect.Bind1())
         return function(a)

With the rule on, bind was resolved on every call of the partially applied apply; now once. Delayed evaluation was also observable in strict semantics (an error in 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.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 pushDeclarationsDownTheInnerScope from rewriteRulesInOrder, with an explanatory comment pointing at #136.
  • Regenerated affected Lua structural goldens, showing local bindings 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.

@Unisay Unisay self-assigned this Jul 2, 2026
@Unisay Unisay marked this pull request as ready for review July 2, 2026 10:20
@Unisay Unisay merged commit f68c23f into main Jul 2, 2026
3 checks passed
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.

2 participants