Skip to content

feat(ts): wide integers are numbers while safe, and each integer type is branded - #26

Merged
kixelated merged 11 commits into
mainfrom
quest/m2/ts-wide-ints
Oct 24, 2026
Merged

kixelated merged 11 commits into
mainfrom
quest/m2/ts-wide-ints

Conversation

@kixelated

@kixelated kixelated commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The wide integer spike: rust2-ts translated u64, i64, u128, and i128 to bigint, which the design kept until just ts bench measured it. #15's gap tables put bigint at up to 55 ns per varint and 30-140 ns per frame header.

Approach

Measured four representations on the codec's varint, frame, and message paths, and on an arithmetic loop, then shipped the winner for all four types:

  1. bigint, today's output (main's translation as a route).
  2. Limbs: every value an immutable { hi, lo } object (first shipped, then measured as a route).
  3. Unboxed halves: two uint32 numbers in locals, fields, arguments, and tuples, boxed only inside Result, with a hi register for returns, as Scala.js does (a hand-written translation of the bench paths).
  4. Number or limbs (shipped): a number while the value is a safe integer, and limbs past 2^53. Each value has one form, so x === 0 is exact.

Limbs allocate per value, and a V8 object costs about what a small bigint does, so limbs lost decode in V8. Unboxed halves won decode, but would lower every Rust value to two JS values throughout the translator. Number-or-limbs ties unboxed halves on the codec, beats it on sums, keeps one JS value per Rust value, and reads best: frameStart: 0, return rt.Ok([first, rest]), this.frameStart !== 0. It's also what moq's hand-written TS does for varints.

