Repository navigation
feat(ts): compare Cells and RefCells by what they hold, and one-time cells by their Option - #324
Merged
Merged
Conversation
Quest-Claim: 1638f4ac3335476f
…cells by their Option Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…own Ord Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
kixelated
marked this pull request as ready for review
October 31, 2026 03:30
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.
Closes the quest quest/m3/ts-eq-cells.md.
Problem
Every comparison of std's cells was refused as an unsupported call, including
==/!=ofCellandRefCell(the quest), theirPartialOrd(partial_cmp,lt,le,gt,ge) andOrd::cmp, andPartialEqofOnceCellandOnceLock. Reproduced on a scratch crate: 18 refusals, one per operator, each with its span.Approach
Pinned std (nightly-2026-10-15):
core/src/cell.rs:349-394:Cellcomparesself.get()by the held type'seq,partial_cmp,lt/le/gt/ge, andcmp.core/src/cell.rs:1476-1540:RefCelldoes the same through*self.borrow()and*other.borrow(), so it panics with "RefCell already mutably borrowed" if either side is mutably borrowed.core/src/cell/once.rs:413andstd/src/sync/once_lock.rs:728: one-time cells compare theirget()asOptions.ne, soneis!eqeven where the held type overridesne.Changes:
cell_ofinlower/collections.rsnames what a cell compares by and the runtime wrapper that reads it.eq_fn,cmp_fn,test_fn,own_test, andstd_keyrecurse through it, so cells compose with tuples, slices,Options,Arcs, and B-tree keys.own_nestill stops at cells, so!=of a cell never takes feat(ts): compare through a held type's own ne, as std's slices, tuples, and Arcs do #316'snot_ne_fnpath. A slice inside a cell still compares its items by their ownne, as std's does.rt.cellBy(f)readsv(Cell,OnceCell,OnceLock).rt.refCellBy(f)borrowsa, thenb, throughrefCellBorrow, so it panics with wasm32's message, and releases them in reverse order.RwLocksharesStd::RefCellbut has no comparisons, so it is excluded by its diagnostic item.own_ordnow looks through cells. Without that, collecting drop-valued entries keyed by a cell of an ownOrdbypassed the existing refusal. This was reproduced (it lowered tort.btreeCollect) and is now covered by the reject fixture'sranked_cells.Tests:
collections::cell_eqsin the lang differential fixture, against native wasm32. It covers:Quirky, whosene,lt/le/gt/ge,partial_cmp(sometimesNone), andcmpeach disagree with the others and log every call.Cell/RefCellof it,Cell<u8>,Cell<Option<u8>>, andRefCell<String>.RefCellcompared with itself, including while shared-borrowed.RefCell<RefCell<_>>,RefCell<Cell<_>>,Option<Cell<_>>,OnceCell<RefCell<_>>), tuples, slices of cells, and cells of slices.Arc<RefCell<_>>, including its identity shortcut while mutably borrowed.Ord::max/min/clamp, andOnceCell/OnceLockempty or set.BTreeSet<Cell<u8>>andBTreeMap<RefCell<u8>, _>.kind: aRefCell(either side, or only a nested inner one) compared while mutably borrowed, which panics with wasm32's exact message.A mutation check (dropping
refCellBy's second borrow) produced 44 differences.Impact
Cell,RefCell,OnceCell, andOnceLocknow translate where they were refused. Cells are now accepted as B-tree keys.rt.cellByandrt.refCellBy. Nothing is breaking.Alternatives
a.v === b.vfor cells of primitives instead ofrt.cellBy(rt.same). I skipped it because no consumer needs it yet, and the wrapper composes uniformly.Follow-ups
CloneofCell/RefCellandRefCell::into_innerare still refused (hit while writing the fixture). Recorded in quest/m2/ts-shared.md, which this PR also corrects:OnceCell'sPartialEqis no longer refused.Review
quest review, Codex gpt-6.1-sol, medium effort.0f06f665: one finding (own_orddid not look through cell keys). Fixed in80b89d77, with a reject fixture case.27cf72d0(the fix plus a conflict-resolved merge of origin/main): no findings.just cipassed locally on27cf72d0.🤖 Generated with Claude Code
(written by Claude Opus 5.5)