21
21
#include " swift/AST/Decl.h"
22
22
#include " swift/AST/DiagnosticsSema.h"
23
23
#include " swift/AST/Expr.h"
24
+ #include " swift/AST/Module.h"
24
25
#include " swift/AST/ParameterList.h"
25
26
#include " swift/AST/TypeRepr.h"
26
27
#include " swift/Basic/Assertions.h"
@@ -55,6 +56,27 @@ class NonisolatedNonsendingByDefaultMigrationTarget {
55
56
// / behavior.
56
57
void diagnose () const ;
57
58
};
59
+
60
+ // / Determine whether the decl represents a test function that is
61
+ // / annotated with `@Test` macro from the swift-testing framework.
62
+ // / Such functions should be exempt from the migration because their
63
+ // / execution is controlled by the framework and the change in
64
+ // / behavior doesn't affect them.
65
+ static bool isSwiftTestingTestFunction (ValueDecl *decl) {
66
+ if (!isa<FuncDecl>(decl))
67
+ return false ;
68
+
69
+ return llvm::any_of (decl->getAttrs (), [&decl](DeclAttribute *attr) {
70
+ auto customAttr = dyn_cast<CustomAttr>(attr);
71
+ if (!customAttr)
72
+ return false ;
73
+
74
+ auto *macro = decl->getResolvedMacro (customAttr);
75
+ return macro && macro->getBaseIdentifier ().is (" Test" ) &&
76
+ macro->getParentModule ()->getName ().is (" Testing" );
77
+ });
78
+ }
79
+
58
80
} // end anonymous namespace
59
81
60
82
void NonisolatedNonsendingByDefaultMigrationTarget::diagnose () const {
@@ -78,6 +100,17 @@ void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {
78
100
return ;
79
101
}
80
102
103
+ // `@Test` test-case have special semantics.
104
+ if (isSwiftTestingTestFunction (decl)) {
105
+ return ;
106
+ }
107
+
108
+ // A special declaration that was either synthesized by the compiler
109
+ // or a macro expansion.
110
+ if (decl->getBaseName ().hasDollarPrefix ()) {
111
+ return ;
112
+ }
113
+
81
114
// If the attribute cannot appear on this kind of declaration, we can't
82
115
// diagnose it.
83
116
if (!DeclAttribute::canAttributeAppearOnDecl (DeclAttrKind::Concurrent,
0 commit comments