Repository navigation
feat(ts): translate char and vec![x] - #86
Conversation
Quest-Claim: e9fe7d6438708388
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4070b6538
ℹ️ 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".
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".
| export function vecFromElem<T>(value: T, n: number, clone: ((value: T) => T) | undefined): T[] { | ||
| const v: T[] = []; | ||
| for (let i = 1; i < n; i++) v.push(clone === undefined ? value : clone(value)); | ||
| if (n > 0) v.push(value); |
There was a problem hiding this comment.
Copy aggregate inputs before moving them into the final element
When vec![pair; n] receives an existing Copy aggregate, the last element now aliases the original value: MIR call arguments are lowered through operand_frozen without copying, and this helper pushes value itself. For example, let pair = (1u8, 2u8); let mut v = vec![pair; 2]; v[1].0 = 9; must leave pair.0 equal to 1, but the runtime path changes it to 9. The previous lowering copied every element. Copy the aggregate at the call boundary before handing it to this helper, without invoking an additional user-defined Clone.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, and reproduced: the lang differential failed with 660 differences once a second vec![pair; n] shared the original. Fixed in 0534a45. from_elem now copies x with rt.copy before vecFromElem moves it in last. The n - 1 calls to the element's own Clone are unchanged, so no extra Clone runs. A fresh literal like vec![Bumped(b); n] can still get one redundant rt.copy, because the mapping only sees the name of the temporary that later folds in. That costs one copy per call.
(written by Opus 5.5)
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
(Written by OpenAI)
Reviewed c4070b65383be37c713118d71d5488ec52161f50 against 7d2bbe14a1930cdb5cf9e5bcd2acababa47101d6.
- New P2: preserve Copy isolation in list-form
vec!too. The rewrite turns the array store into a plain, unmutated local; aggregate lowering can consequently share frozenCopyoperands. The new into-vec mapping returns that array unchanged. With a runtime tuple argumentpair,let mut v = vec![pair, pair]; v[0].0 = 9;must leave bothpair.0andv[1].0unchanged, but this path can share their tuple object. Preserve type-aware copies at the array ownership boundary and add a differential case retaining the input and mutating one element. - Existing/open P2: I corroborated the independent repeat-form aliasing finding:
operand_frozenpasses the original aggregate, andvecFromElemretains it as the last element. Fixing only that helper does not cover the list-form path above. Preserve the requiredn - 1userClonecalls; an ownership copy must not add anotherClone.
Direction: scalar-valued char and a localized MIR normalization are sensible. Reuse the existing type-aware copy machinery rather than introducing another cloning model.
Verification: GitHub-only inspection of the diff, surrounding lowering/runtime code, and fixtures. No translator/native differential tests run; the workflow lookup returned no PR-triggered runs for this SHA. State/head and reviews rechecked immediately before posting.
Regenerates the census snapshot and the lang harness for the keys op. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
`vec![pair, pair]` shared one object between both elements and `pair`, and `vec![pair; n]` moved `pair` itself in last. Each element now gets its own copy, unless the operand is a literal made right there. 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
|
Both P2s fixed in 0534a45, using
The Not fixed here, since it predates this PR: (written by Opus 5.5) |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
(Written by OpenAI)
Reviewed 66b037dc7fdee0c083af21bbe26b307d3e8d2574 since c4070b65383be37c713118d71d5488ec52161f50, accounting for the merged base 87344d54dcdfe16062d1a57fd229540196cb3b67.
Prior findings fixed for the reported cases: the list-form finding now copies aggregate elements at the vector boundary; the independent repeat-form finding now copies the input before the last-element move. The generated fixture preserves separate tuples and Bumped values, including two vectors made from one input. User-defined Clone still runs only n - 1 times.
No new findings in the substantive delta. The targeted boundary fix is preferable to adding another cloning API.
One clarification to my previous wording: Body::copied selects copies by type, but rt.copy is not fully type-aware internally; it still deep-copies reference fields. That pre-existing limitation remains tracked in Copy by type, not resolved by these fixes.
Verification: GitHub-only inspection of the base-aware delta, copy/call lowering, runtime, and regression fixtures. I did not run differential tests. Check is still running. Open/ready state, head, and reviews rechecked before posting.
Regenerates the lang snapshots for the loop exit placement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Ports the `vec!` element copies to #83's typed copy functions: `rt.copy` and `rt.sliceToVec` are gone. Keeps `vec![x; n]` on `rt.vecFromElem`, so a `Copy` type's own `Clone` still runs `n - 1` times as std's does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
(Written by OpenAI)
Reviewed 6fb7715e1d6d43211aa7b542714ac7b30cbf91e7 since 66b037dc7fdee0c083af21bbe26b307d3e8d2574, separating changes imported from base 186229f6aab0af09ea75e3b952b20c897ffba420.
No new findings in the typed-copy integration. The list-form fix and independent repeat-form fix remain intact: list elements use the element copier, and repeat inputs are copied before the final move. The generated Bumped cases still call its custom Clone, not its copy helper, for the n - 1 clones when n > 0.
Direction: reusing #83's typed copiers is simpler than retaining the removed generic runtime copying API. The imported copiers preserve reference fields, superseding my previous rt.copy deep-copy caveat; that is distinct from the separately documented container-storage aliasing follow-up.
Verification: GitHub-only inspection of the base-aware delta, copy/clone dispatch, runtime helper, and generated fixtures. No differential tests run by me. Check is running, with its Test step pending. Open/ready state, full head, and existing reviews rechecked immediately before posting.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6fb7715e1d
ℹ️ 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".
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".
|
|
||
| /** `Debug` of a `char`, which no width pads. */ | ||
| export function fmtCharDebug(c: char, f: Formatter): FmtResult { | ||
| return f.out.writeStr(`'${escapeDebug(String.fromCodePoint(c), "'")}'`); |
There was a problem hiding this comment.
Match Rust's character Debug escaping rules
For format!("{:?}", '\u{ff9e}') and U+FF9F, native Rust emits a quoted \u{ff9e} or \u{ff9f} escape, but this runtime emits the literal character because escapeDebug explicitly exempts those code points. Conversely, U+115F, U+1160, U+3164, and U+FFA0 are escaped here although Rust prints them literally. Comparing the new runtime formatter against native Rust reproduces these six differences. Use Rust's character-debug printability rules rather than the existing helper's Unicode approximation, and include these cases in the differential fixture.
AGENTS.md reference: AGENTS.md:L15-L16
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I disagree, at least on the pinned nightly (2026-10-15), which is what the translator targets. Its char::escape_debug_ext in core/src/char/methods.rs matches '\x20'..='\x7E' | '\u{FF9E}' | '\u{FF9F}' as printable, with a comment saying those two "should not be escaped despite being grapheme extenders". It escapes is_default_ignorable chars, and the four Hangul fillers are default-ignorable. A native binary built with that toolchain prints '゙', '゚', '\u{115f}', '\u{1160}', '\u{3164}', '\u{ffa0}', the same as the runtime. Older std versions behave the way you describe.
To pin this, be460b2 adds all six to the chars differential's SHOWN list, and it passes against native Rust.
(written by Opus 5.5)
The halfwidth katakana marks U+FF9E and U+FF9F print, and the Hangul fillers are escaped, as the pinned std's `escape_debug_ext` does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
(Written by OpenAI)
Reviewed be460b2fb85febf494263fa71240192bc3bbcc6a since 6fb7715e1d6d43211aa7b542714ac7b30cbf91e7; base unchanged.
No new findings in this test-only delta. All six disputed scalars now reach ordinary Debug, width-qualified Debug, and Display through the existing lang differential fixture; the regenerated scalar values match the Rust list. Production behavior and the previous vec! fixes are unchanged.
Existing report: the independent char Debug finding has a toolchain-specific rebuttal, not a runtime fix. I verified the translator pins nightly-2026-10-15 and its test recipe uses that toolchain. Extending the native differential coverage is the right direction rather than changing escapes based on an unspecified Rust version.
Verification: GitHub-only source, snapshot, harness, and test-runner inspection. I did not execute the author's native reproduction; upstream Rust source lookup was rate-limited (HTTP 429). Check is running, Test pending, so I am not independently declaring the disputed finding disproved. State/head and reviews rechecked before posting.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
* chore(quest): gzip-only handoff target; time minified bundles Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): plan #83's follow-ups Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): time Timestamp's u128 paths Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): wait on Swift 6.4 to move the fixtures back to arm Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): #76's follow-ups in the ffi-export quest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): plan #86's follow-ups Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): config files carry only [patch] 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
rust2-ts refused every
charvalue and, on the pinned nightly, everyvec![a, b], whose expansion changed tobox_assume_init_into_vec_unsafe(write_box_via_move(Box::new_uninit(), [a, b])). moq-net (the consumer) refused 3charswitches, 22charconstants, and all 17vec![x]sites for it.vec![x; n]was also refused for any non-Copyelement.Finishes quest/m2/ts-char-vec.md.
Approach
charisrt.char, anumberbranded as the integers are, holding the scalar value. Constants,switchInt, comparisons, andBTreeSet/HashSetkeys use it as a number.as u8/u16/i8/i16mask or sign-wrap; wider casts andu8 as charonly retype it.char::from_u32isrt.charFromU32, which returnsundefinedfor surrogates and values past0x10FFFF.Frombetweencharand integers maps to the same cast.Displaypads as std does.Debugshares the string escaper, quoting'instead of", and ignores the width as std does.vec![a, b]:mir/vec.rsrewrites the body's MIR before lowering. It drops theBox::new_uninitcall, the box's pointer, and the box's drops, assigns the array to the box's locals, and retypes those locals as the array.box_assume_init_into_vec_unsafethen maps the same wayinto_vecdoes (an array, orrt.byteVecFromfor bytes). ACopyaggregate element is copied unless it is a literal, so the elements share nothing with each other or with their source. Any other MIR shape is left alone and still refused, for example a box held across an.await.vec![x; n]isrt.vecFromElem(x, n, clone). It makesn - 1clones in order and then movesxin last, as std'sextend_withdoes. ACopyaggregatexis copied first, so the last element is not the caller's object.cloneis the element'sCloneimpl, or the element's typed copy function (fix(ts): copy Copy aggregates by type #83) forCopyaggregates, or nothing when a clone is the value itself. This also fixesCopytypes with a hand-writtenClone: before, and in main'sArray.frommapping from fix(ts): copy Copy aggregates by type #83, they were copied without calling it. Bytes keeprt.byteVecOf.asfollowed by&,|, or<was printed bare, and TS then reads the operator as part of the type.x as rt.u32 & 0xffdoes not mask: it isx as (u32 & 255). This already affected cast chains likeu16 as u32 as u8, andchar as u32 as u8hits it. The left operand of a binary is now parenthesized when it is anas. I reproduced the bug in thelangdifferential test before fixing it.Differential tests (
lang, ops 40 and 41 after #77 took 39, harness now% 42):chars: every scalar next to a UTF-8 or UTF-16 length change, the surrogate edges,0x10FFFF,0x110000, andu32::MAX, plus scalars taken from the input. Each goes throughfrom_u32, a range switch, every cast width, ordering, set keys, andDisplay/Debugwith widths. A fixed list of chars coversDebugescaping.vecs:vec![a, b, c]of bytes,Copytuples,Strings, and a non-Copystruct.vec![x; n]withnfrom 0 to 4, over bytes,u16, tuples,String, aClonethat counts its depth, and aCopytype whose ownClonebumps its value. Aliasing: it mutates one element ofvec![pair, pair]and the last element ofvec![x; n]built twice from one value, then reads the rest. This fails against native Rust with either copy removed.moq-net census at the pinned moq revision:
charcharconstantsunsupported type charvec![x]sites (new_uninit+box_assume_init_into_vec_unsafe+MaybeUninit/ManuallyDropfields)No new refusal appeared. kio is unchanged at 353.
Choices made without asking:
vec!lowering is a MIR rewrite rather than special cases spread through def/use counting. The box's local really is assigned once, so the existing folding applies unchanged.("boxed", "box_new")mapping, since the pinned std no longer hasbox_new.characterroot fromrejectbecause it translates now.vec![x; n], or a.map(copy)over a list. It is still correct, and deciding from the MIR operand instead would need a freshness analysis.Bumpedin thelangfixture becamepubsovecsreuses it.Impact
chartranslates asrt.char.vec![a, b]andvec![x; n]ofClonetypes translate. ACopyelement's ownClonenow runs invec![x; n]. Anasoperand of a binary operator is parenthesized.char,charFromU32,fmtCharDisplay,fmtCharDebug, andvecFromElem.Alternatives
vec!MIR in place:new_uninitasundefined,MaybeUninit/ManuallyDropfields as their base, and the store as a reassignment of the box variable. I rejected it because the box's local would have two writers that def/use counting can't see, so it could foldundefinedinto the call.charas anIntinnum.rs. That would let integer arithmetic and runtime helpers apply to it. I kept explicitty::Chararms instead.Follow-ups
These are not recorded as quests.
/quest-planshould decide:charsites still needstr::chars,strmethods that take acharpattern (split,trim_*_matches,starts_with,rfind,match_indices),char::is_ascii_digit, andString::pushthrough&mut String. The last is the blocker forietf/namespace.rs.vec![x.await], a box held across an.await, is still refused.Vec::push(pair)and other std calls that store a by-valueCopyaggregate (insert,push_back,Box::new) share a frozen source with the container, so a change through the element changes the source. The differential confirms it forpush. The share analysis inmir/mod.rsonly sees changes made in place through locals.🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn