Repository navigation
perf(semantic): compute a feature's redefinition closure once per model - #1353
Merged
Merged
Conversation
AllRedefinedFeatures rebuilt its visited set and closure on every call, and the implicit parameter redefinitions behind it rebuilt the owner's owned-parameter list on every query although parametersOf memoizes that list. An execution root frame asks for the closure of every feature it holds, so each frame paid for both. The closure is now a journaled per-symbol table like the other semantic memos, and the position lookup reads the memoized list. Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
A closure walked while a guard cut a nested query short — a redefinition still resolving its clause, or an owner whose parameter list is still being computed — may lack a target. AllRedefinedFeatures now runs under a resolver lookup frame and caches only when that frame settled, and parametersOf cuts a re-entrant reader short the way RedefinedFeatures does, instead of answering it silently with an empty list. Co-Authored-By: jason.han <hanhuijun@gmail.com>
This was referenced Oct 21, 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.
What and why
In the 0.11.0 release-gate measurement
internal/exec/runtimeBenchmarkNewRootFramereads 36 → 55 allocs/op against 0.10.1 (12.5 → 13.8 KiB/op). The allocation profile puts the whole difference underContext.holdFeature, which since #1057 askssemantics.Model.AllRedefinedFeaturesfor every feature a root frame holds (0.10.1 asked the memoizedRedefinedFeatures, explicit clauses only).AllRedefinedFeaturesrebuilt its visited set andvisitclosure on every call, and the implicit parameter redefinitions it walks (implicitParameterTargets) rebuilt the owner's owned-parameter list (positionalParameters(ownedParameters(owner))) on every query to find the parameter's position — a listparametersOf(owner)already memoizes, and whose owned entries come first in the same order.Changes, all in
internal/semantic/semantics:AllRedefinedFeaturesis a journaled per-symbol table (allRedefined, keyed likenestedRedefsand invalidated with the declaration), so the closure of a feature is computed once per model. The walk runs under a resolver lookup frame and is cached only when that frame settled: a closure cut short by a redefinition still resolving its clause, or by an owner whose parameter list is still being computed, is answered but recomputed on the next query — the same ruleRedefinedFeaturesfollows.parametersOfrecords its lookup depth and cuts a re-entrant reader short (computingParams, likecomputingRedefined) instead of answering it silently with the empty seed, and does not memoize its own list when its frame did not settle.implicitParameterTargetsreads the parameter's position fromm.parametersOf(owner).positionalinstead of rebuilding the owned list.Same redefinitions, same positions; only the repeated work goes.
How it was verified
Failing-before test
TestRedefinedFeaturesAreComputedOncePerSymbol(internal/semantic/semantics/implicit_parameter_memo_test.go):AllRedefinedFeatures(Proc::a)is[Base::x]and a repeated query allocates 0 times (7 on developd8b60ed62), and a repeatedImplicitParameterRedefinitionsquery allocates at most its result beyond what the owner'sImplicitGeneralscosts (a differential bound, so it holds with or without fix(semantics): derive a declaration's implied generals once per symbol #1350).Guard tests:
TestRedefinitionClosureIsNotCachedWhileAGuardCutsItShortqueries the closure under an openRedefinedFeaturesguard and checks that the next query, after the guard lifts, returns the target (the first commit of this branch returned[]);TestParameterListGuardCutsDependentQueriesShortdoes the same under an openparametersOfguard.A/B over six interleaved rounds on one machine, allocations exact (
benchstatp=0.002 on every moved row). The benchmark did not exist on develop before the 0.10.1 back-merge, which is newer than feat(runtime): accepts, counted steps and recursive typed bodies inside action bodies #1057, so the pre-regression column is the 0.10.1 tag itself. Columns: v0.10.11c45b6e17| developd8b60ed62+ fix(semantics): derive a declaration's implied generals once per symbol #1350 | this change + fix(semantics): derive a declaration's implied generals once per symbol #1350:NewRootFrameDerivedReadWriteReadMaterializePlainAttributesNewRootFrameis back to the 0.10.1 allocation count (36 with the lookup frames too); the other two rows are not this change's (their movement bisects to fix(runtime): type an object by every type its feature inherits through subsetting #1276 and is addressed in perf(runtime): compute a feature's effective types once per model #1351).go build ./...,go vet ./...,gofmt -l .empty,go test ./internal/semantic/semantics ./internal/check/... ./internal/ir/... ./internal/exec/runtime,python3 scripts/changelog.py check.Checklist
make testandmake lintpass locally (the packages above locally; the full suite runs in CI)changes/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved (no gate count moved)F4,K5) in the body, docs, or changelogLink to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/cf22d7a746814d20b2f0eaf11682fef9
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/cf22d7a746814d20b2f0eaf11682fef9?variant=devin
Requested by: @HuiJun