| author | |
| committer | |
| log | df4849c4f5aafc7eb80fd7b2299b49162fa2aa79 |
| tree | 864575631cbefdbaffb8228e6085a224684d2eb4 |
| parent | da878dc0776b56c1e2c251857a40415a35e9535a |
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.4 files changed, 15 insertions(+), 5 deletions(-)
src/AstGen.zig+8-3| ... | ... | @@ -2906,9 +2906,14 @@ fn deferStmt( |
| 2906 | 2906 | try gz.addDbgBlockBegin(); |
| 2907 | 2907 | const ident_name = try gz.astgen.identAsString(payload_token); |
| 2908 | 2908 | remapped_err_code = @intCast(Zir.Inst.Index, gz.astgen.instructions.len); |
| 2909 | // Use a placeholder tag of .as to allow querying things that depend on the tag, | |
| 2910 | // but undefined data to prevent querying of data.bin. | |
| 2911 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ .tag = .as, .data = undefined }); | |
| 2909 | try gz.astgen.instructions.append(gz.astgen.gpa, .{ | |
| 2910 | .tag = .extended, | |
| 2911 | .data = .{ .extended = .{ | |
| 2912 | .opcode = .errdefer_err_code, | |
| 2913 | .small = undefined, | |
| 2914 | .operand = undefined, | |
| 2915 | } }, | |
| 2916 | }); | |
| 2912 | 2917 | const remapped_err_code_ref = Zir.indexToRef(remapped_err_code); |
| 2913 | 2918 | local_val_scope = .{ |
| 2914 | 2919 | .parent = &defer_gen.base, |
src/Sema.zig+1| ... | ... | @@ -1198,6 +1198,7 @@ fn analyzeBodyInner( |
| 1198 | 1198 | i += 1; |
| 1199 | 1199 | continue; |
| 1200 | 1200 | }, |
| 1201 | .errdefer_err_code => unreachable, // never appears in a body | |
| 1201 | 1202 | }; |
| 1202 | 1203 | }, |
| 1203 | 1204 |
src/Zir.zig+5-2| ... | ... | @@ -1979,7 +1979,7 @@ pub const Inst = struct { |
| 1979 | 1979 | /// `operand` is `src_node: i32`. |
| 1980 | 1980 | breakpoint, |
| 1981 | 1981 | /// Implements the `@select` builtin. |
| 1982 | /// operand` is payload index to `Select`. | |
| 1982 | /// `operand` is payload index to `Select`. | |
| 1983 | 1983 | select, |
| 1984 | 1984 | /// Implement builtin `@errToInt`. |
| 1985 | 1985 | /// `operand` is payload index to `UnNode`. |
| ... | ... | @@ -1999,7 +1999,7 @@ pub const Inst = struct { |
| 1999 | 1999 | /// `operand` is payload index to `Cmpxchg`. |
| 2000 | 2000 | cmpxchg, |
| 2001 | 2001 | /// Implement the builtin `@addrSpaceCast` |
| 2002 | /// `Operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand. | |
| 2002 | /// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand. | |
| 2003 | 2003 | addrspace_cast, |
| 2004 | 2004 | /// Implement builtin `@cVaArg`. |
| 2005 | 2005 | /// `operand` is payload index to `BinNode`. |
| ... | ... | @@ -2031,6 +2031,9 @@ pub const Inst = struct { |
| 2031 | 2031 | /// Implements the `@inComptime` builtin. |
| 2032 | 2032 | /// `operand` is `src_node: i32`. |
| 2033 | 2033 | in_comptime, |
| 2034 | /// Used as a placeholder for the capture of an `errdefer`. | |
| 2035 | /// This is replaced by Sema with the captured value. | |
| 2036 | errdefer_err_code, | |
| 2034 | 2037 | |
| 2035 | 2038 | pub const InstData = struct { |
| 2036 | 2039 | opcode: Extended, |
src/print_zir.zig+1| ... | ... | @@ -467,6 +467,7 @@ const Writer = struct { |
| 467 | 467 | .breakpoint, |
| 468 | 468 | .c_va_start, |
| 469 | 469 | .in_comptime, |
| 470 | .errdefer_err_code, | |
| 470 | 471 | => try self.writeExtNode(stream, extended), |
| 471 | 472 | |
| 472 | 473 | .builtin_src => { |