Skip to content

Ahead-of-time compilation (vibelang aot, experimental)

vibelang aot compiles a whole .vibe program, its entry and the local .vibe and .ts modules it imports, into one standalone Bun executable that does not run Effect's fiber runtime. Typed errors become a result slot instead of a Cause, a service read becomes a field load, scoped and acquireRelease become try/finally, and a try.all or for concurrent over a Sendable kernel runs on a pool of Worker threads.

The command is experimental. It is separate from vibelang -p .: a project that never calls vibelang aot compiles exactly as before, and vibelang-runtime does not import its runtime. A program that uses a form AOT's checks recognize as unlowered fails with a diagnostic and writes no output. The checks catch generated code that does not parse or reads a name it never defines, and declarations that shadow a lowered intrinsic. They cannot see a form the emitter translates into valid but different TypeScript; the differential oracle, the fuzz targets and the corpus below are the guard against that, so use AOT on the forms the table lists. -o never overwrites a source the program was loaded from: AOT refuses a destination that resolves to a source, and writes every output to a new file beside its destination and renames it into place, so it never writes through a symlink or into a hard-linked file.

vibelang aot app.vibe -o app            # standalone executable ./app
vibelang aot app.vibe --emit-only       # write app.aot.ts (and app.aot.worker.ts) instead
vibelang aot app.vibe --report          # also print the analysis: tiers, services, kernels

With a released Bun, vibelang aot builds with bun build --compile, and the Worker module is bundled as a second entry point. With a Bun AOT build that has the bun compile subcommand (pass it with --bun or BUN_AOT_BIN), it builds with bun compile --trim, and --explain passes through. AOT detects that subcommand by running bun compile --help in an empty temporary directory, so a project script named compile never runs. --threads N sets the Worker pool size (default 8; 1 disables the pool). npm imports, such as effect for the EffectBridge, resolve from the node_modules of the entry's project.

Supported subset

Each row names the test that holds it. "Differential" means the differential oracle runs the same program under Effect 4 and under AOT and compares results, logs and exits.

