[AST] Lazily compute ProtocolDecl::getKnownProtocolKind()

Rather than eagerly doing a bunch of name lookups to establish the known
protocol kind, lazily match the ProtocolDecl to the list of known
protocols as-needed. This eliminates a bunch of up-front unqualified
name lookups when spinning up a type checker.
This commit is contained in:
Doug Gregor
2019-02-04 20:30:23 -08:00
parent 1b4b7390ba
commit d19d2f2490
6 changed files with 27 additions and 42 deletions

View File

@@ -4384,6 +4384,24 @@ void ProtocolDecl::setRequirementSignature(ArrayRef<Requirement> requirements) {
}
}
void ProtocolDecl::computeKnownProtocolKind() const {
auto module = getModuleContext();
if (module != module->getASTContext().getStdlibModule() &&
!module->getName().is("Foundation")) {
const_cast<ProtocolDecl *>(this)->Bits.ProtocolDecl.KnownProtocol = 1;
return;
}
unsigned value =
llvm::StringSwitch<unsigned>(getBaseName().userFacingName())
#define PROTOCOL_WITH_NAME(Id, Name) \
.Case(Name, static_cast<unsigned>(KnownProtocolKind::Id) + 2)
#include "swift/AST/KnownProtocols.def"
.Default(1);
const_cast<ProtocolDecl *>(this)->Bits.ProtocolDecl.KnownProtocol = value;
}
void AbstractStorageDecl::overwriteImplInfo(StorageImplInfo implInfo) {
setFieldsFromImplInfo(implInfo);
Accessors.getPointer()->overwriteImplInfo(implInfo);