@@ -8,7 +8,7 @@ func applyBackground(_ color: ColorComponents) {
8
8
}
9
9
10
10
#if swift(<6.0)
11
- /// A non-isolated function that accepts non-`Sendable` parameters.
11
+ /// A non-isolated function that accepts non-`Sendable` parameters.
12
12
func updateStyle( backgroundColor: ColorComponents ) async {
13
13
// the `backgroundColor` parameter is being moved from the
14
14
// non-isolated domain to the `MainActor` here.
@@ -19,6 +19,13 @@ func updateStyle(backgroundColor: ColorComponents) async {
19
19
}
20
20
#endif
21
21
22
+ #if swift(>=6.0)
23
+ /// A non-isolated function that accepts non-`Sendable` parameters which must be safe to use at callsites.
24
+ func sending_updateStyle( backgroundColor: sending ColorComponents) async {
25
+ await applyBackground ( backgroundColor)
26
+ }
27
+ #endif
28
+
22
29
// MARK: Latent Isolation
23
30
24
31
/// MainActor-isolated function that accepts non-`Sendable` parameters.
@@ -96,13 +103,35 @@ actor Style {
96
103
}
97
104
}
98
105
106
+ // MARK: Manual Synchronization
107
+
108
+ extension RetroactiveColorComponents : @retroactive @unchecked Sendable {
109
+ }
110
+
111
+ /// An overload used by `retroactive_updateStyle` to match types.
112
+ @MainActor
113
+ func applyBackground( _ color: RetroactiveColorComponents ) {
114
+ }
115
+
116
+ /// A non-isolated function that accepts retroactively-`Sendable` parameters.
117
+ func retroactive_updateStyle( backgroundColor: RetroactiveColorComponents ) async {
118
+ await applyBackground ( backgroundColor)
119
+ }
120
+
99
121
func exerciseBoundaryCrossingExamples( ) async {
100
122
print ( " Isolation Boundary Crossing Examples " )
101
123
102
124
#if swift(<6.0)
103
125
print ( " - updateStyle(backgroundColor:) passing its argument unsafely " )
104
126
#endif
105
127
128
+ #if swift(>=6.0)
129
+ print ( " - using sending to allow safe usage of ColorComponents " )
130
+ let nonSendableComponents = ColorComponents ( )
131
+
132
+ await sending_updateStyle ( backgroundColor: nonSendableComponents)
133
+ #endif
134
+
106
135
print ( " - using ColorComponents only from the main actor " )
107
136
let t1 = Task { @MainActor in
108
137
let components = ColorComponents ( )
@@ -137,4 +166,9 @@ func exerciseBoundaryCrossingExamples() async {
137
166
let actor = Style ( background: actorComponents)
138
167
139
168
await actor . applyBackground ( )
169
+
170
+ print ( " - using a retroactive unchecked Sendable argument " )
171
+ let retroactiveComponents = RetroactiveColorComponents ( )
172
+
173
+ await retroactive_updateStyle ( backgroundColor: retroactiveComponents)
140
174
}
0 commit comments