Skip to content

Commit f53226a

Browse files
committed
Fix resilience of global actor hops and test MainActor.run.
1 parent f307d20 commit f53226a

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ SILValue SILGenFunction::emitLoadGlobalActorExecutor(Type globalActor) {
611611
actorType->getTypeOfMember(SGM.SwiftModule, sharedInstanceDecl);
612612

613613
auto metaRepr =
614-
nominal->isResilient(SGM.SwiftModule, ResilienceExpansion::Maximal)
614+
nominal->isResilient(SGM.SwiftModule, F.getResilienceExpansion())
615615
? MetatypeRepresentation::Thick
616616
: MetatypeRepresentation::Thin;
617617

stdlib/public/Concurrency/MainActor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extension MainActor {
5959
}
6060

6161
/// Execute the given body closure on the main actor.
62+
@_silgen_name("$sScM12runAndReturn10resultType4bodyxxm_xyYbKScMYcXEtYaKlFZ")
6263
@_alwaysEmitIntoClient
6364
public static func run<T>(
6465
resultType: T.Type = T.self,

test/Concurrency/Runtime/mainactor.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ actor A {
8080
// CHECK-NOT: ERROR
8181
// CHECK: finished with return counter = 4
8282

83+
// CHECK: detached task not on main queue
84+
// CHECK: on main queue again
85+
// CHECK: detached task hopped back
86+
8387
@main struct RunIt {
8488
static func main() async {
8589
print("starting")
@@ -90,5 +94,25 @@ actor A {
9094
}
9195
let result = await someFunc()
9296
print("finished with return counter = \(result)")
97+
98+
// Check actor hopping with MainActor.run.
99+
let task = Task.detached {
100+
if checkIfMainQueue(expectedAnswer: false) {
101+
print("detached task not on main queue")
102+
} else {
103+
print("ERROR: detached task is on the main queue?")
104+
}
105+
106+
_ = await MainActor.run {
107+
checkAnotherFn(1)
108+
}
109+
110+
if checkIfMainQueue(expectedAnswer: false) {
111+
print("detached task hopped back")
112+
} else {
113+
print("ERROR: detached task is on the main queue?")
114+
}
115+
}
116+
_ = await task.value
93117
}
94118
}

0 commit comments

Comments
 (0)