Repository navigation
Atomic builtins checked at the call + atomicload/atomicstore; literal vs generic T; new through an alias; JIT read-only section layout - #767
Merged
Conversation
…atomicstore, volatile and weak The op code, orderings, syncscope, alignment and flags of atomicrmw, cmpxchg and fence become op attributes, so each has to be a constant. A variable one crashed tslang (the op was built with a null attribute), a constant LLVM doesn't take (op code 99, an atomicrmw ordering below monotonic, a cmpxchg failure ordering of release) was reported only by LLVM's verifier at <unknown>:0, and a wrong argument count said just "failed statement". Each is now an error at the call, naming what the argument may be or the builtin's signature. New builtins atomicload(ref, ordering[, syncscope[, alignment[, volatile]]]) and atomicstore(ref, value, ordering[, ...]) lower to LLVM `load atomic` / `store atomic`, aligned naturally unless an alignment is given. atomicrmw and the new two take a trailing volatile flag, cmpxchg weak and volatile ones. The value (and cmpxchg's expected value) is cast to the type the reference points at: a literal added to a u16 is a 16-bit atomicrmw, not a 32-bit one over the element and its neighbour. The reference's type is checked against the operation (integer ops, float ops, cmpxchg integer or pointer, no boolean). Tests: tests/00atomic_builtins.ts, atomic-errors/*.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n it holds the value With `add<T>(ta: TA<T>, i: int, v: T)`, `add(new TA<u16>([65535]), 0, 2)` merged T = u16 with the literal's s32 into s32, and failed with "type TA<ui16> is not assignable to type TA<si32>". A number literal now yields to a candidate it fits (u16 holds 2), in either parameter order, and is cast to it; a literal the other type can't hold merges as before. Test: tests/00generic_literal_inference.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… literals fit overloaded T[] constructors `type Uint8Array = TypedArray<u8>; new Uint8Array([250])` inferred the class's type arguments from the constructor's arguments, which made a TypedArray<s32>. A `new` naming an alias that already specialises the class no longer infers them, from the arguments or the receiver. Constructor overload resolution scored `[250]` by its evaluated type, s32[], which fits no u8[] parameter, so `new TypedArray<u8>([250])` of a class with a second constructor found none. An array literal argument now fits a T[] parameter as its elements fit T, as it is generated. Test: tests/00new_alias_and_ctor_overloads.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m the code pool On Win64 the JIT allocated read-only sections from the code pool, so they could hold the personality thunks RTDyld puts in .xdata. RTDyld's reservation sizes the code pool for the code alone, so an object whose read-only data outgrew the page-rounding slack spilled into a mapping of its own wherever the OS put it. Below the reserved block (about a third of runs of the DefaultLib Atomics tests under rc), an IMAGE_REL_AMD64_ADDR32NB relocation to it fell below the image base: "LLVM ERROR: IMAGE_REL_AMD64_ADDR32NB relocation requires an ordered section layout". Read-only sections now come from the read-only pool, in the reserved block between code and data as RTDyld lays it out, and finalizeMemory makes their pages read+execute. The JIT also warns when a section is outside the reserved block, which a spill always is, so the regression test fails in every run rather than in a few: the old routing warned on every run of tests/00jit_rodata_layout.ts. Test: test-jit-rodata-layout (tests/00jit_rodata_layout.ts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t regression tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Compiler issues found while adding
Atomicsto the default library (ASDAlexander77/TypeScriptCompilerDefaultLib#64), where they were worked around. One commit per fix.Atomic builtins (
MLIRCodeLogic.h,TypeScriptOps.td,LowerToLLVM.cpp)getIntegerAttrreturned. Now an error at the call:atomicrmw: the op code must be a constant integer.<unknown>:0. They're checked in MLIRGen and reported at the call with the allowed values, e.g.atomicrmw: the ordering 1 (unordered) is not allowed here; expected 2 (monotonic), 4 (acquire), 5 (release), 6 (acq_rel) or 7 (seq_cst). Also checked: the reference's element type against the operation (integer ops, float ops, cmpxchg integer or pointer, no boolean), a non-reference first argument, and the alignment (a power of two).expected atomicrmw(op, ref, value, ordering[, syncscope[, alignment[, volatile]]]), but got 3 arguments.atomicload(ref, ordering[, syncscope[, alignment[, volatile]]])andatomicstore(ref, value, ordering[, ...]), lowering to LLVMload atomic/store atomic, aligned naturally unless an alignment is given.Atomics.load/Atomics.storein the default lib can use them instead ofor 0/xchg.volatileandweakare optional trailing boolean arguments (a syncscope of""and an alignment of0mean the defaults, for a call that only wants a flag).Also: the value (and cmpxchg's expected value) is now cast to the type the reference points at. Before,
atomicrmw(1, ReferenceOf(u16var), 1, 7)was a 32-bit atomicrmw over the u16 and its neighbour.Type checking
MLIRGenTypes.cppzipTypeParameterWithArgument,MLIRGenGenerics.cpp): withadd<T>(ta: TA<T>, i: int, v: T),add(new TA<u16>([65535]), 0, 2)is T = u16 with 2 cast to it, in either parameter order. A literal the type can't hold (300 for a u8) merges as before.newthrough a specialising alias (MLIRGenExpressions.cpp):type Uint8Array = TypedArray<u8>; new Uint8Array([250])built aTypedArray<s32>; the alias's type arguments are now kept, and the constructor's arguments and the receiver don't override them. Constructor overloads (MLIRGenAccessCall.cpp): an array literal argument fits aT[]parameter as its elements fit T, sonew TypedArray<u8>([250])of a class with a secondconstructor(length: int)findsconstructor(data: T[]).JIT
JitSectionMemoryManagerallocated read-only sections from the code pool, which RTDyld's reservation sizes for the code alone. An object whose read-only data outgrew the page-rounding slack spilled into a fresh mapping wherever the OS put it, and below the reserved block an ADDR32NB relocation to it fell below the image base (seen with instrumentation: the reservation at…2400000, the spilled.pdataat…2010000). Read-only sections now come from the read-only pool (Code < RO < RW inside the reserved block, as RTDyld expects), andfinalizeMemorymakes their pages read+execute for the.xdatapersonality thunks. Before: 9/30 failing runs; after: 60/60 passing.The JIT also warns when a section lies outside the reserved block. A spill is always outside, but only a spill below crashed, and that depended on the address space, so the crash itself couldn't be reproduced by any in-tree program (I tried five shapes, 0 failures each). The warning appears every run under the old routing (checked on three programs and both memory models), so
test-jit-rodata-layoutfails deterministically if read-only sections ever go back to the code pool.Tests
tests/00atomic_builtins.ts: every builtin and flag, the u16 cast, a weak cmpxchg retried in a loop. Compile and JIT under gc, own, rc and none.atomic-errors/*.ts(18 cases): each message at itsfile:line:col, failing onStack dump,Assertion failedor<unknown>.tests/00generic_literal_inference.tsandtests/00new_alias_and_ctor_overloads.ts: all four models.test-jit-rodata-layout(tests/00jit_rodata_layout.ts).Verification
ctest -C Release: 6630 tests, all passed (3 disabled as before).tests.ps1release compile + jit: gc 184/184; rc, none and own 183/184 (1 gc-only skip).lib.generics.tsstill passes<T>valuetoatomicrmw, so the new cast is a no-op there.ctest -C Debug --timeout 300: 161 of 6629 fail. None of the new tests is among them. The failures fall into classes in code this PR doesn't touch:inlinable function call ... must have a debug location/ "Failed to emit LLVM IR" (--di),cast<Ty>() argument of incompatible typeasserts, anAPSInt"Too many bits for int64_t" assert in 64-bit tests (00int64_remainder,00throw_bool_bigint), and-sharedexport/import link errors. I didn't build a Debug tree of main to confirm they predate this branch: Debug wasn't green before (38 known failures on 2026-10-01).Not in this PR
awaitoffloads but blocks, an unawaitedasynccall is synchronous): investigated only, write-up in the session notes.Atomics.load/storecan useatomicload/atomicstore, and theconst x: Uint8Array = …annotations and<T>casts in its tests and lib are no longer needed.🤖 Generated with Claude Code