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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 2 additions & 14 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 15 additions & 5 deletions
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.

0 commit comments

Comments
 (0)