commit 353959d28f343ea7ba47828bc521c46bd0d01b7b (tree)
parent aff6dd419c913c7f0f410422229dcc93aa307b3f
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date: Fri, 13 Feb 2026 19:20:47 +0000
astgen: pass struct_init_empty through rvalue for proper RL handling
Typed struct init empty (SomeType{}) was returning the result directly
without going through rvalue(), missing STORE_NODE/STORE_TO_INFERRED_PTR/
COERCE_PTR_ELEM_TY+REF emissions when result location requires storage.
Reduces parser_test.zig corpus diff from 5 to 1 instruction.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat:
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/astgen.c b/astgen.c
@@ -3790,8 +3790,10 @@ static uint32_t structInitExpr(
uint32_t array_type_inst
= addPlNodeBin(gz, ZIR_INST_ARRAY_TYPE, type_expr_node,
ZIR_REF_ZERO_USIZE, elem_type);
- return addUnNode(
- gz, ZIR_INST_STRUCT_INIT_EMPTY, array_type_inst, node);
+ return rvalue(gz, rl,
+ addUnNode(gz, ZIR_INST_STRUCT_INIT_EMPTY,
+ array_type_inst, node),
+ node);
}
// ARRAY_TYPE_SENTINEL: extra[rhs] = sentinel, extra[rhs+1]
// = elem_type
@@ -3808,12 +3810,15 @@ static uint32_t structInitExpr(
uint32_t array_type_inst = addPlNodeTriple(gz,
ZIR_INST_ARRAY_TYPE_SENTINEL, type_expr_node,
ZIR_REF_ZERO_USIZE, elem_type, sentinel);
- return addUnNode(
- gz, ZIR_INST_STRUCT_INIT_EMPTY, array_type_inst, node);
+ return rvalue(gz, rl,
+ addUnNode(
+ gz, ZIR_INST_STRUCT_INIT_EMPTY, array_type_inst, node),
+ node);
}
}
uint32_t ty_inst = typeExpr(gz, scope, type_expr_node);
- return addUnNode(gz, ZIR_INST_STRUCT_INIT_EMPTY, ty_inst, node);
+ return rvalue(gz, rl,
+ addUnNode(gz, ZIR_INST_STRUCT_INIT_EMPTY, ty_inst, node), node);
}
// Typed struct init with fields (AstGen.zig:1808-1818).
diff --git a/astgen_test.zig b/astgen_test.zig
@@ -798,8 +798,8 @@ test "astgen: corpus tokenizer_test.zig" {
}
test "astgen: corpus parser_test.zig" {
- // TODO: 5 inst diff — 2 STORE_TO_INFERRED_PTR, 1 REF, 1 STORE_NODE,
- // 1 COERCE_PTR_ELEM_TY.
+ // TODO: 1 inst diff — 1 STORE_NODE inside ptr-based struct init with
+ // block field init expression.
if (true) return error.SkipZigTest;
const gpa = std.testing.allocator;
try corpusCheck(gpa, @embedFile("parser_test.zig"));