sema: fix ret_implicit inlining, remove spurious generic dead blocks; enable mulhf3

- Fix RET_IMPLICIT handler to check block->inlining (generates br instead
  of ret when inside inline functions), matching upstream's analyzeRet
- Remove invented skip_returns_type_blocks mechanism that incorrectly
  pre-emitted dead BLOCK instructions for generic param type evaluation.
  Upstream evaluates generic param types at comptime in a separate
  generic_block, producing no runtime AIR instructions.
- Remove unused variables (src_ty, completed)
- Add unit tests for inline function call patterns

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 20:08:11 +00:00
parent 15e7722505
commit c4fe2e7780
3 changed files with 458 additions and 243 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1226,3 +1226,117 @@ test "sema air: if-else block result" {
\\}
);
}
test "sema air: call inside runtime conditional" {
try semaAirRawCheck(
\\fn bar(p: *u32) void {
\\ p.* += 1;
\\}
\\export fn f(a: u32) u32 {
\\ var x: u32 = a;
\\ if (a < 10) bar(&x);
\\ return x;
\\}
);
}
test "sema air: inline fn with call inside conditional" {
try semaAirRawCheck(
\\fn bar(p: *u32) void {
\\ p.* += 1;
\\}
\\inline fn baz(a: u32, x: *u32) void {
\\ if (a < 10) bar(x);
\\}
\\export fn f(a: u32) u32 {
\\ var x: u32 = a;
\\ baz(a, &x);
\\ return x;
\\}
);
}
test "sema air: += with call inside conditional" {
try semaAirRawCheck(
\\fn bar(p: *u32) u32 {
\\ return p.* + 1;
\\}
\\export fn f(a: u32) u32 {
\\ var x: u32 = a;
\\ if (a < 10) x += bar(&x);
\\ return x;
\\}
);
}
test "sema air: inline fn with += call inside conditional" {
try semaAirRawCheck(
\\fn bar(p: *u32) u32 {
\\ return p.* + 1;
\\}
\\inline fn baz(a: u32, x: *u32) void {
\\ if (a < 10) x.* += bar(x);
\\}
\\export fn f(a: u32) u32 {
\\ var x: u32 = a;
\\ baz(a, &x);
\\ return x;
\\}
);
}
test "sema air: inline fn with generic call inside conditional" {
try semaAirRawCheck(
\\fn normalize(comptime T: type, p: *T) i32 {
\\ p.* +%= 1;
\\ return 1;
\\}
\\inline fn mulf(comptime T: type, a: T) T {
\\ var x: T = a;
\\ var scale: i32 = 0;
\\ if (x < 10) scale += normalize(T, &x);
\\ return x +% @as(T, @intCast(@as(u32, @bitCast(scale))));
\\}
\\export fn f(a: u32) u32 {
\\ return mulf(u32, a);
\\}
);
}
test "sema air: inline fn with two generic calls in conditionals" {
try semaAirRawCheck(
\\fn normalize(comptime T: type, p: *T) i32 {
\\ p.* +%= 1;
\\ return 1;
\\}
\\inline fn mulf(comptime T: type, a: T, b: T) T {
\\ var x: T = a;
\\ var y: T = b;
\\ var scale: i32 = 0;
\\ if (x < 10) scale += normalize(T, &x);
\\ if (y < 10) scale += normalize(T, &y);
\\ return x +% y +% @as(T, @intCast(@as(u32, @bitCast(scale))));
\\}
\\export fn f(a: u32, b: u32) u32 {
\\ return mulf(u32, a, b);
\\}
);
}
test "sema air: inline fn with += call inside two conditionals" {
try semaAirRawCheck(
\\fn bar(p: *u32) u32 {
\\ return p.* + 1;
\\}
\\inline fn baz(a: u32, x: *u32, y: *u32) void {
\\ if (a < 10) x.* += bar(x);
\\ if (a < 20) y.* += bar(y);
\\}
\\export fn f(a: u32) u32 {
\\ var x: u32 = a;
\\ var y: u32 = a;
\\ baz(a, &x, &y);
\\ return x +% y;
\\}
);
}

View File

@@ -146,8 +146,8 @@ const corpus_files = .{
"../lib/compiler_rt/floatunsixf.zig", // 353
"../lib/compiler_rt/truncxfhf2.zig", // 356
"../lib/compiler_rt/floatunsihf.zig", // 357
//"../lib/compiler_rt/trunctfhf2.zig", // 359
//"../lib/compiler_rt/extendsfxf2.zig", // 360
"../lib/compiler_rt/trunctfhf2.zig", // 359
"../lib/compiler_rt/extendsfxf2.zig", // 360
//"../lib/compiler/aro/backend.zig", // 362
//"../lib/compiler_rt/extenddfxf2.zig", // 364
//"../lib/std/compress.zig", // 372