From 624ff60bd87d3c2f417c8ba1d9327d7d4d3bda6f Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 12:50:39 -0700 Subject: [PATCH 1/4] test(ts): deref a pinned reference to an Arc and a reference to a pinned Arc Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/src/objects.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ts/fixtures/lang/src/objects.rs b/ts/fixtures/lang/src/objects.rs index 6461985e0..fb3d257ac 100644 --- a/ts/fixtures/lang/src/objects.rs +++ b/ts/fixtures/lang/src/objects.rs @@ -24,6 +24,11 @@ fn repin(p: &mut Pin>, to: u8) { *p = Pin::new(Arc::new(to)); } +/// What a pointer to a pinned `Arc` reads, through its own `Deref` and then the pin's. +fn through>>>(p: P) -> u8 { + **p +} + /// The `Arc` a pinned box holds, replaced through `Pin`'s `DerefMut`. fn rebox(p: &mut Pin>>, to: u8) { **p = Arc::new(to); @@ -183,6 +188,10 @@ pub fn objects(data: &[u8], out: &mut Vec) { let mut boxed = Box::pin(Arc::clone(&held)); rebox(&mut boxed, by.wrapping_add(9)); out.extend_from_slice(&[**boxed, Arc::strong_count(&held) as u8]); + // A pinned reference to an `Arc` lends the `Arc`, and a reference to a pinned `Arc` + // the pin, each through `Deref`. + let lent = Pin::new(&held); + out.extend_from_slice(&[Arc::strong_count(&*lent) as u8, **lent, through(&pinned)]); // Through a guard, taken and assigned. let locked = Mutex::new(v); let taken = std::mem::take(&mut *locked.lock().unwrap()); From 279719e993b795f8b2f7f9d56e8321f8cd982dc9 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 13:14:14 -0700 Subject: [PATCH 2/4] fix(ts): deref a reference to an Arc, a lock, or a pin as the reference Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/objects.ts | 149 ++++++++++++++++----------- ts/fixtures/lang/src/objects.rs | 15 +++ ts/src/lower/task.rs | 14 ++- 3 files changed, 113 insertions(+), 65 deletions(-) diff --git a/ts/fixtures/lang/expected/objects.ts b/ts/fixtures/lang/expected/objects.ts index ac2ee68cd..73c32dc07 100644 --- a/ts/fixtures/lang/expected/objects.ts +++ b/ts/fixtures/lang/expected/objects.ts @@ -23,6 +23,28 @@ export function repin(p: rt.Place>, to: rt.u8): void { p.v = _3; } +/** What a pointer to a pinned `Arc` reads, through its own `Deref` and then the pin's. */ +export function through$Pin_Arc_u8(p: rt.Arc): rt.u8 { + return p.value; +} + +/** What a pointer to an `Arc` reads, through its own `Deref` and then the `Arc`'s. */ +export function throughArc$Arc_u8(p: rt.Arc): rt.u8 { + return p.value; +} + +/** What a pointer to a guard reads, through its own `Deref` and then the guard's. */ +export function throughMutex$Mutex_u8(p: rt.Mutex): rt.u8 { + const _4: rt.Mutex = rt.mutexLock(p); + const _0: rt.u8 = _4.value; + rt.mutexUnlock(_4); + return _0; +} + +export function lockedBy(n: rt.u8): rt.Mutex { + return new rt.Mutex(rt.u8WrappingAdd(n, 3)); +} + /** The `Arc` a pinned box holds, replaced through `Pin`'s `DerefMut`. */ export function rebox(p: rt.Place>, to: rt.u8): void { const _3: rt.Arc = new rt.Arc(to); @@ -139,7 +161,7 @@ export function counts(out: rt.ByteVec, arcs: rt.Arc[], items: rt.Arc = new rt.Arc(by); const two: rt.Arc = new rt.Arc(rt.u8WrappingAdd(by, 1)); @@ -226,84 +248,87 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { const _156: rt.u8 = rt.u8WrappingAdd(by, 9); rebox(rt.place(() => boxed, (value4) => boxed = value4), _156); rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(boxed.value, held.strong & 0xff))); + const lent: rt.Arc = held; + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(lent.strong & 0xff, lent.value, through$Pin_Arc_u8(pinned)))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(throughArc$Arc_u8(held), throughMutex$Mutex_u8(lockedBy(by))))); const locked: rt.Mutex[]> = new rt.Mutex(v); - const _173: rt.Mutex[]> = rt.mutexLock(locked); - const taken3 = _173.value; - _173.value = []; + const _198: rt.Mutex[]> = rt.mutexLock(locked); + const taken3 = _198.value; + _198.value = []; const taken: rt.Arc[] = taken3; - rt.mutexUnlock(_173); + rt.mutexUnlock(_198); counts(out, [one, two], taken); - const _184: rt.Arc[] = [rt.arcClone(two)]; - const _190: rt.Mutex[]> = rt.mutexLock(locked); - rt.dropAll(_190.value); - _190.value = _184; - rt.mutexUnlock(_190); + const _209: rt.Arc[] = [rt.arcClone(two)]; + const _215: rt.Mutex[]> = rt.mutexLock(locked); + rt.dropAll(_215.value); + _215.value = _209; + rt.mutexUnlock(_215); rt.dropAll(taken); - const _195: rt.Arc[] = [one, two]; - const _203: rt.Mutex[]> = rt.mutexLock(locked); - counts(out, _195, _203.value); - rt.mutexUnlock(_203); + const _220: rt.Arc[] = [one, two]; + const _228: rt.Mutex[]> = rt.mutexLock(locked); + counts(out, _220, _228.value); + rt.mutexUnlock(_228); const cell: rt.RefCell[]> = new rt.RefCell([rt.arcClone(one)]); - const _214: rt.RefCell[]> = rt.refCellBorrowMut(cell); - const taken4 = _214.value; - _214.value = []; + const _239: rt.RefCell[]> = rt.refCellBorrowMut(cell); + const taken4 = _239.value; + _239.value = []; const taken2: rt.Arc[] = taken4; - rt.refMutRelease(_214); - const _216: rt.Arc[] = [rt.arcClone(two), rt.arcClone(two)]; - const _224: rt.RefCell[]> = rt.refCellBorrowMut(cell); - rt.dropAll(_224.value); - _224.value = _216; - rt.refMutRelease(_224); + rt.refMutRelease(_239); + const _241: rt.Arc[] = [rt.arcClone(two), rt.arcClone(two)]; + const _249: rt.RefCell[]> = rt.refCellBorrowMut(cell); + rt.dropAll(_249.value); + _249.value = _241; + rt.refMutRelease(_249); counts(out, [one, two], taken2); - const _235: rt.Arc[] = [one, two]; - const _243: rt.RefCell[]> = rt.refCellBorrow(cell); - counts(out, _235, _243.value); - rt.refRelease(_243); + const _260: rt.Arc[] = [one, two]; + const _268: rt.RefCell[]> = rt.refCellBorrow(cell); + counts(out, _260, _268.value); + rt.refRelease(_268); const sets: rt.HashMap> = rt.hashNew() as rt.HashMap>; - const _249: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); - const _248: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _249, true); - rt.hashInsert(sets, by, _248); - const _251: rt.BTreeSet | undefined = rt.hashGet(sets, by); - if (_251 !== undefined) { - const _258: Uint8Array = Uint8Array.of(rt.u8WrappingAdd(by, 1)); - rt.byteVecPush(out, rt.btreeLen(rt.replaceIn(_251, rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_258), true))) & 0xff); + const _274: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); + const _273: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _274, true); + rt.hashInsert(sets, by, _273); + const _276: rt.BTreeSet | undefined = rt.hashGet(sets, by); + if (_276 !== undefined) { + const _283: Uint8Array = Uint8Array.of(rt.u8WrappingAdd(by, 1)); + rt.byteVecPush(out, rt.btreeLen(rt.replaceIn(_276, rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_283), true))) & 0xff); } - const _265: Uint8Array = Uint8Array.of(by); - const _264: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_265), true); - const _269: rt.u8 = rt.u8WrappingAdd(by, 1); - Object.assign(rt.entryOrInsertWith(rt.entry(sets, _269), (): rt.BTreeSet => { + const _290: Uint8Array = Uint8Array.of(by); + const _289: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_290), true); + const _294: rt.u8 = rt.u8WrappingAdd(by, 1); + Object.assign(rt.entryOrInsertWith(rt.entry(sets, _294), (): rt.BTreeSet => { return rt.btreeNew(rt.cmp) as rt.BTreeSet; - }), _264); + }), _289); const keys: [rt.u8, rt.u8][] = rt.iterToArray(rt.iterMap(rt.hashIter(sets), (_22: [rt.u8, rt.BTreeSet]): [rt.u8, rt.u8] => { return [_22[0], rt.btreeLen(_22[1]) & 0xff] as [rt.u8, rt.u8]; })); rt.sliceSort(keys, rt.cmpLt(rt.cmpTuple([rt.cmp, rt.cmp]))); - for (const _280 of keys) { - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(_280[0], _280[1]))); + for (const _305 of keys) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(_305[0], _305[1]))); } - const _290: rt.Arc[] = [rt.arcClone(one)]; - const w: Window.Window = new Window.Window(by, _290); + const _315: rt.Arc[] = [rt.arcClone(one)]; + const w: Window.Window = new Window.Window(by, _315); const other: rt.Arc[] = [rt.arcClone(two), rt.arcClone(two)]; const bytes: rt.ByteVec = new rt.ByteVec(); for (const b4 of rt.byteSliceView(data)) { - const _308: rt.u8 = rt.u8Rem(b4, 5); - if (_308 === 0) { + const _333: rt.u8 = rt.u8Rem(b4, 5); + if (_333 === 0) { apply(w, b4); continue; } - if (_308 === 1) { + if (_333 === 1) { rt.byteVecPush(out, park(w, b4)); continue; } - if (_308 === 2) { + if (_333 === 2) { swapAll(w.held, other); continue; } - if (_308 === 3) { + if (_333 === 3) { refill(other, bytes, one, b4); continue; } - if (_308 === 4) { + if (_333 === 4) { if (rt.u8Rem(b4, 2) === 0) { const mine: rt.Arc[] = swapIn(other, two); counts(out, [one, two], mine); @@ -314,8 +339,8 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rt.dropAll(takeAll(w.held)); } const pinnedAll: rt.Arc[] = [rt.arcClone(two)]; - for (const _341 of rt.byteSliceView(data)) { - rt.byteVecPush(out, repinAll(pinnedAll, one, _341) & 0xff); + for (const _366 of rt.byteSliceView(data)) { + rt.byteVecPush(out, repinAll(pinnedAll, one, _366) & 0xff); } counts(out, [one, two], pinnedAll); rt.dropAll(pinnedAll); @@ -327,11 +352,11 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecExtendFromSlice(out, rt.byteVecSlice(bytes)); counts(out, [one, two], w.held); counts(out, [one, two], other); - const _401: Uint8Array = Uint8Array.of(by); - const q: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, rt.iterSlice(_401)); + const _426: Uint8Array = Uint8Array.of(by); + const q: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, rt.iterSlice(_426)); const map: rt.HashMap = rt.hashNew() as rt.HashMap; - for (const _405 of rt.byteSliceView(data)) { - rt.byteVecPush(out, requeue(q, map, _405) & 0xff); + for (const _430 of rt.byteSliceView(data)) { + rt.byteVecPush(out, requeue(q, map, _430) & 0xff); } rt.iterExtendBytes(out, rt.dequeIter(q)); rt.iterExtendBytes(out, rt.hashValues(map)); @@ -345,9 +370,9 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, two.weak & 0xff); const a: Window.Window = Window.withStart(Window.default$Default(), by); const b7: Window.Window = new Window.Window(rt.u8WrappingAdd(by, 2), [rt.arcClone(one)]); - const _441: rt.u16 = by as rt.u16; + const _466: rt.u16 = by as rt.u16; const array: rt.u16[] = Array.from({ length: 2 }, (): rt.u16 => { - return _441; + return _466; }); for (const x of rt.byteSliceView(data)) { if (rt.u8Rem(x, 2) === 0) { @@ -362,13 +387,13 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { const counting: rt.Waker = new rt.ArcWaker(rt.arcClone(wakes), Wakes.wake$Wake, (arc: rt.Arc) => arc[Symbol.dispose]()); const noop: rt.Waker = rt.NOOP_WAKER.clone(); let w2: rt.Waker = noop.clone(); - for (const _505 of rt.byteSliceView(data)) { - if (!(rt.u8Rem(_505, 2) === 0)) { - _511 = noop; + for (const _530 of rt.byteSliceView(data)) { + if (!(rt.u8Rem(_530, 2) === 0)) { + _536 = noop; } else { - _511 = counting; + _536 = counting; } - const old3: rt.Waker = rewake(rt.place(() => w2, (value5) => w2 = value5), _511); + const old3: rt.Waker = rewake(rt.place(() => w2, (value5) => w2 = value5), _536); old3.wakeByRef(); w2.wakeByRef(); old3[Symbol.dispose](); diff --git a/ts/fixtures/lang/src/objects.rs b/ts/fixtures/lang/src/objects.rs index fb3d257ac..1a2b0150c 100644 --- a/ts/fixtures/lang/src/objects.rs +++ b/ts/fixtures/lang/src/objects.rs @@ -29,6 +29,20 @@ fn through>>>(p: P) -> u8 { **p } +/// What a pointer to an `Arc` reads, through its own `Deref` and then the `Arc`'s. +fn through_arc>>(p: P) -> u8 { + **p +} + +/// What a pointer to a guard reads, through its own `Deref` and then the guard's. +fn through_mutex>>(p: P) -> u8 { + *p.lock().unwrap() +} + +fn locked_by(n: u8) -> Mutex { + Mutex::new(n.wrapping_add(3)) +} + /// The `Arc` a pinned box holds, replaced through `Pin`'s `DerefMut`. fn rebox(p: &mut Pin>>, to: u8) { **p = Arc::new(to); @@ -192,6 +206,7 @@ pub fn objects(data: &[u8], out: &mut Vec) { // the pin, each through `Deref`. let lent = Pin::new(&held); out.extend_from_slice(&[Arc::strong_count(&*lent) as u8, **lent, through(&pinned)]); + out.extend_from_slice(&[through_arc(&held), through_mutex(&locked_by(by))]); // Through a guard, taken and assigned. let locked = Mutex::new(v); let taken = std::mem::take(&mut *locked.lock().unwrap()); diff --git a/ts/src/lower/task.rs b/ts/src/lower/task.rs index bd3ec4465..75ddef70d 100644 --- a/ts/src/lower/task.rs +++ b/ts/src/lower/task.rs @@ -176,11 +176,19 @@ pub fn call<'tcx>( ("Clone", "clone") if self_std == Some(Std::Weak) => Expr::rt("weakClone", args), // A waker is the executor's, whose `clone` is its own. ("Clone", "clone") if self_std == Some(Std::Waker) => first(args).member("clone").call(vec![]), + // A reference to one of these is the object it points at, which its own `Deref` gives. + ("Deref", "deref") | ("DerefMut", "deref_mut") if self_ty.is_some_and(|t| t.is_ref()) => match self_std { + Some(Std::Arc | Std::Mutex | Std::MutexGuard | Std::Ref | Std::RefMut | Std::Pin) => first(args), + _ => return Err(args), + }, ("Deref", "deref") | ("DerefMut", "deref_mut") => match self_std { Some(Std::Arc | Std::Mutex | Std::MutexGuard | Std::Ref | Std::RefMut) => first(args).member("value"), - // A pinned `Arc` is the `Arc`, which holds its value. - Some(Std::Pin) => match self_ty.map(|t| t.peel_refs().kind()) { - Some(ty::Adt(_, pin)) if std_of(pin.type_at(0)) == Some(Std::Arc) => first(args).member("value"), + // A pinned `Arc` is the `Arc`, which holds its value; a pinned reference to one is + // the `Arc` itself. + Some(Std::Pin) => match self_ty.map(|t| t.kind()) { + Some(ty::Adt(_, pin)) if matches!(pin.type_at(0).kind(), ty::Adt(arc, _) if Std::of(tcx, arc.did()) == Some(Std::Arc)) => { + first(args).member("value") + } _ => first(args), }, _ => return Err(args), From 4be01fa738d15605b001f266f30d60289f1fe679 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 13:27:13 -0700 Subject: [PATCH 3/4] fix(ts): read a shared Deref of a place's &mut out of the place A `&mut` to an `Arc`, pinned or not, is an `rt.Place`, so `<&mut Arc as Deref>::deref` gives the `Arc` the place holds, while `DerefMut` lends the place on. Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/objects.ts | 154 +++++++++++++++------------ ts/fixtures/lang/src/objects.rs | 3 + ts/src/lower/task.rs | 18 +++- 3 files changed, 104 insertions(+), 71 deletions(-) diff --git a/ts/fixtures/lang/expected/objects.ts b/ts/fixtures/lang/expected/objects.ts index 73c32dc07..b3765599a 100644 --- a/ts/fixtures/lang/expected/objects.ts +++ b/ts/fixtures/lang/expected/objects.ts @@ -24,12 +24,22 @@ export function repin(p: rt.Place>, to: rt.u8): void { } /** What a pointer to a pinned `Arc` reads, through its own `Deref` and then the pin's. */ -export function through$Pin_Arc_u8(p: rt.Arc): rt.u8 { +export function through$Pin_Arc_u8(p: rt.Place>): rt.u8 { + return p.v.value; +} + +/** What a pointer to a pinned `Arc` reads, through its own `Deref` and then the pin's. */ +export function through$Pin_Arc_u8$2(p: rt.Arc): rt.u8 { return p.value; } /** What a pointer to an `Arc` reads, through its own `Deref` and then the `Arc`'s. */ -export function throughArc$Arc_u8(p: rt.Arc): rt.u8 { +export function throughArc$Arc_u8(p: rt.Place>): rt.u8 { + return p.v.value; +} + +/** What a pointer to an `Arc` reads, through its own `Deref` and then the `Arc`'s. */ +export function throughArc$Arc_u8$2(p: rt.Arc): rt.u8 { return p.value; } @@ -41,6 +51,14 @@ export function throughMutex$Mutex_u8(p: rt.Mutex): rt.u8 { return _0; } +/** What a pointer to a guard reads, through its own `Deref` and then the guard's. */ +export function throughMutex$Mutex_u8$2(p: rt.Mutex): rt.u8 { + const _4: rt.Mutex = rt.mutexLock(p); + const _0: rt.u8 = _4.value; + rt.mutexUnlock(_4); + return _0; +} + export function lockedBy(n: rt.u8): rt.Mutex { return new rt.Mutex(rt.u8WrappingAdd(n, 3)); } @@ -161,7 +179,7 @@ export function counts(out: rt.ByteVec, arcs: rt.Arc[], items: rt.Arc = new rt.Arc(by); const two: rt.Arc = new rt.Arc(rt.u8WrappingAdd(by, 1)); @@ -249,86 +267,90 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rebox(rt.place(() => boxed, (value4) => boxed = value4), _156); rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(boxed.value, held.strong & 0xff))); const lent: rt.Arc = held; - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(lent.strong & 0xff, lent.value, through$Pin_Arc_u8(pinned)))); - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(throughArc$Arc_u8(held), throughMutex$Mutex_u8(lockedBy(by))))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(lent.strong & 0xff, lent.value, through$Pin_Arc_u8$2(pinned)))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(throughArc$Arc_u8$2(held), throughMutex$Mutex_u8$2(lockedBy(by))))); + let _199: rt.Arc = rt.arcClone(held); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(throughArc$Arc_u8(rt.place(() => _199, (value5) => _199 = value5)), through$Pin_Arc_u8(rt.place(() => pinned, (value6) => pinned = value6))))); + _199[Symbol.dispose](); + rt.byteVecPush(out, throughMutex$Mutex_u8(lockedBy(by))); const locked: rt.Mutex[]> = new rt.Mutex(v); - const _198: rt.Mutex[]> = rt.mutexLock(locked); - const taken3 = _198.value; - _198.value = []; + const _212: rt.Mutex[]> = rt.mutexLock(locked); + const taken3 = _212.value; + _212.value = []; const taken: rt.Arc[] = taken3; - rt.mutexUnlock(_198); + rt.mutexUnlock(_212); counts(out, [one, two], taken); - const _209: rt.Arc[] = [rt.arcClone(two)]; - const _215: rt.Mutex[]> = rt.mutexLock(locked); - rt.dropAll(_215.value); - _215.value = _209; - rt.mutexUnlock(_215); + const _223: rt.Arc[] = [rt.arcClone(two)]; + const _229: rt.Mutex[]> = rt.mutexLock(locked); + rt.dropAll(_229.value); + _229.value = _223; + rt.mutexUnlock(_229); rt.dropAll(taken); - const _220: rt.Arc[] = [one, two]; - const _228: rt.Mutex[]> = rt.mutexLock(locked); - counts(out, _220, _228.value); - rt.mutexUnlock(_228); + const _234: rt.Arc[] = [one, two]; + const _242: rt.Mutex[]> = rt.mutexLock(locked); + counts(out, _234, _242.value); + rt.mutexUnlock(_242); const cell: rt.RefCell[]> = new rt.RefCell([rt.arcClone(one)]); - const _239: rt.RefCell[]> = rt.refCellBorrowMut(cell); - const taken4 = _239.value; - _239.value = []; + const _253: rt.RefCell[]> = rt.refCellBorrowMut(cell); + const taken4 = _253.value; + _253.value = []; const taken2: rt.Arc[] = taken4; - rt.refMutRelease(_239); - const _241: rt.Arc[] = [rt.arcClone(two), rt.arcClone(two)]; - const _249: rt.RefCell[]> = rt.refCellBorrowMut(cell); - rt.dropAll(_249.value); - _249.value = _241; - rt.refMutRelease(_249); + rt.refMutRelease(_253); + const _255: rt.Arc[] = [rt.arcClone(two), rt.arcClone(two)]; + const _263: rt.RefCell[]> = rt.refCellBorrowMut(cell); + rt.dropAll(_263.value); + _263.value = _255; + rt.refMutRelease(_263); counts(out, [one, two], taken2); - const _260: rt.Arc[] = [one, two]; - const _268: rt.RefCell[]> = rt.refCellBorrow(cell); - counts(out, _260, _268.value); - rt.refRelease(_268); + const _274: rt.Arc[] = [one, two]; + const _282: rt.RefCell[]> = rt.refCellBorrow(cell); + counts(out, _274, _282.value); + rt.refRelease(_282); const sets: rt.HashMap> = rt.hashNew() as rt.HashMap>; - const _274: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); - const _273: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _274, true); - rt.hashInsert(sets, by, _273); - const _276: rt.BTreeSet | undefined = rt.hashGet(sets, by); - if (_276 !== undefined) { - const _283: Uint8Array = Uint8Array.of(rt.u8WrappingAdd(by, 1)); - rt.byteVecPush(out, rt.btreeLen(rt.replaceIn(_276, rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_283), true))) & 0xff); + const _288: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); + const _287: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _288, true); + rt.hashInsert(sets, by, _287); + const _290: rt.BTreeSet | undefined = rt.hashGet(sets, by); + if (_290 !== undefined) { + const _297: Uint8Array = Uint8Array.of(rt.u8WrappingAdd(by, 1)); + rt.byteVecPush(out, rt.btreeLen(rt.replaceIn(_290, rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_297), true))) & 0xff); } - const _290: Uint8Array = Uint8Array.of(by); - const _289: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_290), true); - const _294: rt.u8 = rt.u8WrappingAdd(by, 1); - Object.assign(rt.entryOrInsertWith(rt.entry(sets, _294), (): rt.BTreeSet => { + const _304: Uint8Array = Uint8Array.of(by); + const _303: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_304), true); + const _308: rt.u8 = rt.u8WrappingAdd(by, 1); + Object.assign(rt.entryOrInsertWith(rt.entry(sets, _308), (): rt.BTreeSet => { return rt.btreeNew(rt.cmp) as rt.BTreeSet; - }), _289); + }), _303); const keys: [rt.u8, rt.u8][] = rt.iterToArray(rt.iterMap(rt.hashIter(sets), (_22: [rt.u8, rt.BTreeSet]): [rt.u8, rt.u8] => { return [_22[0], rt.btreeLen(_22[1]) & 0xff] as [rt.u8, rt.u8]; })); rt.sliceSort(keys, rt.cmpLt(rt.cmpTuple([rt.cmp, rt.cmp]))); - for (const _305 of keys) { - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(_305[0], _305[1]))); + for (const _319 of keys) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(_319[0], _319[1]))); } - const _315: rt.Arc[] = [rt.arcClone(one)]; - const w: Window.Window = new Window.Window(by, _315); + const _329: rt.Arc[] = [rt.arcClone(one)]; + const w: Window.Window = new Window.Window(by, _329); const other: rt.Arc[] = [rt.arcClone(two), rt.arcClone(two)]; const bytes: rt.ByteVec = new rt.ByteVec(); for (const b4 of rt.byteSliceView(data)) { - const _333: rt.u8 = rt.u8Rem(b4, 5); - if (_333 === 0) { + const _347: rt.u8 = rt.u8Rem(b4, 5); + if (_347 === 0) { apply(w, b4); continue; } - if (_333 === 1) { + if (_347 === 1) { rt.byteVecPush(out, park(w, b4)); continue; } - if (_333 === 2) { + if (_347 === 2) { swapAll(w.held, other); continue; } - if (_333 === 3) { + if (_347 === 3) { refill(other, bytes, one, b4); continue; } - if (_333 === 4) { + if (_347 === 4) { if (rt.u8Rem(b4, 2) === 0) { const mine: rt.Arc[] = swapIn(other, two); counts(out, [one, two], mine); @@ -339,8 +361,8 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rt.dropAll(takeAll(w.held)); } const pinnedAll: rt.Arc[] = [rt.arcClone(two)]; - for (const _366 of rt.byteSliceView(data)) { - rt.byteVecPush(out, repinAll(pinnedAll, one, _366) & 0xff); + for (const _380 of rt.byteSliceView(data)) { + rt.byteVecPush(out, repinAll(pinnedAll, one, _380) & 0xff); } counts(out, [one, two], pinnedAll); rt.dropAll(pinnedAll); @@ -352,11 +374,11 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecExtendFromSlice(out, rt.byteVecSlice(bytes)); counts(out, [one, two], w.held); counts(out, [one, two], other); - const _426: Uint8Array = Uint8Array.of(by); - const q: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, rt.iterSlice(_426)); + const _440: Uint8Array = Uint8Array.of(by); + const q: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, rt.iterSlice(_440)); const map: rt.HashMap = rt.hashNew() as rt.HashMap; - for (const _430 of rt.byteSliceView(data)) { - rt.byteVecPush(out, requeue(q, map, _430) & 0xff); + for (const _444 of rt.byteSliceView(data)) { + rt.byteVecPush(out, requeue(q, map, _444) & 0xff); } rt.iterExtendBytes(out, rt.dequeIter(q)); rt.iterExtendBytes(out, rt.hashValues(map)); @@ -370,9 +392,9 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, two.weak & 0xff); const a: Window.Window = Window.withStart(Window.default$Default(), by); const b7: Window.Window = new Window.Window(rt.u8WrappingAdd(by, 2), [rt.arcClone(one)]); - const _466: rt.u16 = by as rt.u16; + const _480: rt.u16 = by as rt.u16; const array: rt.u16[] = Array.from({ length: 2 }, (): rt.u16 => { - return _466; + return _480; }); for (const x of rt.byteSliceView(data)) { if (rt.u8Rem(x, 2) === 0) { @@ -387,13 +409,13 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { const counting: rt.Waker = new rt.ArcWaker(rt.arcClone(wakes), Wakes.wake$Wake, (arc: rt.Arc) => arc[Symbol.dispose]()); const noop: rt.Waker = rt.NOOP_WAKER.clone(); let w2: rt.Waker = noop.clone(); - for (const _530 of rt.byteSliceView(data)) { - if (!(rt.u8Rem(_530, 2) === 0)) { - _536 = noop; + for (const _544 of rt.byteSliceView(data)) { + if (!(rt.u8Rem(_544, 2) === 0)) { + _550 = noop; } else { - _536 = counting; + _550 = counting; } - const old3: rt.Waker = rewake(rt.place(() => w2, (value5) => w2 = value5), _536); + const old3: rt.Waker = rewake(rt.place(() => w2, (value7) => w2 = value7), _550); old3.wakeByRef(); w2.wakeByRef(); old3[Symbol.dispose](); diff --git a/ts/fixtures/lang/src/objects.rs b/ts/fixtures/lang/src/objects.rs index 1a2b0150c..7546f613d 100644 --- a/ts/fixtures/lang/src/objects.rs +++ b/ts/fixtures/lang/src/objects.rs @@ -207,6 +207,9 @@ pub fn objects(data: &[u8], out: &mut Vec) { let lent = Pin::new(&held); out.extend_from_slice(&[Arc::strong_count(&*lent) as u8, **lent, through(&pinned)]); out.extend_from_slice(&[through_arc(&held), through_mutex(&locked_by(by))]); + // A mutable reference to each, read through the shared `Deref`. + out.extend_from_slice(&[through_arc(&mut Arc::clone(&held)), through(&mut pinned)]); + out.push(through_mutex(&mut locked_by(by))); // Through a guard, taken and assigned. let locked = Mutex::new(v); let taken = std::mem::take(&mut *locked.lock().unwrap()); diff --git a/ts/src/lower/task.rs b/ts/src/lower/task.rs index 75ddef70d..3fddd69fd 100644 --- a/ts/src/lower/task.rs +++ b/ts/src/lower/task.rs @@ -176,11 +176,19 @@ pub fn call<'tcx>( ("Clone", "clone") if self_std == Some(Std::Weak) => Expr::rt("weakClone", args), // A waker is the executor's, whose `clone` is its own. ("Clone", "clone") if self_std == Some(Std::Waker) => first(args).member("clone").call(vec![]), - // A reference to one of these is the object it points at, which its own `Deref` gives. - ("Deref", "deref") | ("DerefMut", "deref_mut") if self_ty.is_some_and(|t| t.is_ref()) => match self_std { - Some(Std::Arc | Std::Mutex | Std::MutexGuard | Std::Ref | Std::RefMut | Std::Pin) => first(args), - _ => return Err(args), - }, + // A reference to one of these is the object it points at, which its own `Deref` gives: + // read out of a `&mut` that is an `rt.Place`, whose place `DerefMut` lends on. + ("Deref", "deref") | ("DerefMut", "deref_mut") if let Some(ty) = self_ty.filter(|t| t.is_ref()) => { + match self_std { + Some(Std::Arc | Std::Mutex | Std::MutexGuard | Std::Ref | Std::RefMut | Std::Pin) + if name == "deref" => + { + b.t.pointee_value(ty, first(args)) + } + Some(Std::Arc | Std::Mutex | Std::MutexGuard | Std::Ref | Std::RefMut | Std::Pin) => first(args), + _ => return Err(args), + } + } ("Deref", "deref") | ("DerefMut", "deref_mut") => match self_std { Some(Std::Arc | Std::Mutex | Std::MutexGuard | Std::Ref | Std::RefMut) => first(args).member("value"), // A pinned `Arc` is the `Arc`, which holds its value; a pinned reference to one is From 0ec35c23027c8a6046c426b563783e184ce1e851 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 29 Oct 2026 13:38:52 -0700 Subject: [PATCH 4/4] fix(ts): deref a pin's mutable reference as the reference does A pin is its pointer, so `Pin<&mut Arc>`'s shared `Deref` reads the `Arc` out of the `rt.Place` the reference is. Co-Authored-By: Claude Opus 5.5 --- ts/fixtures/lang/expected/objects.ts | 128 ++++++++++++++------------- ts/fixtures/lang/src/objects.rs | 3 + ts/src/lower/task.rs | 12 +-- 3 files changed, 76 insertions(+), 67 deletions(-) diff --git a/ts/fixtures/lang/expected/objects.ts b/ts/fixtures/lang/expected/objects.ts index b3765599a..2e8971509 100644 --- a/ts/fixtures/lang/expected/objects.ts +++ b/ts/fixtures/lang/expected/objects.ts @@ -179,7 +179,7 @@ export function counts(out: rt.ByteVec, arcs: rt.Arc[], items: rt.Arc = new rt.Arc(by); const two: rt.Arc = new rt.Arc(rt.u8WrappingAdd(by, 1)); @@ -273,84 +273,87 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(throughArc$Arc_u8(rt.place(() => _199, (value5) => _199 = value5)), through$Pin_Arc_u8(rt.place(() => pinned, (value6) => pinned = value6))))); _199[Symbol.dispose](); rt.byteVecPush(out, throughMutex$Mutex_u8(lockedBy(by))); + let owned: rt.Arc = rt.arcClone(held); + const lent2: rt.Place> = rt.place(() => owned, (value7) => owned = value7); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(lent2.v.strong & 0xff, lent2.v.value))); const locked: rt.Mutex[]> = new rt.Mutex(v); - const _212: rt.Mutex[]> = rt.mutexLock(locked); - const taken3 = _212.value; - _212.value = []; + const _228: rt.Mutex[]> = rt.mutexLock(locked); + const taken3 = _228.value; + _228.value = []; const taken: rt.Arc[] = taken3; - rt.mutexUnlock(_212); + rt.mutexUnlock(_228); counts(out, [one, two], taken); - const _223: rt.Arc[] = [rt.arcClone(two)]; - const _229: rt.Mutex[]> = rt.mutexLock(locked); - rt.dropAll(_229.value); - _229.value = _223; - rt.mutexUnlock(_229); + const _239: rt.Arc[] = [rt.arcClone(two)]; + const _245: rt.Mutex[]> = rt.mutexLock(locked); + rt.dropAll(_245.value); + _245.value = _239; + rt.mutexUnlock(_245); rt.dropAll(taken); - const _234: rt.Arc[] = [one, two]; - const _242: rt.Mutex[]> = rt.mutexLock(locked); - counts(out, _234, _242.value); - rt.mutexUnlock(_242); + const _250: rt.Arc[] = [one, two]; + const _258: rt.Mutex[]> = rt.mutexLock(locked); + counts(out, _250, _258.value); + rt.mutexUnlock(_258); const cell: rt.RefCell[]> = new rt.RefCell([rt.arcClone(one)]); - const _253: rt.RefCell[]> = rt.refCellBorrowMut(cell); - const taken4 = _253.value; - _253.value = []; + const _269: rt.RefCell[]> = rt.refCellBorrowMut(cell); + const taken4 = _269.value; + _269.value = []; const taken2: rt.Arc[] = taken4; - rt.refMutRelease(_253); - const _255: rt.Arc[] = [rt.arcClone(two), rt.arcClone(two)]; - const _263: rt.RefCell[]> = rt.refCellBorrowMut(cell); - rt.dropAll(_263.value); - _263.value = _255; - rt.refMutRelease(_263); + rt.refMutRelease(_269); + const _271: rt.Arc[] = [rt.arcClone(two), rt.arcClone(two)]; + const _279: rt.RefCell[]> = rt.refCellBorrowMut(cell); + rt.dropAll(_279.value); + _279.value = _271; + rt.refMutRelease(_279); counts(out, [one, two], taken2); - const _274: rt.Arc[] = [one, two]; - const _282: rt.RefCell[]> = rt.refCellBorrow(cell); - counts(out, _274, _282.value); - rt.refRelease(_282); + const _290: rt.Arc[] = [one, two]; + const _298: rt.RefCell[]> = rt.refCellBorrow(cell); + counts(out, _290, _298.value); + rt.refRelease(_298); const sets: rt.HashMap> = rt.hashNew() as rt.HashMap>; - const _288: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); - const _287: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _288, true); - rt.hashInsert(sets, by, _287); - const _290: rt.BTreeSet | undefined = rt.hashGet(sets, by); - if (_290 !== undefined) { - const _297: Uint8Array = Uint8Array.of(rt.u8WrappingAdd(by, 1)); - rt.byteVecPush(out, rt.btreeLen(rt.replaceIn(_290, rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_297), true))) & 0xff); + const _304: rt.Iter = rt.iterSlice(rt.byteSliceView(data)); + const _303: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _304, true); + rt.hashInsert(sets, by, _303); + const _306: rt.BTreeSet | undefined = rt.hashGet(sets, by); + if (_306 !== undefined) { + const _313: Uint8Array = Uint8Array.of(rt.u8WrappingAdd(by, 1)); + rt.byteVecPush(out, rt.btreeLen(rt.replaceIn(_306, rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_313), true))) & 0xff); } - const _304: Uint8Array = Uint8Array.of(by); - const _303: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_304), true); - const _308: rt.u8 = rt.u8WrappingAdd(by, 1); - Object.assign(rt.entryOrInsertWith(rt.entry(sets, _308), (): rt.BTreeSet => { + const _320: Uint8Array = Uint8Array.of(by); + const _319: rt.BTreeSet = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, rt.iterSlice(_320), true); + const _324: rt.u8 = rt.u8WrappingAdd(by, 1); + Object.assign(rt.entryOrInsertWith(rt.entry(sets, _324), (): rt.BTreeSet => { return rt.btreeNew(rt.cmp) as rt.BTreeSet; - }), _303); + }), _319); const keys: [rt.u8, rt.u8][] = rt.iterToArray(rt.iterMap(rt.hashIter(sets), (_22: [rt.u8, rt.BTreeSet]): [rt.u8, rt.u8] => { return [_22[0], rt.btreeLen(_22[1]) & 0xff] as [rt.u8, rt.u8]; })); rt.sliceSort(keys, rt.cmpLt(rt.cmpTuple([rt.cmp, rt.cmp]))); - for (const _319 of keys) { - rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(_319[0], _319[1]))); + for (const _335 of keys) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(_335[0], _335[1]))); } - const _329: rt.Arc[] = [rt.arcClone(one)]; - const w: Window.Window = new Window.Window(by, _329); + const _345: rt.Arc[] = [rt.arcClone(one)]; + const w: Window.Window = new Window.Window(by, _345); const other: rt.Arc[] = [rt.arcClone(two), rt.arcClone(two)]; const bytes: rt.ByteVec = new rt.ByteVec(); for (const b4 of rt.byteSliceView(data)) { - const _347: rt.u8 = rt.u8Rem(b4, 5); - if (_347 === 0) { + const _363: rt.u8 = rt.u8Rem(b4, 5); + if (_363 === 0) { apply(w, b4); continue; } - if (_347 === 1) { + if (_363 === 1) { rt.byteVecPush(out, park(w, b4)); continue; } - if (_347 === 2) { + if (_363 === 2) { swapAll(w.held, other); continue; } - if (_347 === 3) { + if (_363 === 3) { refill(other, bytes, one, b4); continue; } - if (_347 === 4) { + if (_363 === 4) { if (rt.u8Rem(b4, 2) === 0) { const mine: rt.Arc[] = swapIn(other, two); counts(out, [one, two], mine); @@ -361,8 +364,8 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rt.dropAll(takeAll(w.held)); } const pinnedAll: rt.Arc[] = [rt.arcClone(two)]; - for (const _380 of rt.byteSliceView(data)) { - rt.byteVecPush(out, repinAll(pinnedAll, one, _380) & 0xff); + for (const _396 of rt.byteSliceView(data)) { + rt.byteVecPush(out, repinAll(pinnedAll, one, _396) & 0xff); } counts(out, [one, two], pinnedAll); rt.dropAll(pinnedAll); @@ -374,11 +377,11 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecExtendFromSlice(out, rt.byteVecSlice(bytes)); counts(out, [one, two], w.held); counts(out, [one, two], other); - const _440: Uint8Array = Uint8Array.of(by); - const q: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, rt.iterSlice(_440)); + const _456: Uint8Array = Uint8Array.of(by); + const q: rt.VecDeque = rt.dequeExtend(rt.dequeNew() as rt.VecDeque, rt.iterSlice(_456)); const map: rt.HashMap = rt.hashNew() as rt.HashMap; - for (const _444 of rt.byteSliceView(data)) { - rt.byteVecPush(out, requeue(q, map, _444) & 0xff); + for (const _460 of rt.byteSliceView(data)) { + rt.byteVecPush(out, requeue(q, map, _460) & 0xff); } rt.iterExtendBytes(out, rt.dequeIter(q)); rt.iterExtendBytes(out, rt.hashValues(map)); @@ -392,9 +395,9 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, two.weak & 0xff); const a: Window.Window = Window.withStart(Window.default$Default(), by); const b7: Window.Window = new Window.Window(rt.u8WrappingAdd(by, 2), [rt.arcClone(one)]); - const _480: rt.u16 = by as rt.u16; + const _496: rt.u16 = by as rt.u16; const array: rt.u16[] = Array.from({ length: 2 }, (): rt.u16 => { - return _480; + return _496; }); for (const x of rt.byteSliceView(data)) { if (rt.u8Rem(x, 2) === 0) { @@ -409,13 +412,13 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { const counting: rt.Waker = new rt.ArcWaker(rt.arcClone(wakes), Wakes.wake$Wake, (arc: rt.Arc) => arc[Symbol.dispose]()); const noop: rt.Waker = rt.NOOP_WAKER.clone(); let w2: rt.Waker = noop.clone(); - for (const _544 of rt.byteSliceView(data)) { - if (!(rt.u8Rem(_544, 2) === 0)) { - _550 = noop; + for (const _560 of rt.byteSliceView(data)) { + if (!(rt.u8Rem(_560, 2) === 0)) { + _566 = noop; } else { - _550 = counting; + _566 = counting; } - const old3: rt.Waker = rewake(rt.place(() => w2, (value7) => w2 = value7), _550); + const old3: rt.Waker = rewake(rt.place(() => w2, (value8) => w2 = value8), _566); old3.wakeByRef(); w2.wakeByRef(); old3[Symbol.dispose](); @@ -434,6 +437,7 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void { rt.dropAll(taken2); rt.dropAll(cell.value); rt.dropAll(locked.value); + owned[Symbol.dispose](); boxed[Symbol.dispose](); held[Symbol.dispose](); pinned[Symbol.dispose](); diff --git a/ts/fixtures/lang/src/objects.rs b/ts/fixtures/lang/src/objects.rs index 7546f613d..7b274d8bb 100644 --- a/ts/fixtures/lang/src/objects.rs +++ b/ts/fixtures/lang/src/objects.rs @@ -210,6 +210,9 @@ pub fn objects(data: &[u8], out: &mut Vec) { // A mutable reference to each, read through the shared `Deref`. out.extend_from_slice(&[through_arc(&mut Arc::clone(&held)), through(&mut pinned)]); out.push(through_mutex(&mut locked_by(by))); + let mut owned = Arc::clone(&held); + let lent = Pin::new(&mut owned); + out.extend_from_slice(&[Arc::strong_count(&*lent) as u8, **lent]); // Through a guard, taken and assigned. let locked = Mutex::new(v); let taken = std::mem::take(&mut *locked.lock().unwrap()); diff --git a/ts/src/lower/task.rs b/ts/src/lower/task.rs index 3fddd69fd..61f98fc12 100644 --- a/ts/src/lower/task.rs +++ b/ts/src/lower/task.rs @@ -191,12 +191,14 @@ pub fn call<'tcx>( } ("Deref", "deref") | ("DerefMut", "deref_mut") => match self_std { Some(Std::Arc | Std::Mutex | Std::MutexGuard | Std::Ref | Std::RefMut) => first(args).member("value"), - // A pinned `Arc` is the `Arc`, which holds its value; a pinned reference to one is - // the `Arc` itself. + // A pin is its pointer, which derefs as it does: an `Arc` to the value it holds, and + // a reference to what it points at. Some(Std::Pin) => match self_ty.map(|t| t.kind()) { - Some(ty::Adt(_, pin)) if matches!(pin.type_at(0).kind(), ty::Adt(arc, _) if Std::of(tcx, arc.did()) == Some(Std::Arc)) => { - first(args).member("value") - } + Some(ty::Adt(_, pin)) => match pin.type_at(0).kind() { + ty::Adt(arc, _) if Std::of(tcx, arc.did()) == Some(Std::Arc) => first(args).member("value"), + ty::Ref(..) if name == "deref" => b.t.pointee_value(pin.type_at(0), first(args)), + _ => first(args), + }, _ => first(args), }, _ => return Err(args),