Repository navigation
feat(model): add Stmt.forEachWhile early-exit bounded loop (#2916) - #2958
Merged
Merged
Conversation
Each distinct Environment passed to evalConstCheck is retained by Lean's interpreter closure cache (~3 GB for the Contracts import cone), pushing multi-call driver suites such as CompileDriverTest past the 10 GB cgroup memory cap. Reuse the cached Environment when a subsequent in-process call requests a subset of its modules under the same search path.
Add Stmt.forEachWhile varName count guard body to the CompilationModel, re-evaluating the guard before every iteration check and lowering the loop condition to and(lt(idx, cnt), iszero(iszero(guard))) so an early exit runs no remaining empty iterations. Includes Denote and SourceSemantics execution, validation (scope rules, CEI, ADT and call-like guard rejection), constructor-wide analysis/proof-surface cases, conservativity and guarded-flag-loop equivalence theorems in Compiler.Proofs.IRGeneration.ForEachWhile, DenoteAgreement proofs, feature tests, and Foundry differential smoke tests against Solidity break loops. Refs #2916
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
Author
|
Looks good to merge on 046387b. No blocking or non-blocking findings. What I Ran
What I Read & Verified
|
This branch was successfully deployed
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.
Refs #2916 (partial: adds the
CompilationModelearly-exit bounded loop constructStmt.forEachWhile, proofs, and differential smoke tests; Solidity importer lowering of early-exitforloops is deferred to follow-up PR B).What changes
1.
Stmt.forEachWhile varName count guard body(046387bdf)Verity/Core/Model/Types.lean,Denote.lean,DenoteFunctionCalls.lean,Compiler/Proofs/IRGeneration/SourceSemantics.lean):countonce, initializesvarName := 0before iteration check 0, and re-evaluatesguardbefore every iteration check (including the terminalremaining = 0check, matching Yul's non-short-circuiting condition order).remaining : Nat(boundfromcount), stopping immediately on the first check whereguardevaluates to0with no silent out-of-fuel fallback.Compiler/CompilationModel/Compile.lean):for { let idx := 0 let cnt := <count> let <varName> := 0 } and(lt(idx, cnt), iszero(iszero(<guard>))) { idx := add(idx, 1) } { <varName> := idx <body> }, freshening synthetic counters againstinScopeNames,varName,count,guard, andbody(forEachWhileUsedNames/forEachWhileBodyScope).ScopeValidation.lean,Validation.lean,ValidationCalls.lean,ValidationHelpers.lean,ValidationInterop.lean,UsageAnalysis.lean,TrustSurface.lean,Verity/Macro/EffectAnalysis.lean):countin the outer scope andguard/bodyin the loop scope (varName :: localScope), rejectingvarNameshadowing of parameters, outer locals, or enclosing loop variables while allowing sequential sibling reuse.guardand ADT expressions incount/guard.count -> guardand cross-iterationbody/guard -> guardordering in CEI and read-after-external-call checkers, with soundness lemmas inEffectAnalysis.lean.Compiler/Proofs/IRGeneration/ForEachWhile.lean,DenoteAgreement.lean,SupportedSpec.lean,HelperBodyShape.lean,FunctionBody/Stmt.lean):Stmt.forEachunder constant nonzero guards (execStmt_forEachWhile_eq_forEach_of_guard_const,execStmt_forEachWhile_literal_one_eq_forEach).Stmt.forEachloops up to the out-of-scope loop variable (execStmt_forEach_guarded_eq_forEachWhile,execStmt_forEach_flagGuarded_eq_forEachWhile).evalIRExpr_forEachWhile_cond), early-exit step (execIRStmt_forEachWhile_exit), andDenote<->SourceSemanticsagreement (execForEachWhileLoop_rawFree,execForEachWhileLoop_agree).sorry, ornative_decide; zero weakened theorem statements.Contracts/Smoke/ForEachWhileSmoke.lean,test/ForEachWhileSmoke.t.sol,SourceSemanticsFeatureTest.lean,CompilationModelFeatureTest.lean,CompileDriverTest.lean):breakloops covering first/middle/last match, no match,n = 0, empty body,2^200/uint256.maxwith early exit,2^200without exit (out-of-gas on both sides), plainforEachnegative control, loop-variable reads inguard, even nonzero word (2) guard normalization, and fuzzing.2. Reuse imported
Environmentacross in-process module loads (ed0a0d1d3)Compiler/ModuleInput.lean: Lean 4.31's interpreter closure cache retains each distinctEnvironmentpassed toevalConstCheck(~3 GB for theContractsimport cone), pushing multi-call suites such asCompileDriverTestpast a 10 GB cgroup cap.loadSpecsFromModulesnow reuses the cachedEnvironmentwhen a subsequent in-process call requests a subset of its modules under the sameSearchPath.Verification (on
046387bdf)lake build(7777/7777jobs) -> PASSlake build Verity Contracts+python3 scripts/check_lean_warning_regression.py(3baseline warnings) -> PASSpython3 scripts/generate_print_axioms.py+lake build PrintAxioms+python3 scripts/check_axioms.py(8922theorems,0project axioms) -> PASS./.lake/build/bin/verity-compiler --module Contracts.Smoke.ForEachWhileSmoke --output compiler/yul-smoke+FOUNDRY_PROFILE=difftest forge test --match-path test/ForEachWhileSmoke.t.sol -vv(13/13passed) -> PASSForEachWhileSmoke.yul(drop early exit, invert guard, dropiszero(iszero(guard))normalization) -> all 3 killedmake check(1043unit tests + hygiene, boundary, proof-length, and docsync checks) -> PASS