Skip to content

Commit cb86d9e

Browse files
Merge pull request #5358 from swiftwasm/yonihemi/merge-release-5.8
Merge release/5.8
2 parents 17bb478 + 44767b9 commit cb86d9e

File tree

18 files changed

+109
-47
lines changed

18 files changed

+109
-47
lines changed

include/swift/AST/ActorIsolation.h

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ class ActorIsolation {
160160
return getKind() == GlobalActor || getKind() == GlobalActorUnsafe;
161161
}
162162

163+
bool isMainActor() const;
164+
163165
bool isDistributedActor() const;
164166

165167
Type getGlobalActor() const {

include/swift/AST/Decl.h

+3
Original file line numberDiff line numberDiff line change
@@ -3834,6 +3834,9 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
38343834
/// Whether this nominal type qualifies as any actor (plain or distributed).
38353835
bool isAnyActor() const;
38363836

3837+
/// Whether this nominal type is the `MainActor` global actor.
3838+
bool isMainActor() const;
3839+
38373840
/// Return the range of semantics attributes attached to this NominalTypeDecl.
38383841
auto getSemanticsAttrs() const
38393842
-> decltype(getAttrs().getSemanticsAttrs()) {

include/swift/PrintAsClang/ClangMacros.def

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ CLANG_MACRO_BODY("SWIFT_CLASS", \
133133
"SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) " \
134134
"SWIFT_CLASS_EXTRA\n" \
135135
"# define SWIFT_CLASS_NAMED(SWIFT_NAME) " \
136-
"__attribute((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) " \
136+
"__attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) " \
137137
"SWIFT_CLASS_EXTRA\n" \
138138
"# else\n" \
139139
"# define SWIFT_CLASS(SWIFT_NAME) " \
@@ -175,7 +175,7 @@ CLANG_MACRO_CONDITIONAL("SWIFT_ENUM_ATTR", "(_extensibility)", \
175175
CLANG_MACRO_BODY("SWIFT_ENUM", \
176176
"# define SWIFT_ENUM(_type, _name, _extensibility) " \
177177
"enum _name : _type _name; " \
178-
"enum SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA _name: _type\n" \
178+
"enum SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA _name : _type\n" \
179179
"# if __has_feature(generalized_swift_name)\n" \
180180
"# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, _extensibility) " \
181181
"enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); " \
@@ -197,7 +197,7 @@ CLANG_MACRO("SWIFT_DEPRECATED", , "__attribute__((deprecated))")
197197
CLANG_MACRO("SWIFT_DEPRECATED_MSG", "(...)", "__attribute__((deprecated(__VA_ARGS__)))")
198198

199199
CLANG_MACRO_ALTERNATIVE("SWIFT_DEPRECATED_OBJC", "(Msg)", \
200-
"__has_feature(attribute_diagnost_if_objc)", \
200+
"__has_feature(attribute_diagnose_if_objc)", \
201201
"__attribute__((diagnose_if(1, Msg, \"warning\")))", \
202202
"SWIFT_DEPRECATED_MSG(Msg)")
203203

lib/AST/Decl.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -4567,6 +4567,11 @@ bool NominalTypeDecl::isAnyActor() const {
45674567
return isActor() || isDistributedActor();
45684568
}
45694569

4570+
bool NominalTypeDecl::isMainActor() const {
4571+
return getName().is("MainActor") &&
4572+
getParentModule()->getName() == getASTContext().Id_Concurrency;
4573+
}
4574+
45704575
GenericTypeDecl::GenericTypeDecl(DeclKind K, DeclContext *DC,
45714576
Identifier name, SourceLoc nameLoc,
45724577
ArrayRef<InheritedEntry> inherited,
@@ -9614,6 +9619,15 @@ void swift::simple_display(llvm::raw_ostream &out, AnyFunctionRef fn) {
96149619
out << "closure";
96159620
}
96169621

9622+
bool ActorIsolation::isMainActor() const {
9623+
if (isGlobalActor()) {
9624+
if (auto *nominal = getGlobalActor()->getAnyNominal())
9625+
return nominal->isMainActor();
9626+
}
9627+
9628+
return false;
9629+
}
9630+
96179631
bool ActorIsolation::isDistributedActor() const {
96189632
return getKind() == ActorInstance && getActor()->isDistributedActor();
96199633
}

lib/AST/DiagnosticEngine.cpp

+2-14
Original file line numberDiff line numberDiff line change
@@ -576,18 +576,6 @@ static bool typeSpellingIsAmbiguous(Type type,
576576
return false;
577577
}
578578

579-
/// Determine whether this is the main actor type.
580-
static bool isMainActor(Type type) {
581-
if (auto nominal = type->getAnyNominal()) {
582-
if (nominal->getName().is("MainActor") &&
583-
nominal->getParentModule()->getName() ==
584-
nominal->getASTContext().Id_Concurrency)
585-
return true;
586-
}
587-
588-
return false;
589-
}
590-
591579
void swift::printClangDeclName(const clang::NamedDecl *ND,
592580
llvm::raw_ostream &os) {
593581
ND->getNameForDiagnostic(os, ND->getASTContext().getPrintingPolicy(), false);
@@ -841,10 +829,10 @@ static void formatDiagnosticArgument(StringRef Modifier,
841829

842830
case ActorIsolation::GlobalActor:
843831
case ActorIsolation::GlobalActorUnsafe: {
844-
Type globalActor = isolation.getGlobalActor();
845-
if (isMainActor(globalActor)) {
832+
if (isolation.isMainActor()) {
846833
Out << "main actor-isolated";
847834
} else {
835+
Type globalActor = isolation.getGlobalActor();
848836
Out << "global actor " << FormatOpts.OpeningQuotationMark
849837
<< globalActor.getString()
850838
<< FormatOpts.ClosingQuotationMark << "-isolated";

lib/AST/Module.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,9 @@ void ModuleDecl::getDisplayDecls(SmallVectorImpl<Decl*> &Results, bool Recursive
11281128
llvm::SmallDenseMap<ModuleDecl *, SmallPtrSet<Decl *, 4>, 4> QualifiedImports;
11291129
collectParsedExportedImports(this, Modules, QualifiedImports);
11301130
for (const auto &QI : QualifiedImports) {
1131+
auto Module = QI.getFirst();
1132+
if (Modules.contains(Module)) continue;
1133+
11311134
auto &Decls = QI.getSecond();
11321135
Results.append(Decls.begin(), Decls.end());
11331136
}

lib/SILGen/SILGenProlog.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,11 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
712712
!isInActorDestructor(FunctionDC) &&
713713
!F.isDefer();
714714

715+
// FIXME: Avoid loading and checking the expected executor if concurrency is
716+
// unavailable. This is specifically relevant for MainActor isolated contexts,
717+
// which are allowed to be available on OSes where concurrency is not
718+
// available. rdar://106827064
719+
715720
// Local function to load the expected executor from a local actor
716721
auto loadExpectedExecutorForLocalVar = [&](VarDecl *var) {
717722
auto loc = RegularLocation::getAutoGeneratedLocation(F.getLocation());

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ void AvailableValueAggregator::addHandOffCopyDestroysForPhis(
12191219
// Otherwise, we need to insert one last destroy after the load for our phi.
12201220
auto next = std::next(load->getIterator());
12211221
SILBuilderWithScope builder(next);
1222-
builder.emitDestroyValueOperation(next->getLoc(), phi);
1222+
builder.emitDestroyValueOperation(RegularLocation(next->getLoc()), phi);
12231223
}
12241224

12251225
// Alright! In summary, we just lifetime extended all of our phis,
@@ -1251,7 +1251,7 @@ void AvailableValueAggregator::addMissingDestroysForCopiedValues(
12511251
assert(li->getParent() == load->getParent());
12521252
auto next = std::next(load->getIterator());
12531253
SILBuilderWithScope builder(next);
1254-
builder.emitDestroyValueOperation(next->getLoc(), li);
1254+
builder.emitDestroyValueOperation(RegularLocation(next->getLoc()), li);
12551255
continue;
12561256
}
12571257
}
@@ -1301,7 +1301,7 @@ void AvailableValueAggregator::addMissingDestroysForCopiedValues(
13011301
// Otherwise, we need to insert one last destroy after the load for our phi.
13021302
auto next = std::next(load->getIterator());
13031303
SILBuilderWithScope builder(next);
1304-
builder.emitDestroyValueOperation(next->getLoc(), cvi);
1304+
builder.emitDestroyValueOperation(RegularLocation(next->getLoc()), cvi);
13051305
}
13061306
}
13071307

lib/SILOptimizer/Utils/InstOptUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ void swift::insertDeallocOfCapturedArguments(PartialApplyInst *pai,
15071507
} else {
15081508
insertionPoint = terminator;
15091509
}
1510-
auto builder = SILBuilder(insertionPoint);
1510+
SILBuilderWithScope builder(insertionPoint);
15111511
builder.createDeallocStack(CleanupLocation(insertionPoint->getLoc()),
15121512
arg.get());
15131513
}

lib/Sema/TypeCheckAccess.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -1744,13 +1744,23 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
17441744
explicit DeclAvailabilityChecker(ExportContext where)
17451745
: Where(where) {}
17461746

1747+
void checkGlobalActor(Decl *D) {
1748+
auto globalActor = D->getGlobalActorAttr();
1749+
if (!globalActor)
1750+
return;
1751+
1752+
// Avoid checking the availability for a @MainActor constraint since it does
1753+
// not carry an inherent ABI impact.
1754+
if (globalActor->second->isMainActor())
1755+
return;
1756+
1757+
auto customAttr = globalActor->first;
1758+
checkType(customAttr->getType(), customAttr->getTypeRepr(), D);
1759+
}
1760+
17471761
void visit(Decl *D) {
17481762
DeclVisitor<DeclAvailabilityChecker>::visit(D);
1749-
1750-
if (auto globalActor = D->getGlobalActorAttr()) {
1751-
auto customAttr = globalActor->first;
1752-
checkType(customAttr->getType(), customAttr->getTypeRepr(), D);
1753-
}
1763+
checkGlobalActor(D);
17541764
}
17551765

17561766
// Force all kinds to be handled at a lower level.

lib/Sema/TypeCheckAttr.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -3538,15 +3538,6 @@ void AttributeChecker::visitFrozenAttr(FrozenAttr *attr) {
35383538
}
35393539
}
35403540

3541-
/// Determine whether this is the main actor type.
3542-
/// FIXME: the diagnostics engine and TypeCheckConcurrency both have a copy of
3543-
/// this
3544-
static bool isMainActor(NominalTypeDecl *nominal) {
3545-
return nominal->getName().is("MainActor") &&
3546-
nominal->getParentModule()->getName() ==
3547-
nominal->getASTContext().Id_Concurrency;
3548-
}
3549-
35503541
void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
35513542
auto dc = D->getDeclContext();
35523543

@@ -3582,7 +3573,7 @@ void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
35823573
return;
35833574
}
35843575

3585-
if (isMainActor(nominal) && Ctx.LangOpts.isConcurrencyModelTaskToThread() &&
3576+
if (nominal->isMainActor() && Ctx.LangOpts.isConcurrencyModelTaskToThread() &&
35863577
!AvailableAttr::isUnavailable(D)) {
35873578
Ctx.Diags.diagnose(attr->getLocation(),
35883579
diag::concurrency_task_to_thread_model_main_actor,

lib/Sema/TypeCheckConcurrency.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -1193,14 +1193,9 @@ void swift::diagnoseMissingExplicitSendable(NominalTypeDecl *nominal) {
11931193
}
11941194

11951195
/// Determine whether this is the main actor type.
1196-
/// FIXME: the diagnostics engine has a copy of this.
11971196
static bool isMainActor(Type type) {
1198-
if (auto nominal = type->getAnyNominal()) {
1199-
if (nominal->getName().is("MainActor") &&
1200-
nominal->getParentModule()->getName() ==
1201-
nominal->getASTContext().Id_Concurrency)
1202-
return true;
1203-
}
1197+
if (auto nominal = type->getAnyNominal())
1198+
return nominal->isMainActor();
12041199

12051200
return false;
12061201
}

test/SILOptimizer/closure-lifetime-fixup.sil

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -enable-sil-verify-all -closure-lifetime-fixup %s | %FileCheck %s
1+
// RUN: %target-sil-opt -enable-sil-verify-all -sil-print-debuginfo -closure-lifetime-fixup %s | %FileCheck %s
22

33
sil_stage raw
44

@@ -261,16 +261,16 @@ bb3:
261261
// CHECK: [[STACK:%[^,]+]] = alloc_stack $Self
262262
// CHECK: try_apply undef() {{.*}}, normal [[SUCCESS_1:bb[0-9]+]], error [[FAILURE_1:bb[0-9]+]]
263263
// CHECK: [[SUCCESS_1]]
264-
// CHECK: copy_addr [[INSTANCE]] to [init] [[STACK]] : $*Self
264+
// CHECK: copy_addr [[INSTANCE]] to [init] [[STACK]] : $*Self, {{.*}} scope [[STACK_SCOPE:[0-9]+]]
265265
// CHECK: [[CLOSURE:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] undef<Self>([[STACK]])
266266
// CHECK: [[DEPENDENCY:%[^,]+]] = mark_dependence [[CLOSURE]] {{.*}} on [[STACK]]
267267
// CHECK: try_apply undef([[DEPENDENCY]]) {{.*}}, normal [[SUCCESS_2:bb[0-9]+]], error [[FAILURE_2:bb[0-9]+]]
268268
// CHECK: [[SUCCESS_2]]
269269
// CHECK: dealloc_stack [[CLOSURE]]
270270
// CHECK: destroy_addr [[STACK]]
271-
// CHECK: dealloc_stack [[STACK]] : $*Self
271+
// CHECK: dealloc_stack [[STACK]] : $*Self, {{.*}} scope [[STACK_SCOPE]]
272272
// CHECK: [[FAILURE_1]]
273-
// CHECK: dealloc_stack [[STACK]]
273+
// CHECK: dealloc_stack [[STACK]] : $*Self, {{.*}} scope [[STACK_SCOPE]]
274274
// CHECK: throw
275275
// CHECK: [[FAILURE_2]]
276276
// CHECK-NOT: dealloc_stack
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// REQUIRES: concurrency
4+
5+
// This test is meant to verify that a @MainActor constraint is accepted without
6+
// any availability restrictions for all targets.
7+
8+
@MainActor
9+
struct AlwaysAvailable {}
10+
11+
@MainActor(unsafe)
12+
struct AlwaysAvailableUnsafe {}
13+
14+
@available(SwiftStdlib 5.1, *)
15+
@MainActor
16+
struct AvailableSwift5_1 {}
17+
18+
@available(SwiftStdlib 5.1, *)
19+
@MainActor(unsafe)
20+
struct AvailableSwift5_1Unsafe {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %S/Inputs/DuplicateExportedImport/A.swift -module-name A -emit-module -emit-module-path %t/A.swiftmodule
3+
// RUN: %target-swift-frontend %s -module-name DuplicateExportedImport -emit-module -emit-module-path /dev/null -I %t -emit-symbol-graph -emit-symbol-graph-dir %t/
4+
// RUN: %FileCheck %s --input-file %t/DuplicateExportedImport.symbols.json
5+
6+
// REQUIRES: asserts
7+
8+
// CHECK-COUNT-1: "precise":"s:1A8ClassTwoC"
9+
10+
@_exported import A
11+
@_exported import class A.ClassTwo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class ClassOne {}
2+
3+
public class ClassTwo {}

test/stdlib/NSStringAPI.swift

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// Tests for the NSString APIs as exposed by String
1313
//
1414

15+
// Temporarily disabled as it is taking too long to execute.
16+
// REQUIRES: rdar106755810
17+
1518
import StdlibUnittest
1619

1720

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library
3+
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
4+
// RUN: %FileCheck %s < %t/Library.swiftinterface
5+
6+
// REQUIRES: OS=macosx
7+
8+
import AppKit
9+
10+
// CHECK: @objc @_inheritsConvenienceInitializers @_Concurrency.MainActor(unsafe) public class Subclass : AppKit.NSView {
11+
public class Subclass: NSView {
12+
// CHECK: @_Concurrency.MainActor(unsafe) @objc override dynamic public init(frame frameRect: Foundation.NSRect)
13+
// CHECK: @_Concurrency.MainActor(unsafe) @objc required dynamic public init?(coder: Foundation.NSCoder)
14+
}

0 commit comments

Comments
 (0)