aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/zig.zig373
-rw-r--r--lib/std/zig/AstGen.zig44
-rw-r--r--lib/std/zig/Zir.zig97
3 files changed, 64 insertions, 450 deletions
diff --git a/lib/std/zig.zig b/lib/std/zig.zig
index f0bcc974f6..230dc45ddc 100644
--- a/lib/std/zig.zig
+++ b/lib/std/zig.zig
@@ -350,379 +350,6 @@ pub fn serializeCpuAlloc(ally: Allocator, cpu: std.Target.Cpu) Allocator.Error![
return buffer.toOwnedSlice();
}
-pub const DeclIndex = enum(u32) {
- _,
-
- pub fn toOptional(i: DeclIndex) OptionalDeclIndex {
- return @enumFromInt(@intFromEnum(i));
- }
-};
-
-pub const OptionalDeclIndex = enum(u32) {
- none = std.math.maxInt(u32),
- _,
-
- pub fn init(oi: ?DeclIndex) OptionalDeclIndex {
- return @enumFromInt(@intFromEnum(oi orelse return .none));
- }
-
- pub fn unwrap(oi: OptionalDeclIndex) ?DeclIndex {
- if (oi == .none) return null;
- return @enumFromInt(@intFromEnum(oi));
- }
-};
-
-/// Resolving a source location into a byte offset may require doing work
-/// that we would rather not do unless the error actually occurs.
-/// Therefore we need a data structure that contains the information necessary
-/// to lazily produce a `SrcLoc` as required.
-/// Most of the offsets in this data structure are relative to the containing Decl.
-/// This makes the source location resolve properly even when a Decl gets
-/// shifted up or down in the file, as long as the Decl's contents itself
-/// do not change.
-pub const LazySrcLoc = union(enum) {
- /// When this tag is set, the code that constructed this `LazySrcLoc` is asserting
- /// that all code paths which would need to resolve the source location are
- /// unreachable. If you are debugging this tag incorrectly being this value,
- /// look into using reverse-continue with a memory watchpoint to see where the
- /// value is being set to this tag.
- unneeded,
- /// Means the source location points to an entire file; not any particular
- /// location within the file. `file_scope` union field will be active.
- entire_file,
- /// The source location points to a byte offset within a source file,
- /// offset from 0. The source file is determined contextually.
- /// Inside a `SrcLoc`, the `file_scope` union field will be active.
- byte_abs: u32,
- /// The source location points to a token within a source file,
- /// offset from 0. The source file is determined contextually.
- /// Inside a `SrcLoc`, the `file_scope` union field will be active.
- token_abs: u32,
- /// The source location points to an AST node within a source file,
- /// offset from 0. The source file is determined contextually.
- /// Inside a `SrcLoc`, the `file_scope` union field will be active.
- node_abs: u32,
- /// The source location points to a byte offset within a source file,
- /// offset from the byte offset of the Decl within the file.
- /// The Decl is determined contextually.
- byte_offset: u32,
- /// This data is the offset into the token list from the Decl token.
- /// The Decl is determined contextually.
- token_offset: u32,
- /// The source location points to an AST node, which is this value offset
- /// from its containing Decl node AST index.
- /// The Decl is determined contextually.
- node_offset: TracedOffset,
- /// The source location points to the main token of an AST node, found
- /// by taking this AST node index offset from the containing Decl AST node.
- /// The Decl is determined contextually.
- node_offset_main_token: i32,
- /// The source location points to the beginning of a struct initializer.
- /// The Decl is determined contextually.
- node_offset_initializer: i32,
- /// The source location points to a variable declaration type expression,
- /// found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a variable declaration AST node. Next, navigate
- /// to the type expression.
- /// The Decl is determined contextually.
- node_offset_var_decl_ty: i32,
- /// The source location points to the alignment expression of a var decl.
- /// The Decl is determined contextually.
- node_offset_var_decl_align: i32,
- /// The source location points to the linksection expression of a var decl.
- /// The Decl is determined contextually.
- node_offset_var_decl_section: i32,
- /// The source location points to the addrspace expression of a var decl.
- /// The Decl is determined contextually.
- node_offset_var_decl_addrspace: i32,
- /// The source location points to the initializer of a var decl.
- /// The Decl is determined contextually.
- node_offset_var_decl_init: i32,
- /// The source location points to the first parameter of a builtin
- /// function call, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a builtin call AST node. Next, navigate
- /// to the first parameter.
- /// The Decl is determined contextually.
- node_offset_builtin_call_arg0: i32,
- /// Same as `node_offset_builtin_call_arg0` except arg index 1.
- node_offset_builtin_call_arg1: i32,
- node_offset_builtin_call_arg2: i32,
- node_offset_builtin_call_arg3: i32,
- node_offset_builtin_call_arg4: i32,
- node_offset_builtin_call_arg5: i32,
- /// Like `node_offset_builtin_call_arg0` but recurses through arbitrarily many calls
- /// to pointer cast builtins.
- node_offset_ptrcast_operand: i32,
- /// The source location points to the index expression of an array access
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to an array access AST node. Next, navigate
- /// to the index expression.
- /// The Decl is determined contextually.
- node_offset_array_access_index: i32,
- /// The source location points to the LHS of a slice expression
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a slice AST node. Next, navigate
- /// to the sentinel expression.
- /// The Decl is determined contextually.
- node_offset_slice_ptr: i32,
- /// The source location points to start expression of a slice expression
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a slice AST node. Next, navigate
- /// to the sentinel expression.
- /// The Decl is determined contextually.
- node_offset_slice_start: i32,
- /// The source location points to the end expression of a slice
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a slice AST node. Next, navigate
- /// to the sentinel expression.
- /// The Decl is determined contextually.
- node_offset_slice_end: i32,
- /// The source location points to the sentinel expression of a slice
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a slice AST node. Next, navigate
- /// to the sentinel expression.
- /// The Decl is determined contextually.
- node_offset_slice_sentinel: i32,
- /// The source location points to the callee expression of a function
- /// call expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a function call AST node. Next, navigate
- /// to the callee expression.
- /// The Decl is determined contextually.
- node_offset_call_func: i32,
- /// The payload is offset from the containing Decl AST node.
- /// The source location points to the field name of:
- /// * a field access expression (`a.b`), or
- /// * the callee of a method call (`a.b()`)
- /// The Decl is determined contextually.
- node_offset_field_name: i32,
- /// The payload is offset from the containing Decl AST node.
- /// The source location points to the field name of the operand ("b" node)
- /// of a field initialization expression (`.a = b`)
- /// The Decl is determined contextually.
- node_offset_field_name_init: i32,
- /// The source location points to the pointer of a pointer deref expression,
- /// found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a pointer deref AST node. Next, navigate
- /// to the pointer expression.
- /// The Decl is determined contextually.
- node_offset_deref_ptr: i32,
- /// The source location points to the assembly source code of an inline assembly
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to inline assembly AST node. Next, navigate
- /// to the asm template source code.
- /// The Decl is determined contextually.
- node_offset_asm_source: i32,
- /// The source location points to the return type of an inline assembly
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to inline assembly AST node. Next, navigate
- /// to the return type expression.
- /// The Decl is determined contextually.
- node_offset_asm_ret_ty: i32,
- /// The source location points to the condition expression of an if
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to an if expression AST node. Next, navigate
- /// to the condition expression.
- /// The Decl is determined contextually.
- node_offset_if_cond: i32,
- /// The source location points to a binary expression, such as `a + b`, found
- /// by taking this AST node index offset from the containing Decl AST node.
- /// The Decl is determined contextually.
- node_offset_bin_op: i32,
- /// The source location points to the LHS of a binary expression, found
- /// by taking this AST node index offset from the containing Decl AST node,
- /// which points to a binary expression AST node. Next, navigate to the LHS.
- /// The Decl is determined contextually.
- node_offset_bin_lhs: i32,
- /// The source location points to the RHS of a binary expression, found
- /// by taking this AST node index offset from the containing Decl AST node,
- /// which points to a binary expression AST node. Next, navigate to the RHS.
- /// The Decl is determined contextually.
- node_offset_bin_rhs: i32,
- /// The source location points to the operand of a switch expression, found
- /// by taking this AST node index offset from the containing Decl AST node,
- /// which points to a switch expression AST node. Next, navigate to the operand.
- /// The Decl is determined contextually.
- node_offset_switch_operand: i32,
- /// The source location points to the else/`_` prong of a switch expression, found
- /// by taking this AST node index offset from the containing Decl AST node,
- /// which points to a switch expression AST node. Next, navigate to the else/`_` prong.
- /// The Decl is determined contextually.
- node_offset_switch_special_prong: i32,
- /// The source location points to all the ranges of a switch expression, found
- /// by taking this AST node index offset from the containing Decl AST node,
- /// which points to a switch expression AST node. Next, navigate to any of the
- /// range nodes. The error applies to all of them.
- /// The Decl is determined contextually.
- node_offset_switch_range: i32,
- /// The source location points to the capture of a switch_prong.
- /// The Decl is determined contextually.
- node_offset_switch_prong_capture: i32,
- /// The source location points to the tag capture of a switch_prong.
- /// The Decl is determined contextually.
- node_offset_switch_prong_tag_capture: i32,
- /// The source location points to the align expr of a function type
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a function type AST node. Next, navigate to
- /// the calling convention node.
- /// The Decl is determined contextually.
- node_offset_fn_type_align: i32,
- /// The source location points to the addrspace expr of a function type
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a function type AST node. Next, navigate to
- /// the calling convention node.
- /// The Decl is determined contextually.
- node_offset_fn_type_addrspace: i32,
- /// The source location points to the linksection expr of a function type
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a function type AST node. Next, navigate to
- /// the calling convention node.
- /// The Decl is determined contextually.
- node_offset_fn_type_section: i32,
- /// The source location points to the calling convention of a function type
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a function type AST node. Next, navigate to
- /// the calling convention node.
- /// The Decl is determined contextually.
- node_offset_fn_type_cc: i32,
- /// The source location points to the return type of a function type
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a function type AST node. Next, navigate to
- /// the return type node.
- /// The Decl is determined contextually.
- node_offset_fn_type_ret_ty: i32,
- node_offset_param: i32,
- token_offset_param: i32,
- /// The source location points to the type expression of an `anyframe->T`
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to a `anyframe->T` expression AST node. Next, navigate
- /// to the type expression.
- /// The Decl is determined contextually.
- node_offset_anyframe_type: i32,
- /// The source location points to the string literal of `extern "foo"`, found
- /// by taking this AST node index offset from the containing
- /// Decl AST node, which points to a function prototype or variable declaration
- /// expression AST node. Next, navigate to the string literal of the `extern "foo"`.
- /// The Decl is determined contextually.
- node_offset_lib_name: i32,
- /// The source location points to the len expression of an `[N:S]T`
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
- /// to the len expression.
- /// The Decl is determined contextually.
- node_offset_array_type_len: i32,
- /// The source location points to the sentinel expression of an `[N:S]T`
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
- /// to the sentinel expression.
- /// The Decl is determined contextually.
- node_offset_array_type_sentinel: i32,
- /// The source location points to the elem expression of an `[N:S]T`
- /// expression, found by taking this AST node index offset from the containing
- /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
- /// to the elem expression.
- /// The Decl is determined contextually.
- node_offset_array_type_elem: i32,
- /// The source location points to the operand of an unary expression.
- /// The Decl is determined contextually.
- node_offset_un_op: i32,
- /// The source location points to the elem type of a pointer.
- /// The Decl is determined contextually.
- node_offset_ptr_elem: i32,
- /// The source location points to the sentinel of a pointer.
- /// The Decl is determined contextually.
- node_offset_ptr_sentinel: i32,
- /// The source location points to the align expr of a pointer.
- /// The Decl is determined contextually.
- node_offset_ptr_align: i32,
- /// The source location points to the addrspace expr of a pointer.
- /// The Decl is determined contextually.
- node_offset_ptr_addrspace: i32,
- /// The source location points to the bit-offset of a pointer.
- /// The Decl is determined contextually.
- node_offset_ptr_bitoffset: i32,
- /// The source location points to the host size of a pointer.
- /// The Decl is determined contextually.
- node_offset_ptr_hostsize: i32,
- /// The source location points to the tag type of an union or an enum.
- /// The Decl is determined contextually.
- node_offset_container_tag: i32,
- /// The source location points to the default value of a field.
- /// The Decl is determined contextually.
- node_offset_field_default: i32,
- /// The source location points to the type of an array or struct initializer.
- /// The Decl is determined contextually.
- node_offset_init_ty: i32,
- /// The source location points to the LHS of an assignment.
- /// The Decl is determined contextually.
- node_offset_store_ptr: i32,
- /// The source location points to the RHS of an assignment.
- /// The Decl is determined contextually.
- node_offset_store_operand: i32,
- /// The source location points to the operand of a `return` statement, or
- /// the `return` itself if there is no explicit operand.
- /// The Decl is determined contextually.
- node_offset_return_operand: i32,
- /// The source location points to a for loop input.
- /// The Decl is determined contextually.
- for_input: struct {
- /// Points to the for loop AST node.
- for_node_offset: i32,
- /// Picks one of the inputs from the condition.
- input_index: u32,
- },
- /// The source location points to one of the captures of a for loop, found
- /// by taking this AST node index offset from the containing
- /// Decl AST node, which points to one of the input nodes of a for loop.
- /// Next, navigate to the corresponding capture.
- /// The Decl is determined contextually.
- for_capture_from_input: i32,
- /// The source location points to the argument node of a function call.
- call_arg: struct {
- decl: DeclIndex,
- /// Points to the function call AST node.
- call_node_offset: i32,
- /// The index of the argument the source location points to.
- arg_index: u32,
- },
- fn_proto_param: struct {
- decl: DeclIndex,
- /// Points to the function prototype AST node.
- fn_proto_node_offset: i32,
- /// The index of the parameter the source location points to.
- param_index: u32,
- },
- array_cat_lhs: ArrayCat,
- array_cat_rhs: ArrayCat,
-
- const ArrayCat = struct {
- /// Points to the array concat AST node.
- array_cat_offset: i32,
- /// The index of the element the source location points to.
- elem_index: u32,
- };
-
- pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;
-
- noinline fn nodeOffsetDebug(node_offset: i32) LazySrcLoc {
- var result: LazySrcLoc = .{ .node_offset = .{ .x = node_offset } };
- result.node_offset.trace.addAddr(@returnAddress(), "init");
- return result;
- }
-
- fn nodeOffsetRelease(node_offset: i32) LazySrcLoc {
- return .{ .node_offset = .{ .x = node_offset } };
- }
-
- /// This wraps a simple integer in debug builds so that later on we can find out
- /// where in semantic analysis the value got set.
- pub const TracedOffset = struct {
- x: i32,
- trace: std.debug.Trace = std.debug.Trace.init,
-
- const want_tracing = false;
- };
-};
-
const std = @import("std.zig");
const tokenizer = @import("zig/tokenizer.zig");
const assert = std.debug.assert;
diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig
index 03b9fa51b7..eecda76031 100644
--- a/lib/std/zig/AstGen.zig
+++ b/lib/std/zig/AstGen.zig
@@ -4011,7 +4011,7 @@ fn fnDecl(
// We insert this at the beginning so that its instruction index marks the
// start of the top level declaration.
- const decl_inst = try gz.makeBlockInst(.declaration, fn_proto.ast.proto_node);
+ const decl_inst = try gz.makeDeclaration(fn_proto.ast.proto_node);
astgen.advanceSourceCursorToNode(decl_node);
var decl_gz: GenZir = .{
@@ -4393,7 +4393,7 @@ fn globalVarDecl(
const is_mutable = token_tags[var_decl.ast.mut_token] == .keyword_var;
// We do this at the beginning so that the instruction index marks the range start
// of the top level declaration.
- const decl_inst = try gz.makeBlockInst(.declaration, node);
+ const decl_inst = try gz.makeDeclaration(node);
const name_token = var_decl.ast.mut_token + 1;
astgen.advanceSourceCursorToNode(node);
@@ -4555,7 +4555,7 @@ fn comptimeDecl(
// Up top so the ZIR instruction index marks the start range of this
// top-level declaration.
- const decl_inst = try gz.makeBlockInst(.declaration, node);
+ const decl_inst = try gz.makeDeclaration(node);
wip_members.nextDecl(decl_inst);
astgen.advanceSourceCursorToNode(node);
@@ -4607,7 +4607,7 @@ fn usingnamespaceDecl(
};
// Up top so the ZIR instruction index marks the start range of this
// top-level declaration.
- const decl_inst = try gz.makeBlockInst(.declaration, node);
+ const decl_inst = try gz.makeDeclaration(node);
wip_members.nextDecl(decl_inst);
astgen.advanceSourceCursorToNode(node);
@@ -4651,7 +4651,7 @@ fn testDecl(
// Up top so the ZIR instruction index marks the start range of this
// top-level declaration.
- const decl_inst = try gz.makeBlockInst(.declaration, node);
+ const decl_inst = try gz.makeDeclaration(node);
wip_members.nextDecl(decl_inst);
astgen.advanceSourceCursorToNode(node);
@@ -9366,9 +9366,10 @@ fn builtinCall(
try gz.instructions.ensureUnusedCapacity(gpa, 1);
try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
- const payload_index = try gz.astgen.addExtra(Zir.Inst.UnNode{
- .node = gz.nodeIndexToRelative(node),
+ const payload_index = try gz.astgen.addExtra(Zir.Inst.Reify{
+ .node = node, // Absolute node index -- see the definition of `Reify`.
.operand = operand,
+ .src_line = astgen.source_line,
});
const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
gz.astgen.instructions.appendAssumeCapacity(.{
@@ -13077,6 +13078,21 @@ const GenZir = struct {
}
/// Note that this returns a `Zir.Inst.Index` not a ref.
+ /// Does *not* append the block instruction to the scope.
+ /// Leaves the `payload_index` field undefined. Use `setDeclaration` to finalize.
+ fn makeDeclaration(gz: *GenZir, node: Ast.Node.Index) !Zir.Inst.Index {
+ const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
+ try gz.astgen.instructions.append(gz.astgen.gpa, .{
+ .tag = .declaration,
+ .data = .{ .declaration = .{
+ .src_node = node,
+ .payload_index = undefined,
+ } },
+ });
+ return new_index;
+ }
+
+ /// Note that this returns a `Zir.Inst.Index` not a ref.
/// Leaves the `payload_index` field undefined.
fn addCondBr(gz: *GenZir, tag: Zir.Inst.Tag, node: Ast.Node.Index) !Zir.Inst.Index {
const gpa = gz.astgen.gpa;
@@ -13122,7 +13138,8 @@ const GenZir = struct {
.fields_hash_1 = fields_hash_arr[1],
.fields_hash_2 = fields_hash_arr[2],
.fields_hash_3 = fields_hash_arr[3],
- .src_node = gz.nodeIndexToRelative(args.src_node),
+ .src_line = astgen.source_line,
+ .src_node = args.src_node,
});
if (args.captures_len != 0) {
@@ -13182,7 +13199,8 @@ const GenZir = struct {
.fields_hash_1 = fields_hash_arr[1],
.fields_hash_2 = fields_hash_arr[2],
.fields_hash_3 = fields_hash_arr[3],
- .src_node = gz.nodeIndexToRelative(args.src_node),
+ .src_line = astgen.source_line,
+ .src_node = args.src_node,
});
if (args.tag_type != .none) {
@@ -13243,7 +13261,8 @@ const GenZir = struct {
.fields_hash_1 = fields_hash_arr[1],
.fields_hash_2 = fields_hash_arr[2],
.fields_hash_3 = fields_hash_arr[3],
- .src_node = gz.nodeIndexToRelative(args.src_node),
+ .src_line = astgen.source_line,
+ .src_node = args.src_node,
});
if (args.tag_type != .none) {
@@ -13291,7 +13310,8 @@ const GenZir = struct {
try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.OpaqueDecl).Struct.fields.len + 2);
const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.OpaqueDecl{
- .src_node = gz.nodeIndexToRelative(args.src_node),
+ .src_line = astgen.source_line,
+ .src_node = args.src_node,
});
if (args.captures_len != 0) {
@@ -13902,7 +13922,7 @@ fn setDeclaration(
.has_align_linksection_addrspace = align_len != 0 or linksection_len != 0 or addrspace_len != 0,
},
};
- astgen.instructions.items(.data)[@intFromEnum(decl_inst)].pl_node.payload_index = try astgen.addExtra(extra);
+ astgen.instructions.items(.data)[@intFromEnum(decl_inst)].declaration.payload_index = try astgen.addExtra(extra);
if (extra.flags.has_doc_comment) {
try astgen.extra.append(gpa, @intFromEnum(true_doc_comment));
}
diff --git a/lib/std/zig/Zir.zig b/lib/std/zig/Zir.zig
index a79e965fe9..5dd69f9923 100644
--- a/lib/std/zig/Zir.zig
+++ b/lib/std/zig/Zir.zig
@@ -20,7 +20,6 @@ const BigIntMutable = std.math.big.int.Mutable;
const Ast = std.zig.Ast;
const Zir = @This();
-const LazySrcLoc = std.zig.LazySrcLoc;
instructions: std.MultiArrayList(Inst).Slice,
/// In order to store references to strings in fewer bytes, we copy all
@@ -287,7 +286,7 @@ pub const Inst = struct {
/// namespace type, e.g. within a `struct_decl` instruction. It represents a
/// single source declaration (`const`/`var`/`fn`), containing the name,
/// attributes, type, and value of the declaration.
- /// Uses the `pl_node` union field. Payload is `Declaration`.
+ /// Uses the `declaration` union field. Payload is `Declaration`.
declaration,
/// Implements `suspend {...}`.
/// Uses the `pl_node` union field. Payload is `Block`.
@@ -1596,7 +1595,7 @@ pub const Inst = struct {
.block = .pl_node,
.block_comptime = .pl_node,
.block_inline = .pl_node,
- .declaration = .pl_node,
+ .declaration = .declaration,
.suspend_block = .pl_node,
.bool_not = .un_node,
.bool_br_and = .pl_node,
@@ -1982,7 +1981,7 @@ pub const Inst = struct {
/// `operand` is payload index to `UnNode`.
error_from_int,
/// Implement builtin `@Type`.
- /// `operand` is payload index to `UnNode`.
+ /// `operand` is payload index to `Reify`.
/// `small` contains `NameStrategy`.
reify,
/// Implements the `@asyncCall` builtin.
@@ -2221,10 +2220,6 @@ pub const Inst = struct {
src_node: i32,
/// The meaning of this operand depends on the corresponding `Tag`.
operand: Ref,
-
- pub fn src(self: @This()) LazySrcLoc {
- return LazySrcLoc.nodeOffset(self.src_node);
- }
},
/// Used for unary operators, with a token source location.
un_tok: struct {
@@ -2232,10 +2227,6 @@ pub const Inst = struct {
src_tok: Ast.TokenIndex,
/// The meaning of this operand depends on the corresponding `Tag`.
operand: Ref,
-
- pub fn src(self: @This()) LazySrcLoc {
- return .{ .token_offset = self.src_tok };
- }
},
pl_node: struct {
/// Offset from Decl AST node index.
@@ -2244,10 +2235,6 @@ pub const Inst = struct {
/// index into extra.
/// `Tag` determines what lives there.
payload_index: u32,
-
- pub fn src(self: @This()) LazySrcLoc {
- return LazySrcLoc.nodeOffset(self.src_node);
- }
},
pl_tok: struct {
/// Offset from Decl AST token index.
@@ -2255,10 +2242,6 @@ pub const Inst = struct {
/// index into extra.
/// `Tag` determines what lives there.
payload_index: u32,
-
- pub fn src(self: @This()) LazySrcLoc {
- return .{ .token_offset = self.src_tok };
- }
},
bin: Bin,
/// For strings which may contain null bytes.
@@ -2281,10 +2264,6 @@ pub const Inst = struct {
pub fn get(self: @This(), code: Zir) [:0]const u8 {
return code.nullTerminatedString(self.start);
}
-
- pub fn src(self: @This()) LazySrcLoc {
- return .{ .token_offset = self.src_tok };
- }
},
/// Offset from Decl AST token index.
tok: Ast.TokenIndex,
@@ -2313,19 +2292,11 @@ pub const Inst = struct {
src_node: i32,
signedness: std.builtin.Signedness,
bit_count: u16,
-
- pub fn src(self: @This()) LazySrcLoc {
- return LazySrcLoc.nodeOffset(self.src_node);
- }
},
@"unreachable": struct {
/// Offset from Decl AST node index.
/// `Tag` determines which kind of AST node this points to.
src_node: i32,
-
- pub fn src(self: @This()) LazySrcLoc {
- return LazySrcLoc.nodeOffset(self.src_node);
- }
},
@"break": struct {
operand: Ref,
@@ -2339,10 +2310,6 @@ pub const Inst = struct {
src_node: i32,
/// The meaning of this operand depends on the corresponding `Tag`.
inst: Index,
-
- pub fn src(self: @This()) LazySrcLoc {
- return LazySrcLoc.nodeOffset(self.src_node);
- }
},
str_op: struct {
/// Offset into `string_bytes`. Null-terminated.
@@ -2370,6 +2337,12 @@ pub const Inst = struct {
/// The index being accessed.
idx: u32,
},
+ declaration: struct {
+ /// This node provides a new absolute baseline node for all instructions within this struct.
+ src_node: Ast.Node.Index,
+ /// index into extra to a `Declaration` payload.
+ payload_index: u32,
+ },
// Make sure we don't accidentally add a field to make this union
// bigger than expected. Note that in Debug builds, Zig is allowed
@@ -2408,6 +2381,7 @@ pub const Inst = struct {
defer_err_code,
save_err_ret_index,
elem_val_imm,
+ declaration,
};
};
@@ -2860,6 +2834,14 @@ pub const Inst = struct {
index: u32,
};
+ pub const Reify = struct {
+ /// This node is absolute, because `reify` instructions are tracked across updates, and
+ /// this simplifies the logic for getting source locations for types.
+ node: Ast.Node.Index,
+ operand: Ref,
+ src_line: u32,
+ };
+
pub const SwitchBlockErrUnion = struct {
operand: Ref,
bits: Bits,
@@ -3018,11 +3000,9 @@ pub const Inst = struct {
fields_hash_1: u32,
fields_hash_2: u32,
fields_hash_3: u32,
- src_node: i32,
-
- pub fn src(self: StructDecl) LazySrcLoc {
- return LazySrcLoc.nodeOffset(self.src_node);
- }
+ src_line: u32,
+ /// This node provides a new absolute baseline node for all instructions within this struct.
+ src_node: Ast.Node.Index,
pub const Small = packed struct {
has_captures_len: bool,
@@ -3150,11 +3130,9 @@ pub const Inst = struct {
fields_hash_1: u32,
fields_hash_2: u32,
fields_hash_3: u32,
- src_node: i32,
-
- pub fn src(self: EnumDecl) LazySrcLoc {
- return LazySrcLoc.nodeOffset(self.src_node);
- }
+ src_line: u32,
+ /// This node provides a new absolute baseline node for all instructions within this struct.
+ src_node: Ast.Node.Index,
pub const Small = packed struct {
has_tag_type: bool,
@@ -3198,11 +3176,9 @@ pub const Inst = struct {
fields_hash_1: u32,
fields_hash_2: u32,
fields_hash_3: u32,
- src_node: i32,
-
- pub fn src(self: UnionDecl) LazySrcLoc {
- return LazySrcLoc.nodeOffset(self.src_node);
- }
+ src_line: u32,
+ /// This node provides a new absolute baseline node for all instructions within this struct.
+ src_node: Ast.Node.Index,
pub const Small = packed struct {
has_tag_type: bool,
@@ -3230,11 +3206,9 @@ pub const Inst = struct {
/// 2. capture: Capture, // for every captures_len
/// 3. decl: Index, // for every decls_len; points to a `declaration` instruction
pub const OpaqueDecl = struct {
- src_node: i32,
-
- pub fn src(self: OpaqueDecl) LazySrcLoc {
- return LazySrcLoc.nodeOffset(self.src_node);
- }
+ src_line: u32,
+ /// This node provides a new absolute baseline node for all instructions within this struct.
+ src_node: Ast.Node.Index,
pub const Small = packed struct {
has_captures_len: bool,
@@ -3352,10 +3326,6 @@ pub const Inst = struct {
parent_ptr_type: Ref,
field_name: Ref,
field_ptr: Ref,
-
- pub fn src(self: FieldParentPtr) LazySrcLoc {
- return LazySrcLoc.nodeOffset(self.src_node);
- }
};
pub const Shuffle = struct {
@@ -3505,10 +3475,6 @@ pub const Inst = struct {
block: Ref,
/// If `.none`, restore unconditionally.
operand: Ref,
-
- pub fn src(self: RestoreErrRetIndex) LazySrcLoc {
- return LazySrcLoc.nodeOffset(self.src_node);
- }
};
};
@@ -3772,6 +3738,7 @@ fn findDeclsInner(
.union_decl,
.enum_decl,
.opaque_decl,
+ .reify,
=> return list.append(inst),
else => return,
@@ -4046,7 +4013,7 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo {
pub fn getDeclaration(zir: Zir, inst: Zir.Inst.Index) struct { Inst.Declaration, u32 } {
assert(zir.instructions.items(.tag)[@intFromEnum(inst)] == .declaration);
- const pl_node = zir.instructions.items(.data)[@intFromEnum(inst)].pl_node;
+ const pl_node = zir.instructions.items(.data)[@intFromEnum(inst)].declaration;
const extra = zir.extraData(Inst.Declaration, pl_node.payload_index);
return .{
extra.data,