astgen: fix @as result propagation, RL_REF_COERCED_TY, continue break src_node, varDecl init RL
- @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 <noreply@anthropic.com>
This commit is contained in:
21
astgen.c
21
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;
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user