Skip to content

Commit 64404f5

Browse files
authored
Merge pull request #82229 from xedin/rdar-152689053
[Concurrency] NonisolatedNonsendingByDefault: Except `@Test` test-cases and `$` prefixed declarations from migration
2 parents 64168ed + 17976c7 commit 64404f5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

include/swift/AST/Identifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class DeclBaseName {
362362
}
363363

364364
bool hasDollarPrefix() const {
365-
return getIdentifier().hasDollarPrefix();
365+
return !isSpecial() && getIdentifier().hasDollarPrefix();
366366
}
367367

368368
/// A representation of the name to be displayed to users. May be ambiguous

lib/Sema/NonisolatedNonsendingByDefaultMigration.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/AST/Decl.h"
2222
#include "swift/AST/DiagnosticsSema.h"
2323
#include "swift/AST/Expr.h"
24+
#include "swift/AST/Module.h"
2425
#include "swift/AST/ParameterList.h"
2526
#include "swift/AST/TypeRepr.h"
2627
#include "swift/Basic/Assertions.h"
@@ -55,6 +56,27 @@ class NonisolatedNonsendingByDefaultMigrationTarget {
5556
/// behavior.
5657
void diagnose() const;
5758
};
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+
5880
} // end anonymous namespace
5981

6082
void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {
@@ -78,6 +100,17 @@ void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {
78100
return;
79101
}
80102

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+
81114
// If the attribute cannot appear on this kind of declaration, we can't
82115
// diagnose it.
83116
if (!DeclAttribute::canAttributeAppearOnDecl(DeclAttrKind::Concurrent,

0 commit comments

Comments
 (0)