mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
AST: Remove the hack for lazily setting contextual types on VarDecls
This commit is contained in:
@@ -4164,10 +4164,7 @@ protected:
|
||||
/// This is the type specified, including location information.
|
||||
TypeLoc typeLoc;
|
||||
|
||||
mutable Type typeInContext;
|
||||
|
||||
/// Compute the type in context from the interface type.
|
||||
Type computeTypeInContextSlow() const;
|
||||
Type typeInContext;
|
||||
|
||||
public:
|
||||
VarDecl(bool IsStatic, bool IsLet, SourceLoc NameLoc, Identifier Name,
|
||||
@@ -4190,15 +4187,13 @@ public:
|
||||
bool hasType() const {
|
||||
// We have a type if either the type has been computed already or if
|
||||
// this is a deserialized declaration with an interface type.
|
||||
return typeInContext ||
|
||||
(hasInterfaceType() && !getDeclContext()->getParentSourceFile());
|
||||
return !typeInContext.isNull();
|
||||
}
|
||||
|
||||
/// Get the type of the variable within its context. If the context is generic,
|
||||
/// this will use archetypes.
|
||||
Type getType() const {
|
||||
if (!typeInContext)
|
||||
return computeTypeInContextSlow();
|
||||
assert(!typeInContext.isNull() && "no contextual type set yet");
|
||||
return typeInContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -3428,31 +3428,6 @@ void VarDecl::setType(Type t) {
|
||||
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() {
|
||||
auto &Ctx = getASTContext();
|
||||
setType(ErrorType::get(Ctx));
|
||||
|
||||
Reference in New Issue
Block a user