From da170e7e8e6a21278641b0db18955be93dba6d9a Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Tue, 19 May 2026 16:04:32 -0700 Subject: [PATCH] [Embedded] Only emit global variables from another module if they are @used --- lib/IRGen/GenDecl.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index d3a8bd179f8..d7128d2c91b 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -1169,11 +1169,10 @@ static bool isLazilyEmittedFunction(SILFunction &f, SILModule &m) { // Eagerly emit global variables that are externally visible. static bool isLazilyEmittedGlobalVariable(SILGlobalVariable &v, SILModule &m) { if (v.isPossiblyUsedExternally()) { - // Under the embedded linkage model, if it has a non-unique definition, - // treat it lazily. - if (v.hasNonUniqueDefinition() && !v.markedAsUsed()) { + // Globals that come from a different module will be lazily emitted unless + // explicitly marked @used. + if (v.getParentModule() != m.getSwiftModule() && !v.markedAsUsed()) return true; - } return false; }