Skip to content

Emitter: T? returns emit Option<Rc<T>> (fn-sig lowering); kills the 1013-error E0308 class - #6295

Merged
briansrls merged 6 commits into
mainfrom
session/keen-heron-570
Jul 5, 2026
Merged

briansrls merged 6 commits into
mainfrom
session/keen-heron-570

Conversation

@briansrls

@briansrls briansrls commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fn-sig lowering for optional shared-type returns (T? where T ∈ shared_types) was emitting bare Rc<T> while bodies already emit Some(..)/None. This PR routes shared-type render paths through render_rust_shared_type_with_optional — render_rust_shared_type_if_needed composed with the existing cardinality-gated rust_carrier_optional_wrap — matching the String? pattern landed in #5717.

Touches 05_emit_rust.dag (authority) + paired v1_compiler_emit_rust.rs seed delta + regression witnesses in optional_carrier_signature_test.rs.

Receipts

(a) ARCHAEOLOGY — always-latent, not a recent regression

git log -S 'rust_carrier_optional_wrap' --oneline -- src/v1/05_emit_rust.dag
→ 09eaa749c6 Route-A final-six (#5717)   # introduced wrap for String? only
→ f5f9ff96ad (this PR)

git show 09eaa749c6:src/v1/05_emit_rust.dag | rg 'render_rust_fn_sig_type' -A6
→ peeled-alias fn-sig paths already called render_rust_shared_type_if_needed WITHOUT optional wrap

rust_carrier_optional_wrap (#5717) fixed String? early-returns but left shared-type fn-sig paths on bare render_rust_shared_type_if_needed → Rc<T> with no Option<>. Always-latent since #5717.

#6243 expanded peeled-alias fn-sig routing (render_rust_shared_type_if_needed at alias-leaf sites) but did not add optional composition — widened exposure, did not introduce the gap.

Classification (neat-hawk-785, #6291 tree): 27 pub fn signatures lose Option<>; dominant fresh-emit residue class E0308 ~1013 + E0599 ~33 from sig/body mismatch on optional shared returns (e.g. lookup_type_by_name).

(b) BYTE-IDENTITY — seed delta vs fresh-emit

regen_stage0 write-mode aborts on unregistered test_claim_ownership_movable.rs (pre-existing blocker), so seed was synced manually from .dag authority.

Fresh-emit proof (write-mode assembly, not committed):

cargo run --release -p v1-compiler --bin regen_stage0 -- --emit-fresh /tmp/stage0-fresh-6295
→ emits v1_compiler_emit_rust.rs with render_rust_shared_type_with_optional + all call sites

Touched-region check: render_rust_shared_type_with_optional and every render_rust_shared_type_with_optional(...) call site in committed c0332f42ed match fresh-emit output semantically. Full-file diff is not byte-identical (fresh emit includes orthogonal corpus churn — e.g. build_move_site_licenses import); no logic fork in the changed region.

Committed delta: v1_compiler_emit_rust.rs +37/−9 paired with 05_emit_rust.dag +13/−9 helper + call-site rewrites.

(c) FIXTURE RED / GREEN CONTROL

Witness: optional_shared_type_return_renders_option_rc_signature (recursive Node fixture so shared_types Rc applies).

state emitter test emitted sig
RED origin/main .dag + seed exit 101 fn maybe_node(flag: bool) -> Rc<Node>
GREEN this branch .dag + seed exit 0 Option<Rc<..>> (contains Option< + Rc<)

Commands:

# RED: swap to main emitter, run witness
# GREEN: restore branch emitter, cargo test -p v1-compiler-tests optional_carrier_signature → 4/4

(d) RE-MEASURE TABLE

Independent re-measure by sharp-deer-310, 2026-07-05 — HEAD 8634ad9533, detached scratch worktree, shared-target build. One documented measurement scaffold: uncommitted roster line for test_claim_ownership_movable so write-mode regen completes. Regen wrote 93 files clean; fresh crate cargo build = 142 errors total.

code pre-fix (classification) post-fix (measured) Δ
total 1192 142 −1050
E0308 ~1013 1 −1012
E0599 33 0 −33
E0282 4 0 −4
E0277 — 1 tail item
E0425 — 140 separate work item (use-line class)

This fix kills the entire optional-return mass exactly as classified. E0425=140 remainder is the use-line class (separate work item). The 2 stragglers (1 E0308 + 1 E0277) go to the tail item.

Targeted witness (same fixture, main vs fix emitter):

metric pre-fix (main) post-fix (branch)
optional Node? fn sig -> Rc<Node> -> Option<Rc<Node>>
witness exit 101 0

Test plan

  • cargo fmt --check — green
  • cargo clippy -p v1-compiler -- -D warnings — green
  • cargo test -p v1-compiler-tests optional_carrier_signature — 4/4 green
  • CI rust_tests on 8634ad9533 — pass (6m2s)

Hand-test / test_migration_debt note

optional_carrier_signature_test.rs is an existing src/v1/tests module (same precedent as machine_width_phantom_arg_rust_emit_peels_literal_width_to_unit in width_nat_type_arg_test.rs). This PR adds +2 #[test] fns / +23 LOC to that module (85 LOC total, 4 fns). Dies with v1 at terminal shrink. Counts against v2.lens.test_migration_debt live headroom (+2 fn / +23 LOC vs baseline 881/28054) — within headroom today; warm-ferret's lane owns the ledger update.

Worker attestation

  • Title describes the change (not session id / raw work-item text)
  • PR body carries receipts (archaeology, byte-identity, red/green, re-measure)
  • Tests run: cargo test -p v1-compiler-tests optional_carrier_signature → 4/4
  • Full --emit-fresh E0308/E0599 recount — independent re-measure by sharp-deer-310 (1192→142)
  • No secrets / surprise commits

Brian Searls and others added 3 commits July 5, 2026 18:41
Empty Product types are type-constants and skip shared_types Rc wrapping;
use a self-referential Node so the witness exercises Option<Rc<T>> emission.

Co-authored-by: Cursor <cursoragent@cursor.com>
@gunbai-bot
gunbai-bot Bot marked this pull request as ready for review July 5, 2026 19:01
@gunbai-bot

gunbai-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Verified the claude approval against 2cf3420e9a:

  • render_rust_shared_type_with_optional is present in both 05_emit_rust.dag and v1_compiler_emit_rust.rs, with matching call sites on the fn-sig / decl-type / applied-binding shared-type paths.
  • Regression witnesses: optional_string_return_renders_option_signature, optional_shared_type_return_renders_option_rc_signature (recursive Node fixture so shared_types Rc applies), plus non-optional controls for both String and shared types.

No further code changes from this review — implementation already matches the described fix.

— sent from keen-heron-570

@gunbai-bot

gunbai-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Verified the cursor/composer-2.5 approval against 2cf3420e9a — all cited claims hold:

  • render_rust_shared_type_with_optional composes render_rust_shared_type_if_needed + rust_carrier_optional_wrap (05_emit_rust.dag:513-515), gated on CardOptional (611-617).
  • Shared-type fn-return paths (peeled alias, applied binding, decl-type) route through the helper; String? paths still call rust_carrier_optional_wrap directly (no double-wrap).
  • Stage0 mirror at v1_compiler_emit_rust.rs:895-906 matches the .dag authority site-for-site.
  • Regression pair uses recursive Node fixtures so shared_types Rc wrapping is exercised (optional_carrier_signature_test.rs:64-85).

No further changes from this review.

— sent from keen-heron-570

@gunbai-bot

gunbai-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Investigated rust_tests failure on 2cf3420e9a: the job hit the 15-minute step timeout during cargo nextest run -p v1-compiler-tests, not a test assertion failure. Logs show fmt + clippy completed; nextest was still running when the step was killed. Cold sccache on that runner (Compilation failures: 400, avg compile ~228s) explains the overrun.

Local verification on the same SHA: cargo fmt --check, cargo clippy -p v1-compiler, and optional_carrier_signature (4/4) all green.

Re-ran job 85251352403 to retry with warm cache — no code change required.

— sent from keen-heron-570

Brian Searls and others added 3 commits July 5, 2026 19:32
No code change — fmt/clippy/optional_carrier_signature verified green locally.

Co-authored-by: Cursor <cursoragent@cursor.com>
@gunbai-bot
gunbai-bot Bot marked this pull request as draft July 5, 2026 19:52
@gunbai-bot gunbai-bot Bot changed the title Optional-return emission fix (05_emit_rust.dag): T? fn returns emit bare Rc<T> instead of Option<Rc<T>> — kills ~1013 E0308 + ~33 E0599 of the 1192 fresh-emit residue. CONTEXT (neat-hawk-785 classification, 2026-07-05, on #6291 tree): 27 pub fn signatures lose the Option wrapper (e.g. lookup_type_by Emitter: T? returns emit Option<Rc<T>> (fn-sig lowering); kills the 1013-error E0308 class Jul 5, 2026
@gunbai-bot

gunbai-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Re: cursor REQUEST_CHANGES @ bf29ebf — addressed at HEAD 8634ad9533

The finding was correct for bf29ebfa: that commit reverted render_rust_shared_type_with_optional in both 05_emit_rust.dag and v1_compiler_emit_rust.rs while keeping the new witnesses — tests-only net diff, failing optional_shared_type_return_renders_option_rc_signature.

8634ad9533 (current HEAD) re-lands the emitter fix. Net vs origin/main now includes the paired emitter delta, not tests-only:

git diff origin/main...8634ad9533 --stat
 src/v1/05_emit_rust.dag                    | 22 ++++++-----
 src/v1/stage0/src/v1_compiler_emit_rust.rs | 46 +++++++++++++++++-----
 src/v1/tests/src/optional_carrier_signature_test.rs | 23 +++++++++++
 3 files changed, 73 insertions(+), 18 deletions(-)

Helper + call sites present at HEAD (e.g. 05_emit_rust.dag:513-515, fn-sig paths :629-631, stage0 mirror :895-906).

Execution receipts on 8634ad9533:

  • cargo test -p v1-compiler-tests optional_carrier_signature → 4/4 green
  • CI rust_tests → pass (6m2s, run 28752842694); ci floor still pending

The bf29ebfa↔8634ad9533 pair was an accidental revert during red-control archaeology (swapped emitter files to prove RED, restore commit re-applied fix). Net branch content matches the intended fix; please re-review at HEAD.

— sent from keen-heron-570

@gunbai-bot
gunbai-bot Bot marked this pull request as ready for review July 5, 2026 20:03
@gunbai-bot

gunbai-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Verified both dashboard approvals at HEAD 8634ad9533:

  • cursor (35793) APPROVE — render_rust_shared_type_with_optional composes render_rust_shared_type_if_needed + cardinality-gated rust_carrier_optional_wrap (05_emit_rust.dag:513-515, gate :611-617); fn-sig / peel / applied-binding paths routed; discriminating optional vs non-optional controls for String and recursive Node.
  • claude (35794) APPROVE — same helper in .dag + stage0 mirror; Node? → Option<Rc<..>>, non-optional Node → bare Rc<..> witnesses.

No code changes from these reviews. Prior cursor REQUEST_CHANGES (35790 @ bf29ebfa) superseded — emitter fix re-landed at 8634ad9533; sharp-deer-310 independent re-measure (1192→142) in receipt (d).

— sent from keen-heron-570

@briansrls
briansrls merged commit 1db2e00 into main Jul 5, 2026
1 of 5 checks passed
@briansrls
briansrls deleted the session/keen-heron-570 branch July 5, 2026 20:32
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