mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
AstGen: cleanup previous fix
Allocating an extended tag is much cleaner and easier to reason about than reusing an existing tag. The previous `.data = undefined` was a clear indication that we don't have any data to store, and so might as well store an extended tag in that space almost for free.
This commit is contained in:
parent
da878dc077
commit
df4849c4f5
4 changed files with 15 additions and 5 deletions
|
|
@ -2906,9 +2906,14 @@ fn deferStmt(
|
||||||
try gz.addDbgBlockBegin();
|
try gz.addDbgBlockBegin();
|
||||||
const ident_name = try gz.astgen.identAsString(payload_token);
|
const ident_name = try gz.astgen.identAsString(payload_token);
|
||||||
remapped_err_code = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
|
remapped_err_code = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
|
||||||
// Use a placeholder tag of .as to allow querying things that depend on the tag,
|
try gz.astgen.instructions.append(gz.astgen.gpa, .{
|
||||||
// but undefined data to prevent querying of data.bin.
|
.tag = .extended,
|
||||||
try gz.astgen.instructions.append(gz.astgen.gpa, .{ .tag = .as, .data = undefined });
|
.data = .{ .extended = .{
|
||||||
|
.opcode = .errdefer_err_code,
|
||||||
|
.small = undefined,
|
||||||
|
.operand = undefined,
|
||||||
|
} },
|
||||||
|
});
|
||||||
const remapped_err_code_ref = Zir.indexToRef(remapped_err_code);
|
const remapped_err_code_ref = Zir.indexToRef(remapped_err_code);
|
||||||
local_val_scope = .{
|
local_val_scope = .{
|
||||||
.parent = &defer_gen.base,
|
.parent = &defer_gen.base,
|
||||||
|
|
|
||||||
|
|
@ -1198,6 +1198,7 @@ fn analyzeBodyInner(
|
||||||
i += 1;
|
i += 1;
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
|
.errdefer_err_code => unreachable, // never appears in a body
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1979,7 +1979,7 @@ pub const Inst = struct {
|
||||||
/// `operand` is `src_node: i32`.
|
/// `operand` is `src_node: i32`.
|
||||||
breakpoint,
|
breakpoint,
|
||||||
/// Implements the `@select` builtin.
|
/// Implements the `@select` builtin.
|
||||||
/// operand` is payload index to `Select`.
|
/// `operand` is payload index to `Select`.
|
||||||
select,
|
select,
|
||||||
/// Implement builtin `@errToInt`.
|
/// Implement builtin `@errToInt`.
|
||||||
/// `operand` is payload index to `UnNode`.
|
/// `operand` is payload index to `UnNode`.
|
||||||
|
|
@ -1999,7 +1999,7 @@ pub const Inst = struct {
|
||||||
/// `operand` is payload index to `Cmpxchg`.
|
/// `operand` is payload index to `Cmpxchg`.
|
||||||
cmpxchg,
|
cmpxchg,
|
||||||
/// Implement the builtin `@addrSpaceCast`
|
/// Implement the builtin `@addrSpaceCast`
|
||||||
/// `Operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand.
|
/// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand.
|
||||||
addrspace_cast,
|
addrspace_cast,
|
||||||
/// Implement builtin `@cVaArg`.
|
/// Implement builtin `@cVaArg`.
|
||||||
/// `operand` is payload index to `BinNode`.
|
/// `operand` is payload index to `BinNode`.
|
||||||
|
|
@ -2031,6 +2031,9 @@ pub const Inst = struct {
|
||||||
/// Implements the `@inComptime` builtin.
|
/// Implements the `@inComptime` builtin.
|
||||||
/// `operand` is `src_node: i32`.
|
/// `operand` is `src_node: i32`.
|
||||||
in_comptime,
|
in_comptime,
|
||||||
|
/// Used as a placeholder for the capture of an `errdefer`.
|
||||||
|
/// This is replaced by Sema with the captured value.
|
||||||
|
errdefer_err_code,
|
||||||
|
|
||||||
pub const InstData = struct {
|
pub const InstData = struct {
|
||||||
opcode: Extended,
|
opcode: Extended,
|
||||||
|
|
|
||||||
|
|
@ -467,6 +467,7 @@ const Writer = struct {
|
||||||
.breakpoint,
|
.breakpoint,
|
||||||
.c_va_start,
|
.c_va_start,
|
||||||
.in_comptime,
|
.in_comptime,
|
||||||
|
.errdefer_err_code,
|
||||||
=> try self.writeExtNode(stream, extended),
|
=> try self.writeExtNode(stream, extended),
|
||||||
|
|
||||||
.builtin_src => {
|
.builtin_src => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue