@@ -29,7 +29,7 @@ import SymbolKit
29
29
/// - ``kindVariants``
30
30
/// - ``platformNameVariants``
31
31
/// - ``moduleReference``
32
- /// - ``extendedModule ``
32
+ /// - ``extendedModuleVariants ``
33
33
/// - ``bystanderModuleNames``
34
34
/// - ``isRequiredVariants``
35
35
/// - ``externalIDVariants``
@@ -115,9 +115,15 @@ public final class Symbol: Semantic, Abstracted, Redirected, AutomaticTaskGroups
115
115
116
116
/// The reference to the documentation node that represents this symbol's module symbol.
117
117
internal( set) public var moduleReference : ResolvedTopicReference
118
-
119
- /// The name of the module extension in which the symbol is defined, if applicable.
120
- internal( set) public var extendedModule : String ?
118
+
119
+ /// The name of the module extension in which the symbol is defined, in each language variant the symbol is available in
120
+ public var extendedModuleVariants : DocumentationDataVariants < String > {
121
+ var variants = DocumentationDataVariants < String > ( )
122
+ for (trait, swiftExtension) in swiftExtensionVariants ( ) {
123
+ variants [ trait] = swiftExtension. extendedModule
124
+ }
125
+ return variants
126
+ }
121
127
122
128
/// The names of any "bystander" modules required for this symbol, if it came from a cross-import overlay.
123
129
@available ( * , deprecated, message: " Use crossImportOverlayModule instead " )
@@ -146,10 +152,16 @@ public final class Symbol: Semantic, Abstracted, Redirected, AutomaticTaskGroups
146
152
)
147
153
148
154
public var locationVariants = DocumentationDataVariants < SymbolGraph . Symbol . Location > ( )
149
-
155
+
150
156
/// The symbol's availability or conformance constraints, in each language variant the symbol is available in.
151
- public var constraintsVariants = DocumentationDataVariants < [ SymbolGraph . Symbol . Swift . GenericConstraint ] > ( )
152
-
157
+ public var constraintsVariants : DocumentationDataVariants < [ SymbolGraph . Symbol . Swift . GenericConstraint ] > {
158
+ var variants = DocumentationDataVariants < [ SymbolGraph . Symbol . Swift . GenericConstraint ] > ( )
159
+ for (trait, swiftExtension) in swiftExtensionVariants ( ) {
160
+ variants [ trait] = swiftExtension. constraints
161
+ }
162
+ return variants
163
+ }
164
+
153
165
/// The inheritance information for the symbol in each language variant the symbol is available in.
154
166
public var originVariants : DocumentationDataVariants < SymbolGraph . Relationship . SourceOrigin >
155
167
@@ -236,7 +248,6 @@ public final class Symbol: Semantic, Abstracted, Redirected, AutomaticTaskGroups
236
248
roleHeadingVariants: DocumentationDataVariants < String > ,
237
249
platformNameVariants: DocumentationDataVariants < PlatformName > ,
238
250
moduleReference: ResolvedTopicReference ,
239
- extendedModule: String ? = nil ,
240
251
requiredVariants: DocumentationDataVariants < Bool > = . init( defaultVariantValue: false ) ,
241
252
externalIDVariants: DocumentationDataVariants < String > ,
242
253
accessLevelVariants: DocumentationDataVariants < String > ,
@@ -292,8 +303,6 @@ public final class Symbol: Semantic, Abstracted, Redirected, AutomaticTaskGroups
292
303
if !self . declarationVariants. hasVariant ( for: trait) {
293
304
self . declarationVariants [ trait] = [ [ platformNameVariants [ trait] ] : declaration]
294
305
}
295
- case let extensionConstraints as SymbolGraph . Symbol . Swift . Extension where !extensionConstraints. constraints. isEmpty:
296
- self . constraintsVariants [ trait] = extensionConstraints. constraints
297
306
case let location as SymbolGraph . Symbol . Location :
298
307
self . locationVariants [ trait] = location
299
308
case let spi as SymbolGraph . Symbol . SPI :
@@ -323,12 +332,69 @@ public final class Symbol: Semantic, Abstracted, Redirected, AutomaticTaskGroups
323
332
self . redirectsVariants = redirectsVariants
324
333
self . originVariants = originVariants
325
334
self . automaticTaskGroupsVariants = automaticTaskGroupsVariants
326
- self . extendedModule = extendedModule
327
335
}
328
336
329
337
public override func accept< V: SemanticVisitor > ( _ visitor: inout V ) -> V . Result {
330
338
return visitor. visitSymbol ( self )
331
339
}
340
+
341
+ /// Append a new generic constraint for the given extended module
342
+ /// - Parameters:
343
+ /// - extendedModule: The name of the extended module.
344
+ /// - extendedSymbolKind: The kind of the extended symbol.
345
+ /// - constraint: The new generic constraints to add.
346
+ public func addSwiftExtensionConstraint(
347
+ extendedModule: String ,
348
+ extendedSymbolKind: SymbolGraph . Symbol . KindIdentifier ? = nil ,
349
+ constraint newConstraint: SymbolGraph . Symbol . Swift . GenericConstraint
350
+ ) {
351
+
352
+ var swiftExtension : SymbolGraph . Symbol . Swift . Extension
353
+
354
+ // Does this symbol already have a swift extension variant for the swift trait?
355
+
356
+ // Yes: Create a new copy of the existing extension with
357
+ // the new constraint appended to the existing list
358
+ let trait = DocumentationDataVariantsTrait . swift
359
+ if let existing = swiftExtensionVariants ( ) [ trait] {
360
+ // Double check the existing extension uses the same module and type. If it does not,
361
+ // we must have a tooling or data consistency problem.
362
+ assert (
363
+ existing. extendedModule == extendedModule && existing. typeKind == extendedSymbolKind,
364
+ " New constraint's module and type kind do not match symbol's existing constraints. "
365
+ )
366
+ swiftExtension = existing
367
+ swiftExtension. constraints = swiftExtension. constraints + [ newConstraint]
368
+
369
+ // No: Create a new extension with the specified module, type and
370
+ // new constraint
371
+ } else {
372
+ swiftExtension = SymbolGraph . Symbol. Swift. Extension (
373
+ extendedModule: extendedModule,
374
+ typeKind: extendedSymbolKind,
375
+ constraints: [ newConstraint]
376
+ )
377
+ }
378
+
379
+ // Save the new or updated extension
380
+ self . mixinsVariants [
381
+ trait,
382
+ default: [ : ]
383
+ ] [ SymbolGraph . Symbol. Swift. Extension. mixinKey] = swiftExtension
384
+ }
385
+
386
+ // MARK: - Private helpers
387
+
388
+ /// Return all of this symbol's Swift extension variants.
389
+ private func swiftExtensionVariants( ) -> [ DocumentationDataVariantsTrait : SymbolGraph . Symbol . Swift . Extension ] {
390
+ var variants : [ DocumentationDataVariantsTrait : SymbolGraph . Symbol . Swift . Extension ] = [ : ]
391
+ for (trait, mixins) in mixinsVariants. allValues {
392
+ if let swiftExtension = mixins [ SymbolGraph . Symbol. Swift. Extension. mixinKey] as? SymbolGraph . Symbol . Swift . Extension {
393
+ variants [ trait] = swiftExtension
394
+ }
395
+ }
396
+ return variants
397
+ }
332
398
}
333
399
334
400
extension Symbol {
@@ -432,6 +498,10 @@ extension Symbol {
432
498
/// The first variant of the symbol's platform, if available.
433
499
public var platformName : PlatformName ? { platformNameVariants. firstValue }
434
500
501
+ /// The first variant of the symbol's extended module, if available
502
+ @available ( * , deprecated, message: " Please use extendedModuleVariants instead. " )
503
+ public var extendedModule : String ? { extendedModuleVariants. firstValue }
504
+
435
505
/// Whether the first variant of the symbol is required in its context.
436
506
public var isRequired : Bool {
437
507
get { isRequiredVariants. firstValue! }
@@ -462,10 +532,7 @@ extension Symbol {
462
532
}
463
533
464
534
/// The first variant of the symbol's availability or conformance constraints.
465
- public var constraints : [ SymbolGraph . Symbol . Swift . GenericConstraint ] ? {
466
- get { constraintsVariants. firstValue }
467
- set { constraintsVariants. firstValue = newValue }
468
- }
535
+ public var constraints : [ SymbolGraph . Symbol . Swift . GenericConstraint ] ? { constraintsVariants. firstValue }
469
536
470
537
/// The inheritance information for the first variant of the symbol.
471
538
public var origin : SymbolGraph . Relationship . SourceOrigin ? {
0 commit comments