0233. Fast C backend by default for dev builds and tests
- Status: Accepted (maintainer, 2026-11-22)
- Date: 2026-11-14
- Plan: optimization round 1 (Optimization Researcher findings)
- Review: (none)
Context
Every native test compiles one large C file with
gcc -O2. Measured on the shared 8-core box: the full
suite took 586 s with gcc -O2 and 183 s with TinyCC; the golden
suite took 43.7 s (gcc -O2), 19.4 s (gcc -O0) and 10.5 s (TinyCC),
with identical program output. The runtime header refused any
compiler but gcc/clang because it relies on
__builtin_*_overflow.
Decision
Amendment 2026-11-22
Native dev builds (tenon run and
tenon test, including the check gate) default to
TinyCC. The standalone tenon check stays
frontend-only. If TinyCC is unavailable, the driver notes the
fallback and uses gcc at -O0; dev FFI still uses the
GCC-compatible path. tenon build (including
--release) defaults to gcc -O2; explicit
debug and profile modes keep their flags. An explicit
CC wins. TENON_FAST_CC=0 opts dev builds
out; TENON_FAST_CC=1 remains compatible.
scripts/gate.sh --gcc opts out and
--fast-cc remains compatible.
Original decision (superseded where it differs)
HARNESS_FAST_CC=1 opts in to a fast C backend. It
applies only to Release builds and only when CC is
unset; an explicit CC, Debug (-Og -g)
and Profile (-O2 -g) builds, and any other value keep
today's command line byte for byte. When it applies, the driver
uses tcc (or HARNESS_TCC) with
-O0 -Wno-all (TinyCC's -Wall reports GCC
pragmas it ignores); if TinyCC is missing it uses the normal
cc/gcc candidate with -O0.
FFI builds always take that -O0 fallback because they
rely on GCC-compatible header probes, prototype diagnostics and
dependency/linker capture. The native build cache keys on the full
command and <compiler> --version output, so
fast and normal artefacts never mix; -Wno-all is
appended by the driver rather than kept with the compiler because
tcc -Wno-all --version fails and would turn caching
off.
harness_rt.h gains a portable checked-arithmetic
fallback, selected only for TinyCC or compilers lacking the
builtins. It covers exactly the operand types the runtime uses
(i64, i32, u8, u32, u64), returns the same overflow flag and
stores the same wrapped bits as the builtins; a C parity test
compares gcc builtins, the fallback under gcc+UBSan, and TinyCC.
The GCC/Clang path is textually unchanged. HRT_COLD
expands to nothing under TinyCC.
Tests that check gcc-only behaviour must pin
CC=gcc. A full
HARNESS_FAST_CC=1 cargo test --release --workspace
run (with CC unset) needed no new pins: DWARF tests
use --debug, FFI builds take the gcc fallback, and
runtime C tests already invoke gcc directly. glibc defines
__attribute__(x) away for TinyCC, so
packed/cold/noinline
attributes are ignored there; the only packed struct
(Landlock) has identical field offsets either way.
scripts/gate.sh --fast-cc runs the check with
CC unset and HARNESS_FAST_CC=1, and
never reads or records a cached pass.
Alternatives considered
- gcc -O0 only — portable and no runtime changes, but about half the speedup of TinyCC.
- Default to TinyCC — changes shipped binaries'
performance and the required gcc gate; the gate stays
CC=gcc. - Impersonate GCC under TinyCC
(
#define __GNUC__, as the research shim did) — leaks into libc headers; rejected.
Original consequences
Local and agent test loops can run several times faster. The
required gate is unchanged and still the source of truth; fast
runs are evidence only. New gcc-specific tests must pin
CC=gcc. Any TinyCC/gcc output difference is a bug to
report, not to hide.