Skip to content

Commit fc46c00

Browse files
committed
Inherit main thread priority/context
This patch changes the main task to inherit the context of the main thread. This should assign the appropriate priority based on how the program was invoked. I've also updated the tests to reflect these changes.
1 parent b416a1a commit fc46c00

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

lib/SILGen/SILGenFunction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
946946

947947
// Emit the CreateAsyncTask builtin
948948
TaskCreateFlags taskCreationFlagMask(0);
949+
taskCreationFlagMask.setInheritContext(true);
949950
SILValue taskFlags =
950951
emitWrapIntegerLiteral(moduleLoc, getLoweredType(ctx.getIntType()),
951952
taskCreationFlagMask.getOpaqueValue());

test/Concurrency/Runtime/async_task_priority_current.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension TaskPriority: CustomStringConvertible {
2020
@available(SwiftStdlib 5.5, *)
2121
func test_detach() async {
2222
let a1 = Task.currentPriority
23-
print("a1: \(a1)") // CHECK: TaskPriority(rawValue: 21)
23+
print("a1: \(a1)") // CHECK: TaskPriority(rawValue: 25)
2424

2525
// Note: remember to detach using a higher priority, otherwise a lower one
2626
// might be escalated by the get() and we could see `default` in the detached
@@ -31,7 +31,7 @@ func test_detach() async {
3131
}.get()
3232

3333
let a3 = Task.currentPriority
34-
print("a3: \(a3)") // CHECK: a3: TaskPriority(rawValue: 21)
34+
print("a3: \(a3)") // CHECK: a3: TaskPriority(rawValue: 25)
3535
}
3636

3737
@available(SwiftStdlib 5.5, *)

test/Concurrency/async_main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func asyncFunc() async {
5656

5757
// CHECK-SIL: // function_ref async_Main
5858
// CHECK-SIL-NEXT: %2 = function_ref @async_Main : $@convention(thin) @async () -> ()
59-
// CHECK-SIL-NEXT: %3 = integer_literal $Builtin.Int64, 21
59+
// CHECK-SIL-NEXT: %3 = integer_literal $Builtin.Int64, 2048
6060
// CHECK-SIL-NEXT: %4 = struct $Int (%3 : $Builtin.Int64)
6161
// CHECK-SIL-NEXT: %5 = metatype $@thick ().Type
6262
// CHECK-SIL-NEXT: %6 = init_existential_metatype %5 : $@thick ().Type, $@thick Any.Type

0 commit comments

Comments
 (0)