Skip to content

Commit 16f32fd

Browse files
committed
Eliminate support for @mainactor(unsafe) Clang attribute.
The `@MainActor(unsafe)` attribute could be provided for C declarations via the Clang `swift_attr` attribute. However, this facility was never used outside of tests, and has been superceded by `@MainActor` with the inferred `@_predatesConcurrency`.
1 parent 2fb2871 commit 16f32fd

File tree

4 files changed

+8
-19
lines changed

4 files changed

+8
-19
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8392,17 +8392,13 @@ SourceFile &ClangImporter::Implementation::getClangSwiftAttrSourceFile(
83928392
return *sourceFile;
83938393
}
83948394

8395-
Optional<bool> swift::importer::isMainActorAttr(
8396-
ASTContext &ctx, const clang::SwiftAttrAttr *swiftAttr) {
8395+
bool swift::importer::isMainActorAttr(const clang::SwiftAttrAttr *swiftAttr) {
83978396
if (swiftAttr->getAttribute() == "@MainActor" ||
8398-
swiftAttr->getAttribute() == "@MainActor(unsafe)" ||
83998397
swiftAttr->getAttribute() == "@UIActor") {
8400-
bool isUnsafe = swiftAttr->getAttribute() == "@MainActor(unsafe)" ||
8401-
!ctx.LangOpts.isSwiftVersionAtLeast(6);
8402-
return isUnsafe;
8398+
return true;
84038399
}
84048400

8405-
return None;
8401+
return false;
84068402
}
84078403

84088404
void
@@ -8430,9 +8426,7 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
84308426
for (auto swiftAttr : ClangDecl->specific_attrs<clang::SwiftAttrAttr>()) {
84318427
// FIXME: Hard-code @MainActor and @UIActor, because we don't have a
84328428
// point at which to do name lookup for imported entities.
8433-
if (auto isMainActor = isMainActorAttr(SwiftContext, swiftAttr)) {
8434-
bool isUnsafe = *isMainActor;
8435-
8429+
if (isMainActorAttr(swiftAttr)) {
84368430
if (SeenMainActorAttr) {
84378431
// Cannot add main actor annotation twice. We'll keep the first
84388432
// one and raise a warning about the duplicate.
@@ -8446,7 +8440,6 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
84468440
if (Type mainActorType = SwiftContext.getMainActorType()) {
84478441
auto typeExpr = TypeExpr::createImplicit(mainActorType, SwiftContext);
84488442
auto attr = CustomAttr::create(SwiftContext, SourceLoc(), typeExpr);
8449-
attr->setArgIsUnsafe(isUnsafe);
84508443
MappedDecl->getAttrs().add(attr);
84518444
SeenMainActorAttr = swiftAttr;
84528445
}

lib/ClangImporter/ImportType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ Type ClangImporter::Implementation::applyParamAttributes(
17261726
continue;
17271727

17281728
// Map the main-actor attribute.
1729-
if (isMainActorAttr(SwiftContext, swiftAttr)) {
1729+
if (isMainActorAttr(swiftAttr)) {
17301730
if (Type mainActor = SwiftContext.getMainActorType()) {
17311731
type = applyToFunctionType(type, [&](ASTExtInfo extInfo) {
17321732
return extInfo.withGlobalActor(mainActor);

lib/ClangImporter/ImporterImpl.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,11 +1663,7 @@ class SwiftNameLookupExtension : public clang::ModuleFileExtension {
16631663

16641664
/// Determines whether the given swift_attr attribute describes the main
16651665
/// actor.
1666-
///
1667-
/// \returns None if this is not a main-actor attribute, and a Boolean
1668-
/// indicating whether (unsafe) was provided in the attribute otherwise.
1669-
Optional<bool> isMainActorAttr(
1670-
ASTContext &ctx, const clang::SwiftAttrAttr *swiftAttr);
1666+
bool isMainActorAttr(const clang::SwiftAttrAttr *swiftAttr);
16711667

16721668
}
16731669
}

test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ typedef void ( ^ObjCErrorHandler )( NSError * _Nullable inError );
178178
#define MAGIC_NUMBER 42
179179

180180

181-
__attribute__((__swift_attr__("@MainActor(unsafe)")))
181+
__attribute__((__swift_attr__("@MainActor")))
182182
@interface NXView : NSObject
183183
-(void)onDisplay;
184184
@end
@@ -195,7 +195,7 @@ void doSomethingConcurrently(__attribute__((noescape)) SENDABLE void (^block)(vo
195195
void doSomethingConcurrentlyButUnsafe(__attribute__((noescape)) __attribute__((swift_attr("@Sendable"))) void (^block)(void));
196196

197197

198-
MAIN_ACTOR MAIN_ACTOR __attribute__((__swift_attr__("@MainActor(unsafe)"))) @protocol TripleMainActor
198+
MAIN_ACTOR MAIN_ACTOR __attribute__((__swift_attr__("@MainActor"))) @protocol TripleMainActor
199199
@end
200200

201201
@protocol ProtocolWithAsync

0 commit comments

Comments
 (0)