FormStatusEvidence
effect function, try, throw of a declared error, catch, match on error tagsCompilesDifferential (nested-catches, match-*, catch-recovers-typed-failure)
Evaluation order of target op= try f() and of the fields of throw new E({ … }); default and rest parameters of nested arrowsCompilesDifferential fuzz FuzzAOTReviewShapes (every target, operator, field order and arrow shape), TestReviewAssignmentEvaluatesTargetFirst, TestReviewUnboxedErrorFieldsKeepSourceOrder, TestReviewNestedArrowKeepsDefaultAndRestParams
is pattern with a binding in an if conditionCompilesTestReviewIsPatternInIfCompiles (not differential; other is homes are not verified)
service, Layer.succeed, Layer.merge, provide blocks, nested overridesCompilesDifferential (merged-services), TestNestedProvideOverride
scoped, acquireRelease (LIFO release, finalizer failures), uninterruptibleCompilesDifferential (scoped-*, second-acquire-failure), TestScopedLIFOCleanupAndMasks
Deep and async recursion of effect functionsCompilesDifferential (recursion-*), TestDeepRecursionTrampoline
try.all and for concurrent over a Sendable kernel (numbers, booleans, numeric data/schema)Compiles to the Worker poolDifferential (sendable-parallel), TestSendableStructKernelRunsOnWorkerPool, benchmark B5
try.all, for concurrent over a kernel that is not SendableCompiles, runs on the calling threadTestNonSendableClosureFallsBackToSingleThread
fork, fork.scoped, fork.detached, join, try.race, try.any, try.allSettledCompilesTestForkJoinSuccessAndTypedError, TestTryRaceCancelsLoser, TestTryAnyAndAllSettled (not differential)
data records and variants, match on their tags in plain functionsCompilesTestDataRecordAndVariantMatch (not differential)
Effect 4 values from import … from "effect" run with tryCompiles through the EffectBridgeDifferential (catch-preserves-defect, -interrupt, -compound-cause)
Local .vibe and .ts importsCompiles into one moduleTestAOTE2EMultiModuleAndFixtures/multi-mod
runSync and runPromise entry callsCompilesDifferential (every scenario settles through them)
.vibe import of @effect/* or vibelang-runtimeDiagnostic AOT001TestVibeImportOfEffectPlatformIsRejected
Effect modules used as values in .vibe (Console, Schema, Equal, …)Diagnostic AOT003TestUnloweredEffectModuleIsLocatedInSource
effect arrows and methods in object literals, effect methods in classes, effect function* producers, pipe % placeholders, effectful defaults in a catch handler's destructuringDiagnostic AOT002TestEachUnloweredFormIsReported (one program per form)
Generic data declarationsDiagnostic AOT003TestCorpusGapsBecomeDiagnostics/data-declaration
A declaration or import named like a name the backends lower by spelling (succeed, fail, sync, restore, race, provide, Effect, …), in a program that calls that name; an import from effect binds the intrinsic only under its own name (import { Effect } from "effect", import { succeed } from "effect/Effect")Diagnostic AOT004TestShadowedIntrinsicIsReported, TestAliasedEffectImportShadows, TestLoweredIntrinsicsCoverEveryMatchedName (reads the emitters' sources), fuzz FuzzAOTShadowedIntrinsic
Import cycles, unresolved local imports, one top-level name declared in two modulesError before analysisTestAOTE2ECorpusCoverage (module graph)

Over the acceptance corpus (TestAOTE2ECorpusCoverage, 1,051 cases with a main.vibe and an expected stdout), AOT compiles 625 cases and reports a diagnostic or module-graph error for 426. Of the compiled cases, the 5 whose expected stdout AOT can produce on its own match exactly; the other 620 compile cleanly but have no stdout oracle that runs without Effect, so they are checked statically only. The 625 compiled cases are pinned in internal/vibelangaot/testdata/aot-corpus-emitted.txt: the test fails when one of them stops compiling.

Diagnostics

CodeMeaning
AOT001A .vibe file imports an Effect platform package or the VibeLang runtime. AOT lowers neither their runners nor their services.
AOT002The generated TypeScript does not parse: AOT has no lowering for a VibeLang form and copied it.
AOT003The generated program reads a name it never defines, usually an Effect module such as Console. The diagnostic points at the first identifier with that name in the .vibe source, skipping comments and strings, when it finds one.
AOT004A declaration or aliased import shadows a prelude name the backends lower as an Effect intrinsic, so a call to it would compile to the intrinsic. Rename the declaration.
AOT005--target=native only: the native preview has no faithful C lowering for this statement, expression or operator. The Bun target may still compile the program.

Compile such a program with vibelang instead.

Native target (preview)

--target=native --preview-native compiles to C and builds with clang, or cc when clang is missing. It first runs the same checks as the Bun target, then refuses with AOT005 every statement, expression and operator it has no faithful lowering for, instead of emitting C for it. It represents numbers as 64-bit integers, with doubles only where a value comes from performance.now(), a fractional literal, -0 or arithmetic on one; strings as immutable UTF-8; and booleans. Where a value leaves what that representation holds exactly, the program stops with exit status 70 and a message naming the value, instead of printing a different one.

FormNative behaviorEvidence
if, for with one integer counter, while, break, continue, return, throw, catch and match on error tags, services, scoped with acquireRelease of { handle, active }Compiles; operands and arguments run left to rightTestNativeEmitAndExecuteE2E, fuzz FuzzAOTNativeLoops and FuzzAOTNativeOperandOrder (against Bun), bench_suite.vibe (same checksums as Effect 4)
Conditions of if, while, for and ?:Compiles; a boolean, number or string is tested as JavaScript tests it ("", 0 and NaN are false); ?: with an integer and a double branch yields a doubleFuzz FuzzAOTNativeTruthiness (against Bun)
Integer +, -, *, +=, -=, *=, unary -Compiles; a result beyond 2^53 in magnitude, or a negative zero, stops the program with exit status 70Fuzz FuzzAOTNativeIntArithmetic (against Bun)
Integer / and %Compiles; a result that is not an integer, or is negative zero, stops the program with exit status 70; (a / b) | 0 truncates as JavaScript doesTestNativeValuesMatchJavaScript
Calls to plain and effect functions, returns, error and data fieldsCompiles; a double passed or stored where a number is declared converts exactly or stops the program with exit status 70; a program function named like a host call (Number) is called, not the hostFuzz FuzzAOTNativeArgCoercion, FuzzAOTNativeHostShadow (against Bun)
Indexing a try.all resultCompiles for an integer index; one outside the result stops the program with exit status 70Fuzz FuzzAOTNativeIndex (under AddressSanitizer, against Bun)
String + and templates, .length and .slice in UTF-16 code units, startsWith, ===/!== on stringsCompiles; strings are allocated on the heap and never freed; a slice that would split a surrogate pair stops the program with exit status 70Fuzz FuzzAOTNativeTemplates (under AddressSanitizer), FuzzAOTNativeStringOps (against Bun)
console.log of numbers, doubles, booleans and stringsCompiles; doubles print with JavaScript's digits and notation, a negative zero as -0Fuzz FuzzAOTNativeDoubles (against Bun)
Number(s)Compiles; a string that does not hold an integer of at most 2^53 in magnitude stops the program with exit status 70Fuzz FuzzAOTNativeNumber (against Bun)
do, for…of, switch, try statements, arrays other than a try.all result, an integer literal index outside a try.all result or an index that is not an integer, objects, Math, string ordering, &&/|| on non-booleans, ?: with branches of different kinds other than integer and double, a string holding a NUL character, an error not built from one object literal giving every field, default and rest parameters, and a try or catch in a loop condition, for incrementor, conditional branch or right side of &&/|| (a template there compiles)Diagnostic AOT005TestNativeRefusesUnloweredForms, TestNativeReview3Refuses, fuzz FuzzAOTNativeNULStrings, FuzzAOTNativeIndex

There is no differential oracle for whole programs on this target, so it needs the explicit flag.

Performance

Median time per operation of 3 runs of experiments/bench/aot/bench_suite.vibe (AOT) and its Effect 4.1.6 twin effect-baseline.ts, measured on 2026-12-01 (UTC, the container's clock) after the native preview's checked arithmetic and exact conversions with Bun 1.4.4 (released; no bun compile, so no --trim) on a 4-core x86_64 Linux container, 8 Worker threads, cc (gcc) for the native preview. effect-jit is bun run; effect-compiled is bun build --compile. All four runners printed identical samples and checksums for every benchmark, and the script fails if they do not.

Benchmarkeffect-jiteffect-compiledaot-bunaot-nativeaot-bun vs effect-jitaot-bun vs effect-compiled
B1b req happy (200k)3.5 µs2.9 µs129.2 ns179.6 ns27.3x22.5x
B1c req error 404 (200k)4.1 µs3.7 µs43.6 ns28.0 ns94.0x84.2x
B1d req error 401 (200k)3.2 µs3.1 µs21.0 ns6.4 ns154.9x147.8x
B2 deepChain(16..23 200k)13.6 µs13.3 µs105.5 ns13.3 ns128.6x126.4x
B3 errorLoop(96..103 50k)152.4 µs142.0 µs231.2 ns84.9 ns659.2x614.5x
B4 scopedOp (200k)6.4 µs5.8 µs15.9 ns2.1 ns404.4x366.8x
B5a parallelCpu(8x50k)3.91 ms3.66 ms1.65 ms2.21 ms2.4x2.2x
B5b parallelCpu(8x250k)17.04 ms17.93 ms6.00 ms9.86 ms2.8x3.0x

Reproduce from the repository root after building typescript/built/local/tsc and installing experiments/node_modules:

bash experiments/bench/aot/run.sh 3

The single-thread rows measure removing the fiber runtime: typed failures, service reads and scopes cost nanoseconds instead of microseconds. The B5 rows measure the Worker pool on 4 cores. Numbers vary with the machine; the speedup columns are the claim, not the absolute times.

How it is verified

SuiteCommand (from typescript/tsc unless noted)
Analyzer, emitters, checks, CLI, corpusgo test ./internal/vibelangaot/...
Differential oracle and fuzz seeds (Effect 4 or Bun versus AOT, output aliasing, shadowed intrinsics, native values)VIBELANG_FUZZ_REQUIRE=1 EFFECT_NODE_MODULES=$PWD/../../experiments/node_modules go test -short ./internal/vibelangfuzz/ -run AOT
Runtime packagebun test in packages/aot-runtime
Benchmarksbash experiments/bench/aot/run.sh from the repository root

The Z3 and Dafny proofs in internal/vibelangaot/proofs run when z3 and dafny are on PATH; without them the tests check the proof files' structure only. On 2026-12-01 (UTC) the Z3 obligations and their mutation checks passed again with Z3 4.13.4 (PATH=<z3>/bin:$PATH go test ./internal/vibelangaot/proofs/); Dafny was not available, so the Dafny proofs were checked structurally only. The typed-access and --trim gates (TestAOTExplainAndTrimGate) need a Bun AOT build and skip on a released Bun.