Skip to content

Merge release/5.8 #5358

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 14 commits into from
Apr 5, 2023
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
2 changes: 2 additions & 0 deletions include/swift/AST/ActorIsolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class ActorIsolation {
return getKind() == GlobalActor || getKind() == GlobalActorUnsafe;
}

bool isMainActor() const;

bool isDistributedActor() const;

Type getGlobalActor() const {
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3834,6 +3834,9 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
/// Whether this nominal type qualifies as any actor (plain or distributed).
bool isAnyActor() const;

/// Whether this nominal type is the `MainActor` global actor.
bool isMainActor() const;

/// Return the range of semantics attributes attached to this NominalTypeDecl.
auto getSemanticsAttrs() const
-> decltype(getAttrs().getSemanticsAttrs()) {
Expand Down
6 changes: 3 additions & 3 deletions include/swift/PrintAsClang/ClangMacros.def
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ CLANG_MACRO_BODY("SWIFT_CLASS", \
"SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) " \
"SWIFT_CLASS_EXTRA\n" \
"# define SWIFT_CLASS_NAMED(SWIFT_NAME) " \
"__attribute((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) " \
"__attribute__((objc_subclassing_restricted)) SWIFT_COMPILE_NAME(SWIFT_NAME) " \
"SWIFT_CLASS_EXTRA\n" \
"# else\n" \
"# define SWIFT_CLASS(SWIFT_NAME) " \
Expand Down Expand Up @@ -175,7 +175,7 @@ CLANG_MACRO_CONDITIONAL("SWIFT_ENUM_ATTR", "(_extensibility)", \
CLANG_MACRO_BODY("SWIFT_ENUM", \
"# define SWIFT_ENUM(_type, _name, _extensibility) " \
"enum _name : _type _name; " \
"enum SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA _name: _type\n" \
"enum SWIFT_ENUM_ATTR(_extensibility) SWIFT_ENUM_EXTRA _name : _type\n" \
"# if __has_feature(generalized_swift_name)\n" \
"# define SWIFT_ENUM_NAMED(_type, _name, SWIFT_NAME, _extensibility) " \
"enum _name : _type _name SWIFT_COMPILE_NAME(SWIFT_NAME); " \
Expand All @@ -197,7 +197,7 @@ CLANG_MACRO("SWIFT_DEPRECATED", , "__attribute__((deprecated))")
CLANG_MACRO("SWIFT_DEPRECATED_MSG", "(...)", "__attribute__((deprecated(__VA_ARGS__)))")

CLANG_MACRO_ALTERNATIVE("SWIFT_DEPRECATED_OBJC", "(Msg)", \
"__has_feature(attribute_diagnost_if_objc)", \
"__has_feature(attribute_diagnose_if_objc)", \
"__attribute__((diagnose_if(1, Msg, \"warning\")))", \
"SWIFT_DEPRECATED_MSG(Msg)")

Expand Down
14 changes: 14 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4567,6 +4567,11 @@ bool NominalTypeDecl::isAnyActor() const {
return isActor() || isDistributedActor();
}

bool NominalTypeDecl::isMainActor() const {
return getName().is("MainActor") &&
getParentModule()->getName() == getASTContext().Id_Concurrency;
}

GenericTypeDecl::GenericTypeDecl(DeclKind K, DeclContext *DC,
Identifier name, SourceLoc nameLoc,
ArrayRef<InheritedEntry> inherited,
Expand Down Expand Up @@ -9614,6 +9619,15 @@ void swift::simple_display(llvm::raw_ostream &out, AnyFunctionRef fn) {
out << "closure";
}

bool ActorIsolation::isMainActor() const {
if (isGlobalActor()) {
if (auto *nominal = getGlobalActor()->getAnyNominal())
return nominal->isMainActor();
}

return false;
}

bool ActorIsolation::isDistributedActor() const {
return getKind() == ActorInstance && getActor()->isDistributedActor();
}
Expand Down
16 changes: 2 additions & 14 deletions lib/AST/DiagnosticEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,18 +576,6 @@ static bool typeSpellingIsAmbiguous(Type type,
return false;
}

/// Determine whether this is the main actor type.
static bool isMainActor(Type type) {
if (auto nominal = type->getAnyNominal()) {
if (nominal->getName().is("MainActor") &&
nominal->getParentModule()->getName() ==
nominal->getASTContext().Id_Concurrency)
return true;
}

return false;
}

void swift::printClangDeclName(const clang::NamedDecl *ND,
llvm::raw_ostream &os) {
ND->getNameForDiagnostic(os, ND->getASTContext().getPrintingPolicy(), false);
Expand Down Expand Up @@ -841,10 +829,10 @@ static void formatDiagnosticArgument(StringRef Modifier,

case ActorIsolation::GlobalActor:
case ActorIsolation::GlobalActorUnsafe: {
Type globalActor = isolation.getGlobalActor();
if (isMainActor(globalActor)) {
if (isolation.isMainActor()) {
Out << "main actor-isolated";
} else {
Type globalActor = isolation.getGlobalActor();
Out << "global actor " << FormatOpts.OpeningQuotationMark
<< globalActor.getString()
<< FormatOpts.ClosingQuotationMark << "-isolated";
Expand Down
3 changes: 3 additions & 0 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,9 @@ void ModuleDecl::getDisplayDecls(SmallVectorImpl<Decl*> &Results, bool Recursive
llvm::SmallDenseMap<ModuleDecl *, SmallPtrSet<Decl *, 4>, 4> QualifiedImports;
collectParsedExportedImports(this, Modules, QualifiedImports);
for (const auto &QI : QualifiedImports) {
auto Module = QI.getFirst();
if (Modules.contains(Module)) continue;

auto &Decls = QI.getSecond();
Results.append(Decls.begin(), Decls.end());
}
Expand Down
5 changes: 5 additions & 0 deletions lib/SILGen/SILGenProlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,11 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
!isInActorDestructor(FunctionDC) &&
!F.isDefer();

// FIXME: Avoid loading and checking the expected executor if concurrency is
// unavailable. This is specifically relevant for MainActor isolated contexts,
// which are allowed to be available on OSes where concurrency is not
// available. rdar://106827064

// Local function to load the expected executor from a local actor
auto loadExpectedExecutorForLocalVar = [&](VarDecl *var) {
auto loc = RegularLocation::getAutoGeneratedLocation(F.getLocation());
Expand Down
6 changes: 3 additions & 3 deletions lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ void AvailableValueAggregator::addHandOffCopyDestroysForPhis(
// Otherwise, we need to insert one last destroy after the load for our phi.
auto next = std::next(load->getIterator());
SILBuilderWithScope builder(next);
builder.emitDestroyValueOperation(next->getLoc(), phi);
builder.emitDestroyValueOperation(RegularLocation(next->getLoc()), phi);
}

// Alright! In summary, we just lifetime extended all of our phis,
Expand Down Expand Up @@ -1251,7 +1251,7 @@ void AvailableValueAggregator::addMissingDestroysForCopiedValues(
assert(li->getParent() == load->getParent());
auto next = std::next(load->getIterator());
SILBuilderWithScope builder(next);
builder.emitDestroyValueOperation(next->getLoc(), li);
builder.emitDestroyValueOperation(RegularLocation(next->getLoc()), li);
continue;
}
}
Expand Down Expand Up @@ -1301,7 +1301,7 @@ void AvailableValueAggregator::addMissingDestroysForCopiedValues(
// Otherwise, we need to insert one last destroy after the load for our phi.
auto next = std::next(load->getIterator());
SILBuilderWithScope builder(next);
builder.emitDestroyValueOperation(next->getLoc(), cvi);
builder.emitDestroyValueOperation(RegularLocation(next->getLoc()), cvi);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Utils/InstOptUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ void swift::insertDeallocOfCapturedArguments(PartialApplyInst *pai,
} else {
insertionPoint = terminator;
}
auto builder = SILBuilder(insertionPoint);
SILBuilderWithScope builder(insertionPoint);
builder.createDeallocStack(CleanupLocation(insertionPoint->getLoc()),
arg.get());
}
Expand Down
20 changes: 15 additions & 5 deletions lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,13 +1744,23 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
explicit DeclAvailabilityChecker(ExportContext where)
: Where(where) {}

void checkGlobalActor(Decl *D) {
auto globalActor = D->getGlobalActorAttr();
if (!globalActor)
return;

// Avoid checking the availability for a @MainActor constraint since it does
// not carry an inherent ABI impact.
if (globalActor->second->isMainActor())
return;

auto customAttr = globalActor->first;
checkType(customAttr->getType(), customAttr->getTypeRepr(), D);
}

void visit(Decl *D) {
DeclVisitor<DeclAvailabilityChecker>::visit(D);

if (auto globalActor = D->getGlobalActorAttr()) {
auto customAttr = globalActor->first;
checkType(customAttr->getType(), customAttr->getTypeRepr(), D);
}
checkGlobalActor(D);
}

// Force all kinds to be handled at a lower level.
Expand Down
11 changes: 1 addition & 10 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3538,15 +3538,6 @@ void AttributeChecker::visitFrozenAttr(FrozenAttr *attr) {
}
}

/// Determine whether this is the main actor type.
/// FIXME: the diagnostics engine and TypeCheckConcurrency both have a copy of
/// this
static bool isMainActor(NominalTypeDecl *nominal) {
return nominal->getName().is("MainActor") &&
nominal->getParentModule()->getName() ==
nominal->getASTContext().Id_Concurrency;
}

void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
auto dc = D->getDeclContext();

Expand Down Expand Up @@ -3582,7 +3573,7 @@ void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
return;
}

if (isMainActor(nominal) && Ctx.LangOpts.isConcurrencyModelTaskToThread() &&
if (nominal->isMainActor() && Ctx.LangOpts.isConcurrencyModelTaskToThread() &&
!AvailableAttr::isUnavailable(D)) {
Ctx.Diags.diagnose(attr->getLocation(),
diag::concurrency_task_to_thread_model_main_actor,
Expand Down
9 changes: 2 additions & 7 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,14 +1193,9 @@ void swift::diagnoseMissingExplicitSendable(NominalTypeDecl *nominal) {
}

/// Determine whether this is the main actor type.
/// FIXME: the diagnostics engine has a copy of this.
static bool isMainActor(Type type) {
if (auto nominal = type->getAnyNominal()) {
if (nominal->getName().is("MainActor") &&
nominal->getParentModule()->getName() ==
nominal->getASTContext().Id_Concurrency)
return true;
}
if (auto nominal = type->getAnyNominal())
return nominal->isMainActor();

return false;
}
Expand Down
8 changes: 4 additions & 4 deletions test/SILOptimizer/closure-lifetime-fixup.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-sil-verify-all -closure-lifetime-fixup %s | %FileCheck %s
// RUN: %target-sil-opt -enable-sil-verify-all -sil-print-debuginfo -closure-lifetime-fixup %s | %FileCheck %s

sil_stage raw

Expand Down Expand Up @@ -261,16 +261,16 @@ bb3:
// CHECK: [[STACK:%[^,]+]] = alloc_stack $Self
// CHECK: try_apply undef() {{.*}}, normal [[SUCCESS_1:bb[0-9]+]], error [[FAILURE_1:bb[0-9]+]]
// CHECK: [[SUCCESS_1]]
// CHECK: copy_addr [[INSTANCE]] to [init] [[STACK]] : $*Self
// CHECK: copy_addr [[INSTANCE]] to [init] [[STACK]] : $*Self, {{.*}} scope [[STACK_SCOPE:[0-9]+]]
// CHECK: [[CLOSURE:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] undef<Self>([[STACK]])
// CHECK: [[DEPENDENCY:%[^,]+]] = mark_dependence [[CLOSURE]] {{.*}} on [[STACK]]
// CHECK: try_apply undef([[DEPENDENCY]]) {{.*}}, normal [[SUCCESS_2:bb[0-9]+]], error [[FAILURE_2:bb[0-9]+]]
// CHECK: [[SUCCESS_2]]
// CHECK: dealloc_stack [[CLOSURE]]
// CHECK: destroy_addr [[STACK]]
// CHECK: dealloc_stack [[STACK]] : $*Self
// CHECK: dealloc_stack [[STACK]] : $*Self, {{.*}} scope [[STACK_SCOPE]]
// CHECK: [[FAILURE_1]]
// CHECK: dealloc_stack [[STACK]]
// CHECK: dealloc_stack [[STACK]] : $*Self, {{.*}} scope [[STACK_SCOPE]]
// CHECK: throw
// CHECK: [[FAILURE_2]]
// CHECK-NOT: dealloc_stack
Expand Down
20 changes: 20 additions & 0 deletions test/Sema/availability_main_actor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %target-typecheck-verify-swift

// REQUIRES: concurrency

// This test is meant to verify that a @MainActor constraint is accepted without
// any availability restrictions for all targets.

@MainActor
struct AlwaysAvailable {}

@MainActor(unsafe)
struct AlwaysAvailableUnsafe {}

@available(SwiftStdlib 5.1, *)
@MainActor
struct AvailableSwift5_1 {}

@available(SwiftStdlib 5.1, *)
@MainActor(unsafe)
struct AvailableSwift5_1Unsafe {}
11 changes: 11 additions & 0 deletions test/SymbolGraph/Module/DuplicateExportedImport.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %S/Inputs/DuplicateExportedImport/A.swift -module-name A -emit-module -emit-module-path %t/A.swiftmodule
// 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/
// RUN: %FileCheck %s --input-file %t/DuplicateExportedImport.symbols.json

// REQUIRES: asserts

// CHECK-COUNT-1: "precise":"s:1A8ClassTwoC"

@_exported import A
@_exported import class A.ClassTwo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class ClassOne {}

public class ClassTwo {}
3 changes: 3 additions & 0 deletions test/stdlib/NSStringAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// Tests for the NSString APIs as exposed by String
//

// Temporarily disabled as it is taking too long to execute.
// REQUIRES: rdar106755810

import StdlibUnittest


Expand Down
14 changes: 14 additions & 0 deletions validation-test/ParseableInterface/unsafe-mainactor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
// RUN: %FileCheck %s < %t/Library.swiftinterface

// REQUIRES: OS=macosx

import AppKit

// CHECK: @objc @_inheritsConvenienceInitializers @_Concurrency.MainActor(unsafe) public class Subclass : AppKit.NSView {
public class Subclass: NSView {
// CHECK: @_Concurrency.MainActor(unsafe) @objc override dynamic public init(frame frameRect: Foundation.NSRect)
// CHECK: @_Concurrency.MainActor(unsafe) @objc required dynamic public init?(coder: Foundation.NSCoder)
}