Repository navigation
feat: plan 08 part C constant folding, recursive parameters, application fusion and silent O2 - #41
Merged
Merged
Conversation
Remove the early passes and use the existing post-ANF cleanup loops. Update snapshots, documentation and the 108-case baseline. All 3827 workspace tests, strict Clippy, formatting and the explicit performance check pass. Signed-off-by: microproofs <kwhitemsg@gmail.com>
Add bounded builtin evaluation after ANF, update the production optimizer snapshot corpus, and extend the separate performance baseline to 148 cases. Validation: 3832 workspace tests passed; strict Clippy and formatting passed; all 148 explicit performance cases match the baseline. Signed-off-by: microproofs <kwhitemsg@gmail.com>
Integrate only the pair rewrite whose projection cancels through constructor inverse cleanup. Include guard snapshots, semantic fixtures, and the separate 178-case performance baseline. Validation: 3834 workspace tests passed; strict compiler and performance-tool Clippy passed; formatting and all 178 explicit performance checks passed. Signed-off-by: microproofs <kwhitemsg@gmail.com>
Resolve fst and snd fields and accessors for known native pair types, lower them to the pair builtins, and report pair-specific missing-field diagnostics. Include inference, codegen, and rejection snapshots and update the language documentation. Validation: 3845 workspace tests passed; strict Clippy, formatting, and whitespace checks passed. The final tree exactly matches the original combined change. Signed-off-by: microproofs <kwhitemsg@gmail.com>
Follow self and mutual forwarding dependencies to a liveness fixed point, preserve strict argument evaluation and type views, and support delayed workers in mutual recursion encoding and reachability cleanup. Validation: 3852 workspace tests, strict root and performance-tool Clippy, formatting, and 194 explicit performance checks passed. Six measured cases improve without regressions; the original 178 rows and O0 snapshots remain unchanged. Signed-off-by: microproofs <kwhitemsg@gmail.com>
Verify same-size cleanup progress, per-phase hygiene, recursive-cycle stability, deterministic output, and the intentional one-pass signature and bounded-folding limits. Document the final O0/O1 configuration and mark the retained Plan 08 scope complete. Validation: 3857 workspace tests and the five focused composition tests passed; strict Clippy, formatting, and 194 explicit performance checks passed. New semantic snapshots exclude evaluator cost figures. 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>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Signed-off-by: microproofs <kwhitemsg@gmail.com>
Nash compiles validators against the V3 script context only, so a V1 or V2 language tag produced an invalid validator. Remove the plutusVersion project setting, the --plutus-version option of build and test, nash_config::PlutusVersion, assemble_core_for_version, TestProgram::plutus_version and the version parameters of assemble_core_with_options and compile_tests*. The driver and the test runner always use V3, and script hashes always use the V3 language tag. The evaluator enum in nash-plutus is unchanged. Validation: 3893 workspace tests passed with no unreferenced snapshots; strict Clippy passed for the repository and the performance workspace; formatting passed. The explicit performance check was not run. Signed-off-by: microproofs <kwhitemsg@gmail.com>
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.
Summary
Third and last part of plan 08 (plans/08-optimizer.md). This PR completes Chunks 6, 9, 10 and 11, adds a new Chunk 12 (application fusion, native packing and late UPLC cleanup), and lands the first chunk of the new plan 15 (plans/15-o2-optimizer.md): silent O2. Twelve commits, eight changesets.
SPEC.mdmarks plan 08 complete and plan 15 partial.Behavior changes:
-O0output is unchanged.nash buildandnash testaccept-O2/--optimize 2, andnash.jsoncaccepts"optimize": 2. O2 is never the default..fstand.sndaccess for known builtin pair types.Versioning: minor bumps for
nash-codegen,nash-solve,nash-config,nash-driverandnash-cli; patch fornash-ir,nash-reportandnash-plutus. See.sampo/changesets/.Post-ANF placement (
perf(codegen): run constructor and inverse folding only after ANF)known_case::reduce_constrandinverse::reducecalls before ANF are removed.Constant builtin evaluation, Chunk 9
integrate bounded constant folding into O1). Newnash-ir::constant_foldpass with a callback that codegen supplies, sonash-irstays independent of codegen. It folds saturated builtin calls with literal arguments through ANF bindings, then repeats cleanup.fold and clean up to an unbudgeted fixed point). The 128-attempt cap, the per-call CPU and memory allowance, the payload byte, node and depth gates, the allowlist and the Flat growth gate are gone. Every pure, representable, successful call folds. The loop stops only when folding and cleanup both leave Core unchanged.nash-plutusaddseval_constant_builtin, a direct evaluator with no budget. Out-of-range constant indices and constructor tags now return errors instead of a panic. Whole-byte left shifts are corrected, and shift, rotate and list-drop accept arbitrary-size inputs.comptimekeep their existing policies.Pair projection and pair access, Chunk 10
cancel single-field constructor pair cases). Newnash-ir::pair_projection. A one-branchCaseKind::Pairbecomes afstPair/sndPairprojection only when constructor inverse cleanup then removes that projection. Producer bindings stay strict. The general projection rule from the trial is not adopted..fst/.snd(add typed fst and snd pair access).p.fst,p.sndand the accessor functions.fst,.sndresolve for known builtin pair types and their aliases, and lower directly to the pair builtins. The receiver type must be known. Records with fields namedfstorsndkeep ordinary record semantics. Record update and record patterns on pairs are rejected with pair-specific diagnostics.docs/syntax.mdhas the new section.Recursive unused parameters, Chunk 6 (
remove unused recursive parameters before ANF)nash-ir::unused_paramsnow handles self-recursive and mutually recursive groups, after static lifting and before the single ANF pass.Composition and convergence, Chunk 11
complete optimizer composition and convergence review). Five regression tests: a mixed cleanup pipeline with phase, type and hygiene evidence; a same-node-count rewrite that exposes more cleanup; a reachable recursive cycle rendered without evaluation; cleanup-exposed signature removal; and a 130-call fixture that reaches a folding fixed point.revisit static lifting after cleanup). Static lifting, unused-parameter removal, constant folding and cleanup now repeat together until Core pointers are unchanged. Before this, a second O1 run could still remove work:cleanupExposesStaticgave 46 Flat bytes after one run and 39 after two. One run now gives 39.Application fusion, native packing and late UPLC cleanup, Chunk 12 (
fuse O1 applications and clean up late UPLC)All three are O1 rules. They preserve enabled traces, failure and termination.
single_use::inlineturnslet p = f a in p bintof a bwhenphas one direct use, the operands are atomic and the intermediate type views agree.nash-codegen::uplc_optimizer. It removes identity applications without dropping argument evaluation, substitutes single-use values, removes unused value bindings and cancels direct force/delay pairs. Substitution rejects possible name capture. Recursive self-application is never unfolded.Case(Constr(0, args), [function])when the function and all arguments are UPLC values. Packing starts at three arguments, which is the first arity where the two native nodes replace moreApplynodes.lower::lower_optimizedis the common O1 entry point for production, shared snapshots, source tests and performance checks. O0 and the isolated sharing APIs are unchanged.Silent O2, plan 15 Chunk 2 (
add silent O2 compilation and trace erasure)nash-codegen::silentpass andoptimizer::optimize_silent. O2 erases every Core trace operation, then runs the O1 pipeline.CoreKind::Traceand directBuiltin.Tracein saturated, partial, aliased and first-class positions. A bare builtin reference becomes a typed no-log function. The value that a trace returns still evaluates, and work outside the trace stays strict.nash-configaddsOptimizationLevel::O2andBuild::validate. O2 with compact or verbose tracing, or with compiler traces, is an error (BuildConflict) in project config and after CLI overrides.nash testdefaults to verbose traces under O0/O1 and to silent under O2. Runner status reporting is not affected.docs/cli.mdanddocs/codegen.mddescribe the level and the erasure boundary.Tests and measurements
tools/optimizer-perf/baseline.jsongrows from 108 to 199 rows and from 10 to 13 sources. All 199 cases produce identical O1 code after one, two and three runs.decodingcleanupExposesStaticdocs/research/:constant-fold-trial.md,pair-projection-trial.md,recursive-parameters.md,optimizer-convergence.md,application-packing-trial.mdando2-silence-trial.md. Raw trial reports are intools/optimizer-perf/trials/.Not in this PR
Test plan
The last commit records 3,896 passing workspace tests, strict Clippy on the repository and on the performance workspace, and 199 matching performance cases.
cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningscargo nextest run --workspacecargo check --manifest-path tools/optimizer-perf/Cargo.tomlnash build -O2andnash test -O2, because automated tests call the Rust APIs and do not launch the binary