aboutsummaryrefslogtreecommitdiff
path: root/src/Zcu.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-08-21 12:48:54 +0100
committerMatthew Lugg <mlugg@mlugg.co.uk>2024-08-21 16:24:57 +0100
commit7bbbbf8ffa3fa9be085cef8e8237cd94ce342483 (patch)
treeae66c4b5c90ec6593a96bda1c645b2248c59b448 /src/Zcu.zig
parent8fc15f188c0deb1b0e2847297e535823eca1d2e8 (diff)
downloadzig-7bbbbf8ffa3fa9be085cef8e8237cd94ce342483.tar.gz
zig-7bbbbf8ffa3fa9be085cef8e8237cd94ce342483.zip
compiler: fix losing ZIR instructions in main_struct_inst fields
Diffstat (limited to 'src/Zcu.zig')
-rw-r--r--src/Zcu.zig23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/Zcu.zig b/src/Zcu.zig
index 53ad80444e..9754740833 100644
--- a/src/Zcu.zig
+++ b/src/Zcu.zig
@@ -2554,18 +2554,29 @@ pub fn mapOldZirToNew(
var match_stack: std.ArrayListUnmanaged(MatchedZirDecl) = .{};
defer match_stack.deinit(gpa);
- // Main struct inst is always matched
- try match_stack.append(gpa, .{
- .old_inst = .main_struct_inst,
- .new_inst = .main_struct_inst,
- });
-
// Used as temporary buffers for namespace declaration instructions
var old_decls: std.ArrayListUnmanaged(Zir.Inst.Index) = .{};
defer old_decls.deinit(gpa);
var new_decls: std.ArrayListUnmanaged(Zir.Inst.Index) = .{};
defer new_decls.deinit(gpa);
+ // Map the main struct inst (and anything in its fields)
+ {
+ try old_zir.findDeclsRoot(gpa, &old_decls);
+ try new_zir.findDeclsRoot(gpa, &new_decls);
+
+ assert(old_decls.items[0] == .main_struct_inst);
+ assert(new_decls.items[0] == .main_struct_inst);
+
+ // We don't have any smart way of matching up these type declarations, so we always
+ // correlate them based on source order.
+ const n = @min(old_decls.items.len, new_decls.items.len);
+ try match_stack.ensureUnusedCapacity(gpa, n);
+ for (old_decls.items[0..n], new_decls.items[0..n]) |old_inst, new_inst| {
+ match_stack.appendAssumeCapacity(.{ .old_inst = old_inst, .new_inst = new_inst });
+ }
+ }
+
while (match_stack.popOrNull()) |match_item| {
// Match the namespace declaration itself
try inst_map.put(gpa, match_item.old_inst, match_item.new_inst);