Skip to content

Clang importer concurrency tweaks #35982

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
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
11 changes: 6 additions & 5 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8036,9 +8036,10 @@ void ClangImporter::Implementation::importAttributes(
// __attribute__((swift_attr("attribute")))
//
if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(*AI)) {
// FIXME: Hard-core @MainActor, because we don't have a point at which to
// do name lookup for imported entities.
if (swiftAttr->getAttribute() == "@MainActor") {
// FIXME: Hard-core @MainActor and @UIActor, because we don't have a
// point at which to do name lookup for imported entities.
if (swiftAttr->getAttribute() == "@MainActor" ||
swiftAttr->getAttribute() == "@UIActor") {
if (Type mainActorType = getMainActorType()) {
auto typeExpr = TypeExpr::createImplicit(mainActorType, SwiftContext);
auto attr = CustomAttr::create(SwiftContext, SourceLoc(), typeExpr);
Expand Down Expand Up @@ -8969,8 +8970,8 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
func->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
// If we're in concurrency mode, mark the constant as @actorIndependent
if (SwiftContext.LangOpts.EnableExperimentalConcurrency) {
auto actorIndependentAttr = new (C) ActorIndependentAttr(SourceLoc(),
SourceRange(), ActorIndependentKind::Safe);
auto actorIndependentAttr = new (C) ActorIndependentAttr(
ActorIndependentKind::Unsafe, /*IsImplicit=*/true);
var->getAttrs().add(actorIndependentAttr);
}
// Set the function up as the getter.
Expand Down
2 changes: 2 additions & 0 deletions test/ClangImporter/objc_async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ actor MySubclassCheckingSwiftAttributes : ProtocolWithSwiftAttributes {
func mainActorMethod() {
syncMethod() // expected-error{{actor-isolated instance method 'syncMethod()' can not be referenced from context of global actor 'MainActor'}}
}

func uiActorMethod() { }
}
3 changes: 2 additions & 1 deletion test/IDE/print_clang_objc_async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import _Concurrency
// CHECK-NEXT: @actorIndependent func independentMethod()
// CHECK-NEXT: @asyncHandler func asyncHandlerMethod()
// CHECK-NEXT: @MainActor func mainActorMethod()
// CHECK-NEXT: @MainActor func uiActorMethod()
// CHECK-NEXT: {{^}} optional func missingAtAttributeMethod()
// CHECK-NEXT: {{^[}]$}}

// CHECK: @actorIndependent var MAGIC_NUMBER: Int32 { get }
// CHECK: {{^}}var MAGIC_NUMBER: Int32 { get }
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ typedef void (^CompletionHandler)(NSString * _Nullable, NSString * _Nullable_res
-(void)independentMethod __attribute__((__swift_attr__("@actorIndependent")));
-(void)asyncHandlerMethod __attribute__((__swift_attr__("@asyncHandler")));
-(void)mainActorMethod __attribute__((__swift_attr__("@MainActor")));
-(void)uiActorMethod __attribute__((__swift_attr__("@UIActor")));

@optional
-(void)missingAtAttributeMethod __attribute__((__swift_attr__("asyncHandler")));
Expand Down