Skip to content

Rebase #5135 (fix/infer-perf-body-producer) onto main + resolve the §3/§7 REQUEST_CHANGES: model substitute_generics_apply identity short-circuit in 04_infer.dag + regen seed - #5146

Merged
briansrls merged 22 commits into
mainfrom
work/5135-s3-fix
Jun 18, 2026

Conversation

@gunbai-bot

@gunbai-bot gunbai-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Auto-opened by session-dashboard for session crisp-wolf-348.
Pushing to work/5135-s3-fix advances this PR.

Worker attestation

Before flipping this PR to ready for review, confirm each item:

  • Title describes the change (not the session id or branch).
  • PR body summarises what and why (replace the TODO below).
  • Tests run: name the command (e.g. npm test, cargo test) and the result.
  • If this closes a work item, the body contains a Closes #N directive.
  • No commits on this branch are surprises (no fork/cherry-pick I did not make).
  • No secrets / credentials / large binaries staged.

Summary

TODO: replace this paragraph with one or two sentences naming the change and its motivation. Reviewers read this first.

Test plan

  • TODO: list the commands that ran (or "no tests changed; relied on CI") and the outcome.

briansrls and others added 21 commits June 17, 2026 21:51
…esses

Root cause for 244s body_producer resolve was decode_value_expression_projection_bundle
(15-deep bind_outcome in target_model, ~287s analyze_item), not body_producer itself.
Shard into one-bind chain steps (244s→~23s). Execution instrumentation confirms H2a:
substitute_generics 13446 calls / 169 distinct sites (ratio 79.6) — memo deferred to
merry-owl cache-kernel consolidation per §3. Adds §5 witness (bounded resolve + wrong-type RED).

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Accidental removal of Commands::Ci and extdeps_shape_transport_policy_project
broke CI (`gunbc ci` unrecognized). Restore both alongside generic-inst instrumentation.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep generic_instantiation_instrument and interface_elaboration_instrument
modules from the perf-fix branch.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ducers

Empty `diagnostics: []` failed resolve (Diagnostics is None | Some, not List).

Co-authored-by: Cursor <cursoragent@cursor.com>
#5135 is fix-only per sequencing: substitute_generics + VEP shard +
execution witnesses. Complexity_lens roster enrollment tracked in #5139.

Co-authored-by: Cursor <cursoragent@cursor.com>
Remove generic_instantiation_instrument and interface_elaboration_instrument
(hand-Rust scaffolding with no dissolution receipt). H2a localization and
the structural perf fixes are proven; hooks added per-call overhead on
substitute_generics/build_type_env/typecheck_module. Guard enrollment
tracks in follow-on #5139.

Co-authored-by: Cursor <cursoragent@cursor.com>
substitute_generics uses map_is_empty(subst) in 04_infer.dag; without
builtin_function_registry entry it fell through to unit_type() and
diverged from hand-synced Rust. Wire .dag authority + seed + interpreter.

Co-authored-by: Cursor <cursoragent@cursor.com>
… 04_infer.dag

Resolves the §3/§7 REQUEST_CHANGES: the seed's substitute_generics_apply
preserved Node identity via a short-circuit (Rc::ptr_eq on the resolved
inferred node + rc_vec_ptr_eq on children/params) that the .dag never
modeled and could not emit — a second authority for infer behavior in a
"do not edit" generated seed.

Model it in 04_infer.dag as a SOUND IDENTITY HINT (true => structurally
equal): recurse children/params/inferred, return the original n when all
are unchanged, else rebuild. Surface the primitives as ordinary builtins
with OWNED Rc signatures (cheap refcount bump preserves inner pointers),
so they emit through the normal clone path — no all-args-by-ref emit rule
and no emit-logic change:
- runtime_rust.dag: add rc_ptr_eq, flip rc_vec_ptr_eq to owned + contract
- extdeps/languages/rust/emit.dag: register map_is_empty, rc_ptr_eq,
  rc_vec_ptr_eq in rt_function_registry (map_is_empty also never
  round-tripped before — fixed here)
- 04_method.dag: register rc_ptr_eq/rc_vec_ptr_eq result types
- v1_interpreter.rs: value-equality realization of the same contract

Seed regenerated via regen_stage0 from the .dag (round-trip proven: the
emitter now produces v1_rt::rc_ptr_eq(new_rt.clone(), rt.clone()) etc.).
Narrow seed update only — a blanket regen also rewrites unrelated files
(emit_rust.rs wire_variant_tag_for_policy, extdeps_cargo.rs) byte-
identically on main too, a pre-existing emit non-fixpoint tracked
separately; adopting it would regress the seed (broken /* Type */
placeholder), so it is out of scope here.

Also fixes pre-existing PR-branch CI dirtiness: cargo fmt on build_type_env
+ the perf witness/profile tests, and #[cfg(test)] on the profile test
module (the lone module missing it, which failed clippy --all-targets).

Proof: crate builds, clippy --all-targets -D warnings green, fmt clean,
body_producer_infer_perf_witness green (clean resolve + wrong-type RED).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gunbai-bot

gunbai-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

§3/§7 resolution + stash-regen control (why narrow, not blanket-regen)

The §3/§7 finding is resolved: substitute_generics_apply's identity short-circuit is now modeled in 04_infer.dag and the seed is regenerated from it (round-trip proven — the emitter produces v1_rt::rc_ptr_eq(new_rt.clone(), rt.clone()) and v1_rt::rc_vec_ptr_eq(new_children.clone(), n.children.clone()) directly from the .dag, via owned-Rc builtins that need no emit-logic change). map_is_empty (which also never round-tripped) is registered the same way.

This is a narrow seed update, not a blanket regen_stage0 --verify. Reason: a full regen also rewrites files this change does not touch (v1_compiler_emit_rust.rs, extdeps_cargo.rs, lib.rs, main.rs) because the committed seed is not a regen fixpoint — a pre-existing emit-completeness debt (tracked separately, not this PR's scope). Adopting that collateral would regress the seed (a broken |e: /* Type */| placeholder), the opposite of faithful.

Control (proves the collateral is pre-existing, not induced by this change):

  • main fb5414452 committed seed contains wire_variant_tag_for_policy (2 hits); a clean regen_stage0 removes it (0 hits).
  • Regenerating with this branch's .dag+registry changes stashed (pristine base) produces those 4 collateral files byte-identical to regenerating with the changes. So the rc_ptr_eq/rc_vec_ptr_eq/map_is_empty rows have zero effect on unrelated emit output.

Proof bar: crate builds; clippy --all-targets -D warnings green; cargo fmt --all --check clean; body_producer_infer_perf_witness green (clean resolve + wrong-type RED). The build_type_env/test fmt + the #[cfg(test)] on the profile-test module fix pre-existing PR-branch CI dirtiness (not present on main).

@gunbai-bot
gunbai-bot Bot marked this pull request as ready for review June 18, 2026 11:51
@briansrls
briansrls merged commit fe2cd11 into main Jun 18, 2026
1 of 2 checks passed
@briansrls
briansrls deleted the work/5135-s3-fix branch June 18, 2026 12:47
briansrls added a commit that referenced this pull request Jun 19, 2026
…nblock)

