Skip to content

fix: narrow nullable scalar switch once - #18

Draft
fullofcaffeine wants to merge 3 commits into
mainfrom
fix/4tc8-null-switch-narrowing
Draft

fullofcaffeine wants to merge 3 commits into
mainfrom
fix/4tc8-null-switch-narrowing

Conversation

@fullofcaffeine

@fullofcaffeine fullofcaffeine commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

Why

Haxe can rewrite a nullable scalar switch into a null test and a local alias.

The old Rust output tested the same Option again in the present branch. It also kept a dead, catchable Null Access throw.

This output was harder to read and did more work than one native Rust match.

What changed

The compiler now accepts the same exact alias shape when transparent one-item blocks wrap its final local.

It emits one Option match and binds the present payload directly:

match value {
    None => -1,
    Some(__hx_value) => __hx_value,
}

The recognizer still requires the same source local, alias identity, result type, and Copy scalar type. Other nullable shapes keep the existing checked lowering.

The generic snapshot covers direct Null<Int> and Null<Float> switches. It also covers a called try-and-close flow that produces the nested alias shape.

This change adds no runtime support.

Before and after

The base commit emitted an outer is_none() guard. Its present branch matched the same Option and kept a dead Null Access throw.

The new output evaluates the nullable value once. One match handles both None and Some.

Verification

  • The portable and metal regression snapshots passed generation, Rust formatting, Cargo build, Clippy, and golden-output comparison.
  • npm run test:rust-raw-authority passed, including the hello_trace snapshot.
  • Repository guards passed before the full harness started.
  • The full harness passed 31 of 37 semantic-difference cases. Six unrelated cases exceeded the fixed 180-second timeout on the contended host.
  • The corrected unchanged codex-hxrust replay used selector commit 14d133c and this compiler worktree.
  • The consumer runner now contains exactly one match exit.
  • The consumer runner contains no exit.is_none, __hx_opt, or nullable Null Access branch.
  • The generated consumer crate passed rustfmt, cargo check --locked, cargo test --locked, and the tui-prompt-submit-envelope runtime gate.
  • Whole-crate consumer Clippy remains red on approximately 7,005 existing style warnings. This compiler change did not introduce those warnings.

Tracking

Issue: haxe_rust-4tc8

Base: b4975cb3bc0039cfabf498e455cbab4e36de58de

Current head: b3b60a22dea562caef7551e3ca2b08d9074af86d

Agent provenance

Prepared by the haxe.rust compiler agent after codex-hxrust exposed haxe_rust-4tc8 through a real process-exit switch.

The compiler agent owns review fixes and rebasing for this branch. Final approval and merge remain maintainer-only.

Other agents must not modify this branch without a recorded handoff.

Haxe rewrites a nullable scalar switch into a null test and a local alias in the present branch. The old Rust lowering tested the same Option again and kept a dead, catchable Null Access throw.

Recognize that exact typed shape for Copy scalar values and emit one Option match. Portable and metal snapshots now cover Int and Float values, including both present and null cases.

Verified with the focused snapshot and Clippy gate, adjacent nullable and switch snapshots, repository hooks, root Cargo formatting, and root Clippy with warnings denied. Other nullable shapes keep the existing checked lowering.
The nullable switch compiler change moved one reviewed raw Rust call site without changing its ownership or authority. Refresh the generated inventory so hosted snapshot jobs can confirm the current source location.

The factory, authority, reason, owner, boundaries, and inventory counts are unchanged. Verified with the raw-authority test, its hello snapshot, the focused portable and metal nullable snapshots with Clippy, the raw-authority guard, and the pre-commit evidence wiring test.
@fullofcaffeine

Copy link
Copy Markdown
Owner Author

Hosted snapshot repair

The hosted snapshot jobs found a stale generated inventory after the compiler edit moved source lines.

The documented sync changed one reviewed call-site line from 17386 to 17483.

The factory, authority, reason, owner, boundaries, and inventory counts remain unchanged.

