On this page

Fast Iteration & Build-Speed Guardrails

Practical workflows for fast Rust toolchain iteration, fast .tn application development, and the guardrails that keep builds and the gate fast.

For test authoring rules and focused test commands, see docs/testing.md.

Fast Rust toolchain iteration

Use the smallest command that answers your question:

cargo check --workspace                 # fast syntax/type check without linking
cargo test --bin tenon <filter>         # run one Rust unit-test module/test
make dev-fast                           # cargo build --profile dev-fast --bin tenon -> target/dev-fast/tenon
make check-fast                         # TENON_CHECK_FAST=1 scripts/check.sh (workspace tests + fmt-check)
scripts/gate.sh --fast --quiet          # inner-loop gate tier (never cached as a full pass)
scripts/gate.sh --quiet                 # cached full gate (reuses clean tree + toolchain pass)

Profiles and workspace layout

Multi-worktree and parallel agent lanes

Fast .tn application iteration

Work in a tight inner loop before compiling a release binary:

  1. Check first (~25–45ms): tenon check <file.tn> runs the frontend only (parse + typecheck, no C compiler).
  2. Interpret for quick logic checks: tenon interp <file.tn>. For heavy interpreter workloads or scripts, run a release binary or target/dev-fast/tenon (make dev-fast) rather than an unoptimized debug binary.
  3. Compile & run with --dev: tenon build --dev and tenon run --dev compile in BuildMode::Dev (-O0 / TinyCC when installed; pass --dev --release to override back to -O2) and benefit from four build-time accelerators:
    • Deduplicated compiler probes: cc --version / tcc --version, pkg-config probes (fail-closed on env/search-dir/.pc changes), and tool lookup results are cached (crates/tenon-compiler/src/build_cache.rs, crates/tenon-compiler/src/driver.rs).
    • Native build cache (Cache): identical compiled programs hit ~/.cache/tenon and skip invoking the C compiler entirely.
    • FFI object & library cache (FfiCache): caches FFI builds on both Linux and macOS (including vendored SQLite object compilation and cross-platform link-library discovery). On macOS (ffi-cache-macos-v2), pre-stage cache hits verify inputs before creating a TempDir, extracting vendored SQLite, or running system-header probes, keeping repeat SQLite and TUI FFI hits fast.
    • Cached C runtime acceleration (crates/tenon-compiler/src/driver/runtime_pch.rs): for uncached native GCC/Clang builds, compiles core runtime/ headers once into a cached tenon_rt.o and precompiled header (.pch on Clang, .gch on GCC). tenon emit-c stays 100% self-contained C and never depends on PCH. TinyCC remains the fast default for non-FFI dev builds when installed.
  4. Batch formatting: use tenon fmt [--check] <path...> or tenon fmt --check --stdin0 (NUL-delimited paths, as used by scripts/fmt-check.tn) to check or format many files in a single process.

Useful environment knobs

Variable Effect
TENON_NO_CACHE=1 Bypass executable, FFI, and runtime PCH caches (forces direct uncached C compilation)
TENON_CACHE_DIR=<path> Override the cache root (default: $XDG_CACHE_HOME/tenon or ~/.cache/tenon)
TENON_CACHE_MAX_MB=<N> Set the build-cache LRU size limit in MiB (default: 2048)
TENON_FAST_CC=0 Opt out of the TinyCC dev default (an explicit CC=gcc or CC=clang also wins)
TENON_SQLITE=system Link system -lsqlite3 instead of compiling the vendored SQLite amalgamation
TENON_RELEASE_COMMIT=<sha> Stamp explicit release commit provenance in crates/tenon/build.rs (pairs with SOURCE_DATE_EPOCH)
TENON_QUIET=1 Same as scripts/check.sh --quiet (prints check: OK + log path, or failing step summary)
TENON_TEST_BUDGET_SECONDS=<N> Override scripts/check.sh unit-test runtime budget (default: 120)

Anti-regression guardrails

Do not undo these speedups when adding features, tests, or scripts:

  1. No .git watching or large static assets in crates/tenon: Never add .git rerun-if-changed lines or multi-MB include_bytes!/include_str! payloads to crates/tenon. Keep static assets in crates/tenon-assets (with opt-level = 0 in test/dev-fast profiles) and keep git provenance stamping gated behind release builds or TENON_RELEASE_COMMIT.
  2. Keep the 4-crate split (tenon-assets, tenon-frontend, tenon-compiler, tenon) and debug = "line-tables-only" intact: Do not duplicate modules across binaries (tenon-codec must reuse tenon-frontend), do not pull CLI/main handlers into tenon-compiler or plugin_kit, keep [profile.dev]/[profile.test] at debug = "line-tables-only", and keep [profile.test] at opt-level = 0 with tenon-compiler/tenon-frontend at opt-level = 1.
  3. Batch CLI invocations; never spawn tenon per file in shell loops: Use tenon fmt --check --stdin0 or multi-path CLI arguments (tenon fmt --check path1 path2 ...) instead of per-file subprocess loops.
  4. Keep scripts/check.sh free of redundant builds, consolidated, and parallel-safe: Never re-add a full cargo build step to scripts/check.sh (cargo test --workspace --no-run already builds a fresh $target_dir/debug/tenon via CARGO_BIN_EXE_tenon, and cargo clippy --workspace --all-targets already checks tenon-codec). Keep TENON_CHECK_FAST=1 (make check-fast / scripts/gate.sh --fast) scoped to workspace tests + fmt-check.tn with its fast-tier banner and never cached as a full pass. Keep Rust integration tests consolidated in crates/tenon/tests/integration.rs (one compiled/linked test binary with parallel-safe temp dirs) instead of adding separate crates/tenon/tests/*.rs crates, and preserve scripts/check.sh's Bash 3.2-compatible pipeline overlap. Keep every scripts/test_*.tn suite parallel-safe (isolated temp dirs, ephemeral 127.0.0.1:0 ports, no shared global paths) so scripts/run_script_tests.tn stays deterministic.
  5. Keep build caches fail-closed and probe-free: Keep build_cache (Cache, Linux/macOS/vendored-SQLite FfiCache) and driver/runtime_pch fail-closed (any unsupported mode or corrupt cache entry must evict/fall back cleanly to direct compilation) and free of redundant subprocess probes (cc --version, tcc --version). Never make tenon emit-c depend on PCH or cached objects.
  6. Keep lower/regions linear on branch-heavy functions: Never reintroduce O(locals * branches) cloning/joining or O(locals * stmts) scans over all scalar locals in crates/tenon-compiler/src/lower*.rs or regions*.rs. Preserve dense container-local slot indexing, scalar-only function/block skipping, and the regions_place_scales_linearly_on_branch_heavy_functions regression test.
  7. Keep Rust unit tests millisecond-fast and parallel-friendly: Keep unit tests unit-level (in-memory inputs, no child processes, C compiler, network, or sleeps) so cargo test --workspace stays far below the 120s budget. Split multi-app or multi-scenario compiler tests into independent #[test] functions so libtest runs them across cores, use BuildMode::Dev (-O0) unless -O2 is specifically under test, reuse precompiled objects where safe, and record before/after timings whenever touching build scripts, caches, or gate steps.