From 7c4793f23c971f5305c63f1b343e7f8576f32781 Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 8 Mar 2024 10:59:32 +0000 Subject: [PATCH] Zcu: remove old decls after scanning namespace --- src/Module.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Module.zig b/src/Module.zig index 01aa6702e0..f17232c674 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4103,6 +4103,21 @@ pub fn scanNamespace( for (decls) |decl_inst| { try scanDecl(&scan_decl_iter, decl_inst); } + + if (seen_decls.count() != namespace.decls.count()) { + // Do a pass over the namespace contents and remove any decls from the last update + // which were removed in this one. + var i: usize = 0; + while (i < namespace.decls.count()) { + const decl_index = namespace.decls.keys()[i]; + const decl = zcu.declPtr(decl_index); + if (!seen_decls.contains(decl.name)) { + // We must preserve namespace ordering for @typeInfo. + namespace.decls.orderedRemoveAt(i); + i -= 1; + } + } + } } const ScanDeclIter = struct {