Introduce lazy computation of a BoundGenericType's substitutions.

Teach a BoundGenericType to compute its own substitutions, which
allows AST clients to create new bound generic types without the aid
of the type checker. 

This eliminates the TypeChecker::validateTypeSimple() abomination as
well as the need for the BoundGenericType AST validation step. There
is still more cleanup to do in this area.

Note that BoundGenericType::getSubstitutions() now accepts a module
parameter, which is the place from which we will look for
conformances. This is a baby step toward properly modeling the
conformances as part of the bound generic type, and is nowhere near
complete.


Swift SVN r8193
This commit is contained in:
Doug Gregor
2013-09-13 14:25:36 +00:00
parent 427a3f3024
commit 978eaab5c6
14 changed files with 28 additions and 306 deletions

View File

@@ -366,6 +366,14 @@ void Module::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) {
ArrayRef<Substitution> BoundGenericType::getSubstitutions(
Module *module,
LazyResolver *resolver) {
// FIXME: If there is no module, infer one. This is a hack for callers that
// don't have access to the module. It will have to go away once we're
// properly differentiating bound generic types based on the protocol
// conformances visible from a given module.
if (!module) {
module = getDecl()->getParentModule();
}
// If we already have a cached copy of the substitutions, return them.
auto *canon = getCanonicalType()->castTo<BoundGenericType>();
const ASTContext &ctx = canon->getASTContext();