tests: IR-snapshot harness — diff sx ir output when .ir present

run_examples.sh now supports an optional `tests/expected/<name>.ir`
sibling to `.txt`/`.exit`. When present, the runner also captures
`sx ir <file>` output, normalizes target-/host-specific noise
(module ID, target triple/datalayout, attribute groups, LLVM's
auto-suffixed %temp numbering), and diffs against the snapshot.
`--update` regenerates it alongside the runtime output.

Catches lowering changes that don't affect what the program prints
— exactly the shape Phase 1.5's selector interning will produce
(same runtime output, very different IR).

First snapshot: `ffi-objc-call-03-selector-sharing.ir`. Today the
test emits four `call ptr @sel_registerName(ptr @str.N)` lines for
its four call sites; after 1.5 we expect two static
`@OBJC_SELECTOR_REFERENCES_<sel>` globals + loads at each call
site. The diff between the two snapshots will be the visible
artifact of the optimization.
This commit is contained in:
agra
2026-05-19 13:01:28 +03:00
parent c54ca755fa
commit 26a04e49d0
3 changed files with 330 additions and 7 deletions

View File

@@ -9,12 +9,13 @@
// at module init. Per call site becomes a single load.
//
// Runtime behavior is unchanged before vs. after 1.5; the
// improvement is visible in `sx ir` only. After 1.5 we should
// see exactly one `sel_registerName` call per unique selector
// string in the emitted IR — verify with:
//
// ./zig-out/bin/sx ir examples/ffi-objc-call-03-selector-sharing.sx \
// | grep -c "call ptr @sel_registerName"
// improvement is visible in `sx ir` only. The IR snapshot at
// `tests/expected/ffi-objc-call-03-selector-sharing.ir` locks
// in today's shape (4 `call ptr @sel_registerName` instructions,
// one per call site). After 1.5 lands selector interning, the
// snapshot updates to ≤2 (one per unique selector string) plus
// a static `@OBJC_SELECTOR_REFERENCES_<sel>` global and loads at
// the call sites.
#import "modules/std.sx";
#import "modules/compiler.sx";