Skip to content

Commit 50fa6cf

Browse files
authored
Merge pull request #37775 from compnerd/static-deserialization
IRGen: handle static imports in deserialised modules
2 parents 0eeaec1 + 1f39610 commit 50fa6cf

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

include/swift/SIL/SILFunction.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ class SILFunction
320320
/// The function's effects attribute.
321321
unsigned EffectsKindAttr : NumEffectsKindBits;
322322

323+
/// The function is in a statically linked module.
324+
unsigned IsStaticallyLinked : 1;
325+
323326
static void
324327
validateSubclassScope(SubclassScope scope, IsThunk_t isThunk,
325328
const GenericSpecializationInformation *genericInfo) {
@@ -543,6 +546,12 @@ class SILFunction
543546
WasDeserializedCanonical = val;
544547
}
545548

549+
bool isStaticallyLinked() const { return IsStaticallyLinked; }
550+
551+
void setIsStaticallyLinked(bool value) {
552+
IsStaticallyLinked = value;
553+
}
554+
546555
/// Returns true if this is a reabstraction thunk of escaping function type
547556
/// whose single argument is a potentially non-escaping closure. i.e. the
548557
/// thunks' function argument may itself have @inout_aliasable parameters.

lib/IRGen/GenDecl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,13 +2055,20 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
20552055
const LinkEntity &entity,
20562056
ForDefinition_t isDefinition) {
20572057
LinkInfo result;
2058+
entity.mangle(result.Name);
20582059

20592060
bool isKnownLocal = entity.isAlwaysSharedLinkage();
2060-
if (const auto *DC = entity.getDeclContextForEmission())
2061+
if (const auto *DC = entity.getDeclContextForEmission()) {
20612062
if (const auto *MD = DC->getParentModule())
20622063
isKnownLocal = MD == swiftModule || MD->isStaticLibrary();
2064+
} else if (entity.hasSILFunction()) {
2065+
// SIL serialized entitites (functions, witness tables, vtables) do not have
2066+
// an associated DeclContext and are serialized into the current module. As
2067+
// a result, we explicitly handle SIL Functions here. We do not expect other
2068+
// types to be referenced directly.
2069+
isKnownLocal = entity.getSILFunction()->isStaticallyLinked();
2070+
}
20632071

2064-
entity.mangle(result.Name);
20652072
bool weakImported = entity.isWeakImported(swiftModule);
20662073
result.IRL = getIRLinkage(linkInfo, entity.getLinkage(isDefinition),
20672074
isDefinition, weakImported, isKnownLocal);

lib/SIL/IR/SILFunction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ void SILFunction::init(SILLinkage Linkage, StringRef Name,
182182
this->Zombie = false;
183183
this->HasOwnership = true,
184184
this->WasDeserializedCanonical = false;
185+
this->IsStaticallyLinked = false;
185186
this->IsWithoutActuallyEscapingThunk = false;
186187
this->OptMode = unsigned(OptimizationMode::NotSet);
187188
this->EffectsKindAttr = unsigned(E);

lib/Serialization/DeserializeSIL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
613613
if (getFile()->getParentModule() == SILMod.getSwiftModule())
614614
fn->setLinkage(linkage);
615615

616+
if (getFile()->getParentModule()->isStaticLibrary() ||
617+
getFile()->getParentModule() == SILMod.getSwiftModule())
618+
fn->setIsStaticallyLinked(true);
619+
616620
// Don't override the transparency or linkage of a function with
617621
// an existing declaration, except if we deserialized a
618622
// PublicNonABI function, which has HiddenExternal when

0 commit comments

Comments
 (0)