Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Generics/chapters/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ \subsection*{Generic Contexts}
\begin{itemize}
\item \texttt{getParsedGenericParams()} returns the declaration's parsed generic parameter list, or \texttt{nullptr}.
\item \texttt{getGenericParams()} returns the declaration's full generic parameter list, which includes any implicit generic parameters. Evaluates a \texttt{GenericParamListRequest}.
\item \texttt{isGeneric()} answers if this declaration has a generic parameter list. This is equivalent to calling \texttt{DeclContext::isInnermostContextGeneric()}. Compare with \texttt{DeclContext::isGenericContext()}.
\item \texttt{hasGenericParamList()} answers if this declaration has a generic parameter list. This is equivalent to calling \texttt{isInnermostContextGeneric()} on \texttt{DeclContext}. Compare with \texttt{DeclContext::isGenericContext()}.
\item \texttt{getGenericContextDepth()} returns the \IndexSource{depth}depth of the declaration's generic parameter list, or \texttt{(unsigned)-1} if neither this declaration nor any outer declaration is generic.
\item \texttt{getTrailingWhereClause()} returns the declaration's trailing \texttt{where} clause, or \texttt{nullptr}.
\end{itemize}
Expand Down
10 changes: 5 additions & 5 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1696,15 +1696,15 @@ class GenericContext : private _GenericContext, public DeclContext {
///
/// \code
/// class C<T> {
/// func f1() {} // isGeneric == false
/// func f2<T>() {} // isGeneric == true
/// func f1() {} // hasGenericParamList == false
/// func f2<T>() {} // hasGenericParamList == true
/// }
///
/// protocol P { // isGeneric == true due to implicit Self param
/// func p() // isGeneric == false
/// protocol P { // hasGenericParamList == true due to implicit Self param
/// func p() // hasGenericParamList == false
/// }
/// \endcode
bool isGeneric() const { return getGenericParams() != nullptr; }
bool hasGenericParamList() const { return getGenericParams() != nullptr; }
bool hasComputedGenericSignature() const;
bool isComputingGenericSignature() const;

Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6892,10 +6892,10 @@ bool ASTContext::overrideGenericSignatureReqsSatisfied(
auto *baseCtx = base->getAsGenericContext();
auto *derivedCtx = derived->getAsGenericContext();

if (baseCtx->isGeneric() != derivedCtx->isGeneric())
if (baseCtx->hasGenericParamList() != derivedCtx->hasGenericParamList())
return false;

if (baseCtx->isGeneric() &&
if (baseCtx->hasGenericParamList() &&
(baseCtx->getGenericParams()->size() !=
derivedCtx->getGenericParams()->size()))
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ Type ASTBuilder::createNominalType(GenericTypeDecl *decl, Type parent) {
return Type();

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

// Imported types can be renamed to be members of other (non-generic)
Expand Down
7 changes: 4 additions & 3 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2008,9 +2008,10 @@ unsigned ASTMangler::appendBoundGenericArgs(DeclContext *dc,
// type declaration are not part of the mangling, so check whether the
// naming declaration has generic parameters.
auto namedGenericContext = opaque->getNamingDecl()->getAsGenericContext();
treatAsGeneric = namedGenericContext && namedGenericContext->isGeneric();
treatAsGeneric =
namedGenericContext && namedGenericContext->hasGenericParamList();
} else {
treatAsGeneric = genericContext->isGeneric();
treatAsGeneric = genericContext->hasGenericParamList();
}
if (treatAsGeneric) {
auto genericParams = subs.getGenericSignature().getGenericParams();
Expand Down Expand Up @@ -5430,7 +5431,7 @@ static std::optional<unsigned> getEnclosingTypeGenericDepth(const Decl *decl) {
if (!typeDecl)
return std::nullopt;

if (!typeDecl->isGeneric())
if (!typeDecl->hasGenericParamList())
return std::nullopt;

return typeDecl->getGenericSignature()->getMaxDepth();
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2961,7 +2961,7 @@ void PrintAST::printMembers(ArrayRef<Decl *> members, bool needComma,
}

void PrintAST::printGenericDeclGenericParams(GenericContext *decl) {
if (decl->isGeneric())
if (decl->hasGenericParamList())
if (auto GenericSig = decl->getGenericSignature()) {
Printer.printStructurePre(PrintStructureKind::DeclGenericParameterClause);
printGenericSignature(GenericSig, PrintParams | InnermostOnly);
Expand Down Expand Up @@ -6364,7 +6364,7 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
printQualifiedType(T);

auto *typeAliasDecl = T->getDecl();
if (typeAliasDecl->isGeneric()) {
if (typeAliasDecl->hasGenericParamList()) {
if (Options.PrintTypesForDebugging)
printGenericArgs(T->getDirectGenericArgs());
else
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3239,7 +3239,7 @@ class Verifier : public ASTWalker {
void verifyParsed(DestructorDecl *DD) {
PrettyStackTraceDecl debugStack("verifying DestructorDecl", DD);

if (DD->isGeneric()) {
if (DD->hasGenericParamList()) {
Out << "DestructorDecl cannot be generic";
abort();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4250,7 +4250,7 @@ OverloadSignature ValueDecl::getOverloadSignature() const {
}

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

return signature;
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/DeclContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ swift::FragileFunctionKindRequest::evaluate(Evaluator &evaluator,
bool DeclContext::isInnermostContextGeneric() const {
if (auto Decl = getAsDecl())
if (auto GC = Decl->getAsGenericContext())
return GC->isGeneric();
return GC->hasGenericParamList();
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions lib/AST/DistributedDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
auto &C = getASTContext();
auto *DC = getDeclContext();

if (!DC->isTypeContext() || !isGeneric())
if (!DC->isTypeContext() || !hasGenericParamList())
return false;

// === Check the name
Expand Down Expand Up @@ -512,7 +512,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
}

// === Check generics
if (!isGeneric()) {
if (!hasGenericParamList()) {
return false;
}

Expand Down Expand Up @@ -809,7 +809,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
}

// === Check generics
if (!isGeneric()) {
if (!hasGenericParamList()) {
return false;
}

Expand Down Expand Up @@ -949,7 +949,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
}

// === Check generics
if (!isGeneric()) {
if (!hasGenericParamList()) {
return false;
}

Expand Down Expand Up @@ -1078,7 +1078,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() cons
}

// === Check generics
if (!isGeneric()) {
if (!hasGenericParamList()) {
return false;
}

Expand Down Expand Up @@ -1188,7 +1188,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationDecoderDecodeNextArgument() c


// === Check generics
if (!isGeneric()) {
if (!hasGenericParamList()) {
return false;
}

Expand Down Expand Up @@ -1282,7 +1282,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationResultHandlerOnReturn() const
}

// === Check generics
if (!isGeneric()) {
if (!hasGenericParamList()) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3768,7 +3768,7 @@ createTupleExtensionGenericParams(ASTContext &ctx,
return nullptr;

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

return createExtensionGenericParams(ctx, ext, typeAlias);
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/ParameterPack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct PackReferenceCollector: TypeWalker {
}

if (auto *typeAliasType = dyn_cast<TypeAliasType>(t.getPointer())) {
if (typeAliasType->getDecl()->isGeneric()) {
if (typeAliasType->getDecl()->hasGenericParamList()) {
if (auto parentType = typeAliasType->getParent())
parentType.walk(*this);

Expand Down Expand Up @@ -403,7 +403,7 @@ SmallVector<Type, 2> BoundGenericType::getExpandedGenericArgs() {

/// <T...> Foo<T, Pack{Int, String}> => Pack{T..., Int, String}
SmallVector<Type, 2> TypeAliasType::getExpandedGenericArgs() {
if (!getDecl()->isGeneric())
if (!getDecl()->hasGenericParamList())
return SmallVector<Type, 2>();

auto genericSig = getGenericSignature();
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/RequirementMachine/RequirementLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ StructuralRequirementsRequest::evaluate(Evaluator &evaluator,
// DependentMemberType X, and the right hand side is the
// underlying type of the typealias.
if (auto *typeAliasDecl = dyn_cast<TypeAliasDecl>(decl)) {
if (typeAliasDecl->isGeneric())
if (typeAliasDecl->hasGenericParamList())
continue;

// Ignore the typealias if we have an associated type with the same name
Expand Down Expand Up @@ -1046,7 +1046,7 @@ TypeAliasRequirementsRequest::evaluate(Evaluator &evaluator,
auto isSuitableType = [&](TypeDecl *req) -> bool {
// Ignore generic types.
if (auto genReq = dyn_cast<GenericTypeDecl>(req))
if (genReq->isGeneric())
if (genReq->hasGenericParamList())
return false;

// Ignore typealiases with UnboundGenericType, since they
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/SwiftNameTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ swift::cxx_translation::getDeclRepresentation(
!AFD->getASTContext().LangOpts.hasFeature(
Feature::GenerateBindingsForThrowingFunctionsInCXX))
return {Unsupported, UnrepresentableThrows};
if (AFD->isGeneric())
if (AFD->hasGenericParamList())
genericSignature = AFD->getGenericSignature();
}
if (const auto *typeDecl = dyn_cast<NominalTypeDecl>(VD)) {
Expand All @@ -325,7 +325,7 @@ swift::cxx_translation::getDeclRepresentation(
return {Unsupported, UnrepresentableMoveOnly};
if (isa<ClassDecl>(VD) && VD->isObjC())
return {Unsupported, UnrepresentableObjC};
if (typeDecl->isGeneric()) {
if (typeDecl->hasGenericParamList()) {
if (isa<ClassDecl>(VD))
return {Unsupported, UnrepresentableGeneric};
genericSignature = typeDecl->getGenericSignature();
Expand Down
4 changes: 2 additions & 2 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6341,7 +6341,7 @@ namespace {

if (auto *GTD = dyn_cast<GenericTypeDecl>(typeDecl)) {
typealias->setGenericSignature(GTD->getGenericSignature());
if (GTD->isGeneric()) {
if (GTD->hasGenericParamList()) {
typealias->getASTContext().evaluator.cacheOutput(
GenericParamListRequest{typealias},
std::move(GTD->getGenericParams()->clone(typealias)));
Expand Down Expand Up @@ -6564,7 +6564,7 @@ Decl *SwiftDeclConverter::importCompatibilityTypeAlias(
auto *GTD = dyn_cast<GenericTypeDecl>(typeDecl);
if (GTD && !isa<ProtocolDecl>(GTD)) {
alias->setGenericSignature(GTD->getGenericSignature());
if (GTD->isGeneric()) {
if (GTD->hasGenericParamList()) {
alias->getASTContext().evaluator.cacheOutput(
GenericParamListRequest{alias},
std::move(GTD->getGenericParams()->clone(alias)));
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/CompletionLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void CompletionLookup::foundFunction(const AnyFunctionType *AFT) {

bool CompletionLookup::canBeUsedAsRequirementFirstType(Type selfTy,
TypeAliasDecl *TAD) {
if (TAD->isGeneric())
if (TAD->hasGenericParamList())
return false;

auto T = TAD->getDeclaredInterfaceType();
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ void EmitPolymorphicParameters::injectAdHocDistributedRequirements() {
auto loc = Fn.getLocation();

auto *funcDecl = dyn_cast_or_null<FuncDecl>(loc.getAsDeclContext());
if (!(funcDecl && funcDecl->isGeneric()))
if (!(funcDecl && funcDecl->hasGenericParamList()))
return;

if (!funcDecl->isDistributedWitnessWithAdHocSerializationRequirement())
Expand Down
6 changes: 3 additions & 3 deletions lib/PrintAsClang/ClangSyntaxPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void ClangSyntaxPrinter::printModuleNamespaceQualifiersIfNeeded(

bool ClangSyntaxPrinter::printNominalTypeOutsideMemberDeclTemplateSpecifiers(
const NominalTypeDecl *typeDecl) {
if (!typeDecl->isGeneric())
if (!typeDecl->hasGenericParamList())
return true;
printGenericSignature(
typeDecl->getGenericSignature().getCanonicalSignature());
Expand All @@ -93,7 +93,7 @@ bool ClangSyntaxPrinter::printNominalTypeOutsideMemberDeclTemplateSpecifiers(

bool ClangSyntaxPrinter::printNominalTypeOutsideMemberDeclInnerStaticAssert(
const NominalTypeDecl *typeDecl) {
if (!typeDecl->isGeneric())
if (!typeDecl->hasGenericParamList())
return true;
printGenericSignatureInnerStaticAsserts(
typeDecl->getGenericSignature().getCanonicalSignature());
Expand Down Expand Up @@ -173,7 +173,7 @@ void ClangSyntaxPrinter::printNominalTypeReference(
if (!printNestedTypeNamespaceQualifiers(typeDecl))
os << "::";
ClangSyntaxPrinter(typeDecl->getASTContext(), os).printBaseName(typeDecl);
if (typeDecl->isGeneric())
if (typeDecl->hasGenericParamList())
printGenericSignatureParams(
typeDecl->getGenericSignature().getCanonicalSignature());
}
Expand Down
6 changes: 3 additions & 3 deletions lib/PrintAsClang/DeclAndTypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2381,7 +2381,7 @@ class DeclAndTypePrinter::Implementation

if (auto *clangTypeDecl =
dyn_cast<clang::TypeDecl>(alias->getClangDecl())) {
assert(!alias->isGeneric()
assert(!alias->hasGenericParamList()
&& "generic typealias backed by clang typedecl?");

maybePrintTagKeyword(alias);
Expand All @@ -2391,7 +2391,7 @@ class DeclAndTypePrinter::Implementation
printNullability(optionalKind);
} else if (auto *clangObjCClass
= dyn_cast<clang::ObjCInterfaceDecl>(alias->getClangDecl())){
assert(!alias->isGeneric()
assert(!alias->hasGenericParamList()
&& "generic typealias backed by clang interface?");

os << clangObjCClass->getName() << " *";
Expand Down Expand Up @@ -2713,7 +2713,7 @@ class DeclAndTypePrinter::Implementation

if (auto *extension = dyn_cast<ExtensionDecl>(decl->getDeclContext())) {
const ClassDecl *extendedClass = extension->getSelfClassDecl();
assert(extendedClass->isGeneric());
assert(extendedClass->hasGenericParamList());
assert(extension->getGenericParams()->size() ==
extendedClass->getGenericParams()->size() &&
"extensions with custom generic parameters?");
Expand Down
4 changes: 2 additions & 2 deletions lib/PrintAsClang/ModuleContentsWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ class ModuleWriter {
bool imported = false;
if (TAD->hasClangNode())
imported = addImport(TD);
assert((imported || !TAD->isGeneric()) &&
assert((imported || !TAD->hasGenericParamList()) &&
"referencing non-imported generic typealias?");
} else if (addImport(TD)) {
return;
Expand Down Expand Up @@ -1109,7 +1109,7 @@ class ModuleWriter {
vd, [this](const NominalTypeDecl *decl) {
return printer.isZeroSized(decl);
});
if (nmtd->isGeneric()) {
if (nmtd->hasGenericParamList()) {
auto genericSignature =
nmtd->getGenericSignature().getCanonicalSignature();
ClangSyntaxPrinter(nmtd->getASTContext(), os).printGenericSignature(genericSignature);
Expand Down
4 changes: 2 additions & 2 deletions lib/PrintAsClang/PrintClangFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ ClangRepresentation DeclAndTypeClangFunctionPrinter::printFunctionSignature(
ClangSyntaxPrinter(FD->getASTContext(), functionSignatureOS)
.printNominalTypeOutsideMemberDeclTemplateSpecifiers(typeDecl);
}
if (FD->isGeneric()) {
if (FD->hasGenericParamList()) {
auto Signature = FD->getGenericSignature().getCanonicalSignature();
if (!cxx_translation::isExposableToCxx(Signature))
return ClangRepresentation::unsupported;
Expand Down Expand Up @@ -1257,7 +1257,7 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
if (typeDeclContext)
ClangSyntaxPrinter(FD->getASTContext(), os).printNominalTypeOutsideMemberDeclInnerStaticAssert(
typeDeclContext);
if (FD->isGeneric()) {
if (FD->hasGenericParamList()) {
auto Signature = FD->getGenericSignature().getCanonicalSignature();
ClangSyntaxPrinter(FD->getASTContext(), os).printGenericSignatureInnerStaticAsserts(Signature);
}
Expand Down
Loading