Skip to content

Commit 5a46464

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents f36485e + 213ad8a commit 5a46464

File tree

12 files changed

+163
-87
lines changed

12 files changed

+163
-87
lines changed

Runtimes/Core/Concurrency/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ add_library(swift_Concurrency
1616
ExecutorImpl.cpp
1717
ExecutorChecks.cpp
1818
GlobalExecutor.cpp
19-
Setup.cpp
2019
Task.cpp
2120
TaskAlloc.cpp
2221
TaskGroup.cpp

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,17 +1451,11 @@ FunctionType::ExtInfo ClosureEffectsRequest::evaluate(
14511451
if (!body)
14521452
return ASTExtInfoBuilder().withSendable(sendable).build();
14531453

1454-
// `@concurrent` attribute is only valid on asynchronous function types.
1455-
bool asyncFromAttr = false;
1456-
if (expr->getAttrs().hasAttribute<ConcurrentAttr>()) {
1457-
asyncFromAttr = true;
1458-
}
1459-
14601454
auto throwFinder = FindInnerThrows(expr);
14611455
body->walk(throwFinder);
14621456
return ASTExtInfoBuilder()
14631457
.withThrows(throwFinder.foundThrow(), /*FIXME:*/Type())
1464-
.withAsync(asyncFromAttr || bool(findAsyncNode(expr)))
1458+
.withAsync(bool(findAsyncNode(expr)))
14651459
.withSendable(sendable)
14661460
.build();
14671461
}

lib/Sema/MiscDiagnostics.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
305305
}
306306
}
307307

308+
// Performs checks on a closure.
309+
if (auto *closure = dyn_cast<ClosureExpr>(E)) {
310+
checkClosure(closure);
311+
}
312+
308313
// Specially diagnose some checked casts that are illegal.
309314
if (auto cast = dyn_cast<CheckedCastExpr>(E)) {
310315
checkCheckedCastExpr(cast);
@@ -1455,6 +1460,33 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
14551460
}
14561461
}
14571462
}
1463+
1464+
void checkClosure(ClosureExpr *closure) {
1465+
if (closure->isImplicit()) {
1466+
return;
1467+
}
1468+
1469+
auto attr = closure->getAttrs().getAttribute<ConcurrentAttr>();
1470+
if (!attr) {
1471+
return;
1472+
}
1473+
1474+
if (closure->getAsyncLoc().isValid()) {
1475+
return;
1476+
}
1477+
1478+
if (closure->getType()->castTo<AnyFunctionType>()->isAsync()) {
1479+
return;
1480+
}
1481+
1482+
// `@concurrent` is not allowed on synchronous closures, but this is
1483+
// likely to change, so diagnose this here, post solution application,
1484+
// instead of introducing an "implies `async`" inference rule that won't
1485+
// make sense in the nearish future.
1486+
Ctx.Diags.diagnose(attr->getLocation(),
1487+
diag::execution_behavior_only_on_async_closure, attr);
1488+
attr->setInvalid();
1489+
}
14581490
};
14591491

14601492
DiagnoseWalker Walker(DC, isExprStmt);

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8296,16 +8296,6 @@ class ClosureAttributeChecker
82968296
}
82978297