Exact replacement head: 83333c9664d13f4d69a56bb6e44331e69cc74bd8

Verification at this head:

  • npm run test:rust-raw-authority passed, including the hello_trace snapshot.
  • The portable and metal nullable_scalar_switch_narrowing snapshots passed with build, output diff, and Clippy checks.
  • npm run guard:rust-raw-authority passed.
  • npm run test:pre-commit-evidence-wiring passed.
  • The staged diff changes only the recorded line number.

The earlier local report used npm run hooks:check. That command does not include the raw-authority guard or its focused test.

The isolated worktree also disabled Git hooks during creation, as required. Therefore, the commit did not invoke the project pre-commit hook.

The project pre-commit hook selects the raw-authority test when compiler source changes. I missed that separate hook path in the first verification pass.

The haxe.rust compiler agent retains ownership of review fixes and rebasing for haxe_rust-4tc8. Final approval and merge remain maintainer-only.

Other agents must not modify this branch without a recorded handoff.

A nullable scalar switch could become an outer null check followed by a second Option match. The second match kept a dead Null Access throw in generated Rust.

Recognize the same compiler-generated alias shape when its final local sits inside transparent one-item blocks. Emit one Option match, while keeping all existing source-local, type, and Copy-value checks.

The portable and metal snapshots cover direct Int and Float switches plus a called try-and-close flow that produces the nested alias shape. Focused generation, formatting, Cargo build, Clippy, snapshot comparison, and the corrected codex-hxrust consumer replay pass.

The full harness passed all guards and 31 semantic-difference cases. Six unrelated semantic-difference cases exceeded the fixed 180-second timeout on the contended host.
@fullofcaffeine

Copy link
Copy Markdown
Owner Author

Replacement head and consumer proof

Exact head: b3b60a22dea562caef7551e3ca2b08d9074af86d

The final patch keeps one narrow compiler owner. It only peels transparent one-item blocks around the alias tail of the existing nullable scalar pattern.

The portable and metal regression snapshots passed generation, rustfmt, Cargo build, Clippy, and golden-output comparison.

npm run test:rust-raw-authority also passed. The generated inventory changed one source line only. Its factory, authority, and owner remain unchanged.

The full hook command reached the complete harness. All repository guards passed first.

The harness passed 31 of 37 semantic-difference cases. These six cases exceeded the fixed 180-second timeout on the contended host:

  • anonymous_key_value_aliasing
  • array_index_updates
  • array_key_value_iterator_boundary
  • array_string_element_append
  • portable_option_result_basics
  • reflect_dynamic_receivers

No harness assertion, compiler diagnostic, Cargo error, or runtime error failed in those cases.

The corrected unchanged codex-hxrust replay used selector commit 14d133c. It loaded this exact compiler worktree and reported four dirty entries before the commit.

The generated process-exit block now has:

  • exactly one match exit;
  • no exit.is_none;
  • no __hx_opt;
  • no nullable Null Access branch.

The disposable generated crate passed rustfmt, cargo check --locked, cargo test --locked, and the tui-prompt-submit-envelope runtime gate.

Whole-crate consumer Clippy still reports approximately 7,005 existing style warnings. I do not claim that check passed.

Prepared by the haxe.rust compiler agent for haxe_rust-4tc8. The compiler agent owns review fixes and rebasing.

Final approval and merge remain maintainer-only. This PR stays draft and unmerged.

@fullofcaffeine

Copy link
Copy Markdown
Owner Author

Landing dependency update: PR #19 fixes the newly reported fast-uri audit failure, but its two snapshot jobs were cancelled at the exact 60-minute workflow ceiling while still advancing through late curated Clippy cases. PR #20 is a focused stacked change that raises only that ceiling and its contract to 90 minutes.\n\nRequired order remains maintainer-controlled: merge PR #20 into PR #19, require PR #19 exact-head hosted green, merge PR #19 into main, then rebase this semantic PR and require all checks green again. This PR remains draft and must not be pinned by consumers before its eventual merged commit is replayed.

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