@@ -293,38 +293,26 @@ struct ParametersAndReturnValidator {
293
293
private static func traitSpecificSignatures( _ symbol: UnifiedSymbolGraph . Symbol ) -> Signatures ? {
294
294
var signatures : [ DocumentationDataVariantsTrait : SymbolGraph . Symbol . FunctionSignature ] = [ : ]
295
295
for (selector, mixin) in symbol. mixins {
296
- guard let signature = mixin. getValueIfPresent ( for: SymbolGraph . Symbol. FunctionSignature. self) else {
296
+ guard var signature = mixin. getValueIfPresent ( for: SymbolGraph . Symbol. FunctionSignature. self) else {
297
297
continue
298
298
}
299
299
300
+ if let alternateSymbols = mixin. getValueIfPresent ( for: SymbolGraph . Symbol. AlternateSymbols. self) {
301
+ for alternateSymbol in alternateSymbols. alternateSymbols {
302
+ guard let alternateSignature = alternateSymbol. functionSignature else { continue }
303
+ signature. merge ( with: alternateSignature, selector: selector)
304
+ }
305
+ }
306
+
300
307
let trait = DocumentationDataVariantsTrait ( for: selector)
301
308
// Check if we've already encountered a different signature for another platform
302
- guard var existing = signatures. removeValue ( forKey: trait) else {
309
+ guard let existing = signatures. removeValue ( forKey: trait) else {
303
310
signatures [ trait] = signature
304
311
continue
305
312
}
306
313
307
- // An internal helper function that compares parameter names
308
- func hasSameNames( _ lhs: SymbolGraph . Symbol . FunctionSignature . FunctionParameter , _ rhs: SymbolGraph . Symbol . FunctionSignature . FunctionParameter ) -> Bool {
309
- lhs. name == rhs. name && lhs. externalName == rhs. externalName
310
- }
311
- // If the two signatures have different parameters, add any missing parameters.
312
- // This allows for documenting parameters that are only available on some platforms.
313
- //
314
- // Note: Doing this redundant `elementsEqual(_:by:)` check is significantly faster in the common case when all platforms have the same signature.
315
- // In the rare case where platforms have different signatures, the overhead of checking `elementsEqual(_:by:)` first is too small to measure.
316
- if !existing. parameters. elementsEqual ( signature. parameters, by: hasSameNames) {
317
- for case . insert( offset: let offset, element: let element, _) in signature. parameters. difference ( from: existing. parameters, by: hasSameNames) {
318
- existing. parameters. insert ( element, at: offset)
319
- }
320
- }
321
-
322
- // If the already encountered signature has a void return type, replace it with the non-void return type.
323
- // This allows for documenting the return values that are only available on some platforms.
324
- if existing. returns != signature. returns, existing. returns == knownVoidReturnValuesByLanguage [ . init( id: selector. interfaceLanguage) ] {
325
- existing. returns = signature. returns
326
- }
327
- signatures [ trait] = existing
314
+ signature. merge ( with: existing, selector: selector)
315
+ signatures [ trait] = signature
328
316
}
329
317
330
318
guard !signatures. isEmpty else { return nil }
@@ -673,3 +661,36 @@ struct ParametersAndReturnValidator {
673
661
" - \( standalone ? " Parameter " : " " ) \( name) : <#parameter description#> "
674
662
}
675
663
}
664
+
665
+ // MARK: Helper extensions
666
+
667
+ private extension SymbolGraph . Symbol . FunctionSignature {
668
+ mutating func merge( with signature: Self , selector: UnifiedSymbolGraph . Selector ) {
669
+ // An internal helper function that compares parameter names
670
+ func hasSameNames( _ lhs: Self . FunctionParameter , _ rhs: Self . FunctionParameter ) -> Bool {
671
+ lhs. name == rhs. name && lhs. externalName == rhs. externalName
672
+ }
673
+ // If the two signatures have different parameters, add any missing parameters.
674
+ // This allows for documenting parameters that are only available on some platforms.
675
+ //
676
+ // Note: Doing this redundant `elementsEqual(_:by:)` check is significantly faster in the common case when all platforms have the same signature.
677
+ // In the rare case where platforms have different signatures, the overhead of checking `elementsEqual(_:by:)` first is too small to measure.
678
+ if !self . parameters. elementsEqual ( signature. parameters, by: hasSameNames) {
679
+ for case . insert( offset: let offset, element: let element, _) in signature. parameters. difference ( from: self . parameters, by: hasSameNames) {
680
+ self . parameters. insert ( element, at: offset)
681
+ }
682
+ }
683
+
684
+ // If the already encountered signature has a void return type, replace it with the non-void return type.
685
+ // This allows for documenting the return values that are only available on some platforms.
686
+ if self . returns != signature. returns,
687
+ let knownVoidReturnValues = ParametersAndReturnValidator . knownVoidReturnValuesByLanguage [ . init( id: selector. interfaceLanguage) ]
688
+ {
689
+ for knownVoidReturnValue in knownVoidReturnValues where [ knownVoidReturnValue] == self . returns {
690
+ // The current return value was a known void return value so we replace it with the new return value.
691
+ self . returns = signature. returns
692
+ return
693
+ }
694
+ }
695
+ }
696
+ }
0 commit comments