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(...@@ -1484,7 +1484,7 @@ fn varDecl(
1484 init_scope.rl_ptr = try init_scope.addUnNode(.alloc, type_inst, node);1484 init_scope.rl_ptr = try init_scope.addUnNode(.alloc, type_inst, node);
1485 init_scope.rl_ty_inst = type_inst;1485 init_scope.rl_ty_inst = type_inst;
1486 } else {1486 } else {
1487 const alloc = try init_scope.addUnNode(.alloc_inferred, undefined, node);1487 const alloc = try init_scope.addNode(.alloc_inferred, node);
1488 resolve_inferred_alloc = alloc;1488 resolve_inferred_alloc = alloc;
1489 init_scope.rl_ptr = alloc;1489 init_scope.rl_ptr = alloc;
1490 }1490 }
...@@ -1559,7 +1559,7 @@ fn varDecl(...@@ -1559,7 +1559,7 @@ fn varDecl(
1559 const alloc = try gz.addUnNode(.alloc_mut, type_inst, node);1559 const alloc = try gz.addUnNode(.alloc_mut, type_inst, node);
1560 break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } };1560 break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } };
1561 } else a: {1561 } else a: {
1562 const alloc = try gz.addUnNode(.alloc_inferred_mut, undefined, node);1562 const alloc = try gz.addNode(.alloc_inferred_mut, node);
1563 resolve_inferred_alloc = alloc;1563 resolve_inferred_alloc = alloc;
1564 break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };1564 break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } };
1565 };1565 };
src/Sema.zig+2-2
...@@ -785,8 +785,8 @@ fn zirAllocInferred(...@@ -785,8 +785,8 @@ fn zirAllocInferred(
785 const tracy = trace(@src());785 const tracy = trace(@src());
786 defer tracy.end();786 defer tracy.end();
787787
788 const inst_data = sema.code.instructions.items(.data)[inst].un_node;788 const src_node = sema.code.instructions.items(.data)[inst].node;
789 const src = inst_data.src();789 const src: LazySrcLoc = .{ .node_offset = src_node };
790790
791 const val_payload = try sema.arena.create(Value.Payload.InferredAlloc);791 const val_payload = try sema.arena.create(Value.Payload.InferredAlloc);
792 val_payload.* = .{792 val_payload.* = .{
src/zir.zig+3-3
...@@ -130,7 +130,7 @@ pub const Inst = struct {...@@ -130,7 +130,7 @@ pub const Inst = struct {
130 /// Same as `alloc` except mutable.130 /// Same as `alloc` except mutable.
131 alloc_mut,131 alloc_mut,
132 /// Same as `alloc` except the type is inferred.132 /// Same as `alloc` except the type is inferred.
133 /// The operand is unused.133 /// Uses the `node` union field.
134 alloc_inferred,134 alloc_inferred,
135 /// Same as `alloc_inferred` except mutable.135 /// Same as `alloc_inferred` except mutable.
136 alloc_inferred_mut,136 alloc_inferred_mut,
...@@ -1577,8 +1577,6 @@ const Writer = struct {...@@ -1577,8 +1577,6 @@ const Writer = struct {
15771577
1578 .alloc,1578 .alloc,
1579 .alloc_mut,1579 .alloc_mut,
1580 .alloc_inferred,
1581 .alloc_inferred_mut,
1582 .indexable_ptr_len,1580 .indexable_ptr_len,
1583 .bit_not,1581 .bit_not,
1584 .bool_not,1582 .bool_not,
...@@ -1745,6 +1743,8 @@ const Writer = struct {...@@ -1745,6 +1743,8 @@ const Writer = struct {
1745 .ret_type,1743 .ret_type,
1746 .repeat,1744 .repeat,
1747 .repeat_inline,1745 .repeat_inline,
1746 .alloc_inferred,
1747 .alloc_inferred_mut,
1748 => try self.writeNode(stream, inst),1748 => try self.writeNode(stream, inst),
17491749
1750 .error_value,1750 .error_value,