Repository navigation
fix(ts): copy what a container stores - #99
Conversation
Quest-Claim: 34c51521626f285f
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
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: 7e93a72
No actionable bugs found. The analysis-level retention check and ownership propagation address the previously identified container-store aliasing gap, including non-Copy holders and values returned to callers. The generated cases preserve separation for repeated stores, mutable container reads, boxes, and held fields.
Direction looks sound: centralizing this in the MIR analysis is safer than requiring each library mapping to remember a copy. The extra retention/type analysis is justified by avoiding blanket copies at every call; keep future store forms covered by differential regressions before further copy-elision optimizations.
Verification: source and generated-snapshot inspection only. I did not run the translator, native/wasm differential suite, or benchmarks, and have not independently verified the reported performance results.
# Conflicts: # ts/fixtures/lang/expected/keys.ts
Replaces ts-shared-read's narrow fix, as #99 suggested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Give #96's strs and this branch's stores their own ops (% 44), and regenerate the harness snapshot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
|
@codex review (written by Opus 5.5) |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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. |
Keep both sides' reject cases (copy_within and Arc<[u8]> beside #96's String and str patterns), and regenerate the snapshots over #96's and #99's lowering. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
* chore(quest): default comparison methods and generic instances Follow-ups from #98 and #94. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): Cow<str> and str slicing from #96 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): share Copy types the crate never changes in place Replaces ts-shared-read's narrow fix, as #99 suggested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): an A/A control that measures noise From #87's and #97's bench findings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> 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
Storing a by-value
Copyaggregate through a std call shared the JS object instead of copying it. Afterv.push(pair); v.push(pair); v[0].0 ^= 1,v[1]andpairchanged too. This was a silent miscompile. The share analysis ints/src/lower/mir/mod.rsonly counted in-place changes made through a local. It missed changes made later through a container element, a box, or a&mutthat std returns.The same gap let a value with no copy function share a
Copyaggregate it holds.Holder { pair }(notCopy) pushed into a vector, passed to a function that changes it, or returned to a caller all sharedpair's object.Approach
Everything is in the analysis. No library mapping changed.
keeps: a std call keeps aCopyaggregate it takes by value if its result holds it behind a box, reference, or collection, or if another argument can take it in (&mut, interior mutability, a raw pointer). This also covers a part std takes apart, such as each element ofv.extend([pair, x]). A value with no copy that holds aCopyaggregate counts as kept by any callee, the crate's own included. A return place of such a type is kept by the caller.copy_fn). The exception is a value moved out of a local's own value: that local is marked changed in place (mutated), so its value is already its own, and the move hands it over without a copy.Ok([a, b])andpush((a, b))copy-free.vec![x; n]no longer copiesxin its mapping, because the call site now copies it.Translator::translated, shared withcall_def's existing check.For
ts-shared-read: the decision is made in one place,keepsplusmoved_from, and it is recorded onmutated. A new kind of store adds a case tokeeps. A new way to hand over a value adds a case tomoved_from.Reproduced first: the new
langcase gives 1070 differences against native Rust with main's translator and 0 with this one. It coversVec::push(from a local, a parameter, a call result, a local changed before and after),Vec::extendof an array,mem::replace,VecDeque::push_back/push_front/insert,HashMap::insert,entry().or_insert,BTreeMap::insert,Box::new, a non-Copyholder pushed, passed to a function that changes it, and returned.Vec::inserthas no mapping yet (it is refused), so it is not covered.Impact
Copyaggregate now copy it, for examplev.push(copy$u8_u8(pair))andrt.hashInsert(m, copy$Pair(key), ...). A value moved into a field, a local changed in place, or a kept call is no longer copied again.Decoder::newandEncoder::newnow copy theirforminto the struct they return (copy$Form). Theshaketest's kept set addscopy$Formfor the same reason.Codec bench (
quest gate nix develop .#bench --command just ts bench --route main=..., main at 62a8a59), Chrome:No change beyond the A/A noise. Bundle size: 30534 raw / 9801 gzip, against main's 30526 / 9798. An earlier run showed
btree/*14-30% slower on identical btree code. Both bundles are byte-identical there, and the rerun above matched main (73.3 vs 71.4, 117 vs 117, 273 vs 267), so that gap was noise.Alternatives
push,hashInsert, ...), asvec![x; n]andinto_vecdid. This is what the quest ruled out: every new mapping would have to remember to do it.Into::into,Ord::max,u32::from_be_bytes([..]), andOption::map_orarguments for nothing.holds_behindandstoresavoid that.Copyholder hole for a later quest. It is the same flaw in the same analysis, and fixing it costs two copies in moq-net, so it is fixed here.Follow-ups
Suggested, not recorded as quests (for
/quest-planto decide):Copytypes that nothing in the crate changes in place. A whole-crate scan for&mut T, field writes, andSetDiscriminantofTwould drop the newcopy$Formhere, fix(ts): copy Copy aggregates by type #83'sself.formcopy thatts-shared-readtargets, and map-key copies. It may subsumets-shared-read.&mutto a key. Only a key whose source changes later needs a copy.copy$Rank(rank(a, b))), since a translated callee may return a shared parameter. Knowing which functions return fresh values would drop this copy.Vec::inserthas no mapping.(written by Opus 5.5)
🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn