Skip to content

[6.2][Concurrency] NonisolatedNonsendingByDefault: Except @Test test-cases and $ prefixed declarations from migration #82276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/Identifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class DeclBaseName {
}

bool hasDollarPrefix() const {
return getIdentifier().hasDollarPrefix();
return !isSpecial() && getIdentifier().hasDollarPrefix();
}

/// A representation of the name to be displayed to users. May be ambiguous
Expand Down
33 changes: 33 additions & 0 deletions lib/Sema/NonisolatedNonsendingByDefaultMigration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "swift/AST/Decl.h"
#include "swift/AST/DiagnosticsSema.h"
#include "swift/AST/Expr.h"
#include "swift/AST/Module.h"
#include "swift/AST/ParameterList.h"
#include "swift/AST/TypeRepr.h"
#include "swift/Basic/Assertions.h"
Expand Down Expand Up @@ -55,6 +56,27 @@ class NonisolatedNonsendingByDefaultMigrationTarget {
/// behavior.
void diagnose() const;
};

/// Determine whether the decl represents a test function that is
/// annotated with `@Test` macro from the swift-testing framework.
/// Such functions should be exempt from the migration because their
/// execution is controlled by the framework and the change in
/// behavior doesn't affect them.
static bool isSwiftTestingTestFunction(ValueDecl *decl) {
if (!isa<FuncDecl>(decl))
return false;

return llvm::any_of(decl->getAttrs(), [&decl](DeclAttribute *attr) {
auto customAttr = dyn_cast<CustomAttr>(attr);
if (!customAttr)
return false;

auto *macro = decl->getResolvedMacro(customAttr);
return macro && macro->getBaseIdentifier().is("Test") &&
macro->getParentModule()->getName().is("Testing");
});
}

} // end anonymous namespace

void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {
Expand All @@ -78,6 +100,17 @@ void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {
return;
}

// `@Test` test-case have special semantics.
if (isSwiftTestingTestFunction(decl)) {
return;
}

// A special declaration that was either synthesized by the compiler
// or a macro expansion.
if (decl->getBaseName().hasDollarPrefix()) {
return;
}

// If the attribute cannot appear on this kind of declaration, we can't
// diagnose it.
if (!DeclAttribute::canAttributeAppearOnDecl(DeclAttrKind::Concurrent,
Expand Down