Skip to content

Commit 7369b86

Browse files
authored
Merge pull request #318 from tayloraswift/multiple-origins
Multiple origins
2 parents f3912f8 + f634d4f commit 7369b86

File tree

11 files changed

+62
-47
lines changed

11 files changed

+62
-47
lines changed

Sources/SymbolGraphBuilder/SSGC.Compile.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ extension SSGC.Compile
182182
}
183183
catch let error as SSGC.DocumentationBuildError
184184
{
185+
// We need to print the error here, otherwise it will be lost.
186+
print(error)
187+
185188
switch error
186189
{
187190
case .scanning: try status.send(.failedToLoadSymbolGraph)

Sources/SymbolGraphCompiler/Declarations/SSGC.Decl.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ extension SSGC
4444
public internal(set)
4545
var superforms:Set<Symbol.Decl>
4646

47-
/// A scalar that has documentation that is relevant, but less specific
48-
/// to this scalar.
47+
/// Scalars that potentially have documentation that is relevant, but less specific
48+
/// to this scalar. Only one will be ultimately used, but the others are kept for
49+
/// de-duplication purposes.
4950
public internal(set)
50-
var origin:Symbol.Decl?
51+
var origins:Set<Symbol.Decl>
5152
public internal(set)
5253
var kinks:Phylum.Decl.Kinks
5354

@@ -73,7 +74,7 @@ extension SSGC
7374
self.requirements = []
7475
self.inhabitants = []
7576
self.superforms = []
76-
self.origin = nil
77+
self.origins = []
7778

7879
self.kinks = kinks
7980
self.comment = comment

Sources/SymbolGraphCompiler/Declarations/SSGC.DeclObject.swift

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,9 @@ extension SSGC.DeclObject
7878
extension SSGC.DeclObject
7979
{
8080
/// Assigns an origin to this scalar object.
81-
func assign(origin:Symbol.Decl) throws
81+
func assign(origin:Symbol.Decl)
8282
{
83-
switch self.value.origin
84-
{
85-
case nil, origin?:
86-
self.value.origin = origin
87-
88-
case let other?:
89-
throw SSGC.SemanticError.already(has: .origin(other))
90-
}
83+
self.value.origins.insert(origin)
9184
}
9285
/// Assigns a lexical scope to this scalar object.
9386
func assign(scope:Symbol.Decl, by relationship:some NestingRelationship) throws
@@ -107,7 +100,7 @@ extension SSGC.DeclObject
107100
case let existing?:
108101
if case .s = self.id.language
109102
{
110-
throw SSGC.SemanticError.already(has: .scope(existing))
103+
throw SSGC.LexicalScopeError.multiple(existing, scope)
111104
}
112105
else
113106
{
@@ -122,7 +115,7 @@ extension SSGC.DeclObject
122115

123116
if let origin:Symbol.Decl = relationship.origin
124117
{
125-
try self.assign(origin: origin)
118+
self.assign(origin: origin)
126119
}
127120
}
128121
/// Adds a superform to this scalar object.
@@ -155,7 +148,7 @@ extension SSGC.DeclObject
155148
}
156149
if let origin:Symbol.Decl = relationship.origin
157150
{
158-
try self.assign(origin: origin)
151+
self.assign(origin: origin)
159152
}
160153
}
161154
/// Adds a requirement to this scalar object, assuming it is a protocol.

Sources/SymbolGraphCompiler/Declarations/SSGC.Declarations.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,17 @@ extension SSGC.Declarations
150150
var decl:SSGC.Decl = $1.value
151151

152152
// Strip duplicated doccomments
153-
if let documentationComment:SSGC.DocumentationComment = decl.comment,
154-
let origin:Symbol.Decl = decl.origin,
155-
let originComment:SSGC.DocumentationComment = self.decls[origin]?.value.comment,
156-
originComment.text == documentationComment.text
153+
if let documentationComment:SSGC.DocumentationComment = decl.comment
157154
{
158-
decl.comment = nil
155+
for origin:Symbol.Decl in decl.origins
156+
{
157+
if let origin:SSGC.Decl = self.decls[origin]?.value,
158+
let originComment:SSGC.DocumentationComment = origin.comment,
159+
originComment.text == documentationComment.text
160+
{
161+
decl.comment = nil
162+
}
163+
}
159164
}
160165

161166
$0[$1.namespace, default: []].append(decl)

Sources/SymbolGraphCompiler/SSGC.TypeChecker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ extension SSGC.TypeChecker
370370

371371
if let origin:Symbol.Decl = conformance.origin
372372
{
373-
try type.assign(origin: origin)
373+
type.assign(origin: origin)
374374
}
375375
if case .protocol = type.value.phylum
376376
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Symbols
2+
3+
extension SSGC
4+
{
5+
enum LexicalScopeError:Error, Sendable
6+
{
7+
case multiple(Symbol.Decl, Symbol.Decl)
8+
}
9+
}
10+
extension SSGC.LexicalScopeError:CustomStringConvertible
11+
{
12+
public
13+
var description:String
14+
{
15+
switch self
16+
{
17+
case .multiple(let existing, let scope):
18+
"""
19+
Scalar already has a lexical scope (\(existing)) and cannot have another (\(scope))
20+
"""
21+
}
22+
}
23+
}

Sources/SymbolGraphCompiler/Sema/SSGC.SemanticError.Counterpart.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

Sources/SymbolGraphCompiler/Sema/SSGC.SemanticError.swift

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ extension SSGC
55
public
66
enum SemanticError:Error, Sendable
77
{
8-
case already(has:Counterpart)
98
case cannot(have:Counterparts, as:Phylum.Decl)
109
}
1110
}
@@ -16,26 +15,20 @@ extension SSGC.SemanticError:CustomStringConvertible
1615
{
1716
switch self
1817
{
19-
case .already(has: .origin(let symbol)):
20-
"Scalar already has an origin, \(symbol)."
21-
22-
case .already(has: .scope(let symbol)):
23-
"Scalar already has a lexical scope, \(symbol)."
24-
2518
case .cannot(have: .requirements, as: let phylum):
26-
"Scalar of phylum '\(phylum)' cannot have requirements."
19+
"Scalar of phylum '\(phylum)' cannot have requirements"
2720

2821
case .cannot(have: .inhabitants, as: let phylum):
29-
"Scalar of phylum '\(phylum)' cannot have enumeration cases."
22+
"Scalar of phylum '\(phylum)' cannot have enumeration cases"
3023

3124
case .cannot(have: .scope, as: let phylum):
32-
"Scalar of phylum '\(phylum)' cannot have a lexical scope."
25+
"Scalar of phylum '\(phylum)' cannot have a lexical scope"
3326

3427
case .cannot(have: .superforms(besides: nil), as: let phylum):
35-
"Scalar of phylum '\(phylum)' cannot have superforms."
28+
"Scalar of phylum '\(phylum)' cannot have superforms"
3629

3730
case .cannot(have: .superforms(besides: let type?), as: _):
38-
"Scalar already has superforms of type \(type)."
31+
"Scalar already has superforms of type \(type)"
3932
}
4033
}
4134
}

Sources/SymbolGraphLinker/SSGC.Linker.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,9 @@ extension SSGC.Linker
542542
let requirements:[Int32] = decl.requirements.sorted().map { self.tables.intern($0) }
543543
let inhabitants:[Int32] = decl.inhabitants.sorted().map { self.tables.intern($0) }
544544
let superforms:[Int32] = decl.superforms.sorted().map { self.tables.intern($0) }
545-
let origin:Int32? = decl.origin.map { self.tables.intern($0) }
545+
/// We don’t have a great way to choose which origin to keep, so we just keep the first
546+
/// one in alphabetical order.
547+
let origin:Int32? = decl.origins.sorted().first.map { self.tables.intern($0) }
546548

547549
let location:SourceLocation<Int32>? = decl.location?.map
548550
{

Sources/SymbolGraphs/SymbolGraphABI.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import SemanticVersions
33
@frozen public
44
enum SymbolGraphABI
55
{
6-
@inlinable public static var version:PatchVersion { .v(0, 10, 1) }
6+
@inlinable public static var version:PatchVersion { .v(0, 10, 2) }
77
}

0 commit comments

Comments
 (0)