Skip to content

Commit 35cc303

Browse files
committed
AST: Be more careful about calls to ErrorType::get()
It's nice to be able to set a breakpoint on this method when debugging the type checker, but recently we started unconditionally calling it to get the circularity sentinel before kicking off a request. Instead, let's only call it when we're in the failure path.
1 parent 4971bc3 commit 35cc303

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

lib/AST/Decl.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,9 +1256,11 @@ AccessLevel ExtensionDecl::getMaxAccessLevel() const {
12561256

12571257
Type ExtensionDecl::getExtendedType() const {
12581258
ASTContext &ctx = getASTContext();
1259-
return evaluateOrDefault(ctx.evaluator,
1260-
ExtendedTypeRequest{const_cast<ExtensionDecl *>(this)},
1261-
ErrorType::get(ctx));
1259+
if (auto type = evaluateOrDefault(ctx.evaluator,
1260+
ExtendedTypeRequest{const_cast<ExtensionDecl *>(this)},
1261+
Type()))
1262+
return type;
1263+
return ErrorType::get(ctx);
12621264
}
12631265

12641266
/// Clone the given generic parameters in the given list. We don't need any
@@ -2881,19 +2883,21 @@ bool ValueDecl::isRecursiveValidation() const {
28812883
}
28822884

28832885
Type ValueDecl::getInterfaceType() const {
2886+
auto &ctx = getASTContext();
2887+
28842888
// Our clients that don't register the lazy resolver are relying on the
28852889
// fact that they can't pull an interface type out to avoid doing work.
28862890
// This is a necessary evil until we can wean them off.
2887-
if (!getASTContext().getLazyResolver()) {
2891+
if (!ctx.getLazyResolver()) {
28882892
return TypeAndAccess.getPointer();
28892893
}
28902894

2891-
if (auto Ty =
2892-
evaluateOrDefault(getASTContext().evaluator,
2895+
if (auto type =
2896+
evaluateOrDefault(ctx.evaluator,
28932897
InterfaceTypeRequest{const_cast<ValueDecl *>(this)},
2894-
ErrorType::get(getASTContext())))
2895-
return Ty;
2896-
return ErrorType::get(getASTContext());
2898+
Type()))
2899+
return type;
2900+
return ErrorType::get(ctx);
28972901
}
28982902

28992903
void ValueDecl::setInterfaceType(Type type) {
@@ -3695,9 +3699,11 @@ SourceRange TypeAliasDecl::getSourceRange() const {
36953699

36963700
Type TypeAliasDecl::getUnderlyingType() const {
36973701
auto &ctx = getASTContext();
3698-
return evaluateOrDefault(ctx.evaluator,
3702+
if (auto type = evaluateOrDefault(ctx.evaluator,
36993703
UnderlyingTypeRequest{const_cast<TypeAliasDecl *>(this)},
3700-
ErrorType::get(ctx));
3704+
Type()))
3705+
return type;
3706+
return ErrorType::get(ctx);
37013707
}
37023708

37033709
void TypeAliasDecl::setUnderlyingType(Type underlying) {
@@ -3728,10 +3734,12 @@ UnboundGenericType *TypeAliasDecl::getUnboundGenericType() const {
37283734

37293735
Type TypeAliasDecl::getStructuralType() const {
37303736
auto &ctx = getASTContext();
3731-
return evaluateOrDefault(
3737+
if (auto type = evaluateOrDefault(
37323738
ctx.evaluator,
37333739
StructuralTypeRequest{const_cast<TypeAliasDecl *>(this)},
3734-
ErrorType::get(ctx));
3740+
Type()))
3741+
return type;
3742+
return ErrorType::get(ctx);
37353743
}
37363744

37373745
Type AbstractTypeParamDecl::getSuperclass() const {
@@ -6313,9 +6321,11 @@ void SubscriptDecl::setIndices(ParameterList *p) {
63136321
Type SubscriptDecl::getElementInterfaceType() const {
63146322
auto &ctx = getASTContext();
63156323
auto mutableThis = const_cast<SubscriptDecl *>(this);
6316-
return evaluateOrDefault(ctx.evaluator,
6324+
if (auto type = evaluateOrDefault(ctx.evaluator,
63176325
ResultTypeRequest{mutableThis},
6318-
ErrorType::get(ctx));
6326+
Type()))
6327+
return type;
6328+
return ErrorType::get(ctx);
63196329
}
63206330

63216331
ObjCSubscriptKind SubscriptDecl::getObjCSubscriptKind() const {
@@ -6943,9 +6953,11 @@ StaticSpellingKind FuncDecl::getCorrectStaticSpelling() const {
69436953
Type FuncDecl::getResultInterfaceType() const {
69446954
auto &ctx = getASTContext();
69456955
auto mutableThis = const_cast<FuncDecl *>(this);
6946-
return evaluateOrDefault(ctx.evaluator,
6956+
if (auto type = evaluateOrDefault(ctx.evaluator,
69476957
ResultTypeRequest{mutableThis},
6948-
ErrorType::get(ctx));
6958+
Type()))
6959+
return type;
6960+
return ErrorType::get(ctx);
69496961
}
69506962

69516963
bool FuncDecl::isUnaryOperator() const {

0 commit comments

Comments
 (0)