14
14
15
15
#include " swift/AST/Decl.h"
16
16
#include " swift/AST/ExistentialLayout.h"
17
- #include " swift/AST/InverseMarking.h"
18
17
#include " swift/AST/NameLookup.h"
19
18
#include " swift/AST/ParameterList.h"
20
19
#include " swift/AST/Pattern.h"
@@ -34,62 +33,6 @@ static bool usesTypeMatching(Decl *decl, llvm::function_ref<bool(Type)> fn) {
34
33
return false ;
35
34
}
36
35
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
-
93
36
// ----------------------------------------------------------------------------
94
37
// MARK: - Standard Features
95
38
// ----------------------------------------------------------------------------
@@ -256,10 +199,39 @@ static bool usesFeatureExtensionMacros(Decl *decl) {
256
199
}
257
200
258
201
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 ;
263
235
}
264
236
265
237
static bool usesFeatureMoveOnlyResilientTypes (Decl *decl) {
0 commit comments