Skip to content

Atomics.load/store use atomic load/store; Promise functions over settled values - #65

Merged
ASDAlexander77 merged 2 commits into
mainfrom
atomics-builtins-and-promise
Nov 5, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
atomics-builtins-and-promise

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to ASDAlexander77/TypeScriptCompiler#767 (atomic builtins) and #64 (Atomics).

Atomics

  • Atomics.load is now an atomic load (atomicload). It was an atomic or 0, a locked write to the element.
  • Atomics.store is now an atomic store (atomicstore) instead of an exchange whose result was dropped.
  • tests/atomics.ts: the arrays aren't declared with their type any more (new Uint8Array([250]) keeps u8 since #767), and new cases check that a value wraps to the element width as in JavaScript (adding 300 to a Uint8Array element adds 44, subtracting -1 adds 1) and cover load/store on a narrow element.

Promise

The compiler takes Promise<T> as T: an async function returns its value and await gives it back. A class Promise<T> in the library would take precedence over that and break every async function f(): Promise<int>. So Promise is a namespace of functions over values that have already settled:

  • resolve(value): the value.
  • reject(reason): throws the reason, keeping its class, so catch (e: RangeError) catches it.
  • all(values): a new array, as in JavaScript. Under -mm=own this lets the result leave an await.
  • allSettled(values): { status: "fulfilled", value } for each.
  • race(values) / any(values): the first value; both throw on an empty array.

There is no then/catch/finally. The README lists both namespaces.

tests/promise_reject.ts ran into two -mm=own gaps. Both are fixed in ASDAlexander77/TypeScriptCompiler#768, which this PR now needs:

  • Promise.reject: without @keeps the thrown parameter is "kept, but -mm=own cannot make the callers give it up"; with @keeps("reason") it is "its body keeps nothing".
  • await Promise.resolve(someString): the result borrows the argument and can't leave the await.

Verification

Built with the compiler at #768 (main + the own fixes). tests.ps1 release compile + jit:

  • gc: 186/186
  • rc and none: 185/186 (1 gc-only skip)
  • own: 185/186 (the gc-only skip), with #768

🤖 Generated with Claude Code

…ons over settled values

Atomics.load was an atomic `or 0` (a locked write) and Atomics.store an exchange whose result was
dropped; they are now `atomicload` and `atomicstore` (TypeScriptCompiler#767). The atomics test no
longer declares each array's type (`new Uint8Array([250])` now keeps u8) and checks that a value
wraps to the element's width as in JavaScript.

Promise: the compiler takes Promise<T> as T, so these are functions over values that have already
settled: resolve, reject (throws its reason, keeping its class), all (a new array, so the result
can leave an `await` under -mm=own), allSettled, race and any. No then/catch/finally.
promise_reject.ts is `// not own`: under -mm=own a thrown parameter does not build, and a string
Promise.resolve returns borrows its argument and cannot leave an `await`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TypeScriptCompiler#768 keeps a thrown parameter and copies an awaited string that borrows its
argument, so Promise.reject and `await Promise.resolve(someString)` build under own. Needs #768.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 9b875cb into main Nov 5, 2026
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