Don't record the declared type of nominal type decls within the module file.

Instead, compute the type just after we load the nominal type
declaration. This centralizes the type-computation code better as
well.


Swift SVN r7454
This commit is contained in:
Doug Gregor
2013-08-22 17:33:24 +00:00
parent 5034803021
commit 2e91172d4f
10 changed files with 44 additions and 116 deletions

View File

@@ -626,9 +626,14 @@ NominalType *NominalType::get(NominalTypeDecl *D, Type Parent, const ASTContext
return StructType::get(cast<StructDecl>(D), Parent, C);
case DeclKind::Class:
return ClassType::get(cast<ClassDecl>(D), Parent, C);
case DeclKind::Protocol:
case DeclKind::Protocol: {
assert(!Parent && "Protocols cannot have parents");
return ProtocolType::get(cast<ProtocolDecl>(D), C);
auto proto = cast<ProtocolDecl>(D);
if (!proto->hasType())
proto->computeType();
return proto->getDeclaredType()->castTo<ProtocolType>();
}
default:
llvm_unreachable("Not a nominal declaration!");
@@ -879,14 +884,6 @@ 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) { }