Skip to content

IRGen: handle static imports in deserialised modules #37775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/swift/SIL/SILFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ class SILFunction
/// The function's effects attribute.
unsigned EffectsKindAttr : NumEffectsKindBits;

/// The function is in a statically linked module.
unsigned IsStaticallyLinked : 1;

static void
validateSubclassScope(SubclassScope scope, IsThunk_t isThunk,
const GenericSpecializationInformation *genericInfo) {
Expand Down Expand Up @@ -534,6 +537,12 @@ class SILFunction
WasDeserializedCanonical = val;
}

bool isStaticallyLinked() const { return IsStaticallyLinked; }

void setIsStaticallyLinked(bool value) {
IsStaticallyLinked = value;
}

/// Returns true if this is a reabstraction thunk of escaping function type
/// whose single argument is a potentially non-escaping closure. i.e. the
/// thunks' function argument may itself have @inout_aliasable parameters.
Expand Down
11 changes: 9 additions & 2 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2055,13 +2055,20 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
const LinkEntity &entity,
ForDefinition_t isDefinition) {
LinkInfo result;
entity.mangle(result.Name);

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

entity.mangle(result.Name);
bool weakImported = entity.isWeakImported(swiftModule);
result.IRL = getIRLinkage(linkInfo, entity.getLinkage(isDefinition),
isDefinition, weakImported, isKnownLocal);
Expand Down
1 change: 1 addition & 0 deletions lib/SIL/IR/SILFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ void SILFunction::init(SILLinkage Linkage, StringRef Name,
this->Zombie = false;
this->HasOwnership = true,
this->WasDeserializedCanonical = false;
this->IsStaticallyLinked = false;
this->IsWithoutActuallyEscapingThunk = false;
this->OptMode = unsigned(OptimizationMode::NotSet);
this->EffectsKindAttr = unsigned(E);
Expand Down
4 changes: 4 additions & 0 deletions lib/Serialization/DeserializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ SILDeserializer::readSILFunctionChecked(DeclID FID, SILFunction *existingFn,
if (getFile()->getParentModule() == SILMod.getSwiftModule())
fn->setLinkage(linkage);

if (getFile()->getParentModule()->isStaticLibrary() ||
getFile()->getParentModule() == SILMod.getSwiftModule())
fn->setIsStaticallyLinked(true);

// Don't override the transparency or linkage of a function with
// an existing declaration, except if we deserialized a
// PublicNonABI function, which has HiddenExternal when
Expand Down