Skip to content

Commit 1716832

Browse files
committed
AST: Remove most usages of AbstractFunctionDecl::hasDynamicSelfResult()
1 parent 9e3d0e0 commit 1716832

File tree

7 files changed

+35
-30
lines changed

7 files changed

+35
-30
lines changed

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4076,7 +4076,7 @@ AnyFunctionType::Param swift::computeSelfParam(AbstractFunctionDecl *AFD,
40764076
// Methods returning 'Self' have a dynamic 'self'.
40774077
//
40784078
// FIXME: All methods of non-final classes should have this.
4079-
else if (wantDynamicSelf && FD->hasDynamicSelfResult())
4079+
else if (wantDynamicSelf && FD->getResultInterfaceType()->hasDynamicSelfType())
40804080
isDynamicSelf = true;
40814081

40824082
} else if (auto *CD = dyn_cast<ConstructorDecl>(AFD)) {

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,8 @@ class DeclAndTypePrinter::Implementation
12501250
// Constructors and methods returning DynamicSelf return
12511251
// instancetype.
12521252
if (isa<ConstructorDecl>(AFD) ||
1253-
(isa<FuncDecl>(AFD) && cast<FuncDecl>(AFD)->hasDynamicSelfResult() &&
1253+
(isa<FuncDecl>(AFD) &&
1254+
cast<FuncDecl>(AFD)->getResultInterfaceType()->hasDynamicSelfType() &&
12541255
!AFD->hasAsync())) {
12551256
if (errorConvention && errorConvention->stripsResultOptionality()) {
12561257
printNullability(OTK_Optional, NullabilityPrintKind::ContextSensitive);

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4283,7 +4283,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
42834283
// If the method returns dynamic Self, substitute AnyObject for the
42844284
// result type.
42854285
if (auto fnDecl = dyn_cast<FuncDecl>(method.getDecl())) {
4286-
if (fnDecl->hasDynamicSelfResult()) {
4286+
if (fnDecl->getResultInterfaceType()->hasDynamicSelfType()) {
42874287
auto anyObjectTy = C.getAnyObjectType();
42884288
for (auto &result : results) {
42894289
auto resultTy =

lib/Sema/MiscDiagnostics.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6800,13 +6800,15 @@ TypeChecker::omitNeedlessWords(AbstractFunctionDecl *afd) {
68006800
// Handle contextual type, result type, and returnsSelf.
68016801
Type contextType = afd->getDeclContext()->getDeclaredInterfaceType();
68026802
Type resultType;
6803-
bool returnsSelf = afd->hasDynamicSelfResult();
6803+
bool returnsSelf;
68046804

68056805
if (auto func = dyn_cast<FuncDecl>(afd)) {
68066806
resultType = func->getResultInterfaceType();
68076807
resultType = func->mapTypeIntoContext(resultType);
6808+
returnsSelf = func->getResultInterfaceType()->hasDynamicSelfType();
68086809
} else if (isa<ConstructorDecl>(afd)) {
68096810
resultType = contextType;
6811+
returnsSelf = true;
68106812
}
68116813

68126814
// Figure out the first parameter name.

lib/Sema/TypeCheckAttr.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6641,21 +6641,21 @@ typecheckDifferentiableAttrforDecl(AbstractFunctionDecl *original,
66416641
// Dynamic `Self` is supported only as a single top-level result for class
66426642
// members. JVP/VJP functions returning `(Self, ...)` tuples would not
66436643
// type-check.
6644-
bool diagnoseDynamicSelfResult = original->hasDynamicSelfResult();
6645-
if (diagnoseDynamicSelfResult) {
6646-
// Diagnose class initializers in non-final classes.
6647-
if (isa<ConstructorDecl>(original)) {
6648-
if (!classDecl->isSemanticallyFinal()) {
6649-
diags.diagnose(
6650-
attr->getLocation(),
6651-
diag::differentiable_attr_nonfinal_class_init_unsupported,
6652-
classDecl->getDeclaredInterfaceType());
6653-
attr->setInvalid();
6654-
return nullptr;
6655-
}
6644+
// Diagnose class initializers in non-final classes.
6645+
if (isa<ConstructorDecl>(original)) {
6646+
if (!classDecl->isSemanticallyFinal()) {
6647+
diags.diagnose(
6648+
attr->getLocation(),
6649+
diag::differentiable_attr_nonfinal_class_init_unsupported,
6650+
classDecl->getDeclaredInterfaceType());
6651+
attr->setInvalid();
6652+
return nullptr;
66566653
}
6654+
}
6655+
6656+
if (auto *funcDecl = dyn_cast<FuncDecl>(original)) {
66576657
// Diagnose all other declarations returning dynamic `Self`.
6658-
else {
6658+
if (funcDecl->getResultInterfaceType()->hasDynamicSelfType()) {
66596659
diags.diagnose(
66606660
attr->getLocation(),
66616661
diag::
@@ -7035,19 +7035,19 @@ static bool typeCheckDerivativeAttr(DerivativeAttr *attr) {
70357035
// Dynamic `Self` is supported only as a single top-level result for class
70367036
// members. JVP/VJP functions returning `(Self, ...)` tuples would not
70377037
// type-check.
7038-
bool diagnoseDynamicSelfResult = originalAFD->hasDynamicSelfResult();
7039-
if (diagnoseDynamicSelfResult) {
7038+
if (isa<ConstructorDecl>(originalAFD)) {
70407039
// Diagnose class initializers in non-final classes.
7041-
if (isa<ConstructorDecl>(originalAFD)) {
7042-
if (!classDecl->isSemanticallyFinal()) {
7043-
diags.diagnose(attr->getLocation(),
7044-
diag::derivative_attr_nonfinal_class_init_unsupported,
7045-
classDecl->getDeclaredInterfaceType());
7046-
return true;
7047-
}
7040+
if (!classDecl->isSemanticallyFinal()) {
7041+
diags.diagnose(attr->getLocation(),
7042+
diag::derivative_attr_nonfinal_class_init_unsupported,
7043+
classDecl->getDeclaredInterfaceType());
7044+
return true;
70487045
}
7046+
}
7047+
7048+
if (auto *FD = dyn_cast<FuncDecl>(originalAFD)) {
70497049
// Diagnose all other declarations returning dynamic `Self`.
7050-
else {
7050+
if (FD->getResultInterfaceType()->hasDynamicSelfType()) {
70517051
diags.diagnose(
70527052
attr->getLocation(),
70537053
diag::derivative_attr_class_member_dynamic_self_result_unsupported,

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ bool swift::isRepresentableInLanguage(
855855

856856
// The completion handler transformation cannot properly represent a
857857
// dynamic 'Self' type, so disallow @objc for such methods.
858-
if (FD->hasDynamicSelfResult()) {
858+
if (FD->getResultInterfaceType()->hasDynamicSelfType()) {
859859
AFD->diagnose(diag::async_objc_dynamic_self)
860860
.highlight(AFD->getAsyncLoc())
861861
.limitBehavior(behavior);

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4246,8 +4246,10 @@ void ConformanceChecker::checkNonFinalClassWitness(ValueDecl *requirement,
42464246
// by holding onto Self accordingly.
42474247
if (witness->getDeclContext()->getSelfClassDecl()) {
42484248
const bool hasDynamicSelfResult = [&] {
4249-
if (auto func = dyn_cast<AbstractFunctionDecl>(witness)) {
4250-
return func->hasDynamicSelfResult();
4249+
if (isa<ConstructorDecl>(witness)) {
4250+
return true;
4251+
} else if (auto func = dyn_cast<FuncDecl>(witness)) {
4252+
return func->getResultInterfaceType()->hasDynamicSelfType();
42514253
} else if (auto var = dyn_cast<VarDecl>(witness)) {
42524254
return var->getInterfaceType()->hasDynamicSelfType();
42534255
}

0 commit comments

Comments
 (0)