Skip to content

Commit 8d9629e

Browse files
committed
Requestify getInterfaceType() in Name Only
Make getInterfaceType() call validateDecl on behalf of its clients. In effect, this makes the interface type behave like a request. It also means that its clients no longer need to perform a number of undesirable anti-patterns in order to sidestep the bizarre API contract validateDecl has at the moment In particular, the following things are no longer necessary: - Checking for a missing interface type then validating - Validating the interface type then retrieving it - Validating the interface type then retrieving a derived value These anti-patterns will be removed in follow-up commits
1 parent 079a1a4 commit 8d9629e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,13 @@ bool ValueDecl::hasInterfaceType() const {
26972697
}
26982698

26992699
Type ValueDecl::getInterfaceType() const {
2700-
assert(hasInterfaceType() && "No interface type was set");
2700+
if (!hasInterfaceType()) {
2701+
// Our clients that don't register the lazy resolver are relying on the
2702+
// fact that they can't pull an interface type out to avoid doing work.
2703+
// This is a necessary evil until we can wean them off.
2704+
if (auto resolver = getASTContext().getLazyResolver())
2705+
resolver->resolveDeclSignature(const_cast<ValueDecl *>(this));
2706+
}
27012707
return TypeAndAccess.getPointer();
27022708
}
27032709

@@ -3241,7 +3247,7 @@ Type TypeDecl::getDeclaredInterfaceType() const {
32413247
selfTy, const_cast<AssociatedTypeDecl *>(ATD));
32423248
}
32433249

3244-
Type interfaceType = hasInterfaceType() ? getInterfaceType() : nullptr;
3250+
Type interfaceType = getInterfaceType();
32453251
if (interfaceType.isNull() || interfaceType->is<ErrorType>())
32463252
return interfaceType;
32473253

0 commit comments

Comments
 (0)