authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-07 11:34:23-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-07 11:34:23-07:00
logd9c25ec6720ecb0bc79fcab67659ee12ca6ad687
tree6ec9572a2d31ee93492a0746732308aa04b1a0dc
parent4e8fb9e6a5f9a65bbf6469e386e83ba469e7543b

zir: use `node` union field for `alloc_inferred`

Previously we used `un_node` and passed `undefined` for the operand, but this causes illegal behavior when printing ZIR code.

3 files changed, 7 insertions(+), 7 deletions(-)

src/AstGen.zig+2-2
......@@ -1484,7 +1484,7 @@ fn varDecl(
14841484 init_scope.rl_ptr = try init_scope.addUnNode(.alloc, type_inst, node);
14851485 init_scope.rl_ty_inst = type_inst;
14861486 } else {
1487 const alloc = try init_scope.addUnNode(.alloc_inferred, undefined, node);
1487 const alloc = try init_scope.addNode(.alloc_inferred, node);
14881488 resolve_inferred_alloc = alloc;
14891489 init_scope.rl_ptr = alloc;
14901490 }
......@@ -1559,7 +1559,7 @@ fn varDecl(
15591559 const alloc = try gz.addUnNode(.alloc_mut, type_inst, node);
15601560 break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } };
15611561 } else a: {
1562 const alloc = try gz.addUnNode(.alloc_inferred_mut, undefined, node);
1562 const alloc = try gz.addNode(.alloc_inferred_mut, node);
15631563 resolve_inferred_alloc = alloc;
15641564 break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };
15651565 };
src/Sema.zig+2-2
......@@ -785,8 +785,8 @@ fn zirAllocInferred(
785785 const tracy = trace(@src());
786786 defer tracy.end();
787787
788 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
789 const src = inst_data.src();
788 const src_node = sema.code.instructions.items(.data)[inst].node;
789 const src: LazySrcLoc = .{ .node_offset = src_node };
790790
791791 const val_payload = try sema.arena.create(Value.Payload.InferredAlloc);
792792 val_payload.* = .{
src/zir.zig+3-3
......@@ -130,7 +130,7 @@ pub const Inst = struct {
130130 /// Same as `alloc` except mutable.
131131 alloc_mut,
132132 /// Same as `alloc` except the type is inferred.
133 /// The operand is unused.
133 /// Uses the `node` union field.
134134 alloc_inferred,
135135 /// Same as `alloc_inferred` except mutable.
136136 alloc_inferred_mut,
......@@ -1577,8 +1577,6 @@ const Writer = struct {
15771577
15781578 .alloc,
15791579 .alloc_mut,
1580 .alloc_inferred,
1581 .alloc_inferred_mut,
15821580 .indexable_ptr_len,
15831581 .bit_not,
15841582 .bool_not,
......@@ -1745,6 +1743,8 @@ const Writer = struct {
17451743 .ret_type,
17461744 .repeat,
17471745 .repeat_inline,
1746 .alloc_inferred,
1747 .alloc_inferred_mut,
17481748 => try self.writeNode(stream, inst),
17491749
17501750 .error_value,