mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-02 08:35:07 +08:00
feat(compiler): run the IR validator natively (#493)
- Compile the production validator and exercise native IR construction and validation on C and LLVM. - Preserve Error causes, wider callbacks, and discriminated JSON layouts in static programs. - Version the IR and runtime ABI and cover the new compiler paths with differential and sanitizer tests.
This commit is contained in:
@@ -59,22 +59,7 @@ fib.s
|
||||
|
||||
Different output kinds accumulate in `.scriptc/`; rebuilding a kind updates its file.
|
||||
|
||||
The three source outputs require only Node. On macOS 15+ arm64, assembly and object
|
||||
outputs use the matching native helper installed with scriptc and do not
|
||||
invoke an external compiler, archiver, linker, or SDK. The object is a
|
||||
relocatable program object with undefined <code>scr_*</code> runtime symbols
|
||||
and a required <code>scr_runtime_abi_v1</code> marker, not a standalone library.
|
||||
External consumption is experimental and requires the exact runtime version
|
||||
reported by <code>--print=native-link-info</code>. That option still writes the
|
||||
object, performs no link, and prints a versioned JSON recipe with the target,
|
||||
<code>main</code> entry, installed source runtime pack, FFI inputs, and system
|
||||
libraries. It never reports private scriptc cache paths. See
|
||||
<a href="/native-objects">Native Program Objects</a> for complete C-driver and
|
||||
direct-linker examples.
|
||||
<code>--emit=exe</code> is the default. On macOS 15+ arm64, LLVM-tier builds
|
||||
emit the program object through the helper and link release-built runtime
|
||||
objects; explicit C, LLVM fallback, and sanitizer builds retain runtime C
|
||||
compilation.
|
||||
The three source outputs require only Node. On macOS 15+ arm64, assembly and object outputs use the matching native helper installed with scriptc and do not invoke an external compiler, archiver, linker, or SDK. The object is a relocatable program object with undefined <code>scr_*</code> runtime symbols and a required <code>scr_runtime_abi_v2</code> marker, not a standalone library. External consumption is experimental and requires the exact runtime version reported by <code>--print=native-link-info</code>. That option still writes the object, performs no link, and prints a versioned JSON recipe with the target, <code>main</code> entry, installed source runtime pack, FFI inputs, and system libraries. It never reports private scriptc cache paths. See <a href="/native-objects">Native Program Objects</a> for complete C-driver and direct-linker examples. <code>--emit=exe</code> is the default. On macOS 15+ arm64, LLVM-tier builds emit the program object through the helper and link release-built runtime objects; explicit C, LLVM fallback, and sanitizer builds retain runtime C compilation.
|
||||
|
||||
## scriptc run
|
||||
|
||||
|
||||
@@ -14,12 +14,7 @@ TypeScript ──tsc: parse + typecheck──▶ lowering ──▶ typed IR ─
|
||||
3. **Backends** — `--emit=c` writes readable C and stops; `--emit=llvm` writes textual LLVM IR and stops. Neither source-output command discovers or invokes a native toolchain. On supported macOS, Linux, and Windows hosts (and for WASI), `--emit=asm|obj` sends LLVM IR to a version-matched out-of-process LLVM 22 helper; it needs no clang or linker. Executable builds default to LLVM and can fall back to C on a native program outside the LLVM tier (one stderr note; `--backend llvm` pins it and fails with a diagnostic instead). The production <code>wasm32-wasi</code> target never falls back.
|
||||
4. **Link** — release packages contain one precompiled object per runtime feature unit plus QuickJS, libregexp, zlib, and mbedTLS archives for every supported target. A hashed manifest maps IR feature gates to an ordered typed link plan, so binaries still pay only for what they use. The user needs the target platform linker and SDK/sysroot, but ordinary LLVM-tier builds compile no C. AddressSanitizer, explicit C builds, and LLVM refusals keep the external C-toolchain path.
|
||||
|
||||
Program objects define <code>main</code> and leave their selected
|
||||
<code>scr_*</code> runtime functions undefined. The
|
||||
<code>scr_runtime_abi_v1</code> reference is a strong link-time compatibility
|
||||
check. <code>--print=native-link-info</code> exposes the exact source runtime
|
||||
pack and link ordering for external builds; that object ABI is currently
|
||||
experimental and exact-runtime-version compatible, not semver-stable.
|
||||
Program objects define <code>main</code> and leave their selected <code>scr_*</code> runtime functions undefined. The <code>scr_runtime_abi_v2</code> reference is a strong link-time compatibility check. <code>--print=native-link-info</code> exposes the exact source runtime pack and link ordering for external builds; that object ABI is currently experimental and exact-runtime-version compatible, not semver-stable.
|
||||
|
||||
Inspect any stage yourself:
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ These are rejected at compile time with an `SC` code, a code frame, and usually
|
||||
|
||||
**Language edges**
|
||||
|
||||
- `Error`, `TypeError`, `RangeError`, and `SyntaxError` accept `{ cause }` options, including through inherited constructors. The options must expose `cause` as a data property; accessor options and subclass redeclarations of `cause` remain unsupported. Reading `error.cause` and testing `"cause" in error` preserve the distinction between an absent cause and an explicitly undefined cause.
|
||||
- Loose `==`/`!=` comparisons compile across statically represented primitive and primitive-union operands, including number/string/boolean/BigInt coercions and the `x == null`/`x != null` nullish idiom. Object-to-primitive comparisons remain fenced because custom `valueOf`/`toString` methods can execute arbitrary code; convert the object explicitly first.
|
||||
- Block- and function-scoped `using` and `await using` compile for statically represented classes with zero-parameter disposal methods and for the supported FileHandle, timer, immediate, child-process, and readline handles. Array `for (using ... of ...)` loops compile. Top-level and switch-clause declarations, disposal through an engine-held package value, and the `DisposableStack` constructors remain fenced; a caught `SuppressedError` exposes its Node-compatible `name` and `message`, while its `error` and `suppressed` payload properties remain outside the static catch surface.
|
||||
- Typed async generator functions and methods compile with lazy execution, `await`, direct `yield`, queued `.next()`/`.return()`/`.throw()` requests, and `for await`. `for await` also consumes Node `Readable` streams, Web `ReadableStream` values, and statically represented class iterators whose zero-parameter `next()` returns a promise of a `{ value, done? }` record; abrupt completion runs the iterator's cleanup, including literal `destroyOnReturn` and `preventCancel` options. Async `yield*` delegation, stored Web/Node iterator handles, and other structural async-iterator objects remain fenced. The `node:timers/promises` `setInterval(delay, value)` async iterator compiles, while its AbortSignal options remain fenced.
|
||||
|
||||
@@ -13,11 +13,7 @@ surface may change before 1.0, so consumers must use the exact
|
||||
`@scriptc/runtime` version reported by the same compiler installation. This
|
||||
is stricter than semver compatibility.
|
||||
|
||||
The object intentionally leaves its selected runtime symbols undefined. It
|
||||
also holds a strong reference to `scr_runtime_abi_v1`, which the matching
|
||||
runtime defines. Linking an object against a runtime with another ABI marker
|
||||
fails at link time with the missing versioned symbol; it cannot become a
|
||||
latent runtime incompatibility.
|
||||
The object intentionally leaves its selected runtime symbols undefined. It also holds a strong reference to `scr_runtime_abi_v2`, which the matching runtime defines. Linking an object against a runtime with another ABI marker fails at link time with the missing versioned symbol; it cannot become a latent runtime incompatibility.
|
||||
|
||||
## Machine-readable link information
|
||||
|
||||
|
||||
Reference in New Issue
Block a user