iter hs.1: static-Str layout migration — packed-struct globals + sentinel rc-header + len

First iter of the heap-Str ABI milestone. Pure codegen refactor; every existing program produces byte-identical stdout.

Static-Str LLVM globals migrate from `[N x i8] c"…\00"` to `<{ i64, i64, [N x i8] }> <{ i64 -1, i64 N-1, [N x i8] c"…\00" }>`, carrying the UINT64_MAX sentinel rc-header (slot exploited in hs.2 via runtime short-circuit) and an explicit byte length. Two parallel intern paths (`intern_string` for raw format scaffolding, new `intern_str_literal` for language Str values) keep format strings untouched in `[N x i8]` shape.

IR-Str pointers now uniformly land on the len-field (offset +8 from rc-header, -8 from bytes). Four codegen sites that hand a Str pointer to a NUL-terminated-bytes C-API consumer now emit a +8 GEP first: `@puts` (io/print_str), `@ail_str_eq` (eq__Str intercept), `@ail_str_compare` (compare__Str intercept), and `@strcmp` (lower_eq Str arm — the 4th site was not in the plan; surfaced by Task-5 e2e regression and fixed inline).

6 new IR-shape pinning tests; `hello.ll` snapshot regenerated; cross_lang.py + compile_check.py + full `cargo test --workspace` green.
This commit is contained in:
2026-05-12 16:48:24 +02:00
parent 69bb5f9952
commit c56498aca7
5 changed files with 532 additions and 12 deletions
+3 -2
View File
@@ -2,7 +2,7 @@
source_filename = "hello.ail"
target triple = "<NORMALIZED>"
@.str_hello_str_0 = private unnamed_addr constant [15 x i8] c"Hello, AILang.\00", align 1
@.str_hello_str_0 = private unnamed_addr constant <{ i64, i64, [15 x i8] }> <{ i64 -1, i64 14, [15 x i8] c"Hello, AILang.\00" }>, align 8
declare i32 @printf(ptr, ...)
declare i32 @puts(ptr)
@@ -15,7 +15,8 @@ declare i64 @llvm.fptosi.sat.i64.f64(double)
@ail_hello_main_clos = private unnamed_addr constant { ptr, ptr } { ptr @ail_hello_main_adapter, ptr null }
define i8 @ail_hello_main() {
entry:
call i32 @puts(ptr @.str_hello_str_0)
%v1 = getelementptr inbounds i8, ptr getelementptr inbounds (<{ i64, i64, [15 x i8] }>, ptr @.str_hello_str_0, i32 0, i32 1), i64 8
call i32 @puts(ptr %v1)
ret i8 0
}