Skip to content

Commit

Permalink
Imported macros are actor independent
Browse files Browse the repository at this point in the history
Macros are thread safe. Marking them actor-independent will avoid
imported macros being reported as not concurrency safe.
  • Loading branch information
etcwilde committed Jan 19, 2021
1 parent 4f708fa commit 8f81609
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8953,7 +8953,12 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,

// Mark the function transparent so that we inline it away completely.
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);
var->getAttrs().add(actorIndependentAttr);
}
// Set the function up as the getter.
makeComputed(var, func, nullptr);

Expand Down
2 changes: 2 additions & 0 deletions test/IDE/print_clang_objc_async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ import _Concurrency
// CHECK-NEXT: @MainActor func mainActorMethod()
// CHECK-NEXT: {{^}} optional func missingAtAttributeMethod()
// CHECK-NEXT: {{^[}]$}}

// CHECK: @actorIndependent var MAGIC_NUMBER: Int32 { get }
2 changes: 2 additions & 0 deletions test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ typedef void (^CompletionHandler)(NSString * _Nullable, NSString * _Nullable_res
-(void)missingAtAttributeMethod __attribute__((__swift_attr__("asyncHandler")));
@end

#define MAGIC_NUMBER 42

#pragma clang assume_nonnull end

0 comments on commit 8f81609

Please sign in to comment.