What changed:

  • rt.ts: rt.u64, rt.i64, rt.u128, and rt.i128 take numbers or limbs. Sums, products, quotients, shifts, and bitwise ops stay in numbers while the result is safe. Past 2^53 they fall back on 64-bit limb arithmetic: add, sub, mul by a 32-bit factor, and long division by a 32-bit divisor are computed on the halves, the rest through bigint. 128-bit limbs go through bigint.
  • Translator: literals are plain numbers when safe, else rt.u64.of(0xffffffffffffffffn). A cast that keeps the value is x as rt.u64, x as u32 is rt.u64.low(x), and every other operator and comparison is a runtime call. == against a literal stays ===.
  • Types: every integer type is its own TS type named as Rust's, rt.u8 through rt.i128 and rt.usize: a number with a type-only brand, or limbs past 2^53 for the wide four. The brand is an optional unique symbol key, so tsc refuses a u16 where a u8 goes, or a u64 where an i64 goes, while a plain number such as a literal passes for any. fixtures/lang/brands.ts holds five such mixes under @ts-expect-error.
  • Iterators (feat(ts): translate iterators through a DONE protocol #23): ranges of wide integers carry their type (new rt.Range(a, b, rt.u64)) to step past 2^53, and max/min/max_by_key compare limbs through rt.lt. A for over a wide range iterates that rt.Range.
  • Tests: differential.ts wide runs every 64- and 128-bit lang case over each pair of values next to a power of two (2^k ± 1 at limb, safe-integer, and sign edges, -2^k ± 1 for small and safe-edge negatives, plus four unstructured values) and 14 shift amounts. That's 175k cases, about 5 s. Each result must also equal its bytes read back, which a wide value does only in its one form. A cast case now prints its text as well as its bytes, which shows a value's sign and form. iters steps ranges across 2^53 and up to u64::MAX. Of 18 hand mutations of the runtime's fast paths (a carry, a shift, the long division, the canonical form, a cast), the sweep caught all 18 and the random cases alone missed 6.

Numbers

ns per item: the median of 25 interleaved samples of 15 ms. Load average 9-23 on the shared 32-thread host. A/A noise at the median workload was 2.6% (Node), 5.9% (Bun), and 4.9% (Chrome).

workload Node bigint → shipped (unboxed) Bun Chrome
varint/quic/1B encode 48 → 17 (23) 56 → 27 (21) 43 → 15 (13)
varint/quic/8B encode 191 → 153 (149) 165 → 106 (100) 163 → 134 (124)
varint/leading-ones/8B encode 184 → 141 (135) 163 → 119 (99) 162 → 132 (124)
varint/quic/1B decode 58 → 47 (45) 59 → 55 (50) 47 → 31 (31)
varint/quic/2B decode 106 → 100 (106) 131 → 145 (121) 80 → 84 (82)
varint/quic/8B decode 137 → 140 (134) 218 → 193 (158) 108 → 136 (106)
frames/video/lite-07 decode 272 → 241 (218) 393 → 278 (253) 205 → 182 (177)
frames/video/lite-07 encode 385 → 304 (303) 403 → 250 (278) 347 → 349 (234)
group/lite-07 decode 1110 → 824 (858) 1040 → 809 (727) 896 → 622 (616)
Every workload, with limbs for every value

Node v24.21.0

workload op hand-written bigint shipped A/A limbs unboxed
varint/quic/1B encode 36 47.8 17.3 17.6 17.7 22.5
varint/quic/1B decode 3.73 58.3 47.3 43.7 57.4 45
varint/quic/2B encode 37.6 97.3 58.2 54.8 57.1 59.6
varint/quic/2B decode 4.35 106 100 98.4 115 106
varint/quic/4B encode 37 91.2 59.5 58.8 55.8 63.3
varint/quic/4B decode 5.93 104 96.9 99.3 112 98.4
varint/quic/8B encode 44.7 191 153 151 148 149
varint/quic/8B decode 14 137 140 147 164 134
varint/leading-ones/1B encode 38.9 77.9 46.4 45.3 47.3 52.8
varint/leading-ones/1B decode 3.73 56.7 45.3 43.4 50.9 44.3
varint/leading-ones/2B encode 37.6 127 94 101 91.8 92.8
varint/leading-ones/2B decode 4.39 111 107 108 120 107
varint/leading-ones/4B encode 48.3 147 102 109 105 98.1
varint/leading-ones/4B decode 6.39 113 109 111 114 105
varint/leading-ones/8B encode 54.6 184 141 143 137 135
varint/leading-ones/8B decode 18.4 192 141 170 164 145
frames/video/lite-06 encode 2610 306 250 258 271 237
frames/video/lite-06 decode 148 251 221 227 273 209
frames/audio/lite-06 encode 1830 323 308 263 267 267
frames/audio/lite-06 decode 141 252 225 224 299 214
group/lite-06 encode 8910 3050 1290 1830 2010 1050
group/lite-06 decode 2020 1110 797 797 858 817
frames/video/lite-07 encode 1660 385 304 313 310 303
frames/video/lite-07 decode 145 272 241 236 307 218
frames/audio/lite-07 encode 1490 386 354 312 363 314
frames/audio/lite-07 decode 141 270 235 241 312 229
group/lite-07 encode 9250 2880 2110 1680 1950 2690
group/lite-07 decode 2080 1110 824 822 871 858

Bun 1.4.2

workload op hand-written bigint shipped A/A limbs unboxed
varint/quic/1B encode 77.2 56.3 26.7 24 26.6 20.9
varint/quic/1B decode 4.31 59.3 54.6 50.4 54 50
varint/quic/2B encode 71.2 79.6 51 48.3 50 42.2
varint/quic/2B decode 4.78 131 145 121 125 121
varint/quic/4B encode 71.7 84.7 52 52.4 52.3 46.4
varint/quic/4B decode 6.1 133 147 124 125 118
varint/quic/8B encode 84.1 165 106 105 102 99.8
varint/quic/8B decode 13.5 218 193 173 175 158
varint/leading-ones/1B encode 66.8 65.5 35.7 33.4 38.3 32.2
varint/leading-ones/1B decode 4.31 61 63.6 51.2 54.7 50.4
varint/leading-ones/2B encode 67.1 113 78.1 70.2 73.7 67.8
varint/leading-ones/2B decode 4.79 134 141 122 122 119
varint/leading-ones/4B encode 65.5 119 79.9 76.6 81 73.9
varint/leading-ones/4B decode 6.49 128 134 118 121 120
varint/leading-ones/8B encode 70.9 163 119 101 111 98.8
varint/leading-ones/8B decode 14.1 220 186 164 162 151
frames/video/lite-06 encode 1100 334 205 216 205 219
frames/video/lite-06 decode 198 397 274 258 287 248
frames/audio/lite-06 encode 1110 316 216 212 207 221
frames/audio/lite-06 decode 200 400 274 264 295 248
group/lite-06 encode 8340 2590 2070 1940 2080 2020
group/lite-06 decode 2860 1070 795 771 787 730
frames/video/lite-07 encode 1090 403 250 248 254 278
frames/video/lite-07 decode 198 393 278 267 288 253
frames/audio/lite-07 encode 1090 397 251 257 260 280
frames/audio/lite-07 decode 195 410 279 270 287 246
group/lite-07 encode 8160 2610 2390 2260 2200 2310
group/lite-07 decode 2990 1040 809 753 787 727

Chromium 155

workload op hand-written bigint shipped A/A limbs unboxed
varint/quic/1B encode 76.6 42.6 14.7 12.6 12.8 13.3
varint/quic/1B decode 2.82 47.3 31.3 30.6 37.9 31.3
varint/quic/2B encode 46.7 76 47.2 40.8 45.2 41.3
varint/quic/2B decode 3.45 80 83.8 79.2 82 81.7
varint/quic/4B encode 55.5 86.7 48.7 45.4 49.6 45.5
varint/quic/4B decode 4.81 76.4 80.6 78.6 83 77.6
varint/quic/8B encode 58 163 134 126 132 124
varint/quic/8B decode 17.1 108 136 135 120 106
varint/leading-ones/1B encode 42.5 60.4 39.8 33.2 33.4 33.2
varint/leading-ones/1B decode 2.83 47.8 33.1 32.3 36 33.2
varint/leading-ones/2B encode 48.6 105 90.9 74.6 76 75.3
varint/leading-ones/2B decode 3.49 79.2 77.7 78.6 85.5 80.4
varint/leading-ones/4B encode 56.4 114 88.4 84.1 85.8 84.1
varint/leading-ones/4B decode 5.24 81.8 81.9 82.1 84.2 84.8
varint/leading-ones/8B encode 59.4 162 132 124 121 124
varint/leading-ones/8B decode 17.9 108 155 136 130 110
frames/video/lite-06 encode 6080 258 322 198 174 163
frames/video/lite-06 decode 111 193 178 174 192 170
frames/audio/lite-06 encode 5670 276 290 210 188 184
frames/audio/lite-06 decode 111 194 177 176 191 168
group/lite-06 encode 30400 2010 1870 1640 1650 1610
group/lite-06 decode 1830 869 637 626 658 620
frames/video/lite-07 encode 5750 347 349 361 249 234
frames/video/lite-07 decode 109 205 182 184 206 177
frames/audio/lite-07 encode 5620 334 322 322 242 228
frames/audio/lite-07 decode 111 204 181 184 205 176
group/lite-07 encode 31000 2150 2120 1940 1850 1810
group/lite-07 decode 1810 896 622 633 649 616

Arithmetic, ns per item over 1024 items, as the translator emits each kernel. accounting adds, subtracts, and compares u64s around 2^40. rescale computes t * 90_000 / 1_000_000 with t near 1.7e12, so the product passes 2^53. Native Rust takes 1.0 and 1.6 ns.

kernel engine bigint shipped limbs unboxed
accounting Node 39 8.1 27 16
accounting Bun 76 36 26 10
accounting Chrome 31 5.3 23 15
rescale Node 45 85 58 43
rescale Bun 85 124 66 50
rescale Chrome 36 57 47 39

A loop whose values all pass 2^53 takes 77 ns in Node, against bigint's 35.

Bundle: the translated codec grows from 31.3 KB to 37.5 KB raw, and from 8.8 KB to 11.0 KB gzipped, all of it runtime.

Verdict: number-or-limbs is the representation for all four types. It matches unboxed halves on the consumer's paths, while unboxed halves would add a second lowering for every value. Its loss is arithmetic past 2^53: 1.5-1.9x slower than bigint when a product passes 2^53, and 2x when every value is past it.

Decisions

  1. Type-level brand, decided by the maintainer:

    • (a) Plain numbers, no brand on numbers.
    • ✅ (b) Plain numbers, branded with Rust type names: rt.u8 through rt.i128, type-only, so tsc tells every integer type apart at no run-time cost.

    Branding costs nothing at run time: TypeScript erases it, and the translated codec bundles to the same JS before and after (byte-identical unminified; 48372 bytes minified both ways, and 13493 vs 13492 gzipped, the difference being Bun's choice of short names). With identical JS, just ts bench can only show noise. A run on the branded output passed, but the shared host was loaded (A/A noise 4.9-7.2% at the median, and hand-written moq 20-50% slower than in the table above), so its numbers are not a new baseline.

Impact

  • Translator output: every integer type is rt.<its Rust name>: u8-u32, usize, and the signed ones instead of number, and u64, i64, u128, and i128 (a branded number or rt.U64Limbs, and so on) instead of bigint. A cast that keeps the value is x as rt.u16. Safe literals are numbers, operators and comparisons on them are rt.u64.* calls, and narrowing is rt.u64.low(x).
  • rt.ts: new exported types u8 through i128, usize, and isize, the wide four's *Limbs, Limbs, and WideInt. New rt.lt. rt.u64 and the other three are WideInts with of, cast, low, comparisons, and bitwise methods. rt.max and rt.min take numbers only, and rt.option.mapOr infers its type from its closure, not its fallback. Int<T> is no longer constrained, and bigint appears nowhere.
  • rt/iter.ts: Range takes an optional integer type, RangeInclusive's third argument is an Int<T>, and max/min/maxByKey/minByKey take Limbs keys where they took bigint.
  • differential.ts takes an optional wide argument.
  • No MIGRATE.md entry: rust2-ts is unreleased (0.0.0, publish = false) and has none.

Alternatives

  • Limbs for every value: shipped first, then measured slower than number-or-limbs on every decode path in V8. That was 15-30% on frames, because each value is an allocation.
  • Unboxed halves: the fastest on rescale and in JavaScriptCore's accounting, and tied on the codec. It needs a pair-valued lowering of every expression, pattern, field, argument, and return. Not done.
  • bigint kept: slowest on encode in every engine, and on everything in JavaScriptCore.
  • A required brand: every literal would need a cast. The optional one keeps literals plain and still refuses one type's value where another's goes.

Follow-ups

  • Chrome's 8-byte varint decode is 25-45% slower than bigint. from_halves goes through rt.u64.or(rt.u64.shl(hi, 32), lo), and a fused form is likely worth measuring.
  • A product of two numbers past 2^53 boxes both factors before multiplying. Multiplying the numbers' halves directly would cut rescale's allocations.
  • just ts bench has no way to load another translation as a route. This spike and perf(ts): number-only small ints, inline from_be_bytes, and indexed byte patterns #15 both patched main.ts locally to do it, and a --route name=dir option would keep A/B runs reproducible.

(written by Opus 5.5)

🤖 Generated with Claude Code

https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

Quest-Claim: c50f424a11193534
kixelated and others added 5 commits October 24, 2026 05:52
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Ranges of 64- and 128-bit integers carry their type, so they step past 2^53
into limbs, and max and min compare limbs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated kixelated changed the title Wide integer spike feat(ts): 64- and 128-bit integers are numbers while safe, limbs past 2^53 Oct 24, 2026
…sed or wrapped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated
kixelated marked this pull request as ready for review October 24, 2026 14:35
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T17:07:15.731152Z 83640b3 New commits
🔒 Security Review ✅ Completed 2026-10-24T17:08:38.472040Z 83640b3 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 691b800bf7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ts/runtime/rt.ts Resolved
kixelated and others added 4 commits October 24, 2026 07:47
`!`, `&`, and `^` on two safe `i64` or `i128` numbers can make -2^53, which
was left a number, so it compared unequal to the same value as limbs. The
lang fixture now checks each result equals its bytes read back, and the wide
sweep adds small and safe-edge negative operands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Every integer type is its own TypeScript type, `rt.u8` through `rt.i128`
and `rt.usize`, a number with a type-only brand (limbs past 2^53 for the
wide four), so `tsc` refuses one type's value where another's goes. The
brand is optional, so a plain number such as a literal passes for any
type. A cast that keeps the value is now `x as rt.u16`. The lang fixture's
`brands.ts` holds mixes `tsc` must refuse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated kixelated changed the title feat(ts): 64- and 128-bit integers are numbers while safe, limbs past 2^53 feat(ts): wide integers are numbers while safe, and each integer type is branded Oct 24, 2026
@kixelated

Copy link
Copy Markdown
Collaborator Author

Summary before merge at 83640b3:

  • Main (feat(ts): emit each module in Rust source order #27, fix(ts): type-check values of type ! where a value goes #28, feat(bench): attribute an edit rebuild by unit, critical path, and stage #22) merged in; no conflicts. just check, just test (including differential.ts wide), and just ts moq pass locally, and CI is green.
  • Codex's P1 (a signed bitwise result of -2^53 left a non-canonical number) is fixed in e4d46ba. It was reproduced first by a new canonical-form check in the lang fixture and negative safe-edge operands in the wide sweep.
  • Decision, per the maintainer: plain numbers, branded with Rust type names (rt.u8 through rt.i128, rt.usize). The brand is type-only and optional, so literals stay plain while tsc refuses mixed types. fixtures/lang/brands.ts proves five mixes under @ts-expect-error. A cast that keeps the value is x as rt.u16. The translated codec's JS is unchanged: byte-identical unminified, 48372 bytes minified both ways, and 13493 vs 13492 gzipped.
  • Codex found nothing on the final head. quest check --base origin/main passes.

(written by Opus 5.5)

@kixelated
kixelated merged commit c13980d into main Oct 24, 2026
1 check passed
kixelated added a commit that referenced this pull request Oct 24, 2026
A u64 is now a number while safe, or limbs, so the hand-written executor and the
bench's translated routes make each value with `rt.u64.of` and read the sum with
`rt.u64.toBeBytes`, rather than as a bigint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated added a commit that referenced this pull request Oct 24, 2026
…e async spike (#16)

* chore(quest): claim quest/m2/ts-async-spike.md

Quest-Claim: b76999a56b3a7148

* wip(ts): async spike, generators from THIR with drops

Checkpoint: the task fixture, its FIFO executors in Rust and TS, and the
generator prototype passing the trace differential test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* wip(ts): async spike, MIR state machine prototype

Both prototypes pass the task fixture's trace differential test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* wip(ts): async spike, hoisted generators and the handoff bench's native side

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* wip(ts): async spike, generators win; delete the MIR state machines

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* wip(ts): async spike cleanup: one closure path, trimmed runtime, text diffs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): census-safe drop analysis, and refuse a pattern-bound parameter that drops

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): an async block drops only what it owns, on the path that moves it

A block borrowing a value that drops no longer drops it when cancelled, a
block created on one branch moves its captures out on that branch only, and
a block drops the captures it owns when it returns or is cancelled
mid-await, in capture order after its locals. The task fixture's `blocks`
covers each against native Rust.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* test(ts): a loop broken inside a drop scope still ends its match arm

Merging main's tail loops taught `breaks_out` about `try` blocks, which
wrap a loop body that holds a value that drops. Without that, the task
fixture's `turns` falls through to the next arm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): rt.spawn yields after its poll budget even when a task wakes itself

`run` cleared `scheduled` before its batch, so a task waking itself queued
another microtask, which ran ahead of the `setTimeout` continuation and
starved timers. `scheduled` now stays set until the queue drains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): refuse dropping a borrow of a value that drops through an untyped holder

An `Arc`, a `Mutex`, and a generic class's glue drop their contents through
`[Symbol.dispose]`, but a reference is its referent in JS: `Arc<&Noisy>`
dropping its last count would drop the `Noisy` it borrows. Such a holder now
fails with its span, as the reject fixture's `shared_borrow` shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): refuse an operand that drops ahead of an .await in the same call

`consume(guard, fut.await)` moved `guard` into a temporary before the
`yield`, where no scope dropped it if the future was cancelled. It now fails
with its span (3 in moq-net, none in kio). The README and the Drop quest list
it with the `Arc` of a borrow, and the quest's counts follow the census
after main's merges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): rt.spawn rejects when a finished future panics as it drops

The completed future's disposal ran outside the `try` that settles the
promise, so a panic there left it pending and escaped the scheduler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): a let that binds part of a value that drops leaves the rest to drop

