Skip to content

Commit 27cf245

Browse files
committed
AST: Remove a usage of hasInverseMarking()
1 parent 3559c44 commit 27cf245

File tree

1 file changed

+33
-61
lines changed

1 file changed

+33
-61
lines changed

lib/AST/FeatureSet.cpp

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "swift/AST/Decl.h"
1616
#include "swift/AST/ExistentialLayout.h"
17-
#include "swift/AST/InverseMarking.h"
1817
#include "swift/AST/NameLookup.h"
1918
#include "swift/AST/ParameterList.h"
2019
#include "swift/AST/Pattern.h"
@@ -34,62 +33,6 @@ static bool usesTypeMatching(Decl *decl, llvm::function_ref<bool(Type)> fn) {
3433
return false;
3534
}
3635

37-
/// \param isRelevantInverse the function used to inspect a mark corresponding
38-
/// to an inverse to determine whether it "has" an inverse that we care about.
39-
static bool hasInverse(
40-
Decl *decl, InvertibleProtocolKind ip,
41-
std::function<bool(InverseMarking::Mark const &)> isRelevantInverse) {
42-
43-
auto getTypeDecl = [](Type type) -> TypeDecl * {
44-
if (auto genericTy = type->getAnyGeneric())
45-
return genericTy;
46-
if (auto gtpt = dyn_cast<GenericTypeParamType>(type))
47-
return gtpt->getDecl();
48-
return nullptr;
49-
};
50-
51-
if (auto *extension = dyn_cast<ExtensionDecl>(decl)) {
52-
if (auto *nominal = extension->getSelfNominalTypeDecl())
53-
return hasInverse(nominal, ip, isRelevantInverse);
54-
return false;
55-
}
56-
57-
auto hasInverseInType = [&](Type type) {
58-
return type.findIf([&](Type type) -> bool {
59-
if (auto *typeDecl = getTypeDecl(type))
60-
return hasInverse(typeDecl, ip, isRelevantInverse);
61-
return false;
62-
});
63-
};
64-
65-
if (auto *TD = dyn_cast<TypeDecl>(decl)) {
66-
if (auto *alias = dyn_cast<TypeAliasDecl>(TD))
67-
return hasInverseInType(alias->getUnderlyingType());
68-
69-
if (auto *NTD = dyn_cast<NominalTypeDecl>(TD)) {
70-
if (isRelevantInverse(NTD->hasInverseMarking(ip)))
71-
return true;
72-
}
73-
74-
if (auto *P = dyn_cast<ProtocolDecl>(TD)) {
75-
// Check the protocol's associated types too.
76-
return llvm::any_of(
77-
P->getAssociatedTypeMembers(), [&](AssociatedTypeDecl *ATD) {
78-
return isRelevantInverse(ATD->hasInverseMarking(ip));
79-
});
80-
}
81-
82-
return false;
83-
}
84-
85-
if (auto *VD = dyn_cast<ValueDecl>(decl)) {
86-
if (VD->hasInterfaceType())
87-
return hasInverseInType(VD->getInterfaceType());
88-
}
89-
90-
return false;
91-
}
92-
9336
// ----------------------------------------------------------------------------
9437
// MARK: - Standard Features
9538
// ----------------------------------------------------------------------------
@@ -256,10 +199,39 @@ static bool usesFeatureExtensionMacros(Decl *decl) {
256199
}
257200

258201
static bool usesFeatureMoveOnly(Decl *decl) {
259-
return hasInverse(decl, InvertibleProtocolKind::Copyable,
260-
[](auto &marking) -> bool {
261-
return marking.is(InverseMarking::Kind::LegacyExplicit);
262-
});
202+
if (auto *extension = dyn_cast<ExtensionDecl>(decl)) {
203+
if (auto *nominal = extension->getExtendedNominal())
204+
return usesFeatureMoveOnly(nominal);
205+
return false;
206+
}
207+
208+
auto hasInverseInType = [&](Type type) {
209+
return type.findIf([&](Type type) -> bool {
210+
if (auto *NTD = type->getAnyNominal()) {
211+
if (NTD->getAttrs().hasAttribute<MoveOnlyAttr>())
212+
return true;
213+
}
214+
return false;
215+
});
216+
};
217+
218+
if (auto *TD = dyn_cast<TypeDecl>(decl)) {
219+
if (auto *alias = dyn_cast<TypeAliasDecl>(TD))
220+
return hasInverseInType(alias->getUnderlyingType());
221+
222+
if (auto *NTD = dyn_cast<NominalTypeDecl>(TD)) {
223+
if (NTD->getAttrs().hasAttribute<MoveOnlyAttr>())
224+
return true;
225+
}
226+
227+
return false;
228+
}
229+
230+
if (auto *VD = dyn_cast<ValueDecl>(decl)) {
231+
return hasInverseInType(VD->getInterfaceType());
232+
}
233+
234+
return false;
263235
}
264236

265237
static bool usesFeatureMoveOnlyResilientTypes(Decl *decl) {

0 commit comments

Comments
 (0)