Skip to content

Commit 7197d54

Browse files
authored
Remove error for mixed symbol graph formats. (#715)
rdar://114405721 rdar://115438349
1 parent 93585b6 commit 7197d54

File tree

2 files changed

+2
-184
lines changed

2 files changed

+2
-184
lines changed

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

Lines changed: 2 additions & 40 deletions
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 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2023 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
@@ -80,7 +80,6 @@ struct SymbolGraphLoader {
8080

8181
configureSymbolGraph?(&symbolGraph)
8282

83-
// `moduleNameFor(_:at:)` is static because it's pure function.
8483
let (moduleName, isMainSymbolGraph) = Self.moduleNameFor(symbolGraph, at: symbolGraphURL)
8584
// If the bundle provides availability defaults add symbol availability data.
8685
self.addDefaultAvailability(to: &symbolGraph, moduleName: moduleName)
@@ -131,25 +130,6 @@ struct SymbolGraphLoader {
131130

132131
// define an appropriate merging strategy based on the graph formats
133132
let foundGraphUsingExtensionSymbolFormat = loadedGraphs.values.map(\.usesExtensionSymbolFormat).contains(true)
134-
let foundGraphNotUsingExtensionSymbolFormat = loadedGraphs.values.map(\.usesExtensionSymbolFormat).contains(false)
135-
136-
guard !foundGraphUsingExtensionSymbolFormat || !foundGraphNotUsingExtensionSymbolFormat else {
137-
let usingExtensionSymbolFormat = loadedGraphs.filter { (_, value) in
138-
guard let usesExtensionSymbolFormat = value.usesExtensionSymbolFormat else {
139-
return false
140-
}
141-
return usesExtensionSymbolFormat
142-
}.map(\.key)
143-
144-
let notUsingExtensionSymbolFormat = loadedGraphs.filter { (_, value) in
145-
guard let usesExtensionSymbolFormat = value.usesExtensionSymbolFormat else {
146-
return false
147-
}
148-
return !usesExtensionSymbolFormat
149-
}.map(\.key)
150-
151-
throw LoadingError.mixedGraphFormats(usingExtensionSymbolFormat, notUsingExtensionSymbolFormat)
152-
}
153133

154134
let usingExtensionSymbolFormat = foundGraphUsingExtensionSymbolFormat
155135

@@ -170,24 +150,6 @@ struct SymbolGraphLoader {
170150
(self.unifiedGraphs, self.graphLocations) = graphLoader.finishLoading()
171151
}
172152

173-
private enum LoadingError: DescribedError {
174-
case mixedGraphFormats([URL], [URL])
175-
176-
var errorDescription: String {
177-
switch self {
178-
case let .mixedGraphFormats(usingExtensionSymbolFormat, notUsingExtensionSymbolFormat):
179-
return """
180-
Mixing symbol graph files with and without extension declarations is not supported.
181-
182-
Symbol graph files with extension declarations:
183-
\(usingExtensionSymbolFormat.map(\.absoluteString).joined(separator: "\n"))
184-
Symbol graph files without extension declarations:
185-
\(notUsingExtensionSymbolFormat.map(\.absoluteString).joined(separator: "\n"))
186-
"""
187-
}
188-
}
189-
}
190-
191153
// Alias to declutter code
192154
typealias AvailabilityItem = SymbolGraph.Symbol.Availability.AvailabilityItem
193155

@@ -209,7 +171,7 @@ struct SymbolGraphLoader {
209171
let (moduleName, isMainSymbolGraph) = Self.moduleNameFor(symbolGraph, at: url)
210172

211173
if !isMainSymbolGraph && symbolGraph.module.bystanders == nil {
212-
// If this is an extending another module, change the module name to match the exteneded module.
174+
// If this is an extending another module, change the module name to match the extended module.
213175
// This makes the symbols in this graph have a path that starts with the extended module's name.
214176
symbolGraph.module.name = moduleName
215177
}

Tests/SwiftDocCTests/Infrastructure/SymbolGraph/SymbolGraphLoaderTests.swift

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -329,150 +329,6 @@ class SymbolGraphLoaderTests: XCTestCase {
329329
XCTAssertEqual(loader.decodingStrategy, .concurrentlyEachFileInBatches)
330330
#endif
331331
}
332-
333-
func testInputWithMixedGraphFormats() throws {
334-
let tempURL = try createTemporaryDirectory()
335-
336-
let mainGraph = (url: tempURL.appendingPathComponent("A.symbols.json"),
337-
content: makeSymbolGraphString(moduleName: "A"))
338-
339-
let emptyExtensionGraph = (url: tempURL.appendingPathComponent("[email protected]"),
340-
content: makeSymbolGraphString(moduleName: "A"))
341-
342-
let extensionBlockFormatExtensionGraph = (url: tempURL.appendingPathComponent("[email protected]"),
343-
content: makeSymbolGraphString(moduleName: "A", symbols: """
344-
{
345-
"kind": {
346-
"identifier": "swift.extension",
347-
"displayName": "Extension"
348-
},
349-
"identifier": {
350-
"precise": "s:e:s:EBFfunction",
351-
"interfaceLanguage": "swift"
352-
},
353-
"pathComponents": [
354-
"EBF"
355-
],
356-
"names": {
357-
"title": "EBF",
358-
},
359-
"swiftExtension": {
360-
"extendedModule": "A",
361-
"typeKind": "struct"
362-
},
363-
"accessLevel": "public"
364-
},
365-
{
366-
"kind": {
367-
"identifier": "swift.func",
368-
"displayName": "Function"
369-
},
370-
"identifier": {
371-
"precise": "s:EBFfunction",
372-
"interfaceLanguage": "swift"
373-
},
374-
"pathComponents": [
375-
"EBF",
376-
"function"
377-
],
378-
"names": {
379-
"title": "function",
380-
},
381-
"swiftExtension": {
382-
"extendedModule": "A",
383-
"typeKind": "struct"
384-
},
385-
"accessLevel": "public"
386-
}
387-
""", relationships: """
388-
{
389-
"kind": "memberOf",
390-
"source": "s:EBFfunction",
391-
"target": "s:e:s:EBFfunction",
392-
"targetFallback": "A.EBF"
393-
},
394-
{
395-
"kind": "extensionTo",
396-
"source": "s:e:s:EBFfunction",
397-
"target": "s:EBF",
398-
"targetFallback": "A.EBF"
399-
}
400-
"""))
401-
402-
let noExtensionBlockFormatExtensionGraph = (url: tempURL.appendingPathComponent("[email protected]"),
403-
content: makeSymbolGraphString(moduleName: "A", symbols: """
404-
{
405-
"kind": {
406-
"identifier": "swift.func",
407-
"displayName": "Function"
408-
},
409-
"identifier": {
410-
"precise": "s:EBFfunction",
411-
"interfaceLanguage": "swift"
412-
},
413-
"pathComponents": [
414-
"EBF",
415-
"function"
416-
],
417-
"names": {
418-
"title": "function",
419-
},
420-
"swiftExtension": {
421-
"extendedModule": "A",
422-
"typeKind": "struct"
423-
},
424-
"accessLevel": "public"
425-
}
426-
""", relationships: """
427-
{
428-
"kind": "memberOf",
429-
"source": "s:EBFfunction",
430-
"target": "s:EBF",
431-
"targetFallback": "A.EBF"
432-
}
433-
"""))
434-
435-
let allGraphs = [mainGraph, emptyExtensionGraph, extensionBlockFormatExtensionGraph, noExtensionBlockFormatExtensionGraph]
436-
437-
for graph in allGraphs {
438-
try XCTUnwrap(graph.content.data(using: .utf8)).write(to: graph.url)
439-
}
440-
441-
let validUndetermined = [mainGraph, emptyExtensionGraph]
442-
var loader = try makeSymbolGraphLoader(symbolGraphURLs: validUndetermined.map(\.url))
443-
try loader.loadAll()
444-
// by default, extension graphs should be associated with the extended graph
445-
XCTAssertEqual(loader.unifiedGraphs.count, 2)
446-
447-
let validEBF = [mainGraph, emptyExtensionGraph, extensionBlockFormatExtensionGraph]
448-
loader = try makeSymbolGraphLoader(symbolGraphURLs: validEBF.map(\.url))
449-
try loader.loadAll()
450-
// found extension block symbols; extension graphs should be associated with the extending graph
451-
XCTAssertEqual(loader.unifiedGraphs.count, 1)
452-
453-
let validNEBF = [mainGraph, emptyExtensionGraph, noExtensionBlockFormatExtensionGraph]
454-
loader = try makeSymbolGraphLoader(symbolGraphURLs: validNEBF.map(\.url))
455-
try loader.loadAll()
456-
// found no extension block symbols; extension graphs should be associated with the extended graph
457-
XCTAssertEqual(loader.unifiedGraphs.count, 3)
458-
459-
let invalid = allGraphs
460-
loader = try makeSymbolGraphLoader(symbolGraphURLs: invalid.map(\.url))
461-
// found non-empty extension graphs with and without extension block symbols -> should throw
462-
XCTAssertThrowsError(try loader.loadAll(),
463-
"SymbolGraphLoader should throw when encountering a collection of symbol graph files, where some do and some don't use the extension block format") { error in
464-
XCTAssertFalse(error.localizedDescription.contains(mainGraph.url.absoluteString))
465-
XCTAssertFalse(error.localizedDescription.contains(emptyExtensionGraph.url.absoluteString))
466-
XCTAssert(error.localizedDescription.contains("""
467-
Symbol graph files with extension declarations:
468-
\(extensionBlockFormatExtensionGraph.url.absoluteString)
469-
"""))
470-
XCTAssert(error.localizedDescription.contains("""
471-
Symbol graph files without extension declarations:
472-
\(noExtensionBlockFormatExtensionGraph.url.absoluteString)
473-
"""))
474-
}
475-
}
476332

477333
func testConfiguresSymbolGraphs() throws {
478334
let tempURL = try createTemporaryDirectory()

0 commit comments

Comments
 (0)