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
3 changes: 2 additions & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ generic std gap is planned here even when moq never calls it.
- [References to byte arrays std takes](/quest/m3/ts-byte-refs-taken.md) - `extend` by references to arrays, adaptors' closures over held arrays, and a collection of both forms translate
- [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form
- [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does
- [Equality through a held type's own ne](/quest/m3/ts-eq-own-ne.md) - `==` of slices of a type whose `ne` the crate overrides, and `!=` of a tuple or `Arc` of one, translate
- [Equality of Cell and RefCell](/quest/m3/ts-eq-cells.md) - `==` and `!=` of `Cell`s and `RefCell`s translate
- [Cow of a slice, and Wrapping](/quest/m3/ts-cow-slices.md) - `Cow<[T]>` and `Wrapping<T>` translate, `PartialEq` included
- [std iterators' Debug](/quest/m3/ts-iter-debug.md) - `{:?}` of std's iterators translates, writing std's text, a deque's two slices included
- [LinkedList](/quest/m3/ts-linked-list.md) - `LinkedList` and its methods translate
- [A parameter read only where lowering leaves nothing](/quest/m3/ts-unread-params.md) - an instance whose lowering drops every read of a parameter marks it unused, so `tsc` accepts it
Expand Down
14 changes: 14 additions & 0 deletions quest/m3/ts-cow-slices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# [M] Cow of a slice, and Wrapping

## Goal

[rust2-ts](/ts/README.md) translates `Cow<[T]>` and `Wrapping<T>` and their std impls,
`PartialEq` included, proven by differential tests against native Rust.

## Plan

Found auditing std's `PartialEq` impls that forward `ne`: constructing a `Cow<[T]>`
refuses, as `Cow<str>` does not, and any `Wrapping` refuses as an unsupported type from
another crate. No consumer uses either yet; they are planned here as part of std. A
`Cow`'s and a `Wrapping`'s `ne` are `!eq`, though a `Cow<[T]>`'s `eq` still calls each
item's `ne`.
15 changes: 15 additions & 0 deletions quest/m3/ts-eq-cells.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# [S] Equality of Cell and RefCell

## Goal

[rust2-ts](/ts/README.md) translates `==` and `!=` of `Cell`s and `RefCell`s, proven by
differential tests against native Rust, a `RefCell` mutably borrowed while compared
included.

## Plan

Found auditing std's `PartialEq` impls that forward `ne`: both types translate, but
`<RefCell<u8> as PartialEq>::eq` and `<Cell<u8> as PartialEq>::eq` refuse as an
unsupported call. std's compare what they hold by `eq`, and their `ne` is `!eq`, even
where the held type overrides `ne`; a `RefCell`'s borrows each side and panics if either
is mutably borrowed.
16 changes: 0 additions & 16 deletions quest/m3/ts-eq-own-ne.md

This file was deleted.

7 changes: 4 additions & 3 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ other elements, order by their elements and then their length, and compare and h
whatever their form, so a map of `Vec<u8>` finds a `&[u8]` and one of `[u16; 2]` a `&[u16]`.
Slices, arrays, `Vec`s, and `VecDeque`s compare against each
other as std's do, by their lengths and then each pair of items in order, through the
items' own `PartialEq<U>`, and its `ne` where the crate overrides it. A collection's reference to a byte array it holds, as `keys`,
items' own `PartialEq<U>`, and its `ne` where the crate overrides it, which a tuple's and
an `Arc`'s `!=` call as well. A collection's reference to a byte array it holds, as `keys`,
`HashSet::get`, and `retain`'s closure get one, is an `rt.ByteSlice` of its bytes, as a
`&[u8; N]` is elsewhere; a `&mut` writes where the collection holds them. A `&mut` to a value a map holds that JS copies,
such as a number, from `get_mut` or the entry API, is an `rt.Place` whose `v` reads and
Expand Down Expand Up @@ -700,8 +701,8 @@ built natively for wasm32 and run beside its translation on the same inputs by
closures that log what each
adaptor reads, `Option`'s and `Result`'s combinators, with closures that log each call,
and std's collections, over keys whose own `Hash`, `Eq`, and `Ord`
disagree with JS's, sequences compared across forms and item types by an `eq` and `ne`
that disagree, `vec![x; n]` of types whose `Clone` counts its clones, `&mut`
disagree with JS's, sequences, tuples, and `Arc`s compared across forms and item types by an
`eq` and `ne` that disagree, `vec![x; n]` of types whose `Clone` counts its clones, `&mut`
to values JS copies, of locals, fields, elements, and a map's values, passed on,
returned, kept in a struct, and captured, a `Vec`'s edits and sorts, with closures
that log what each is called with, std's `Bound`, `Reverse`, and `NonZero`, and raw
Expand Down
6 changes: 5 additions & 1 deletion ts/fixtures/lang/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,8 @@ const unlikeEqs = [[], [5], [1, 2], [0, 7, 2, 9], [3, 3, 3, 3, 3, 3, 3, 3, 3]].f
Array.from({ length: 128 }, (_, kind) => Uint8Array.of(unlikeEqsOp, kind, ...bytes)),
);

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs];
/** `collections::own_nes` of the same positions, lengths, and items as `unlike_eqs`. */
const ownNesOp = op("collections::own_nes");
const ownNes = unlikeEqs.map((input) => Uint8Array.of(ownNesOp, ...input.subarray(1)));

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs, ...ownNes];
32 changes: 32 additions & 0 deletions ts/fixtures/lang/expected/collections.Picky.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";

export function clone$Clone(self: Picky): Picky {
return { _0: self._0, _1: self._1 };
}

/**
* An item whose `ne` sees the remainder by 3 where its `eq` sees it by 4, so what `==` and
* `!=` find tells which std calls. Each call adds to the log, in order.
*/
export interface Picky {
_0: rt.u16;
_1: rt.Cell<rt.u16>;
}

export function log(self: Picky, other: Picky, by: rt.u16): void {
rt.cellSet(self._1, rt.u16WrappingAdd(rt.u16WrappingMul(self._1.v, 31), self._0 ^ ((other._0 << 4) & 0xffff) ^ by));
}

export function eq$PartialEq(self: Picky, other: Picky): boolean {
log(self, other, 256);
return rt.u16Rem(self._0, 4) === rt.u16Rem(other._0, 4);
}

export function ne$PartialEq(self: Picky, other: Picky): boolean {
log(self, other, 512);
return rt.u16Rem(self._0, 3) !== rt.u16Rem(other._0, 3);
}

//# sourceMappingURL=collections.Picky.ts.map
Loading