diff --git a/quest/m2/ts-model/README.md b/quest/m2/ts-model/README.md index 427ca2d17..435515c5f 100644 --- a/quest/m2/ts-model/README.md +++ b/quest/m2/ts-model/README.md @@ -49,7 +49,6 @@ Public API: the translator's output for moq-net's model. - [Shared ownership](/quest/m2/ts-shared.md) - kio's waiters are `Arc`/`Weak` with observable counts, and its atomics and locks are plain values - [Translate safe dependencies with the package](/quest/m2/ts-model/crates.md) - kio, moq-clock, moq-pattern, and rangemap translate as one program with moq-net - [Float formatting](/quest/m2/ts-model/floats.md) - `f64` formats and parses as std does -- [Std's mutable references to values JS copies](/quest/m2/ts-model/std-places.md) - `as_mut`, `get_or_insert`, `iter_mut`, and the rest give an `rt.Place` - [The rest of std the model reaches](/quest/m2/ts-model/std-rest.md) - the std calls the census still refuses - [Well-known crates without config](/quest/m2/ts-model/stock.md) - rust2-ts maps `bytes`, `rand`, and `tracing` itself, so `model.toml` stops binding and ignoring them - [Async in the TypeScript translator](/quest/m2/ts-async.md) - kio's producers and consumers are futures diff --git a/quest/m2/ts-model/std-places.md b/quest/m2/ts-model/std-places.md deleted file mode 100644 index 9da313041..000000000 --- a/quest/m2/ts-model/std-places.md +++ /dev/null @@ -1,24 +0,0 @@ -# [M] Std's mutable references to values JS copies - -## Goal - -rust2-ts translates the std methods that hand out a `&mut` to a value JS copies (a -number, an `Option` of one, a `Box`), giving an `rt.Place` where -[#128](https://github.com/kixelated/rust2/pull/128)'s guard refuses them now, proven by -differential tests against native Rust. - -## Plan - -Found by #128 on 2026-10-27: its guard refused 74 std-made `&mut`s in moq-net, most from -`Option::as_mut`, `get_or_insert*`, `insert`, `slice::get_mut` and `last_mut`, -`iter_mut` and `values_mut`, `Entry::and_modify`, `retain_mut`, and `dedup_by_key`. -Also refused: an `Option<&mut T>` passed through `map`, `map_or`, `filter`, and -`and_then` closures, and comparing `Option`s or tuples of Places through the runtime's key -functions. - -- Rerun the model's census first: [#129](https://github.com/kixelated/rust2/pull/129) now - lowers `Option`'s combinators from core's MIR, so some of these may already translate. -- Code that needs no Place still gets none; measure on the - [TS benchmark](/ts/README.md#bench). - -Public API: the translator's output. diff --git a/quest/m2/ts-model/std-rest.md b/quest/m2/ts-model/std-rest.md index ca2221d9f..557025b68 100644 --- a/quest/m2/ts-model/std-rest.md +++ b/quest/m2/ts-model/std-rest.md @@ -4,7 +4,7 @@ rust2-ts translates the std calls the model's census still refuses after [std gaps](https://github.com/kixelated/rust2/pull/124) and [core's MIR](https://github.com/kixelated/rust2/pull/129), -outside [Places](/quest/m2/ts-model/std-places.md), proven by differential tests against +outside [Places](https://github.com/kixelated/rust2/pull/149), proven by differential tests against native Rust. ## Plan diff --git a/ts/fixtures/lang/expected/combinators.ts b/ts/fixtures/lang/expected/combinators.ts index 734bbc2e5..43743d041 100644 --- a/ts/fixtures/lang/expected/combinators.ts +++ b/ts/fixtures/lang/expected/combinators.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; import { copy$Result_u32s_u16, copy$u32s } from "./lib.ts"; -import { isSomeAnd$Option_u8_bools_closure0, isNoneOr$Option_u8_options_closure1, unwrapOr$Option_u8, unwrapOrElse$Option_String_owned_closure3, unwrapOrElse$Option_u8_options_closure9, unwrapOrDefault$Option_String, unwrapOrDefault$Option_Vec_u8, unwrapOrDefault$Option_u8, map$Option_u8_String_owned_closure0, map$Option_u8_Vec_u8_owned_closure4, map$Option_u8_u32s_owned_closure9, map$Option_u8_u8_made_closure0_closure0, inspect$Option_u8_options_closure11, mapOr$Option_u16_u8_hash_maps_closure0, mapOr$Option_u8_u8_iters_closure3, mapOr$Option_u8_u8_u8_btree_maps_closure0, mapOrElse$Option_u8_u8_options_closure7_options_closure8, okOr$Option_u32s_u8, okOr$Option_u8_u16, okOr$Option_u8_u8, okOrElse$Option_Vec_u8_String_owned_closure5, okOrElse$Option_u8_u16_options_closure12, and$Option_u8_u8, andThen$Option_u8_u8_options_closure2, filter$Option_String_owned_closure1, filter$Option_u8_combinators_closure0, or$Option_u8, orElse$Option_String_owned_closure2, orElse$Option_u8_options_closure6, xor$Option_u8, zip$Option_u8_u8, clone$Clone_Option_String } from "./core/option.ts"; +import { isSomeAnd$Option_u8_bools_closure0, isNoneOr$Option_u8_options_closure1, unwrapOr$Option_u8, unwrapOrElse$Option_String_owned_closure3, unwrapOrElse$Option_u8_options_closure9, unwrapOrDefault$Option_String, unwrapOrDefault$Option_Vec_u8, unwrapOrDefault$Option_u8, map$Option_u8_String_owned_closure0, map$Option_u8_Vec_u8_owned_closure4, map$Option_u8_u32s_owned_closure9, map$Option_u8_u8_elements_closure8, inspect$Option_u8_options_closure11, mapOr$Option_u16_u8_hash_maps_closure0, mapOr$Option_u8_u8_elements_closure3, mapOr$Option_u8_u8_u8_btree_maps_closure0, mapOrElse$Option_u8_u8_options_closure7_options_closure8, okOr$Option_u32s_u8, okOr$Option_u8_u16, okOr$Option_u8_u8, okOrElse$Option_Vec_u8_String_owned_closure5, okOrElse$Option_u8_u16_options_closure12, and$Option_u8_u8, andThen$Option_u8_u8_options_closure2, filter$Option_String_owned_closure1, filter$Option_u8_combinators_closure0, or$Option_u8, orElse$Option_String_owned_closure2, orElse$Option_u8_options_closure6, xor$Option_u8, zip$Option_u8_u8, clone$Clone_Option_String } from "./core/option.ts"; import { isOkAnd$Result_u8_u16_results_closure5, isErrAnd$Result_u8_u16_results_closure6, ok$Result_u8_u16, err$Result_u8_u16, asRef$Result_u8_u16, map$Result_Vec_u8_String_Vec_u8_owned_closure6, map$Result_u8_u16_u8_options_closure13, mapOr$Result_u8_u16_u8_results_closure7, mapOrElse$Result_u8_u16_u8_results_closure8_results_closure9, mapErr$Result_u32s_u8_u16_from, mapErr$Result_u8_u16_u16_results_closure14, inspect$Result_u8_u16_results_closure12, inspectErr$Result_u8_u16_results_closure13, unwrapOrDefault$Result_u8_u16, and$Result_u8_u16_u8, andThen$Result_u8_u16_u8_results_closure3, or$Result_u8_u16_u16, orElse$Result_u8_u16_u16_results_closure4, unwrapOr$Result_u8_u16, unwrapOrElse$Result_u8_u16_results_closure11, unwrapOrElse$Result_u8_u8_panics_closure1, copied$Result_u8_u16, clone$Clone_Result_Vec_u8_String } from "./core/result.ts"; /** Run case `kind % 4` over `data`, whose bytes pick each `Some` or `None`, `Ok` or `Err`. */ @@ -39,11 +39,11 @@ export function options(a: rt.u8 | undefined, b: rt.u8 | undefined, limit: rt.u8 return rt.u8CheckedAdd(x3, limit); }), (x4: rt.u8): rt.u8 | undefined => { rt.byteVecPush(out, 162); - return map$Option_u8_u8_made_closure0_closure0(b, (y: rt.u8): rt.u8 => { + return map$Option_u8_u8_elements_closure8(b, (y: rt.u8): rt.u8 => { return x4 ^ y; }); }), 238)); - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(filter$Option_u8_combinators_closure0(a, (x5: rt.u8): boolean => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(filter$Option_u8_combinators_closure0(a, (x5: rt.u8): boolean => { rt.byteVecPush(out, 163); return x5 > limit; }), 221, (x6: rt.u8): rt.u8 => { diff --git a/ts/fixtures/lang/expected/core/option.ts b/ts/fixtures/lang/expected/core/option.ts index 29f45817f..f5c010fdb 100644 --- a/ts/fixtures/lang/expected/core/option.ts +++ b/ts/fixtures/lang/expected/core/option.ts @@ -72,6 +72,13 @@ export function unwrapOr$Option_u16(self: rt.u16 | undefined, default_: rt.u16): return self; } +export function unwrapOr$Option_u32(self: rt.u32 | undefined, default_: rt.u32): rt.u32 { + if (self === undefined) { + return default_; + } + return self; +} + export function unwrapOr$Option_u8(self: rt.u8 | undefined, default_: rt.u8): rt.u8 { if (self === undefined) { return default_; @@ -79,6 +86,13 @@ export function unwrapOr$Option_u8(self: rt.u8 | undefined, default_: rt.u8): rt return self; } +export function unwrapOr$Option_u8_u8(self: [rt.u8, rt.u8] | undefined, default_: [rt.u8, rt.u8]): [rt.u8, rt.u8] { + if (self === undefined) { + return default_; + } + return self; +} + export function unwrapOr$Option_usize_u8(self: [rt.usize, rt.u8] | undefined, default_: [rt.usize, rt.u8]): [rt.usize, rt.u8] { if (self === undefined) { return default_; @@ -205,7 +219,21 @@ export function map$Option_u8_u32s_owned_closure9(self: rt.u8 | undefined, f: (a return f(self); } -export function map$Option_u8_u8_made_closure0_closure0(self: rt.u8 | undefined, f: (a0: rt.u8) => rt.u8): rt.u8 | undefined { +export function map$Option_u8_u8_elements_closure8(self: rt.u8 | undefined, f: (a0: rt.u8) => rt.u8): rt.u8 | undefined { + if (self === undefined) { + return undefined; + } + return f(self); +} + +export function map$Option_u8_u8_u8_elements_closure9(self: rt.u8 | undefined, f: (a0: rt.u8) => [rt.u8, rt.u8]): [rt.u8, rt.u8] | undefined { + if (self === undefined) { + return undefined; + } + return f(self); +} + +export function map$Option_u8_u8_u8_u8_lent_closure2(self: [rt.u8, rt.u8] | undefined, f: (a0: [rt.u8, rt.u8]) => [rt.u8, rt.u8]): [rt.u8, rt.u8] | undefined { if (self === undefined) { return undefined; } @@ -331,6 +359,13 @@ export function mapOr$Option_u16_u8_hash_maps_closure0(self: rt.u16 | undefined, return f(self); } +export function mapOr$Option_u32_u32_lent_closure4(self: rt.Place | undefined, default_: rt.u32, f: (a0: rt.Place) => rt.u32): rt.u32 { + if (self === undefined) { + return default_; + } + return f(self); +} + export function mapOr$Option_u8_bool_take_largest_closure0(self: rt.u8 | undefined, default_: boolean, f: (a0: rt.u8) => boolean): boolean { if (self === undefined) { return default_; @@ -345,7 +380,7 @@ export function mapOr$Option_u8_u64_floats_closure1(self: rt.u8 | undefined, def return f(self); } -export function mapOr$Option_u8_u8_iters_closure3(self: rt.u8 | undefined, default_: rt.u8, f: (a0: rt.u8) => rt.u8): rt.u8 { +export function mapOr$Option_u8_u8_elements_closure3(self: rt.u8 | undefined, default_: rt.u8, f: (a0: rt.u8) => rt.u8): rt.u8 { if (self === undefined) { return default_; } @@ -506,6 +541,13 @@ export function andThen$Option_Option_u8_Option_u8_made_closure1(self: rt.u8 | u return f(self); } +export function andThen$Option_u32_u32_lent_closure3(self: rt.Place | undefined, f: (a0: rt.Place) => rt.Place | undefined): rt.Place | undefined { + if (self === undefined) { + return undefined; + } + return f(self); +} + export function andThen$Option_u8_u8_options_closure2(self: rt.u8 | undefined, f: (a0: rt.u8) => rt.u8 | undefined): rt.u8 | undefined { if (self === undefined) { return undefined; @@ -543,6 +585,16 @@ export function filter$Option_u8_combinators_closure0(self: rt.u8 | undefined, p return undefined; } +export function filter$Option_u8_u8_lent_closure1(self: [rt.u8, rt.u8] | undefined, predicate: (a0: [rt.u8, rt.u8]) => boolean): [rt.u8, rt.u8] | undefined { + if (self !== undefined) { + const x: [rt.u8, rt.u8] = self; + if (predicate(x)) { + return x; + } + } + return undefined; +} + export function or$Option_Option_u8(self: rt.u8 | undefined | rt.None, optb: rt.u8 | undefined | rt.None): rt.u8 | undefined | rt.None { if (self === rt.None) { return optb; diff --git a/ts/fixtures/lang/expected/iters.ts b/ts/fixtures/lang/expected/iters.ts index 2b8302b71..27740c7ed 100644 --- a/ts/fixtures/lang/expected/iters.ts +++ b/ts/fixtures/lang/expected/iters.ts @@ -2,7 +2,7 @@ import * as rt from "./rt.ts"; import { copy$Bumped, copy$u8_u8 } from "./lib.ts"; -import { unwrapOr$Option_NonZero_u64, unwrapOr$Option_i64, unwrapOr$Option_u8, unwrapOr$Option_usize_u8, map$Option_u8_u8_made_closure0_closure0, mapOr$Option_Vec_u16_u8_consumers_closure23, mapOr$Option_u8_u8_iters_closure3, mapOr$Option_u8_u8_u8_btree_maps_closure0, mapOr$Option_u8_usize_iters_closure1, mapOr$Option_u8s_u8_skips_closure44, mapOr$Option_usize_u8_consumers_closure8, mapOr$Option_usize_u8_u8_ranges_closure0 } from "./core/option.ts"; +import { unwrapOr$Option_NonZero_u64, unwrapOr$Option_i64, unwrapOr$Option_u8, unwrapOr$Option_usize_u8, map$Option_u8_u8_elements_closure8, mapOr$Option_Vec_u16_u8_consumers_closure23, mapOr$Option_u8_u8_elements_closure3, mapOr$Option_u8_u8_u8_btree_maps_closure0, mapOr$Option_u8_usize_iters_closure1, mapOr$Option_u8s_u8_skips_closure44, mapOr$Option_usize_u8_consumers_closure8, mapOr$Option_usize_u8_u8_ranges_closure0 } from "./core/option.ts"; import * as Bumped from "./iters.Bumped.ts"; import * as Countdown from "./iters.Countdown.ts"; import * as Doubled from "./iters.Doubled.ts"; @@ -359,7 +359,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item = rt.iterNthBack(it, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item, 238, (_264: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item, 238, (_264: rt.u8): rt.u8 => { return _264; })); rt.byteVecPush(out, rest.len() & 0xff); @@ -372,7 +372,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item2 = rt.iterNthBack(it2, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item2, 238, (_268: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item2, 238, (_268: rt.u8): rt.u8 => { return _268; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log)); @@ -386,7 +386,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item3 = rt.iterNthBack(it3, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item3, 238, (_261: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item3, 238, (_261: rt.u8): rt.u8 => { return _261; })); rt.byteVecPush(out, rest2.len() & 0xff); @@ -399,7 +399,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item4 = rt.iterNthBack(it4, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item4, 238, (_263: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item4, 238, (_263: rt.u8): rt.u8 => { return _263; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log2)); @@ -411,7 +411,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item5 = rt.iterNthBack(it5, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item5, 238, (_255: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item5, 238, (_255: rt.u8): rt.u8 => { return _255; })); rt.byteVecPush(out, rest3.len() & 0xff); @@ -424,7 +424,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item6 = rt.iterNthBack(it6, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item6, 238, (_260: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item6, 238, (_260: rt.u8): rt.u8 => { return _260; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log3)); @@ -437,7 +437,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item7 = rt.iterNthBack(it7, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item7, 238, (_252: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item7, 238, (_252: rt.u8): rt.u8 => { return _252; })); rt.byteVecPush(out, rest4.len() & 0xff); @@ -451,7 +451,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item8 = rt.iterNthBack(it8, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item8, 238, (_254: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item8, 238, (_254: rt.u8): rt.u8 => { return _254; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log4)); @@ -465,7 +465,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item9 = rt.iterNthBack(it9, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item9, 238, (_245: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item9, 238, (_245: rt.u8): rt.u8 => { return _245; })); rt.byteVecPush(out, rest5.len() & 0xff); @@ -478,7 +478,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item10 = rt.iterNthBack(it10, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item10, 238, (_251: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item10, 238, (_251: rt.u8): rt.u8 => { return _251; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log5)); @@ -490,7 +490,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item11 = rt.iterNthBack(it11, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item11, 238, (_240: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item11, 238, (_240: rt.u8): rt.u8 => { return _240; })); rt.byteVecPush(out, rest6.len() & 0xff); @@ -503,7 +503,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item12 = rt.iterNthBack(it12, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item12, 238, (_244: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item12, 238, (_244: rt.u8): rt.u8 => { return _244; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log6)); @@ -519,7 +519,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item13 = rt.iterNthBack(it13, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item13, 238, (_233: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item13, 238, (_233: rt.u8): rt.u8 => { return _233; })); rt.byteVecPush(out, rest7.len() & 0xff); @@ -534,7 +534,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item14 = rt.iterNthBack(it15, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item14, 238, (_239: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item14, 238, (_239: rt.u8): rt.u8 => { return _239; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log7)); @@ -546,7 +546,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item15 = rt.iterNthBack(it17, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item15, 238, (_230: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item15, 238, (_230: rt.u8): rt.u8 => { return _230; })); rt.byteVecPush(out, rest8.len() & 0xff); @@ -559,7 +559,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item16 = rt.iterNthBack(it18, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item16, 238, (_232: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item16, 238, (_232: rt.u8): rt.u8 => { return _232; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log8)); @@ -571,7 +571,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item17 = rt.iterNthBack(it19, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item17, 238, (b18: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item17, 238, (b18: rt.u8): rt.u8 => { return b18; })); rt.byteVecPush(out, rest9.len() & 0xff); @@ -584,7 +584,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item18 = rt.iterNthBack(it20, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item18, 238, (b20: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item18, 238, (b20: rt.u8): rt.u8 => { return b20; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log9)); @@ -596,7 +596,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item19 = rt.iterNthBack(it21, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item19, 238, (b15: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item19, 238, (b15: rt.u8): rt.u8 => { return b15; })); rt.byteVecPush(out, rest10.len() & 0xff); @@ -609,7 +609,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item20 = rt.iterNthBack(it22, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item20, 238, (b17: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item20, 238, (b17: rt.u8): rt.u8 => { return b17; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log10)); @@ -646,7 +646,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item23 = rt.iterNthBack(it25, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item23, 238, (_217: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item23, 238, (_217: rt.u8): rt.u8 => { return _217; })); rt.byteVecPush(out, rest12.len() & 0xff); @@ -659,7 +659,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item24 = rt.iterNthBack(it26, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item24, 238, (_220: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item24, 238, (_220: rt.u8): rt.u8 => { return _220; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log12)); @@ -672,7 +672,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item25 = rt.iterNthBack(it27, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item25, 238, (_212: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item25, 238, (_212: rt.u8): rt.u8 => { return _212; })); rt.byteVecPush(out, rest13.len() & 0xff); @@ -686,7 +686,7 @@ export function skips(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { } else { item26 = rt.iterNthBack(it28, n); } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(item26, 238, (_214: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(item26, 238, (_214: rt.u8): rt.u8 => { return _214; })); rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log13)); @@ -865,7 +865,7 @@ export function fullRange(out: rt.ByteVec): undefined { export function options(data: rt.ByteSlice, out: rt.ByteVec): void { const _83: (a0: rt.u8, a1: rt.ByteVec) => rt.u8 | undefined = (b2: rt.u8, calls2: rt.ByteVec): rt.u8 | undefined => { rt.byteVecPush(calls2, b2); - return map$Option_u8_u8_made_closure0_closure0(rt.u8CheckedSub(b2, 1), (b3: rt.u8): rt.u8 => { + return map$Option_u8_u8_elements_closure8(rt.u8CheckedSub(b2, 1), (b3: rt.u8): rt.u8 => { return rt.u8Div(b3, 2); }); }; @@ -951,7 +951,7 @@ export function options(data: rt.ByteSlice, out: rt.ByteVec): void { if (_114 === rt.DONE) { break; } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(_114, 170, (b10: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(_114, 170, (b10: rt.u8): rt.u8 => { return b10; })); } diff --git a/ts/fixtures/lang/expected/lib.ts b/ts/fixtures/lang/expected/lib.ts index 30531276c..a9c9152be 100644 --- a/ts/fixtures/lang/expected/lib.ts +++ b/ts/fixtures/lang/expected/lib.ts @@ -95,6 +95,10 @@ export function copy$Option_Wrap_i16(v: Wrap.Wrap | undefined): Wrap.Wra return v === undefined ? v : copy$Wrap_i16(v); } +export function copy$Option_u8_u8(v: [rt.u8, rt.u8] | undefined): [rt.u8, rt.u8] | undefined { + return v === undefined ? v : copy$u8_u8(v); +} + export function copy$Point(v: Point.Point): Point.Point { return { x: v.x, y: v.y }; } diff --git a/ts/fixtures/lang/expected/nested.ts b/ts/fixtures/lang/expected/nested.ts index b756d7ae6..3bf8ce4ca 100644 --- a/ts/fixtures/lang/expected/nested.ts +++ b/ts/fixtures/lang/expected/nested.ts @@ -1,7 +1,7 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; -import { unwrapOr$Option_u8, map$Option_Option_u8_Option_u8_made_closure0, map$Option_u8_Option_u8_made_closure1_closure0, map$Option_u8_u8_made_closure0_closure0, map$Option_unit_Option_u8_made_closure3, mapOr$Option_u8_u8_iters_closure3, mapOr$Option_u8_usize_iters_closure1, mapOr$Option_unit_u8_made_closure4, andThen$Option_Option_u8_Option_u8_made_closure1, filter$Option_Option_u8_made_closure2, or$Option_Option_u8, xor$Option_Option_u8, flatten$Option_Option_u8 } from "./core/option.ts"; +import { unwrapOr$Option_u8, map$Option_Option_u8_Option_u8_made_closure0, map$Option_u8_Option_u8_made_closure1_closure0, map$Option_u8_u8_elements_closure8, map$Option_unit_Option_u8_made_closure3, mapOr$Option_u8_u8_elements_closure3, mapOr$Option_u8_usize_iters_closure1, mapOr$Option_unit_u8_made_closure4, andThen$Option_Option_u8_Option_u8_made_closure1, filter$Option_Option_u8_made_closure2, or$Option_Option_u8, xor$Option_Option_u8, flatten$Option_Option_u8 } from "./core/option.ts"; import * as Halves from "./nested.Halves.ts"; import type * as Slot from "./nested.Slot.ts"; import * as Tagged from "./nested.Tagged.ts"; @@ -56,7 +56,7 @@ export function tried(a: undefined | rt.None, b: rt.u8 | undefined | rt.None): r if (a !== rt.None) { const _5: rt.u8 | undefined | rt.None = b; if (_5 !== rt.None) { - return map$Option_u8_u8_made_closure0_closure0(_5, (x: rt.u8): rt.u8 => { + return map$Option_u8_u8_elements_closure8(_5, (x: rt.u8): rt.u8 => { return rt.u8Div(x, 2); }); } @@ -72,7 +72,7 @@ export function made(data: rt.ByteSlice, out: rt.ByteVec): void { rt.byteVecPush(out, code(o)); rt.byteVecPush(out, (o !== rt.None ? 1 : 0) | (((o === rt.None ? 1 : 0) << 1) & 0xff) | (((u !== rt.None ? 1 : 0) << 2) & 0xff) | (((u === rt.None ? 1 : 0) << 3) & 0xff)); rt.byteVecPush(out, code(map$Option_Option_u8_Option_u8_made_closure0(o, (x: rt.u8 | undefined): rt.u8 | undefined => { - return map$Option_u8_u8_made_closure0_closure0(x, (y: rt.u8): rt.u8 => { + return map$Option_u8_u8_elements_closure8(x, (y: rt.u8): rt.u8 => { return y ^ 85; }); }))); @@ -213,7 +213,7 @@ export function iters(data: rt.ByteSlice, out: rt.ByteVec): void { if (_64 === rt.DONE) { break; } - rt.byteVecPush(out, mapOr$Option_u8_u8_iters_closure3(_64, 225, (x: rt.u8): rt.u8 => { + rt.byteVecPush(out, mapOr$Option_u8_u8_elements_closure3(_64, 225, (x: rt.u8): rt.u8 => { return x; })); } diff --git a/ts/fixtures/lang/expected/refs.Pair2.ts b/ts/fixtures/lang/expected/refs.Pair2.ts new file mode 100644 index 000000000..7f88821b4 --- /dev/null +++ b/ts/fixtures/lang/expected/refs.Pair2.ts @@ -0,0 +1,10 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export interface Pair2 { + a: rt.u32 | undefined; + b: rt.u32 | undefined; +} + +//# sourceMappingURL=refs.Pair2.ts.map diff --git a/ts/fixtures/lang/expected/refs.ts b/ts/fixtures/lang/expected/refs.ts index f9f13d9a6..e5d6c9a60 100644 --- a/ts/fixtures/lang/expected/refs.ts +++ b/ts/fixtures/lang/expected/refs.ts @@ -1,11 +1,13 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; -import { unwrapOr$Option_u8, mapOr$Option_u8_bool_take_largest_closure0 } from "./core/option.ts"; +import { copy$Option_u8_u8, copy$u32s } from "./lib.ts"; +import { unwrapOr$Option_u32, unwrapOr$Option_u8, unwrapOr$Option_u8_u8, unwrapOrDefault$Option_String, map$Option_u8_u8_elements_closure8, map$Option_u8_u8_u8_elements_closure9, map$Option_u8_u8_u8_u8_lent_closure2, mapOr$Option_u32_u32_lent_closure4, mapOr$Option_u8_bool_take_largest_closure0, mapOr$Option_u8_u8_elements_closure3, mapOr$Option_u8_u8_u8_btree_maps_closure0, andThen$Option_u32_u32_lent_closure3, filter$Option_u8_u8_lent_closure1, or$Option_u8 } from "./core/option.ts"; import * as Counts from "./refs.Counts.ts"; import * as Cursor from "./refs.Cursor.ts"; import type * as Fetch from "./refs.Fetch.ts"; import type * as Pair from "./refs.Pair.ts"; +import type * as Pair2 from "./refs.Pair2.ts"; export function bump(x: rt.Place, by: rt.u8): void { x.v = rt.u32Add(x.v, by as rt.u32); @@ -71,6 +73,9 @@ export function swapPair(p: [rt.u8, rt.u8]): void { p[0] = p[1]; p[1] = swapped; p[1] = rt.u8WrappingAdd(p[1], 1); + if (rt.u8Rem(p[0], 3) === 0) { + Object.assign(p, [p[1], p[0]] as [rt.u8, rt.u8]); + } } export function refuse(f: rt.Place): void { @@ -296,6 +301,585 @@ export function refs(data: rt.ByteSlice, out: rt.ByteVec): void { const _277: rt.u8 = total & 0xff; derefBox(rt.place(() => boxed2, (value20) => boxed2 = value20), _277); rt.byteVecPush(out, unwrapOr$Option_u8(boxed2, 238)); + lent(data, out); +} + +/** + * What std lends of an `Option` a `&mut` borrows: its payload, written through in place, + * passed on, and kept. + */ +export function lent(data: rt.ByteSlice, out: rt.ByteVec): void { + let at!: rt.Place; + let seen: rt.u32 | undefined = undefined; + let last = undefined as [rt.u8, rt.u8] | undefined; + let text = undefined as string | undefined; + const held: rt.Place[] = []; + const spare: Array = [undefined, 9]; + for (const b of rt.byteSliceView(data)) { + const _17: rt.u8 = rt.u8Rem(b, 6); + if (_17 === 0) { + const _20: rt.Place = rt.place(() => seen, (value7) => seen = value7); + const _21: rt.u32 = b as rt.u32; + if (_20.v === undefined) { + _20.v = _21; + } + _20.v = rt.u32Add(_20.v as rt.u32, 1); + } else if (_17 === 1) { + const _24: rt.Place = rt.place(() => seen, (value5) => seen = value5); + const _25: () => rt.u32 = (): rt.u32 => { + return rt.u32Mul(b as rt.u32, 2); + }; + if (_24.v === undefined) { + _24.v = _25(); + } + bump(rt.place(() => _24.v as rt.u32, (value6) => (_24.v as rt.u32) = value6), b); + } else if (_17 === 2) { + const _27: rt.u32 = b as rt.u32; + const _29: rt.Place = rt.place(() => seen, (value4) => seen = value4); + if (_29.v === undefined) { + _29.v = 0; + } + _29.v = rt.u32Add(_29.v as rt.u32, _27); + } else if (_17 === 3) { + const _32: rt.Place = rt.place(() => seen, (value3) => seen = value3); + _32.v = b as rt.u32; + _32.v = rt.u32WrappingAdd(_32.v as rt.u32, _32.v as rt.u32); + } else if (_17 === 4) { + const _38: rt.Place = rt.place(() => seen, (value) => seen = value); + const _37: rt.Place | undefined = _38.v === undefined ? undefined : rt.place(() => _38.v as rt.u32, (value2) => _38.v = value2); + if (_37 !== undefined) { + bump(_37, b); + } + } else { + seen = undefined; + } + const _45: [rt.u8, rt.u8] = [b, 0]; + if (last === undefined) { + last = _45; + } + (last as [rt.u8, rt.u8])[1] = (last as [rt.u8, rt.u8])[1] ^ b; + const _46: [rt.u8, rt.u8] | undefined = last; + if (_46 !== undefined) { + _46[0] = rt.u8WrappingAdd(_46[0], 1); + } + const _52: [rt.u8, rt.u8] | undefined = map$Option_u8_u8_u8_u8_lent_closure2(filter$Option_u8_u8_lent_closure1(last, (p: [rt.u8, rt.u8]): boolean => { + return rt.u8Rem(p[0], 2) === 0; + }), (p2: [rt.u8, rt.u8]): [rt.u8, rt.u8] => { + p2[1] = rt.u8WrappingAdd(p2[1], 2); + return p2; + }); + if (_52 !== undefined) { + _52[0] = _52[0] ^ 1; + } + const _61: rt.Place = rt.place(() => seen, (value8) => seen = value8); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(mapOr$Option_u32_u32_lent_closure4(andThen$Option_u32_u32_lent_closure3(_61.v === undefined ? undefined : rt.place(() => _61.v as rt.u32, (value9) => _61.v = value9), (x4: rt.Place): rt.Place | undefined => { + return rt.thenSome(rt.u32Rem(x4.v, 3) === 0, x4); + }), 0, (x5: rt.Place): rt.u32 => { + x5.v = rt.u32Mul(x5.v, 2); + return x5.v; + })))); + if (text === undefined) { + text = ""; + } + text = (text as string) + String.fromCodePoint(rt.u8Add(97, rt.u8Rem(b, 26)) as rt.char); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(unwrapOr$Option_u32(seen, 61166)))); + } + const _82: [rt.u8, rt.u8] = unwrapOr$Option_u8_u8(last, [238, 238] as [rt.u8, rt.u8]); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(_82[0], _82[1]))); + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(unwrapOrDefault$Option_String(text))); + const counts: Pair2.Pair2 = { a: undefined, b: undefined }; + const iter2: rt.Iter<[rt.usize, rt.u8]> = rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data))); + while (true) { + const _101: [rt.usize, rt.u8] | rt.Done = iter2.next(); + if (_101 === rt.DONE) { + break; + } + const i: rt.usize = _101[0]; + const b2: rt.u8 = _101[1]; + if (rt.usizeRem(i, 2) === 0) { + if (counts.a === undefined) { + counts.a = 0; + } + const borrowed = counts; + at = rt.place(() => borrowed.a as rt.u32, (value11) => borrowed.a = value11); + } else { + const f = (): rt.u32 => { + return 100; + }; + if (counts.b === undefined) { + counts.b = f(); + } + at = rt.place(() => counts.b as rt.u32, (value10) => (counts.b as rt.u32) = value10); + } + at.v = rt.u32Add(at.v, b2 as rt.u32); + const _117: rt.usize = rt.usizeRem(i, 2); + if (!(_117 < 2)) { + rt.panic("index out of bounds: the len is " + 2 + " but the index is " + _117); + } + if (spare[_117] === undefined) { + spare[_117] = 1; + } + bump(rt.place(() => spare[_117] as rt.u32, (value12) => (spare[_117] as rt.u32) = value12), b2); + } + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(spare)); + while (true) { + const _126: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_126 === rt.DONE) { + break; + } + _126[1].v = _126[0] as rt.u32; + held.push(rt.place(() => _126[1].v as rt.u32, (value13) => (_126[1].v as rt.u32) = value13)); + } + const iter4: rt.Iter> = rt.iterSlice(held); + while (true) { + const _138: rt.Place | rt.Done = iter4.next(); + if (_138 === rt.DONE) { + break; + } + _138.v = rt.u32Add(_138.v, 7); + } + const iter5: rt.Iter = rt.iterSlice([counts.a, counts.b, spare[0], spare[1]]); + while (true) { + const _154: rt.u32 | undefined | rt.Done = iter5.next(); + if (_154 === rt.DONE) { + break; + } + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(unwrapOr$Option_u32(_154, 61166)))); + } + elements(data, out); +} + +/** + * What std lends of the elements and values of slices and collections, which JS copies: + * one, each in turn, or each to a closure. + */ +export function elements(data: rt.ByteSlice, out: rt.ByteVec): void { + let _326!: rt.u8; + const v: rt.u32[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_2: rt.u8): rt.u32 => { + return _2 as rt.u32; + })); + const bytes: rt.ByteVec = rt.byteSliceToByteVec(data); + const pairs: [rt.u8, rt.u8 | undefined][] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_22: rt.u8): [rt.u8, rt.u8 | undefined] => { + const b8: rt.u8 = _22; + return [b8, rt.u8CheckedSub(b8, 100)] as [rt.u8, rt.u8 | undefined]; + })); + const by: rt.u8 = unwrapOr$Option_u8(rt.byteSliceFirst(data), 1); + const _13: rt.Place | undefined = rt.sliceFirstMut(v); + if (_13 !== undefined) { + _13.v = rt.u32Add(_13.v, 1); + } + const _19: rt.Place | undefined = rt.sliceLastMut(v); + if (_19 !== undefined) { + bump(_19, by); + } + const _25: rt.Place | undefined = rt.sliceGetMut(v, rt.usizeRem(by as rt.usize, 4)); + if (_25 !== undefined) { + _25.v = rt.u32Mul(_25.v, 2); + } + const _34: rt.Place | undefined = rt.sliceLastMut(rt.byteSliceView(rt.byteVecSlice(bytes))); + if (_34 !== undefined) { + _34.v = rt.u8WrappingAdd(_34.v, 1); + } + const _41: rt.Place | undefined = rt.sliceGetMut(rt.byteSliceView(rt.byteVecSlice(bytes)), 1); + if (_41 !== undefined) { + bumpByte(_41); + } + const iter: rt.Iter> = rt.iterStepBy(rt.iterRev(rt.iterSliceMut(v)), 2); + while (true) { + const _54: rt.Place | rt.Done = iter.next(); + if (_54 === rt.DONE) { + break; + } + _54.v = rt.u32Add(_54.v, 3); + } + const iter2: rt.Iter> = rt.iterSliceMut(v); + while (true) { + const _62: rt.Place | rt.Done = iter2.next(); + if (_62 === rt.DONE) { + break; + } + bump(_62, 1); + } + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteVecSlice(bytes)))); + while (true) { + const _73: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_73 === rt.DONE) { + break; + } + _73[1].v = _73[1].v ^ (_73[0] & 0xff); + } + const iter4: rt.Iter<[rt.Place, rt.Place]> = rt.iterZip(rt.iterSliceMut(rt.byteSliceView(rt.byteVecSlice(bytes))), rt.iterSliceMut(v), true); + while (true) { + const _86: [rt.Place, rt.Place] | rt.Done = iter4.next(); + if (_86 === rt.DONE) { + break; + } + _86[1].v = rt.u32Add(_86[1].v, _86[0].v as rt.u32); + _86[0].v = rt.u8WrappingAdd(_86[0].v, _86[0].v); + } + const _97: [rt.u8, rt.u8 | undefined] | undefined = rt.iterFind(rt.iterSlice(pairs), (_23: [rt.u8, rt.u8 | undefined]): boolean => { + return rt.u8Rem(_23[0], 3) === 0; + }); + if (_97 !== undefined) { + _97[1] = mapOr$Option_u8_u8_elements_closure3(_97[1], 0, (s: rt.u8): rt.u8 => { + return rt.u8WrappingAdd(s, 1); + }); + } + const most: rt.Place | undefined = rt.iterMaxByKey(rt.iterSliceMut(v), (x7: rt.Place): rt.u32 => { + return x7.v; + }); + if (most !== undefined) { + most.v = 0; + } + const iter5: rt.Iter> = rt.iterSlice(rt.iterToArray(rt.iterFilter(rt.iterSliceMut(v), (x8: rt.Place): boolean => { + return rt.u32Rem(x8.v, 2) === 0; + }))); + while (true) { + const _120: rt.Place | rt.Done = iter5.next(); + if (_120 === rt.DONE) { + break; + } + _120.v = rt.u32Add(_120.v, 1); + } + const item = copy$u32s(Array.from({ length: 2 }, (): rt.u32 => { + return 0; + })); + const grid: rt.u32[][] = Array.from({ length: 3 }, (): rt.u32[] => { + return copy$u32s(item); + }); + const iter6: rt.Iter<[rt.u32[], rt.u8]> = rt.iterZip(rt.iterSlice(grid), rt.iterSlice(rt.byteSliceView(data)), true); + l18: while (true) { + const _133: [rt.u32[], rt.u8] | rt.Done = iter6.next(); + if (_133 === rt.DONE) { + break; + } + const b: rt.u8 = _133[1]; + const iter7: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(_133[0])); + while (true) { + const _143: [rt.usize, rt.Place] | rt.Done = iter7.next(); + if (_143 === rt.DONE) { + continue l18; + } + _143[1].v = rt.u32Shl(b as rt.u32, _143[0]); + } + } + for (const _153 of v) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(_153))); + } + rt.byteVecExtendFromSlice(out, rt.byteVecSlice(bytes)); + for (const _168 of pairs) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(_168[0], unwrapOr$Option_u8(_168[1], 238)))); + } + const iter10: rt.Iter = rt.iterFlatten(rt.iterSlice(grid), (value: rt.u32[]) => rt.iterSlice(value)); + while (true) { + const _186: rt.u32 | rt.Done = iter10.next(); + if (_186 === rt.DONE) { + break; + } + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(_186))); + } + const hash: rt.HashMap = rt.hashNew() as rt.HashMap; + const tree: rt.BTreeMap = rt.btreeNew(rt.cmp) as rt.BTreeMap; + const queue: rt.VecDeque = rt.dequeNew() as rt.VecDeque; + for (const b2 of rt.byteSliceView(data)) { + rt.entryOrInsert(rt.entryAndModify(rt.entry(hash, rt.u8Rem(b2, 5)), (x9: [rt.u8, rt.u8]): void => { + x9[1] = rt.u8WrappingAdd(x9[1], b2); + }), [b2, 0] as [rt.u8, rt.u8]); + const _213: rt.u32 = b2 as rt.u32; + const _214: rt.Place = rt.entryOrInsertWithMut(rt.entryAndModifyMut(rt.entry(tree, rt.u8Rem(b2, 4)), (x10: rt.Place): void => { + x10.v = rt.u32Add(x10.v, 1); + }), (): rt.u32 => { + return 0; + }); + _214.v = rt.u32Add(_214.v, _213); + rt.dequePushBack(queue, b2 as rt.u32); + if (rt.u8Rem(b2, 3) === 0) { + rt.dequePushFront(queue, rt.u32Add(b2 as rt.u32, 1)); + } + } + const iter12: rt.Iter<[rt.u8, rt.u8]> = rt.hashValues(hash); + while (true) { + const _236: [rt.u8, rt.u8] | rt.Done = iter12.next(); + if (_236 === rt.DONE) { + break; + } + _236[0] = rt.u8WrappingAdd(_236[0], 1); + } + const iter13: rt.Iter<[rt.u8, [rt.u8, rt.u8]]> = rt.hashIter(hash); + while (true) { + const _246: [rt.u8, [rt.u8, rt.u8]] | rt.Done = iter13.next(); + if (_246 === rt.DONE) { + break; + } + if (rt.u8Rem(_246[0], 2) === 0) { + Object.assign(_246[1], [_246[1][1], _246[1][0]] as [rt.u8, rt.u8]); + } + } + const iter14: rt.Iter<[rt.u8, rt.Place]> = rt.btreeIterMut(tree); + while (true) { + const _258: [rt.u8, rt.Place] | rt.Done = iter14.next(); + if (_258 === rt.DONE) { + break; + } + _258[1].v = rt.u32Add(_258[1].v, _258[0] as rt.u32); + } + const iter15: rt.Iter> = rt.iterRev(rt.btreeValuesMut(tree)); + while (true) { + const _271: rt.Place | rt.Done = iter15.next(); + if (_271 === rt.DONE) { + break; + } + _271.v = rt.u32Mul(_271.v, 2); + } + const iter16: rt.Iter<[rt.u8, rt.Place]> = rt.btreeRangeMut(tree, new rt.Range(1, 3)); + while (true) { + const _281: [rt.u8, rt.Place] | rt.Done = iter16.next(); + if (_281 === rt.DONE) { + break; + } + _281[1].v = rt.u32Add(_281[1].v, (((_281[0] as rt.u32)) << 8) >>> 0); + } + let nested = rt.None as rt.u8 | undefined | rt.None; + l39: for (const b3 of rt.byteSliceView(data)) { + const _300: rt.u8 = rt.u8Rem(b3, 3); + if (_300 === 0) { + const _302: rt.u8 | undefined = rt.u8CheckedSub(b3, 50); + const _305 = undefined as rt.u8 | undefined; + if (nested === rt.None) { + nested = _305; + } + nested = _302; + } else if (_300 === 1) { + const _306: rt.Place | undefined = nested === rt.None ? undefined : rt.place(() => nested as rt.u8 | undefined, (value2) => nested = value2); + if (_306 !== undefined) { + _306.v = map$Option_u8_u8_elements_closure8(_306.v, (x11: rt.u8): rt.u8 => { + return rt.u8WrappingAdd(x11, 1); + }); + } + } else { + nested = b3; + rt.place(() => nested as rt.u8 | undefined, (value) => (nested as rt.u8 | undefined) = value); + } + const iter18: rt.Iter> = rt.iterOption(rt.optionAsMut(rt.place(() => nested, (value3) => nested = value3), rt.None)); + while (true) { + const _318: rt.Place | rt.Done = iter18.next(); + if (_318 === rt.DONE) { + continue l39; + } + _318.v = or$Option_u8(_318.v, 1); + } + } + if (nested === rt.None) { + _326 = 238; + } else if (nested === undefined) { + _326 = 221; + } else { + _326 = nested; + } + rt.byteVecPush(out, _326); + const iter19: rt.Iter = rt.iterSlice([seenOf(data), undefined]); + while (true) { + const _335: rt.u8 | undefined | rt.Done = iter19.next(); + if (_335 === rt.DONE) { + break; + } + let o2: rt.u8 | undefined = _335; + const iter20: rt.Iter> = rt.iterOption(rt.optionAsMut(rt.place(() => o2, (value4) => o2 = value4))); + while (true) { + const _343: rt.Place | rt.Done = iter20.next(); + if (_343 === rt.DONE) { + break; + } + _343.v = rt.u8WrappingAdd(_343.v, 7); + } + rt.byteVecPush(out, rt.iterCount(rt.iterOption(rt.optionAsMut(rt.place(() => o2, (value5) => o2 = value5)))) & 0xff); + rt.byteVecPush(out, unwrapOr$Option_u8(o2, 238)); + } + const iter21: rt.Iter<[rt.u8, rt.u8] | undefined> = rt.iterSlice([copy$Option_u8_u8(map$Option_u8_u8_u8_elements_closure9(seenOf(data), (b9: rt.u8): [rt.u8, rt.u8] => { + return [b9, 1] as [rt.u8, rt.u8]; + })), undefined]); + while (true) { + const _363: [rt.u8, rt.u8] | undefined | rt.Done = iter21.next(); + if (_363 === rt.DONE) { + break; + } + let o4: [rt.u8, rt.u8] | undefined = copy$Option_u8_u8(_363); + const iter22: rt.Iter<[rt.u8, rt.u8]> = rt.iterOption(rt.place(() => o4, (value6) => o4 = value6).v); + while (true) { + const _371: [rt.u8, rt.u8] | rt.Done = iter22.next(); + if (_371 === rt.DONE) { + break; + } + _371[0] = _371[0] ^ 90; + } + rt.byteVecPush(out, rt.iterCount(rt.iterOption(rt.place(() => o4, (value7) => o4 = value7).v)) & 0xff); + rt.byteVecPush(out, mapOr$Option_u8_u8_u8_btree_maps_closure0(o4, 238, (p: [rt.u8, rt.u8]): rt.u8 => { + return p[0]; + })); + } + let n: rt.u8 = unwrapOr$Option_u8(seenOf(data), 0); + const iter23: rt.Iter | undefined> = rt.iterSlice([rt.place(() => n, (value8) => n = value8), undefined]); + while (true) { + const _391: rt.Place | undefined | rt.Done = iter23.next(); + if (_391 === rt.DONE) { + break; + } + let o6: rt.Place | undefined = _391; + rt.byteVecPush(out, rt.iterCount(rt.iterOption(rt.place(() => o6, (value9) => o6 = value9).v)) & 0xff); + } + rt.byteVecPush(out, n); + let _406: rt.u8 | undefined = seenOf(data); + const iter24: rt.Iter> = rt.iterOption(_406 === undefined ? undefined : rt.place(() => _406 as rt.u8, (value10) => _406 = value10)); + while (true) { + const _408: rt.Place | rt.Done = iter24.next(); + if (_408 === rt.DONE) { + break; + } + _408.v = _408.v ^ 255; + rt.btreeInsert(tree, 9, _408.v as rt.u32); + } + rt.hashRetain(hash, (k4: rt.u8, x12: [rt.u8, rt.u8]): boolean => { + x12[1] = x12[1] ^ k4; + return k4 !== rt.u8Rem(by, 5); + }); + rt.btreeRetainMut(tree, (k5: rt.u8, x13: rt.Place): boolean => { + x13.v = rt.u32Add(x13.v, 1); + return k5 !== rt.u8Rem(by, 4); + }); + const iter25: rt.Iter> = rt.dequeIterMut(queue); + while (true) { + const _428: rt.Place | rt.Done = iter25.next(); + if (_428 === rt.DONE) { + break; + } + _428.v = rt.u32Add(_428.v, 1); + } + const _433: rt.Place | undefined = rt.dequeEndMut(queue); + if (_433 !== undefined) { + _433.v = rt.u32Add(_433.v, 100); + } + const _438: rt.Place | undefined = rt.dequeEndMut(queue, true); + if (_438 !== undefined) { + _438.v = rt.u32Add(_438.v, 200); + } + const _443: rt.Place | undefined = rt.dequeGetMut(queue, 1); + if (_443 !== undefined) { + _443.v = rt.u32Add(_443.v, 300); + } + rt.dequeRetainMut(queue, (x14: rt.Place): boolean => { + x14.v = rt.u32Add(x14.v, 1); + return rt.u32Rem(x14.v, 3) !== 0; + }); + const scalars: rt.HashMap = rt.hashNew() as rt.HashMap; + for (const b4 of rt.byteSliceView(data)) { + const _457: rt.u32 = b4 as rt.u32; + const _458: rt.Place = rt.entryOrInsertWithMut(rt.entry(scalars, rt.u8Rem(b4, 5)), (): rt.u32 => { + return 0; + }); + _458.v = rt.u32Add(_458.v, _457); + } + const iter27: rt.Iter<[rt.u8, rt.Place]> = rt.hashIterMut(scalars); + while (true) { + const _468: [rt.u8, rt.Place] | rt.Done = iter27.next(); + if (_468 === rt.DONE) { + break; + } + _468[1].v = rt.u32Add(_468[1].v, _468[0] as rt.u32); + } + const iter28: rt.Iter> = rt.hashValuesMut(scalars); + while (true) { + const _480: rt.Place | rt.Done = iter28.next(); + if (_480 === rt.DONE) { + break; + } + _480.v = rt.u32Mul(_480.v, 3); + } + const _486: rt.Iter<[rt.u8, rt.u32]> = rt.hashIter(scalars); + const iter29: rt.Iter<[rt.u8, rt.u32]> = rt.btreeIter(rt.btreeExtend(rt.btreeNew(rt.cmp) as rt.BTreeMap, _486, true)); + while (true) { + const _490: [rt.u8, rt.u32] | rt.Done = iter29.next(); + if (_490 === rt.DONE) { + break; + } + const k: rt.u8 = _490[0]; + const x2: rt.u32 = _490[1]; + rt.byteVecPush(out, k); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(x2))); + } + const paired: rt.HashMap<[rt.u8, rt.u8], rt.u32> = rt.hashNew(rt.hashing(rt.hashTuple([rt.hashInt, rt.hashInt]), rt.eqTuple([rt.same, rt.same]))) as rt.HashMap<[rt.u8, rt.u8], rt.u32>; + for (const b5 of rt.byteSliceView(data)) { + const _507: rt.u32 = b5 as rt.u32; + const _511: [rt.u8, rt.u8] = [rt.u8Rem(b5, 3), rt.u8Rem(b5, 2)]; + const _508: rt.Place = rt.entryOrInsertWithMut(rt.entry(paired, _511), (): rt.u32 => { + return 0; + }); + _508.v = rt.u32Add(_508.v, _507); + } + const iter31: rt.Iter<[[rt.u8, rt.u8], rt.Place]> = rt.hashIterMut(paired); + while (true) { + const _521: [[rt.u8, rt.u8], rt.Place] | rt.Done = iter31.next(); + if (_521 === rt.DONE) { + break; + } + _521[1].v = rt.u32Add(_521[1].v, _521[0][0] as rt.u32); + } + const iter32: rt.Iter> = rt.hashValuesMut(paired); + while (true) { + const _533: rt.Place | rt.Done = iter32.next(); + if (_533 === rt.DONE) { + break; + } + _533.v = rt.u32Mul(_533.v, 2); + } + rt.hashRetainMut(paired, (k6: [rt.u8, rt.u8], x15: rt.Place): boolean => { + x15.v = rt.u32Add(x15.v, 1); + return k6[1] === 0; + }); + const _541: rt.Iter<[[rt.u8, rt.u8], rt.u32]> = rt.hashIter(paired); + const iter33: rt.Iter<[[rt.u8, rt.u8], rt.u32]> = rt.btreeIter(rt.btreeExtend(rt.btreeNew(rt.cmpTuple([rt.cmp, rt.cmp])) as rt.BTreeMap<[rt.u8, rt.u8], rt.u32>, _541, true)); + while (true) { + const _545: [[rt.u8, rt.u8], rt.u32] | rt.Done = iter33.next(); + if (_545 === rt.DONE) { + break; + } + const a: rt.u8 = _545[0][0]; + const b6: rt.u8 = _545[0][1]; + const x3: rt.u32 = _545[1]; + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(a, b6))); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(x3))); + } + const _560: rt.Iter<[rt.u8, [rt.u8, rt.u8]]> = rt.hashIter(hash); + const iter34: rt.Iter<[rt.u8, [rt.u8, rt.u8]]> = rt.btreeIter(rt.btreeExtend(rt.btreeNew(rt.cmp) as rt.BTreeMap, _560, true)); + while (true) { + const _564: [rt.u8, [rt.u8, rt.u8]] | rt.Done = iter34.next(); + if (_564 === rt.DONE) { + break; + } + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(_564[0], _564[1][0], _564[1][1]))); + } + const iter35: rt.Iter<[rt.u8, rt.u32]> = rt.btreeIter(tree); + while (true) { + const _577: [rt.u8, rt.u32] | rt.Done = iter35.next(); + if (_577 === rt.DONE) { + break; + } + const k3: rt.u8 = _577[0]; + const x5: rt.u32 = _577[1]; + rt.byteVecPush(out, k3); + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(x5))); + } + const iter36: rt.Iter = rt.dequeIter(queue); + while (true) { + const _590: rt.u32 | rt.Done = iter36.next(); + if (_590 === rt.DONE) { + break; + } + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(_590))); + } +} + +export function seenOf(data: rt.ByteSlice): rt.u8 | undefined { + return rt.byteSliceGet(data, 2); } export function bumpSlot(c: rt.Place, b: rt.u8): void { diff --git a/ts/fixtures/lang/src/refs.rs b/ts/fixtures/lang/src/refs.rs index 18632a31a..d61512a47 100644 --- a/ts/fixtures/lang/src/refs.rs +++ b/ts/fixtures/lang/src/refs.rs @@ -2,7 +2,7 @@ //! `String`, passed on, returned, kept in a struct, and captured: each borrows a local, a //! field, an element, or a map's value, and what is written through it must land there. -use std::collections::{BTreeMap, HashMap}; +use std::collections::{BTreeMap, HashMap, VecDeque}; fn bump(x: &mut u32, by: u8) { *x += u32::from(by); @@ -56,6 +56,10 @@ fn rebox(b: &mut Box, by: u8) { fn swap_pair(p: &mut (u8, u8)) { std::mem::swap(&mut p.0, &mut p.1); p.1 = p.1.wrapping_add(1); + // The whole tuple, replaced in the caller's. + if p.0 % 3 == 0 { + *p = (p.1, p.0); + } } #[derive(Clone, Copy, Debug, PartialEq)] @@ -259,6 +263,300 @@ pub fn refs(data: &[u8], out: &mut Vec) { let mut boxed = Box::new(None); deref_box(&mut boxed, total as u8); out.push(std::ops::Deref::deref(&boxed).unwrap_or(0xee)); + lent(data, out); +} + +/// What std lends of an `Option` a `&mut` borrows: its payload, written through in place, +/// passed on, and kept. +fn lent(data: &[u8], out: &mut Vec) { + let mut seen: Option = None; + let mut last: Option<(u8, u8)> = None; + let mut text: Option = None; + let mut held: Vec<&mut u32> = Vec::new(); + let mut spare = [None, Some(9u32)]; + for &b in data { + match b % 6 { + 0 => *seen.get_or_insert(u32::from(b)) += 1, + 1 => bump(seen.get_or_insert_with(|| u32::from(b) * 2), b), + 2 => *seen.get_or_insert_default() += u32::from(b), + 3 => { + let x = seen.insert(u32::from(b)); + *x = x.wrapping_add(*x); + } + 4 => { + if let Some(x) = seen.as_mut() { + bump(x, b); + } + } + _ => seen = None, + } + last.get_or_insert((b, 0)).1 ^= b; + if let Some((x, _)) = last.as_mut() { + *x = x.wrapping_add(1); + } + // Through `Option`'s combinators, which hand the closure the place. + if let Some(p) = last.as_mut().filter(|p| p.0 % 2 == 0).map(|p| { + p.1 = p.1.wrapping_add(2); + p + }) { + p.0 ^= 1; + } + let doubled = seen.as_mut().and_then(|x| (*x % 3 == 0).then_some(x)).map_or(0, |x| { + *x *= 2; + *x + }); + out.extend_from_slice(&doubled.to_be_bytes()); + text.get_or_insert_with(String::new).push(char::from(b'a' + b % 26)); + out.extend_from_slice(&seen.unwrap_or(0xeeee).to_be_bytes()); + } + let (x, y) = last.unwrap_or((0xee, 0xee)); + out.extend_from_slice(&[x, y]); + out.extend_from_slice(text.unwrap_or_default().as_bytes()); + // A payload lent through a field and an element, then kept past its loan. + let mut counts = Pair2 { a: None, b: None }; + for (i, &b) in data.iter().enumerate() { + let at = match i % 2 { + 0 => counts.a.get_or_insert(0), + _ => counts.b.get_or_insert_with(|| 100), + }; + *at += u32::from(b); + bump(spare[i % 2].get_or_insert(1), b); + } + for (i, x) in spare.iter_mut().enumerate() { + held.push(x.insert(i as u32)); + } + for x in held { + *x += 7; + } + for x in [counts.a, counts.b, spare[0], spare[1]] { + out.extend_from_slice(&x.unwrap_or(0xeeee).to_be_bytes()); + } + elements(data, out); +} + +/// What std lends of the elements and values of slices and collections, which JS copies: +/// one, each in turn, or each to a closure. +fn elements(data: &[u8], out: &mut Vec) { + let mut v: Vec = data.iter().map(|&b| u32::from(b)).collect(); + let mut bytes = data.to_vec(); + let mut pairs: Vec<(u8, Option)> = data.iter().map(|&b| (b, b.checked_sub(100))).collect(); + let by = data.first().copied().unwrap_or(1); + if let Some(x) = v.first_mut() { + *x += 1; + } + if let Some(x) = v.last_mut() { + bump(x, by); + } + if let Some(x) = v.get_mut(usize::from(by) % 4) { + *x *= 2; + } + if let Some(b) = bytes.last_mut() { + *b = b.wrapping_add(1); + } + if let Some(b) = bytes.get_mut(1) { + bump_byte(b); + } + for x in v.iter_mut().rev().step_by(2) { + *x += 3; + } + for x in &mut v { + bump(x, 1); + } + for (i, b) in bytes.iter_mut().enumerate() { + *b ^= i as u8; + } + for (b, x) in bytes.iter_mut().zip(&mut v) { + *x += u32::from(*b); + *b = b.wrapping_add(*b); + } + // Places found, kept, and compared. + if let Some((_, slot)) = pairs.iter_mut().find(|(k, _)| *k % 3 == 0) { + *slot = Some(slot.map_or(0, |s| s.wrapping_add(1))); + } + let most = v.iter_mut().max_by_key(|x| **x); + if let Some(x) = most { + *x = 0; + } + let every: Vec<&mut u32> = v.iter_mut().filter(|x| **x % 2 == 0).collect(); + for x in every { + *x += 1; + } + let mut grid = [[0u32; 2]; 3]; + for (row, &b) in grid.iter_mut().zip(data) { + for (i, x) in row.iter_mut().enumerate() { + *x = u32::from(b) << i; + } + } + for x in &v { + out.extend_from_slice(&x.to_be_bytes()); + } + out.extend_from_slice(&bytes); + for (k, slot) in &pairs { + out.extend_from_slice(&[*k, slot.unwrap_or(0xee)]); + } + for x in grid.iter().flatten() { + out.extend_from_slice(&x.to_be_bytes()); + } + // Maps' and a deque's values. + let mut hash: HashMap = HashMap::new(); + let mut tree: BTreeMap = BTreeMap::new(); + let mut queue: VecDeque = VecDeque::new(); + for &b in data { + hash.entry(b % 5) + .and_modify(|x| x.1 = x.1.wrapping_add(b)) + .or_insert((b, 0)); + *tree.entry(b % 4).and_modify(|x| *x += 1).or_default() += u32::from(b); + queue.push_back(u32::from(b)); + if b % 3 == 0 { + queue.push_front(u32::from(b) + 1); + } + } + for x in hash.values_mut() { + x.0 = x.0.wrapping_add(1); + } + for (k, x) in hash.iter_mut() { + if k % 2 == 0 { + *x = (x.1, x.0); + } + } + for (k, x) in &mut tree { + *x += u32::from(*k); + } + for x in tree.values_mut().rev() { + *x *= 2; + } + for (k, x) in tree.range_mut(1..3) { + *x += u32::from(*k) << 8; + } + // An `Option` whose payload can be `undefined`, whose `None` is apart from it. + let mut nested: Option> = None; + for &b in data { + match b % 3 { + 0 => *nested.get_or_insert(None) = b.checked_sub(50), + 1 => { + if let Some(x) = nested.as_mut() { + *x = x.map(|x| x.wrapping_add(1)); + } + } + _ => drop(nested.insert(Some(b))), + } + for x in &mut nested { + *x = x.or(Some(1)); + } + } + out.push(match nested { + None => 0xee, + Some(None) => 0xdd, + Some(Some(x)) => x, + }); + // A borrowed `Option` iterated: its payload's place, or nothing. + for o in [seen_of(data), None] { + let mut o = o; + for x in &mut o { + *x = x.wrapping_add(7); + } + out.push((&mut o).into_iter().count() as u8); + out.push(o.unwrap_or(0xee)); + } + // Of a payload JS doesn't copy, a tuple or a `&mut`: the payload itself, or nothing. + for o in [seen_of(data).map(|b| (b, 1u8)), None] { + let mut o = o; + for p in &mut o { + p.0 ^= 0x5a; + } + out.push((&mut o).into_iter().count() as u8); + out.push(o.map_or(0xee, |p| p.0)); + } + let mut n = seen_of(data).unwrap_or(0); + for o in [Some(&mut n), None] { + let mut o = o; + out.push((&mut o).into_iter().count() as u8); + } + out.push(n); + for x in seen_of(data).iter_mut() { + *x ^= 0xff; + tree.insert(9, u32::from(*x)); + } + hash.retain(|k, x| { + x.1 ^= *k; + *k != by % 5 + }); + tree.retain(|k, x| { + *x += 1; + *k != by % 4 + }); + for x in queue.iter_mut() { + *x += 1; + } + if let Some(x) = queue.front_mut() { + *x += 100; + } + if let Some(x) = queue.back_mut() { + *x += 200; + } + if let Some(x) = queue.get_mut(1) { + *x += 300; + } + queue.retain_mut(|x| { + *x += 1; + *x % 3 != 0 + }); + // Keys that are their own JS map keys, of values JS copies. + let mut scalars: HashMap = HashMap::new(); + for &b in data { + *scalars.entry(b % 5).or_default() += u32::from(b); + } + for (k, x) in scalars.iter_mut() { + *x += u32::from(*k); + } + for x in scalars.values_mut() { + *x *= 3; + } + let scalars: BTreeMap = scalars.into_iter().collect(); + for (k, x) in scalars { + out.push(k); + out.extend_from_slice(&x.to_be_bytes()); + } + // Keys that are objects, which the runtime chains by hash. + let mut paired: HashMap<(u8, u8), u32> = HashMap::new(); + for &b in data { + *paired.entry((b % 3, b % 2)).or_default() += u32::from(b); + } + for (k, x) in paired.iter_mut() { + *x += u32::from(k.0); + } + for x in paired.values_mut() { + *x *= 2; + } + paired.retain(|k, x| { + *x += 1; + k.1 == 0 + }); + let paired: BTreeMap<(u8, u8), u32> = paired.into_iter().collect(); + for ((a, b), x) in paired { + out.extend_from_slice(&[a, b]); + out.extend_from_slice(&x.to_be_bytes()); + } + let hash: BTreeMap = hash.into_iter().collect(); + for (k, (x, y)) in hash { + out.extend_from_slice(&[k, x, y]); + } + for (k, x) in tree { + out.push(k); + out.extend_from_slice(&x.to_be_bytes()); + } + for x in queue { + out.extend_from_slice(&x.to_be_bytes()); + } +} + +fn seen_of(data: &[u8]) -> Option { + data.get(2).copied() +} + +struct Pair2 { + a: Option, + b: Option, } fn bump_slot(c: &mut usize, b: u8) { diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index 97aadb27f..d1cb2b603 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,59 +1,58 @@ # Census of `reject-fixture` -- Refusals: 79 -- Function instances: 87 +- Refusals: 76 +- Function instances: 84 - Generic functions no instance reached, lowered over their type parameters: 6 ## By construct | Count | Construct | First | | ---: | --- | --- | -| 11 | unsupported call to `_` | fixtures/reject/src/lib.rs:28:4 | -| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:403:2 | -| 4 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:117:2 | -| 3 | `_` with a mutable reference to a value JS copies, which its mapping would copy | fixtures/reject/src/lib.rs:17:2 | -| 3 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:101:2 | +| 11 | unsupported call to `_` | fixtures/reject/src/lib.rs:21:4 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:396:2 | +| 4 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:110:2 | +| 3 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:94:2 | | 3 | unsupported type `_` | fixtures/reject/src/lib.rs:7:14 | -| 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:121:20 | -| 2 | `_` is not supported: its `None` and `Some` would both be `rt.None` | fixtures/reject/src/lib.rs:23:15 | -| 2 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | fixtures/reject/src/lib.rs:48:42 | -| 2 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | fixtures/reject/src/lib.rs:268:16 | -| 2 | `_`, a trait object of the generic trait `_`, which is not supported yet | fixtures/reject/src/lib.rs:522:23 | -| 2 | a coercion to `_` | fixtures/reject/src/lib.rs:362:2 | -| 2 | a coercion to `_`, which is not supported yet | fixtures/reject/src/lib.rs:513:39 | -| 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:175:1 | -| 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:161:23 | -| 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:155:2 | -| 2 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:390:13 | -| 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:84:2 | -| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:414:18 | -| 1 | `_` is not supported: its field `_` is `_`, typed `_`, whose `None` would be `rt.None` as `_` | fixtures/reject/src/lib.rs:38:2 | -| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:307:6 | -| 1 | `_` of `_`, which drops `_`, which is not supported yet | fixtures/reject/src/lib.rs:69:13 | -| 1 | `_` of `_`, which folds a closure that drops beside what else drops, which is not supported yet | fixtures/reject/src/lib.rs:63:23 | -| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:339:2 | +| 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:114:20 | +| 2 | `_` is not supported: its `None` and `Some` would both be `rt.None` | fixtures/reject/src/lib.rs:16:15 | +| 2 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | fixtures/reject/src/lib.rs:41:42 | +| 2 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | fixtures/reject/src/lib.rs:261:16 | +| 2 | `_`, a trait object of the generic trait `_`, which is not supported yet | fixtures/reject/src/lib.rs:503:23 | +| 2 | a coercion to `_` | fixtures/reject/src/lib.rs:355:2 | +| 2 | a coercion to `_`, which is not supported yet | fixtures/reject/src/lib.rs:494:39 | +| 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:168:1 | +| 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:154:23 | +| 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:148:2 | +| 2 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:383:13 | +| 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:77:2 | +| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:407:18 | +| 1 | `_` is not supported: its field `_` is `_`, typed `_`, whose `None` would be `rt.None` as `_` | fixtures/reject/src/lib.rs:31:2 | +| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:300:6 | +| 1 | `_` of `_`, which drops `_`, which is not supported yet | fixtures/reject/src/lib.rs:62:13 | +| 1 | `_` of `_`, which folds a closure that drops beside what else drops, which is not supported yet | fixtures/reject/src/lib.rs:56:23 | +| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:332:2 | | 1 | `_`, a trait object of another crate's trait, which is not supported yet | fixtures/reject/src/lib.rs:11:16 | -| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:315:9 | -| 1 | `f64::mul_add`, which rounds once, where JS would round twice | fixtures/reject/src/lib.rs:477:4 | -| 1 | `fold` of `_`, which folds a `flatten` whose source and iterators both drop, which is not supported yet | fixtures/reject/src/lib.rs:237:26 | -| 1 | a `zip` of `_` and `_`, which std reads by index, of items that drop, which is not supported yet | fixtures/reject/src/lib.rs:242:30 | -| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | fixtures/reject/src/lib.rs:188:51 | -| 1 | a cast from `_` to `_` | fixtures/reject/src/lib.rs:112:2 | -| 1 | a constant of type `_` | fixtures/reject/src/lib.rs:96:2 | -| 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:278:14 | -| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:247:13 | -| 1 | a mutable reference into a `Result`'s payload, passed on or kept | fixtures/reject/src/lib.rs:446:12 | -| 1 | a printable type must implement `Display` or `Debug` | fixtures/reject/src/lib.rs:108:1 | +| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:308:9 | +| 1 | `f64::mul_add`, which rounds once, where JS would round twice | fixtures/reject/src/lib.rs:458:4 | +| 1 | `fold` of `_`, which folds a `flatten` whose source and iterators both drop, which is not supported yet | fixtures/reject/src/lib.rs:230:26 | +| 1 | a `zip` of `_` and `_`, which std reads by index, of items that drop, which is not supported yet | fixtures/reject/src/lib.rs:235:30 | +| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | fixtures/reject/src/lib.rs:181:51 | +| 1 | a cast from `_` to `_` | fixtures/reject/src/lib.rs:105:2 | +| 1 | a constant of type `_` | fixtures/reject/src/lib.rs:89:2 | +| 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:271:14 | +| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:240:13 | +| 1 | a mutable reference into a `Result`'s payload, passed on or kept | fixtures/reject/src/lib.rs:427:12 | +| 1 | a printable type must implement `Display` or `Debug` | fixtures/reject/src/lib.rs:101:1 | | 1 | a scalar constant of type `_` | fixtures/reject/src/lib.rs:8:2 | -| 1 | a trait object of `_`, which is not supported yet | fixtures/reject/src/lib.rs:539:26 | -| 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:78:2 | +| 1 | a trait object of `_`, which is not supported yet | fixtures/reject/src/lib.rs:520:26 | +| 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:71:2 | | 1 | arithmetic on `_` | fixtures/reject/src/lib.rs:8:2 | -| 1 | collecting `_`, whose `None` is `rt.None`, which is not supported yet | fixtures/reject/src/lib.rs:43:43 | -| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:289:52 | -| 1 | constructing `_` | fixtures/reject/src/lib.rs:421:53 | -| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:289:52 | -| 1 | hashing `_` through `_`'s own `Hash::hash_slice`, which is not supported yet | fixtures/reject/src/lib.rs:381:16 | -| 1 | passing `_`, which drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:398:4 | +| 1 | collecting `_`, whose `None` is `rt.None`, which is not supported yet | fixtures/reject/src/lib.rs:36:43 | +| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:282:52 | +| 1 | constructing `_` | fixtures/reject/src/lib.rs:414:53 | +| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:282:52 | +| 1 | hashing `_` through `_`'s own `Hash::hash_slice`, which is not supported yet | fixtures/reject/src/lib.rs:374:16 | +| 1 | passing `_`, which drops, to `_`, which is not supported yet | fixtures/reject/src/lib.rs:391:4 | ## By API @@ -61,172 +60,159 @@ The type or module each refused type or path belongs to. | Count | API | First | | ---: | --- | --- | -| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:403:2 | -| 6 | `Option` | fixtures/reject/src/lib.rs:23:15 | +| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:396:2 | +| 6 | `Option` | fixtures/reject/src/lib.rs:16:15 | | 6 | `f32` | fixtures/reject/src/lib.rs:7:14 | -| 5 | `std::sync::Arc` | fixtures/reject/src/lib.rs:117:2 | -| 4 | `Iterator` | fixtures/reject/src/lib.rs:48:42 | -| 3 | `std::iter::Map` | fixtures/reject/src/lib.rs:63:23 | -| 3 | `std::slice` | fixtures/reject/src/lib.rs:28:4 | -| 3 | `std::vec::Vec` | fixtures/reject/src/lib.rs:289:52 | -| 3 | `u8` | fixtures/reject/src/lib.rs:96:2 | -| 3 | `{closure}` | fixtures/reject/src/lib.rs:390:13 | -| 2 | `HashMap` | fixtures/reject/src/lib.rs:284:6 | -| 2 | `Meters` | fixtures/reject/src/lib.rs:101:2 | -| 2 | `Poll` | fixtures/reject/src/lib.rs:121:20 | -| 2 | `Scaled` | fixtures/reject/src/lib.rs:522:23 | -| 2 | `dyn Scaled` | fixtures/reject/src/lib.rs:522:23 | -| 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:69:13 | -| 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:268:16 | -| 2 | `std::ops::Range` | fixtures/reject/src/lib.rs:196:8 | -| 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:132:2 | -| 2 | `std::vec::IntoIter` | fixtures/reject/src/lib.rs:472:17 | -| 1 | `Batched` | fixtures/reject/src/lib.rs:381:16 | -| 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:175:1 | -| 1 | `Entry` | fixtures/reject/src/lib.rs:390:13 | -| 1 | `FusedIterator` | fixtures/reject/src/lib.rs:229:1 | -| 1 | `Hasher` | fixtures/reject/src/lib.rs:315:9 | -| 1 | `Maybe` | fixtures/reject/src/lib.rs:38:2 | -| 1 | `Noisy` | fixtures/reject/src/lib.rs:69:13 | -| 1 | `T \| undefined` | fixtures/reject/src/lib.rs:38:2 | -| 1 | `Tail` | fixtures/reject/src/lib.rs:549:30 | -| 1 | `[u16; 1]` | fixtures/reject/src/lib.rs:261:22 | -| 1 | `[u8; 4]` | fixtures/reject/src/lib.rs:539:26 | -| 1 | `count` | fixtures/reject/src/lib.rs:63:23 | +| 5 | `std::sync::Arc` | fixtures/reject/src/lib.rs:110:2 | +| 4 | `Iterator` | fixtures/reject/src/lib.rs:41:42 | +| 3 | `std::iter::Map` | fixtures/reject/src/lib.rs:56:23 | +| 3 | `std::vec::Vec` | fixtures/reject/src/lib.rs:282:52 | +| 3 | `u8` | fixtures/reject/src/lib.rs:89:2 | +| 3 | `{closure}` | fixtures/reject/src/lib.rs:383:13 | +| 2 | `HashMap` | fixtures/reject/src/lib.rs:277:6 | +| 2 | `Meters` | fixtures/reject/src/lib.rs:94:2 | +| 2 | `Poll` | fixtures/reject/src/lib.rs:114:20 | +| 2 | `Scaled` | fixtures/reject/src/lib.rs:503:23 | +| 2 | `dyn Scaled` | fixtures/reject/src/lib.rs:503:23 | +| 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:62:13 | +| 2 | `std::iter::Iterator` | fixtures/reject/src/lib.rs:261:16 | +| 2 | `std::ops::Range` | fixtures/reject/src/lib.rs:189:8 | +| 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:125:2 | +| 2 | `std::slice` | fixtures/reject/src/lib.rs:21:4 | +| 2 | `std::vec::IntoIter` | fixtures/reject/src/lib.rs:453:17 | +| 1 | `Batched` | fixtures/reject/src/lib.rs:374:16 | +| 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:168:1 | +| 1 | `Entry` | fixtures/reject/src/lib.rs:383:13 | +| 1 | `FusedIterator` | fixtures/reject/src/lib.rs:222:1 | +| 1 | `Hasher` | fixtures/reject/src/lib.rs:308:9 | +| 1 | `Maybe` | fixtures/reject/src/lib.rs:31:2 | +| 1 | `Noisy` | fixtures/reject/src/lib.rs:62:13 | +| 1 | `T \| undefined` | fixtures/reject/src/lib.rs:31:2 | +| 1 | `Tail` | fixtures/reject/src/lib.rs:530:30 | +| 1 | `[u16; 1]` | fixtures/reject/src/lib.rs:254:22 | +| 1 | `[u8; 4]` | fixtures/reject/src/lib.rs:520:26 | +| 1 | `count` | fixtures/reject/src/lib.rs:56:23 | | 1 | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:11:16 | -| 1 | `f64` | fixtures/reject/src/lib.rs:482:2 | -| 1 | `into_keys` | fixtures/reject/src/lib.rs:69:13 | -| 1 | `std::collections::hash_map::Entry` | fixtures/reject/src/lib.rs:436:15 | -| 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:188:51 | -| 1 | `std::iter::Flatten` | fixtures/reject/src/lib.rs:237:26 | -| 1 | `std::iter::IntoIterator` | fixtures/reject/src/lib.rs:17:2 | -| 1 | `std::iter::Rev` | fixtures/reject/src/lib.rs:182:14 | -| 1 | `std::option::Option` | fixtures/reject/src/lib.rs:453:2 | -| 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:142:11 | -| 1 | `std::string::String` | fixtures/reject/src/lib.rs:90:10 | -| 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:137:2 | -| 1 | `str` | fixtures/reject/src/lib.rs:398:4 | -| 1 | `u32` | fixtures/reject/src/lib.rs:247:13 | -| 1 | `u64` | fixtures/reject/src/lib.rs:112:2 | -| 1 | `value` | fixtures/reject/src/lib.rs:38:2 | -| 1 | `{async closure}` | fixtures/reject/src/lib.rs:78:2 | +| 1 | `f64` | fixtures/reject/src/lib.rs:463:2 | +| 1 | `into_keys` | fixtures/reject/src/lib.rs:62:13 | +| 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:181:51 | +| 1 | `std::iter::Flatten` | fixtures/reject/src/lib.rs:230:26 | +| 1 | `std::iter::Rev` | fixtures/reject/src/lib.rs:175:14 | +| 1 | `std::option::Option` | fixtures/reject/src/lib.rs:434:2 | +| 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:135:11 | +| 1 | `std::string::String` | fixtures/reject/src/lib.rs:83:10 | +| 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:130:2 | +| 1 | `str` | fixtures/reject/src/lib.rs:391:4 | +| 1 | `u32` | fixtures/reject/src/lib.rs:240:13 | +| 1 | `u64` | fixtures/reject/src/lib.rs:105:2 | +| 1 | `value` | fixtures/reject/src/lib.rs:31:2 | +| 1 | `{async closure}` | fixtures/reject/src/lib.rs:71:2 | ## By type or path | Count | Construct | Type or path | First | | ---: | --- | --- | --- | -| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:403:2 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:396:2 | | 3 | unsupported type `_` | `f32` | fixtures/reject/src/lib.rs:7:14 | -| 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:121:20 | -| 2 | `_` is not supported: its `None` and `Some` would both be `rt.None` | `Option` | fixtures/reject/src/lib.rs:23:15 | -| 2 | `_`, a trait object of the generic trait `_`, which is not supported yet | `dyn Scaled`, `Scaled` | fixtures/reject/src/lib.rs:522:23 | -| 2 | a coercion to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:362:2 | -| 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:132:2 | -| 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:101:2 | -| 2 | unsupported call to `_` | `::sum` | fixtures/reject/src/lib.rs:472:17 | -| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:414:18 | -| 1 | `_` is not supported: its field `_` is `_`, typed `_`, whose `None` would be `rt.None` as `_` | `Maybe`, `value`, `Option`, `T \| undefined`, `Option` | fixtures/reject/src/lib.rs:38:2 | -| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:307:6 | -| 1 | `_` of `_`, which drops `_`, which is not supported yet | `into_keys`, `std::collections::HashMap`, `Noisy` | fixtures/reject/src/lib.rs:69:13 | -| 1 | `_` of `_`, which folds a closure that drops beside what else drops, which is not supported yet | `count`, `std::iter::Map` | fixtures/reject/src/lib.rs:63:23 | -| 1 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `HashMap::get`, `Option` | fixtures/reject/src/lib.rs:284:6 | -| 1 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `Iterator::find`, `Option` | fixtures/reject/src/lib.rs:48:42 | -| 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::count` | fixtures/reject/src/lib.rs:268:38 | -| 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::filter` | fixtures/reject/src/lib.rs:268:16 | -| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:339:2 | -| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::collections::hash_map::Entry::and_modify` | fixtures/reject/src/lib.rs:436:15 | -| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::iter::IntoIterator::into_iter` | fixtures/reject/src/lib.rs:17:2 | -| 1 | `_` with a mutable reference to a value JS copies, which its mapping would copy | `std::slice::last_mut` | fixtures/reject/src/lib.rs:429:21 | +| 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:114:20 | +| 2 | `_` is not supported: its `None` and `Some` would both be `rt.None` | `Option` | fixtures/reject/src/lib.rs:16:15 | +| 2 | `_`, a trait object of the generic trait `_`, which is not supported yet | `dyn Scaled`, `Scaled` | fixtures/reject/src/lib.rs:503:23 | +| 2 | a coercion to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:355:2 | +| 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:125:2 | +| 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:94:2 | +| 2 | unsupported call to `_` | `::sum` | fixtures/reject/src/lib.rs:453:17 | +| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:407:18 | +| 1 | `_` is not supported: its field `_` is `_`, typed `_`, whose `None` would be `rt.None` as `_` | `Maybe`, `value`, `Option`, `T \| undefined`, `Option` | fixtures/reject/src/lib.rs:31:2 | +| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:300:6 | +| 1 | `_` of `_`, which drops `_`, which is not supported yet | `into_keys`, `std::collections::HashMap`, `Noisy` | fixtures/reject/src/lib.rs:62:13 | +| 1 | `_` of `_`, which folds a closure that drops beside what else drops, which is not supported yet | `count`, `std::iter::Map` | fixtures/reject/src/lib.rs:56:23 | +| 1 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `HashMap::get`, `Option` | fixtures/reject/src/lib.rs:277:6 | +| 1 | `_` of `_`, whose `None` is `rt.None`, which is not supported yet | `Iterator::find`, `Option` | fixtures/reject/src/lib.rs:41:42 | +| 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::count` | fixtures/reject/src/lib.rs:261:38 | +| 1 | `_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it | `std::iter::Iterator::filter` | fixtures/reject/src/lib.rs:261:16 | +| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:332:2 | | 1 | `_`, a trait object of another crate's trait, which is not supported yet | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:11:16 | -| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:315:9 | -| 1 | `fold` of `_`, which folds a `flatten` whose source and iterators both drop, which is not supported yet | `std::iter::Flatten` | fixtures/reject/src/lib.rs:237:26 | -| 1 | a `zip` of `_` and `_`, which std reads by index, of items that drop, which is not supported yet | `std::iter::Map`, `std::ops::Range` | fixtures/reject/src/lib.rs:242:30 | -| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | `std::iter::Chain` | fixtures/reject/src/lib.rs:188:51 | -| 1 | a cast from `_` to `_` | `u64`, `f32` | fixtures/reject/src/lib.rs:112:2 | -| 1 | a coercion to `_`, which is not supported yet | `&Tail` | fixtures/reject/src/lib.rs:549:30 | -| 1 | a coercion to `_`, which is not supported yet | `std::sync::Arc` | fixtures/reject/src/lib.rs:513:39 | -| 1 | a constant of type `_` | `&u8` | fixtures/reject/src/lib.rs:96:2 | -| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | `u32` | fixtures/reject/src/lib.rs:247:13 | +| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:308:9 | +| 1 | `fold` of `_`, which folds a `flatten` whose source and iterators both drop, which is not supported yet | `std::iter::Flatten` | fixtures/reject/src/lib.rs:230:26 | +| 1 | a `zip` of `_` and `_`, which std reads by index, of items that drop, which is not supported yet | `std::iter::Map`, `std::ops::Range` | fixtures/reject/src/lib.rs:235:30 | +| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | `std::iter::Chain` | fixtures/reject/src/lib.rs:181:51 | +| 1 | a cast from `_` to `_` | `u64`, `f32` | fixtures/reject/src/lib.rs:105:2 | +| 1 | a coercion to `_`, which is not supported yet | `&Tail` | fixtures/reject/src/lib.rs:530:30 | +| 1 | a coercion to `_`, which is not supported yet | `std::sync::Arc` | fixtures/reject/src/lib.rs:494:39 | +| 1 | a constant of type `_` | `&u8` | fixtures/reject/src/lib.rs:89:2 | +| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | `u32` | fixtures/reject/src/lib.rs:240:13 | | 1 | a scalar constant of type `_` | `f32` | fixtures/reject/src/lib.rs:8:2 | -| 1 | a trait object of `_`, which is not supported yet | `[u8; 4]` | fixtures/reject/src/lib.rs:539:26 | -| 1 | a zero-sized constant of type `_` | `{async closure}` | fixtures/reject/src/lib.rs:78:2 | -| 1 | an assignment through a reference to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:117:2 | -| 1 | an assignment through a reference to `_` | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:137:2 | -| 1 | an iterator of the crate implementing `_`, which is not supported yet | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:175:1 | -| 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:229:1 | +| 1 | a trait object of `_`, which is not supported yet | `[u8; 4]` | fixtures/reject/src/lib.rs:520:26 | +| 1 | a zero-sized constant of type `_` | `{async closure}` | fixtures/reject/src/lib.rs:71:2 | +| 1 | an assignment through a reference to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:110:2 | +| 1 | an assignment through a reference to `_` | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:130:2 | +| 1 | an iterator of the crate implementing `_`, which is not supported yet | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:168:1 | +| 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:222:1 | | 1 | arithmetic on `_` | `f32` | fixtures/reject/src/lib.rs:8:2 | -| 1 | collecting `_`, whose `None` is `rt.None`, which is not supported yet | `Option` | fixtures/reject/src/lib.rs:43:43 | -| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:289:52 | -| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:421:53 | -| 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:161:23 | -| 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:182:14 | -| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:289:52 | -| 1 | hashing `_` through `_`'s own `Hash::hash_slice`, which is not supported yet | `std::vec::Vec`, `Batched` | fixtures/reject/src/lib.rs:381:16 | -| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:155:2 | -| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:209:2 | -| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Entry::or_insert_with` | fixtures/reject/src/lib.rs:390:13 | -| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Iterator::for_each` | fixtures/reject/src/lib.rs:391:16 | -| 1 | passing `_`, which drops, to `_`, which is not supported yet | `{closure}`, `str::contains` | fixtures/reject/src/lib.rs:398:4 | -| 1 | replacing the value behind a reference to `_` | `[u16; 1]` | fixtures/reject/src/lib.rs:261:22 | -| 1 | unsupported call to `_` | `::fmt` | fixtures/reject/src/lib.rs:482:2 | -| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:415:2 | -| 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:453:2 | -| 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:142:11 | -| 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:90:10 | -| 1 | unsupported call to `_` | `::hash` | fixtures/reject/src/lib.rs:372:10 | -| 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:196:8 | -| 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:357:4 | -| 1 | unsupported call to `_` | `std::slice::sort` | fixtures/reject/src/lib.rs:28:4 | +| 1 | collecting `_`, whose `None` is `rt.None`, which is not supported yet | `Option` | fixtures/reject/src/lib.rs:36:43 | +| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:282:52 | +| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:414:53 | +| 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:154:23 | +| 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:175:14 | +| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:282:52 | +| 1 | hashing `_` through `_`'s own `Hash::hash_slice`, which is not supported yet | `std::vec::Vec`, `Batched` | fixtures/reject/src/lib.rs:374:16 | +| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:148:2 | +| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:202:2 | +| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Entry::or_insert_with` | fixtures/reject/src/lib.rs:383:13 | +| 1 | passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet | `{closure}`, `Iterator::for_each` | fixtures/reject/src/lib.rs:384:16 | +| 1 | passing `_`, which drops, to `_`, which is not supported yet | `{closure}`, `str::contains` | fixtures/reject/src/lib.rs:391:4 | +| 1 | replacing the value behind a reference to `_` | `[u16; 1]` | fixtures/reject/src/lib.rs:254:22 | +| 1 | unsupported call to `_` | `::fmt` | fixtures/reject/src/lib.rs:463:2 | +| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:408:2 | +| 1 | unsupported call to `_` | `::eq` | fixtures/reject/src/lib.rs:434:2 | +| 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:135:11 | +| 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:83:10 | +| 1 | unsupported call to `_` | `::hash` | fixtures/reject/src/lib.rs:365:10 | +| 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:189:8 | +| 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:350:4 | +| 1 | unsupported call to `_` | `std::slice::sort` | fixtures/reject/src/lib.rs:21:4 | ## Spans
unsupported call to `_` (11) -- fixtures/reject/src/lib.rs:28:4: unsupported call to `std::slice::::sort` -- fixtures/reject/src/lib.rs:90:10: unsupported call to `::write_fmt` -- fixtures/reject/src/lib.rs:142:11: unsupported call to ` as std::iter::Iterator>::cycle` -- fixtures/reject/src/lib.rs:196:8: unsupported call to `std::ops::Range::::contains::` -- fixtures/reject/src/lib.rs:357:4: unsupported call to `core::slice::::copy_within::>` -- fixtures/reject/src/lib.rs:372:10: unsupported call to `::hash::` -- fixtures/reject/src/lib.rs:415:2: unsupported call to ` as std::ops::Deref>::deref` -- fixtures/reject/src/lib.rs:453:2: unsupported call to ` as std::cmp::PartialEq>::eq` -- fixtures/reject/src/lib.rs:472:17: unsupported call to ` as std::iter::Iterator>::sum::` -- fixtures/reject/src/lib.rs:472:38: unsupported call to ` as std::iter::Iterator>::sum::` -- fixtures/reject/src/lib.rs:482:2: unsupported call to `::fmt` +- fixtures/reject/src/lib.rs:21:4: unsupported call to `std::slice::::sort` +- fixtures/reject/src/lib.rs:83:10: unsupported call to `::write_fmt` +- fixtures/reject/src/lib.rs:135:11: unsupported call to ` as std::iter::Iterator>::cycle` +- fixtures/reject/src/lib.rs:189:8: unsupported call to `std::ops::Range::::contains::` +- fixtures/reject/src/lib.rs:350:4: unsupported call to `core::slice::::copy_within::>` +- fixtures/reject/src/lib.rs:365:10: unsupported call to `::hash::` +- fixtures/reject/src/lib.rs:408:2: unsupported call to ` as std::ops::Deref>::deref` +- fixtures/reject/src/lib.rs:434:2: unsupported call to ` as std::cmp::PartialEq>::eq` +- fixtures/reject/src/lib.rs:453:17: unsupported call to ` as std::iter::Iterator>::sum::` +- fixtures/reject/src/lib.rs:453:38: unsupported call to ` as std::iter::Iterator>::sum::` +- fixtures/reject/src/lib.rs:463:2: unsupported call to `::fmt`
a variant of `_`, which is not supported: either is the same JS string (4) +- fixtures/reject/src/lib.rs:396:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:397:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:398:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string - fixtures/reject/src/lib.rs:403:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:404:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:405:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string -- fixtures/reject/src/lib.rs:410:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string
an assignment through a reference to `_` (4) -- fixtures/reject/src/lib.rs:117:2: an assignment through a reference to `std::sync::Arc` -- fixtures/reject/src/lib.rs:132:2: an assignment through a reference to `std::pin::Pin>` -- fixtures/reject/src/lib.rs:137:2: an assignment through a reference to `std::sync::MutexGuard<'_, u8>` -- fixtures/reject/src/lib.rs:255:2: an assignment through a reference to `std::pin::Pin<&mut Noisy>` - -
- -
`_` with a mutable reference to a value JS copies, which its mapping would copy (3) - -- fixtures/reject/src/lib.rs:17:2: `std::iter::IntoIterator::into_iter` with a mutable reference to a value JS copies, which its mapping would copy -- fixtures/reject/src/lib.rs:429:21: `core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy -- fixtures/reject/src/lib.rs:436:15: `std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy +- fixtures/reject/src/lib.rs:110:2: an assignment through a reference to `std::sync::Arc` +- fixtures/reject/src/lib.rs:125:2: an assignment through a reference to `std::pin::Pin>` +- fixtures/reject/src/lib.rs:130:2: an assignment through a reference to `std::sync::MutexGuard<'_, u8>` +- fixtures/reject/src/lib.rs:248:2: an assignment through a reference to `std::pin::Pin<&mut Noisy>`
replacing the value behind a reference to `_` (3) -- fixtures/reject/src/lib.rs:101:2: replacing the value behind a reference to `Meters` -- fixtures/reject/src/lib.rs:105:2: replacing the value behind a reference to `Meters` -- fixtures/reject/src/lib.rs:261:22: replacing the value behind a reference to `[u16; 1]` +- fixtures/reject/src/lib.rs:94:2: replacing the value behind a reference to `Meters` +- fixtures/reject/src/lib.rs:98:2: replacing the value behind a reference to `Meters` +- fixtures/reject/src/lib.rs:254:22: replacing the value behind a reference to `[u16; 1]`
@@ -234,126 +220,126 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:7:14: unsupported type `f32` - fixtures/reject/src/lib.rs:7:25: unsupported type `f32` -- fixtures/reject/src/lib.rs:110:51: unsupported type `f32` +- fixtures/reject/src/lib.rs:103:51: unsupported type `f32`
`_` is not supported: it would be pending two ways with one value (2) -- fixtures/reject/src/lib.rs:121:20: `Poll>>` is not supported: it would be pending two ways with one value -- fixtures/reject/src/lib.rs:126:54: `Poll>` is not supported: it would be pending two ways with one value +- fixtures/reject/src/lib.rs:114:20: `Poll>>` is not supported: it would be pending two ways with one value +- fixtures/reject/src/lib.rs:119:54: `Poll>` is not supported: it would be pending two ways with one value
`_` is not supported: its `None` and `Some` would both be `rt.None` (2) -- fixtures/reject/src/lib.rs:23:15: `Option>>` is not supported: its `None` and `Some` would both be `rt.None` -- fixtures/reject/src/lib.rs:24:2: `Option>>` is not supported: its `None` and `Some` would both be `rt.None` +- fixtures/reject/src/lib.rs:16:15: `Option>>` is not supported: its `None` and `Some` would both be `rt.None` +- fixtures/reject/src/lib.rs:17:2: `Option>>` is not supported: its `None` and `Some` would both be `rt.None`
`_` of `_`, whose `None` is `rt.None`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:48:42: `Iterator::find` of `Option>`, whose `None` is `rt.None`, which is not supported yet -- fixtures/reject/src/lib.rs:284:6: `HashMap::get` of `Option<&std::option::Option>`, whose `None` is `rt.None`, which is not supported yet +- fixtures/reject/src/lib.rs:41:42: `Iterator::find` of `Option>`, whose `None` is `rt.None`, which is not supported yet +- fixtures/reject/src/lib.rs:277:6: `HashMap::get` of `Option<&std::option::Option>`, whose `None` is `rt.None`, which is not supported yet
`_` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it (2) -- fixtures/reject/src/lib.rs:268:16: `std::iter::Iterator::filter` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it -- fixtures/reject/src/lib.rs:268:38: `std::iter::Iterator::count` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it +- fixtures/reject/src/lib.rs:261:16: `std::iter::Iterator::filter` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it +- fixtures/reject/src/lib.rs:261:38: `std::iter::Iterator::count` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it
`_`, a trait object of the generic trait `_`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:522:23: `dyn Scaled`, a trait object of the generic trait `Scaled`, which is not supported yet -- fixtures/reject/src/lib.rs:523:4: `dyn Scaled`, a trait object of the generic trait `Scaled`, which is not supported yet +- fixtures/reject/src/lib.rs:503:23: `dyn Scaled`, a trait object of the generic trait `Scaled`, which is not supported yet +- fixtures/reject/src/lib.rs:504:4: `dyn Scaled`, a trait object of the generic trait `Scaled`, which is not supported yet
a coercion to `_` (2) -- fixtures/reject/src/lib.rs:362:2: a coercion to `std::sync::Arc<[u8]>` -- fixtures/reject/src/lib.rs:488:2: a coercion to `std::sync::Arc>` +- fixtures/reject/src/lib.rs:355:2: a coercion to `std::sync::Arc<[u8]>` +- fixtures/reject/src/lib.rs:469:2: a coercion to `std::sync::Arc>`
a coercion to `_`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:513:39: a coercion to `std::sync::Arc`, which is not supported yet -- fixtures/reject/src/lib.rs:549:30: a coercion to `&Tail`, which is not supported yet +- fixtures/reject/src/lib.rs:494:39: a coercion to `std::sync::Arc`, which is not supported yet +- fixtures/reject/src/lib.rs:530:30: a coercion to `&Tail`, which is not supported yet
an iterator of the crate implementing `_`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:175:1: an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet -- fixtures/reject/src/lib.rs:229:1: an iterator of the crate implementing `FusedIterator`, which is not supported yet +- fixtures/reject/src/lib.rs:168:1: an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet +- fixtures/reject/src/lib.rs:222:1: an iterator of the crate implementing `FusedIterator`, which is not supported yet
constructing `_` from another crate (2) -- fixtures/reject/src/lib.rs:161:23: constructing `std::iter::Map` from another crate -- fixtures/reject/src/lib.rs:182:14: constructing `std::iter::Rev` from another crate +- fixtures/reject/src/lib.rs:154:23: constructing `std::iter::Map` from another crate +- fixtures/reject/src/lib.rs:175:14: constructing `std::iter::Rev` from another crate
overriding `_`, which std's adaptors call in place of `next` or beside it (2) -- fixtures/reject/src/lib.rs:155:2: overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it -- fixtures/reject/src/lib.rs:209:2: overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it +- fixtures/reject/src/lib.rs:148:2: overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it +- fixtures/reject/src/lib.rs:202:2: overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it
passing `_`, a closure that owns a value that drops, to `_`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:390:13: passing `{closure@fixtures/reject/src/lib.rs:390:28: 390:35}`, a closure that owns a value that drops, to `Entry::or_insert_with`, which is not supported yet -- fixtures/reject/src/lib.rs:391:16: passing `{closure@fixtures/reject/src/lib.rs:391:25: 391:33}`, a closure that owns a value that drops, to `Iterator::for_each`, which is not supported yet +- fixtures/reject/src/lib.rs:383:13: passing `{closure@fixtures/reject/src/lib.rs:383:28: 383:35}`, a closure that owns a value that drops, to `Entry::or_insert_with`, which is not supported yet +- fixtures/reject/src/lib.rs:384:16: passing `{closure@fixtures/reject/src/lib.rs:384:25: 384:33}`, a closure that owns a value that drops, to `Iterator::for_each`, which is not supported yet
`Pointer` formatting, as in `{:p}`, is not supported (1) -- fixtures/reject/src/lib.rs:84:2: `Pointer` formatting, as in `{:p}`, is not supported +- fixtures/reject/src/lib.rs:77:2: `Pointer` formatting, as in `{:p}`, is not supported
`_` is not supported yet (1) -- fixtures/reject/src/lib.rs:414:18: `std::borrow::Cow<'_, [u8]>` is not supported yet +- fixtures/reject/src/lib.rs:407:18: `std::borrow::Cow<'_, [u8]>` is not supported yet
`_` is not supported: its field `_` is `_`, typed `_`, whose `None` would be `rt.None` as `_` (1) -- fixtures/reject/src/lib.rs:38:2: `Maybe<()>` is not supported: its field `value` is `Option`, typed `T | undefined`, whose `None` would be `rt.None` as `Option<()>` +- fixtures/reject/src/lib.rs:31:2: `Maybe<()>` is not supported: its field `value` is `Option`, typed `T | undefined`, whose `None` would be `rt.None` as `Option<()>`
`_` of `_` by `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:307:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet +- fixtures/reject/src/lib.rs:300:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet
`_` of `_`, which drops `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:69:13: `into_keys` of `std::collections::HashMap`, which drops `Noisy`, which is not supported yet +- fixtures/reject/src/lib.rs:62:13: `into_keys` of `std::collections::HashMap`, which drops `Noisy`, which is not supported yet
`_` of `_`, which folds a closure that drops beside what else drops, which is not supported yet (1) -- fixtures/reject/src/lib.rs:63:23: `count` of `std::iter::Map, {closure@fixtures/reject/src/lib.rs:62:10: 62:25}>`, which folds a closure that drops beside what else drops, which is not supported yet +- fixtures/reject/src/lib.rs:56:23: `count` of `std::iter::Map, {closure@fixtures/reject/src/lib.rs:55:10: 55:25}>`, which folds a closure that drops beside what else drops, which is not supported yet
`_` through a held type's own, which is not supported yet (1) -- fixtures/reject/src/lib.rs:339:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet +- fixtures/reject/src/lib.rs:332:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet
@@ -365,67 +351,67 @@ The type or module each refused type or path belongs to.
`_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:315:9: `Hasher::write`, which is not supported yet +- fixtures/reject/src/lib.rs:308:9: `Hasher::write`, which is not supported yet
`f64::mul_add`, which rounds once, where JS would round twice (1) -- fixtures/reject/src/lib.rs:477:4: `f64::mul_add`, which rounds once, where JS would round twice +- fixtures/reject/src/lib.rs:458:4: `f64::mul_add`, which rounds once, where JS would round twice
`fold` of `_`, which folds a `flatten` whose source and iterators both drop, which is not supported yet (1) -- fixtures/reject/src/lib.rs:237:26: `fold` of `std::iter::Flatten>>`, which folds a `flatten` whose source and iterators both drop, which is not supported yet +- fixtures/reject/src/lib.rs:230:26: `fold` of `std::iter::Flatten>>`, which folds a `flatten` whose source and iterators both drop, which is not supported yet
a `zip` of `_` and `_`, which std reads by index, of items that drop, which is not supported yet (1) -- fixtures/reject/src/lib.rs:242:30: a `zip` of `std::iter::Map, {closure@fixtures/reject/src/lib.rs:242:15: 242:19}>` and `std::ops::Range`, which std reads by index, of items that drop, which is not supported yet +- fixtures/reject/src/lib.rs:235:30: a `zip` of `std::iter::Map, {closure@fixtures/reject/src/lib.rs:235:15: 235:19}>` and `std::ops::Range`, which std reads by index, of items that drop, which is not supported yet
a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` (1) -- fixtures/reject/src/lib.rs:188:51: a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:188:15: 188:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` +- fixtures/reject/src/lib.rs:181:51: a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:181:15: 181:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold`
a cast from `_` to `_` (1) -- fixtures/reject/src/lib.rs:112:2: a cast from `u64` to `f32` +- fixtures/reject/src/lib.rs:105:2: a cast from `u64` to `f32`
a constant of type `_` (1) -- fixtures/reject/src/lib.rs:96:2: a constant of type `&u8` +- fixtures/reject/src/lib.rs:89:2: a constant of type `&u8`
a copy of a closure that changes what it captured (1) -- fixtures/reject/src/lib.rs:278:14: a copy of a closure that changes what it captured +- fixtures/reject/src/lib.rs:271:14: a copy of a closure that changes what it captured
a mutable borrow of a subslice of `_`, which JS would copy, having no views (1) -- fixtures/reject/src/lib.rs:247:13: a mutable borrow of a subslice of `u32`, which JS would copy, having no views +- fixtures/reject/src/lib.rs:240:13: a mutable borrow of a subslice of `u32`, which JS would copy, having no views
a mutable reference into a `Result`'s payload, passed on or kept (1) -- fixtures/reject/src/lib.rs:446:12: a mutable reference into a `Result`'s payload, passed on or kept +- fixtures/reject/src/lib.rs:427:12: a mutable reference into a `Result`'s payload, passed on or kept
a printable type must implement `Display` or `Debug` (1) -- fixtures/reject/src/lib.rs:108:1: a printable type must implement `Display` or `Debug` +- fixtures/reject/src/lib.rs:101:1: a printable type must implement `Display` or `Debug`
@@ -437,13 +423,13 @@ The type or module each refused type or path belongs to.
a trait object of `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:539:26: a trait object of `[u8; 4]`, which is not supported yet +- fixtures/reject/src/lib.rs:520:26: a trait object of `[u8; 4]`, which is not supported yet
a zero-sized constant of type `_` (1) -- fixtures/reject/src/lib.rs:78:2: a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:77:10: 77:18}` +- fixtures/reject/src/lib.rs:71:2: a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:70:10: 70:18}`
@@ -455,36 +441,36 @@ The type or module each refused type or path belongs to.
collecting `_`, whose `None` is `rt.None`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:43:43: collecting `Option<()>`, whose `None` is `rt.None`, which is not supported yet +- fixtures/reject/src/lib.rs:36:43: collecting `Option<()>`, whose `None` is `rt.None`, which is not supported yet
comparing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:289:52: comparing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:282:52: comparing `std::vec::Vec` as a key, which is not supported yet
constructing `_` (1) -- fixtures/reject/src/lib.rs:421:53: constructing `std::borrow::Cow<'_, std::sync::Arc>` +- fixtures/reject/src/lib.rs:414:53: constructing `std::borrow::Cow<'_, std::sync::Arc>`
hashing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:289:52: hashing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:282:52: hashing `std::vec::Vec` as a key, which is not supported yet
hashing `_` through `_`'s own `Hash::hash_slice`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:381:16: hashing `std::vec::Vec` through `Batched`'s own `Hash::hash_slice`, which is not supported yet +- fixtures/reject/src/lib.rs:374:16: hashing `std::vec::Vec` through `Batched`'s own `Hash::hash_slice`, which is not supported yet
passing `_`, which drops, to `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:398:4: passing `{closure@fixtures/reject/src/lib.rs:398:13: 398:27}`, which drops, to `str::contains`, which is not supported yet +- fixtures/reject/src/lib.rs:391:4: passing `{closure@fixtures/reject/src/lib.rs:391:13: 391:27}`, which drops, to `str::contains`, which is not supported yet
diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index e59288e1e..892d2bc96 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -1,78 +1,75 @@ -a root must not be generic at fixtures/reject/src/lib.rs:110:1 +a root must not be generic at fixtures/reject/src/lib.rs:103:1 no item `lopsided` in the crate no item `missing` in the crate -a printable type must implement `Display` or `Debug` at fixtures/reject/src/lib.rs:108:1 +a printable type must implement `Display` or `Debug` at fixtures/reject/src/lib.rs:101:1 unsupported type `f32` at fixtures/reject/src/lib.rs:7:14 a scalar constant of type `f32` at fixtures/reject/src/lib.rs:8:2 arithmetic on `f32` at fixtures/reject/src/lib.rs:8:2 unsupported type `f32` at fixtures/reject/src/lib.rs:7:25 `dyn std::ops::Fn(u8) -> u8`, a trait object of another crate's trait, which is not supported yet at fixtures/reject/src/lib.rs:11:16 -`std::iter::IntoIterator::into_iter` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:17:11 -`Option>>` is not supported: its `None` and `Some` would both be `rt.None` at fixtures/reject/src/lib.rs:24:2 -`Option>>` is not supported: its `None` and `Some` would both be `rt.None` at fixtures/reject/src/lib.rs:23:15 -unsupported call to `std::slice::::sort` at fixtures/reject/src/lib.rs:28:4 -`Iterator::find` of `Option>`, whose `None` is `rt.None`, which is not supported yet at fixtures/reject/src/lib.rs:48:42 -`Maybe<()>` is not supported: its field `value` is `Option`, typed `T | undefined`, whose `None` would be `rt.None` as `Option<()>` at fixtures/reject/src/lib.rs:38:2 -collecting `Option<()>`, whose `None` is `rt.None`, which is not supported yet at fixtures/reject/src/lib.rs:43:43 -`count` of `std::iter::Map, {closure@fixtures/reject/src/lib.rs:62:10: 62:25}>`, which folds a closure that drops beside what else drops, which is not supported yet at fixtures/reject/src/lib.rs:63:23 -`into_keys` of `std::collections::HashMap`, which drops `Noisy`, which is not supported yet at fixtures/reject/src/lib.rs:69:13 -a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:77:10: 77:18}` at fixtures/reject/src/lib.rs:78:2 -`Pointer` formatting, as in `{:p}`, is not supported at fixtures/reject/src/lib.rs:84:11 -unsupported call to `::write_fmt` at fixtures/reject/src/lib.rs:90:10 -a constant of type `&u8` at fixtures/reject/src/lib.rs:96:2 -replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:101:2 -replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:105:2 -an assignment through a reference to `std::sync::Arc` at fixtures/reject/src/lib.rs:117:2 -`Poll>>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:121:20 -`Poll>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:126:54 -a coercion to `std::sync::Arc>` at fixtures/reject/src/lib.rs:488:2 -an assignment through a reference to `std::pin::Pin>` at fixtures/reject/src/lib.rs:132:2 -an assignment through a reference to `std::sync::MutexGuard<'_, u8>` at fixtures/reject/src/lib.rs:137:2 -unsupported call to ` as std::iter::Iterator>::cycle` at fixtures/reject/src/lib.rs:142:11 -constructing `std::iter::Map` from another crate at fixtures/reject/src/lib.rs:161:23 -constructing `std::iter::Rev` from another crate at fixtures/reject/src/lib.rs:182:14 -a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:188:15: 188:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` at fixtures/reject/src/lib.rs:188:51 -unsupported call to `std::ops::Range::::contains::` at fixtures/reject/src/lib.rs:196:8 -`fold` of `std::iter::Flatten>>`, which folds a `flatten` whose source and iterators both drop, which is not supported yet at fixtures/reject/src/lib.rs:237:26 -a `zip` of `std::iter::Map, {closure@fixtures/reject/src/lib.rs:242:15: 242:19}>` and `std::ops::Range`, which std reads by index, of items that drop, which is not supported yet at fixtures/reject/src/lib.rs:242:30 -a mutable borrow of a subslice of `u32`, which JS would copy, having no views at fixtures/reject/src/lib.rs:247:13 -an assignment through a reference to `std::pin::Pin<&mut Noisy>` at fixtures/reject/src/lib.rs:255:2 -replacing the value behind a reference to `[u16; 1]` at fixtures/reject/src/lib.rs:261:22 -`std::iter::Iterator::filter` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:268:16 -`std::iter::Iterator::count` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:268:38 -a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs:278:14 -`HashMap::get` of `Option<&std::option::Option>`, whose `None` is `rt.None`, which is not supported yet at fixtures/reject/src/lib.rs:284:6 -hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:289:52 -comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:289:52 -`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:307:6 -unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:357:4 -a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:362:2 +`Option>>` is not supported: its `None` and `Some` would both be `rt.None` at fixtures/reject/src/lib.rs:17:2 +`Option>>` is not supported: its `None` and `Some` would both be `rt.None` at fixtures/reject/src/lib.rs:16:15 +unsupported call to `std::slice::::sort` at fixtures/reject/src/lib.rs:21:4 +`Iterator::find` of `Option>`, whose `None` is `rt.None`, which is not supported yet at fixtures/reject/src/lib.rs:41:42 +`Maybe<()>` is not supported: its field `value` is `Option`, typed `T | undefined`, whose `None` would be `rt.None` as `Option<()>` at fixtures/reject/src/lib.rs:31:2 +collecting `Option<()>`, whose `None` is `rt.None`, which is not supported yet at fixtures/reject/src/lib.rs:36:43 +`count` of `std::iter::Map, {closure@fixtures/reject/src/lib.rs:55:10: 55:25}>`, which folds a closure that drops beside what else drops, which is not supported yet at fixtures/reject/src/lib.rs:56:23 +`into_keys` of `std::collections::HashMap`, which drops `Noisy`, which is not supported yet at fixtures/reject/src/lib.rs:62:13 +a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:70:10: 70:18}` at fixtures/reject/src/lib.rs:71:2 +`Pointer` formatting, as in `{:p}`, is not supported at fixtures/reject/src/lib.rs:77:11 +unsupported call to `::write_fmt` at fixtures/reject/src/lib.rs:83:10 +a constant of type `&u8` at fixtures/reject/src/lib.rs:89:2 +replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:94:2 +replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:98:2 +an assignment through a reference to `std::sync::Arc` at fixtures/reject/src/lib.rs:110:2 +`Poll>>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:114:20 +`Poll>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:119:54 +a coercion to `std::sync::Arc>` at fixtures/reject/src/lib.rs:469:2 +an assignment through a reference to `std::pin::Pin>` at fixtures/reject/src/lib.rs:125:2 +an assignment through a reference to `std::sync::MutexGuard<'_, u8>` at fixtures/reject/src/lib.rs:130:2 +unsupported call to ` as std::iter::Iterator>::cycle` at fixtures/reject/src/lib.rs:135:11 +constructing `std::iter::Map` from another crate at fixtures/reject/src/lib.rs:154:23 +constructing `std::iter::Rev` from another crate at fixtures/reject/src/lib.rs:175:14 +a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:181:15: 181:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` at fixtures/reject/src/lib.rs:181:51 +unsupported call to `std::ops::Range::::contains::` at fixtures/reject/src/lib.rs:189:8 +`fold` of `std::iter::Flatten>>`, which folds a `flatten` whose source and iterators both drop, which is not supported yet at fixtures/reject/src/lib.rs:230:26 +a `zip` of `std::iter::Map, {closure@fixtures/reject/src/lib.rs:235:15: 235:19}>` and `std::ops::Range`, which std reads by index, of items that drop, which is not supported yet at fixtures/reject/src/lib.rs:235:30 +a mutable borrow of a subslice of `u32`, which JS would copy, having no views at fixtures/reject/src/lib.rs:240:13 +an assignment through a reference to `std::pin::Pin<&mut Noisy>` at fixtures/reject/src/lib.rs:248:2 +replacing the value behind a reference to `[u16; 1]` at fixtures/reject/src/lib.rs:254:22 +`std::iter::Iterator::filter` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:261:16 +`std::iter::Iterator::count` of a reference to an array of bytes it is generic over, which its mapping would take as the array, not as a slice of it at fixtures/reject/src/lib.rs:261:38 +a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs:271:14 +`HashMap::get` of `Option<&std::option::Option>`, whose `None` is `rt.None`, which is not supported yet at fixtures/reject/src/lib.rs:277:6 +hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:282:52 +comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:282:52 +`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:300:6 +unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:350:4 +a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:355:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:396:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:398:27 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:397:30 a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:403:2 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:405:27 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:404:30 -a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:410:2 -`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:414:18 -unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:415:2 -constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:421:53 -hashing `std::vec::Vec` through `Batched`'s own `Hash::hash_slice`, which is not supported yet at fixtures/reject/src/lib.rs:381:16 -passing `{closure@fixtures/reject/src/lib.rs:390:28: 390:35}`, a closure that owns a value that drops, to `Entry::or_insert_with`, which is not supported yet at fixtures/reject/src/lib.rs:390:13 -passing `{closure@fixtures/reject/src/lib.rs:391:25: 391:33}`, a closure that owns a value that drops, to `Iterator::for_each`, which is not supported yet at fixtures/reject/src/lib.rs:391:16 -passing `{closure@fixtures/reject/src/lib.rs:398:13: 398:27}`, which drops, to `str::contains`, which is not supported yet at fixtures/reject/src/lib.rs:398:4 -unsupported call to ` as std::iter::Iterator>::sum::` at fixtures/reject/src/lib.rs:472:17 -unsupported call to ` as std::iter::Iterator>::sum::` at fixtures/reject/src/lib.rs:472:38 -`core::slice::::last_mut` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:429:21 -`std::collections::hash_map::Entry::<'a, K, V, A>::and_modify` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:436:15 -a mutable reference into a `Result`'s payload, passed on or kept at fixtures/reject/src/lib.rs:446:12 -unsupported call to ` as std::cmp::PartialEq>::eq` at fixtures/reject/src/lib.rs:453:2 -`f64::mul_add`, which rounds once, where JS would round twice at fixtures/reject/src/lib.rs:477:4 -unsupported call to `::fmt` at fixtures/reject/src/lib.rs:482:11 -a coercion to `std::sync::Arc`, which is not supported yet at fixtures/reject/src/lib.rs:513:39 -`dyn Scaled`, a trait object of the generic trait `Scaled`, which is not supported yet at fixtures/reject/src/lib.rs:522:23 -`dyn Scaled`, a trait object of the generic trait `Scaled`, which is not supported yet at fixtures/reject/src/lib.rs:523:4 -a trait object of `[u8; 4]`, which is not supported yet at fixtures/reject/src/lib.rs:539:26 -a coercion to `&Tail`, which is not supported yet at fixtures/reject/src/lib.rs:549:30 -overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:155:2 -an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:175:1 -overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:209:2 -an iterator of the crate implementing `FusedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:229:1 -`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:315:9 +`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:407:18 +unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:408:2 +constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:414:53 +hashing `std::vec::Vec` through `Batched`'s own `Hash::hash_slice`, which is not supported yet at fixtures/reject/src/lib.rs:374:16 +passing `{closure@fixtures/reject/src/lib.rs:383:28: 383:35}`, a closure that owns a value that drops, to `Entry::or_insert_with`, which is not supported yet at fixtures/reject/src/lib.rs:383:13 +passing `{closure@fixtures/reject/src/lib.rs:384:25: 384:33}`, a closure that owns a value that drops, to `Iterator::for_each`, which is not supported yet at fixtures/reject/src/lib.rs:384:16 +passing `{closure@fixtures/reject/src/lib.rs:391:13: 391:27}`, which drops, to `str::contains`, which is not supported yet at fixtures/reject/src/lib.rs:391:4 +unsupported call to ` as std::iter::Iterator>::sum::` at fixtures/reject/src/lib.rs:453:17 +unsupported call to ` as std::iter::Iterator>::sum::` at fixtures/reject/src/lib.rs:453:38 +a mutable reference into a `Result`'s payload, passed on or kept at fixtures/reject/src/lib.rs:427:12 +unsupported call to ` as std::cmp::PartialEq>::eq` at fixtures/reject/src/lib.rs:434:2 +`f64::mul_add`, which rounds once, where JS would round twice at fixtures/reject/src/lib.rs:458:4 +unsupported call to `::fmt` at fixtures/reject/src/lib.rs:463:11 +a coercion to `std::sync::Arc`, which is not supported yet at fixtures/reject/src/lib.rs:494:39 +`dyn Scaled`, a trait object of the generic trait `Scaled`, which is not supported yet at fixtures/reject/src/lib.rs:503:23 +`dyn Scaled`, a trait object of the generic trait `Scaled`, which is not supported yet at fixtures/reject/src/lib.rs:504:4 +a trait object of `[u8; 4]`, which is not supported yet at fixtures/reject/src/lib.rs:520:26 +a coercion to `&Tail`, which is not supported yet at fixtures/reject/src/lib.rs:530:30 +overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:148:2 +an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:168:1 +overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:202:2 +an iterator of the crate implementing `FusedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:222:1 +`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:308:9 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index 4d4f41ca9..956f39b04 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -12,13 +12,6 @@ pub fn dynamic(f: &dyn Fn(u8) -> u8) -> u8 { f(1) } -/// Each element would be a copy, so the increments would be lost. -pub fn increment(v: &mut [u32]) { - for x in v { - *x += 1; - } -} - /// `None` and `Some(None)` would both be `rt.None`, as `Some(Some(None))` is `undefined`. pub fn nested(x: Option>>) -> bool { x.is_some() @@ -424,18 +417,6 @@ pub fn cow_made(a: &std::sync::Arc) -> usize { std::sync::Arc::strong_count(a) } -/// std makes a `&mut` to a value JS copies, which its mapping has as the value. -pub fn last_bumped(v: &mut Vec) { - if let Some(x) = v.last_mut() { - *x += 1; - } -} - -/// std hands the closure a `&mut` to a value JS copies, as `passed`'s is. -pub fn modified(map: &mut std::collections::HashMap) { - map.entry(1).and_modify(|v| *v += 1); -} - fn bumped(x: &mut u8) { *x += 1; } diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index a62473744..dd7c74f31 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -2,7 +2,6 @@ package = "reject-fixture" roots = [ "float", "dynamic", - "increment", "nested", "sorted", "iterators", @@ -53,8 +52,6 @@ roots = [ "called_closure", "pattern_closure", "parts_summed", - "last_bumped", - "modified", "ok_passed", "places_equal", "fma", diff --git a/ts/fixtures/task/expected/core/result.ts b/ts/fixtures/task/expected/core/result.ts index 9017338ae..84c691174 100644 --- a/ts/fixtures/task/expected/core/result.ts +++ b/ts/fixtures/task/expected/core/result.ts @@ -3,7 +3,7 @@ import * as rt from "../rt.ts"; import { drop$Result_Guard_Guard, drop$Result_u8_Key } from "../lib.ts"; import type * as Key from "../drops.Key.ts"; -import type * as Guard from "../model.Guard.ts"; +import * as Guard from "../model.Guard.ts"; export function ok$Result_Guard_Guard(self: rt.Result): Guard.Guard | undefined { let _0!: Guard.Guard | undefined; @@ -33,6 +33,13 @@ export function err$Result_Guard_Guard(self: rt.Result return _0; } +export function asRef$Result_Guard_u8(self: rt.Result): rt.Result { + if (self.ok) { + return rt.Ok(self.value); + } + return rt.Err(self.error); +} + export function map$Result_u32_u32_u32_discarded_closure4(self: rt.Result, op: (a0: rt.u32) => rt.u32): rt.Result { let _0!: rt.Result; let _9: boolean = false; @@ -51,6 +58,13 @@ export function map$Result_u32_u32_u32_discarded_closure4(self: rt.Result, default_: rt.u32, _: (a0: Guard.Guard) => rt.u32): rt.u32 { + if (self.ok) { + return Guard.id(self.value); + } + return default_; +} + export function mapOrElse$Result_Guard_Guard_u32_options_closure9_options_closure10(self: rt.Result, default_: (a0: Guard.Guard) => rt.u32, f: (a0: Guard.Guard) => rt.u32): rt.u32 { if (self.ok) { return f(self.value); diff --git a/ts/fixtures/task/expected/drops.ts b/ts/fixtures/task/expected/drops.ts index a9a6a9ee0..16ad06254 100644 --- a/ts/fixtures/task/expected/drops.ts +++ b/ts/fixtures/task/expected/drops.ts @@ -1,9 +1,9 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; -import { drop$Arc_Wrap_Pair_Held, drop$Arc_str_Arc_str, drop$Bomb_Guard, drop$Guard_Entries_Bomb_Guard_Held, drop$Held, drop$Key_Key, drop$Mutex_Held, drop$Option_Box_Held, drop$Option_Guard_Guard, drop$Option_Held, drop$Pair_Held, drop$Result_Guard_Guard, drop$Result_u8_Key, drop$Wrap_Arc_Held, drop$Wrap_Guard, drop$Wrap_Held, drop$Wrap_Pair_Held, drop$Wrap_Vec_Wrap_Held } from "./lib.ts"; +import { drop$Arc_Wrap_Pair_Held, drop$Arc_str_Arc_str, drop$Bomb_Guard, drop$Guard_Entries_Bomb_Guard_Held, drop$Held, drop$Key_Key, drop$Mutex_Held, drop$Option_Box_Held, drop$Option_Guard_Guard, drop$Option_Held, drop$Option_Result_Guard_u8, drop$Pair_Held, drop$Result_Guard_Guard, drop$Result_Guard_u8, drop$Result_u8_Key, drop$Wrap_Arc_Held, drop$Wrap_Guard, drop$Wrap_Held, drop$Wrap_Pair_Held, drop$Wrap_Vec_Wrap_Held } from "./lib.ts"; import { isSomeAnd$Option_Guard_options_closure7, unwrapOr$Option_Guard, unwrapOr$Option_u64, mapOr$Option_u32_Guard_options_closure2, okOr$Option_Guard_Guard, filter$Option_Guard_options_closure4, orElse$Option_Guard_options_closure6, zip$Option_Guard_Guard, clone$Clone_Option_Arc_Guard } from "./core/option.ts"; -import { ok$Result_Guard_Guard, err$Result_Guard_Guard, mapOrElse$Result_Guard_Guard_u32_options_closure9_options_closure10, inspectErr$Result_u8_Key_tripped_closure6, andThen$Result_Guard_Guard_Guard_options_closure8, unwrapOr$Result_Guard_Guard } from "./core/result.ts"; +import { ok$Result_Guard_Guard, err$Result_Guard_Guard, asRef$Result_Guard_u8, mapOr$Result_Guard_u8_u32_id, mapOrElse$Result_Guard_Guard_u32_options_closure9_options_closure10, inspectErr$Result_u8_Key_tripped_closure6, andThen$Result_Guard_Guard_Guard_options_closure8, unwrapOr$Result_Guard_Guard } from "./core/result.ts"; import { scoped, discarded, iterated, blasted } from "./drops/closures.ts"; import { looped, collected, drained, extended, bombed, spent } from "./drops/iters.ts"; import { boxed } from "./drops/objects.ts"; @@ -1633,65 +1633,72 @@ export function options(log: Log.Log, id: rt.u32, at: rt.u8): void { let chained!: rt.Result; let cloned!: rt.Arc | undefined; let _275!: rt.Arc | undefined; - let _319!: boolean; - let _320!: boolean; - let _321!: boolean; - let _322!: boolean; - let _323!: boolean; - let _324!: boolean; - let _325!: boolean; + let slot!: Guard.Guard | undefined; + let empty!: Guard.Guard | undefined; + let answered!: rt.Result | undefined; + let _359!: rt.Result; + let _369!: boolean; + let _403!: boolean; + let _404!: boolean; + let _405!: boolean; + let _406!: boolean; + let _407!: boolean; + let _408!: boolean; + let _409!: boolean; + let _410!: boolean; let unwind: number = 0; try { - _325 = false; - _324 = false; - _323 = false; - _322 = false; - _321 = false; - _320 = false; - _319 = false; + _410 = false; + _409 = false; + _408 = false; + _407 = false; + _406 = false; + _405 = false; + _404 = false; + _403 = false; const guard: (a0: rt.u32) => Guard.Guard = (n: rt.u32): Guard.Guard => { return Guard.new(rt.u32Add(id, n), Log.clone$Clone(log)); }; const check: (a0: rt.u8) => void = (point: rt.u8): void => { if (point === at) { - const args16: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(id, f), (f: rt.Formatter) => rt.u8Display(point, f)]; - rt.panicFmt(["d", args16[0], " at ", args16[1]]); + const args20: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(id, f), (f: rt.Formatter) => rt.u8Display(point, f)]; + rt.panicFmt(["d", args20[0], " at ", args20[1]]); } }; const _11: Guard.Guard = guard(1); - unwind = 185; - _325 = true; + unwind = 231; + _410 = true; _10 = _11; const _14: Guard.Guard = guard(2); - _325 = false; + _410 = false; some = okOr$Option_Guard_Guard(_10, _14); - _325 = false; + _410 = false; if (!(at > 8)) { - _324 = true; + _409 = true; _18 = undefined as Guard.Guard | undefined; } else { - unwind = 170; + unwind = 214; const _20: Guard.Guard = guard(0); - _324 = true; + _409 = true; _18 = _20; } - unwind = 183; + unwind = 229; const _23: Guard.Guard = guard(3); - _324 = false; + _409 = false; none = okOr$Option_Guard_Guard(_18, _23); - unwind = 169; - _324 = false; + unwind = 213; + _409 = false; const _32: boolean = some.ok; const _35: boolean = none.ok; const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtBool(_32, f), (f: rt.Formatter) => rt.fmtBool(_35, f)]; Log.note(log, rt.fmtFormat(["ok_or ", args2[0], " ", args2[1]])); check(1); ok = ok$Result_Guard_Guard(rt.Ok(guard(4))); - unwind = 168; + unwind = 212; err = ok$Result_Guard_Guard(rt.Err(guard(5))); - unwind = 167; + unwind = 211; flipped = err$Result_Guard_Guard(rt.Ok(guard(6))); - unwind = 166; + unwind = 210; const _66: boolean = ok !== undefined; const _69: boolean = err !== undefined; const _72: boolean = flipped !== undefined; @@ -1699,39 +1706,39 @@ export function options(log: Log.Log, id: rt.u32, at: rt.u8): void { Log.note(log, rt.fmtFormat(["ok ", args4[0], " ", args4[1], " ", args4[2]])); check(2); const _85: Guard.Guard = guard(7); - unwind = 181; - _323 = true; + unwind = 227; + _408 = true; _84 = _85; const _88: Guard.Guard = guard(8); - _323 = false; + _408 = false; kept = unwrapOr$Option_Guard(_84, _88); - unwind = 179; - _323 = false; - _322 = true; + unwind = 225; + _408 = false; + _407 = true; _92 = undefined as Guard.Guard | undefined; const _93: Guard.Guard = guard(9); - _322 = false; + _407 = false; fallback = unwrapOr$Option_Guard(_92, _93); - unwind = 164; - _322 = false; + unwind = 208; + _407 = false; const _98: Guard.Guard = guard(10); - unwind = 177; - _321 = true; + unwind = 223; + _406 = true; _97 = rt.Ok(_98); const _101: Guard.Guard = guard(11); - _321 = false; + _406 = false; value = unwrapOr$Result_Guard_Guard(_97, _101); - unwind = 163; - _321 = false; + unwind = 207; + _406 = false; const _106: Guard.Guard = guard(12); - unwind = 175; - _320 = true; + unwind = 221; + _405 = true; _105 = rt.Err(_106); const _109: Guard.Guard = guard(13); - _320 = false; + _405 = false; error = unwrapOr$Result_Guard_Guard(_105, _109); - unwind = 162; - _320 = false; + unwind = 206; + _405 = false; const _118: rt.u32 = Guard.id(kept); const _121: rt.u32 = Guard.id(fallback); const _124: rt.u32 = Guard.id(value); @@ -1743,20 +1750,20 @@ export function options(log: Log.Log, id: rt.u32, at: rt.u8): void { Log.note(log, rt.fmtFormat(["mapped"])); return Guard.new(rt.u32Add(n2, 15), Log.clone$Clone(log)); }); - unwind = 161; + unwind = 205; unmapped = mapOr$Option_u32_Guard_options_closure2(undefined as rt.u32 | undefined, guard(16), (n3: rt.u32): Guard.Guard => { return Guard.new(n3, Log.clone$Clone(log)); }); - unwind = 160; + unwind = 204; const _157: rt.u32 = Guard.id(mapped); const _160: rt.u32 = Guard.id(unmapped); const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(_157, f), (f: rt.Formatter) => rt.u32Display(_160, f)]; Log.note(log, rt.fmtFormat(["map_or ", args8[0], " ", args8[1]])); check(4); then = rt.thenSome(rt.u8Rem(at, 2) === 0, guard(17), rt.drop); - unwind = 159; + unwind = 203; never = rt.thenSome(false, guard(18), rt.drop); - unwind = 158; + unwind = 202; const _187: boolean = then !== undefined; const _190: boolean = never !== undefined; const args10: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtBool(_187, f), (f: rt.Formatter) => rt.fmtBool(_190, f)]; @@ -1766,28 +1773,28 @@ export function options(log: Log.Log, id: rt.u32, at: rt.u8): void { check(6); return rt.u32Rem(Guard.id(g), 2) === 0; }); - unwind = 157; + unwind = 201; dropped = filter$Option_Guard_options_closure4(guard(20), (_2: Guard.Guard): boolean => { return false; }); - unwind = 156; + unwind = 200; const _214: Guard.Guard = guard(21); - unwind = 173; - _319 = true; + unwind = 219; + _404 = true; _213 = _214; if (!(rt.u8Rem(at, 2) === 0)) { _217 = undefined as Guard.Guard | undefined; } else { _217 = guard(22); } - _319 = false; + _404 = false; zipped = zip$Option_Guard_Guard(_213, _217); - unwind = 155; - _319 = false; + unwind = 199; + _404 = false; other = orElse$Option_Guard_options_closure6(undefined as Guard.Guard | undefined, (): Guard.Guard | undefined => { return guard(23); }); - unwind = 154; + unwind = 198; const flag: boolean = isSomeAnd$Option_Guard_options_closure7(guard(24), (g2: Guard.Guard): boolean => { let unwind2: number = 0; try { @@ -1825,7 +1832,7 @@ export function options(log: Log.Log, id: rt.u32, at: rt.u8): void { throw e3; } }); - unwind = 153; + unwind = 197; const error2: rt.u32 = mapOrElse$Result_Guard_Guard_u32_options_closure9_options_closure10(rt.Err(guard(26)), (e4: Guard.Guard): rt.u32 => { let unwind4: number = 0; try { @@ -1858,178 +1865,321 @@ export function options(log: Log.Log, id: rt.u32, at: rt.u8): void { } }); const _276: rt.Arc = new rt.Arc(guard(27)); - unwind = 152; + unwind = 196; _275 = _276; cloned = clone$Clone_Option_Arc_Guard(_275); - unwind = 151; + unwind = 195; rt.drop(_275); const _286: boolean = chained.ok; const _289: boolean = cloned !== undefined; const args14: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtBool(_286, f), (f: rt.Formatter) => rt.u32Display(error2, f), (f: rt.Formatter) => rt.fmtBool(_289, f)]; Log.note(log, rt.fmtFormat(["and_then ", args14[0], " map_or_else ", args14[1], " clone ", args14[2]])); - unwind = 153; + unwind = 194; + slot = undefined as Guard.Guard | undefined; + const _301: Guard.Guard = guard(28); + if (slot === undefined) { + slot = _301; + } else { + rt.drop(_301); + } + const _306: Guard.Guard = guard(29); + if (slot === undefined) { + slot = _306; + } else { + rt.drop(_306); + } + const captured = guard(30); + const _314: () => Guard.Guard = rt.closure((): Guard.Guard => { + return captured; + }, (): void => { + rt.drop(captured); + }); + if (slot === undefined) { + slot = _314(); + } else { + rt.drop(_314); + } + const owned2: Guard.Guard = guard(31); + unwind = 193; + empty = undefined as Guard.Guard | undefined; + const captured2 = check; + const captured3 = owned2; + const _323: () => Guard.Guard = rt.closure((): Guard.Guard => { + let unwind6: number = 0; + try { + unwind6 = 3; + captured2(5); + return captured3; + } catch (e7) { + if (unwind6 === 0) { + throw e7; + } + rt.drop(captured3); + throw e7; + } + }, (): void => { + rt.drop(captured3); + }); + if (empty === undefined) { + empty = _323(); + } else { + rt.drop(_323); + } + const made: rt.u32 = Guard.id(empty as Guard.Guard); + const _328: Guard.Guard = guard(32); + const old = slot; + slot = _328; + rt.drop(old); + const replaced: rt.u32 = Guard.id(slot as Guard.Guard); + const args16: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(made, f), (f: rt.Formatter) => rt.u32Display(replaced, f)]; + Log.note(log, rt.fmtFormat(["get_or_insert ", args16[0], " ", args16[1]])); + unwind = 192; + answered = undefined as rt.Result | undefined; + const _346: rt.Result = rt.Ok(guard(33)); + if (answered === undefined) { + answered = _346; + } else { + drop$Result_Guard_u8(_346); + } + const _355: rt.Result = rt.Ok(guard(34)); + if (answered === undefined) { + answered = _355; + } else { + drop$Result_Guard_u8(_355); + } + const kept3: rt.u32 = mapOr$Result_Guard_u8_u32_id(asRef$Result_Guard_u8(answered as rt.Result), 0, Guard.id); + unwind = 217; + _403 = true; + _359 = rt.Err(4); + const _362: rt.Result = rt.Err(3); + const old2 = answered; + answered = _362; + drop$Option_Result_Guard_u8(old2); + unwind = 158; + drop$Result_Guard_u8(answered as rt.Result); + b2: { + _403 = false; + answered = _359; + _403 = false; + if (answered !== undefined) { + if (!answered.ok) { + if (answered.error === 4) { + _369 = true; + break b2; + } + } + } + _369 = false; + } + unwind = 192; + const args18: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(kept3, f), (f: rt.Formatter) => rt.fmtBool(_369, f)]; + Log.note(log, rt.fmtFormat(["answered ", args18[0], " ", args18[1]])); + unwind = 193; + drop$Option_Result_Guard_u8(answered); + unwind = 194; + rt.drop(empty); + unwind = 195; + rt.drop(slot); + unwind = 197; rt.drop(cloned); - unwind = 154; + unwind = 198; drop$Result_Guard_Guard(chained); - unwind = 155; + unwind = 199; rt.drop(other); - unwind = 156; + unwind = 200; drop$Option_Guard_Guard(zipped); - unwind = 157; + unwind = 201; rt.drop(dropped); - unwind = 158; + unwind = 202; rt.drop(kept2); - unwind = 159; + unwind = 203; rt.drop(never); - unwind = 160; + unwind = 204; rt.drop(then); - unwind = 161; + unwind = 205; rt.drop(unmapped); - unwind = 162; + unwind = 206; rt.drop(mapped); - unwind = 163; + unwind = 207; rt.drop(error); - unwind = 164; + unwind = 208; rt.drop(value); - unwind = 165; + unwind = 209; rt.drop(fallback); - unwind = 166; + unwind = 210; rt.drop(kept); - unwind = 167; + unwind = 211; rt.drop(flipped); - unwind = 168; + unwind = 212; rt.drop(err); - unwind = 169; + unwind = 213; rt.drop(ok); - unwind = 170; + unwind = 214; drop$Result_Guard_Guard(none); unwind = 0; drop$Result_Guard_Guard(some); } catch (e) { - b2: { - b3: { - b4: { - b5: { - b6: { - b7: { - b8: { - b9: { - b10: { - b11: { - b12: { - b13: { - b14: { - b15: { - b16: { - b17: { - b18: { - b19: { - if (unwind === 0) { - throw e; - } - if (unwind === 151) { - rt.drop(cloned); - } else if (unwind === 152) { - rt.drop(_275); - } else if (unwind !== 153) { - if (unwind === 154) { - break b19; - } - if (unwind === 155) { - break b18; - } - if (unwind === 156) { - break b17; - } - if (unwind === 157) { - break b16; - } - if (unwind === 158) { - break b15; - } - if (unwind === 159) { - break b14; - } - if (unwind === 160) { - break b13; - } - if (unwind === 161) { - break b12; - } - if (unwind === 162) { - break b11; - } - if (unwind === 163) { - break b10; - } - if (unwind === 164) { - break b9; - } - if (unwind === 165) { - break b8; - } - if (unwind === 166) { - break b7; - } - if (unwind === 167) { - break b6; - } - if (unwind === 168) { - break b5; - } - if (unwind === 169) { - break b4; - } - if (unwind === 170) { - break b3; - } - if (unwind === 173) { - if (!_319) { - break b17; - } - rt.drop(_213); - break b17; - } - if (unwind === 175) { - if (!_320) { - break b10; - } - drop$Result_Guard_Guard(_105); - break b10; - } - if (unwind === 177) { - if (!_321) { - break b9; - } - drop$Result_Guard_Guard(_97); - break b9; - } - if (unwind === 179) { - if (!_322) { - break b8; - } - rt.drop(_92); - break b8; - } - if (unwind === 181) { - if (!_323) { - break b7; - } - rt.drop(_84); - break b7; - } - if (unwind === 183) { - if (!_324) { - break b3; + b4: { + b5: { + b6: { + b7: { + b8: { + b9: { + b10: { + b11: { + b12: { + b13: { + b14: { + b15: { + b16: { + b17: { + b18: { + b19: { + b20: { + b21: { + b22: { + b23: { + b24: { + b25: { + b26: { + if (unwind === 0) { + throw e; + } + if (unwind === 158) { + _403 = false; + answered = _359; + } else { + if (unwind === 192) { + break b26; + } + if (unwind === 193) { + break b25; + } + if (unwind === 194) { + break b24; + } + if (unwind === 195) { + break b23; + } + if (unwind === 196) { + rt.drop(_275); + break b22; + } + if (unwind === 197) { + break b22; + } + if (unwind === 198) { + break b21; + } + if (unwind === 199) { + break b20; + } + if (unwind === 200) { + break b19; + } + if (unwind === 201) { + break b18; + } + if (unwind === 202) { + break b17; + } + if (unwind === 203) { + break b16; + } + if (unwind === 204) { + break b15; + } + if (unwind === 205) { + break b14; + } + if (unwind === 206) { + break b13; + } + if (unwind === 207) { + break b12; + } + if (unwind === 208) { + break b11; + } + if (unwind === 209) { + break b10; + } + if (unwind === 210) { + break b9; + } + if (unwind === 211) { + break b8; + } + if (unwind === 212) { + break b7; + } + if (unwind === 213) { + break b6; + } + if (unwind === 214) { + break b5; + } + if (unwind !== 217) { + if (unwind === 219) { + if (!_404) { + break b19; + } + rt.drop(_213); + break b19; + } + if (unwind === 221) { + if (!_405) { + break b12; + } + drop$Result_Guard_Guard(_105); + break b12; + } + if (unwind === 223) { + if (!_406) { + break b11; + } + drop$Result_Guard_Guard(_97); + break b11; + } + if (unwind === 225) { + if (!_407) { + break b10; + } + rt.drop(_92); + break b10; + } + if (unwind === 227) { + if (!_408) { + break b9; + } + rt.drop(_84); + break b9; + } + if (unwind === 229) { + if (!_409) { + break b5; + } + rt.drop(_18); + break b5; + } + if (!_410) { + break b4; + } + rt.drop(_10); + break b4; + } + } + if (_403) { + drop$Result_Guard_u8(_359); + } + } + drop$Option_Result_Guard_u8(answered); + } + rt.drop(empty); } - rt.drop(_18); - break b3; - } - if (!_325) { - break b2; + rt.drop(slot); } - rt.drop(_10); - break b2; + rt.drop(cloned); } drop$Result_Guard_Guard(chained); } diff --git a/ts/fixtures/task/expected/lib.ts b/ts/fixtures/task/expected/lib.ts index 628fc357d..ae5068829 100644 --- a/ts/fixtures/task/expected/lib.ts +++ b/ts/fixtures/task/expected/lib.ts @@ -179,6 +179,12 @@ export function drop$Option_Key_Guard(_1: [Key.Key, Guard.Guard] | undefined): v } } +export function drop$Option_Result_Guard_u8(_1: rt.Result | undefined): void { + if (_1 !== undefined) { + drop$Result_Guard_u8(_1); + } +} + export function drop$Option_u32_Bomb(_1: [rt.u32, Bomb.Bomb] | undefined): void { if (_1 !== undefined) { drop$u32_Bomb(_1); @@ -209,6 +215,12 @@ export function drop$Result_Guard_Guard(_1: rt.Result) } } +export function drop$Result_Guard_u8(_1: rt.Result): void { + if (_1.ok) { + rt.drop(_1.value); + } +} + export function drop$Result_Vec_Guard_Guard(_1: rt.Result): void { if (_1.ok) { rt.dropAll(_1.value); diff --git a/ts/fixtures/task/src/drops.rs b/ts/fixtures/task/src/drops.rs index 4f5457c62..bd077becb 100644 --- a/ts/fixtures/task/src/drops.rs +++ b/ts/fixtures/task/src/drops.rs @@ -547,6 +547,29 @@ fn options(log: &Log, id: u32, at: u8) { chained.is_ok(), cloned.is_some() )); + // What a `&mut Option`'s methods drop: the value `get_or_insert` doesn't insert, the + // closure `get_or_insert_with` doesn't call, and what `insert` replaces. + let mut slot = None; + slot.get_or_insert(guard(28)); + slot.get_or_insert(guard(29)); + let owned = guard(30); + slot.get_or_insert_with(move || owned); + let owned = guard(31); + let mut empty = None; + let made = empty + .get_or_insert_with(move || { + check(5); + owned + }) + .id(); + let replaced = slot.insert(guard(32)).id(); + log.note(format!("get_or_insert {made} {replaced}")); + // Of a payload JS copies, which the methods lend as its place, as moq's `answered` is. + let mut answered: Option> = None; + answered.get_or_insert(Ok(guard(33))); + let kept = answered.get_or_insert(Ok(guard(34))).as_ref().map_or(0, Guard::id); + *answered.insert(Err(3)) = Err(4); + log.note(format!("answered {kept} {}", matches!(answered, Some(Err(4))))); } /// What maps keyed by `Arc` drop of the keys they are given or hold, and `max` and diff --git a/ts/runtime/rt.ts b/ts/runtime/rt.ts index f32eb1c55..cb8510d09 100644 --- a/ts/runtime/rt.ts +++ b/ts/runtime/rt.ts @@ -9,6 +9,7 @@ import type { Ordering } from "./rt/collections.ts"; import { type char, type TryFromIntError, type u32, type usize, u8Debug, usizeDebug, usizeDisplay } from "./rt/int.ts"; import type { Pending } from "./rt/task.ts"; +import { AtIndex } from "./rt/collections.ts"; export * from "./rt/collections.ts"; export * from "./rt/float.ts"; export * from "./rt/int.ts"; @@ -77,6 +78,16 @@ class Accessed implements Place { } } +/** + * The payload's place of the `Option` at `p`, whose `None` is `none`: `p` itself, as + * `Some(x)` is `x`, or `undefined` while it is `None`. + */ +export function optionAsMut(p: Place): Place | undefined; +export function optionAsMut(p: Place, none: None): Place | undefined; +export function optionAsMut(p: Place, none?: None): Place | undefined { + return p.v === none ? undefined : (p as Place); +} + /** The place `get` reads and `set` writes. */ export function place(get: () => T, set: (value: T) => void): Place { return new Accessed(get, set); @@ -284,11 +295,26 @@ export function sliceReverse(s: T[]): void { s.reverse(); } -/** `last` and `last_mut`: the last element, or `undefined` if empty. */ +/** `last`, and `last_mut` of an element that is an object: the last element, or `undefined` if empty. */ export function sliceLast(s: ArrayLike): T | undefined { return s.length === 0 ? undefined : s[s.length - 1]; } +/** `get_mut` of an element JS copies: its place, or `undefined` past the end. */ +export function sliceGetMut(s: { [i: number]: T; length: number }, index: number): Place | undefined { + return index < s.length ? new AtIndex(s, index) : undefined; +} + +/** `first_mut` of an element JS copies. */ +export function sliceFirstMut(s: { [i: number]: T; length: number }): Place | undefined { + return sliceGetMut(s, 0); +} + +/** `last_mut` of an element JS copies. */ +export function sliceLastMut(s: { [i: number]: T; length: number }): Place | undefined { + return s.length === 0 ? undefined : new AtIndex(s, s.length - 1); +} + /** `contains`, by `eq` of each element and then `x`, as std's `==` reads them. */ export function sliceContains(s: ArrayLike, x: T, eq: (a: T, b: T) => boolean): boolean { for (let i = 0; i < s.length; i++) if (eq(s[i], x)) return true; diff --git a/ts/runtime/rt/collections.ts b/ts/runtime/rt/collections.ts index 0a785fb01..be4efa96f 100644 --- a/ts/runtime/rt/collections.ts +++ b/ts/runtime/rt/collections.ts @@ -16,7 +16,7 @@ import { type None, type Place, panic } from "../rt.ts"; import { type Limbs, lt } from "./int.ts"; -import { DONE, type Done, Iter, iterSlice, type RangeInclusive } from "./iter.ts"; +import { DONE, type Done, Iter, iterMap, iterSlice, type RangeInclusive } from "./iter.ts"; import { type Arc, dropAll } from "./task.ts"; // Ordering @@ -366,11 +366,11 @@ function itself(value: T): T { } /** The place of index `i` of `a`. */ -class AtIndex implements Place { - private readonly a: T[]; +export class AtIndex implements Place { + private readonly a: { [i: number]: T }; private readonly i: number; - constructor(a: T[], i: number) { + constructor(a: { [i: number]: T }, i: number) { this.a = a; this.i = i; } @@ -660,16 +660,27 @@ export function hashClear(m: HashMap, k?: (key: K) => void, v?: (val * `f` rejects it, so a panic in `f` leaves the map whole, as std's. */ export function hashRetain(m: HashMap, f: (key: K, value: V) => boolean, k?: (key: K) => void, v?: (value: V) => void): void { + retainHash(m, f as (key: K, value: V | Place) => boolean, false, k, v); +} + +/** `retain` of values JS copies: `f` takes the place of each. */ +export function hashRetainMut(m: HashMap, f: (key: K, value: Place) => boolean, k?: (key: K) => void, v?: (value: V) => void): void { + retainHash(m, f as (key: K, value: V | Place) => boolean, true, k, v); +} + +/** `retain`, handing `f` each value or, if `lend`, its place. */ +function retainHash(m: HashMap, f: (key: K, value: V | Place) => boolean, lend: boolean, k?: (key: K) => void, v?: (value: V) => void): void { for (const [key, value] of m.p) { - if (f(key, value)) continue; + if (f(key, lend ? new AtKey(m.p, key) : value)) continue; + const now = lend ? (m.p.get(key) as V) : value; m.p.delete(key); - dropPair(key, value, k, v); + dropPair(key, now, k, v); } if (m.o === undefined) return; for (const [hash, first] of m.o) { let prev: Slot | undefined; for (let s: Slot | undefined = first; s !== undefined; s = s.next) { - if (f(s.k, s.v)) { + if (f(s.k, lend ? s : s.v)) { prev = s; continue; } @@ -682,11 +693,15 @@ export function hashRetain(m: HashMap, f: (key: K, value: V) => bool } } -/** What a collection's iterator yields: its entries as `[key, value]`, keys, or values. */ -type Pick = 0 | 1 | 2; +/** + * What a collection's iterator yields: its entries as `[key, value]`, keys, values, or + * `[key, place]`, the place of a value JS copies. + */ +type Pick = 0 | 1 | 2 | 3; const ENTRIES = 0; const KEYS = 1; const VALUES = 2; +const PLACES = 3; /** * An iterator of a hash collection: `iter`, `keys`, `values`, `drain`, and the rest. @@ -694,6 +709,7 @@ const VALUES = 2; * and drops each entry it still holds as it drops. */ export class HashIter extends Iter implements Disposable { + private readonly m: Map; private readonly p: Iterator<[K, V]>; private readonly o: Iterator> | undefined; private at: Slot | undefined; @@ -706,6 +722,7 @@ export class HashIter extends Iter implements Disposable { constructor(m: HashMap, pick: Pick, k?: (key: K) => void, v?: (value: V) => void, drain = false) { super(); + this.m = m.p; this.p = m.p.entries(); this.o = m.o?.values(); this.pick = pick; @@ -719,15 +736,30 @@ export class HashIter extends Iter implements Disposable { private entry(): [K, V] { const entry = this.p.next(); if (!entry.done) return entry.value; + const s = this.slot(); + return [s.k, s.v]; + } + + /** The next entry of the `left` it has, as its key and the place of its value. */ + private place(): [K, Place] { + const entry = this.p.next(); + if (!entry.done) return [entry.value[0], new AtKey(this.m, entry.value[0])]; + const s = this.slot(); + return [s.k, s]; + } + + /** The next chained entry, once the primitive keys are done. */ + private slot(): Slot { if (this.at === undefined) this.at = (this.o as Iterator>).next().value; const s = this.at as Slot; this.at = s.next; - return [s.k, s.v]; + return s; } next(): T | Done { if (this.left === 0) return DONE; this.left--; + if (this.pick === PLACES) return this.place() as T; const entry = this.entry(); if (this.pick === ENTRIES) return entry as T; return (this.pick === KEYS ? entry[0] : entry[1]) as unknown as T; @@ -768,6 +800,16 @@ export function hashValues(m: HashMap, v?: (value: V) => void): Iter return new HashIter(m, VALUES, undefined, v); } +/** `iter_mut` of values JS copies: each key and the place of its value, in `hashIter`'s order. */ +export function hashIterMut(m: HashMap): Iter<[K, Place]> { + return new HashIter]>(m, PLACES); +} + +/** `values_mut` of values JS copies: the place of each. */ +export function hashValuesMut(m: HashMap): Iter> { + return iterMap(hashIterMut(m), (entry) => entry[1]); +} + /** `drain` of a map: every entry, taken out at once, which drops as `hashIter`'s. */ export function hashDrain(m: HashMap, k?: (key: K) => void, v?: (value: V) => void): Iter<[K, V]> { return new HashIter(taken(m), ENTRIES, k, v, true); @@ -1305,14 +1347,25 @@ export function btreeSplitOff(m: BTreeMap, key: K): BTreeMap { * one it panicked on, as std's. */ export function btreeRetain(m: BTreeMap, f: (key: K, value: V) => boolean, k?: (key: K) => void, v?: (value: V) => void): void { + retainBTree(m, f as (key: K, value: V | Place) => boolean, false, k, v); +} + +/** `retain` of values JS copies: `f` takes the place of each. */ +export function btreeRetainMut(m: BTreeMap, f: (key: K, value: Place) => boolean, k?: (key: K) => void, v?: (value: V) => void): void { + retainBTree(m, f as (key: K, value: V | Place) => boolean, true, k, v); +} + +/** `retain`, handing `f` each value or, if `lend`, its place, which the map is built from again. */ +function retainBTree(m: BTreeMap, f: (key: K, value: V | Place) => boolean, lend: boolean, k?: (key: K) => void, v?: (value: V) => void): void { const [keys, values] = flatten(m); let kept = 0; let i = 0; try { while (i < keys.length) { const key = keys[i]; + const keep = f(key, lend ? new AtIndex(values, i) : values[i]); const value = values[i]; - if (!f(key, value)) { + if (!keep) { i++; dropPair(key, value, k, v); continue; @@ -1323,7 +1376,7 @@ export function btreeRetain(m: BTreeMap, f: (key: K, value: V) => bo i++; } } finally { - if (kept < i) { + if (kept < i || lend) { keys.splice(kept, i - kept); values.splice(kept, i - kept); build(m, keys, values); @@ -1403,6 +1456,7 @@ export class BTreeIter extends Iter implements Disposable { */ private picked(l: Leaf, i: number): T { if (this.pick === ENTRIES) return [l.k[i], l.v[i]] as T; + if (this.pick === PLACES) return [l.k[i], new AtIndex(l.v, i)] as T; if (this.pick === KEYS) { this.v?.(l.v[i]); return l.k[i] as unknown as T; @@ -1460,6 +1514,16 @@ export function btreeKeys(m: BTreeMap, k?: (key: K) => void, v?: (va return whole(m, KEYS, k, v, back); } +/** `iter_mut` of values JS copies: each key and the place of its value, in key order. */ +export function btreeIterMut(m: BTreeMap): Iter<[K, Place]> { + return whole(m, PLACES); +} + +/** `values_mut` of values JS copies: the place of each. */ +export function btreeValuesMut(m: BTreeMap): Iter> { + return iterMap(btreeIterMut(m), (entry) => entry[1]); +} + /** `values` and `values_mut`, and with droppers as `btreeIter`'s, `into_values`. */ export function btreeValues(m: BTreeMap, k?: (key: K) => void, v?: (value: V) => void): Iter { return whole(m, VALUES, k, v, k !== undefined || v !== undefined); @@ -1490,6 +1554,11 @@ export function btreeRange(m: BTreeMap, r: Bounds): Iter<[K, V]> return range(m, r, ENTRIES, "BTreeMap"); } +/** `range_mut` of values JS copies: each key within `r` and the place of its value. */ +export function btreeRangeMut(m: BTreeMap, r: Bounds): Iter<[K, Place]> { + return range(m, r, PLACES, "BTreeMap"); +} + /** `BTreeSet::range`: the keys within `r`. */ export function btreeRangeKeys(m: BTreeMap, r: Bounds): Iter { return range(m, r, KEYS, "BTreeSet"); @@ -1729,6 +1798,12 @@ export function entryOccupied(e: Entry): boolean { return e.o; } +/** `Entry::and_modify` of a value JS copies: `f` of its place, if any. */ +export function entryAndModifyMut(e: Entry, f: (value: Place) => void): Entry { + if (e.o) f(entryGetMut(e)); + return e; +} + /** `Entry::and_modify`: `f` of the value there, if any. */ export function entryAndModify(e: Entry, f: (value: V) => void): Entry { if (e.o) f(entryGet(e)); @@ -1873,6 +1948,16 @@ export function dequeEnd(q: VecDeque, back = false): T | undefined { return q.n === 0 ? undefined : q.b[at(q, back ? q.n - 1 : 0)]; } +/** `get_mut` of an item JS copies: its place, or `undefined` past the end. */ +export function dequeGetMut(q: VecDeque, i: number): Place | undefined { + return i < q.n ? new AtIndex(q.b as T[], at(q, i)) : undefined; +} + +/** `front_mut` of an item JS copies, and with `back`, `back_mut`. */ +export function dequeEndMut(q: VecDeque, back = false): Place | undefined { + return q.n === 0 ? undefined : new AtIndex(q.b as T[], at(q, back ? q.n - 1 : 0)); +} + /** `index` and `index_mut`: `q[i]`. */ export function dequeIndex(q: VecDeque, i: number): T { if (i >= q.n) panic("out of bounds access"); @@ -1918,10 +2003,21 @@ export function dequeTruncate(q: VecDeque, len: number, f?: (item: T) => v * each kept item into place, as std's does, so a panic in `f` leaves every item. */ export function dequeRetain(q: VecDeque, f: (item: T) => boolean, drop?: (item: T) => void): void { + retainDeque(q, f as (item: T | Place) => boolean, false, drop); +} + +/** `retain_mut` of items JS copies: `f` takes the place of each. */ +export function dequeRetainMut(q: VecDeque, f: (item: Place) => boolean, drop?: (item: T) => void): void { + retainDeque(q, f as (item: T | Place) => boolean, true, drop); +} + +/** `retain`, handing `f` each item or, if `lend`, its place. */ +function retainDeque(q: VecDeque, f: (item: T | Place) => boolean, lend: boolean, drop?: (item: T) => void): void { let kept = 0; for (let i = 0; i < q.n; i++) { + const keep = f(lend ? new AtIndex(q.b as T[], at(q, i)) : (q.b[at(q, i)] as T)); const item = q.b[at(q, i)] as T; - if (!f(item)) continue; + if (!keep) continue; q.b[at(q, i)] = q.b[at(q, kept)]; q.b[at(q, kept++)] = item; } @@ -2000,6 +2096,36 @@ export function dequeIter(q: VecDeque, drop?: (item: T) => void): Iter return iterSlice(items, drop); } +/** `iter_mut` of items JS copies: the place of each. */ +export function dequeIterMut(q: VecDeque): Iter> { + return new DequePlaces(q); +} + +/** A deque's `iter_mut` of items JS copies, which lends each as its place. */ +class DequePlaces extends Iter> { + private readonly q: VecDeque; + private front = 0; + private back: number; + + constructor(q: VecDeque) { + super(); + this.q = q; + this.back = q.n; + } + + next(): Place | Done { + return this.front < this.back ? new AtIndex(this.q.b as T[], at(this.q, this.front++)) : DONE; + } + + override nextBack(): Place | Done { + return this.front < this.back ? new AtIndex(this.q.b as T[], at(this.q, --this.back)) : DONE; + } + + override len(): number { + return this.back - this.front; + } +} + /** `drain`: the items within `r`, taken out at once, which drop by `drop` as `dequeIter`'s. */ export function dequeDrain(q: VecDeque, r: Bounds, drop?: (item: T) => void): Iter { // As `slice::range` checks it. diff --git a/ts/runtime/rt/iter.ts b/ts/runtime/rt/iter.ts index 1c57102c5..e0df4c084 100644 --- a/ts/runtime/rt/iter.ts +++ b/ts/runtime/rt/iter.ts @@ -18,8 +18,8 @@ // of iterator has its own, the `owned` functions follow it, dispatching on the kind, so a // bundle that never drops an item carries none of it. -import { ByteVec, byteVecPush, Err, type None, Ok, panic, type RangeBound, type Result } from "../rt.ts"; -import { BTreeIter, HashIter } from "./collections.ts"; +import { ByteVec, byteVecPush, Err, type None, Ok, type Place, panic, type RangeBound, type Result } from "../rt.ts"; +import { AtIndex, BTreeIter, HashIter } from "./collections.ts"; import { type Limbs, lt as wideLt, type Step } from "./int.ts"; import { drop as dispose, dropAll, dropRange } from "./task.ts"; @@ -154,6 +154,11 @@ export function iterSlice(s: ArrayLike, drop?: Drop): Iter { return new SliceIter(s, drop); } +/** `slice::IterMut` of elements JS copies: the place of each. */ +export function iterSliceMut(s: { [i: number]: T; length: number }): Iter> { + return new SliceMutIter(s); +} + /** `Option::iter`, and with what drops its item, `option::IntoIter`. */ export function iterOption(o: T | undefined, drop?: Drop): Iter; export function iterOption(o: T | None, drop: Drop | undefined, none: None): Iter; @@ -954,6 +959,43 @@ class SliceIter extends Iter implements Disposable { } } +/** The places of a slice's elements, from both ends. */ +class SliceMutIter extends Iter> { + private readonly s: { [i: number]: T; length: number }; + private front = 0; + private back: number; + + constructor(s: { [i: number]: T; length: number }) { + super(); + this.s = s; + this.back = s.length; + } + + next(): Place | Done { + return this.front < this.back ? new AtIndex(this.s, this.front++) : DONE; + } + + override nextBack(): Place | Done { + return this.front < this.back ? new AtIndex(this.s, --this.back) : DONE; + } + + override len(): number { + return this.back - this.front; + } + + override advanceBy(n: number): number { + const step = Math.min(n, this.back - this.front); + this.front += step; + return n - step; + } + + override advanceBackBy(n: number): number { + const step = Math.min(n, this.back - this.front); + this.back -= step; + return n - step; + } +} + /** `option::IntoIter`, `Once`, and `Empty`: at most one item. */ class OptionIter extends Iter implements Disposable { private item: T | undefined; diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 43b8348fd..35bcdb9f4 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -277,9 +277,9 @@ fn undefined_arg<'tcx>(b: &Body<'_, '_, 'tcx>, std: Std, coll: Ty<'tcx>) -> Opti (0..n).map(|i| arg(coll, i)).find(|&t| b.t.erases_to(t).undefined) } -/// Whether `call` returns a `&mut`, or an `Option` of one, to a value a map or an atomic -/// holds that JS copies, which its mapping returns as an `rt.Place`: `get_mut`, and an -/// entry's. An atomic is that place itself. +/// Whether `call` lends a value a collection or an atomic holds that JS copies, which its +/// mapping makes an `rt.Place` of: returned as `get_mut` and an entry's do, yielded as +/// `iter_mut`'s, or handed to a closure as `retain`'s. An atomic is that place itself. pub fn place_call<'tcx>(b: &Body<'_, '_, 'tcx>, call: &Call<'tcx>) -> bool { let tcx = b.t.tcx; let Some(std) = library::inherent_std(tcx, call.def_id) else { @@ -288,7 +288,9 @@ pub fn place_call<'tcx>(b: &Body<'_, '_, 'tcx>, call: &Call<'tcx>) -> bool { let name = tcx.item_name(call.def_id); let coll = impl_self_ty(b, call); let (methods, value): (&[&str], usize) = match std { - Std::HashMap | Std::BTreeMap => (&["get_mut"], 1), + Std::VecDeque => (&["get_mut", "front_mut", "back_mut", "iter_mut", "retain_mut"], 0), + Std::HashMap => (&["get_mut", "iter_mut", "values_mut", "retain"], 1), + Std::BTreeMap => (&["get_mut", "iter_mut", "values_mut", "range_mut", "retain"], 1), Std::Entry if is_vacant(b, coll) => (&["insert"], 1), Std::Entry => ( &[ @@ -298,6 +300,7 @@ pub fn place_call<'tcx>(b: &Body<'_, '_, 'tcx>, call: &Call<'tcx>) -> bool { "or_default", "get_mut", "into_mut", + "and_modify", ], 1, ), @@ -384,7 +387,10 @@ fn hash<'tcx>( (_, "remove") if set => Expr::rt("hashDelete", values), (_, "remove") => Expr::rt("hashRemove", values), (_, "remove_entry") => Expr::rt("hashRemoveEntry", values), + (_, "retain") if !set && b.t.needs_place(arg(coll, 1)) => Expr::rt("hashRetainMut", values), (_, "retain") => Expr::rt("hashRetain", values), + (_, "iter_mut") if b.t.needs_place(arg(coll, 1)) => Expr::rt("hashIterMut", values), + (_, "values_mut") if b.t.needs_place(arg(coll, 1)) => Expr::rt("hashValuesMut", values), (_, "iter" | "iter_mut") if !set => Expr::rt("hashIter", values), (_, "iter" | "keys") => Expr::rt("hashKeys", values), (_, "values" | "values_mut") => Expr::rt("hashValues", values), @@ -637,6 +643,7 @@ fn btree<'tcx>( (_, "remove") if set => Expr::rt("btreeDelete", values), (_, "remove") => Expr::rt("btreeRemove", values), (_, "remove_entry") => Expr::rt("btreeRemoveEntry", values), + (_, "retain") if !set && b.t.needs_place(arg(coll, 1)) => Expr::rt("btreeRetainMut", values), (_, "retain") => Expr::rt("btreeRetain", values), (_, "first_key_value") => Expr::rt("btreeFirst", values), (_, "last_key_value") => Expr::rt("btreeFirst", last(values)), @@ -648,6 +655,8 @@ fn btree<'tcx>( (_, "last") => Expr::rt("btreeFirstKey", last(values)), (_, "first_entry") => Expr::rt("btreeFirstEntry", values), (_, "last_entry") => Expr::rt("btreeFirstEntry", last(values)), + (_, "iter_mut") if b.t.needs_place(arg(coll, 1)) => Expr::rt("btreeIterMut", values), + (_, "values_mut") if b.t.needs_place(arg(coll, 1)) => Expr::rt("btreeValuesMut", values), (_, "iter" | "iter_mut") if !set => Expr::rt("btreeIter", values), (_, "iter" | "keys") => Expr::rt("btreeKeys", values), (_, "values" | "values_mut") => Expr::rt("btreeValues", values), @@ -666,6 +675,7 @@ fn btree<'tcx>( Expr::rt(f, super::iter::tail(values, droppers)) } (_, "range") if set => Expr::rt("btreeRangeKeys", values), + (_, "range_mut") if b.t.needs_place(arg(coll, 1)) => Expr::rt("btreeRangeMut", values), (_, "range" | "range_mut") => Expr::rt("btreeRange", values), (_, "entry") => Expr::rt("entry", values), (_, "split_off") => Expr::rt("btreeSplitOff", values), @@ -803,10 +813,14 @@ fn deque<'tcx>( (_, "push_front") => Expr::rt("dequePushFront", values), (_, "pop_back") => Expr::rt("dequePopBack", values), (_, "pop_front") => Expr::rt("dequePopFront", values), + (_, "front_mut") if b.t.needs_place(item) => Expr::rt("dequeEndMut", values), + (_, "back_mut") if b.t.needs_place(item) => Expr::rt("dequeEndMut", back(values)), + (_, "get_mut") if b.t.needs_place(item) => Expr::rt("dequeGetMut", values), (_, "front" | "front_mut") => Expr::rt("dequeEnd", values), (_, "back" | "back_mut") => Expr::rt("dequeEnd", back(values)), (_, "get" | "get_mut") => Expr::rt("dequeGet", values), (_, "truncate") => Expr::rt("dequeTruncate", values), + (_, "retain_mut") if b.t.needs_place(item) => Expr::rt("dequeRetainMut", values), (_, "retain" | "retain_mut") => Expr::rt("dequeRetain", values), (_, "remove") => Expr::rt("dequeRemove", values), (_, "insert") => Expr::rt("dequeInsert", values), @@ -814,6 +828,7 @@ fn deque<'tcx>( values.push(eq_fn(b, peel(b, item), span)); Expr::rt("dequeContains", values) } + (_, "iter_mut") if b.t.needs_place(item) => Expr::rt("dequeIterMut", values), (_, "iter" | "iter_mut") => Expr::rt("dequeIter", values), (_, "drain") => { let droppers = entry_droppers(b, coll, span); @@ -904,7 +919,7 @@ fn entry<'tcx>(b: &mut Body<'_, '_, 'tcx>, coll: Ty<'tcx>, name: &str, args: Vec values.push(b.fn_value(default, tcx.mk_args(&[value.into()]), span)); Expr::rt(mutable("entryOrInsertWith"), values) } - "and_modify" => Expr::rt("entryAndModify", values), + "and_modify" => Expr::rt(mutable("entryAndModify"), values), "key" => Expr::rt("entryKey", values), "into_key" => values.pop()?.member("k"), "get" => Expr::rt("entryGet", values), @@ -1234,7 +1249,12 @@ pub fn trait_fn(tcx: ty::TyCtxt<'_>, tr: &str, item: &str) -> rustc_hir::def_id: /// `rt.Iter` of its entries, keys, or items, which by value drops those it still holds. pub fn into_iter<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, value: Expr, span: Span) -> Option { let coll = ty.peel_refs(); + // A `&mut` lends each value JS copies as its place. + let places = |n: usize| ty.ref_mutability() == Some(ty::Mutability::Mut) && b.t.needs_place(arg(coll, n)); let name = match b.t.std_of(coll)? { + Std::HashMap if places(1) => "hashIterMut", + Std::BTreeMap if places(1) => "btreeIterMut", + Std::VecDeque if places(0) => "dequeIterMut", Std::HashMap => "hashIter", Std::HashSet => "hashKeys", Std::BTreeMap => "btreeIter", diff --git a/ts/src/lower/iter.rs b/ts/src/lower/iter.rs index d2dcb45ab..4616453f5 100644 --- a/ts/src/lower/iter.rs +++ b/ts/src/lower/iter.rs @@ -153,19 +153,36 @@ pub fn into_iter<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, value: Expr, sp true => by_ref(iter, elem), false => iter, }; + // Elements a `&mut` lends as their places, which JS copies. + let places = |b: &Body<'_, '_, 'tcx>, elem: Ty<'tcx>| { + ty.ref_mutability() == Some(ty::Mutability::Mut) && b.t.needs_place(elem) + }; match ty.peel_refs().kind() { + ty::Slice(elem) | ty::Array(elem, _) if places(b, *elem) => { + Some(Expr::rt("iterSliceMut", vec![library::elements(value, ty)])) + } ty::Slice(elem) | ty::Array(elem, _) => { let values = each(b, *elem, vec![library::elements(value, ty)]); Some(items(Expr::rt("iterSlice", values), *elem)) } ty::Adt(adt, args) => match Std::of(tcx, adt.did())? { + Std::Vec if places(b, args.type_at(0)) => { + Some(Expr::rt("iterSliceMut", vec![library::elements(value, ty)])) + } Std::Vec => { let values = each(b, args.type_at(0), vec![library::elements(value, ty)]); Some(items(Expr::rt("iterSlice", values), args.type_at(0))) } + // A `&mut` lends the payload JS copies as the `Option`'s own place, while it has one. + Std::Option if places(b, args.type_at(0)) => { + let mut values = vec![value]; + values.extend(b.t.none_arg(args.type_at(0))); + Some(Expr::rt("iterOption", vec![Expr::rt("optionAsMut", values)])) + } + // A `&mut` to one of another payload is its place, and yields the payload itself. Std::Option => { let inner = args.type_at(0); - let mut values = each(b, inner, vec![value]); + let mut values = each(b, inner, vec![b.t.pointee_value(ty, value)]); if let Some(none) = b.t.none_arg(inner) { values.resize(2, Expr::undefined()); values.push(none); @@ -243,6 +260,10 @@ pub fn call<'tcx>( // Where iterators come from. match (owner, name) { + ("slice", "iter_mut") if b.t.needs_place(targ(0)?) => { + let s = library::elements(args.pop()?, Ty::new_slice(tcx, targ(0)?)); + return Some(Expr::rt("iterSliceMut", vec![s])); + } ("slice", "iter" | "iter_mut") => { let s = args.pop()?; let s = library::elements(s, Ty::new_slice(tcx, targ(0)?)); @@ -435,7 +456,8 @@ pub fn call<'tcx>( }; method(&camel, tail(rest, droppers)) } - "max" | "min" if primitive(item.peel_refs()) => { + // Not of places, which the runtime would compare as the objects they are. + "max" | "min" if primitive(item.peel_refs()) && !b.t.has_place(item) => { // A `BTreeMap`'s `into_keys` reads the one end and drops the rest with it. if std_iter_path(tcx, self_ty).is_some_and(|p| p == ["collections", "btree", "map", "IntoKeys"]) && b.t.drops(self_ty) diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index 226cdacf9..5053fb954 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -1100,6 +1100,17 @@ fn mapping<'tcx>( }; rt2(args, of, &super::camel(&name)) } + // An element JS copies is lent as its place, and an object as itself. + ("slice", "first_mut" | "last_mut" | "get_mut") if name != "get_mut" || Int::of(targ(gargs, 1)).is_some() => { + let elem = targ(gargs, 0); + let mut values = args; + values[0] = elements(values[0].clone(), Ty::new_slice(tcx, elem)); + let name = match b.t.needs_place(elem) { + true => name.as_str(), + false => name.strip_suffix("_mut")?, + }; + rt2(values, "slice", &super::camel(name)) + } ("slice", "split_first_chunk") => { let n = gargs.consts().next()?.try_to_target_usize(tcx)?; let mut values = args; @@ -1121,8 +1132,7 @@ fn mapping<'tcx>( false => return vec_clone(b, slice, elem, span), } } - ("slice", "first_mut") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceFirst", args), - ("slice", "last" | "last_mut") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceLast", args), + ("slice", "last") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceLast", args), ("slice", "reverse") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceReverse", args), ("slice", "swap") if !is_u8(targ(gargs, 0)) => Expr::rt("sliceSwap", args), ("slice", "contains") => { diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index d43537683..fbf7183ee 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -3,8 +3,8 @@ //! expression through a temporary: a place to replace (`mem::take`), a range to slice //! by, an array of bytes to read, `format_args!`'s parts, and `?`'s `ControlFlow`. -use rustc_abi::VariantIdx; -use rustc_middle::mir::{Operand, Place}; +use rustc_abi::{FieldIdx, VariantIdx}; +use rustc_middle::mir::{Operand, Place, ProjectionElem}; use rustc_middle::ty::{self, GenericArgsRef, Instance, Ty, TyCtxt}; use rustc_span::{Span, Spanned}; @@ -340,6 +340,37 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { return None; } let t = &*self.b.t; + // Mappings that lend an element JS copies as its place, as a map's `get_mut` does. + let lends = match library::key(tcx, def_id) { + Some((owner, name)) => match (owner.as_str(), name.as_str()) { + ("slice", "get_mut" | "first_mut" | "last_mut" | "iter_mut") => true, + ("IntoIterator", "into_iter") => gargs.types().next().is_some_and(|ty| { + ty.ref_mutability() == Some(ty::Mutability::Mut) + && match ty.peel_refs().kind() { + ty::Slice(_) | ty::Array(..) => true, + _ => matches!( + t.std_of(ty.peel_refs()), + Some(Std::Vec | Std::Option | Std::HashMap | Std::BTreeMap | Std::VecDeque) + ), + } + }), + _ => false, + }, + None => false, + }; + // Places held in what it is given, not one it is given, or that the iterator it adapts + // yields, were made where they came from, as are what it hands a closure of them. + let sig = tcx.fn_sig(def_id).instantiate(tcx, gargs).skip_norm_wip(); + let adapts = tcx + .instantiate_bound_regions_with_erased(sig) + .inputs() + .iter() + .any(|&i| { + t.place_pointee(i).is_none() && t.has_place(i) || t.iter_item(i).is_some_and(|item| t.has_place(item)) + }); + if lends || adapts { + return None; + } let handed = gargs.types().any(|ty| { let sig = match ty.kind() { ty::Closure(_, args) => args.as_closure().sig(), @@ -499,6 +530,23 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { let option = dest.ty(&self.mir.local_decls, tcx).ty; done(self.swap_out(place, option, none, "taken", span, out), true) } + // The place of the payload, if any: `as_mut`'s, or what `iter_mut` yields. + ("Option", "as_mut" | "iter_mut") if self.b.t.needs_place(targ(0)?) => { + let (target, payload) = self.payload_place(&args[0].node, targ(0)?, span, out)?; + let Some(payload) = payload else { + return done(target, true); + }; + let none = target.clone().binary("===", self.b.t.none(targ(0)?)); + let place = self.make_place(payload, target, span, out); + let lent = Expr::Cond(Box::new(none), Box::new(Expr::undefined()), Box::new(place)); + match name.as_str() { + "as_mut" => done(lent, true), + _ => done(Expr::rt("iterOption", vec![lent]), true), + } + } + ("Option", "get_or_insert" | "get_or_insert_with" | "get_or_insert_default" | "insert") => { + self.option_insert(&name, targ(0)?, args, dest, span, out) + } // Indexing, whose result a `&mut` reads in place. ("Index" | "IndexMut", "index" | "index_mut") => self.index(&name, gargs, args, dest, span, out), // A `&mut` to a value JS copies, such as through a `MutexGuard`, reads and writes @@ -746,6 +794,112 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } } + /// The path of the `Option` a `&mut` operand borrows, and the place of its `Some`'s + /// payload, of type `payload`, unless the reference is refused. + fn payload_place( + &mut self, + op: &Operand<'tcx>, + payload: Ty<'tcx>, + span: Span, + out: &mut Vec, + ) -> Option> { + let (target, place) = self.borrowed_place(op, span, out)?; + let elems = [ + ProjectionElem::Downcast(None, VariantIdx::from_u32(1)), + ProjectionElem::Field(FieldIdx::ZERO, payload), + ]; + Some((target, place.map(|p| p.project_deeper(&elems, self.tcx)))) + } + + /// `get_or_insert`, `get_or_insert_with`, `get_or_insert_default`, or `insert` of the + /// `Option` a `&mut` borrows: the store, then the payload it lends, an alias of it where + /// the destination is read only as one. + fn option_insert( + &mut self, + name: &str, + payload_ty: Ty<'tcx>, + args: &[Spanned>], + dest: Place<'tcx>, + span: Span, + out: &mut Vec, + ) -> Option> { + let tcx = self.tcx; + let (target, payload) = self.payload_place(&args[0].node, payload_ty, span, out)?; + let Some(payload) = payload else { + return Some(Some((target, true))); + }; + let whole = tcx.mk_place_deref(args[0].node.place()?); + let option_ty = whole.ty(&self.mir.local_decls, tcx).ty; + // What it inserts, made before the `Option` is read, as Rust makes the argument. + let value = match name { + "get_or_insert" | "insert" => { + let value = self.operand(&args[1].node, span, out); + Some(self.path(value, "value", out)) + } + _ => None, + }; + if name == "insert" { + // What it replaced drops, as `*self = Some(value)` drops it. + let old = self.b.fresh("old"); + let drop = self.b.t.drop_value(Expr::ident(&old), option_ty, span); + if drop.is_some() { + out.push(StmtKind::decl(false, old, None, Some(target.clone())).at(None)); + } + out.extend(self.store(whole, value?, span)); + out.extend(drop.map(|drop| StmtKind::Expr(drop).at(None))); + } else { + let mut then = Vec::new(); + let mut els = Vec::new(); + let value = match name { + "get_or_insert" => { + let value = value?; + if let Some(drop) = self.b.t.drop_value(value.clone(), payload_ty, span) { + els.push(StmtKind::Expr(drop).at(None)); + } + value + } + "get_or_insert_default" => library::default_value(self.b, payload_ty)?, + _ => { + let f_ty = args[1].node.ty(&self.mir.local_decls, tcx); + if let ty::FnDef(f, f_args) = *f_ty.kind() { + self.b.call_def(f, f_args.skip_binder(), Vec::new(), span, &mut then) + } else { + // A closure it doesn't call drops; one it calls drops as `FnOnce` does. + let f = self.operand(&args[1].node, span, out); + let f = self.path(f, "f", out); + if let Some(drop) = self.b.t.drop_value(f.clone(), f_ty, span) { + els.push(StmtKind::Expr(drop).at(None)); + } + match f_ty.kind() { + ty::Closure(_, c) + if c.as_closure().kind() != ty::ClosureKind::FnOnce && self.b.t.drops(f_ty) => + { + Expr::rt("callOnce", vec![f]) + } + _ => f.call(Vec::new()), + } + } + } + }; + then.extend(self.store(whole, value, span)); + let cond = target.clone().binary("===", self.b.t.none(payload_ty)); + out.push(StmtKind::If { cond, then, els }.at(None)); + } + let read = Expr::As(Box::new(target.clone()), self.b.t.ty(payload_ty, span)); + if let Some(local) = dest.as_local() + && self.defs[local] == 1 + && matches!(self.slots[local], Slot::Var(_)) + { + self.slots[local] = Slot::Alias(Some(read)); + self.reborrows.insert(local, payload); + return Some(None); + } + match self.b.t.needs_place(payload_ty) { + true => Some(Some((self.make_place(payload, target, span, out), true))), + false => Some(Some((read, true))), + } + } + /// The place a reference operand reads in place, if it is one. fn alias_place(&self, op: &Operand<'tcx>) -> Option { let (Operand::Copy(place) | Operand::Move(place)) = op else { diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index a27ffa8ca..235bf9f0d 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -616,6 +616,10 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { Some(Expr::ident("Object").member("assign").call(vec![target, value.clone()])) } Some(ObjectKind::Bytes) => Some(target.member("set").call(vec![value.clone()])), + // A tuple's array has a fixed length, so its parts copy over in place. + Some(ObjectKind::Array) if matches!(pointee.kind(), ty::Tuple(_)) => { + Some(Expr::ident("Object").member("assign").call(vec![target, value.clone()])) + } _ => None, }; match (e, alias) { @@ -772,6 +776,8 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { }; match target { Expr::Located(_, e) => self.stable_path(*e, own, span, out), + // A payload `Option::insert` lends, read as its type. + Expr::As(e, ty) => Expr::As(Box::new(self.stable_path(*e, own, span, out)), ty), Expr::Ident(_) | Expr::This => target, Expr::Member(object, key) => Expr::Member(Box::new(base(self, *object)), key), Expr::Index(object, i) => { diff --git a/ts/src/lower/mir/step.rs b/ts/src/lower/mir/step.rs index 0044d56fd..63a8d07e1 100644 --- a/ts/src/lower/mir/step.rs +++ b/ts/src/lower/mir/step.rs @@ -49,7 +49,9 @@ impl<'tcx> Fx<'_, '_, '_, 'tcx> { .filter(|&l| !self.is_arg(l) && l != mir::RETURN_PLACE && self.defs[l] == 1) .filter(|&l| { let ty = mir.local_decls[l].ty; - array_iter(tcx, ty).is_some() || super::small_range(tcx, ty) + // An element JS copies is lent as its place, which `rt.iterSliceMut` makes. + let places = || self.b.t.iter_item(ty).is_some_and(|item| self.b.t.has_place(item)); + array_iter(tcx, ty).is_some() && !places() || super::small_range(tcx, ty) }) .collect(); if iters.is_empty() {