From 24ba8a1bfc40e9dcf1c43db012dbd5d9303c71c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Fri, 13 Feb 2026 18:20:36 +0000 Subject: [PATCH] astgen: fix @as result propagation, RL_REF_COERCED_TY, continue break src_node, varDecl init RL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - @as builtin: propagate RL_TY with dest_type through exprRl instead of evaluating operand with RL_NONE and manually emitting as_node. Matches upstream AstGen.zig lines 8909-8920. - rlResultType: add missing RL_REF_COERCED_TY case (elem_type extraction). - continue handler: use AST_NODE_OFFSET_NONE for addBreak operand_src_node instead of computing node offset. Upstream uses addBreak (not addBreakWithSrcNode), which writes .none. - varDecl: set init_rl.src_node = 0 for RL_PTR (upstream leaves PtrResultLoc.src_node at default .none). Enables astgen_test.zig corpus test — all corpus tests now pass. Co-Authored-By: Claude Opus 4.6 --- astgen.c | 21 ++++++++++++++------- astgen_test.zig | 1 - 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/astgen.c b/astgen.c index bd2f14d88e..5a5c1d9c1b 100644 --- a/astgen.c +++ b/astgen.c @@ -1844,6 +1844,10 @@ static uint32_t rlResultType(GenZir* gz, ResultLoc rl, uint32_t node) { case RL_TY: case RL_COERCED_TY: return rl.data; + case RL_REF_COERCED_TY: + // AstGen.zig:345: .ref_coerced_ty => |ptr_ty| gz.addUnNode(.elem_type, + // ptr_ty, node) + return addUnNode(gz, ZIR_INST_ELEM_TYPE, rl.data, node); case RL_PTR: { // typeof(ptr) -> elem_type (AstGen.zig:346-349). uint32_t ptr_ty = addUnNode(gz, ZIR_INST_TYPEOF, rl.data, node); @@ -2482,12 +2486,14 @@ static uint32_t builtinCall( emitDbgStmt(gz, saved_line, saved_col); return addUnNode(gz, ZIR_INST_TAG_NAME, operand, node); } - // @as (AstGen.zig:9388). + // @as (AstGen.zig:8909-8920). if (name_len == 2 && memcmp(source + name_start, "as", 2) == 0) { AstData nd = tree->nodes.datas[node]; uint32_t dest_type = typeExpr(gz, scope, nd.lhs); - uint32_t operand = expr(gz, scope, nd.rhs); - return addPlNodeBin(gz, ZIR_INST_AS_NODE, node, dest_type, operand); + ResultLoc as_rl = { .tag = RL_TY, .data = dest_type, .src_node = 0, + .ctx = rl.ctx }; + uint32_t operand = exprRl(gz, scope, as_rl, nd.rhs); + return rvalue(gz, rl, operand, node); } // @truncate — typeCast pattern (AstGen.zig:9417, 9807-9826). if (name_len == 8 && memcmp(source + name_start, "truncate", 8) == 0) { @@ -4380,8 +4386,7 @@ static uint32_t exprRl(GenZir* gz, Scope* scope, ResultLoc rl, uint32_t node) { rdata); } addBreak(gz, break_tag, gz2->continue_block, - ZIR_REF_VOID_VALUE, - (int32_t)node - (int32_t)gz->decl_node_index); + ZIR_REF_VOID_VALUE, AST_NODE_OFFSET_NONE); return ZIR_REF_UNREACHABLE_VALUE; } s = gz2->parent; @@ -6294,7 +6299,8 @@ static void varDecl(GenZir* gz, Scope* scope, uint32_t node, if (type_node != 0) { init_rl.tag = RL_PTR; init_rl.data = var_ptr; - init_rl.src_node = node; + init_rl.src_node = 0; // upstream: .none (PtrResultLoc.src_node + // defaults to null) } else { init_rl.tag = RL_INFERRED_PTR; init_rl.data = var_ptr; @@ -6362,7 +6368,8 @@ static void varDecl(GenZir* gz, Scope* scope, uint32_t node, if (type_node != 0) { var_init_rl.tag = RL_PTR; var_init_rl.data = alloc_ref; - var_init_rl.src_node = node; + var_init_rl.src_node = 0; // upstream: .none (PtrResultLoc.src_node + // defaults to null) } else { var_init_rl.tag = RL_INFERRED_PTR; var_init_rl.data = alloc_ref; diff --git a/astgen_test.zig b/astgen_test.zig index 6d61a7dd03..b1bf630ebd 100644 --- a/astgen_test.zig +++ b/astgen_test.zig @@ -798,7 +798,6 @@ test "astgen: corpus tokenizer_test.zig" { } test "astgen: corpus astgen_test.zig" { - if (true) return error.SkipZigTest; // TODO: extra data offset mismatches const gpa = std.testing.allocator; try corpusCheck(gpa, @embedFile("astgen_test.zig")); }