Skip to content

[ci] add scripts/check-ir-determinism.sh for latent non-determinism detection#669

Merged
cs01 merged 1 commit intomainfrom
ir-determinism
Apr 22, 2026
Merged

[ci] add scripts/check-ir-determinism.sh for latent non-determinism detection#669
cs01 merged 1 commit intomainfrom
ir-determinism

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Apr 22, 2026

Before

No way to catch codegen non-determinism (Map iteration order, Set order, unstable sort, etc.). Non-determinism can produce arch-divergent IR under `-O2` optimization — suspected contributor to cases like the #662 x86-64-only break.

After

`bash scripts/check-ir-determinism.sh [target]` compiles a .ts file to LLVM IR twice in independent processes and diffs byte-for-byte.

First data point: `src/chad-native.ts` is bit-identical across runs on arm64 macOS (44,617,573 bytes). x86-64 verification pending.

Description

Investigative tool, not a CI gate yet (per the first-ship-observability plan).

If the tool finds non-determinism in the future, root causes get their own PRs (iteration order, seeded randomness, stable sort). Only once known sources are clean does this become a CI gate.

Part of the #658 architectural-hygiene track: before attempting more typeOf-cache gate-loosening, ship visibility tools that tell us which changes are safe.

Known CLI nit (unrelated)

`node dist/chad-node.js ir -o ` ignores `-o` and writes to `.build/src/.ll` regardless. Worked around; file separately if desired.

Refs #658.

Compiles a .ts file to LLVM IR twice in independent processes, diffs
byte-for-byte. Any divergence = latent non-determinism in codegen (Map
iteration order, Set order, unseeded PRNG, etc.) — each of which can
produce arch-divergent IR under -O2 optimization.

Investigative, not a CI gate. Once known sources are fixed, this becomes
the gate. Result on arm64 macOS for src/chad-native.ts: bit-identical at
44MB (deterministic). x86-64 Linux result pending.

Part of the #658 architectural-hygiene plan: ship visibility tools before
attempting further gate-loosening.
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark Results (Linux x86-64)

Benchmark C ChadScript Go Node Place
Fibonacci 0.815s 0.763s 1.563s 3.170s 🥇
Hash Map Lookup 0.104s 0.064s 0.091s 0.130s 🥇
Binary Trees 1.635s 1.330s 2.759s 1.262s 🥈
Cold Start 0.8ms 0.9ms 1.3ms 29.9ms 🥈
File I/O 0.123s 0.096s 0.091s 0.213s 🥈
JSON Parse/Stringify 0.035s 0.053s 0.178s 0.137s 🥈
N-Body Simulation 1.667s 2.122s 2.200s 2.413s 🥈
Regex Match 0.017s 0.005s 0.022s 0.004s 🥈
SQLite 0.051s 0.376s 0.508s 0.468s 🥈
Monte Carlo Pi 0.389s 0.410s 0.405s 2.249s 🥉
Quicksort 0.218s 0.246s 0.213s 0.262s 🥉
Sieve of Eratosthenes 0.016s 0.029s 0.018s 0.038s 🥉
String Manipulation 0.008s 0.018s 0.017s 0.037s 🥉
Matrix Multiply 0.444s 0.703s 0.609s 0.442s #4

CLI Tool Benchmarks

Benchmark ChadScript grep node xxd Place
Hex Dump 0.559s 0.989s 0.131s 🥈
Recursive Grep 0.022s 0.011s 0.107s 🥈

@cs01 cs01 merged commit 76522b8 into main Apr 22, 2026
13 checks passed
@cs01 cs01 deleted the ir-determinism branch April 22, 2026 22:57
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