Skip to content

Revert some Sendable fixes around KeyPath while we sort out a compiler bug with ABI stability #679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ extension AttributedString {
andChanged changed: AttributedString.SingleAttributeTransformer<K>,
to attrStr: inout AttributedString,
key: K.Type
)
where
K.Value : Sendable {
) {
if orig.range != changed.range || orig.attrName != changed.attrName {
attrStr._guts.removeAttributeValue(forKey: K.self, in: orig.range._bstringRange) // If the range changed, we need to remove from the old range first.
}
Expand All @@ -65,7 +63,7 @@ extension AttributedString {
andChanged changed: AttributedString.SingleAttributeTransformer<K>,
to attrStr: inout AttributedString,
key: K.Type
) where K.Value : Sendable {
) {
if orig.range != changed.range || orig.attrName != changed.attrName || orig.attr != changed.attr {
if let newVal = changed.attr { // Then if there's a new value, we add it in.
// Unfortunately, we can't use the attrStr[range].set() provided by the AttributedStringProtocol, because we *don't know* the new type statically!
Expand All @@ -80,13 +78,10 @@ extension AttributedString {

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
extension AttributedString {
@preconcurrency
public func transformingAttributes<K>(
_ k: K.Type,
_ c: (inout AttributedString.SingleAttributeTransformer<K>) -> Void
) -> AttributedString
where
K.Value : Sendable {
) -> AttributedString {
let orig = AttributedString(_guts)
var copy = orig
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.
Expand All @@ -100,16 +95,12 @@ extension AttributedString {
return copy
}

@preconcurrency
public func transformingAttributes<K1, K2>(
_ k: K1.Type,
_ k2: K2.Type,
_ c: (inout AttributedString.SingleAttributeTransformer<K1>,
inout AttributedString.SingleAttributeTransformer<K2>) -> Void
) -> AttributedString
where
K1.Value : Sendable,
K2.Value : Sendable {
) -> AttributedString {
let orig = AttributedString(_guts)
var copy = orig
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.
Expand All @@ -127,19 +118,14 @@ extension AttributedString {
return copy
}

@preconcurrency
public func transformingAttributes<K1, K2, K3>(
_ k: K1.Type,
_ k2: K2.Type,
_ k3: K3.Type,
_ c: (inout AttributedString.SingleAttributeTransformer<K1>,
inout AttributedString.SingleAttributeTransformer<K2>,
inout AttributedString.SingleAttributeTransformer<K3>) -> Void
) -> AttributedString
where
K1.Value : Sendable,
K2.Value : Sendable,
K3.Value : Sendable {
) -> AttributedString {
let orig = AttributedString(_guts)
var copy = orig
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.
Expand All @@ -161,7 +147,6 @@ extension AttributedString {
return copy
}

@preconcurrency
public func transformingAttributes<K1, K2, K3, K4>(
_ k: K1.Type,
_ k2: K2.Type,
Expand All @@ -171,12 +156,7 @@ extension AttributedString {
inout AttributedString.SingleAttributeTransformer<K2>,
inout AttributedString.SingleAttributeTransformer<K3>,
inout AttributedString.SingleAttributeTransformer<K4>) -> Void
) -> AttributedString
where
K1.Value : Sendable,
K2.Value : Sendable,
K3.Value : Sendable,
K4.Value : Sendable {
) -> AttributedString {
let orig = AttributedString(_guts)
var copy = orig
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.
Expand All @@ -202,7 +182,6 @@ extension AttributedString {
return copy
}

@preconcurrency
public func transformingAttributes<K1, K2, K3, K4, K5>(
_ k: K1.Type,
_ k2: K2.Type,
Expand All @@ -214,13 +193,7 @@ extension AttributedString {
inout AttributedString.SingleAttributeTransformer<K3>,
inout AttributedString.SingleAttributeTransformer<K4>,
inout AttributedString.SingleAttributeTransformer<K5>) -> Void
) -> AttributedString
where
K1.Value : Sendable,
K2.Value : Sendable,
K3.Value : Sendable,
K4.Value : Sendable,
K5.Value : Sendable {
) -> AttributedString {
let orig = AttributedString(_guts)
var copy = orig
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.
Expand Down Expand Up @@ -253,46 +226,33 @@ extension AttributedString {

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
extension AttributedString {
@preconcurrency
public func transformingAttributes<K>(
_ k: KeyPath<AttributeDynamicLookup, K>,
_ c: (inout AttributedString.SingleAttributeTransformer<K>) -> Void
) -> AttributedString
where
K.Value : Sendable {
) -> AttributedString {
self.transformingAttributes(K.self, c)
}

@preconcurrency
public func transformingAttributes<K1, K2>(
_ k: KeyPath<AttributeDynamicLookup, K1>,
_ k2: KeyPath<AttributeDynamicLookup, K2>,
_ c: (inout AttributedString.SingleAttributeTransformer<K1>,
inout AttributedString.SingleAttributeTransformer<K2>) -> Void
) -> AttributedString
where
K1.Value : Sendable,
K2.Value : Sendable {
) -> AttributedString {
self.transformingAttributes(K1.self, K2.self, c)
}

@preconcurrency
public func transformingAttributes<K1, K2, K3>(
_ k: KeyPath<AttributeDynamicLookup, K1>,
_ k2: KeyPath<AttributeDynamicLookup, K2>,
_ k3: KeyPath<AttributeDynamicLookup, K3>,
_ c: (inout AttributedString.SingleAttributeTransformer<K1>,
inout AttributedString.SingleAttributeTransformer<K2>,
inout AttributedString.SingleAttributeTransformer<K3>) -> Void
) -> AttributedString
where
K1.Value : Sendable,
K2.Value : Sendable,
K3.Value : Sendable {
) -> AttributedString {
self.transformingAttributes(K1.self, K2.self, K3.self, c)
}

@preconcurrency
public func transformingAttributes<K1, K2, K3, K4>(
_ k: KeyPath<AttributeDynamicLookup, K1>,
_ k2: KeyPath<AttributeDynamicLookup, K2>,
Expand All @@ -302,16 +262,10 @@ extension AttributedString {
inout AttributedString.SingleAttributeTransformer<K2>,
inout AttributedString.SingleAttributeTransformer<K3>,
inout AttributedString.SingleAttributeTransformer<K4>) -> Void
) -> AttributedString
where
K1.Value : Sendable,
K2.Value : Sendable,
K3.Value : Sendable,
K4.Value : Sendable {
) -> AttributedString {
self.transformingAttributes(K1.self, K2.self, K3.self, K4.self, c)
}

@preconcurrency
public func transformingAttributes<K1, K2, K3, K4, K5>(
_ k: KeyPath<AttributeDynamicLookup, K1>,
_ k2: KeyPath<AttributeDynamicLookup, K2>,
Expand All @@ -323,13 +277,7 @@ extension AttributedString {
inout AttributedString.SingleAttributeTransformer<K3>,
inout AttributedString.SingleAttributeTransformer<K4>,
inout AttributedString.SingleAttributeTransformer<K5>) -> Void
) -> AttributedString
where
K1.Value : Sendable,
K2.Value : Sendable,
K3.Value : Sendable,
K4.Value : Sendable,
K5.Value : Sendable {
) -> AttributedString {
self.transformingAttributes(K1.self, K2.self, K3.self, K4.self, K5.self, c)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,11 @@ extension AttributedString.Runs {
// down to the nearest valid indices.
}

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

@preconcurrency
public subscript<T : AttributedStringKey>(_ t: T.Type) -> AttributesSlice1<T> where T.Value : Sendable {
public subscript<T : AttributedStringKey>(_ t: T.Type) -> AttributesSlice1<T> {
return AttributesSlice1<T>(runs: self)
}
}
Expand Down Expand Up @@ -207,31 +205,23 @@ extension AttributedString.Runs {
// down to the nearest valid indices.
}

@preconcurrency
public subscript <
T : AttributedStringKey,
U : AttributedStringKey
> (
_ t: KeyPath<AttributeDynamicLookup, T>,
_ u: KeyPath<AttributeDynamicLookup, U>
) -> AttributesSlice2<T, U>
where
T.Value : Sendable,
U.Value : Sendable {
) -> AttributesSlice2<T, U> {
return AttributesSlice2<T, U>(runs: self)
}

@preconcurrency
public subscript <
T : AttributedStringKey,
U : AttributedStringKey
> (
_ t: T.Type,
_ u: U.Type
) -> AttributesSlice2<T, U>
where
T.Value : Sendable,
U.Value : Sendable {
) -> AttributesSlice2<T, U> {
return AttributesSlice2<T, U>(runs: self)
}
}
Expand Down Expand Up @@ -338,7 +328,6 @@ extension AttributedString.Runs {
// down to the nearest valid indices.
}

@preconcurrency
public subscript <
T : AttributedStringKey,
U : AttributedStringKey,
Expand All @@ -347,15 +336,10 @@ extension AttributedString.Runs {
_ t: KeyPath<AttributeDynamicLookup, T>,
_ u: KeyPath<AttributeDynamicLookup, U>,
_ v: KeyPath<AttributeDynamicLookup, V>
) -> AttributesSlice3<T, U, V>
where
T.Value : Sendable,
U.Value : Sendable,
V.Value : Sendable {
) -> AttributesSlice3<T, U, V> {
return AttributesSlice3<T, U, V>(runs: self)
}

@preconcurrency
public subscript <
T : AttributedStringKey,
U : AttributedStringKey,
Expand All @@ -364,11 +348,7 @@ extension AttributedString.Runs {
_ t: T.Type,
_ u: U.Type,
_ v: V.Type
) -> AttributesSlice3<T, U, V>
where
T.Value : Sendable,
U.Value : Sendable,
V.Value : Sendable {
) -> AttributesSlice3<T, U, V> {
return AttributesSlice3<T, U, V>(runs: self)
}
}
Expand Down Expand Up @@ -484,7 +464,6 @@ extension AttributedString.Runs {
// down to the nearest valid indices.
}

@preconcurrency
public subscript <
T : AttributedStringKey,
U : AttributedStringKey,
Expand All @@ -499,7 +478,6 @@ extension AttributedString.Runs {
return AttributesSlice4<T, U, V, W>(runs: self)
}

@preconcurrency
public subscript <
T : AttributedStringKey,
U : AttributedStringKey,
Expand Down Expand Up @@ -632,7 +610,6 @@ extension AttributedString.Runs {
// down to the nearest valid indices.
}

@preconcurrency
public subscript <
T : AttributedStringKey,
U : AttributedStringKey,
Expand All @@ -645,17 +622,10 @@ extension AttributedString.Runs {
_ v: KeyPath<AttributeDynamicLookup, V>,
_ w: KeyPath<AttributeDynamicLookup, W>,
_ x: KeyPath<AttributeDynamicLookup, X>
) -> AttributesSlice5<T, U, V, W, X>
where
T.Value : Sendable,
U.Value : Sendable,
V.Value : Sendable,
W.Value : Sendable,
X.Value : Sendable {
) -> AttributesSlice5<T, U, V, W, X> {
return AttributesSlice5<T, U, V, W, X>(runs: self)
}

@preconcurrency
public subscript <
T : AttributedStringKey,
U : AttributedStringKey,
Expand All @@ -668,13 +638,7 @@ extension AttributedString.Runs {
_ v: V.Type,
_ w: W.Type,
_ x: X.Type
) -> AttributesSlice5<T, U, V, W, X>
where
T.Value : Sendable,
U.Value : Sendable,
V.Value : Sendable,
W.Value : Sendable,
X.Value : Sendable {
) -> AttributesSlice5<T, U, V, W, X> {
return AttributesSlice5<T, U, V, W, X>(runs: self)
}
}
Expand Down
Loading