Skip to content

Commit 757f253

Browse files
committed
AST: Remove the hack for lazily setting contextual types on VarDecls
1 parent a384b2a commit 757f253

File tree

2 files changed

+3
-33
lines changed

2 files changed

+3
-33
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,10 +4164,7 @@ class VarDecl : public AbstractStorageDecl {
41644164
/// This is the type specified, including location information.
41654165
TypeLoc typeLoc;
41664166

4167-
mutable Type typeInContext;
4168-
4169-
/// Compute the type in context from the interface type.
4170-
Type computeTypeInContextSlow() const;
4167+
Type typeInContext;
41714168

41724169
public:
41734170
VarDecl(bool IsStatic, bool IsLet, SourceLoc NameLoc, Identifier Name,
@@ -4190,15 +4187,13 @@ class VarDecl : public AbstractStorageDecl {
41904187
bool hasType() const {
41914188
// We have a type if either the type has been computed already or if
41924189
// this is a deserialized declaration with an interface type.
4193-
return typeInContext ||
4194-
(hasInterfaceType() && !getDeclContext()->getParentSourceFile());
4190+
return !typeInContext.isNull();
41954191
}
41964192

41974193
/// Get the type of the variable within its context. If the context is generic,
41984194
/// this will use archetypes.
41994195
Type getType() const {
4200-
if (!typeInContext)
4201-
return computeTypeInContextSlow();
4196+
assert(!typeInContext.isNull() && "no contextual type set yet");
42024197
return typeInContext;
42034198
}
42044199

lib/AST/Decl.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,31 +3428,6 @@ void VarDecl::setType(Type t) {
34283428
setInvalid();
34293429
}
34303430

3431-
Type VarDecl::computeTypeInContextSlow() const {
3432-
Type contextType = getInterfaceType();
3433-
if (!contextType) return Type();
3434-
3435-
// If we have a type parameter, we need to map into this context.
3436-
if (contextType->hasTypeParameter()) {
3437-
auto genericEnv =
3438-
getInnermostDeclContext()->getGenericEnvironmentOfContext();
3439-
3440-
// FIXME: Hack to degrade somewhat gracefully when we don't have a generic
3441-
// environment yet. We return an interface type, but at least we don't
3442-
// record it.
3443-
if (!genericEnv)
3444-
return contextType;
3445-
3446-
contextType = genericEnv->mapTypeIntoContext(getModuleContext(),
3447-
contextType);
3448-
}
3449-
3450-
typeInContext = contextType;
3451-
if (typeInContext->hasError())
3452-
const_cast<VarDecl *>(this)->setInvalid();
3453-
return typeInContext;
3454-
}
3455-
34563431
void VarDecl::markInvalid() {
34573432
auto &Ctx = getASTContext();
34583433
setType(ErrorType::get(Ctx));

0 commit comments

Comments
 (0)