Repository navigation
feat(ts): translate a guard's downgrade, leak, and whole byte-array map - #402
Merged
Merged
Conversation
Quest-Claim: bf331826411f364e
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tovers # Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
November 1, 2026 22:08
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
kixelated
enabled auto-merge (squash)
November 1, 2026 22:32
This was referenced Nov 1, 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
rust2-ts refused three parts of std's guard API that #392 found:
RwLockWriteGuard::downgrade(stable since 1.92).Ref::leakandRefMut::leak, plusRefCell::undo_leak, which ends a leaked borrow.[u8; N], such asRefMut::map(cell.borrow_mut(), |q| q), refused with "a reference to an array of bytes it is generic over". This affected every guard'smap,filter_map, andtry_map(Ref,RefMut,MutexGuard, and theRwLockguards, mapped or not), not onlyRwLockWriteGuardandRefMut.Approach
rt.rwLockDowngradeturns the lock's one exclusive borrow into one shared borrow and returns the same guard. Atry_writein between getsWouldBlockand atry_readsucceeds, as on wasm32. Only an unmapped write guard hasdowngrade, so the guard is always the lock itself.Ref::leaklends the guard's value, andRefMut::leaklends it the wayget_mutdoes (anrt.Placewhere JS copies the value). Neither releases the borrow.RefCell::undo_leak(rt.refCellUndoLeak) clears the count and then lends likeget_mut.discardslistsleakanddowngrade, since each takes over its guard without dropping it.lend::planrefused a closure that takes a&[u8; N]std holds and also returns one. A guard's map already views each byte-array part its closure returns (task::guard_map), soplannow accepts these closures for guard maps. The closure is given anrt.ByteSliceof the guarded array, and the guard keeps aUint8Arrayview of the same bytes, so writes land in place. The guard-map key list moved intolibrary::maps_guard, whichdiscardsshares.locks::downgraded: a lock's state before and after the downgrade, while the downgraded read drops before or after another read, and after mapping a downgraded guard. Also whole-array maps throughRwLockWriteGuard,MappedRwLockWriteGuard,RwLockReadGuard, andMutexGuard.borrows::leaks: the borrow state after each leak, shared and exclusive, whole and mapped, and afterundo_leak. It covers writes through a leaked&mut, both to a number JS copies and to a value it doesn't, and whole writes. It also coversmap,filter_map,try_map, andleakover a whole[u8; N], and the panic from borrowing again while a leak holds the cell, with wasm32's message.rt.rwLockDowngradeleaves zero or two readers, orrt.refCellUndoLeakkeeps the count, these cases report differences.Impact
rt.rwLockDowngradeandrt.refCellUndoLeakare new runtime exports. These calls now translate where they were refused before. No config or CLI change. Nothing breaks, so noMIGRATE.mdentry.downgradecalls areArc/Weakones.ts/moq/model.toml): unchanged.just censuson this branch and on origin/main gives identical reports: model 222 refusals over 3631 function instances, moq-net 941, kio 110.Alternatives
guard_maplend the guarded byte array as anrt.ByteSliceitself, without going throughlend::plan. I rejected this becauseplanalready wraps the closure that way formap_split, so a second path would duplicate it.RefCell::undo_leakout. I included it because it ends whatleakstarts (samecell_leakfeature), and without it the tests could only show a leaked borrow by panicking.Follow-ups
Review
quest review --base origin/main.quest check.ts/src/lower/collections.rs:535: refuted. It was not part of this change: the branch predated feat(ts): translate hashbrown's HashMap, HashSet, and HashTable as std's maps, with std's capacity #398, so the diff showed feat(ts): translate hashbrown's HashMap, HashSet, and HashTable as std's maps, with std's capacity #398's changes reversed. Merged origin/main, after which the diff no longer touches that file.just cipassed at b296e69, with the lang differential and codec tests included.🤖 Generated with Claude Code