[SIL] Extract ClassVisibility from SILFunction to SubclassScope in SILLinkage.

This commit is contained in:
Huon Wilson
2017-04-13 13:44:31 -07:00
parent 22c9e20a9d
commit b59f95418c
17 changed files with 124 additions and 116 deletions

View File

@@ -234,7 +234,7 @@ SILFunction *SILModule::getOrCreateFunction(SILLocation loc,
IsTransparent_t isTransparent,
IsSerialized_t isSerialized,
IsThunk_t isThunk,
SILFunction::ClassVisibility_t CV) {
SubclassScope subclassScope) {
if (auto fn = lookUpFunction(name)) {
assert(fn->getLoweredFunctionType() == type);
assert(fn->getLinkage() == linkage ||
@@ -244,53 +244,11 @@ SILFunction *SILModule::getOrCreateFunction(SILLocation loc,
auto fn = SILFunction::create(*this, linkage, name, type, nullptr,
loc, isBareSILFunction, isTransparent,
isSerialized, isThunk, CV);
isSerialized, isThunk, subclassScope);
fn->setDebugScope(new (*this) SILDebugScope(loc, fn));
return fn;
}
static SILFunction::ClassVisibility_t getClassVisibility(SILDeclRef constant) {
if (!constant.hasDecl())
return SILFunction::NotRelevant;
// If this declaration is a function which goes into a vtable, then it's
// symbol must be as visible as its class. Derived classes even have to put
// all less visible methods of the base class into their vtables.
auto *FD = dyn_cast<AbstractFunctionDecl>(constant.getDecl());
if (!FD)
return SILFunction::NotRelevant;
DeclContext *context = FD->getDeclContext();
// Methods from extensions don't go into vtables (yet).
if (context->isExtensionContext())
return SILFunction::NotRelevant;
auto *classType = context->getAsClassOrClassExtensionContext();
if (!classType || classType->isFinal())
return SILFunction::NotRelevant;
if (FD->isFinal() && !FD->getOverriddenDecl())
return SILFunction::NotRelevant;
assert(FD->getEffectiveAccess() <= classType->getEffectiveAccess() &&
"class must be as visible as its members");
switch (classType->getEffectiveAccess()) {
case Accessibility::Private:
case Accessibility::FilePrivate:
return SILFunction::NotRelevant;
case Accessibility::Internal:
return SILFunction::InternalClass;
case Accessibility::Public:
case Accessibility::Open:
return SILFunction::PublicClass;
}
llvm_unreachable("Unhandled Accessibility in switch.");
}
static bool verifySILSelfParameterType(SILDeclRef DeclRef,
SILFunction *F, CanSILFunctionType FTy) {
SILModule &M = F->getModule();
@@ -362,7 +320,7 @@ SILFunction *SILModule::getOrCreateFunction(SILLocation loc,
auto *F = SILFunction::create(*this, linkage, name,
constantType, nullptr,
None, IsNotBare, IsTrans, IsSer, IsNotThunk,
getClassVisibility(constant),
constant.getSubclassScope(),
inlineStrategy, EK);
F->setDebugScope(new (*this) SILDebugScope(loc, F));
@@ -413,20 +371,19 @@ SILFunction *SILModule::getOrCreateSharedFunction(SILLocation loc,
IsThunk_t isThunk) {
return getOrCreateFunction(loc, name, SILLinkage::Shared,
type, isBareSILFunction, isTransparent, isSerialized,
isThunk, SILFunction::NotRelevant);
isThunk, SubclassScope::NotApplicable);
}
SILFunction *SILModule::createFunction(
SILLinkage linkage, StringRef name, CanSILFunctionType loweredType,
GenericEnvironment *genericEnv, Optional<SILLocation> loc,
IsBare_t isBareSILFunction, IsTransparent_t isTrans,
IsSerialized_t isSerialized, IsThunk_t isThunk,
SILFunction::ClassVisibility_t classVisibility,
IsSerialized_t isSerialized, IsThunk_t isThunk, SubclassScope subclassScope,
Inline_t inlineStrategy, EffectsKind EK, SILFunction *InsertBefore,
const SILDebugScope *DebugScope) {
return SILFunction::create(*this, linkage, name, loweredType, genericEnv, loc,
isBareSILFunction, isTrans, isSerialized, isThunk,
classVisibility, inlineStrategy, EK, InsertBefore,
subclassScope, inlineStrategy, EK, InsertBefore,
DebugScope);
}