Skip to content

Commit 5591cf0

Browse files
committed
Change type of userInfo to support [CodingUserInfoKey: any Sendable]
This fixes build failures for setups that have swiftlang/swift-foundation#1169 but not swiftlang/swift#79382. rdar://145669600
1 parent 340e83d commit 5591cf0

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

Sources/SymbolKit/SymbolGraph/Relationship/Relationship.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,20 @@ extension SymbolGraph.Relationship {
148148
/// or decode that type and thus skips such entries. Note that ``Mixin``s that occur on relationships
149149
/// in the default symbol graph format do not have to be registered!
150150
///
151+
/// `UserInfoValue` is the type of the value in `JSONEncoder.userInfo`. This is generic to support both `Any` and
152+
/// `any Sendable` (rdar://145669600) and must be either of these two types.
153+
///
151154
/// - Parameter userInfo: A property which allows editing the `userInfo` member of the
152155
/// `Encoder`/`Decoder` protocol.
153156
/// - Parameter onEncodingError: Defines the behavior when an error occurs while encoding these types of ``Mixin``s.
154157
/// You can log warnings and either re-throw or consume the error.
155158
/// - Parameter onDecodingError: Defines the behavior when an error occurs while decoding these types of ``Mixin``s.
156159
/// Next to logging warnings, the function allows for either re-throwing the error,
157160
/// skipping the erroneous entry, or providing a default value.
158-
public static func register<M: Sequence>(mixins mixinTypes: M,
159-
to userInfo: inout [CodingUserInfoKey: Any],
160-
onEncodingError: ((_ error: Error, _ mixin: Mixin) throws -> Void)?,
161-
onDecodingError: ((_ error: Error) throws -> Mixin?)?) where M.Element == Mixin.Type {
161+
public static func register<M: Sequence, UserInfoValue>(mixins mixinTypes: M,
162+
to userInfo: inout [CodingUserInfoKey: UserInfoValue],
163+
onEncodingError: ((_ error: Error, _ mixin: Mixin) throws -> Void)?,
164+
onDecodingError: ((_ error: Error) throws -> Mixin?)?) where M.Element == Mixin.Type {
162165
var registeredMixins = userInfo[.relationshipMixinKey] as? [String: RelationshipMixinCodingInfo] ?? [:]
163166

164167
for type in mixinTypes {
@@ -172,8 +175,11 @@ extension SymbolGraph.Relationship {
172175

173176
registeredMixins[type.mixinKey] = info
174177
}
175-
176-
userInfo[.relationshipMixinKey] = registeredMixins
178+
179+
// FIXME: Remove the `UserInfoValue` generic parameter when we no longer need to build swift-docc-symbolkit in
180+
// a configuration that contains https://github.com/swiftlang/swift-foundation/pull/1169 but not
181+
// https://github.com/swiftlang/swift/pull/79382.
182+
userInfo[.relationshipMixinKey] = (registeredMixins as! UserInfoValue)
177183
}
178184
}
179185

Sources/SymbolKit/SymbolGraph/Symbol/KindIdentifier.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,21 +263,27 @@ extension SymbolGraph.Symbol.KindIdentifier {
263263
///
264264
/// If a type is not registered, language prefixes cannot be removed correctly.
265265
///
266+
/// `UserInfoValue` is the type of the value in `JSONEncoder.userInfo`. This is generic to support both `Any` and
267+
/// `any Sendable` (rdar://145669600) and must be either of these two types.
268+
///
266269
/// - Note: Registering custom identifiers on your decoder is only necessary when working in an uncontrolled environment where
267270
/// other parts of your executable might be disturbed by your modifications to the symbol graph structure. If that is not the case, use
268271
/// ``SymbolGraph/Symbol/KindIdentifier/register(_:)``.
269272
///
270273
/// - Parameter userInfo: A property which allows editing the `userInfo` member of the
271274
/// `Decoder` protocol.
272-
public static func register<I: Sequence>(_ identifiers: I,
273-
to userInfo: inout [CodingUserInfoKey: Any]) where I.Element == Self {
275+
public static func register<I: Sequence, UserInfoValue>(_ identifiers: I,
276+
to userInfo: inout [CodingUserInfoKey: UserInfoValue]) where I.Element == Self {
274277
var registeredIdentifiers = userInfo[.symbolKindIdentifierKey] as? [String: SymbolGraph.Symbol.KindIdentifier] ?? [:]
275278

276279
for identifier in identifiers {
277280
registeredIdentifiers[identifier.identifier] = identifier
278281
}
279282

280-
userInfo[.symbolKindIdentifierKey] = registeredIdentifiers
283+
// FIXME: Remove the `UserInfoValue` generic parameter when we no longer need to build swift-docc-symbolkit in
284+
// a configuration that contains https://github.com/swiftlang/swift-foundation/pull/1169 but not
285+
// https://github.com/swiftlang/swift/pull/79382.
286+
userInfo[.symbolKindIdentifierKey] = (registeredIdentifiers as! UserInfoValue)
281287
}
282288
}
283289

Sources/SymbolKit/SymbolGraph/Symbol/Symbol.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,20 @@ extension SymbolGraph.Symbol {
302302
/// or decode that type and thus skips such entries. Note that ``Mixin``s that occur on symbols
303303
/// in the default symbol graph format do not have to be registered!
304304
///
305+
/// `UserInfoValue` is the type of the value in `JSONEncoder.userInfo`. This is generic to support both `Any` and
306+
/// `any Sendable` (rdar://145669600) and must be either of these two types.
307+
///
305308
/// - Parameter userInfo: A property which allows editing the `userInfo` member of the
306309
/// `Encoder`/`Decoder` protocol.
307310
/// - Parameter onEncodingError: Defines the behavior when an error occurs while encoding these types of ``Mixin``s.
308311
/// You can log warnings and either re-throw or consume the error.
309312
/// - Parameter onDecodingError: Defines the behavior when an error occurs while decoding these types of ``Mixin``s.
310313
/// Next to logging warnings, the function allows for either re-throwing the error,
311314
/// skipping the erroneous entry, or providing a default value.
312-
public static func register<M: Sequence>(mixins mixinTypes: M,
313-
to userInfo: inout [CodingUserInfoKey: Any],
314-
onEncodingError: ((_ error: Error, _ mixin: Mixin) throws -> Void)?,
315-
onDecodingError: ((_ error: Error) throws -> Mixin?)?)
315+
public static func register<M: Sequence, UserInfoValue>(mixins mixinTypes: M,
316+
to userInfo: inout [CodingUserInfoKey: UserInfoValue],
317+
onEncodingError: ((_ error: Error, _ mixin: Mixin) throws -> Void)?,
318+
onDecodingError: ((_ error: Error) throws -> Mixin?)?)
316319
where M.Element == Mixin.Type {
317320
var registeredMixins = userInfo[.symbolMixinKey] as? [String: SymbolMixinCodingInfo] ?? [:]
318321

@@ -328,7 +331,10 @@ extension SymbolGraph.Symbol {
328331
registeredMixins[type.mixinKey] = info
329332
}
330333

331-
userInfo[.symbolMixinKey] = registeredMixins
334+
// FIXME: Remove the `UserInfoValue` generic parameter when we no longer need to build swift-docc-symbolkit in
335+
// a configuration that contains https://github.com/swiftlang/swift-foundation/pull/1169 but not
336+
// https://github.com/swiftlang/swift/pull/79382.
337+
userInfo[.symbolMixinKey] = (registeredMixins as! UserInfoValue)
332338
}
333339
}
334340

0 commit comments

Comments
 (0)