Skip to content

Commit b1716fe

Browse files
authored
Re-add sendable annotations (#740)
* (131556645) Restore sendable annotations * (131556645) Fix build failures
1 parent 892d3c5 commit b1716fe

File tree

10 files changed

+527
-136
lines changed

10 files changed

+527
-136
lines changed

Sources/FoundationEssentials/AttributedString/AttributeScope.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public enum AttributeScopes { }
3131

3232
import Darwin
3333
internal import MachO.dyld
34-
@preconcurrency internal import ReflectionInternal
34+
internal import ReflectionInternal
3535

3636
fileprivate struct ScopeDescription : Sendable {
3737
var attributes: [String : any AttributedStringKey.Type] = [:]

Sources/FoundationEssentials/AttributedString/AttributedString+AttributeTransformation.swift

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ extension AttributedString {
5252
andChanged changed: AttributedString.SingleAttributeTransformer<K>,
5353
to attrStr: inout AttributedString,
5454
key: K.Type
55-
) {
55+
)
56+
where
57+
K.Value : Sendable {
5658
if orig.range != changed.range || orig.attrName != changed.attrName {
5759
attrStr._guts.removeAttributeValue(forKey: K.self, in: orig.range._bstringRange) // If the range changed, we need to remove from the old range first.
5860
}
@@ -63,7 +65,7 @@ extension AttributedString {
6365
andChanged changed: AttributedString.SingleAttributeTransformer<K>,
6466
to attrStr: inout AttributedString,
6567
key: K.Type
66-
) {
68+
) where K.Value : Sendable {
6769
if orig.range != changed.range || orig.attrName != changed.attrName || orig.attr != changed.attr {
6870
if let newVal = changed.attr { // Then if there's a new value, we add it in.
6971
// Unfortunately, we can't use the attrStr[range].set() provided by the AttributedStringProtocol, because we *don't know* the new type statically!
@@ -78,10 +80,13 @@ extension AttributedString {
7880

7981
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
8082
extension AttributedString {
83+
@preconcurrency
8184
public func transformingAttributes<K>(
8285
_ k: K.Type,
8386
_ c: (inout AttributedString.SingleAttributeTransformer<K>) -> Void
84-
) -> AttributedString {
87+
) -> AttributedString
88+
where
89+
K.Value : Sendable {
8590
let orig = AttributedString(_guts)
8691
var copy = orig
8792
copy.ensureUniqueReference() // ???: Is this best practice? We're going behind the back of the AttributedString mutation API surface, so it doesn't happen anywhere else. It's also aggressively speculative.
@@ -95,12 +100,16 @@ extension AttributedString {
95100
return copy
96101
}
97102

103+
@preconcurrency
98104
public func transformingAttributes<K1, K2>(
99105
_ k: K1.Type,
100106
_ k2: K2.Type,
101107
_ c: (inout AttributedString.SingleAttributeTransformer<K1>,
102108
inout AttributedString.SingleAttributeTransformer<K2>) -> Void
103-
) -> AttributedString {
109+
) -> AttributedString
110+
where
111+
K1.Value : Sendable,
112+
K2.Value : Sendable {
104113
let orig = AttributedString(_guts)
105114
var copy = orig
106115
copy.ensureUniqueReference() // ???: Is this best practice? We're going behind the back of the AttributedString mutation API surface, so it doesn't happen anywhere else. It's also aggressively speculative.
@@ -118,14 +127,19 @@ extension AttributedString {
118127
return copy
119128
}
120129

130+
@preconcurrency
121131
public func transformingAttributes<K1, K2, K3>(
122132
_ k: K1.Type,
123133
_ k2: K2.Type,
124134
_ k3: K3.Type,
125135
_ c: (inout AttributedString.SingleAttributeTransformer<K1>,
126136
inout AttributedString.SingleAttributeTransformer<K2>,
127137
inout AttributedString.SingleAttributeTransformer<K3>) -> Void
128-
) -> AttributedString {
138+
) -> AttributedString
139+
where
140+
K1.Value : Sendable,
141+
K2.Value : Sendable,
142+
K3.Value : Sendable {
129143
let orig = AttributedString(_guts)
130144
var copy = orig
131145
copy.ensureUniqueReference() // ???: Is this best practice? We're going behind the back of the AttributedString mutation API surface, so it doesn't happen anywhere else. It's also aggressively speculative.
@@ -147,6 +161,7 @@ extension AttributedString {
147161
return copy
148162
}
149163

164+
@preconcurrency
150165
public func transformingAttributes<K1, K2, K3, K4>(
151166
_ k: K1.Type,
152167
_ k2: K2.Type,
@@ -156,7 +171,12 @@ extension AttributedString {
156171
inout AttributedString.SingleAttributeTransformer<K2>,
157172
inout AttributedString.SingleAttributeTransformer<K3>,
158173
inout AttributedString.SingleAttributeTransformer<K4>) -> Void
159-
) -> AttributedString {
174+
) -> AttributedString
175+
where
176+
K1.Value : Sendable,
177+
K2.Value : Sendable,
178+
K3.Value : Sendable,
179+
K4.Value : Sendable {
160180
let orig = AttributedString(_guts)
161181
var copy = orig
162182
copy.ensureUniqueReference() // ???: Is this best practice? We're going behind the back of the AttributedString mutation API surface, so it doesn't happen anywhere else. It's also aggressively speculative.
@@ -182,6 +202,7 @@ extension AttributedString {
182202
return copy
183203
}
184204

205+
@preconcurrency
185206
public func transformingAttributes<K1, K2, K3, K4, K5>(
186207
_ k: K1.Type,
187208
_ k2: K2.Type,
@@ -193,7 +214,13 @@ extension AttributedString {
193214
inout AttributedString.SingleAttributeTransformer<K3>,
194215
inout AttributedString.SingleAttributeTransformer<K4>,
195216
inout AttributedString.SingleAttributeTransformer<K5>) -> Void
196-
) -> AttributedString {
217+
) -> AttributedString
218+
where
219+
K1.Value : Sendable,
220+
K2.Value : Sendable,
221+
K3.Value : Sendable,
222+
K4.Value : Sendable,
223+
K5.Value : Sendable {
197224
let orig = AttributedString(_guts)
198225
var copy = orig
199226
copy.ensureUniqueReference() // ???: Is this best practice? We're going behind the back of the AttributedString mutation API surface, so it doesn't happen anywhere else. It's also aggressively speculative.
@@ -226,33 +253,46 @@ extension AttributedString {
226253

227254
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
228255
extension AttributedString {
256+
@preconcurrency
229257
public func transformingAttributes<K>(
230258
_ k: KeyPath<AttributeDynamicLookup, K>,
231259
_ c: (inout AttributedString.SingleAttributeTransformer<K>) -> Void
232-
) -> AttributedString {
260+
) -> AttributedString
261+
where
262+
K.Value : Sendable {
233263
self.transformingAttributes(K.self, c)
234264
}
235265

266+
@preconcurrency
236267
public func transformingAttributes<K1, K2>(
237268
_ k: KeyPath<AttributeDynamicLookup, K1>,
238269
_ k2: KeyPath<AttributeDynamicLookup, K2>,
239270
_ c: (inout AttributedString.SingleAttributeTransformer<K1>,
240271
inout AttributedString.SingleAttributeTransformer<K2>) -> Void
241-
) -> AttributedString {
272+
) -> AttributedString
273+
where
274+
K1.Value : Sendable,
275+
K2.Value : Sendable {
242276
self.transformingAttributes(K1.self, K2.self, c)
243277
}
244278

279+
@preconcurrency
245280
public func transformingAttributes<K1, K2, K3>(
246281
_ k: KeyPath<AttributeDynamicLookup, K1>,
247282
_ k2: KeyPath<AttributeDynamicLookup, K2>,
248283
_ k3: KeyPath<AttributeDynamicLookup, K3>,
249284
_ c: (inout AttributedString.SingleAttributeTransformer<K1>,
250285
inout AttributedString.SingleAttributeTransformer<K2>,
251286
inout AttributedString.SingleAttributeTransformer<K3>) -> Void
252-
) -> AttributedString {
287+
) -> AttributedString
288+
where
289+
K1.Value : Sendable,
290+
K2.Value : Sendable,
291+
K3.Value : Sendable {
253292
self.transformingAttributes(K1.self, K2.self, K3.self, c)
254293
}
255294

295+
@preconcurrency
256296
public func transformingAttributes<K1, K2, K3, K4>(
257297
_ k: KeyPath<AttributeDynamicLookup, K1>,
258298
_ k2: KeyPath<AttributeDynamicLookup, K2>,
@@ -262,10 +302,16 @@ extension AttributedString {
262302
inout AttributedString.SingleAttributeTransformer<K2>,
263303
inout AttributedString.SingleAttributeTransformer<K3>,
264304
inout AttributedString.SingleAttributeTransformer<K4>) -> Void
265-
) -> AttributedString {
305+
) -> AttributedString
306+
where
307+
K1.Value : Sendable,
308+
K2.Value : Sendable,
309+
K3.Value : Sendable,
310+
K4.Value : Sendable {
266311
self.transformingAttributes(K1.self, K2.self, K3.self, K4.self, c)
267312
}
268313

314+
@preconcurrency
269315
public func transformingAttributes<K1, K2, K3, K4, K5>(
270316
_ k: KeyPath<AttributeDynamicLookup, K1>,
271317
_ k2: KeyPath<AttributeDynamicLookup, K2>,
@@ -277,7 +323,13 @@ extension AttributedString {
277323
inout AttributedString.SingleAttributeTransformer<K3>,
278324
inout AttributedString.SingleAttributeTransformer<K4>,
279325
inout AttributedString.SingleAttributeTransformer<K5>) -> Void
280-
) -> AttributedString {
326+
) -> AttributedString
327+
where
328+
K1.Value : Sendable,
329+
K2.Value : Sendable,
330+
K3.Value : Sendable,
331+
K4.Value : Sendable,
332+
K5.Value : Sendable {
281333
self.transformingAttributes(K1.self, K2.self, K3.self, K4.self, K5.self, c)
282334
}
283335
}

Sources/FoundationEssentials/AttributedString/AttributedString+Runs+AttributeSlices.swift

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ extension AttributedString.Runs {
100100
// down to the nearest valid indices.
101101
}
102102

103-
public subscript<T : AttributedStringKey>(_ keyPath: KeyPath<AttributeDynamicLookup, T>) -> AttributesSlice1<T> {
103+
@preconcurrency
104+
public subscript<T : AttributedStringKey>(_ keyPath: KeyPath<AttributeDynamicLookup, T>) -> AttributesSlice1<T> where T.Value : Sendable {
104105
return AttributesSlice1<T>(runs: self)
105106
}
106107

107-
public subscript<T : AttributedStringKey>(_ t: T.Type) -> AttributesSlice1<T> {
108+
@preconcurrency
109+
public subscript<T : AttributedStringKey>(_ t: T.Type) -> AttributesSlice1<T> where T.Value : Sendable {
108110
return AttributesSlice1<T>(runs: self)
109111
}
110112
}
@@ -205,23 +207,31 @@ extension AttributedString.Runs {
205207
// down to the nearest valid indices.
206208
}
207209

210+
@preconcurrency
208211
public subscript <
209212
T : AttributedStringKey,
210213
U : AttributedStringKey
211214
> (
212215
_ t: KeyPath<AttributeDynamicLookup, T>,
213216
_ u: KeyPath<AttributeDynamicLookup, U>
214-
) -> AttributesSlice2<T, U> {
217+
) -> AttributesSlice2<T, U>
218+
where
219+
T.Value : Sendable,
220+
U.Value : Sendable {
215221
return AttributesSlice2<T, U>(runs: self)
216222
}
217223

224+
@preconcurrency
218225
public subscript <
219226
T : AttributedStringKey,
220227
U : AttributedStringKey
221228
> (
222229
_ t: T.Type,
223230
_ u: U.Type
224-
) -> AttributesSlice2<T, U> {
231+
) -> AttributesSlice2<T, U>
232+
where
233+
T.Value : Sendable,
234+
U.Value : Sendable {
225235
return AttributesSlice2<T, U>(runs: self)
226236
}
227237
}
@@ -328,6 +338,7 @@ extension AttributedString.Runs {
328338
// down to the nearest valid indices.
329339
}
330340

341+
@preconcurrency
331342
public subscript <
332343
T : AttributedStringKey,
333344
U : AttributedStringKey,
@@ -336,10 +347,15 @@ extension AttributedString.Runs {
336347
_ t: KeyPath<AttributeDynamicLookup, T>,
337348
_ u: KeyPath<AttributeDynamicLookup, U>,
338349
_ v: KeyPath<AttributeDynamicLookup, V>
339-
) -> AttributesSlice3<T, U, V> {
350+
) -> AttributesSlice3<T, U, V>
351+
where
352+
T.Value : Sendable,
353+
U.Value : Sendable,
354+
V.Value : Sendable {
340355
return AttributesSlice3<T, U, V>(runs: self)
341356
}
342357

358+
@preconcurrency
343359
public subscript <
344360
T : AttributedStringKey,
345361
U : AttributedStringKey,
@@ -348,7 +364,11 @@ extension AttributedString.Runs {
348364
_ t: T.Type,
349365
_ u: U.Type,
350366
_ v: V.Type
351-
) -> AttributesSlice3<T, U, V> {
367+
) -> AttributesSlice3<T, U, V>
368+
where
369+
T.Value : Sendable,
370+
U.Value : Sendable,
371+
V.Value : Sendable {
352372
return AttributesSlice3<T, U, V>(runs: self)
353373
}
354374
}
@@ -464,6 +484,7 @@ extension AttributedString.Runs {
464484
// down to the nearest valid indices.
465485
}
466486

487+
@preconcurrency
467488
public subscript <
468489
T : AttributedStringKey,
469490
U : AttributedStringKey,
@@ -474,10 +495,16 @@ extension AttributedString.Runs {
474495
_ u: KeyPath<AttributeDynamicLookup, U>,
475496
_ v: KeyPath<AttributeDynamicLookup, V>,
476497
_ w: KeyPath<AttributeDynamicLookup, W>
477-
) -> AttributesSlice4<T, U, V, W> {
498+
) -> AttributesSlice4<T, U, V, W>
499+
where
500+
T.Value : Sendable,
501+
U.Value : Sendable,
502+
V.Value : Sendable,
503+
W.Value : Sendable {
478504
return AttributesSlice4<T, U, V, W>(runs: self)
479505
}
480506

507+
@preconcurrency
481508
public subscript <
482509
T : AttributedStringKey,
483510
U : AttributedStringKey,
@@ -488,7 +515,12 @@ extension AttributedString.Runs {
488515
_ u: U.Type,
489516
_ v: V.Type,
490517
_ w: W.Type
491-
) -> AttributesSlice4<T, U, V, W> {
518+
) -> AttributesSlice4<T, U, V, W>
519+
where
520+
T.Value : Sendable,
521+
U.Value : Sendable,
522+
V.Value : Sendable,
523+
W.Value : Sendable {
492524
return AttributesSlice4<T, U, V, W>(runs: self)
493525
}
494526
}
@@ -610,6 +642,7 @@ extension AttributedString.Runs {
610642
// down to the nearest valid indices.
611643
}
612644

645+
@preconcurrency
613646
public subscript <
614647
T : AttributedStringKey,
615648
U : AttributedStringKey,
@@ -622,10 +655,17 @@ extension AttributedString.Runs {
622655
_ v: KeyPath<AttributeDynamicLookup, V>,
623656
_ w: KeyPath<AttributeDynamicLookup, W>,
624657
_ x: KeyPath<AttributeDynamicLookup, X>
625-
) -> AttributesSlice5<T, U, V, W, X> {
658+
) -> AttributesSlice5<T, U, V, W, X>
659+
where
660+
T.Value : Sendable,
661+
U.Value : Sendable,
662+
V.Value : Sendable,
663+
W.Value : Sendable,
664+
X.Value : Sendable {
626665
return AttributesSlice5<T, U, V, W, X>(runs: self)
627666
}
628667

668+
@preconcurrency
629669
public subscript <
630670
T : AttributedStringKey,
631671
U : AttributedStringKey,
@@ -638,7 +678,13 @@ extension AttributedString.Runs {
638678
_ v: V.Type,
639679
_ w: W.Type,
640680
_ x: X.Type
641-
) -> AttributesSlice5<T, U, V, W, X> {
681+
) -> AttributesSlice5<T, U, V, W, X>
682+
where
683+
T.Value : Sendable,
684+
U.Value : Sendable,
685+
V.Value : Sendable,
686+
W.Value : Sendable,
687+
X.Value : Sendable {
642688
return AttributesSlice5<T, U, V, W, X>(runs: self)
643689
}
644690
}

0 commit comments

Comments
 (0)