Repository navigation
feat(ts): translate dyn bytes::Buf as an object of Buf's methods - #447
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
codex / Codex land fixer note:
(written by codex / Codex) |
Problem
moq's transports read a lease through
&mut dyn Buf(transport/boxed.rs), and itsErasedLeaseis the crate's own trait overBuf. Adyn Bufwas refused as "a trait object of another crate's trait", and the crate's own object overBuffailed onchunks_vectored'sIoSlice. The provided fixed-size getters (get_u16and up,try_get_*) of any buffer the mapping doesn't name, such as aTakeor the crate's own, failed inbytes' MIR on a slice-to-array pointer cast, so an object holding them could not translate either.Approach
Decided with the maintainer:
dyn bytes::Bufis an object ofBuf's methods, the shape the crate's own traits get, so it works for any implementor.dynamic.rsbuildsBuf's object as a translated crate's trait. It leaves outchunks_vectored, whoseIoSlicehas no JS value, so a call of it through the object fails loud as "not a method ofdyn Buf".get_andtry_get_of an integer of 2 to 16 bytes map to the newrt.bufGetandrt.bufTryGetover the buffer's ownremaining,chunk,advance, andcopy_to_slice. They read the chunk where it holds the integer and copy it out where not, asbytes'buf_get_impl!does, callingremainingas many times.try_get_of the mapped buffers maps the same way, since its MIR hit the same cast.Tests:
buf::dynsin the stock fixture's differential test against native wasm32 reads every getter, thetry_get_*errors, andcopy_to_bytesthrough a&mut dyn Bufof aBytes, aBytesMut, a&[u8], the crate's own buffer with and without its owncopy_to_bytes, and aTake<Bytes>. It also reads each through the&mutforwarding impl over the object (moq'spoll_write_buf(&mut dyn Buf)path) and through aBox<dyn Buf>that drops what it owns once. ABox<dyn Leased>covers the crate's own trait overBuf, as moq'sErasedLeaseis.buf::readsnow runs every getter on the crate's own buffers and on aTake.Census at the moq pin, before → after:
moq-net loses its 5
IoSlicerefusals and the getters' casts ("reads the bytes of one type as another" 77 → 29, "a raw pointer behind a reference" 64 → 16). No construct gained refusals. Its trait-object count stays 9, thedyn Iteratoranddyn Errorin #437 and #442.Impact
dyn Buftranslates instead of failing. New runtime exportsrt.bufGetandrt.bufTryGet.Alternatives
dyn Bufas thert.ByteSliceit reads, the quest's earlier plan: rejected by the maintainer, since it holds for no buffer in pieces, such as aChainor moq's leases.bytes' getters from MIR by supporting the slice-to-array pointer cast: that is byte reinterpretation, the unsafe quest's.Follow-ups
New m3 quests:
ts-buf-chain: aChaincoerced todyn Bufstays refused, since itscopy_to_bytesputs&mut Ainto a freshBytesMut, an existing refusal. moq passes noChain.ts-dyn-buf-size: an object holds every vtable entry, so each buffer coerced adds about 70 functions translated frombytes' MIR (about 4,500 lines in the stock fixture'sbuf_impl.ts).ts-by-ref-place,ts-take-value, andts-refcell-debug: existing refusals met writing feat(ts): translate dyn Iterator and its subtraits as an rt.Iter #437's and feat(ts): translate a Box, Arc, or Rc of dyn Debug or dyn Display #445's fixtures, unrelated todyn.quest/m3/ts-dyn.mdnow namesArc<dyn Iterator>,dyn FusedIterator, and&mut dyn Debug, and dropsdyn Buf. It will conflict with #437, #442, and #445, whichever lands second: keep every removal.Review
mechanical fix by codex / Codex:
Merged base, reconciled trait-object documentation, and regenerated Counted import aliases; validated in ts/: cargo build --locked -p rust2-ts; cargo test --locked (11 fixture tests passed; stale stock snapshot fi·xed and rerun with cargo test --locked --test fixtures stock -- --exact); cargo test --locked --test runtime; cargo clippy --locked --all-targets -- -D warnings; cargo fmt --all --check; cargo shear; cargo sort --workspace --check --no-format; tsc -p runtime.(head af01e4c)Codex
gpt-6.1-solat medium effort, viaquest review, round 2 on headc2d5c914bc1e6707c381d4e5a505c2e8e86f5198: no findings.Round 1 (head
7e4f92b6) reported one finding, refuted: field normalization atts/src/lower/mod.rs:1799, a line from #424, which landed on main during the round, outside this branch's diff. It is not verified here.🤖 Generated with Claude Code