Skip to content

feat(complexity_gate): infer-perf composed-lens guard (follow-on to #5135) - #5139

Closed
gunbai-bot[bot] wants to merge 15 commits into
mainfrom
fix/infer-perf-complexity-guard
Closed

gunbai-bot[bot] wants to merge 15 commits into
mainfrom
fix/infer-perf-complexity-guard

Conversation

@gunbai-bot

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

Copy link
Copy Markdown
Contributor

Summary

Tracked follow-on to #5135 — enrolls the infer-perf pathologies in the existing subject_complexity_budget_roster + complexity_lens machinery (no parallel budget authority).

What the roster measures (pinned by reading v2/lens/complexity.dag):
complexity_lens = asymptotic projection of cost_lens → SymbolicCost → AsymptoticClass (Constant / Linear / Polynomial / …). It is Big-O class over Node-tree symbolic cost, NOT concrete op-count. Cardinality fold → LinearCost; nested Cardinality → ProductCost → multidimensional polynomial (nested_test receipt).

Discrimination by execution (claim_batch receipts):

  • bug1 (substitute_generics tree×keys): infer_substitute_tree_x_subst_semantic_red_holds PASS — pre-fix nested-Cardinality fixture FAILS linear declared budget; post-fix infer_substitute_budget_claim_holds PASS.
  • bug2 (VEP mega-closure): infer_vep_mega_closure_semantic_red_holds PASS — pre-fix nested fixture FAILS ConstantComplexity; post-fix infer_vep_decode_budget_claim_holds PASS.

Coverage honesty: VEP row uses nested-Cardinality pathology model (not literal bind_outcome depth counting — Bind is zero-cost in cost_lens). If real decode-tower depth is too coarse for Big-O class alone, axis extension lands in this PR coordinated with quiet-swift (one roster, extended — never forked).

Depends on

#5135 (perf fix: substitute_generics map_is_empty + target_model VEP shard)

Test plan

Made with Cursor

briansrls and others added 15 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>
briansrls added a commit that referenced this pull request Jun 18, 2026
#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>
briansrls added a commit that referenced this pull request Jun 18, 2026
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>
@gunbai-bot
gunbai-bot Bot marked this pull request as draft June 18, 2026 01:48
@gunbai-bot

gunbai-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Verified — this REQUEST_CHANGES is correct. #5139 (branched at merge-base b63934d, before the removal commits) still carries generic_instantiation_instrument / interface_elaboration_instrument wired into the infer hot path, the claim_batch.rs reset/eprint_report hooks, and the languages_import_elaboration_profile_test harness.

Resolution is at the root, not a patch here: these exact scaffolds were ALREADY removed on #5135 @ a47cd9d — both modules deleted, all production/CI hooks gone (verified). #5139 is the complexity-gate guard FOLLOW-ON, sequenced to rebase onto #5135 after it lands; that rebase brings in the instrument removal and clears this finding, rather than patching a base that is about to be rebased away.

#5139 is in DRAFT and not a merge candidate yet for two reasons beyond the rebase:

  1. Source-bridge the synthetic infer_perf_lens_fixture subjects to the REAL substitute_generics / VEP function Nodes (the current fixtures prove the lens discriminates the pathology CLASS; they do not yet regression-guard the real functions).
  2. A cost_lens cost-axis extension for the bind-nesting-depth case: the VEP mega-closure computes as Constant today because Bind=zero_cost in cost_lens, so a real 15-deep bind tower is invisible to the lens — that is a cost-model gap, fixed by extending the ONE cost_lens/roster (not a fork).

REQUEST_CHANGES acknowledged; it resolves via the rebase + the rework above, and #5139 stays draft until then. — sent from merry-crab-687

@gunbai-bot

gunbai-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Closing this follow-on — it is blocked and must restart from a rebased base, so a perpetually-draft PR is misleading. Specifics:

  • Cannot progress until fix(infer): shard target_model VEP decode to fix body_producer 312s resolve #5135 (fix/infer-perf-body-producer) lands: this branch must rebase onto the instrument-free a47cd9d (which removes the generic_instantiation_instrument / interface_elaboration_instrument scaffolds cursor flagged on this PR — that REQUEST_CHANGES resolves at the root via the rebase, not a patch here).
  • The guard needs substantive rework before it is real teeth: (1) source-bridge the synthetic infer_perf_lens_fixture subjects to the REAL substitute_generics / VEP function Nodes; (2) a cost_lens cost-axis extension for bind/closure-nesting depth (the VEP mega-closure computes as Constant today because Bind=zero_cost — a cost-model gap, fixed by extending the ONE cost_lens/roster, not a fork).
  • The genuine design (composed-lens ComplexityBound budget rows, semantic RED/GREEN, subject producers) is preserved on branch fix/infer-perf-complexity-guard for reuse.
    Re-dispatched as a fresh PR after fix(infer): shard target_model VEP decode to fix body_producer 312s resolve #5135 merges. The guard follow-on is tracked (merry-owl-830); only the PR number changes. — sent from merry-crab-687

@gunbai-bot gunbai-bot Bot closed this Jun 18, 2026
briansrls added a commit that referenced this pull request Jun 18, 2026
…3/§7 REQUEST_CHANGES: model substitute_generics_apply identity short-circuit in 04_infer.dag + regen seed (#5146)

* WIP: Resolve/infer perf fix: 03_body_producer.dag 244s super-linear infer (H1

* WIP: Resolve/infer perf fix: 03_body_producer.dag 244s super-linear infer (H1

* WIP: Resolve/infer perf fix: 03_body_producer.dag 244s super-linear infer (H1

* WIP: Resolve/infer perf fix: 03_body_producer.dag 244s super-linear infer (H1

* WIP: Resolve/infer perf fix: 03_body_producer.dag 244s super-linear infer (H1

* fix(infer): shard target_model VEP decode; confirm H2a; add perf witnesses

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>

* fix(stage0): restore gunbc ci subcommand dropped by regen

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>

* WIP: Resolve/infer perf fix: 03_body_producer.dag 244s super-linear infer (H1

* WIP: Resolve/infer perf fix: 03_body_producer.dag 244s super-linear infer (H1

* WIP: Resolve/infer perf fix: 03_body_producer.dag 244s super-linear infer (H1

* WIP: Resolve/infer perf fix: 03_body_producer.dag 244s super-linear infer (H1

* WIP: Resolve/infer perf fix: 03_body_producer.dag 244s super-linear infer (H1

* fix(complexity_gate): use outcome_accepted for infer-perf subject producers

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

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

* chore(#5135): move composed-lens guard to follow-on #5139

#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>

* WIP: Resolve/infer perf fix: 03_body_producer.dag 244s super-linear infer (H1

* fix(#5135): drop investigation instrumentation from production hot paths

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>

* fix(#5135): register map_is_empty in v1 builtin registry

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>

* fix(#5135): model substitute_generics_apply identity short-circuit in 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>

---------

Co-authored-by: Brian Searls <briansrls@gunb.ai>
Co-authored-by: Cursor <cursoragent@cursor.com>
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