Enable elimination of dead methods which are in classes of higher visibility.

The underlying problem is that e.g. even if a method is private but its class is public, the method can be referenced from another module - from the vtable of a derived class.
So far we handled this by setting the SILLinkage of such methods according to the visibility of the class. But this prevented dead method elimination.
Now I set the SILLinkage according to the visibility of the method. This enables dead method elimination, but it requires the following:
1) Still set the linkage in llvm so that it can be referenced from outside.
2) If the method is dead and eliminated, create a stub for it (which calls swift_reportMissingMethod).



Swift SVN r23889
This commit is contained in:
Erik Eckstein
2014-12-12 17:35:40 +00:00
parent fcc6738d6a
commit 14af3a57e8
21 changed files with 236 additions and 67 deletions

View File

@@ -32,6 +32,7 @@ SILFunction *SILFunction::create(SILModule &M, SILLinkage linkage,
IsBare_t isBareSILFunction,
IsTransparent_t isTrans,
IsFragile_t isFragile,
ClassVisibility_t classVisibility,
Inline_t inlineStrategy, EffectsKind E,
SILFunction *insertBefore,
SILDebugScope *debugScope,
@@ -48,7 +49,8 @@ SILFunction *SILFunction::create(SILModule &M, SILLinkage linkage,
auto fn = new (M) SILFunction(M, linkage, name,
loweredType, contextGenericParams, loc,
isBareSILFunction, isTrans, isFragile,
inlineStrategy, E, insertBefore, debugScope, DC);
classVisibility, inlineStrategy, E,
insertBefore, debugScope, DC);
if (entry) entry->setValue(fn);
return fn;
@@ -61,6 +63,7 @@ SILFunction::SILFunction(SILModule &Module, SILLinkage Linkage,
IsBare_t isBareSILFunction,
IsTransparent_t isTrans,
IsFragile_t isFragile,
ClassVisibility_t classVisibility,
Inline_t inlineStrategy, EffectsKind E,
SILFunction *InsertBefore,
SILDebugScope *DebugScope,
@@ -76,9 +79,11 @@ SILFunction::SILFunction(SILModule &Module, SILLinkage Linkage,
Bare(isBareSILFunction),
Transparent(isTrans),
Fragile(isFragile),
ClassVisibility(classVisibility),
GlobalInitFlag(false),
InlineStrategy(inlineStrategy),
Linkage(unsigned(Linkage)), EK(E), State(InlineState::NotInlined) {
Linkage(unsigned(Linkage)),
EK(E) {
if (InsertBefore)
Module.functions.insert(SILModule::iterator(InsertBefore), this);
else
@@ -422,3 +427,9 @@ SILFunction::isPossiblyUsedExternally() const {
return swift::isPossiblyUsedExternally(getLinkage(),
getModule().isWholeModule());
}
bool SILFunction::isExternallyUsedSymbol() const {
return swift::isPossiblyUsedExternally(getEffectiveSymbolLinkage(),
getModule().isWholeModule());
}