11/*
22 This source file is part of the Swift.org open source project
33
4- Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
4+ Copyright (c) 2021-2025 Apple Inc. and the Swift project authors
55 Licensed under Apache License v2.0 with Runtime Library Exception
66
77 See https://swift.org/LICENSE.txt for license information
@@ -187,6 +187,26 @@ struct DeclarationsSectionTranslator: RenderSectionTranslator {
187187 return declarations
188188 }
189189
190+ /// Returns the given platforms with any missing fallback platforms added.
191+ ///
192+ /// This function uses the centralized `DefaultAvailability.fallbackPlatforms` mapping to ensure
193+ /// consistency with platform expansion logic used throughout the codebase.
194+ ///
195+ /// For example, when iOS is present in the platforms array, this function adds iPadOS and Mac Catalyst
196+ /// if they are not already included.
197+ ///
198+ /// - Parameter platforms: The original platforms array.
199+ /// - Returns: The platforms array with fallback platforms added where applicable.
200+ func expandPlatformsWithFallbacks( _ platforms: [ PlatformName ? ] ) -> [ PlatformName ? ] {
201+ guard !platforms. isEmpty else { return platforms }
202+
203+ // Add fallback platforms if their primary platform is present but the fallback is missing
204+ let fallbacks = DefaultAvailability . fallbackPlatforms. compactMap { fallback, primary in
205+ platforms. contains ( primary) && !platforms. contains ( fallback) ? fallback : nil
206+ }
207+ return platforms + fallbacks
208+ }
209+
190210 func comparePlatformNames( _ lhs: PlatformName ? , _ rhs: PlatformName ? ) -> Bool {
191211 guard let lhsValue = lhs, let rhsValue = rhs else {
192212 return lhs == nil
@@ -204,6 +224,8 @@ struct DeclarationsSectionTranslator: RenderSectionTranslator {
204224 ]
205225 for pair in declaration {
206226 let ( platforms, declaration) = pair
227+ let expandedPlatforms = expandPlatformsWithFallbacks ( platforms)
228+ let platformNames = sortPlatformNames ( expandedPlatforms)
207229
208230 let renderedTokens : [ DeclarationRenderSection . Token ]
209231 let otherDeclarations : DeclarationRenderSection . OtherDeclarations ?
@@ -242,7 +264,7 @@ struct DeclarationsSectionTranslator: RenderSectionTranslator {
242264 declarations. append (
243265 DeclarationRenderSection (
244266 languages: languages,
245- platforms: sortPlatformNames ( platforms ) ,
267+ platforms: platformNames ,
246268 tokens: renderedTokens,
247269 otherDeclarations: otherDeclarations
248270 )
@@ -252,7 +274,8 @@ struct DeclarationsSectionTranslator: RenderSectionTranslator {
252274 if let alternateDeclarations = symbol. alternateDeclarationVariants [ trait] {
253275 for pair in alternateDeclarations {
254276 let ( platforms, decls) = pair
255- let platformNames = sortPlatformNames ( platforms)
277+ let expandedPlatforms = expandPlatformsWithFallbacks ( platforms)
278+ let platformNames = sortPlatformNames ( expandedPlatforms)
256279 for alternateDeclaration in decls {
257280 let renderedTokens = alternateDeclaration. declarationFragments. map ( translateFragment)
258281
0 commit comments