Skip to content

test: reproduce the Lua parser-nesting crash behind #108#111

Merged
Unisay merged 1 commit into
mainfrom
issue-108/parser-nesting-repro-test
Jun 23, 2026
Merged

test: reproduce the Lua parser-nesting crash behind #108#111
Unisay merged 1 commit into
mainfrom
issue-108/parser-nesting-repro-test

Conversation

@Unisay

@Unisay Unisay commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #110. The #108 goldens (LongApplyChain, LongBindFlipped) only exercise the fixed path — the golden harness always runs the full optimizer, so they never show the red state, and the regression they guard was asserted rather than demonstrated. This adds the missing red-before-green reproduction.

What it does

A new test in the Lua golden spec builds a ~300-deep applicative spine (apply (apply (apply 0 1) 2) … n, depth in the first-argument position) as a synthetic UberModule, compiles it to Lua twice via compileIr — once without flattenDeepBinds, once with — and parse-checks each with luac -p (parse only, no execution):

  • without the passluac fails with chunk has too many syntax levels;
  • with the pass → it loads.

Why it pins the bug to the right cause

Lua 5.1 has two distinct per-function limits, and a wrong fix can trade one for the other (a naive full A-normalisation flattens the nesting but overflows the 200-locals cap). The unflattened spine here is a single nested expression whose only local is the module table, so the test asserts exactly one local — which means the failure can only be parser nesting, not the locals cap. The error message (too many syntax levels) confirms it.

This complements the empirical finding that nested call arguments (and nested function bodies, and nested parens) overflow the recursive-descent parser, while a flat curried suffix chain f(a)(b)(c)… does not — i.e. spineDepth is a deliberately conservative over-approximation of the parser's actual nesting cost.

Test-only; no production code changes.

#108)

The #108 goldens (LongApplyChain etc.) only exercise the *fixed* path — the
golden harness always runs the full optimizer, so they never show the red state,
and the regression they guard was asserted rather than demonstrated.

Add a focused test at the generated-Lua level: build a ~300-deep applicative
spine (`apply (apply (apply 0 1) 2) … n`, depth in the first-argument position),
compile it to Lua twice via `compileIr` — once WITHOUT `flattenDeepBinds`, once
with — and parse-check each with `luac -p`. Without the pass the chunk fails to
load with "chunk has too many syntax levels"; with it, it loads.

Crucially the unflattened form is a single nested expression whose only `local`
is the module table, so the test asserts exactly one `local` — proving the
failure is parser *nesting*, not Lua 5.1's separate 200-locals-per-function cap
(the limit a naive full A-normalisation would instead hit). This is the
red-before-green check that pins the bug to the right cause.

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

Adds a regression-reproduction test in the Lua golden spec to demonstrate (red-before-green) the Lua 5.1 parser-nesting crash behind #108 by compiling a synthetic deep applicative spine with and without flattenDeepBinds, then validating parseability via luac -p.

Changes:

  • Add a new golden-spec test that compiles a ~300-deep apply spine both unflattened and flattened, and asserts luac -p failure vs success.
  • Introduce helpers to build the synthetic UberModule and to parse-check generated Lua with luac -p.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/Language/PureScript/Backend/Lua/Golden/Spec.hs
Comment thread test/Language/PureScript/Backend/Lua/Golden/Spec.hs
@Unisay Unisay merged commit eac26b8 into main Jun 23, 2026
3 checks passed
@Unisay Unisay deleted the issue-108/parser-nesting-repro-test branch June 23, 2026 08:51
@Unisay Unisay self-assigned this Jun 23, 2026
Unisay added a commit that referenced this pull request Jun 23, 2026
…ew-fixes

address copilot review on #111: robust luacParse + looser local-count check
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