AST: Remove the hack for lazily setting contextual types on VarDecls

This commit is contained in:
Slava Pestov
2016-12-15 04:08:45 -08:00
parent a384b2a677
commit 757f253a3b
2 changed files with 3 additions and 33 deletions

View File

@@ -4164,10 +4164,7 @@ protected:
/// This is the type specified, including location information. /// This is the type specified, including location information.
TypeLoc typeLoc; TypeLoc typeLoc;
mutable Type typeInContext; Type typeInContext;
/// Compute the type in context from the interface type.
Type computeTypeInContextSlow() const;
public: public:
VarDecl(bool IsStatic, bool IsLet, SourceLoc NameLoc, Identifier Name, VarDecl(bool IsStatic, bool IsLet, SourceLoc NameLoc, Identifier Name,
@@ -4190,15 +4187,13 @@ public:
bool hasType() const { bool hasType() const {
// We have a type if either the type has been computed already or if // We have a type if either the type has been computed already or if
// this is a deserialized declaration with an interface type. // this is a deserialized declaration with an interface type.
return typeInContext || return !typeInContext.isNull();
(hasInterfaceType() && !getDeclContext()->getParentSourceFile());
} }
/// Get the type of the variable within its context. If the context is generic, /// Get the type of the variable within its context. If the context is generic,
/// this will use archetypes. /// this will use archetypes.
Type getType() const { Type getType() const {
if (!typeInContext) assert(!typeInContext.isNull() && "no contextual type set yet");
return computeTypeInContextSlow();
return typeInContext; return typeInContext;
} }

View File

@@ -3428,31 +3428,6 @@ void VarDecl::setType(Type t) {
setInvalid(); setInvalid();
} }
Type VarDecl::computeTypeInContextSlow() const {
Type contextType = getInterfaceType();
if (!contextType) return Type();
// If we have a type parameter, we need to map into this context.
if (contextType->hasTypeParameter()) {
auto genericEnv =
getInnermostDeclContext()->getGenericEnvironmentOfContext();
// FIXME: Hack to degrade somewhat gracefully when we don't have a generic
// environment yet. We return an interface type, but at least we don't
// record it.
if (!genericEnv)
return contextType;
contextType = genericEnv->mapTypeIntoContext(getModuleContext(),
contextType);
}
typeInContext = contextType;
if (typeInContext->hasError())
const_cast<VarDecl *>(this)->setInvalid();
return typeInContext;
}
void VarDecl::markInvalid() { void VarDecl::markInvalid() {
auto &Ctx = getASTContext(); auto &Ctx = getASTContext();
setType(ErrorType::get(Ctx)); setType(ErrorType::get(Ctx));