Skip to content

Commit 25bcd44

Browse files
committed
AST: Rename GenericContext::isGeneric to hasGenericParamList
`isGeneric` is a misleading name because this method checks for the existence of a `GenericParamList`, which is not implied by genericity.
1 parent 4008589 commit 25bcd44

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+103
-98
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,15 +1677,15 @@ class GenericContext : private _GenericContext, public DeclContext {
16771677
///
16781678
/// \code
16791679
/// class C<T> {
1680-
/// func f1() {} // isGeneric == false
1681-
/// func f2<T>() {} // isGeneric == true
1680+
/// func f1() {} // hasGenericParamList == false
1681+
/// func f2<T>() {} // hasGenericParamList == true
16821682
/// }
16831683
///
1684-
/// protocol P { // isGeneric == true due to implicit Self param
1685-
/// func p() // isGeneric == false
1684+
/// protocol P { // hasGenericParamList == true due to implicit Self param
1685+
/// func p() // hasGenericParamList == false
16861686
/// }
16871687
/// \endcode
1688-
bool isGeneric() const { return getGenericParams() != nullptr; }
1688+
bool hasGenericParamList() const { return getGenericParams() != nullptr; }
16891689
bool hasComputedGenericSignature() const;
16901690
bool isComputingGenericSignature() const;
16911691

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6818,10 +6818,10 @@ bool ASTContext::overrideGenericSignatureReqsSatisfied(
68186818
auto *baseCtx = base->getAsGenericContext();
68196819
auto *derivedCtx = derived->getAsGenericContext();
68206820

6821-
if (baseCtx->isGeneric() != derivedCtx->isGeneric())
6821+
if (baseCtx->hasGenericParamList() != derivedCtx->hasGenericParamList())
68226822
return false;
68236823

6824-
if (baseCtx->isGeneric() &&
6824+
if (baseCtx->hasGenericParamList() &&
68256825
(baseCtx->getGenericParams()->size() !=
68266826
derivedCtx->getGenericParams()->size()))
68276827
return false;

lib/AST/ASTDemangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ Type ASTBuilder::createNominalType(GenericTypeDecl *decl, Type parent) {
281281
return Type();
282282

283283
// If the declaration is generic, fail.
284-
if (nominalDecl->isGeneric())
284+
if (nominalDecl->hasGenericParamList())
285285
return Type();
286286

287287
// Imported types can be renamed to be members of other (non-generic)

lib/AST/ASTMangler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,9 +2014,10 @@ unsigned ASTMangler::appendBoundGenericArgs(DeclContext *dc,
20142014
// type declaration are not part of the mangling, so check whether the
20152015
// naming declaration has generic parameters.
20162016
auto namedGenericContext = opaque->getNamingDecl()->getAsGenericContext();
2017-
treatAsGeneric = namedGenericContext && namedGenericContext->isGeneric();
2017+
treatAsGeneric =
2018+
namedGenericContext && namedGenericContext->hasGenericParamList();
20182019
} else {
2019-
treatAsGeneric = genericContext->isGeneric();
2020+
treatAsGeneric = genericContext->hasGenericParamList();
20202021
}
20212022
if (treatAsGeneric) {
20222023
auto genericParams = subs.getGenericSignature().getGenericParams();
@@ -5434,7 +5435,7 @@ static std::optional<unsigned> getEnclosingTypeGenericDepth(const Decl *decl) {
54345435
if (!typeDecl)
54355436
return std::nullopt;
54365437

5437-
if (!typeDecl->isGeneric())
5438+
if (!typeDecl->hasGenericParamList())
54385439
return std::nullopt;
54395440

54405441
return typeDecl->getGenericSignature()->getMaxDepth();

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,7 @@ void PrintAST::printMembers(ArrayRef<Decl *> members, bool needComma,
29362936
}
29372937

29382938
void PrintAST::printGenericDeclGenericParams(GenericContext *decl) {
2939-
if (decl->isGeneric())
2939+
if (decl->hasGenericParamList())
29402940
if (auto GenericSig = decl->getGenericSignature()) {
29412941
Printer.printStructurePre(PrintStructureKind::DeclGenericParameterClause);
29422942
printGenericSignature(GenericSig, PrintParams | InnermostOnly);
@@ -6299,7 +6299,7 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
62996299
printQualifiedType(T);
63006300

63016301
auto *typeAliasDecl = T->getDecl();
6302-
if (typeAliasDecl->isGeneric()) {
6302+
if (typeAliasDecl->hasGenericParamList()) {
63036303
if (Options.PrintTypesForDebugging)
63046304
printGenericArgs(T->getDirectGenericArgs());
63056305
else

lib/AST/ASTVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3239,7 +3239,7 @@ class Verifier : public ASTWalker {
32393239
void verifyParsed(DestructorDecl *DD) {
32403240
PrettyStackTraceDecl debugStack("verifying DestructorDecl", DD);
32413241

3242-
if (DD->isGeneric()) {
3242+
if (DD->hasGenericParamList()) {
32433243
Out << "DestructorDecl cannot be generic";
32443244
abort();
32453245
}

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4190,7 +4190,7 @@ OverloadSignature ValueDecl::getOverloadSignature() const {
41904190
}
41914191

41924192
if (auto *extension = dyn_cast<ExtensionDecl>(getDeclContext()))
4193-
if (extension->isGeneric())
4193+
if (extension->hasGenericParamList())
41944194
signature.InExtensionOfGenericType = true;
41954195

41964196
return signature;

lib/AST/DeclContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ swift::FragileFunctionKindRequest::evaluate(Evaluator &evaluator,
602602
bool DeclContext::isInnermostContextGeneric() const {
603603
if (auto Decl = getAsDecl())
604604
if (auto GC = Decl->getAsGenericContext())
605-
return GC->isGeneric();
605+
return GC->hasGenericParamList();
606606
return false;
607607
}
608608

lib/AST/DistributedDecl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
476476
auto &C = getASTContext();
477477
auto *DC = getDeclContext();
478478

479-
if (!DC->isTypeContext() || !isGeneric())
479+
if (!DC->isTypeContext() || !hasGenericParamList())
480480
return false;
481481

482482
// === Check the name
@@ -521,7 +521,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
521521
}
522522

523523
// === Check generics
524-
if (!isGeneric()) {
524+
if (!hasGenericParamList()) {
525525
return false;
526526
}
527527

@@ -818,7 +818,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
818818
}
819819

820820
// === Check generics
821-
if (!isGeneric()) {
821+
if (!hasGenericParamList()) {
822822
return false;
823823
}
824824

@@ -958,7 +958,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
958958
}
959959

960960
// === Check generics
961-
if (!isGeneric()) {
961+
if (!hasGenericParamList()) {
962962
return false;
963963
}
964964

@@ -1087,7 +1087,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() cons
10871087
}
10881088

10891089
// === Check generics
1090-
if (!isGeneric()) {
1090+
if (!hasGenericParamList()) {
10911091
return false;
10921092
}
10931093

@@ -1197,7 +1197,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationDecoderDecodeNextArgument() c
11971197

11981198

11991199
// === Check generics
1200-
if (!isGeneric()) {
1200+
if (!hasGenericParamList()) {
12011201
return false;
12021202
}
12031203

@@ -1291,7 +1291,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationResultHandlerOnReturn() const
12911291
}
12921292

12931293
// === Check generics
1294-
if (!isGeneric()) {
1294+
if (!hasGenericParamList()) {
12951295
return false;
12961296
}
12971297

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3719,7 +3719,7 @@ createTupleExtensionGenericParams(ASTContext &ctx,
37193719
return nullptr;
37203720

37213721
auto *typeAlias = cast<TypeAliasDecl>(referenced.first[0]);
3722-
if (!typeAlias->isGeneric())
3722+
if (!typeAlias->hasGenericParamList())
37233723
return nullptr;
37243724

37253725
return createExtensionGenericParams(ctx, ext, typeAlias);

0 commit comments

Comments
 (0)