Lazily compute the type of protocol declarations.

Swift SVN r7453
This commit is contained in:
Doug Gregor
2013-08-22 17:09:16 +00:00
parent 29829a23f4
commit 5034803021
8 changed files with 29 additions and 11 deletions

View File

@@ -627,7 +627,8 @@ NominalType *NominalType::get(NominalTypeDecl *D, Type Parent, const ASTContext
case DeclKind::Class:
return ClassType::get(cast<ClassDecl>(D), Parent, C);
case DeclKind::Protocol:
return D->getDeclaredType()->castTo<ProtocolType>();
assert(!Parent && "Protocols cannot have parents");
return ProtocolType::get(cast<ProtocolDecl>(D), C);
default:
llvm_unreachable("Not a nominal declaration!");
@@ -878,6 +879,14 @@ OptionalType *OptionalType::get(Type base, const ASTContext &C) {
return entry = new (C, arena) OptionalType(base, hasTypeVariable);
}
ProtocolType *ProtocolType::get(ProtocolDecl *D, const ASTContext &C) {
// If the declaration already has a type, return that.
if (D->hasType())
return D->getDeclaredType()->castTo<ProtocolType>();
return new (C, AllocationArena::Permanent) ProtocolType(D, C);
}
ProtocolType::ProtocolType(ProtocolDecl *TheDecl, const ASTContext &Ctx)
: NominalType(TypeKind::Protocol, &Ctx, TheDecl, /*Parent=*/Type(),
/*HasTypeVariable=*/false) { }