File tree Expand file tree Collapse file tree 3 files changed +42
-6
lines changed
stdlib/public/Concurrency Expand file tree Collapse file tree 3 files changed +42
-6
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -45,14 +45,26 @@ import Swift
4545@available ( SwiftStdlib 5 . 5 , * )
4646extension MainActor {
4747 /// Execute the given body closure on the main actor.
48- public static func run< T> (
48+ ///
49+ /// Historical ABI entry point, superceded by the Sendable version that is
50+ /// also inlined to back-deploy a semantic fix where this operation would
51+ /// not hop back at the end.
52+ @_silgen_name ( " $sScM3run10resultType4bodyxxm_xyYbKScMYcXEtYaKlFZ " )
53+ @usableFromInline
54+ static func _historicalRunForABI< T> (
4955 resultType: T . Type = T . self,
5056 body: @MainActor @Sendable ( ) throws -> T
5157 ) async rethrows -> T {
52- @MainActor func runOnMain( body: @MainActor @Sendable ( ) throws -> T ) async rethrows -> T {
53- return try body ( )
54- }
58+ return try await body ( )
59+ }
5560
56- return try await runOnMain ( body: body)
61+ /// Execute the given body closure on the main actor.
62+ @_silgen_name ( " $sScM12runAndReturn10resultType4bodyxxm_xyYbKScMYcXEtYaKlFZ " )
63+ @_alwaysEmitIntoClient
64+ public static func run< T> (
65+ resultType: T . Type = T . self,
66+ body: @MainActor @Sendable ( ) throws -> T
67+ ) async rethrows -> T {
68+ return try await body ( )
5769 }
5870}
Original file line number Diff line number Diff line change @@ -81,6 +81,10 @@ actor A {
8181// CHECK-NOT: ERROR
8282// CHECK: finished with return counter = 4
8383
84+ // CHECK: detached task not on main queue
85+ // CHECK: on main queue again
86+ // CHECK: detached task hopped back
87+
8488@main struct RunIt {
8589 static func main( ) async {
8690 print ( " starting " )
@@ -91,5 +95,25 @@ actor A {
9195 }
9296 let result = await someFunc ( )
9397 print ( " finished with return counter = \( result) " )
98+
99+ // Check actor hopping with MainActor.run.
100+ let task = Task . detached {
101+ if checkIfMainQueue ( expectedAnswer: false ) {
102+ print ( " detached task not on main queue " )
103+ } else {
104+ print ( " ERROR: detached task is on the main queue? " )
105+ }
106+
107+ _ = await MainActor . run {
108+ checkAnotherFn ( 1 )
109+ }
110+
111+ if checkIfMainQueue ( expectedAnswer: false ) {
112+ print ( " detached task hopped back " )
113+ } else {
114+ print ( " ERROR: detached task is on the main queue? " )
115+ }
116+ }
117+ _ = await task. value
94118 }
95119}
You can’t perform that action at this time.
0 commit comments