Skip to content

Vendor Kauri, keep line numbers straight, and lock in reproducible output - #160

Merged
Zaneham merged 3 commits into
masterfrom
feat/kauri-and-provenance
Aug 9, 2026
Merged

Vendor Kauri, keep line numbers straight, and lock in reproducible output#160
Zaneham merged 3 commits into
masterfrom
feat/kauri-and-provenance

Conversation

@Zaneham

@Zaneham Zaneham commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Three things, all foundations rather than features.

DCE and mem2reg were lying about line numbers. inst_lines[] is indexed by instruction position, and both passes move instructions around without moving the table with them. So after any dead code was removed, every line past the first deleted instruction was shifted. Not missing, wrong, which is worse. Four sites: the in-block compaction and the cross-function shift in bir_dce.c, and the scratch rebuild plus its own shift in bir_mem2reg.c. bir_insert.c and bir_inline.c were already doing it properly, which is probably why nobody noticed the rest.

Easy to see with a kernel where lines 2, 3 and 5 are dead:

%2 = add i32 %1, 1   ; line 4   <- int a = n + 1;
%3 = mul i32 %2, 2   ; line 6   <- int b = a * 2;
gep / store / ret    ; line 7   <- out[0] = b;

Before, that first one reported line 2.

make repro checks the same input gives the same bytes. bir.h already claims a deterministic layout, this makes it a property instead of an intention. 309 runs, every test file across --amdgpu, --nvidia-ptx and --ir, compiled twice in separate processes so ASLR and any pointer-ordered container would show up. All reproducible today. The point is catching the commit that breaks it, because that's the only moment it's cheap to find.

Kauri is vendored in. src/kauri.h plus a one-line kauri_impl.c for the single instantiation, included from barracuda.h so KA_GUARD, KA_CHK and KA_PNEW are available everywhere. Three of the style rules in CONTRIBUTING had no mechanism behind them, now they do. Added a section there showing the pattern and inviting PRs for spots that could use it, since most existing code predates the macros.

It's MIT so there's no friction with Apache, and the vendored copy says so at the top. Nothing uses the arena or KA_TRY, since allocation happens once per phase and errors are BC_ERR_*. One error idiom per compiler.

Also fixed the copy in Takahe separately, which had an MPL header stamped on it and was telling people the wrong licence.

Both commits build and test standalone. 379/380 with 1 skipped, make repro clean, no new diagnostics under the strict flags.

This commit was assisted by claude code. The DCE and mem2reg were mine, claude assisted with vendoring in Kauri and adding 'make repro' as well as a draft of this PR description.

@Zaneham
Zaneham merged commit c4b48b3 into master Aug 9, 2026
12 checks passed
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