`let [kept, _] = pair` moved `pair` out whole through the destructuring
shortcut, so the skipped guard never dropped. A place now binds part by part
and keeps the rest for its scope to drop, and a temporary bound only in part
fails with its span, as a `match` or `if let` on one does (27 in moq-net).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): drop a pinned box, and refuse two more drops a cancel or pattern skips

- `Pin<P>` drops as its pointer does, so `Pin::new(Box::new(guard))` drops
  the guard.
- `Some(..)` names no field, so a `match` or `if let` on a temporary that
  drops no longer counts it as moving the payload out (3 in moq-net).
- A value that drops, assigned to a place whose index awaits, would wait out
  the `.await` in a temporary no scope drops: it now fails with its span.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): a ref binding borrows its place, and `let _` still evaluates one

`let ref r = g` moved and cleared `g`, so nothing dropped it; it now
borrows `g` where it is, and `let ref r = make()` owns the temporary it
keeps alive to the end of the block. `let _ = guards[i]` skipped the place
entirely; it now evaluates the index and its bounds check, moving nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): copy an async block's Copy captures, and refuse replacing an Arc in place

`async move { read(tally) }` shared the caller's `Tally` object, so a later
change reached the future; a by-value capture is now copied as any `Copy`
aggregate is. `*dst = src` through a `&mut Arc` copied fields into the one
JS object every clone shares; it now fails with its span, as does the same
through a waker, context, or future.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): a ref temporary keeps its block scoped, and see Option and Poll through wrappers

