Skip to content

Specialize path-dependent dynamic-reference sites per dynamic context - #32

Merged
handrews merged 1 commit into
mainfrom
dynamic-specialization
Sep 24, 2026
Merged

handrews merged 1 commit into
mainfrom
dynamic-specialization

Conversation

@handrews

Copy link
Copy Markdown
Owner

A $dynamicRef/$recursiveRef site whose target differs by path used to island with cause "dynamic" (ADR 0004's unstable case), which for the extensible recursive type — a base tree re-declared by each extension that $refs it — put every nested node through the interpreter. The winner of such a site is the first resource on the path that declares the anchor, so the planner now splits the anchor: a unit's identity becomes (location, dynamic context), the units below each declaring resource are cloned per first declarer, and every clone's site resolves exactly and compiles as a static edge. Clones share one SchemaRef and report the same location, so errors, annotations, and traces are unchanged; the emitter is untouched. max_dynamic_winners (default 16) caps the declarers one anchor may bind; 0 is the previous planner, which keeps the trampoline fixtures and the island golden meaningful.

Also fixes a stale-decision bug: a site resolved in an early round was never re-checked, so a later round that added a path with another winner left the decision standing and the compiled validator could disagree with the interpreter. Every met site is now re-derived each round. In-place cycle detection keys on location and islands the ancestor on the path, so a back-edge through a clone cannot hide a loop from a short-circuiting anyOf.

Census: 2020-12 60 sites resolved, 1 anchor split, 0 islands (58/0/1 at cap 0); 2019-09 51/2/0 (47/0/2). phylohist's schema loads in 0.87 s instead of 1.85 s.

A `$dynamicRef`/`$recursiveRef` site whose target differs by path used to
island with cause "dynamic" (ADR 0004's unstable case), which for the
extensible recursive type — a base `tree` re-declared by each extension
that `$ref`s it — put every nested node through the interpreter. The winner
of such a site is the first resource on the path that declares the anchor,
so the planner now splits the anchor: a unit's identity becomes (location,
dynamic context), the units below each declaring resource are cloned per
first declarer, and every clone's site resolves exactly and compiles as a
static edge. Clones share one SchemaRef and report the same location, so
errors, annotations, and traces are unchanged; the emitter is untouched.
`max_dynamic_winners` (default 16) caps the declarers one anchor may bind;
`0` is the previous planner, which keeps the trampoline fixtures and the
island golden meaningful.

Also fixes a stale-decision bug: a site resolved in an early round was
never re-checked, so a later round that added a path with another winner
left the decision standing and the compiled validator could disagree with
the interpreter. Every met site is now re-derived each round. In-place
cycle detection keys on location and islands the ancestor on the path, so
a back-edge through a clone cannot hide a loop from a short-circuiting
anyOf.

Census: 2020-12 60 sites resolved, 1 anchor split, 0 islands (58/0/1 at
cap 0); 2019-09 51/2/0 (47/0/2). phylohist's schema loads in 0.87 s
instead of 1.85 s.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@handrews
handrews merged commit 3c4be65 into main Sep 24, 2026
6 checks passed
@handrews
handrews deleted the dynamic-specialization branch September 24, 2026 19:36
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.

1 participant