82988298
void checkExecutionBehaviorAttribute(DeclAttribute *attr) {
8299-
// execution behavior attribute implies `async`.
8300-
if (closure->hasExplicitResultType() &&
8301-
closure->getAsyncLoc().isInvalid()) {
8302-
ctx.Diags
8303-
.diagnose(attr->getLocation(),
8304-
diag::execution_behavior_only_on_async_closure, attr)
8305-
.fixItRemove(attr->getRangeWithAt());
8306-
attr->setInvalid();
8307-
}
8308-
83098299
if (auto actorType = getExplicitGlobalActor(closure)) {
83108300
ctx.Diags
83118301
.diagnose(

lib/Sema/TypeCheckStmt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,9 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
10911091
if (resultTarget) {
10921092
RS->setResult(resultTarget->getAsExpr());
10931093
} else {
1094+
// Update the expression even if type-checking failed as e.g pre-checking
1095+
// may have folded a sequence expr.
1096+
RS->setResult(target.getAsExpr());
10941097
tryDiagnoseUnnecessaryCastOverOptionSet(getASTContext(), RS->getResult(),
10951098
ResultTy);
10961099
}

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ set(SWIFT_RUNTIME_CONCURRENCY_C_SOURCES
8484
Error.cpp
8585
ExecutorBridge.cpp
8686
ExecutorChecks.cpp
87-
Setup.cpp
8887
Task.cpp
8988
TaskAlloc.cpp
9089
TaskStatus.cpp

stdlib/public/Concurrency/Setup.cpp

Lines changed: 0 additions & 56 deletions
This file was deleted.

stdlib/public/Concurrency/Task.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,60 @@ static void swift_task_startOnMainActorImpl(AsyncTask* task) {
18751875
_swift_task_setCurrent(originalTask);
18761876
}
18771877

1878+
// ==== Load-time setup code ----------------------------------------------------
1879+
//
1880+
// The ctor below is placed here so that it must always be linked into the final
1881+
// image even if the libswift_Concurrency is linked in as a static library.
1882+
1883+
#if !SWIFT_CONCURRENCY_EMBEDDED
1884+
1885+
// Helper macros for figuring out the mangled name of a context descriptor.
1886+
#define DESCRIPTOR_MANGLING_SUFFIX_Structure Mn
1887+
#define DESCRIPTOR_MANGLING_SUFFIX_Class Mn
1888+
#define DESCRIPTOR_MANGLING_SUFFIX_Enum Mn
1889+
#define DESCRIPTOR_MANGLING_SUFFIX_Protocol Mp
1890+
1891+
#define DESCRIPTOR_MANGLING_SUFFIX_(X) X
1892+
#define DESCRIPTOR_MANGLING_SUFFIX(KIND) \
1893+
DESCRIPTOR_MANGLING_SUFFIX_(DESCRIPTOR_MANGLING_SUFFIX_##KIND)
1894+
1895+
#define DESCRIPTOR_MANGLING_(CHAR, SUFFIX) $sSc##CHAR##SUFFIX
1896+
#define DESCRIPTOR_MANGLING(CHAR, SUFFIX) DESCRIPTOR_MANGLING_(CHAR, SUFFIX)
1897+
1898+
// Declare context descriptors for all of the concurrency descriptors with
1899+
// standard manglings.
1900+
#define STANDARD_TYPE(KIND, MANGLING, TYPENAME)
1901+
#define STANDARD_TYPE_CONCURRENCY(KIND, MANGLING, TYPENAME) \
1902+
extern "C" const swift::ContextDescriptor DESCRIPTOR_MANGLING( \
1903+
MANGLING, DESCRIPTOR_MANGLING_SUFFIX(KIND));
1904+
#include "swift/Demangling/StandardTypesMangling.def"
1905+
1906+
// Defined in Swift, redeclared here so we can register it with the runtime.
1907+
extern "C" SWIFT_CC(swift)
1908+
bool _swift_task_isCurrentGlobalActor(
1909+
const swift::Metadata *, const swift::WitnessTable *);
1910+
1911+
// Register our type descriptors with standard manglings when the concurrency
1912+
// runtime is loaded. This allows the runtime to quickly resolve those standard
1913+
// manglings.
1914+
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_BEGIN
1915+
__attribute__((constructor)) static void setupStandardConcurrencyDescriptors() {
1916+
static const swift::ConcurrencyStandardTypeDescriptors descriptors = {
1917+
#define STANDARD_TYPE(KIND, MANGLING, TYPENAME)
1918+
#define STANDARD_TYPE_CONCURRENCY(KIND, MANGLING, TYPENAME) \
1919+
&DESCRIPTOR_MANGLING(MANGLING, DESCRIPTOR_MANGLING_SUFFIX(KIND)),
1920+
#include "swift/Demangling/StandardTypesMangling.def"
1921+
};
1922+
_swift_registerConcurrencyRuntime(
1923+
&descriptors,
1924+
&_swift_task_isCurrentGlobalActor);
1925+
}
1926+
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_END
1927+
1928+
#endif
1929+
1930+
// ==== Back-deploy hooks -------------------------------------------------------
1931+
18781932
#define OVERRIDE_TASK COMPATIBILITY_OVERRIDE
18791933

18801934
#ifdef SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT

test/Concurrency/Runtime/isolated_conformance.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
// REQUIRES: concurrency_runtime
66
// UNSUPPORTED: back_deployment_runtime
77

8-
// FIXME: WebAssembly doesn't currently have a good way to install the
9-
// "isCurrentGlobalActor" hook on which this checking depends. Disable
10-
// the test for the moment.
11-
// UNSUPPORTED: wasm
12-
// UNSUPPORTED: CPU=wasm32
13-
148
protocol P {
159
func f()
1610
}
@@ -208,6 +202,10 @@ await Task.detached { @SomeGlobalActor in
208202
print("Testing a separate task off the main actor")
209203
await Task.detached {
210204
if #available(SwiftStdlib 6.2, *) {
205+
// Skip tests on platforms that use the same executor for the main
206+
// actor and the global concurrent executor.
207+
guard Task.defaultExecutor !== MainActor.executor else { return }
208+
211209
precondition(!tryCastToP(mc))
212210
precondition(!tryCastToP(wrappedMC))
213211

test/Concurrency/attr_execution/conversions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ do {
9393

9494
do {
9595
let _: () -> Void = { @concurrent in
96-
// expected-error@-1 {{invalid conversion from 'async' function of type '() async -> Void' to synchronous function type '() -> Void'}}
96+
// expected-error@-1 {{cannot use @concurrent on non-async closure}}{{none}}
9797
}
9898
}
9999

0 commit comments

Comments
 (0)