| author | |
| committer | |
| log | 1e91ee1e05f08013e3a4edec5d9f0aef978f3f0b |
| tree | 92f1353ae14a77d14b11897cd9c48484b63bd9c3 |
| parent | 7f4bd247c7735ccf277c9bba42222e014cacf856 |
| signature |
Also add corresponding invaidation logic to Zcu. Therefore, the only
invalidation logic which is not yet in place is `decl_val` dependencies.7 files changed, 283 insertions(+), 34 deletions(-)
lib/std/zig.zig+3-2| ... | @@ -27,11 +27,12 @@ pub const parseNumberLiteral = number_literal.parseNumberLiteral; | ... | @@ -27,11 +27,12 @@ pub const parseNumberLiteral = number_literal.parseNumberLiteral; |
| 27 | pub const c_builtins = @import("zig/c_builtins.zig"); | 27 | pub const c_builtins = @import("zig/c_builtins.zig"); |
| 28 | pub const c_translation = @import("zig/c_translation.zig"); | 28 | pub const c_translation = @import("zig/c_translation.zig"); |
| 29 | 29 | ||
| 30 | pub const SrcHasher = std.crypto.hash.Blake3; | ||
| 30 | pub const SrcHash = [16]u8; | 31 | pub const SrcHash = [16]u8; |
| 31 | 32 | ||
| 32 | pub fn hashSrc(src: []const u8) SrcHash { | 33 | pub fn hashSrc(src: []const u8) SrcHash { |
| 33 | var out: SrcHash = undefined; | 34 | var out: SrcHash = undefined; |
| 34 | std.crypto.hash.Blake3.hash(src, &out, .{}); | 35 | SrcHasher.hash(src, &out, .{}); |
| 35 | return out; | 36 | return out; |
| 36 | } | 37 | } |
| 37 | 38 | ||
| ... | @@ -41,7 +42,7 @@ pub fn srcHashEql(a: SrcHash, b: SrcHash) bool { | ... | @@ -41,7 +42,7 @@ pub fn srcHashEql(a: SrcHash, b: SrcHash) bool { |
| 41 | 42 | ||
| 42 | pub fn hashName(parent_hash: SrcHash, sep: []const u8, name: []const u8) SrcHash { | 43 | pub fn hashName(parent_hash: SrcHash, sep: []const u8, name: []const u8) SrcHash { |
| 43 | var out: SrcHash = undefined; | 44 | var out: SrcHash = undefined; |
| 44 | var hasher = std.crypto.hash.Blake3.init(.{}); | 45 | var hasher = SrcHasher.init(.{}); |
| 45 | hasher.update(&parent_hash); | 46 | hasher.update(&parent_hash); |
| 46 | hasher.update(sep); | 47 | hasher.update(sep); |
| 47 | hasher.update(name); | 48 | hasher.update(name); |
src/AstGen.zig+93-16| ... | @@ -4815,6 +4815,7 @@ fn structDeclInner( | ... | @@ -4815,6 +4815,7 @@ fn structDeclInner( |
| 4815 | .any_comptime_fields = false, | 4815 | .any_comptime_fields = false, |
| 4816 | .any_default_inits = false, | 4816 | .any_default_inits = false, |
| 4817 | .any_aligned_fields = false, | 4817 | .any_aligned_fields = false, |
| 4818 | .fields_hash = std.zig.hashSrc(@tagName(layout)), | ||
| 4818 | }); | 4819 | }); |
| 4819 | return decl_inst.toRef(); | 4820 | return decl_inst.toRef(); |
| 4820 | } | 4821 | } |
| ... | @@ -4936,6 +4937,12 @@ fn structDeclInner( | ... | @@ -4936,6 +4937,12 @@ fn structDeclInner( |
| 4936 | } | 4937 | } |
| 4937 | }; | 4938 | }; |
| 4938 | 4939 | ||
| 4940 | var fields_hasher = std.zig.SrcHasher.init(.{}); | ||
| 4941 | fields_hasher.update(@tagName(layout)); | ||
| 4942 | if (backing_int_node != 0) { | ||
| 4943 | fields_hasher.update(tree.getNodeSource(backing_int_node)); | ||
| 4944 | } | ||
| 4945 | |||
| 4939 | var sfba = std.heap.stackFallback(256, astgen.arena); | 4946 | var sfba = std.heap.stackFallback(256, astgen.arena); |
| 4940 | const sfba_allocator = sfba.get(); | 4947 | const sfba_allocator = sfba.get(); |
| 4941 | 4948 | ||
| ... | @@ -4956,6 +4963,8 @@ fn structDeclInner( | ... | @@ -4956,6 +4963,8 @@ fn structDeclInner( |
| 4956 | .field => |field| field, | 4963 | .field => |field| field, |
| 4957 | }; | 4964 | }; |
| 4958 | 4965 | ||
| 4966 | fields_hasher.update(tree.getNodeSource(member_node)); | ||
| 4967 | |||
| 4959 | if (!is_tuple) { | 4968 | if (!is_tuple) { |
| 4960 | const field_name = try astgen.identAsString(member.ast.main_token); | 4969 | const field_name = try astgen.identAsString(member.ast.main_token); |
| 4961 | 4970 | ||
| ... | @@ -5083,6 +5092,9 @@ fn structDeclInner( | ... | @@ -5083,6 +5092,9 @@ fn structDeclInner( |
| 5083 | return error.AnalysisFail; | 5092 | return error.AnalysisFail; |
| 5084 | } | 5093 | } |
| 5085 | 5094 | ||
| 5095 | var fields_hash: std.zig.SrcHash = undefined; | ||
| 5096 | fields_hasher.final(&fields_hash); | ||
| 5097 | |||
| 5086 | try gz.setStruct(decl_inst, .{ | 5098 | try gz.setStruct(decl_inst, .{ |
| 5087 | .src_node = node, | 5099 | .src_node = node, |
| 5088 | .layout = layout, | 5100 | .layout = layout, |
| ... | @@ -5096,6 +5108,7 @@ fn structDeclInner( | ... | @@ -5096,6 +5108,7 @@ fn structDeclInner( |
| 5096 | .any_comptime_fields = any_comptime_fields, | 5108 | .any_comptime_fields = any_comptime_fields, |
| 5097 | .any_default_inits = any_default_inits, | 5109 | .any_default_inits = any_default_inits, |
| 5098 | .any_aligned_fields = any_aligned_fields, | 5110 | .any_aligned_fields = any_aligned_fields, |
| 5111 | .fields_hash = fields_hash, | ||
| 5099 | }); | 5112 | }); |
| 5100 | 5113 | ||
| 5101 | wip_members.finishBits(bits_per_field); | 5114 | wip_members.finishBits(bits_per_field); |
| ... | @@ -5174,6 +5187,13 @@ fn unionDeclInner( | ... | @@ -5174,6 +5187,13 @@ fn unionDeclInner( |
| 5174 | var wip_members = try WipMembers.init(gpa, &astgen.scratch, decl_count, field_count, bits_per_field, max_field_size); | 5187 | var wip_members = try WipMembers.init(gpa, &astgen.scratch, decl_count, field_count, bits_per_field, max_field_size); |
| 5175 | defer wip_members.deinit(); | 5188 | defer wip_members.deinit(); |
| 5176 | 5189 | ||
| 5190 | var fields_hasher = std.zig.SrcHasher.init(.{}); | ||
| 5191 | fields_hasher.update(@tagName(layout)); | ||
| 5192 | fields_hasher.update(&.{@intFromBool(auto_enum_tok != null)}); | ||
| 5193 | if (arg_node != 0) { | ||
| 5194 | fields_hasher.update(astgen.tree.getNodeSource(arg_node)); | ||
| 5195 | } | ||
| 5196 | |||
| 5177 | var sfba = std.heap.stackFallback(256, astgen.arena); | 5197 | var sfba = std.heap.stackFallback(256, astgen.arena); |
| 5178 | const sfba_allocator = sfba.get(); | 5198 | const sfba_allocator = sfba.get(); |
| 5179 | 5199 | ||
| ... | @@ -5188,6 +5208,7 @@ fn unionDeclInner( | ... | @@ -5188,6 +5208,7 @@ fn unionDeclInner( |
| 5188 | .decl => continue, | 5208 | .decl => continue, |
| 5189 | .field => |field| field, | 5209 | .field => |field| field, |
| 5190 | }; | 5210 | }; |
| 5211 | fields_hasher.update(astgen.tree.getNodeSource(member_node)); | ||
| 5191 | member.convertToNonTupleLike(astgen.tree.nodes); | 5212 | member.convertToNonTupleLike(astgen.tree.nodes); |
| 5192 | if (member.ast.tuple_like) { | 5213 | if (member.ast.tuple_like) { |
| 5193 | return astgen.failTok(member.ast.main_token, "union field missing name", .{}); | 5214 | return astgen.failTok(member.ast.main_token, "union field missing name", .{}); |
| ... | @@ -5289,6 +5310,9 @@ fn unionDeclInner( | ... | @@ -5289,6 +5310,9 @@ fn unionDeclInner( |
| 5289 | return error.AnalysisFail; | 5310 | return error.AnalysisFail; |
| 5290 | } | 5311 | } |
| 5291 | 5312 | ||
| 5313 | var fields_hash: std.zig.SrcHash = undefined; | ||
| 5314 | fields_hasher.final(&fields_hash); | ||
| 5315 | |||
| 5292 | if (!block_scope.isEmpty()) { | 5316 | if (!block_scope.isEmpty()) { |
| 5293 | _ = try block_scope.addBreak(.break_inline, decl_inst, .void_value); | 5317 | _ = try block_scope.addBreak(.break_inline, decl_inst, .void_value); |
| 5294 | } | 5318 | } |
| ... | @@ -5305,6 +5329,7 @@ fn unionDeclInner( | ... | @@ -5305,6 +5329,7 @@ fn unionDeclInner( |
| 5305 | .decls_len = decl_count, | 5329 | .decls_len = decl_count, |
| 5306 | .auto_enum_tag = auto_enum_tok != null, | 5330 | .auto_enum_tag = auto_enum_tok != null, |
| 5307 | .any_aligned_fields = any_aligned_fields, | 5331 | .any_aligned_fields = any_aligned_fields, |
| 5332 | .fields_hash = fields_hash, | ||
| 5308 | }); | 5333 | }); |
| 5309 | 5334 | ||
| 5310 | wip_members.finishBits(bits_per_field); | 5335 | wip_members.finishBits(bits_per_field); |
| ... | @@ -5498,6 +5523,12 @@ fn containerDecl( | ... | @@ -5498,6 +5523,12 @@ fn containerDecl( |
| 5498 | var wip_members = try WipMembers.init(gpa, &astgen.scratch, @intCast(counts.decls), @intCast(counts.total_fields), bits_per_field, max_field_size); | 5523 | var wip_members = try WipMembers.init(gpa, &astgen.scratch, @intCast(counts.decls), @intCast(counts.total_fields), bits_per_field, max_field_size); |
| 5499 | defer wip_members.deinit(); | 5524 | defer wip_members.deinit(); |
| 5500 | 5525 | ||
| 5526 | var fields_hasher = std.zig.SrcHasher.init(.{}); | ||
| 5527 | if (container_decl.ast.arg != 0) { | ||
| 5528 | fields_hasher.update(tree.getNodeSource(container_decl.ast.arg)); | ||
| 5529 | } | ||
| 5530 | fields_hasher.update(&.{@intFromBool(nonexhaustive)}); | ||
| 5531 | |||
| 5501 | var sfba = std.heap.stackFallback(256, astgen.arena); | 5532 | var sfba = std.heap.stackFallback(256, astgen.arena); |
| 5502 | const sfba_allocator = sfba.get(); | 5533 | const sfba_allocator = sfba.get(); |
| 5503 | 5534 | ||
| ... | @@ -5510,6 +5541,7 @@ fn containerDecl( | ... | @@ -5510,6 +5541,7 @@ fn containerDecl( |
| 5510 | for (container_decl.ast.members) |member_node| { | 5541 | for (container_decl.ast.members) |member_node| { |
| 5511 | if (member_node == counts.nonexhaustive_node) | 5542 | if (member_node == counts.nonexhaustive_node) |
| 5512 | continue; | 5543 | continue; |
| 5544 | fields_hasher.update(tree.getNodeSource(member_node)); | ||
| 5513 | namespace.base.tag = .namespace; | 5545 | namespace.base.tag = .namespace; |
| 5514 | var member = switch (try containerMember(&block_scope, &namespace.base, &wip_members, member_node)) { | 5546 | var member = switch (try containerMember(&block_scope, &namespace.base, &wip_members, member_node)) { |
| 5515 | .decl => continue, | 5547 | .decl => continue, |
| ... | @@ -5590,6 +5622,9 @@ fn containerDecl( | ... | @@ -5590,6 +5622,9 @@ fn containerDecl( |
| 5590 | _ = try block_scope.addBreak(.break_inline, decl_inst, .void_value); | 5622 | _ = try block_scope.addBreak(.break_inline, decl_inst, .void_value); |
| 5591 | } | 5623 | } |
| 5592 | 5624 | ||
| 5625 | var fields_hash: std.zig.SrcHash = undefined; | ||
| 5626 | fields_hasher.final(&fields_hash); | ||
| 5627 | |||
| 5593 | const body = block_scope.instructionsSlice(); | 5628 | const body = block_scope.instructionsSlice(); |
| 5594 | const body_len = astgen.countBodyLenAfterFixups(body); | 5629 | const body_len = astgen.countBodyLenAfterFixups(body); |
| 5595 | 5630 | ||
| ... | @@ -5600,6 +5635,7 @@ fn containerDecl( | ... | @@ -5600,6 +5635,7 @@ fn containerDecl( |
| 5600 | .body_len = body_len, | 5635 | .body_len = body_len, |
| 5601 | .fields_len = @intCast(counts.total_fields), | 5636 | .fields_len = @intCast(counts.total_fields), |
| 5602 | .decls_len = @intCast(counts.decls), | 5637 | .decls_len = @intCast(counts.decls), |
| 5638 | .fields_hash = fields_hash, | ||
| 5603 | }); | 5639 | }); |
| 5604 | 5640 | ||
| 5605 | wip_members.finishBits(bits_per_field); | 5641 | wip_members.finishBits(bits_per_field); |
| ... | @@ -11900,8 +11936,8 @@ const GenZir = struct { | ... | @@ -11900,8 +11936,8 @@ const GenZir = struct { |
| 11900 | 11936 | ||
| 11901 | var body: []Zir.Inst.Index = &[0]Zir.Inst.Index{}; | 11937 | var body: []Zir.Inst.Index = &[0]Zir.Inst.Index{}; |
| 11902 | var ret_body: []Zir.Inst.Index = &[0]Zir.Inst.Index{}; | 11938 | var ret_body: []Zir.Inst.Index = &[0]Zir.Inst.Index{}; |
| 11903 | var src_locs_buffer: [3]u32 = undefined; | 11939 | var src_locs_and_hash_buffer: [7]u32 = undefined; |
| 11904 | var src_locs: []u32 = src_locs_buffer[0..0]; | 11940 | var src_locs_and_hash: []u32 = src_locs_and_hash_buffer[0..0]; |
| 11905 | if (args.body_gz) |body_gz| { | 11941 | if (args.body_gz) |body_gz| { |
| 11906 | const tree = astgen.tree; | 11942 | const tree = astgen.tree; |
| 11907 | const node_tags = tree.nodes.items(.tag); | 11943 | const node_tags = tree.nodes.items(.tag); |
| ... | @@ -11916,10 +11952,27 @@ const GenZir = struct { | ... | @@ -11916,10 +11952,27 @@ const GenZir = struct { |
| 11916 | const rbrace_column: u32 = @intCast(astgen.source_column); | 11952 | const rbrace_column: u32 = @intCast(astgen.source_column); |
| 11917 | 11953 | ||
| 11918 | const columns = args.lbrace_column | (rbrace_column << 16); | 11954 | const columns = args.lbrace_column | (rbrace_column << 16); |
| 11919 | src_locs_buffer[0] = args.lbrace_line; | 11955 | |
| 11920 | src_locs_buffer[1] = rbrace_line; | 11956 | const proto_hash: std.zig.SrcHash = switch (node_tags[fn_decl]) { |
| 11921 | src_locs_buffer[2] = columns; | 11957 | .fn_decl => sig_hash: { |
| 11922 | src_locs = &src_locs_buffer; | 11958 | const proto_node = node_datas[fn_decl].lhs; |
| 11959 | break :sig_hash std.zig.hashSrc(tree.getNodeSource(proto_node)); | ||
| 11960 | }, | ||
| 11961 | .test_decl => std.zig.hashSrc(""), // tests don't have a prototype | ||
| 11962 | else => unreachable, | ||
| 11963 | }; | ||
| 11964 | const proto_hash_arr: [4]u32 = @bitCast(proto_hash); | ||
| 11965 | |||
| 11966 | src_locs_and_hash_buffer = .{ | ||
| 11967 | args.lbrace_line, | ||
| 11968 | rbrace_line, | ||
| 11969 | columns, | ||
| 11970 | proto_hash_arr[0], | ||
| 11971 | proto_hash_arr[1], | ||
| 11972 | proto_hash_arr[2], | ||
| 11973 | proto_hash_arr[3], | ||
| 11974 | }; | ||
| 11975 | src_locs_and_hash = &src_locs_and_hash_buffer; | ||
| 11923 | 11976 | ||
| 11924 | body = body_gz.instructionsSlice(); | 11977 | body = body_gz.instructionsSlice(); |
| 11925 | if (args.ret_gz) |ret_gz| | 11978 | if (args.ret_gz) |ret_gz| |
| ... | @@ -11953,7 +12006,7 @@ const GenZir = struct { | ... | @@ -11953,7 +12006,7 @@ const GenZir = struct { |
| 11953 | fancyFnExprExtraLen(astgen, section_body, args.section_ref) + | 12006 | fancyFnExprExtraLen(astgen, section_body, args.section_ref) + |
| 11954 | fancyFnExprExtraLen(astgen, cc_body, args.cc_ref) + | 12007 | fancyFnExprExtraLen(astgen, cc_body, args.cc_ref) + |
| 11955 | fancyFnExprExtraLen(astgen, ret_body, ret_ref) + | 12008 | fancyFnExprExtraLen(astgen, ret_body, ret_ref) + |
| 11956 | body_len + src_locs.len + | 12009 | body_len + src_locs_and_hash.len + |
| 11957 | @intFromBool(args.lib_name != .empty) + | 12010 | @intFromBool(args.lib_name != .empty) + |
| 11958 | @intFromBool(args.noalias_bits != 0), | 12011 | @intFromBool(args.noalias_bits != 0), |
| 11959 | ); | 12012 | ); |
| ... | @@ -12040,7 +12093,7 @@ const GenZir = struct { | ... | @@ -12040,7 +12093,7 @@ const GenZir = struct { |
| 12040 | } | 12093 | } |
| 12041 | 12094 | ||
| 12042 | astgen.appendBodyWithFixups(body); | 12095 | astgen.appendBodyWithFixups(body); |
| 12043 | astgen.extra.appendSliceAssumeCapacity(src_locs); | 12096 | astgen.extra.appendSliceAssumeCapacity(src_locs_and_hash); |
| 12044 | 12097 | ||
| 12045 | // Order is important when unstacking. | 12098 | // Order is important when unstacking. |
| 12046 | if (args.body_gz) |body_gz| body_gz.unstack(); | 12099 | if (args.body_gz) |body_gz| body_gz.unstack(); |
| ... | @@ -12068,7 +12121,7 @@ const GenZir = struct { | ... | @@ -12068,7 +12121,7 @@ const GenZir = struct { |
| 12068 | gpa, | 12121 | gpa, |
| 12069 | @typeInfo(Zir.Inst.Func).Struct.fields.len + 1 + | 12122 | @typeInfo(Zir.Inst.Func).Struct.fields.len + 1 + |
| 12070 | fancyFnExprExtraLen(astgen, ret_body, ret_ref) + | 12123 | fancyFnExprExtraLen(astgen, ret_body, ret_ref) + |
| 12071 | body_len + src_locs.len, | 12124 | body_len + src_locs_and_hash.len, |
| 12072 | ); | 12125 | ); |
| 12073 | 12126 | ||
| 12074 | const ret_body_len = if (ret_body.len != 0) | 12127 | const ret_body_len = if (ret_body.len != 0) |
| ... | @@ -12092,7 +12145,7 @@ const GenZir = struct { | ... | @@ -12092,7 +12145,7 @@ const GenZir = struct { |
| 12092 | astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref)); | 12145 | astgen.extra.appendAssumeCapacity(@intFromEnum(ret_ref)); |
| 12093 | } | 12146 | } |
| 12094 | astgen.appendBodyWithFixups(body); | 12147 | astgen.appendBodyWithFixups(body); |
| 12095 | astgen.extra.appendSliceAssumeCapacity(src_locs); | 12148 | astgen.extra.appendSliceAssumeCapacity(src_locs_and_hash); |
| 12096 | 12149 | ||
| 12097 | // Order is important when unstacking. | 12150 | // Order is important when unstacking. |
| 12098 | if (args.body_gz) |body_gz| body_gz.unstack(); | 12151 | if (args.body_gz) |body_gz| body_gz.unstack(); |
| ... | @@ -12853,12 +12906,20 @@ const GenZir = struct { | ... | @@ -12853,12 +12906,20 @@ const GenZir = struct { |
| 12853 | any_comptime_fields: bool, | 12906 | any_comptime_fields: bool, |
| 12854 | any_default_inits: bool, | 12907 | any_default_inits: bool, |
| 12855 | any_aligned_fields: bool, | 12908 | any_aligned_fields: bool, |
| 12909 | fields_hash: std.zig.SrcHash, | ||
| 12856 | }) !void { | 12910 | }) !void { |
| 12857 | const astgen = gz.astgen; | 12911 | const astgen = gz.astgen; |
| 12858 | const gpa = astgen.gpa; | 12912 | const gpa = astgen.gpa; |
| 12859 | 12913 | ||
| 12860 | try astgen.extra.ensureUnusedCapacity(gpa, 6); | 12914 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); |
| 12861 | const payload_index: u32 = @intCast(astgen.extra.items.len); | 12915 | |
| 12916 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.StructDecl).Struct.fields.len + 6); | ||
| 12917 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.StructDecl{ | ||
| 12918 | .fields_hash_0 = fields_hash_arr[0], | ||
| 12919 | .fields_hash_1 = fields_hash_arr[1], | ||
| 12920 | .fields_hash_2 = fields_hash_arr[2], | ||
| 12921 | .fields_hash_3 = fields_hash_arr[3], | ||
| 12922 | }); | ||
| 12862 | 12923 | ||
| 12863 | if (args.src_node != 0) { | 12924 | if (args.src_node != 0) { |
| 12864 | const node_offset = gz.nodeIndexToRelative(args.src_node); | 12925 | const node_offset = gz.nodeIndexToRelative(args.src_node); |
| ... | @@ -12908,12 +12969,20 @@ const GenZir = struct { | ... | @@ -12908,12 +12969,20 @@ const GenZir = struct { |
| 12908 | layout: std.builtin.Type.ContainerLayout, | 12969 | layout: std.builtin.Type.ContainerLayout, |
| 12909 | auto_enum_tag: bool, | 12970 | auto_enum_tag: bool, |
| 12910 | any_aligned_fields: bool, | 12971 | any_aligned_fields: bool, |
| 12972 | fields_hash: std.zig.SrcHash, | ||
| 12911 | }) !void { | 12973 | }) !void { |
| 12912 | const astgen = gz.astgen; | 12974 | const astgen = gz.astgen; |
| 12913 | const gpa = astgen.gpa; | 12975 | const gpa = astgen.gpa; |
| 12914 | 12976 | ||
| 12915 | try astgen.extra.ensureUnusedCapacity(gpa, 5); | 12977 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); |
| 12916 | const payload_index: u32 = @intCast(astgen.extra.items.len); | 12978 | |
| 12979 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len + 5); | ||
| 12980 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.UnionDecl{ | ||
| 12981 | .fields_hash_0 = fields_hash_arr[0], | ||
| 12982 | .fields_hash_1 = fields_hash_arr[1], | ||
| 12983 | .fields_hash_2 = fields_hash_arr[2], | ||
| 12984 | .fields_hash_3 = fields_hash_arr[3], | ||
| 12985 | }); | ||
| 12917 | 12986 | ||
| 12918 | if (args.src_node != 0) { | 12987 | if (args.src_node != 0) { |
| 12919 | const node_offset = gz.nodeIndexToRelative(args.src_node); | 12988 | const node_offset = gz.nodeIndexToRelative(args.src_node); |
| ... | @@ -12958,12 +13027,20 @@ const GenZir = struct { | ... | @@ -12958,12 +13027,20 @@ const GenZir = struct { |
| 12958 | fields_len: u32, | 13027 | fields_len: u32, |
| 12959 | decls_len: u32, | 13028 | decls_len: u32, |
| 12960 | nonexhaustive: bool, | 13029 | nonexhaustive: bool, |
| 13030 | fields_hash: std.zig.SrcHash, | ||
| 12961 | }) !void { | 13031 | }) !void { |
| 12962 | const astgen = gz.astgen; | 13032 | const astgen = gz.astgen; |
| 12963 | const gpa = astgen.gpa; | 13033 | const gpa = astgen.gpa; |
| 12964 | 13034 | ||
| 12965 | try astgen.extra.ensureUnusedCapacity(gpa, 5); | 13035 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); |
| 12966 | const payload_index: u32 = @intCast(astgen.extra.items.len); | 13036 | |
| 13037 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.EnumDecl).Struct.fields.len + 5); | ||
| 13038 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.EnumDecl{ | ||
| 13039 | .fields_hash_0 = fields_hash_arr[0], | ||
| 13040 | .fields_hash_1 = fields_hash_arr[1], | ||
| 13041 | .fields_hash_2 = fields_hash_arr[2], | ||
| 13042 | .fields_hash_3 = fields_hash_arr[3], | ||
| 13043 | }); | ||
| 12967 | 13044 | ||
| 12968 | if (args.src_node != 0) { | 13045 | if (args.src_node != 0) { |
| 12969 | const node_offset = gz.nodeIndexToRelative(args.src_node); | 13046 | const node_offset = gz.nodeIndexToRelative(args.src_node); |
src/Autodoc.zig+3-3| ... | @@ -3497,7 +3497,7 @@ fn walkInstruction( | ... | @@ -3497,7 +3497,7 @@ fn walkInstruction( |
| 3497 | }; | 3497 | }; |
| 3498 | 3498 | ||
| 3499 | const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small)); | 3499 | const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small)); |
| 3500 | var extra_index: usize = extended.operand; | 3500 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; |
| 3501 | 3501 | ||
| 3502 | const src_node: ?i32 = if (small.has_src_node) blk: { | 3502 | const src_node: ?i32 = if (small.has_src_node) blk: { |
| 3503 | const src_node = @as(i32, @bitCast(file.zir.extra[extra_index])); | 3503 | const src_node = @as(i32, @bitCast(file.zir.extra[extra_index])); |
| ... | @@ -3627,7 +3627,7 @@ fn walkInstruction( | ... | @@ -3627,7 +3627,7 @@ fn walkInstruction( |
| 3627 | }; | 3627 | }; |
| 3628 | 3628 | ||
| 3629 | const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small)); | 3629 | const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small)); |
| 3630 | var extra_index: usize = extended.operand; | 3630 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.EnumDecl).Struct.fields.len; |
| 3631 | 3631 | ||
| 3632 | const src_node: ?i32 = if (small.has_src_node) blk: { | 3632 | const src_node: ?i32 = if (small.has_src_node) blk: { |
| 3633 | const src_node = @as(i32, @bitCast(file.zir.extra[extra_index])); | 3633 | const src_node = @as(i32, @bitCast(file.zir.extra[extra_index])); |
| ... | @@ -3778,7 +3778,7 @@ fn walkInstruction( | ... | @@ -3778,7 +3778,7 @@ fn walkInstruction( |
| 3778 | }; | 3778 | }; |
| 3779 | 3779 | ||
| 3780 | const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small)); | 3780 | const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small)); |
| 3781 | var extra_index: usize = extended.operand; | 3781 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; |
| 3782 | 3782 | ||
| 3783 | const src_node: ?i32 = if (small.has_src_node) blk: { | 3783 | const src_node: ?i32 = if (small.has_src_node) blk: { |
| 3784 | const src_node = @as(i32, @bitCast(file.zir.extra[extra_index])); | 3784 | const src_node = @as(i32, @bitCast(file.zir.extra[extra_index])); |
src/Module.zig+12| ... | @@ -2957,6 +2957,18 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void { | ... | @@ -2957,6 +2957,18 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void { |
| 2957 | continue; | 2957 | continue; |
| 2958 | }; | 2958 | }; |
| 2959 | 2959 | ||
| 2960 | if (old_zir.getAssociatedSrcHash(old_inst)) |old_hash| hash_changed: { | ||
| 2961 | if (new_zir.getAssociatedSrcHash(ti.inst)) |new_hash| { | ||
| 2962 | if (std.zig.srcHashEql(old_hash, new_hash)) { | ||
| 2963 | break :hash_changed; | ||
| 2964 | } | ||
| 2965 | } | ||
| 2966 | // The source hash associated with this instruction changed - invalidate relevant dependencies. | ||
| 2967 | zcu.comp.mutex.lock(); | ||
| 2968 | defer zcu.comp.mutex.unlock(); | ||
| 2969 | try zcu.markDependeeOutdated(.{ .src_hash = ti_idx }); | ||
| 2970 | } | ||
| 2971 | |||
| 2960 | // If this is a `struct_decl` etc, we must invalidate any outdated namespace dependencies. | 2972 | // If this is a `struct_decl` etc, we must invalidate any outdated namespace dependencies. |
| 2961 | const has_namespace = switch (old_tag[@intFromEnum(old_inst)]) { | 2973 | const has_namespace = switch (old_tag[@intFromEnum(old_inst)]) { |
| 2962 | .extended => switch (old_data[@intFromEnum(old_inst)].extended.opcode) { | 2974 | .extended => switch (old_data[@intFromEnum(old_inst)].extended.opcode) { |
src/Sema.zig+7-7| ... | @@ -2718,7 +2718,7 @@ pub fn getStructType( | ... | @@ -2718,7 +2718,7 @@ pub fn getStructType( |
| 2718 | assert(extended.opcode == .struct_decl); | 2718 | assert(extended.opcode == .struct_decl); |
| 2719 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 2719 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2720 | 2720 | ||
| 2721 | var extra_index: usize = extended.operand; | 2721 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; |
| 2722 | extra_index += @intFromBool(small.has_src_node); | 2722 | extra_index += @intFromBool(small.has_src_node); |
| 2723 | const fields_len = if (small.has_fields_len) blk: { | 2723 | const fields_len = if (small.has_fields_len) blk: { |
| 2724 | const fields_len = sema.code.extra[extra_index]; | 2724 | const fields_len = sema.code.extra[extra_index]; |
| ... | @@ -2773,7 +2773,7 @@ fn zirStructDecl( | ... | @@ -2773,7 +2773,7 @@ fn zirStructDecl( |
| 2773 | const ip = &mod.intern_pool; | 2773 | const ip = &mod.intern_pool; |
| 2774 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 2774 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2775 | const src: LazySrcLoc = if (small.has_src_node) blk: { | 2775 | const src: LazySrcLoc = if (small.has_src_node) blk: { |
| 2776 | const node_offset: i32 = @bitCast(sema.code.extra[extended.operand]); | 2776 | const node_offset: i32 = @bitCast(sema.code.extra[extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len]); |
| 2777 | break :blk LazySrcLoc.nodeOffset(node_offset); | 2777 | break :blk LazySrcLoc.nodeOffset(node_offset); |
| 2778 | } else sema.src; | 2778 | } else sema.src; |
| 2779 | 2779 | ||
| ... | @@ -2933,7 +2933,7 @@ fn zirEnumDecl( | ... | @@ -2933,7 +2933,7 @@ fn zirEnumDecl( |
| 2933 | const mod = sema.mod; | 2933 | const mod = sema.mod; |
| 2934 | const gpa = sema.gpa; | 2934 | const gpa = sema.gpa; |
| 2935 | const small: Zir.Inst.EnumDecl.Small = @bitCast(extended.small); | 2935 | const small: Zir.Inst.EnumDecl.Small = @bitCast(extended.small); |
| 2936 | var extra_index: usize = extended.operand; | 2936 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.EnumDecl).Struct.fields.len; |
| 2937 | 2937 | ||
| 2938 | const src: LazySrcLoc = if (small.has_src_node) blk: { | 2938 | const src: LazySrcLoc = if (small.has_src_node) blk: { |
| 2939 | const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); | 2939 | const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); |
| ... | @@ -3204,7 +3204,7 @@ fn zirUnionDecl( | ... | @@ -3204,7 +3204,7 @@ fn zirUnionDecl( |
| 3204 | const mod = sema.mod; | 3204 | const mod = sema.mod; |
| 3205 | const gpa = sema.gpa; | 3205 | const gpa = sema.gpa; |
| 3206 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); | 3206 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); |
| 3207 | var extra_index: usize = extended.operand; | 3207 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; |
| 3208 | 3208 | ||
| 3209 | const src: LazySrcLoc = if (small.has_src_node) blk: { | 3209 | const src: LazySrcLoc = if (small.has_src_node) blk: { |
| 3210 | const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); | 3210 | const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); |
| ... | @@ -35742,7 +35742,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp | ... | @@ -35742,7 +35742,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp |
| 35742 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 35742 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 35743 | 35743 | ||
| 35744 | if (small.has_backing_int) { | 35744 | if (small.has_backing_int) { |
| 35745 | var extra_index: usize = extended.operand; | 35745 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; |
| 35746 | extra_index += @intFromBool(small.has_src_node); | 35746 | extra_index += @intFromBool(small.has_src_node); |
| 35747 | extra_index += @intFromBool(small.has_fields_len); | 35747 | extra_index += @intFromBool(small.has_fields_len); |
| 35748 | extra_index += @intFromBool(small.has_decls_len); | 35748 | extra_index += @intFromBool(small.has_decls_len); |
| ... | @@ -36457,7 +36457,7 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct { | ... | @@ -36457,7 +36457,7 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct { |
| 36457 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; | 36457 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; |
| 36458 | assert(extended.opcode == .struct_decl); | 36458 | assert(extended.opcode == .struct_decl); |
| 36459 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 36459 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 36460 | var extra_index: usize = extended.operand; | 36460 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len; |
| 36461 | 36461 | ||
| 36462 | extra_index += @intFromBool(small.has_src_node); | 36462 | extra_index += @intFromBool(small.has_src_node); |
| 36463 | 36463 | ||
| ... | @@ -36925,7 +36925,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -36925,7 +36925,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 36925 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; | 36925 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; |
| 36926 | assert(extended.opcode == .union_decl); | 36926 | assert(extended.opcode == .union_decl); |
| 36927 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); | 36927 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); |
| 36928 | var extra_index: usize = extended.operand; | 36928 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; |
| 36929 | 36929 | ||
| 36930 | const src = LazySrcLoc.nodeOffset(0); | 36930 | const src = LazySrcLoc.nodeOffset(0); |
| 36931 | extra_index += @intFromBool(small.has_src_node); | 36931 | extra_index += @intFromBool(small.has_src_node); |
src/Zir.zig+131-3| ... | @@ -2497,6 +2497,7 @@ pub const Inst = struct { | ... | @@ -2497,6 +2497,7 @@ pub const Inst = struct { |
| 2497 | /// } | 2497 | /// } |
| 2498 | /// 2. body: Index // for each body_len | 2498 | /// 2. body: Index // for each body_len |
| 2499 | /// 3. src_locs: SrcLocs // if body_len != 0 | 2499 | /// 3. src_locs: SrcLocs // if body_len != 0 |
| 2500 | /// 4. proto_hash: std.zig.SrcHash // if body_len != 0; hash of function prototype | ||
| 2500 | pub const Func = struct { | 2501 | pub const Func = struct { |
| 2501 | /// If this is 0 it means a void return type. | 2502 | /// If this is 0 it means a void return type. |
| 2502 | /// If this is 1 it means return_type is a simple Ref | 2503 | /// If this is 1 it means return_type is a simple Ref |
| ... | @@ -2558,6 +2559,7 @@ pub const Inst = struct { | ... | @@ -2558,6 +2559,7 @@ pub const Inst = struct { |
| 2558 | /// - each bit starting with LSB corresponds to parameter indexes | 2559 | /// - each bit starting with LSB corresponds to parameter indexes |
| 2559 | /// 17. body: Index // for each body_len | 2560 | /// 17. body: Index // for each body_len |
| 2560 | /// 18. src_locs: Func.SrcLocs // if body_len != 0 | 2561 | /// 18. src_locs: Func.SrcLocs // if body_len != 0 |
| 2562 | /// 19. proto_hash: std.zig.SrcHash // if body_len != 0; hash of function prototype | ||
| 2561 | pub const FuncFancy = struct { | 2563 | pub const FuncFancy = struct { |
| 2562 | /// Points to the block that contains the param instructions for this function. | 2564 | /// Points to the block that contains the param instructions for this function. |
| 2563 | /// If this is a `declaration`, it refers to the declaration's value body. | 2565 | /// If this is a `declaration`, it refers to the declaration's value body. |
| ... | @@ -3040,6 +3042,12 @@ pub const Inst = struct { | ... | @@ -3040,6 +3042,12 @@ pub const Inst = struct { |
| 3040 | /// init_body_inst: Inst, // for each init_body_len | 3042 | /// init_body_inst: Inst, // for each init_body_len |
| 3041 | /// } | 3043 | /// } |
| 3042 | pub const StructDecl = struct { | 3044 | pub const StructDecl = struct { |
| 3045 | // These fields should be concatenated and reinterpreted as a `std.zig.SrcHash`. | ||
| 3046 | // This hash contains the source of all fields, and any specified attributes (`extern`, backing type, etc). | ||
| 3047 | fields_hash_0: u32, | ||
| 3048 | fields_hash_1: u32, | ||
| 3049 | fields_hash_2: u32, | ||
| 3050 | fields_hash_3: u32, | ||
| 3043 | pub const Small = packed struct { | 3051 | pub const Small = packed struct { |
| 3044 | has_src_node: bool, | 3052 | has_src_node: bool, |
| 3045 | has_fields_len: bool, | 3053 | has_fields_len: bool, |
| ... | @@ -3102,6 +3110,12 @@ pub const Inst = struct { | ... | @@ -3102,6 +3110,12 @@ pub const Inst = struct { |
| 3102 | /// value: Ref, // if corresponding bit is set | 3110 | /// value: Ref, // if corresponding bit is set |
| 3103 | /// } | 3111 | /// } |
| 3104 | pub const EnumDecl = struct { | 3112 | pub const EnumDecl = struct { |
| 3113 | // These fields should be concatenated and reinterpreted as a `std.zig.SrcHash`. | ||
| 3114 | // This hash contains the source of all fields, and the backing type if specified. | ||
| 3115 | fields_hash_0: u32, | ||
| 3116 | fields_hash_1: u32, | ||
| 3117 | fields_hash_2: u32, | ||
| 3118 | fields_hash_3: u32, | ||
| 3105 | pub const Small = packed struct { | 3119 | pub const Small = packed struct { |
| 3106 | has_src_node: bool, | 3120 | has_src_node: bool, |
| 3107 | has_tag_type: bool, | 3121 | has_tag_type: bool, |
| ... | @@ -3137,6 +3151,12 @@ pub const Inst = struct { | ... | @@ -3137,6 +3151,12 @@ pub const Inst = struct { |
| 3137 | /// tag_value: Ref, // if corresponding bit is set | 3151 | /// tag_value: Ref, // if corresponding bit is set |
| 3138 | /// } | 3152 | /// } |
| 3139 | pub const UnionDecl = struct { | 3153 | pub const UnionDecl = struct { |
| 3154 | // These fields should be concatenated and reinterpreted as a `std.zig.SrcHash`. | ||
| 3155 | // This hash contains the source of all fields, and any specified attributes (`extern` etc). | ||
| 3156 | fields_hash_0: u32, | ||
| 3157 | fields_hash_1: u32, | ||
| 3158 | fields_hash_2: u32, | ||
| 3159 | fields_hash_3: u32, | ||
| 3140 | pub const Small = packed struct { | 3160 | pub const Small = packed struct { |
| 3141 | has_src_node: bool, | 3161 | has_src_node: bool, |
| 3142 | has_tag_type: bool, | 3162 | has_tag_type: bool, |
| ... | @@ -3455,7 +3475,7 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { | ... | @@ -3455,7 +3475,7 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { |
| 3455 | switch (extended.opcode) { | 3475 | switch (extended.opcode) { |
| 3456 | .struct_decl => { | 3476 | .struct_decl => { |
| 3457 | const small: Inst.StructDecl.Small = @bitCast(extended.small); | 3477 | const small: Inst.StructDecl.Small = @bitCast(extended.small); |
| 3458 | var extra_index: u32 = extended.operand; | 3478 | var extra_index: u32 = @intCast(extended.operand + @typeInfo(Inst.StructDecl).Struct.fields.len); |
| 3459 | extra_index += @intFromBool(small.has_src_node); | 3479 | extra_index += @intFromBool(small.has_src_node); |
| 3460 | extra_index += @intFromBool(small.has_fields_len); | 3480 | extra_index += @intFromBool(small.has_fields_len); |
| 3461 | const decls_len = if (small.has_decls_len) decls_len: { | 3481 | const decls_len = if (small.has_decls_len) decls_len: { |
| ... | @@ -3482,7 +3502,7 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { | ... | @@ -3482,7 +3502,7 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { |
| 3482 | }, | 3502 | }, |
| 3483 | .enum_decl => { | 3503 | .enum_decl => { |
| 3484 | const small: Inst.EnumDecl.Small = @bitCast(extended.small); | 3504 | const small: Inst.EnumDecl.Small = @bitCast(extended.small); |
| 3485 | var extra_index: u32 = extended.operand; | 3505 | var extra_index: u32 = @intCast(extended.operand + @typeInfo(Inst.EnumDecl).Struct.fields.len); |
| 3486 | extra_index += @intFromBool(small.has_src_node); | 3506 | extra_index += @intFromBool(small.has_src_node); |
| 3487 | extra_index += @intFromBool(small.has_tag_type); | 3507 | extra_index += @intFromBool(small.has_tag_type); |
| 3488 | extra_index += @intFromBool(small.has_body_len); | 3508 | extra_index += @intFromBool(small.has_body_len); |
| ... | @@ -3501,7 +3521,7 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { | ... | @@ -3501,7 +3521,7 @@ pub fn declIterator(zir: Zir, decl_inst: Zir.Inst.Index) DeclIterator { |
| 3501 | }, | 3521 | }, |
| 3502 | .union_decl => { | 3522 | .union_decl => { |
| 3503 | const small: Inst.UnionDecl.Small = @bitCast(extended.small); | 3523 | const small: Inst.UnionDecl.Small = @bitCast(extended.small); |
| 3504 | var extra_index: u32 = extended.operand; | 3524 | var extra_index: u32 = @intCast(extended.operand + @typeInfo(Inst.UnionDecl).Struct.fields.len); |
| 3505 | extra_index += @intFromBool(small.has_src_node); | 3525 | extra_index += @intFromBool(small.has_src_node); |
| 3506 | extra_index += @intFromBool(small.has_tag_type); | 3526 | extra_index += @intFromBool(small.has_tag_type); |
| 3507 | extra_index += @intFromBool(small.has_body_len); | 3527 | extra_index += @intFromBool(small.has_body_len); |
| ... | @@ -3938,3 +3958,111 @@ pub fn getDeclaration(zir: Zir, inst: Zir.Inst.Index) struct { Inst.Declaration, | ... | @@ -3938,3 +3958,111 @@ pub fn getDeclaration(zir: Zir, inst: Zir.Inst.Index) struct { Inst.Declaration, |
| 3938 | @intCast(extra.end), | 3958 | @intCast(extra.end), |
| 3939 | }; | 3959 | }; |
| 3940 | } | 3960 | } |
| 3961 | |||
| 3962 | pub fn getAssociatedSrcHash(zir: Zir, inst: Zir.Inst.Index) ?std.zig.SrcHash { | ||
| 3963 | const tag = zir.instructions.items(.tag); | ||
| 3964 | const data = zir.instructions.items(.data); | ||
| 3965 | switch (tag[@intFromEnum(inst)]) { | ||
| 3966 | .declaration => { | ||
| 3967 | const pl_node = data[@intFromEnum(inst)].pl_node; | ||
| 3968 | const extra = zir.extraData(Inst.Declaration, pl_node.payload_index); | ||
| 3969 | return @bitCast([4]u32{ | ||
| 3970 | extra.data.src_hash_0, | ||
| 3971 | extra.data.src_hash_1, | ||
| 3972 | extra.data.src_hash_2, | ||
| 3973 | extra.data.src_hash_3, | ||
| 3974 | }); | ||
| 3975 | }, | ||
| 3976 | .func, .func_inferred => { | ||
| 3977 | const pl_node = data[@intFromEnum(inst)].pl_node; | ||
| 3978 | const extra = zir.extraData(Inst.Func, pl_node.payload_index); | ||
| 3979 | if (extra.data.body_len == 0) { | ||
| 3980 | // Function type or extern fn - no associated hash | ||
| 3981 | return null; | ||
| 3982 | } | ||
| 3983 | const extra_index = extra.end + | ||
| 3984 | 1 + | ||
| 3985 | extra.data.body_len + | ||
| 3986 | @typeInfo(Inst.Func.SrcLocs).Struct.fields.len; | ||
| 3987 | return @bitCast([4]u32{ | ||
| 3988 | zir.extra[extra_index + 0], | ||
| 3989 | zir.extra[extra_index + 1], | ||
| 3990 | zir.extra[extra_index + 2], | ||
| 3991 | zir.extra[extra_index + 3], | ||
| 3992 | }); | ||
| 3993 | }, | ||
| 3994 | .func_fancy => { | ||
| 3995 | const pl_node = data[@intFromEnum(inst)].pl_node; | ||
| 3996 | const extra = zir.extraData(Inst.FuncFancy, pl_node.payload_index); | ||
| 3997 | if (extra.data.body_len == 0) { | ||
| 3998 | // Function type or extern fn - no associated hash | ||
| 3999 | return null; | ||
| 4000 | } | ||
| 4001 | const bits = extra.data.bits; | ||
| 4002 | var extra_index = extra.end; | ||
| 4003 | extra_index += @intFromBool(bits.has_lib_name); | ||
| 4004 | if (bits.has_align_body) { | ||
| 4005 | const body_len = zir.extra[extra_index]; | ||
| 4006 | extra_index += 1 + body_len; | ||
| 4007 | } else extra_index += @intFromBool(bits.has_align_ref); | ||
| 4008 | if (bits.has_addrspace_body) { | ||
| 4009 | const body_len = zir.extra[extra_index]; | ||
| 4010 | extra_index += 1 + body_len; | ||
| 4011 | } else extra_index += @intFromBool(bits.has_addrspace_ref); | ||
| 4012 | if (bits.has_section_body) { | ||
| 4013 | const body_len = zir.extra[extra_index]; | ||
| 4014 | extra_index += 1 + body_len; | ||
| 4015 | } else extra_index += @intFromBool(bits.has_section_ref); | ||
| 4016 | if (bits.has_cc_body) { | ||
| 4017 | const body_len = zir.extra[extra_index]; | ||
| 4018 | extra_index += 1 + body_len; | ||
| 4019 | } else extra_index += @intFromBool(bits.has_cc_ref); | ||
| 4020 | if (bits.has_ret_ty_body) { | ||
| 4021 | const body_len = zir.extra[extra_index]; | ||
| 4022 | extra_index += 1 + body_len; | ||
| 4023 | } else extra_index += @intFromBool(bits.has_ret_ty_ref); | ||
| 4024 | extra_index += @intFromBool(bits.has_any_noalias); | ||
| 4025 | extra_index += extra.data.body_len; | ||
| 4026 | extra_index += @typeInfo(Zir.Inst.Func.SrcLocs).Struct.fields.len; | ||
| 4027 | return @bitCast([4]u32{ | ||
| 4028 | zir.extra[extra_index + 0], | ||
| 4029 | zir.extra[extra_index + 1], | ||
| 4030 | zir.extra[extra_index + 2], | ||
| 4031 | zir.extra[extra_index + 3], | ||
| 4032 | }); | ||
| 4033 | }, | ||
| 4034 | .extended => {}, | ||
| 4035 | else => return null, | ||
| 4036 | } | ||
| 4037 | const extended = data[@intFromEnum(inst)].extended; | ||
| 4038 | switch (extended.opcode) { | ||
| 4039 | .struct_decl => { | ||
| 4040 | const extra = zir.extraData(Inst.StructDecl, extended.operand).data; | ||
| 4041 | return @bitCast([4]u32{ | ||
| 4042 | extra.fields_hash_0, | ||
| 4043 | extra.fields_hash_1, | ||
| 4044 | extra.fields_hash_2, | ||
| 4045 | extra.fields_hash_3, | ||
| 4046 | }); | ||
| 4047 | }, | ||
| 4048 | .union_decl => { | ||
| 4049 | const extra = zir.extraData(Inst.UnionDecl, extended.operand).data; | ||
| 4050 | return @bitCast([4]u32{ | ||
| 4051 | extra.fields_hash_0, | ||
| 4052 | extra.fields_hash_1, | ||
| 4053 | extra.fields_hash_2, | ||
| 4054 | extra.fields_hash_3, | ||
| 4055 | }); | ||
| 4056 | }, | ||
| 4057 | .enum_decl => { | ||
| 4058 | const extra = zir.extraData(Inst.EnumDecl, extended.operand).data; | ||
| 4059 | return @bitCast([4]u32{ | ||
| 4060 | extra.fields_hash_0, | ||
| 4061 | extra.fields_hash_1, | ||
| 4062 | extra.fields_hash_2, | ||
| 4063 | extra.fields_hash_3, | ||
| 4064 | }); | ||
| 4065 | }, | ||
| 4066 | else => return null, | ||
| 4067 | } | ||
| 4068 | } |
src/print_zir.zig+34-3| ... | @@ -1401,7 +1401,17 @@ const Writer = struct { | ... | @@ -1401,7 +1401,17 @@ const Writer = struct { |
| 1401 | fn writeStructDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { | 1401 | fn writeStructDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { |
| 1402 | const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small)); | 1402 | const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small)); |
| 1403 | 1403 | ||
| 1404 | var extra_index: usize = extended.operand; | 1404 | const extra = self.code.extraData(Zir.Inst.StructDecl, extended.operand); |
| 1405 | const fields_hash: std.zig.SrcHash = @bitCast([4]u32{ | ||
| 1406 | extra.data.fields_hash_0, | ||
| 1407 | extra.data.fields_hash_1, | ||
| 1408 | extra.data.fields_hash_2, | ||
| 1409 | extra.data.fields_hash_3, | ||
| 1410 | }); | ||
| 1411 | |||
| 1412 | try stream.print("hash({}) ", .{std.fmt.fmtSliceHexLower(&fields_hash)}); | ||
| 1413 | |||
| 1414 | var extra_index: usize = extra.end; | ||
| 1405 | 1415 | ||
| 1406 | const src_node: ?i32 = if (small.has_src_node) blk: { | 1416 | const src_node: ?i32 = if (small.has_src_node) blk: { |
| 1407 | const src_node = @as(i32, @bitCast(self.code.extra[extra_index])); | 1417 | const src_node = @as(i32, @bitCast(self.code.extra[extra_index])); |
| ... | @@ -1591,7 +1601,17 @@ const Writer = struct { | ... | @@ -1591,7 +1601,17 @@ const Writer = struct { |
| 1591 | fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { | 1601 | fn writeUnionDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { |
| 1592 | const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small)); | 1602 | const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small)); |
| 1593 | 1603 | ||
| 1594 | var extra_index: usize = extended.operand; | 1604 | const extra = self.code.extraData(Zir.Inst.UnionDecl, extended.operand); |
| 1605 | const fields_hash: std.zig.SrcHash = @bitCast([4]u32{ | ||
| 1606 | extra.data.fields_hash_0, | ||
| 1607 | extra.data.fields_hash_1, | ||
| 1608 | extra.data.fields_hash_2, | ||
| 1609 | extra.data.fields_hash_3, | ||
| 1610 | }); | ||
| 1611 | |||
| 1612 | try stream.print("hash({}) ", .{std.fmt.fmtSliceHexLower(&fields_hash)}); | ||
| 1613 | |||
| 1614 | var extra_index: usize = extra.end; | ||
| 1595 | 1615 | ||
| 1596 | const src_node: ?i32 = if (small.has_src_node) blk: { | 1616 | const src_node: ?i32 = if (small.has_src_node) blk: { |
| 1597 | const src_node = @as(i32, @bitCast(self.code.extra[extra_index])); | 1617 | const src_node = @as(i32, @bitCast(self.code.extra[extra_index])); |
| ... | @@ -1733,7 +1753,18 @@ const Writer = struct { | ... | @@ -1733,7 +1753,18 @@ const Writer = struct { |
| 1733 | 1753 | ||
| 1734 | fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { | 1754 | fn writeEnumDecl(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { |
| 1735 | const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small)); | 1755 | const small = @as(Zir.Inst.EnumDecl.Small, @bitCast(extended.small)); |
| 1736 | var extra_index: usize = extended.operand; | 1756 | |
| 1757 | const extra = self.code.extraData(Zir.Inst.EnumDecl, extended.operand); | ||
| 1758 | const fields_hash: std.zig.SrcHash = @bitCast([4]u32{ | ||
| 1759 | extra.data.fields_hash_0, | ||
| 1760 | extra.data.fields_hash_1, | ||
| 1761 | extra.data.fields_hash_2, | ||
| 1762 | extra.data.fields_hash_3, | ||
| 1763 | }); | ||
| 1764 | |||
| 1765 | try stream.print("hash({}) ", .{std.fmt.fmtSliceHexLower(&fields_hash)}); | ||
| 1766 | |||
| 1767 | var extra_index: usize = extra.end; | ||
| 1737 | 1768 | ||
| 1738 | const src_node: ?i32 = if (small.has_src_node) blk: { | 1769 | const src_node: ?i32 = if (small.has_src_node) blk: { |
| 1739 | const src_node = @as(i32, @bitCast(self.code.extra[extra_index])); | 1770 | const src_node = @as(i32, @bitCast(self.code.extra[extra_index])); |