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 @@ -22,7 +22,8 @@ generic std gap is planned here even when moq never calls it.
- [Waiting: type-check in process with tsrs](/quest/m3/ts-tsrs.md) - rust2-ts checks bindings through tsrs instead of `tsc` once it is a stable library
- [Drop order in std's folds and iterators](/quest/m3/ts-drop-order.md) - the values that drop still refused in std's consumers, flattens, and collects drop as std's do
- [Fresh writes in a body generic over a type](/quest/m3/ts-fresh-type-params.md) - a whole write into fresh memory holding a type parameter's values fills it, as one generic over a length alone does
- [std's conversions of a reference](/quest/m3/ts-ref-conversions.md) - `to_owned`, `clone_from`, `binary_search`, `size_of_val`, `from_ref`/`from_mut`, and `AsRef`/`Borrow` as a slice translate
- [A slice of one value behind any &mut](/quest/m3/ts-slice-of-one.md) - `slice::from_mut` and `array::from_mut` of a `&mut u8`, or of an object no place names, translate
- [A slice's searches by a closure](/quest/m3/ts-binary-search-by.md) - `binary_search_by`, `binary_search_by_key`, and `partition_point` translate, probing as std's do
- [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
- [A deque's two slices](/quest/m3/ts-deque-slices.md) - `VecDeque::as_slices` and `{:?}` of a deque's `Iter`, `IterMut`, and `Drain` translate, split where std's are
Expand Down
16 changes: 16 additions & 0 deletions quest/m3/ts-binary-search-by.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# [XS] A slice's searches by a closure

## Goal

[rust2-ts](/ts/README.md) translates `slice::binary_search_by`, `binary_search_by_key`,
and `partition_point`, calling the closure on the elements std's search probes, in its
order, proven by a differential test against native Rust over runs of equal elements.

## Plan

Found writing [std's conversions of a reference](https://github.com/moq-dev/rust2/pull/386),
which maps `binary_search` to the runtime's `sliceBinarySearch`, std's probe sequence. The
others are std's same search by another comparison, so they can share it. They are refused
as "unsupported call" today.

Public API: the translator's output.
23 changes: 0 additions & 23 deletions quest/m3/ts-ref-conversions.md

This file was deleted.

21 changes: 21 additions & 0 deletions quest/m3/ts-slice-of-one.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# [S] A slice of one value behind any &mut

## Goal

[rust2-ts](/ts/README.md) translates `slice::from_mut` and `array::from_mut` of every
`&mut`, proven by a differential test against native Rust that writes the element whole,
reads it out with `mem::replace`, and writes it in place: a `&mut u8`, and a `&mut` to an
object, such as a struct or a `[u32; N]`, that names no place in the function, as a
parameter does.

## Plan

Found writing [std's conversions of a reference](https://github.com/moq-dev/rust2/pull/386):
both are refused. A `&mut [u8]` is an `rt.ByteSlice`, which can only view a `Uint8Array`,
not the `rt.Place` of one `u8`. A slice's element write replaces the slot, so a slice of
an object whose place is unknown can't make the caller's variable hold the new value, and
copying the write into the object instead makes `mem::replace` return the object it just
overwrote. Either needs translated code to write such a slice's element in place, or a
`&mut u8` to know the bytes it may point into.

Public API: the translator's output.
3 changes: 2 additions & 1 deletion ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,8 @@ they need.
whose length is a power of two. A `Vec`, `VecDeque`, and `BinaryHeap` hold what std
guarantees of their capacity: at least their length and what `with_capacity`,
`reserve`, and `reserve_exact` ask for, and std's exactly where its doubling fixes it,
as through pushes. One holds a capacity, as `cap`, only where `with_capacity`, `reserve`,
as through pushes. `clone_from` and `clone_into`, of which std guarantees only the
length, leave a clone's capacity, not the allocation std reuses. One holds a capacity, as `cap`, only where `with_capacity`, `reserve`,
`shrink_to`, a `clone`, or a `collect` or `extend` set it, so a push never reads or
writes one. Reading it doubles it while short of the length, from the least std's
`RawVec` allocates for the element size, which a run of pushes grows std's to. A
Expand Down
18 changes: 18 additions & 0 deletions ts/fixtures/lang/expected/conversions.Held.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Generated by rust2-ts. Do not edit.

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

/** Holds a value in a field. */
export class Held<T> {
value: T;

constructor(value: T) {
this.value = value;
}

[Symbol.dispose](): void {
rt.drop(this.value);
}
}

//# sourceMappingURL=conversions.Held.ts.map
54 changes: 54 additions & 0 deletions ts/fixtures/lang/expected/conversions.Logged.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { byte as conversions_byte, LOG as conversions_LOG } from "./conversions.ts";

/**
* Logs its id as it drops, and as it is cloned, the id with the high bit set: its clone's
* id is one more.
*/
export class Logged {
id: rt.u8;
log: rt.Arc<rt.RefCell<rt.ByteVec>>;

constructor(id: rt.u8, log: rt.Arc<rt.RefCell<rt.ByteVec>>) {
this.id = id;
this.log = log;
}

[Symbol.dispose](): void {
drop$ops_Drop(this);
this.log[Symbol.dispose]();
}
}

export function clone$Clone(self: Logged): Logged {
const _5: rt.RefCell<rt.ByteVec> = rt.refCellBorrowMut(self.log.value);
rt.byteVecPush(_5.value, 128 | self.id);
rt.refMutRelease(_5);
return new Logged(rt.u8WrappingAdd(self.id, 1), rt.arcClone(self.log));
}

export function drop$ops_Drop(self: Logged): void {
const _5: rt.RefCell<rt.ByteVec> = rt.refCellBorrowMut(self.log.value);
rt.byteVecPush(_5.value, self.id);
rt.refMutRelease(_5);
}

/** The value `data` makes from `at`. */
export function make$conversions_Value(data: rt.ByteSlice, at: rt.usize): Logged {
return new Logged(conversions_byte(data, at) & 127, ((a0: rt.Arc<rt.RefCell<rt.ByteVec>>): rt.Arc<rt.RefCell<rt.ByteVec>> => {
return rt.arcClone(a0);
})(conversions_LOG.get()));
}

/** Its bytes. */
export function put$conversions_Value(self: Logged, out: rt.ByteVec): void {
rt.byteVecPush(out, self.id);
rt.byteVecPush(out, 253);
const _10: rt.RefCell<rt.ByteVec> = rt.refCellBorrowMut(self.log.value);
rt.iterExtendBytes(out, rt.byteVecDrain(_10.value, undefined), "fold", true);
rt.refMutRelease(_10);
}

//# sourceMappingURL=conversions.Logged.ts.map
39 changes: 39 additions & 0 deletions ts/fixtures/lang/expected/conversions.Named.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { byte as conversions_byte, make$conversions_Value_String as conversions_make$conversions_Value_String, put$conversions_Value_String as conversions_put$conversions_Value_String } from "./conversions.ts";

export function clone$Clone(self: Named): Named {
return { id: self.id, name: self.name };
}

export function partialCmp$cmp_PartialOrd(self: Named, other: Named): rt.Ordering | undefined {
return cmp$cmp_Ord(self, other);
}

export function cmp$cmp_Ord(self: Named, other: Named): rt.Ordering {
const cmp: rt.Ordering = rt.cmp(self.id, other.id);
if (cmp === 0) {
return rt.cmpStr(self.name, other.name);
}
return cmp;
}

/** A struct, which JS holds as an object. */
export interface Named {
id: rt.u16;
name: string;
}

/** The value `data` makes from `at`. */
export function make$conversions_Value(data: rt.ByteSlice, at: rt.usize): Named {
return { id: rt.u8Rem(conversions_byte(data, at), 4) as rt.u16, name: conversions_make$conversions_Value_String(data, rt.usizeAdd(at, 1)) };
}

/** Its bytes. */
export function put$conversions_Value(self: Named, out: rt.ByteVec): void {
rt.iterExtendBytes(out, rt.iterSlice(rt.u16ToBeBytes(self.id)), undefined, true);
conversions_put$conversions_Value_String(self.name, out);
}

//# sourceMappingURL=conversions.Named.ts.map
Loading