Skip to content

The walk binds a variable's first occurrence without asking - #150

Closed
MaxGekk wants to merge 1 commit into
mainfrom
first-binds
Closed

MaxGekk wants to merge 1 commit into
mainfrom
first-binds

Conversation

@MaxGekk

@MaxGekk MaxGekk commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Closes #149.

The matcher's walk no longer asks the substitution for a variable it knows is unbound.

  • Before a search, the walk marks each variable child of each pattern node as a first occurrence or not, in the order it will match them. The first occurrence of a name binds at once. A later occurrence asks the substitution, as before.
  • The marks hold only for a search of one pattern from the empty substitution. A multi-pattern's clauses and Matcher.matchIn with a substitution ask at every occurrence, as before. A pattern that uses one node object at two positions turns the marks off for that search.
  • The Subst objects, their chain order and the match order are the same as before. Matcher.searchAsking keeps the old walk, and MatcherMarksTest compares the two walks match by match on math and prop saturations, including the order of each substitution's bindings.

Why are the changes needed?

Subst.nodeOfInterned is the top self frame of math's run (12 to 14% of the samples) and 9% of prop's. A count over 60 fuzz terms per language showed why: the walk asked idOrUnbound 4.7 million times on prop and got "unbound" back 89% of the time, each followed by a bindNew. The chains are short; the calls are the cost.

Does this PR introduce any user-facing change?

No. The matches, their order and their bindings are the same. The pinned suites pass and the determinism rendering is byte for byte main's.

How was this patch tested?

  • MatcherMarksTest, new: both walks over every rule of math and prop on 24 saturated graphs, compared match by match and binding order by binding order; a variable first met inside a nested node and asked for at the sibling after; a node object used twice, which falls back to asking.
  • The matcher, pinned-suite, analysis, EGraph and determinism tests pass locally (175 tests).
  • Actions: the fuzz, 1,000 terms per language, no divergence, with the compare job, run 45034140264, compare-19 (a first run, 45033330977, failed on a Maven Central rate limit before the fuzz ran); the probe, run 45033354838, probe-18, every counter of every term the same as The rebuild repairs the absorbed side's parents alone, congruence through the hashcons #136's; the Timing against main, run 45033334153, timing-10.

Predictions from #149:

  1. idOrUnbound answered unbound falls under 5% of its former number: failed by the number. prop 4,671,757 to 695,290 (15%), math 4,244,273 to 911,218 (21%). What remains is the ground checks of nested nodes (isGround), which ask about every variable of a nested node before the walk reaches it, and the multi-pattern clauses.
  2. nodeOfInterned's self share falls by half on prop and a third on math: failed. prop 8.7% to 9.9%, math 14.3% to 13.9%, lambda 10.8% (jfr view hot-methods on probe-9 and probe-18). The method is inlined into the walk's loop; the profiler charges it with the loop's samples, and 85% fewer calls did not move it.
  3. The compare job's search row: math to at most 1.22x, lambda to at most 1.07x: failed. math 1.29x to 1.40x, lambda 1.12x to 1.17x, prop 0.56x to 0.56x (egg the control on the same runner; the two runs are on different machines, so only the ratios compare).
  4. Timing reads prop and math faster: failed. prop +0.1%, math +2.3%, within noise.
  5. No count, fuzz verdict or rendering changes; the two walks agree: held.

By #149's exit clause, this closes with no code: the calls were not the cost. The lesson is on PR #151, "A profile's share is not a count". Recommendation: close unmerged.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Fable 5.1)

A search's walk marks, per view and in its own child order, whether a
variable child is the first occurrence of its name in the pattern, and binds
such an occurrence straight away; later occurrences, a multi-pattern's
clauses and a client's matchIn with a substitution ask as before, and a
pattern node object at two positions turns the marks off. Same Subst
objects, same chain and match order; Matcher.searchAsking keeps the asking
walk as the oracle, and MatcherMarksTest compares the two match by match.

Generated-by: Claude Code (Claude Fable 5.1)
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.

The matcher asks the substitution for variables it knows are unbound: the first occurrence binds without a lookup

1 participant