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) {
611
611
actorType->getTypeOfMember (SGM.SwiftModule , sharedInstanceDecl);
612
612
613
613
auto metaRepr =
614
- nominal->isResilient (SGM.SwiftModule , ResilienceExpansion::Maximal )
614
+ nominal->isResilient (SGM.SwiftModule , F. getResilienceExpansion () )
615
615
? MetatypeRepresentation::Thick
616
616
: MetatypeRepresentation::Thin;
617
617
Original file line number Diff line number Diff line change @@ -45,14 +45,26 @@ import Swift
45
45
@available ( SwiftStdlib 5 . 5 , * )
46
46
extension MainActor {
47
47
/// 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> (
49
55
resultType: T . Type = T . self,
50
56
body: @MainActor @Sendable ( ) throws -> T
51
57
) 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
+ }
55
60
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 ( )
57
69
}
58
70
}
Original file line number Diff line number Diff line change @@ -80,6 +80,10 @@ actor A {
80
80
// CHECK-NOT: ERROR
81
81
// CHECK: finished with return counter = 4
82
82
83
+ // CHECK: detached task not on main queue
84
+ // CHECK: on main queue again
85
+ // CHECK: detached task hopped back
86
+
83
87
@main struct RunIt {
84
88
static func main( ) async {
85
89
print ( " starting " )
@@ -90,5 +94,25 @@ actor A {
90
94
}
91
95
let result = await someFunc ( )
92
96
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
93
117
}
94
118
}
You can’t perform that action at this time.
0 commit comments