Skip to content

Commit 2b5bdf1

Browse files
Revert "Fix availability logic refactor (#1065)" (#1158)
This reverts commit 1ad9b6a.
1 parent 9daab13 commit 2b5bdf1

File tree

9 files changed

+639
-759
lines changed

9 files changed

+639
-759
lines changed

Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift

+156-124
Large diffs are not rendered by default.

Sources/SwiftDocC/Infrastructure/Workspace/DefaultAvailability.swift

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021-2025 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 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
@@ -131,30 +131,28 @@ public struct DefaultAvailability: Codable, Equatable {
131131

132132
/// Fallback availability information for platforms we either don't emit SGFs for
133133
/// or have the same availability information as another platform.
134-
///
135-
/// The key corresponds to the fallback platform and the value to the platform it's
136-
/// fallbacking from.
137-
package static let fallbackPlatforms: [PlatformName: [PlatformName]] = [.iOS: [.catalyst, .iPadOS]]
134+
package static let fallbackPlatforms: [PlatformName: PlatformName] = [
135+
.catalyst: .iOS,
136+
.iPadOS: .iOS,
137+
]
138138

139139
/// Creates a default availability module.
140140
/// - Parameter modules: A map of modules and the default platform availability for symbols in that module.
141141
public init(with modules: [String: [ModuleAvailability]]) {
142142
self.modules = modules.mapValues { platformAvailabilities -> [DefaultAvailability.ModuleAvailability] in
143143
// If a module doesn't contain default availability information for any of the fallback platforms,
144144
// infer it from the corresponding mapped value.
145-
platformAvailabilities + DefaultAvailability.fallbackPlatforms.flatMap { (fallbackPlatform, platform) in
146-
platform.compactMap { platformName in
147-
if !platformAvailabilities.contains(where: { $0.platformName == platformName }),
148-
let fallbackAvailability = platformAvailabilities.first(where: { $0.platformName == fallbackPlatform }),
149-
let fallbackIntroducedVersion = fallbackAvailability.introducedVersion
150-
{
151-
return DefaultAvailability.ModuleAvailability(
152-
platformName: platformName,
153-
platformVersion: fallbackIntroducedVersion
154-
)
155-
}
156-
return nil
145+
platformAvailabilities + DefaultAvailability.fallbackPlatforms.compactMap { (platform, fallbackPlatform) in
146+
if !platformAvailabilities.contains(where: { $0.platformName == platform }),
147+
let fallbackAvailability = platformAvailabilities.first(where: { $0.platformName == fallbackPlatform }),
148+
let fallbackIntroducedVersion = fallbackAvailability.introducedVersion
149+
{
150+
return DefaultAvailability.ModuleAvailability(
151+
platformName: platform,
152+
platformVersion: fallbackIntroducedVersion
153+
)
157154
}
155+
return nil
158156
}
159157
}
160158
}

Sources/SwiftDocC/Semantics/Symbol/Symbol.swift

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021-2025 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 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
@@ -591,12 +591,10 @@ extension Symbol {
591591
func mergeAvailabilities(unifiedSymbol: UnifiedSymbolGraph.Symbol) {
592592
for (selector, mixins) in unifiedSymbol.mixins {
593593
let trait = DocumentationDataVariantsTrait(for: selector)
594-
guard let availabilityVariantTrait = availabilityVariants[trait] else {
595-
return
596-
}
597-
if let unifiedSymbolAvailability = mixins.getValueIfPresent(for: SymbolGraph.Symbol.Availability.self) {
594+
if let unifiedSymbolAvailability = mixins[SymbolGraph.Symbol.Availability.mixinKey] as? SymbolGraph.Symbol.Availability {
598595
unifiedSymbolAvailability.availability.forEach { availabilityItem in
599-
guard availabilityVariantTrait.availability.firstIndex(where: { $0.domain?.rawValue == availabilityItem.domain?.rawValue }) == nil else {
596+
guard let availabilityVariantTrait = availabilityVariants[trait] else { return }
597+
if (availabilityVariantTrait.availability.contains(where: { $0.domain?.rawValue == availabilityItem.domain?.rawValue })) {
600598
return
601599
}
602600
availabilityVariants[trait]?.availability.append(availabilityItem)

Sources/SwiftDocCTestUtilities/FilesAndFolders.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public struct InfoPlist: File, DataRepresentable {
112112
self.identifier = identifier
113113
self.defaultAvailability = defaultAvailability
114114
}
115-
115+
116116
public init(from decoder: any Decoder) throws {
117117
let container = try decoder.container(keyedBy: DocumentationBundle.Info.CodingKeys.self)
118118
displayName = try container.decodeIfPresent(String.self, forKey: .displayName)

Sources/SwiftDocCUtilities/Action/Actions/Convert/ConvertAction.swift

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021-2025 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 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
@@ -145,10 +145,8 @@ public struct ConvertAction: AsyncAction {
145145
// Inject current platform versions if provided
146146
if var currentPlatforms {
147147
// Add missing platforms if their fallback platform is present.
148-
for (fallbackPlatform, platforms) in DefaultAvailability.fallbackPlatforms {
149-
for platform in platforms where currentPlatforms[platform.displayName] == nil {
150-
currentPlatforms[platform.displayName] = currentPlatforms[fallbackPlatform.displayName]
151-
}
148+
for (platform, fallbackPlatform) in DefaultAvailability.fallbackPlatforms where currentPlatforms[platform.displayName] == nil {
149+
currentPlatforms[platform.displayName] = currentPlatforms[fallbackPlatform.displayName]
152150
}
153151
configuration.externalMetadata.currentPlatforms = currentPlatforms
154152
}

0 commit comments

Comments
 (0)