1
1
/*
2
2
This source file is part of the Swift.org open source project
3
3
4
- Copyright (c) 2023 Apple Inc. and the Swift project authors
4
+ Copyright (c) 2023-2024 Apple Inc. and the Swift project authors
5
5
Licensed under Apache License v2.0 with Runtime Library Exception
6
6
7
7
See https://swift.org/LICENSE.txt for license information
@@ -14,16 +14,16 @@ import SymbolKit
14
14
///
15
15
/// This is used to identify parsed path components as kind information.
16
16
private let knownSymbolKinds : Set < String > = {
17
- // There's nowhere else that registers these extended symbol kinds and we need to know them in this list .
18
- SymbolGraph . Symbol. KindIdentifier. register (
17
+ // We don't want to register these extended symbol kinds because that makes them available for decoding from symbol graphs which is unexpected .
18
+ let knownKinds = SymbolGraph . Symbol. KindIdentifier. allCases + [
19
19
. extendedProtocol,
20
20
. extendedStructure,
21
21
. extendedClass,
22
22
. extendedEnumeration,
23
23
. unknownExtendedType,
24
24
. extendedModule
25
- )
26
- return Set ( SymbolGraph . Symbol . KindIdentifier . allCases . map ( \. identifier) )
25
+ ]
26
+ return Set ( knownKinds . map ( \. identifier) )
27
27
} ( )
28
28
29
29
/// All known source language identifiers.
@@ -38,10 +38,13 @@ extension PathHierarchy {
38
38
let full : String
39
39
/// The parsed entity name
40
40
let name : Substring
41
- /// The parsed entity kind, if any.
42
- var kind : Substring ?
43
- /// The parsed entity hash, if any.
44
- var hash : Substring ?
41
+ /// The parsed disambiguation information, if any.
42
+ var disambiguation : Disambiguation ?
43
+
44
+ enum Disambiguation {
45
+ /// This path component uses a combination of kind and hash disambiguation
46
+ case kindAndHash( kind: Substring ? , hash: Substring ? )
47
+ }
45
48
}
46
49
47
50
enum PathParser {
@@ -65,13 +68,14 @@ extension PathHierarchy.PathParser {
65
68
static func parse( pathComponent original: Substring ) -> PathComponent {
66
69
let full = String ( original)
67
70
guard let dashIndex = original. lastIndex ( of: " - " ) else {
68
- return PathComponent ( full: full, name: full [ ... ] , kind : nil , hash : nil )
71
+ return PathComponent ( full: full, name: full [ ... ] , disambiguation : nil )
69
72
}
70
73
71
74
let hash = original [ dashIndex... ] . dropFirst ( )
72
75
let name = original [ ..< dashIndex]
73
76
74
77
func isValidHash( _ hash: Substring ) -> Bool {
78
+ // Checks if a string looks like a truncated, lowercase FNV-1 hash string.
75
79
var index : UInt8 = 0
76
80
for char in hash. utf8 {
77
81
guard index <= 5 , ( 48 ... 57 ) . contains ( char) || ( 97 ... 122 ) . contains ( char) else { return false }
@@ -82,28 +86,28 @@ extension PathHierarchy.PathParser {
82
86
83
87
if knownSymbolKinds. contains ( String ( hash) ) {
84
88
// The parsed hash value is a symbol kind
85
- return PathComponent ( full: full, name: name, kind: hash, hash: nil )
89
+ return PathComponent ( full: full, name: name, disambiguation : . kindAndHash ( kind: hash, hash: nil ) )
86
90
}
87
91
if let languagePrefix = knownLanguagePrefixes. first ( where: { hash. starts ( with: $0) } ) {
88
92
// The hash is actually a symbol kind with a language prefix
89
- return PathComponent ( full: full, name: name, kind: hash. dropFirst ( languagePrefix. count) , hash: nil )
93
+ return PathComponent ( full: full, name: name, disambiguation : . kindAndHash ( kind: hash. dropFirst ( languagePrefix. count) , hash: nil ) )
90
94
}
91
95
if !isValidHash( hash) {
92
96
// The parsed hash is neither a symbol not a valid hash. It's probably a hyphen-separated name.
93
- return PathComponent ( full: full, name: full [ ... ] , kind : nil , hash : nil )
97
+ return PathComponent ( full: full, name: full [ ... ] , disambiguation : nil )
94
98
}
95
99
96
100
if let dashIndex = name. lastIndex ( of: " - " ) {
97
101
let kind = name [ dashIndex... ] . dropFirst ( )
98
102
let name = name [ ..< dashIndex]
99
103
if knownSymbolKinds. contains ( String ( kind) ) {
100
- return PathComponent ( full: full, name: name, kind: kind, hash: hash)
104
+ return PathComponent ( full: full, name: name, disambiguation : . kindAndHash ( kind: kind, hash: hash) )
101
105
} else if let languagePrefix = knownLanguagePrefixes. first ( where: { kind. starts ( with: $0) } ) {
102
106
let kindWithoutLanguage = kind. dropFirst ( languagePrefix. count)
103
- return PathComponent ( full: full, name: name, kind: kindWithoutLanguage, hash: hash)
107
+ return PathComponent ( full: full, name: name, disambiguation : . kindAndHash ( kind: kindWithoutLanguage, hash: hash) )
104
108
}
105
109
}
106
- return PathComponent ( full: full, name: name, kind: nil , hash: hash)
110
+ return PathComponent ( full: full, name: name, disambiguation : . kindAndHash ( kind: nil , hash: hash) )
107
111
}
108
112
109
113
static func split( _ path: String ) -> ( componentSubstrings: [ Substring ] , isAbsolute: Bool ) {
0 commit comments