fix(subst): convert bound form-locals to expressions lazily - #1106
Merged
Conversation
Since 615d335 (#1056), `f_bind_local` / `add_flocal` eagerly translate every bound form to an expression so that expression-level locals inside program statements are substituted as well. Both fix-reduction paths (`EcReduction` ι match-fix, `EcCallbyValue.try_reduce_fixdef`) bind the constructor arguments through `f_bind_local` at every recursion step, so reducing a recursive operator over a large datum re-traverses and re-hashconses the whole remaining structure at each step: quadratic time plus heavy GC / weak-table churn. `size [0; ...; 4999] = 5000` took ~10s by `cbv delta`, `simplify delta` or `done`, and ~48s for 10000 elements. The expression-local maps (`fs_eloc`, `sb_elocal`) now hold `expr option Lazy.t`: the translation is suspended at bind time and forced, once per binding, on the first `Elocal` lookup in `e_subst` / `subst_expr`. `None` records the `CannotTranslate` case, preserving the semantics introduced by #1056. Also fix a regression from #1056 in `EcSubst.rename_flocal`: it asserted that no expression binding existed for the renamed local, but `add_flocal` now installs one, so the theory-replay compatibility check for inductive predicates with renamed constructor binders (e.g. `clone T with pred p <- q`) died with an anomaly. The entry is now overwritten, as `f_bind_rename` does. Regression test: `tests/clone_ind_rename_binders.ec`. The 5000-element example drops from 10.4s to 0.036s and scales linearly. `tests/eager_call_instanciate.ec`, `make unit` and `make stdlib` pass.
strub
force-pushed
the
slow-reduction
branch
from
September 2, 2026 15:59
7e5fdc4 to
51def03
Compare
bgregoir
approved these changes
Sep 2, 2026
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.
Since 615d335 (#1056),
f_bind_local/add_flocaleagerly translateevery bound form to an expression so that expression-level locals inside
program statements are substituted as well. Both fix-reduction paths
(
EcReductionι match-fix,EcCallbyValue.try_reduce_fixdef) bind theconstructor arguments through
f_bind_localat every recursion step, soreducing a recursive operator over a large datum re-traverses and
re-hashconses the whole remaining structure at each step: quadratic time
plus heavy GC / weak-table churn.
size [0; ...; 4999] = 5000took ~10sby
cbv delta,simplify deltaordone, and ~48s for 10000 elements.The expression-local maps (
fs_eloc,sb_elocal) now holdexpr option Lazy.t: the translation is suspended at bind time andforced, once per binding, on the first
Elocallookup ine_subst/subst_expr.Nonerecords theCannotTranslatecase, preserving thesemantics introduced by #1056.
Also fix a regression from #1056 in
EcSubst.rename_flocal: it assertedthat no expression binding existed for the renamed local, but
add_flocalnow installs one, so the theory-replay compatibility checkfor inductive predicates with renamed constructor binders (e.g.
clone T with pred p <- q) died with an anomaly. The entry is nowoverwritten, as
f_bind_renamedoes. Regression test:tests/clone_ind_rename_binders.ec.The 5000-element example drops from 10.4s to 0.036s and scales
linearly.
tests/eager_call_instanciate.ec,make unitandmake stdlibpass.