Skip to content

Commit 4957a5e

Browse files
authored
Merge pull request swiftlang#34969 from DougGregor/swift_get_jobflags
[Concurrency] Traffic in underlying C type rather than JobFlags.
2 parents 8914ba6 + 105a273 commit 4957a5e

File tree

16 files changed

+45
-24
lines changed

16 files changed

+45
-24
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,8 @@ ERROR(super_in_closure_with_capture,none,
12221222
NOTE(super_in_closure_with_capture_here,none,
12231223
"'self' explicitly captured here", ())
12241224

1225+
ERROR(try_before_await,none, "'await' must precede 'try'", ())
1226+
12251227
// Tuples and parenthesized expressions
12261228
ERROR(expected_expr_in_expr_list,none,
12271229
"expected expression in list of expressions", ())

include/swift/Runtime/Concurrency.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ bool swift_task_removeStatusRecord(AsyncTask *task,
175175
TaskStatusRecord *record);
176176

177177
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
178-
JobFlags
179-
swift_task_getJobFlags(AsyncTask* task);
178+
size_t swift_task_getJobFlags(AsyncTask* task);
180179

181180
/// This should have the same representation as an enum like this:
182181
/// enum NearestTaskDeadline {

lib/Parse/ParseExpr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,13 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
436436
: parseExprUnary(message, isExprBasic);
437437

438438
if (hadTry && !sub.hasCodeCompletion() && !sub.isNull()) {
439+
// "await" must precede "try".
440+
if (auto await = dyn_cast<AwaitExpr>(sub.get())) {
441+
diagnose(await->getLoc(), diag::try_before_await)
442+
.fixItRemove(await->getLoc())
443+
.fixItInsert(tryLoc, "await ");
444+
}
445+
439446
ElementContext.setCreateSyntax(SyntaxKind::TryExpr);
440447
switch (trySuffix ? trySuffix->getKind() : tok::NUM_TOKENS) {
441448
case tok::exclaim_postfix:

lib/Sema/TypeCheckEffects.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,9 @@ class Context {
985985
}
986986

987987
static Context forTopLevelCode(TopLevelCodeDecl *D) {
988-
// Top-level code implicitly handles errors and 'async' calls.
989-
return Context(/*handlesErrors=*/true, /*handlesAsync=*/true, None);
988+
// Top-level code implicitly handles errors.
989+
// TODO: Eventually, it will handle async as well.
990+
return Context(/*handlesErrors=*/true, /*handlesAsync=*/false, None);
990991
}
991992

992993
static Context forFunction(AbstractFunctionDecl *D) {

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public func withUnsafeContinuation<T>(
8989
public func withUnsafeThrowingContinuation<T>(
9090
_ fn: (UnsafeThrowingContinuation<T>) -> Void
9191
) async throws -> T {
92-
return try await Builtin.withUnsafeThrowingContinuation {
92+
return await try Builtin.withUnsafeThrowingContinuation {
9393
fn(UnsafeThrowingContinuation<T>($0))
9494
}
95-
}
95+
}

stdlib/public/Concurrency/Task.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,6 @@ void swift::swift_task_run(AsyncTask *taskToRun) {
352352
taskToRun->run(ExecutorRef::generic());
353353
}
354354

355-
JobFlags swift::swift_task_getJobFlags(AsyncTask *task) {
356-
return task->Flags;
355+
size_t swift::swift_task_getJobFlags(AsyncTask *task) {
356+
return task->Flags.getOpaqueValue();
357357
}

test/ClangImporter/objc_async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ObjCConcurrency
88
func testSlowServer(slowServer: SlowServer) async throws {
99
let _: Int = await slowServer.doSomethingSlow("mail")
1010
let _: Bool = await slowServer.checkAvailability()
11-
let _: String = try await slowServer.findAnswer()
11+
let _: String = await try slowServer.findAnswer()
1212
let _: String = await try slowServer.findAnswerFailingly()
1313
let _: Void = await slowServer.doSomethingFun("jump")
1414
let _: (Int) -> Void = slowServer.completionHandler

test/Concurrency/async_tasks.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ func test_unsafeContinuations() async {
5454
}
5555

5656
func test_unsafeThrowingContinuations() async {
57-
let _: String = try await Task.withUnsafeThrowingContinuation { continuation in
57+
let _: String = await try Task.withUnsafeThrowingContinuation { continuation in
5858
continuation.resume(returning: "")
5959
}
6060

61-
let _: String = try await Task.withUnsafeThrowingContinuation { continuation in
61+
let _: String = await try Task.withUnsafeThrowingContinuation { continuation in
6262
continuation.resume(throwing: MyError())
6363
}
6464

test/IRGen/async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public func task_future_wait(_ task: __owned SomeClass) async throws -> Int
1919
// CHECK: tail call swiftcc void @swift_task_future_wait(
2020
public func testThis(_ task: __owned SomeClass) async {
2121
do {
22-
let _ = try await task_future_wait(task)
22+
let _ = await try task_future_wait(task)
2323
} catch _ {
2424
print("error")
2525
}

test/SILGen/async_builtins.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public func usesWithUnsafeContinuation() async {
9393

9494
// CHECK-LABEL: sil [ossa] @$s4test34usesWithUnsafeThrowingContinuationyyYKF : $@convention(thin) @async () -> @error Error {
9595
public func usesWithUnsafeThrowingContinuation() async throws {
96-
let _: Int = try await Builtin.withUnsafeThrowingContinuation { c in }
96+
let _: Int = await try Builtin.withUnsafeThrowingContinuation { c in }
9797

9898
// CHECK: [[FN:%.*]] = function_ref @$s4test34usesWithUnsafeThrowingContinuationyyYKFyBcXEfU_ : $@convention(thin) (Builtin.RawUnsafeContinuation) -> ()
9999
// CHECK: [[TMP:%.*]] = convert_function [[FN]] : $@convention(thin) (Builtin.RawUnsafeContinuation) -> () to $@convention(thin) @noescape (Builtin.RawUnsafeContinuation) -> ()
@@ -117,4 +117,4 @@ public func usesWithUnsafeThrowingContinuation() async throws {
117117
// because it has captures and was formed by a partial_apply.
118118
public func usesWithUnsafeContinuationCaptures(fn: (Builtin.RawUnsafeContinuation) -> ()) async throws {
119119
let _: Int = await Builtin.withUnsafeContinuation { c in fn(c) }
120-
}
120+
}

0 commit comments

Comments
 (0)