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
1 change: 0 additions & 1 deletion quest/m3/ts-unsafe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,4 @@ Public API: the translator's output.
- [Unchecked integer operations](/quest/m3/ts-unsafe/unchecked-ops.md) - `unchecked_*` and `NonZero::new_unchecked` translate, aborting on a violated precondition
- [NonZero's unchecked arithmetic](/quest/m3/ts-unsafe/nonzero-unchecked-ops.md) - `NonZero::unchecked_add` and `unchecked_mul` translate, aborting at std's site
- [UnsafeCell's raw accessors](/quest/m3/ts-unsafe/unsafecell.md) - `UnsafeCell::raw_get`, `from_mut`, and `replace` translate
- [A Box of one uninitialized value](/quest/m3/ts-unsafe/box-new-uninit.md) - `Box::new_uninit` and `new_zeroed` for one value translate, through `write` and `assume_init`
- [A byte local whose address is taken, in a buffer of its own](/quest/m3/ts-unsafe/lone-byte-buffers.md) - raw and mutable slices of a `u8` local, and casts of them to byte arrays, translate instead of being refused
20 changes: 0 additions & 20 deletions quest/m3/ts-unsafe/box-new-uninit.md

This file was deleted.

2 changes: 1 addition & 1 deletion ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| `Cow<[T]>`, `Cow<str>` | `rs.Cow<T>`: the `Vec` it owns, or an `rs.Borrowed` holding the slice it borrows; `rs.ByteCow` for bytes, an `rs.ByteVec` or an `rs.ByteSlice`; `rs.StrCow` for text, the `rs.String` it owns or an `rs.Borrowed` holding the string it borrows, whose text `rs.strCowStr` reads |
| `&T`, `&mut T`, `Box<T>`, `Reverse<T>`, `NonZero<T>`, `AssertUnwindSafe<T>` | the value; a `&mut` to a value JS copies, such as a number, an `Option`, or a reference, or to an `Arc`, a `Waker`, or a `LocalKey`, whose copies share what it points at, is an `rs.Place<T>`, which for what a box holds is the place holding the box |
| `*const T`, `*mut T`, `NonNull<T>` | what a `&mut T` is: the object, an `rs.Slice` of a `[T; N]`'s elements or an `rs.ByteSlice` of a `[u8; N]`'s bytes, which compares by the array or buffer and offset they are at, refused for an array of one, which `array::from_ref`, `from_mut` of a variable, and `Option::as_slice` make of their own, or an `rs.Place<T>` to a value JS copies and to a library type such as a `Vec` or an `Arc`, which into an array, slice, or `Vec` is the `rs.AtIndex` of its element, which `add`, `sub`, `offset`, their wrapping forms, `offset_from`, `ptr::copy`, and `slice::from_raw_parts` move, measure, copy between, and view; one to a value in no array is element 0 of an array of one, as in Rust; JS keeps that array, and a shared subslice, which JS copies, apart from what holds it in Rust, so a pointer, slice, or copy the body shows reaching past either, a raw or mutable slice of a byte in no array, and `offset_from` between pointers the body shows JS keeps in different arrays are refused, and through a pointer from elsewhere, such as a field, any of these, or a read or write past the array JS keeps it in but for a `Vec`'s room up to its capacity, fails at run time; a pointer into an array of values JS keeps as objects is refused, as is comparing pointers to other values JS copies, each a place JS makes of its own; `rs.NULL` for null and `rs.DANGLING` for dangling. A pointer to a slice cast to one to an array of its elements is the `rs.Slice` or `rs.ByteSlice` of that many from its first, read through only where Rust reads. A `*const ()` is an identity, such as a waker's data, and `rs.DANGLING_UNIT` when dangling; one to a place of `()` or from a reference to one is refused. A pointer to a value JS keeps as an object cast to one, by `as` or `cast`, is the same object, which `rs.ptrErase` notes the type of, so a cast back to a pointer to another type fails at run time, and null and dangling stay so, dangling at the alignment of the type it was cast from; one to a value JS copies is the same place where an `Arc`'s or `Rc`'s `into_raw` or `as_ptr` gave it, its value's one place, which `rs.arcErase` checks where the body doesn't show it, and refused where the body shows a borrow's, a new place each borrow, as is casting one to a view of bytes, a new one each borrow, or one of no fixed size. A write of a whole object copies into it one object deep, as an assignment through a `&mut` does, the state an `rs` class such as `rs.LazyCell` keeps private included, so a pointer to a part kept as an object, such as a field of a tuple or struct type, is refused wherever the crate may put another object there while a pointer into that memory may still be read, which a write into a fresh allocation, or a variable before any pointer into it is taken, can't, whether by index or through std's iterators over its slots; a read copies what the crate writes into in place |
| `MaybeUninit<T>` | `T`: `undefined` until written, `0` for a byte, or an object whose parts kept as objects are there, holding `undefined`, as each of `Box::new_uninit_slice`'s is; a slice's `write_clone_of_slice` clones into its slots without dropping what they held |
| `MaybeUninit<T>` | `T`: `undefined` until written, `0` for a byte, or an object whose parts kept as objects are there, holding `undefined`, as `Box::new_uninit` and each of `Box::new_uninit_slice`'s is; a slice's `write_clone_of_slice` clones into its slots without dropping what they held. `Box::new_zeroed`'s holds the value of zero bytes in each part they are one of, such as a number, `false`, `None`, a null pointer, or an enum's variant of a tag or niche of zero, and `undefined` in each part they are none of, such as a reference, for a write to fill before a read |
| `ManuallyDrop<T>` | `T`, which nothing drops but its own `drop`; its `Debug`, comparisons, and constants are refused |
| `union` | an object of slots named by offset, `at0` and `at8`, each holding the field part kept there; fields must overlap in the same type, or in a non-null pointer and an `Option` of it |
| an iterator | `rs.Iter<Item>`, whose adaptors are runtime functions: `rs.iterMap(rs.iterSlice(v), f)` |
Expand Down
7 changes: 7 additions & 0 deletions ts/fixtures/lang/manual/expected/core/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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

export function unwrapOr$1fr498u(self: rs.u8 | undefined, default_: rs.u8): rs.u8 {
if (self === undefined) {
return default_;
}
return self;
}

export function map$1yjmt5m(self: rs.u8 | undefined, f: (a0: rs.u8) => rs.u8): rs.u8 | undefined {
if (self === undefined) {
return undefined;
Expand Down
14 changes: 13 additions & 1 deletion ts/fixtures/lang/manual/expected/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

import * as rs from "./rs.ts";
import { arcs, needsDrops } from "./manual.ts";
import { uninits, boxedUninits } from "./uninit.ts";
import { uninits, boxedUninits, boxedOne, boxedZeroed } from "./uninit.ts";

export function copy$array_array2_u16(v: rs.u16[][]): rs.u16[][] {
return v.map(copy$array_u16);
}

export function copy$array_u16(v: rs.u16[]): rs.u16[] {
return v.slice();
}

export function copy$array_u8(v: Uint8Array): Uint8Array {
return v.slice();
Expand Down Expand Up @@ -32,6 +40,10 @@ export function cases(): rs.Vec<[string, (a0: rs.u8, a1: rs.ByteSlice, a2: rs.By
uninits(data3, out3);
}] as [string, (a0: rs.u8, a1: rs.ByteSlice, a2: rs.ByteVec) => undefined], ["uninit::boxed_uninits", (_25: rs.u8, data4: rs.ByteSlice, out4: rs.ByteVec): undefined => {
boxedUninits(data4, out4);
}] as [string, (a0: rs.u8, a1: rs.ByteSlice, a2: rs.ByteVec) => undefined], ["uninit::boxed_one", (_26: rs.u8, data5: rs.ByteSlice, out5: rs.ByteVec): undefined => {
boxedOne(data5, out5);
}] as [string, (a0: rs.u8, a1: rs.ByteSlice, a2: rs.ByteVec) => undefined], ["uninit::boxed_zeroed", (_27: rs.u8, data6: rs.ByteSlice, out6: rs.ByteVec): undefined => {
boxedZeroed(data6, out6);
}] as [string, (a0: rs.u8, a1: rs.ByteSlice, a2: rs.ByteVec) => undefined]]);
}

Expand Down
11 changes: 11 additions & 0 deletions ts/fixtures/lang/manual/expected/uninit.Held.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Generated by rust2-ts. Do not edit.

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

/**
* An enum whose variant of zero bytes may hold a reference, which zero bytes are no
* value of.
*/
export type Held = { tag: "Lent"; _0: rs.u8; _1: rs.u16 } | { tag: "Count"; _0: rs.u32 };

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

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

/** A struct written field by field through a pointer to it. */
export interface Pair {
tag: rs.u8;
name: rs.String;
}

//# sourceMappingURL=uninit.Pair.ts.map
10 changes: 10 additions & 0 deletions ts/fixtures/lang/manual/expected/uninit.Tag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Generated by rust2-ts. Do not edit.

export function eq$cmp_PartialEq(self: Tag, other: Tag): boolean {
return { One: 1, Zero: 0 }[self] === { One: 1, Zero: 0 }[other];
}

/** One of `Tag`'s variants is zero bytes, though not its first. */
export type Tag = "One" | "Zero";

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

import * as rs from "./rs.ts";
import type * as Tag from "./uninit.Tag.ts";

/**
* Every part zero bytes are a value of, a value that counts its drops through one it may
* not hold, and an array whose length is past what an array literal would spell.
*/
export class Zeroed {
n: rs.u32;
on: boolean;
c: rs.char;
f: rs.f64;
wide: rs.u64;
signed: rs.i128;
words: rs.u16[];
many: rs.u32[];
pair: [rs.u8, rs.i64];
tag: Tag.Tag;
maybe: Tag.Tag | undefined;
p: rs.Place<rs.u8>;
seen: rs.Cell<[rs.u8, rs.u8]> | undefined;

constructor(n: rs.u32, on: boolean, c: rs.char, f: rs.f64, wide: rs.u64, signed: rs.i128, words: rs.u16[], many: rs.u32[], pair: [rs.u8, rs.i64], tag: Tag.Tag, maybe: Tag.Tag | undefined, p: rs.Place<rs.u8>, seen: rs.Cell<[rs.u8, rs.u8]> | undefined) {
this.n = n;
this.on = on;
this.c = c;
this.f = f;
this.wide = wide;
this.signed = signed;
this.words = words;
this.many = many;
this.pair = pair;
this.tag = tag;
this.maybe = maybe;
this.p = p;
this.seen = seen;
}

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

export function drop$ops_Drop(self: Zeroed): void {
if (self.seen !== undefined) {
const seen: rs.Cell<[rs.u8, rs.u8]> = self.seen;
const _6: [rs.u8, rs.u8] = seen.v;
rs.cellSet(seen, [_6[0], rs.u8WrappingAdd(_6[1], 1)] as [rs.u8, rs.u8]);
}
}

//# sourceMappingURL=uninit.Zeroed.ts.map
Loading