Skip to content

Commit 9da000f

Browse files
committed
[nfc] localize getAnyTypeDecl
After review, Slava and I decided it's not a good idea to provide a `TypeBase::getAnyTypeDecl` method, as it is not typically what people generally should use, as it doesn't handle all cases (type parameters with no associated decl, for example).
1 parent 2cd2989 commit 9da000f

File tree

4 files changed

+9
-22
lines changed

4 files changed

+9
-22
lines changed

include/swift/AST/Type.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ class CanType : public Type {
541541
CanType getNominalParent() const; // in Types.h
542542
NominalTypeDecl *getAnyNominal() const;
543543
GenericTypeDecl *getAnyGeneric() const;
544-
TypeDecl *getAnyTypeDecl() const;
545544

546545
bool isForeignReferenceType(); // in Types.h
547546

include/swift/AST/Types.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,11 +1233,6 @@ class alignas(1 << TypeAlignInBits) TypeBase
12331233
/// declaration.
12341234
GenericTypeDecl *getAnyGeneric();
12351235

1236-
// If this a GenericType, ModuleType, or GenericTypeParamType, return the
1237-
// type declaration.
1238-
// NOTE: Will not attempt to find an AssociatedTypeDecl.
1239-
TypeDecl *getAnyTypeDecl();
1240-
12411236
/// removeArgumentLabels - Retrieve a version of this type with all
12421237
/// argument labels removed.
12431238
Type removeArgumentLabels(unsigned numArgumentLabels);
@@ -7426,10 +7421,6 @@ inline GenericTypeDecl *TypeBase::getAnyGeneric() {
74267421
return getCanonicalType().getAnyGeneric();
74277422
}
74287423

7429-
inline TypeDecl *TypeBase::getAnyTypeDecl() {
7430-
return getCanonicalType().getAnyTypeDecl();
7431-
}
7432-
74337424
inline bool TypeBase::isBuiltinIntegerType(unsigned n) {
74347425
if (auto intTy = dyn_cast<BuiltinIntegerType>(getCanonicalType()))
74357426
return intTy->getWidth().isFixedWidth()

lib/AST/ASTPrinter.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3336,6 +3336,14 @@ static bool hasInverseCopyable(
33363336
Decl *decl,
33373337
std::function<bool(InverseMarking const&)> isRelevantInverse) {
33383338

3339+
auto getTypeDecl = [](Type type) -> TypeDecl* {
3340+
if (auto genericTy = type->getAnyGeneric())
3341+
return genericTy;
3342+
if (auto gtpt = dyn_cast<GenericTypeParamType>(type))
3343+
return gtpt->getDecl();
3344+
return nullptr;
3345+
};
3346+
33393347
if (auto *extension = dyn_cast<ExtensionDecl>(decl)) {
33403348
if (auto *nominal = extension->getSelfNominalTypeDecl())
33413349
if (isRelevantInverse(nominal->getNoncopyableMarking()))
@@ -3361,7 +3369,7 @@ static bool hasInverseCopyable(
33613369
// Check for noncopyable types in the types of this declaration.
33623370
if (Type type = value->getInterfaceType()) {
33633371
bool hasNoncopyable = type.findIf([&](Type type) {
3364-
if (auto typeDecl = type->getAnyTypeDecl())
3372+
if (auto *typeDecl = getTypeDecl(type))
33653373
if (isRelevantInverse(typeDecl->getNoncopyableMarking()))
33663374
return true;
33673375

lib/AST/Type.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,6 @@ GenericTypeDecl *CanType::getAnyGeneric() const {
9191
return nullptr;
9292
}
9393

94-
TypeDecl *CanType::getAnyTypeDecl() const {
95-
// NOTE: there is no simple way to determine if it's an AssociatedTypeDecl.
96-
if (auto genericTy = getAnyGeneric())
97-
return genericTy;
98-
if (auto gtpt = dyn_cast<GenericTypeParamType>(*this))
99-
return gtpt->getDecl();
100-
if (auto module = dyn_cast<ModuleType>(*this))
101-
return module->getModule();
102-
return nullptr;
103-
}
104-
10594
//===----------------------------------------------------------------------===//
10695
// Various Type Methods.
10796
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)