Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 113 additions & 62 deletions ts/fixtures/lang/expected/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,46 @@ export function repin(p: rt.Place<rt.Arc<rt.u8>>, 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.Place<rt.Arc<rt.u8>>): 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>): 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.Place<rt.Arc<rt.u8>>): 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>): 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>): rt.u8 {
const _4: rt.Mutex<rt.u8> = rt.mutexLock(p);
const _0: rt.u8 = _4.value;
rt.mutexUnlock(_4);
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>): rt.u8 {
const _4: rt.Mutex<rt.u8> = rt.mutexLock(p);
const _0: rt.u8 = _4.value;
rt.mutexUnlock(_4);
return _0;
}

export function lockedBy(n: rt.u8): rt.Mutex<rt.u8> {
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<rt.Arc<rt.u8>>, to: rt.u8): void {
const _3: rt.Arc<rt.u8> = new rt.Arc(to);
Expand Down Expand Up @@ -139,7 +179,7 @@ export function counts(out: rt.ByteVec, arcs: rt.Arc<rt.u8>[], items: rt.Arc<rt.
}

export function objects(data: rt.ByteSlice, out: rt.ByteVec): void {
let _511!: rt.Waker;
let _566!: rt.Waker;
const by: rt.u8 = unwrapOr$Option_u8(rt.byteSliceFirst(data), 5);
const one: rt.Arc<rt.u8> = new rt.Arc(by);
const two: rt.Arc<rt.u8> = new rt.Arc(rt.u8WrappingAdd(by, 1));
Expand Down Expand Up @@ -226,84 +266,94 @@ 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<rt.u8> = held;
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.u8> = 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)));
let owned: rt.Arc<rt.u8> = rt.arcClone(held);
const lent2: rt.Place<rt.Arc<rt.u8>> = rt.place(() => owned, (value7) => owned = value7);
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(lent2.v.strong & 0xff, lent2.v.value)));
const locked: rt.Mutex<rt.Arc<rt.u8>[]> = new rt.Mutex(v);
const _173: rt.Mutex<rt.Arc<rt.u8>[]> = rt.mutexLock(locked);
const taken3 = _173.value;
_173.value = [];
const _228: rt.Mutex<rt.Arc<rt.u8>[]> = rt.mutexLock(locked);
const taken3 = _228.value;
_228.value = [];
const taken: rt.Arc<rt.u8>[] = taken3;
rt.mutexUnlock(_173);
rt.mutexUnlock(_228);
counts(out, [one, two], taken);
const _184: rt.Arc<rt.u8>[] = [rt.arcClone(two)];
const _190: rt.Mutex<rt.Arc<rt.u8>[]> = rt.mutexLock(locked);
rt.dropAll(_190.value);
_190.value = _184;
rt.mutexUnlock(_190);
const _239: rt.Arc<rt.u8>[] = [rt.arcClone(two)];
const _245: rt.Mutex<rt.Arc<rt.u8>[]> = rt.mutexLock(locked);
rt.dropAll(_245.value);
_245.value = _239;
rt.mutexUnlock(_245);
rt.dropAll(taken);
const _195: rt.Arc<rt.u8>[] = [one, two];
const _203: rt.Mutex<rt.Arc<rt.u8>[]> = rt.mutexLock(locked);
counts(out, _195, _203.value);
rt.mutexUnlock(_203);
const _250: rt.Arc<rt.u8>[] = [one, two];
const _258: rt.Mutex<rt.Arc<rt.u8>[]> = rt.mutexLock(locked);
counts(out, _250, _258.value);
rt.mutexUnlock(_258);
const cell: rt.RefCell<rt.Arc<rt.u8>[]> = new rt.RefCell([rt.arcClone(one)]);
const _214: rt.RefCell<rt.Arc<rt.u8>[]> = rt.refCellBorrowMut(cell);
const taken4 = _214.value;
_214.value = [];
const _269: rt.RefCell<rt.Arc<rt.u8>[]> = rt.refCellBorrowMut(cell);
const taken4 = _269.value;
_269.value = [];
const taken2: rt.Arc<rt.u8>[] = taken4;
rt.refMutRelease(_214);
const _216: rt.Arc<rt.u8>[] = [rt.arcClone(two), rt.arcClone(two)];
const _224: rt.RefCell<rt.Arc<rt.u8>[]> = rt.refCellBorrowMut(cell);
rt.dropAll(_224.value);
_224.value = _216;
rt.refMutRelease(_224);
rt.refMutRelease(_269);
const _271: rt.Arc<rt.u8>[] = [rt.arcClone(two), rt.arcClone(two)];
const _279: rt.RefCell<rt.Arc<rt.u8>[]> = rt.refCellBorrowMut(cell);
rt.dropAll(_279.value);
_279.value = _271;
rt.refMutRelease(_279);
counts(out, [one, two], taken2);
const _235: rt.Arc<rt.u8>[] = [one, two];
const _243: rt.RefCell<rt.Arc<rt.u8>[]> = rt.refCellBorrow(cell);
counts(out, _235, _243.value);
rt.refRelease(_243);
const _290: rt.Arc<rt.u8>[] = [one, two];
const _298: rt.RefCell<rt.Arc<rt.u8>[]> = rt.refCellBorrow(cell);
counts(out, _290, _298.value);
rt.refRelease(_298);
const sets: rt.HashMap<rt.u8, rt.BTreeSet<rt.u8>> = rt.hashNew() as rt.HashMap<rt.u8, rt.BTreeSet<rt.u8>>;
const _249: rt.Iter<rt.u8> = rt.iterSlice(rt.byteSliceView(data));
const _248: rt.BTreeSet<rt.u8> = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet<rt.u8>, _249, true);
rt.hashInsert(sets, by, _248);
const _251: rt.BTreeSet<rt.u8> | 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.u8>, rt.iterSlice(_258), true))) & 0xff);
const _304: rt.Iter<rt.u8> = rt.iterSlice(rt.byteSliceView(data));
const _303: rt.BTreeSet<rt.u8> = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet<rt.u8>, _304, true);
rt.hashInsert(sets, by, _303);
const _306: rt.BTreeSet<rt.u8> | 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.u8>, rt.iterSlice(_313), true))) & 0xff);
}
const _265: Uint8Array = Uint8Array.of(by);
const _264: rt.BTreeSet<rt.u8> = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet<rt.u8>, rt.iterSlice(_265), true);
const _269: rt.u8 = rt.u8WrappingAdd(by, 1);
Object.assign(rt.entryOrInsertWith(rt.entry(sets, _269), (): rt.BTreeSet<rt.u8> => {
const _320: Uint8Array = Uint8Array.of(by);
const _319: rt.BTreeSet<rt.u8> = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet<rt.u8>, rt.iterSlice(_320), true);
const _324: rt.u8 = rt.u8WrappingAdd(by, 1);
Object.assign(rt.entryOrInsertWith(rt.entry(sets, _324), (): rt.BTreeSet<rt.u8> => {
return rt.btreeNew(rt.cmp) as rt.BTreeSet<rt.u8>;
}), _264);
}), _319);
const keys: [rt.u8, rt.u8][] = rt.iterToArray(rt.iterMap(rt.hashIter(sets), (_22: [rt.u8, rt.BTreeSet<rt.u8>]): [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 _335 of keys) {
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(_335[0], _335[1])));
}
const _290: rt.Arc<rt.u8>[] = [rt.arcClone(one)];
const w: Window.Window = new Window.Window(by, _290);
const _345: rt.Arc<rt.u8>[] = [rt.arcClone(one)];
const w: Window.Window = new Window.Window(by, _345);
const other: rt.Arc<rt.u8>[] = [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 _363: rt.u8 = rt.u8Rem(b4, 5);
if (_363 === 0) {
apply(w, b4);
continue;
}
if (_308 === 1) {
if (_363 === 1) {
rt.byteVecPush(out, park(w, b4));
continue;
}
if (_308 === 2) {
if (_363 === 2) {
swapAll(w.held, other);
continue;
}
if (_308 === 3) {
if (_363 === 3) {
refill(other, bytes, one, b4);
continue;
}
if (_308 === 4) {
if (_363 === 4) {
if (rt.u8Rem(b4, 2) === 0) {
const mine: rt.Arc<rt.u8>[] = swapIn(other, two);
counts(out, [one, two], mine);
Expand All @@ -314,8 +364,8 @@ export function objects(data: rt.ByteSlice, out: rt.ByteVec): void {
rt.dropAll(takeAll(w.held));
}
const pinnedAll: rt.Arc<rt.u8>[] = [rt.arcClone(two)];
for (const _341 of rt.byteSliceView(data)) {
rt.byteVecPush(out, repinAll(pinnedAll, one, _341) & 0xff);
for (const _396 of rt.byteSliceView(data)) {
rt.byteVecPush(out, repinAll(pinnedAll, one, _396) & 0xff);
}
counts(out, [one, two], pinnedAll);
rt.dropAll(pinnedAll);
Expand All @@ -327,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 _401: Uint8Array = Uint8Array.of(by);
const q: rt.VecDeque<rt.u8> = rt.dequeExtend(rt.dequeNew() as rt.VecDeque<rt.u8>, rt.iterSlice(_401));
const _456: Uint8Array = Uint8Array.of(by);
const q: rt.VecDeque<rt.u8> = rt.dequeExtend(rt.dequeNew() as rt.VecDeque<rt.u8>, rt.iterSlice(_456));
const map: rt.HashMap<rt.u8, rt.u8> = rt.hashNew() as rt.HashMap<rt.u8, rt.u8>;
for (const _405 of rt.byteSliceView(data)) {
rt.byteVecPush(out, requeue(q, map, _405) & 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));
Expand All @@ -345,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 _441: 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 _441;
return _496;
});
for (const x of rt.byteSliceView(data)) {
if (rt.u8Rem(x, 2) === 0) {
Expand All @@ -362,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<Wakes.Wakes>) => 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 _560 of rt.byteSliceView(data)) {
if (!(rt.u8Rem(_560, 2) === 0)) {
_566 = noop;
} else {
_511 = counting;
_566 = counting;
}
const old3: rt.Waker = rewake(rt.place(() => w2, (value5) => w2 = value5), _511);
const old3: rt.Waker = rewake(rt.place(() => w2, (value8) => w2 = value8), _566);
old3.wakeByRef();
w2.wakeByRef();
old3[Symbol.dispose]();
Expand All @@ -387,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]();
Expand Down
30 changes: 30 additions & 0 deletions ts/fixtures/lang/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ fn repin(p: &mut Pin<Arc<u8>>, 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: std::ops::Deref<Target = Pin<Arc<u8>>>>(p: P) -> u8 {
**p
}

/// What a pointer to an `Arc` reads, through its own `Deref` and then the `Arc`'s.
fn through_arc<P: std::ops::Deref<Target = Arc<u8>>>(p: P) -> u8 {
**p
}

/// What a pointer to a guard reads, through its own `Deref` and then the guard's.
fn through_mutex<P: std::ops::Deref<Target = Mutex<u8>>>(p: P) -> u8 {
*p.lock().unwrap()
}

fn locked_by(n: u8) -> Mutex<u8> {
Mutex::new(n.wrapping_add(3))
}

/// The `Arc` a pinned box holds, replaced through `Pin`'s `DerefMut`.
fn rebox(p: &mut Pin<Box<Arc<u8>>>, to: u8) {
**p = Arc::new(to);
Expand Down Expand Up @@ -183,6 +202,17 @@ pub fn objects(data: &[u8], out: &mut Vec<u8>) {
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)]);
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)));
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());
Expand Down
24 changes: 21 additions & 3 deletions ts/src/lower/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,29 @@ 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:
// 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.
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 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)) => 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),
Comment thread
kixelated marked this conversation as resolved.
Resolved
},
_ => return Err(args),
Expand Down