Skip to content

feat: run the compiler on a 128 MiB stack and restore recursive traversals - #43

Merged
MicroProofs merged 9 commits into
mainfrom
bigger-recursion-stack
Oct 10, 2026
Merged

MicroProofs merged 9 commits into
mainfrom
bigger-recursion-stack

Conversation

@MicroProofs

Copy link
Copy Markdown
Contributor

Summary

Compiler work now runs on threads with a 128 MiB stack, and the traversals that #39 converted to heap work lists recurse again. The branch also fixes the CBOR encoding of large negative Data integers, removes unused compiler helpers and adds Nash tests to the vesting example. Nine commits, nine changesets.

Behavior changes:

  • The parser has no nesting limit. The limit of 64 and its Space::TooDeep error are removed.
  • There is no stack check. Input that needs more than 128 MiB of stack ends the process with a stack overflow, not with a diagnostic.
  • Negative Data integers below -(2^64 - 1) have a different CBOR encoding, and tag 3 payloads decode to a different value. See the fix below.

Versioning: minor bumps for nash-driver, nash-parse, nash-test, nash-constrain and nash-report; patch for nash-cli, nash-plutus, nash-ir and nash-codegen. See .sampo/changesets/.

Compiler stack (feat(driver): run compiler work on a 128 MiB stack and remove the parser nesting limit)

  • New nash_driver::stack module: COMPILER_STACK (128 MiB) and run, which executes a closure on a new scoped thread with that stack and resumes a panic from the work.
  • The reserve is address space. The system commits a page only when the thread touches it.
  • These threads use it: the driver's compile and import-scan threads, and the CLI's command, format and docs threads.
  • nash-parse loses with_depth, the depth and depth_error parser state and error::Space::TooDeep. nash-report loses the matching variant and its snapshot.
  • crates/nash-driver/tests/stack.rs compiles a module with 4,000 nested parentheses. That depth overflows a 2 MiB thread in a debug build.

Recursive traversals restored

Four commits convert heap work lists back to recursion, in the shape of the Elm and imported code. Together they remove about 630 lines.

  • Flat (restore the recursive Flat term encoder and decoder). encode_term and decode_term recurse again. nash test decodes programs on its worker pool, so nash_test::Config gains worker_stack and the CLI gives those workers the compiler stack.
  • UPLC support (restore the recursive UPLC printer, De Bruijn conversion, and target validation). pretty::term, to_debruijn and validate_*.
  • Core (restore the recursive Core traversals). walk, map, occurrence and free-variable analysis, discard checks, hygiene, ANF, beta splicing and Core printing in nash-ir.
  • Codegen (restore the recursive lowering, constant-sharing rewrite, and recursion rewrite).

The work lists that the stack audit lists under "Reproduced failures" and that these commits do not name stay as they are.

Data integer fix (fix(plutus): encode and decode negative Data big integers as -1 - n)

  • CBOR tag 3 holds -1 - n (RFC 8949, section 3.4.3). The decoder read the payload as -n, and the encoder wrote n.
  • -2^64 is now a plain negative integer (3bffffffffffffffff), not a tagged big integer.
  • A new test checks five values at the 64-bit boundaries against the Haskell node encoding, in both directions.

Maintenance

  • Unused code (remove unused compiler helpers and ignored parameters). Removes database dependency bookkeeping and DepGraph::depends_on, unused report and type helpers, and the FailureKind alias. Removes ignored private parameters in config parsing, import resolution and destructuring projection.
  • Final cleanup (finish compiler maintenance and verify LSP root compatibility). iterated_dealias is a loop, as Elm's version is tail recursive. The private evidence helper loses duplicate representation-superclass handling; public evidence validation stays. A new language server snapshot covers the root_uri fallback, workspace folder priority and the clearing of prior roots.

Examples, dependencies and plan documents (update vesting example)

  • examples/vesting/app/src/VestingTests.nash calls both validator entry points with synthetic V3 contexts. It checks claim deadline boundaries, owner and non-owner cancellations, and the parameterized minimum lock. The README gives the command.
  • examples/order builds again: the nash/base dependency entry is removed and not comes from Logic.
  • The zip dependency drops Bzip2 support, so bzip2-sys is no longer built. All other ZIP features and XZ extraction stay.
  • docs/macros.md, plans/11-macros-comptime.md and SPEC.md record the Plan 11 sequence, the source location contract and the chunk 15 property and assertion migration. These are document changes only.

Documents

  • docs/overview.md and docs/codegen.md describe the stack model in place of the nesting limit and the work lists.
  • docs/research/compiler-stack-audit.md has a new "Stack model" section that supersedes the work-stack direction, and a "Maintenance cleanup" section.
  • docs/frontend-hardening-verification.md notes that the nesting bound is removed.

Not in this PR

  • A stack check or a diagnostic for input that is too deep.
  • Conversion of the remaining work lists back to recursion.
  • Plan 11 chunk 15 implementation.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo nextest run --workspace
  • cargo check --manifest-path tools/optimizer-perf/Cargo.toml
  • cargo run -p nash-cli -- test examples/vesting

…ser nesting limit

Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
…rsion, and target validation

Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
…ewrite, and recursion rewrite

Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
@MicroProofs
MicroProofs merged commit 74c221a into main Oct 10, 2026
10 checks passed
@MicroProofs
MicroProofs deleted the bigger-recursion-stack branch October 10, 2026 12:12
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.

1 participant