Repository navigation
feat(ts)!: rs.Slice for references to arrays, comparing element places, and unsizing an Arc's array - #584
Merged
Conversation
Quest-Claim: 1a17e6ab1a077b31
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ding gaps Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/src/lower/mir/rvalue.rs # ts/src/lower/mod.rs # ts/src/lower/pointer.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… refuse array objects Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…argument in place Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comparing pointers to places JS may make two of for one stays refused rather than failing at run time; only pointers to arrays compare. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…f one Shared as_chunks and as_rchunks runs answer to their view of the slice, so pointers to them compare where they point. An array of one may be one JS made of its own for a value, as array::from_ref does, so comparing pointers to one is refused at translation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
November 4, 2026 20:17
|
This run was cancelled before it finished. |
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.

Part 2 of quest/m3/ts-slice-object.md, after #576.
Problem
A
&[T; N]or&mut [T; N]of values other than bytes was the JS array itself. So the run thatfirst_chunk_mut,split_first_chunk_mut, a subslice pattern, andarray::from_mutlend had to be anarrayViewProxyover the slice, and a shared one was a copy. That meant:Arc<[T; N]>couldn't unsize to anArc<[T]>, which feat(ts)!: rs.Slice for slices of values other than bytes #576 refused.Approach
A
&[T; N]is now anrs.Sliceof its elements where they are, as&[u8; N]already was anrs.ByteSlice.Pointee::Bytesis nowPointee::Array, and each byte-only path (bytes_ref,in_bytes, the lend boundary) covers any element type, pickingbyteSlice*orslice*by element.lend.rsconverts both ways withsliceFromandsliceItems/sliceView, as it did for bytes. It also now:filterovermap);Option::get_or_insert*to MIR lowering.&mut [T; N]writes each element in place (sliceSet).mem::replace/swap/takego throughreplaceIn(sliceView(..)), which keeps the copy depthsliceIn's arrays need.[T; N]compares by array and offset through any runs view (sliceSame). Comparing pointers to elements and other places of values JS copies stays refused at translation, as on main, since JS may make twors.Places for one place. Comparing pointers to a[T; 1]is refused too:array::from_ref,from_mutof a variable, andOption::as_slicemake an array of one of their own for a value, so only longer arrays are always where Rust's are. This also closes that gap for[u8; 1], which main compared. A sharedas_chunksoras_rchunkslends copies of its runs that answer to their view of the slice, so pointers to them compare where the run is.Arcunsizing. AnArc,Rc, orWeakof an array unsizes to its slice as anrs.ArcDynthat shares its count, as trait objects already do.ptr_eqof slices compares theArcs they were made from.clone_fn,array_copy).objectCopycopies the runs a view of runs holds. Before this, amem::replaceof a run of runs kept views that later writes changed.format_args!'s array is read through the slice that a reference to it now is. An argument read once is folded in place, so it allocates no array (["no case ", (f) => ...]rather than main'sargs2[0]).Removed: the reject fixture's three cases that now translate (array pointer comparison and both
Arc/Rcarray unsizes). Added: comparing pointers to an array of one is refused (pointers::array_of_one), and a trait object of an array of other values than bytes is refused, as a byte array's already was, because a box holds the array and a reference holds a slice of it.Impact
Consumer: moq.
just ts moqtranslates and type-checks, andjust ts bench(moq's codec, four engines) shows no measurable cost:Where single workloads moved beyond that, the A/A route moved as much (Bun
btree/2561.38 vs A/A 1.28, Chromiumpush/deque1.44 vs 1.48). The bundle grows by 927 B raw and 204 B gzipped. Measured before the review fixes: since then the element-place comparisons were dropped, and each sharedas_chunksrun gained a view tag.Public API:
&[T; N]or&mut [T; N]of values other than bytes, and a raw pointer to one, is now anrs.Slice<T>rather thanT[]. A hand-written caller or binding passes and reads slices (seefixtures/crates/bind/slots.ts).rs.Ptr<T>admits thers.Sliceof an array.sliceSame,sliceSet,sliceView,slicePlaces, andsliceToArray's optional element copy.[T; 1]is now refused,[u8; 1]included.[T; N]is now refused (it translated before for other values than bytes).arrayIn,arrayOfPlace,arrayPlaces,sliceFirstChunk(Mut),sliceSplitFirstChunk(Mut),sliceLastChunkMut, andsliceSplitLastChunkMut.arrayViewis no longer exported.sliceLastChunkandsliceSplitLastChunkreturn slices.Decisions
✅ Decided with the maintainer on 2026-11-04: generated code fails at run time only where Rust panics. A pointer comparison the translator can't answer exactly is refused at translation with a span, so this PR adds no runtime error. The exact slower path for the comparisons left refused is planned in
quest/m3/ts-runtime-throws.md(#598), not here.Follow-ups
These remain in the quest:
as_chunks_mut's runs still use theRuns/ByteRunsviews, because a slice of arrays holds each array as a JS array of its own.slice::from_mutof a&mut u8.*const [T].Review
lang::pointers::arrays: array pointers made by every lending path (subslices, chunks, windows, iterators, sharedas_chunksruns,Box,Option,Rc,RefCell,HashMap, fields, an unsizedArc), compared and written through, and a nestedptr::read.lang::shares::unsized_arrays:Rc/Arc/Weakof arrays unsized, counted, written, compared, and dropped by whichever owner is last.just ciandjust ts moqpassed locally on the merge with main at a392514.quest review(Codex) is clean after round 2 of this revision. Fixed along the way:ptr::readof nested arrays now copies them.Arc<[T; N]>toArc<dyn Trait>no longer takes the slice path. An array as a trait object is refused, as byte arrays already were.as_chunksruns compare where they point, and arrays of one are refused rather than compared wrong.🤖 Generated with Claude Code