resolve_expr_types double-resolved every child in its variable-arity arms
(ExprCall/RecordLit/MethodCall/Match/StringInterp): one traversal built the
resolved children, a sibling traversal re-resolved the SAME children to
re-collect diagnostics. A nested constructor's tail child is itself such a
node, so each level doubled the recursion -> O(2^depth) (#5146-class).

This was the N_v2 self-host blocker: resolve_entry_graph hung >800s on the
generated host_source_root_ingest_manifest, whose host_compiler_closure_admission
.imports is a ~20-deep Cons chain (195s, constant in record count) and whose
host_source_root_ingest is a 59-deep chain. Fixed in BOTH the .dag authority
(src/v1/04_resolve.dag) and the v1 seed (v1_compiler_infer_resolve.rs): bind the
per-child result ONCE, then split map(.expr)/flat_map(.diagnostics) — the shape
the in-file ExprListLit/ExprBlock siblings already used.

Proof by execution: N_v2 substrate resolve 279s (was >800s exit-124); scaling
probe linear (n=20 hang -> 87s); purity oracle green (resolve_typed_cache_
equivalence, identical self_gen8 pass/fail split pre/post) — result-identical,
only faster, since resolve_expr_types is pure (resolving once == twice).

Guard: resolve_expr_types_retraversal_guard_test source-bridges the real
04_resolve.dag Node and flags any arm with >=2 sibling self-calling traversals
(RED on the real pre-fix source: 5 arms; GREEN post-fix). Enrolled in the CI
rust gate via ci_spec. The 9 nv2_gate_resolve_bisect scaffolds dissolve per
their root-caused trigger; a cleaned scaling probe remains as the perf harness.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
briansrls added a commit that referenced this pull request Jun 19, 2026
…nblock) (#5258)

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

* Fix O(2^depth) resolve_expr_types: bind-once child resolution (N_v2 unblock)

resolve_expr_types double-resolved every child in its variable-arity arms
(ExprCall/RecordLit/MethodCall/Match/StringInterp): one traversal built the
resolved children, a sibling traversal re-resolved the SAME children to
re-collect diagnostics. A nested constructor's tail child is itself such a
node, so each level doubled the recursion -> O(2^depth) (#5146-class).

This was the N_v2 self-host blocker: resolve_entry_graph hung >800s on the
generated host_source_root_ingest_manifest, whose host_compiler_closure_admission
.imports is a ~20-deep Cons chain (195s, constant in record count) and whose
host_source_root_ingest is a 59-deep chain. Fixed in BOTH the .dag authority
(src/v1/04_resolve.dag) and the v1 seed (v1_compiler_infer_resolve.rs): bind the
per-child result ONCE, then split map(.expr)/flat_map(.diagnostics) — the shape
the in-file ExprListLit/ExprBlock siblings already used.

Proof by execution: N_v2 substrate resolve 279s (was >800s exit-124); scaling
probe linear (n=20 hang -> 87s); purity oracle green (resolve_typed_cache_
equivalence, identical self_gen8 pass/fail split pre/post) — result-identical,
only faster, since resolve_expr_types is pure (resolving once == twice).

Guard: resolve_expr_types_retraversal_guard_test source-bridges the real
04_resolve.dag Node and flags any arm with >=2 sibling self-calling traversals
(RED on the real pre-fix source: 5 arms; GREEN post-fix). Enrolled in the CI
rust gate via ci_spec. The 9 nv2_gate_resolve_bisect scaffolds dissolve per
their root-caused trigger; a cleaned scaling probe remains as the perf harness.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

---------

Co-authored-by: Brian Searls <briansrls@gunb.ai>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
briansrls added a commit that referenced this pull request Jun 19, 2026
…boration hangs resolve_entry_graph on the v2 compiler closure (the N_v2 interpreter blocker; #5146-class), then fix the root (#5266)

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

* N_v2 gap-2: relax dag comma-list to optional inter-item comma (mirror v1)

The v2 dag LanguageModel's shared list combinator dag_grammar_comma_list_expr
required a MANDATORY comma between items, forking from the v1 single authority
parse_field_list_acc (src/v1/stage0/src/v1_compiler_parse.rs) which separates
items on a comma OR bare juxtaposition (comma optional; newlines are whitespace).
The fork left every newline-separated multi-field record/type body unparseable
(parse_g0_tokens_remain) — the next located N_v2 self-host parse blocker after the
caret lex gap, pinned by prefix-bisection of 00_compile.dag to `type Validated`.

Fix: make the inter-item comma optional in the one shared combinator — item
(comma? item)* comma? — a strict superset (comma lists still parse) that fixes all
13 callers (field decls, param lists, generic/type-arg lists, field init/pattern,
arg lists) at once, mirroring v1's uniform optional-comma.

Floor witnesses (green by execution): newline-separated multi-field record + variant
record payload Accept; one-field + comma-separated still Accept (superset); and a
DISCRIMINATING no-fail-open control — a field missing its colon still Rejects, proving
the relaxation made the COMMA optional, not the field SHAPE permissive.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* WIP: Resolve-perf bisect+fix: pin which direct-import's full-interface elabor

---------

Co-authored-by: Brian Searls <briansrls@gunb.ai>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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