Skip to content

Commit 38817f7

Browse files
committed
SIL: Refactor the linker a bit
1 parent 1a66c89 commit 38817f7

File tree

4 files changed

+4
-73
lines changed

4 files changed

+4
-73
lines changed

include/swift/SIL/SILModule.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,6 @@ class SILModule {
493493
bool linkFunction(SILFunction *Fun,
494494
LinkingMode LinkAll = LinkingMode::LinkNormal);
495495

496-
/// Attempt to link a function by mangled name. Returns true if linking
497-
/// succeeded, false otherwise.
498-
///
499-
/// \return false if the linking failed.
500-
bool linkFunction(StringRef Name,
501-
LinkingMode LinkAll = LinkingMode::LinkNormal);
502-
503496
/// Check if a given function exists in any of the modules with a
504497
/// required linkage, i.e. it can be linked by linkFunction.
505498
///

lib/SIL/Linker.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -56,49 +56,6 @@ bool SILLinkerVisitor::processFunction(SILFunction *F) {
5656
return true;
5757
}
5858

59-
/// Process Decl, recursively deserializing any thing Decl may reference.
60-
bool SILLinkerVisitor::processFunction(StringRef Name) {
61-
if (Mode == LinkingMode::LinkNone)
62-
return false;
63-
64-
// If F is a declaration, first deserialize it.
65-
auto *NewFn = Loader->lookupSILFunction(Name);
66-
67-
if (!NewFn || NewFn->isExternalDeclaration())
68-
return false;
69-
70-
++NumFuncLinked;
71-
72-
// Try to transitively deserialize everything referenced by NewFn.
73-
Worklist.push_back(NewFn);
74-
process();
75-
76-
// Since we successfully processed at least one function, return true.
77-
return true;
78-
}
79-
80-
/// Process Decl, recursively deserializing any thing Decl may reference.
81-
SILFunction *SILLinkerVisitor::lookupFunction(StringRef Name,
82-
SILLinkage Linkage) {
83-
84-
auto *NewFn = Loader->lookupSILFunction(Name, /* declarationOnly */ true,
85-
Linkage);
86-
87-
if (!NewFn)
88-
return nullptr;
89-
90-
assert(NewFn->isExternalDeclaration() &&
91-
"SIL function lookup should never read function bodies");
92-
93-
return NewFn;
94-
}
95-
96-
/// Process Decl, recursively deserializing any thing Decl may reference.
97-
bool SILLinkerVisitor::hasFunction(StringRef Name,
98-
Optional<SILLinkage> Linkage) {
99-
return Loader->hasSILFunction(Name, Linkage);
100-
}
101-
10259
/// Deserialize the VTable mapped to C if it exists and all SIL the VTable
10360
/// transitively references.
10461
///

lib/SIL/Linker.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ class SILLinkerVisitor : public SILInstructionVisitor<SILLinkerVisitor, bool> {
5050
/// Process F, recursively deserializing any thing F may reference.
5151
bool processFunction(SILFunction *F);
5252

53-
/// Process Name, recursively deserializing any thing function with name Name
54-
/// may reference.
55-
bool processFunction(StringRef Name);
56-
57-
/// Process Name, try to deserialize a declaration of a function with
58-
/// this Name.
59-
SILFunction *lookupFunction(StringRef Name, SILLinkage Linkage);
60-
61-
/// Process Name, try to check if there is a declaration of a function
62-
/// with this Name.
63-
bool hasFunction(StringRef Name, Optional<SILLinkage> Linkage = None);
64-
6553
/// Deserialize the VTable mapped to C if it exists and all SIL the VTable
6654
/// transitively references.
6755
///

lib/SIL/SILModule.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,6 @@ bool SILModule::linkFunction(SILFunction *Fun, SILModule::LinkingMode Mode) {
476476
return SILLinkerVisitor(*this, getSILLoader(), Mode).processFunction(Fun);
477477
}
478478

479-
bool SILModule::linkFunction(StringRef Name, SILModule::LinkingMode Mode) {
480-
return SILLinkerVisitor(*this, getSILLoader(), Mode).processFunction(Name);
481-
}
482-
483479
SILFunction *SILModule::findFunction(StringRef Name, SILLinkage Linkage) {
484480
assert((Linkage == SILLinkage::Public ||
485481
Linkage == SILLinkage::PublicExternal) &&
@@ -502,14 +498,12 @@ SILFunction *SILModule::findFunction(StringRef Name, SILLinkage Linkage) {
502498
}
503499

504500
if (!F) {
505-
SILLinkerVisitor Visitor(*this, getSILLoader(),
506-
SILModule::LinkingMode::LinkNormal);
507501
if (CurF) {
508502
// Perform this lookup only if a function with a given
509503
// name is present in the current module.
510504
// This is done to reduce the amount of IO from the
511505
// swift module file.
512-
if (!Visitor.hasFunction(Name, Linkage))
506+
if (!getSILLoader()->hasSILFunction(Name, Linkage))
513507
return nullptr;
514508
// The function in the current module will be changed.
515509
F = CurF;
@@ -519,7 +513,8 @@ SILFunction *SILModule::findFunction(StringRef Name, SILLinkage Linkage) {
519513
// or if it is known to exist, perform a lookup.
520514
if (!F) {
521515
// Try to load the function from other modules.
522-
F = Visitor.lookupFunction(Name, Linkage);
516+
F = getSILLoader()->lookupSILFunction(Name, /*declarationOnly*/ true,
517+
Linkage);
523518
// Bail if nothing was found and we are not sure if
524519
// this function exists elsewhere.
525520
if (!F)
@@ -545,9 +540,7 @@ SILFunction *SILModule::findFunction(StringRef Name, SILLinkage Linkage) {
545540
bool SILModule::hasFunction(StringRef Name) {
546541
if (lookUpFunction(Name))
547542
return true;
548-
SILLinkerVisitor Visitor(*this, getSILLoader(),
549-
SILModule::LinkingMode::LinkNormal);
550-
return Visitor.hasFunction(Name);
543+
return getSILLoader()->hasSILFunction(Name);
551544
}
552545

553546
void SILModule::linkAllFromCurrentModule() {

0 commit comments

Comments
 (0)