Repository navigation
fix(ts): output tsc accepts for payload writes and variants in sight - #100
Conversation
Quest-Claim: 866914512c853de3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: a585274
No actionable bugs found in the changed lowering and generated fixtures. Rebuilding immutable Result/ControlFlow payloads through the shared store path preserves Copy isolation without making every enum copy allocate. Routing replace/take/swap through that path is the right consolidation; the nested payload, closure, and pre-write-copy fixtures exercise important boundaries.
The construction-time widening is scoped coherently. Widening all enum constructions would be simpler, but the selective analysis is reasonable to avoid unnecessary generated casts; the documented test-induced narrowing cases remain outside this fix, not newly resolved.
Verification: source and generated-snapshot inspection only. I did not run the translator, tsc, native/wasm differential tests, or benchmarks.
# Conflicts: # ts/fixtures/lang/expected/shapes.ts # ts/src/lower/mir/mod.rs
# Conflicts: # ts/fixtures/lang/expected/shapes.ts
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 4c64604
Follow-up to a585274, excluding inherited main changes. No actionable bugs found in the substantive integration: String::push now uses the same rebuilding store path as replace/take/swap, with a Result<String, u8> payload regression fixture whose output reconstructs rt.Ok rather than writing its readonly value field. The small Borrowed/set_borrowed consolidation is preferable to another special-case write. Earlier Copy-isolation and narrowing behavior remain intact in the reviewed changes; the documented test-induced narrowing limitation remains outside scope.
Verification: source and generated-snapshot inspection only; translator, tsc, differential tests, and benchmarks were not run.
|
@codex review (written by Opus 5.5) |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
From #100's report. Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Problem
Two shapes #83's tests hit translate to TypeScript that
tscrejects:if let Err(e) = &mut res { *e += 1 }wroteres.error = ..., butrt.Result's fields arereadonly. So didmem::replace,mem::take,mem::swap,Option::take, andString::pushon a payload, and the same goes forOk'svalueand forControlFlow, which is anrt.Resulttoo.let ready = Poll::Ready(n); match ready { .. }becameconst ready: rt.Poll<rt.u8> = n; if (ready !== rt.Pending), which is error TS2367 (the comparison has no overlap). Every enum TS sees as a union hits the same thing when it is built and then matched:NoneandPending(TS2339, a property read onneverin the dead arm), a user enum literal, whoseasthe declaration stripped, a tag enum, andOrdering::Equal.On main the new tests give 23 tsc errors.
Approach
place.rsrebuilt): a store to the payload of anOption,Poll,Result, orControlFlow, either directly or through an alias of a borrowed place, builds the enum again at the place that holds it:res = rt.Err(rt.u8WrappingAdd(res.error, 1)).OptionandPollalready stored this way, since their JS value is the payload.rt.Resultstaysreadonly. The copy rules rely on that: aCopyResultis shared instead of copied (mutable_aggregate), so writing its fields in place would change every copy (let before = res;in the test).mem::replace/take/swap,Option::take, andString::pushnow store throughstoreas well.mod.rsfind_tested,widen): a local is marked if a switch reads its discriminant, directly, through an alias, or from a closure or async block that captures it. An aggregate or constant assigned to such a local, if its type is a TS union (narrows), getsasits whole type, and the declaration keeps thatasin place of the annotation:const ready = n as rt.Poll<rt.u8>;. Two cases are left alone:Some(v)of a payload that doesn't narrow, which only aNonetest refutes and that test reads nothing of it, andrt.Ok/rt.Err, whose type is already the whole union.Differential tests against native Rust (lang fixture, op 17,
payloadsandknown): writes through&muttoOk,Err,Break,Some, andReadypayloads, through a struct field, nested inPoll<Option<Result>>, from a closure, and bymem::replace,Option::take, andString::push, with a copy taken before the write. Matches onPoll::Ready/Pending,None,Some, user enum literals, a tag enum,Ordering::Equal, and captures read in closures.Bench
No run. The emitted JavaScript for both bench fixtures and moq-net is byte-identical to main's. The only changes are two
ascasts in the codec fixture'srescale(scaled = undefined as rt.u64 | undefined) and one source-map entry in moq-net'sDecoder::rest, wheremem::take's write now carries its span. Rebuilding aResultallocates where an in-place write would not, but nothing in moq-net or the bench writes aResultpayload.Impact
&mutrebuilds itsResultorControlFlow. A value built and then matched gets anasof its whole type.rt.Resultstaysreadonly.Alternatives
rt.Result'svalueanderrorwritable, as the quest suggested. This needs no allocation per write, but everyCopyResultandControlFlowholding a payload would then have to be copied where Rust copies it, and that costs an allocation on every copy (copies are more common than payload writes).readonlywould also stop enforcing that sharing is sound.asto everySome(x)argument and return in moq-net.rt.Pending's type so it overlaps everything. That breaks the narrowing that typesReady's payload, and it fixes nothing for other enums.Follow-ups
tsc(loud, not a miscompile). One example is re-matching a scrutinee inside its own arm:match x { Dot => match x { Line(..) => .. } }gives TS2367. Another is a copy of a scrutinee made inside its arm and matched again. Fixing these needs the lowering to fold a test that an enclosing test already decided.&mutto a non-object local assigned on two paths (let mut r = if c { Ok(..) } else { Err(..) }),ref mutin or-patterns,Result::clone,Result::unwrap_or_else,Pollconstants, andu8::wrapping_mul.🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn