Skip to content

Commit e276c79

Browse files
author
Zak Kent
committed
[SIL] [Immediate] Promote linkage of SILFunctions defining requested symbols
Promotes the linkage of `SILFunction`s defining requested symbols, ensuring they are emitted during IRGen.
1 parent f82fa91 commit e276c79

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

include/swift/SIL/SILModule.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,12 @@ class SILModule {
737737
return isPossiblyUsedExternally(getDeclSILLinkage(decl), isWholeModule());
738738
}
739739

740+
/// Promote the linkage of every entity in this SIL module so that they are
741+
/// externally visible. This is used to promote the linkage of private
742+
/// entities that are compiled on-demand for lazy immediate mode, as each is
743+
/// emitted into its own `SILModule`.
744+
void promoteLinkages();
745+
740746
PropertyListType &getPropertyList() { return properties; }
741747
const PropertyListType &getPropertyList() const { return properties; }
742748

lib/Immediate/SwiftMaterializationUnit.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,9 @@ LazySwiftMaterializationUnit::Create(SwiftJIT &JIT, CompilerInstance &CI) {
301301
if (Source.kind != SymbolSource::Kind::SIL) {
302302
continue;
303303
}
304-
auto Ref = Source.getSILDeclRef();
305304
const auto &SymbolName = Entry.getKey();
306-
auto Flags = llvm::JITSymbolFlags::Callable;
307-
if (Ref.getDefinitionLinkage() == SILLinkage::Public) {
308-
Flags |= llvm::JITSymbolFlags::Exported;
309-
}
305+
auto Flags =
306+
llvm::JITSymbolFlags::Callable | llvm::JITSymbolFlags::Exported;
310307
auto MangledName = mangle(SymbolName);
311308
PublicInterface[JIT.intern(MangledName)] = Flags;
312309
}
@@ -345,6 +342,12 @@ void LazySwiftMaterializationUnit::materialize(
345342
Refs.push_back(std::move(Ref));
346343
}
347344
auto SM = performASTLowering(CI, std::move(Refs));
345+
346+
// Promote linkages of SIL entities
347+
// defining requested symbols so they are
348+
// emitted during IRGen.
349+
SM->promoteLinkages();
350+
348351
runSILDiagnosticPasses(*SM);
349352
runSILLoweringPasses(*SM);
350353
auto GM = generateModule(CI, std::move(SM));

lib/SIL/IR/SILModule.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,14 @@ void SILModule::installSILRemarkStreamer() {
864864
silRemarkStreamer = SILRemarkStreamer::create(*this);
865865
}
866866

867+
void SILModule::promoteLinkages() {
868+
for (auto &Fn : functions)
869+
if (Fn.isDefinition())
870+
Fn.setLinkage(SILLinkage::Public);
871+
872+
// TODO: Promote linkage of other SIL entities
873+
}
874+
867875
bool SILModule::isStdlibModule() const {
868876
return TheSwiftModule->isStdlibModule();
869877
}

0 commit comments

Comments
 (0)