Repository navigation
feat(ts): translate Rc, Weak, and Pin trait objects, and Rc and Arc from a box of one - #450
Merged
Merged
Conversation
…rom a box of one Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and refuse a Weak's upcast to dyn Any Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#400 covers the same bug (rust-lang/compiler-builtins#1353) with quest/m3/ts-fma-allowance.md. 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.
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
enabled auto-merge (squash)
November 2, 2026 21:13
|
codex / Codex land fixer note:
(written by codex / Codex) |
This was referenced Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A trait object of the crate's own trait,
dyn Any, ordyn Fntranslated behind&,&mut,Box, andArc, but std coerces to one behind more pointers, and these were refused:Pin<Box<dyn Trait>>and other pins, aWeak<T>unsized toWeak<dyn Trait>,Rc::fromandArc::fromof aBox<dyn Trait>, andRc<dyn Any>'sdowncast. The trait objects quest's goal names these pointers. moq builds none of them; this is std coverage the quest calls for.Approach
Pinis the pointer it holds, so an unsizing of aPin<P>unsizesP.Weak<T>unsized to aWeak<dyn Trait>isrt.weakDynof it: the same count, plus aviewthat makes thert.ArcDynas it upgrades. It cannot make the object as it unsizes, sinceRc::new_cyclic'sWeakunsizes before its value is there.Weak::clonekeeps the view. An upcast is the sameWeak.Arc::fromandRc::fromof aBox<T>, a trait object's included, are anrt.Arcof what the box is, which drops it with the last clone. A boxed byte array, held as its ownUint8Array, stays refused.Rc::downcastmaps asArc::downcastdoes. Of anArcmade from a box,rt.arcDowncastgives anrt.ArcDynof the value that shares the box's count.The reject fixture's
weak_objectcase now translates, so it is gone.Rc<RefCell<dyn Trait>>, a struct whose last field unsizes, stays refused and is a new quest.Tests:
dyns::pointersin the lang fixture's differential test against native wasm32 covers:Rc<dyn Named>and an upcast toRc<dyn Shape>, with counts.Weakunsized from anRc<Square>and from anArc<Noisy>: upgrades before and after the value drops,ptr_eqagainst a downgrade of the trait object,weak_count, and a clone.Weak<dyn Shape>made insideRc::new_cyclicand upgraded after.Pin<Box<dyn Shape>>, which drops what it holds at the end of its scope, andPin<&mut dyn Shape>.Rc::fromandArc::fromof boxes of the crate's shapes, a number, and an enum, with the drop order of clones.Rc::downcastof anRc<dyn Any>, including one made from aBox<dyn Any>, which shares its count until the clone drops.Arc::fromof aBox<dyn Any + Send + Sync>and its downcast.Rc<dyn Fn>, andArc::fromof aBox<dyn Fn>.With
rt.weakDynmaking the object as it unsizes instead of as it upgrades, the differential test fails (214 differences in 709,542 cases).Census at the moq pin, before → after: unchanged (959 / 227 / 139 for moq-net / model / kio), since moq builds none.
mul_addand #400Earlier, this PR's new case shifted one random input onto
floats::mul_adds, where wasm32'sfmamisrounds a near tie (rust-lang/compiler-builtins#1353). #400 has since landed with the allowance for it, and this branch has merged it.Impact
rt.Weakgains an optionalview. New runtime exportrt.weakDyn.rt.arcDowncasttakes a third argument, the function giving what the object holds.rtis the translation's own runtime.Alternatives
Weak's object as it unsizes, as anArc's is: rejected. It fails for aWeakunsized insideRc::new_cyclic, and the differential test catches it.Rc::from(Box<dyn Trait>)as anrt.ArcDynover a newrt.Arc: needs the value's own type, which a box of a trait object no longer names. Anrt.Arcof the object works for every call and drop.Follow-ups
quest/m3/ts-dyn-tail.md: a trait object in a struct's last field, such asRc<RefCell<dyn Trait>>.Arc<dyn Iterator>,dyn FusedIterator, and&mut dyn Debug, the quest's remaining items, wait on #437 landing.Review
mechanical fix by codex / Codex:
Merged base and regenerated the harness snapshot, preserving both sides; passed UPDATE_EXPECT=1 cargo test --locked --test fixtures lang -- --exact and cargo test --locked in ts/, plus tsc -p ts/runtime.(head f0f151f)mechanical fix by codex / Codex:
Merged base and combined both README changes without changing behavior; passed RUST2_TS_TOOLCHAIN=/nix/store/i222nr66l2r3xfahzfpp1m6mawvhxyl2-rust-default-1.101.0-nightly-2026-10-15 just ts test; same toolchain with just ts cargo fmt --all --check; tsc -p ts/runtime; git diff --cached --check.(head bc13b8c)mechanical fix by codex / Codex:
Merged base and regenerated reject snapshots and lang harness names; with the installed pinned nightly, just ts cargo build --locked and just ts test -- --skip stable_names passed; stable_names passed in just ts test; tsc -p ts/runtime passed.(head 44ef507)Codex
gpt-6.1-solat medium effort, viaquest review, round 2 on head246f079dea901fb0d193f8852963eced2a07af69: no findings. Round 3, on head2f7006d73e910ca33dbf67d4432a03b6a55e18ddafter merging origin/main (#439, #400, #443, #447, #418) and refreshing snapshots: no findings.Round 1 (head
412a002d) findings:Rc<dyn Any>made from a box gave distinct views, soRc::ptr_eqwasfalse: fixed.rt.arcDowncastkeeps one view per allocation, andarcRootunwraps everyArcDyn.dyns::pointerscovers it.Weak<dyn Trait>toWeak<dyn Any>skippedobject_of's check: fixed. It is refused with a span, pinned by the reject fixture'sweak_any_upcast.🤖 Generated with Claude Code