Skip to content

fix(ts): check every held value against the names its statement writes - #235

Merged
kixelated merged 5 commits into
mainfrom
quest/m2/ts-aliases
Oct 29, 2026
Merged

kixelated merged 5 commits into
mainfrom
quest/m2/ts-aliases

Conversation

@kixelated

@kixelated kixelated commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

quest/m2/ts-aliases.md collected three reports of one shape: a value the lowering holds back, instead of reading it once, names a variable that is assigned again before the read. It asked for an audit of every hold site against one check.

  1. stable_path holds only the last index of an rt.Place's path (#176).
  2. alias()'s copy arm trusts a held-back source (#148).
  3. Loop values may share one JS binding across iterations.

Findings

None of the three miscompiles today. I couldn't reproduce any of them after 24 probe shapes, all exact against native wasm32 over 50k differential cases:

  1. Nested indices. MIR indexes only through SSA temporaries, which a borrow's lifetime can't see assigned again.
  2. Copy arm. It reads the pending temporary's name, so a write of a name that temporary reads flushes it first.
  3. Loop bindings. User bindings become per-iteration consts. Names that stay hoisted (_N = start++ in a loop header, a scalar Option's payload) are never what an escaping closure or rt.Place reads.

Two guards depended on those MIR shapes rather than on what the held value reads:

  • Pending temporaries. Each emit caller passed the one local it assigned (writes). A write anywhere else in the statements, such as in pre, a branch, or x++, didn't flush a temporary that reads x.
  • Fixed objects in stable_path. Their inner indices weren't held.

Approach

  • emit finds the written names itself. It scans its statements for every name they assign, then flushes any pending temporary that reads one (or is one), in hold mode too. The writes parameter and its 28 call-site arguments are gone.
  • stable_path holds every index. Through a fixed object it holds each index the path goes through (stable_object), not only the last.
  • Tests. The lang fixture's new holds case (fixtures/lang/src/holds.rs) covers each hold site, reassigning a name between the hold and the read, in and across loop iterations:
    • nested-index rt.Places, and a place through a reassigned &mut [u8]
    • indexed borrows, shared and mutable, kept across iterations
    • reborrows through a reassigned reference, shared and mutable (#148's review asked for these)
    • copies of references and of Options that next reassigns
    • closures made in a loop and called after it
    • tuples of references read by part and whole
    • a range's start read before next
  • Mutation check. Disabling the overwrite check, or making held_now hold nothing, makes the lang differential differ from native.

Impact

  • Public API: none. No translated output changes.
    • Every fixture snapshot is unchanged apart from harness.ts renumbering for the new case.
    • Instrumenting both new checks showed neither fires on any fixture, on moq-net, its model, or kio, or on just ts moq.
  • Census (just ts census, against main at a8e75f2, before the merges): identical. moq-net 1614, model 541, kio 154.
  • Bench: not run. Generated code is byte-identical.

Alternatives

  • Coverage only, guards unchanged. Rejected: a later lowering that writes in pre or a branch would bring back the miscompile with nothing to flag it.
  • Refusing a non-SSA inner index instead of holding it. Holding it costs one const and keeps a correct translation, so there's nothing to refuse.

Choices made without asking

  • I landed the two guards although no shape reaches them today, rather than closing the quest as not reproducible. Both read the held value's names directly; emit loses a parameter in the process.

Follow-ups

None. Finishes the quest, deleting quest/m2/ts-aliases.md and its link in quest/m2/README.md.

Checks

just check and just test pass on 121143f, and again on 4c10383, which merges main through #232. That merge resolves the lang fixture's case list and crate doc by hand to keep both holds and statics.

Review

  • Reviewer: Codex gpt-6.1-sol, medium effort, via quest review.
  • Round 1 (1540a91): one finding, ffi/src/collect.rs:2200, refuted. It came from main's #233 landing after this branch's base. Main is merged in, and git diff origin/main...HEAD -- ffi is empty.
  • Round 2 (121143f): no findings.
  • Round 3 (4c10383, after the hand-resolved merge of main): no findings.

(written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 3 commits October 29, 2026 13:08
Quest-Claim: 0c06b5a34fda696f
A temporary held back for its one read is flushed before any statement that
assigns a name it reads, found from the statement itself rather than a local
each caller passes. An `rt.Place` through a fixed object holds each index the
path goes through, not only the last. Neither changes any fixture or moq's
output: the lang fixture's `holds` case covers each hold site, reassigning a
name between the hold and the read, in and across loop iterations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Held values that name a reassigned variable fix(ts): check every held value against the names its statement writes Oct 29, 2026
@kixelated
kixelated marked this pull request as ready for review October 29, 2026 21:00
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T21:39:02.551416Z 4c10383 New commits
🔒 Security Review ✅ Completed 2026-10-29T21:40:13.888158Z 4c10383 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed commit: 121143f

No actionable bugs found. The emission change derives assigned names from the statements instead of trusting one caller-supplied destination, and applies overwrite protection in hold mode too. The fixed-object path traversal now holds nested indices in evaluation order while retaining the existing eager capture of nonfixed objects. The new differential fixture covers indexed borrows, reassigned references, copies, loop captures, aggregate parts and range stepping; its generated captures appear consistent with the Rust cases.

Direction: centralizing this invariant and removing the repeated writes parameter is a reasonable simplification. These are defensive guards rather than evidence of a newly reproduced current miscompile: the PR explicitly reports that the added guard paths do not fire on the tested corpus.

Verification: static changed-code and surrounding emission/place-lifetime review, including an independent pass. I did not run differential tests, mutation checks, snapshots, the census, benchmarks or repository gates, and have not independently verified their reported results.

(Written by review (OpenAI))

# Conflicts:
#	ts/fixtures/lang/expected/harness.ts
#	ts/fixtures/lang/src/harness.rs
#	ts/fixtures/lang/src/lib.rs
@kixelated
kixelated merged commit 0f6fa59 into main Oct 29, 2026
1 check passed
@kixelated
kixelated deleted the quest/m2/ts-aliases branch October 29, 2026 22:57
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