A block whose `let ref` keeps a temporary that drops was flattened into the
enclosing scope, delaying the drop past the block's value; it now keeps a
scope of its own. `Option` and `Poll` now check what their payload can
already erase to through `Option`, `Poll`, `Box`, `Pin`, and references:
`Poll<Option<Poll<u8>>>` and `Option<Poll<()>>` collided and are refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): replace a generator's mutable borrow in place, and decide recursive drops whole

An async block that replaced a variable it borrows mutably rebound its own
parameter, so the caller never saw the write; it now writes into the
caller's object, as `*r = v` does. `drops` cached a provisional `false` for a
type that reached one still being decided, so `Inner` in a cycle with a
dropping `Outer` never dropped; a `false` is now cached only once the cycle's
first type is decided.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): an if let takes a temporary whole from every variant, and refuse Poll outputs

`if let None = Some(guard)` passed the whole-move check, since `None` has no
fields, and the failed test leaked the guard. An `if let` or let chain now
asks `leaves_drop`, which also counts the other variants and is exact where
`takes_all` was conservative (moq-net: 6 fewer refusals). An async body
whose output can already be `rt.Pending` is refused, as `Poll<Poll<T>>` is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): read through a Box without moving it, and close two more refusal gaps

`boxed.id` on a `Box` that drops lowered the deref as a move, clearing the
box so a second read threw and nothing dropped it; reading through an owning
pointer now reads it in place (moq-net: 2 fewer refusals). A ternary `match`
on a temporary that drops skipped the check a `match` makes, and replacing a
`Pin<Arc<_>>` through a reference reached every clone; both now fail with
their span.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* test(ts): regenerate snapshots after merging main

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* chore(quest): count iterators that own a value that drops in the Drop quest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): drive the task fixture's u64s through rt.u64, after #26

