Skip to content

Commit c20e5db

Browse files
committed
AST: Re-implement getResultInterfaceType()/getElementInterfaceType()
In preparation for landing the ResultTypeRequest, let's compute the result type directly from the declaration. For now, this still forces getInterfaceType() to be computed, but that will go away next.
1 parent 12231d2 commit c20e5db

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

lib/AST/Decl.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6178,10 +6178,13 @@ void SubscriptDecl::setIndices(ParameterList *p) {
61786178
}
61796179

61806180
Type SubscriptDecl::getElementInterfaceType() const {
6181-
auto elementTy = getInterfaceType();
6182-
if (elementTy->is<ErrorType>())
6183-
return elementTy;
6184-
return elementTy->castTo<AnyFunctionType>()->getResult();
6181+
// Force type checking of the result TypeLoc.
6182+
(void) getInterfaceType();
6183+
6184+
auto type = getElementTypeLoc().getType();
6185+
if (!type)
6186+
return TupleType::getEmpty(getASTContext());
6187+
return type;
61856188
}
61866189

61876190
void SubscriptDecl::computeType() {
@@ -6629,18 +6632,7 @@ void AbstractFunctionDecl::computeType(AnyFunctionType::ExtInfo info) {
66296632
}
66306633

66316634
} else if (auto ctor = dyn_cast<ConstructorDecl>(this)) {
6632-
auto *dc = ctor->getDeclContext();
6633-
6634-
if (hasSelf) {
6635-
if (!dc->isTypeContext())
6636-
resultTy = ErrorType::get(ctx);
6637-
else
6638-
resultTy = dc->getSelfInterfaceType();
6639-
}
6640-
6641-
// Adjust result type for failability.
6642-
if (ctor->isFailable())
6643-
resultTy = OptionalType::get(resultTy);
6635+
resultTy = ctor->getResultInterfaceType();
66446636
} else {
66456637
assert(isa<DestructorDecl>(this));
66466638
resultTy = TupleType::getEmpty(ctx);
@@ -6893,14 +6885,13 @@ StaticSpellingKind FuncDecl::getCorrectStaticSpelling() const {
68936885
}
68946886

68956887
Type FuncDecl::getResultInterfaceType() const {
6896-
Type resultTy = getInterfaceType();
6897-
if (resultTy.isNull() || resultTy->is<ErrorType>())
6898-
return resultTy;
6899-
6900-
if (hasImplicitSelfDecl())
6901-
resultTy = resultTy->castTo<AnyFunctionType>()->getResult();
6888+
// Force type checking of the result TypeLoc.
6889+
(void) getInterfaceType();
69026890

6903-
return resultTy->castTo<AnyFunctionType>()->getResult();
6891+
auto resultTy = getBodyResultTypeLoc().getType();
6892+
if (!resultTy)
6893+
return TupleType::getEmpty(getASTContext());
6894+
return resultTy;
69046895
}
69056896

69066897
bool FuncDecl::isUnaryOperator() const {
@@ -7153,10 +7144,19 @@ SourceRange ConstructorDecl::getSourceRange() const {
71537144
}
71547145

71557146
Type ConstructorDecl::getResultInterfaceType() const {
7156-
Type ArgTy = getInterfaceType();
7157-
ArgTy = ArgTy->castTo<AnyFunctionType>()->getResult();
7158-
ArgTy = ArgTy->castTo<AnyFunctionType>()->getResult();
7159-
return ArgTy;
7147+
Type resultTy;
7148+
7149+
auto *dc = getDeclContext();
7150+
if (!dc->isTypeContext())
7151+
resultTy = ErrorType::get(getASTContext());
7152+
else
7153+
resultTy = dc->getSelfInterfaceType();
7154+
7155+
// Adjust result type for failability.
7156+
if (isFailable())
7157+
return OptionalType::get(resultTy);
7158+
7159+
return resultTy;
71607160
}
71617161

71627162
Type ConstructorDecl::getInitializerInterfaceType() {

0 commit comments

Comments
 (0)