A u64 is now a number while safe, or limbs, so the hand-written executor and the
bench's translated routes make each value with `rt.u64.of` and read the sum with
`rt.u64.toBeBytes`, rather than as a bigint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* test(ts): regenerate snapshots after merging main

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): refuse three more drops JS would skip, from Codex's review

- Replacing a `MutexGuard` through a reference: the guard is its mutex in JS, so the
  copy would change the other mutex.
- A std mapping taking a value that drops by value, unless it moves every such operand
  into its result or a closure: `unwrap_or`, `ok_or`, `map_or`, `then_some`, and
  `Result::ok` discard one.
- A field read through a `Box` made in place: the deref of a temporary box is part of
  the temporary, which drops at the end of the statement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): refuse a rest pattern that moves values that drop out of a place

Its slice copy would drop the elements, and so would the array they stay in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): refuse replacing a pinned reference through a reference

A reference is its referent in JS, so copying the new one's fields in would change
what the old one pointed at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): refuse an array repeat of a value that drops

`[v; 0]` drops `v` at once, which no element of the array would.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): keep a move inside the arm of a `match` or `if` that takes it

An expression that moves a value that drops clears its place with a statement of
its own, so it is not simple enough for `?:`: both arms' statements would run, and
the second would read the `undefined` the first left. The task fixture's `blocks`
moves a guard on each arm of a `match`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

---------

Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated deleted the quest/m2/ts-wide-ints branch October 27, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant