Skip to content

Commit aa5b5a3

Browse files
committed
track @_spi ness of declarations, and display the warning on the doc pages
1 parent c2fc598 commit aa5b5a3

File tree

11 files changed

+60
-21
lines changed

11 files changed

+60
-21
lines changed

Assets/css/Main.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/css/Main.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/Signatures/Signatures/Signature.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@ struct Signature<Scalar>:Equatable where Scalar:Hashable
1212
public
1313
var generics:Generics
1414

15+
/// Empty array means the declaration is gated by an SPI, but SymbolGraphGen doesn't know
16+
/// which one.
17+
public
18+
var spis:[String]?
19+
1520
@inlinable public
1621
init(availability:Availability = .init(),
1722
abridged:Abridged = .init(),
1823
expanded:Expanded = .init(),
19-
generics:Generics = .init())
24+
generics:Generics = .init(),
25+
spis:[String]? = nil)
2026
{
2127
self.availability = availability
2228
self.expanded = expanded
2329
self.abridged = abridged
2430
self.generics = generics
31+
self.spis = spis
2532
}
2633
}
2734
extension Signature:Sendable where Scalar:Sendable
@@ -35,6 +42,7 @@ extension Signature
3542
.init(availability: self.availability,
3643
abridged: .init(bytecode: self.abridged.bytecode),
3744
expanded: try self.expanded.map(transform),
38-
generics: try self.generics.map(transform))
45+
generics: try self.generics.map(transform),
46+
spis: self.spis)
3947
}
4048
}

Sources/SymbolGraphPartTests/Main.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ enum Main:SyncTests
9494
let part:SymbolGraphPart = tests.load(
9595
part: "TestModules/Symbolgraphs/SPI.symbols.json")
9696
{
97-
for (symbol, interfaces):([String], SymbolDescription.Interfaces?) in
97+
for (symbol, interfaces):([String], [String]?) in
9898
[
9999
(["NoSPI"], nil),
100-
(["SPI"], .init()),
100+
(["SPI"], []),
101101
]
102102
{
103103
if let symbol:SymbolDescription = tests.expect(symbol: symbol, in: part)
104104
{
105-
tests.expect(symbol.interfaces ==? interfaces)
105+
tests.expect(symbol.signature.spis ==? interfaces)
106106
}
107107
}
108108
}

Sources/SymbolGraphParts/Descriptions/SymbolDescription.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ struct SymbolDescription:Equatable, Sendable
1717
public
1818
let doccomment:Doccomment?
1919
public
20-
let interfaces:Interfaces?
21-
public
2220
let visibility:Visibility
2321
public
2422
let `extension`:ExtensionContext
@@ -36,15 +34,13 @@ struct SymbolDescription:Equatable, Sendable
3634
init(_ usr:Symbol,
3735
phylum:Unidoc.Phylum,
3836
doccomment:Doccomment?,
39-
interfaces:Interfaces?,
4037
visibility:Visibility,
4138
extension:ExtensionContext,
4239
signature:Signature<Symbol.Decl>,
4340
location:SourceLocation<String>?,
4441
path:UnqualifiedPath)
4542
{
4643
self.doccomment = doccomment
47-
self.interfaces = interfaces
4844
self.visibility = visibility
4945
self.extension = `extension`
5046
self.signature = signature
@@ -94,11 +90,12 @@ extension SymbolDescription
9490
}
9591

9692
// SymbolGraphGen incorrectly prints the fragment as 'class' in
97-
// the abridged signature
93+
// the abridged signature.
9894
let signature:Signature<Symbol.Decl> = .init(availability: availability,
9995
abridged: .init(abridged, actor: phylum == .decl(.actor)),
10096
expanded: expanded,
101-
generics: generics)
97+
generics: generics,
98+
spis: interfaces.map { _ in [] })
10299

103100
// strip empty parentheses from last path component
104101
let simplified:UnqualifiedPath
@@ -117,7 +114,6 @@ extension SymbolDescription
117114
self.init(usr,
118115
phylum: phylum,
119116
doccomment: doccomment.flatMap { $0.text.isEmpty ? nil : $0 },
120-
interfaces: interfaces,
121117
visibility: visibility,
122118
extension: `extension`,
123119
signature: signature,

Sources/SymbolGraphs/Declarations/SymbolGraph.Decl.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ extension SymbolGraph.Decl
109109
case signature_expanded_scalars = "K"
110110
case signature_generics_constraints = "C"
111111
case signature_generics_parameters = "G"
112+
case signature_spis = "I"
112113

113114
case requirements = "R"
114115
case superforms = "S"
@@ -150,6 +151,9 @@ extension SymbolGraph.Decl:BSONDocumentEncodable
150151
self.signature.generics.parameters.isEmpty ? nil :
151152
self.signature.generics.parameters
152153

154+
/// Do *not* elide empty SPI arrays!
155+
bson[.signature_spis] = self.signature.spis
156+
153157
bson[.requirements] = SymbolGraph.Buffer.init(elidingEmpty: self.requirements)
154158
bson[.superforms] = SymbolGraph.Buffer.init(elidingEmpty: self.superforms)
155159
bson[.features] = SymbolGraph.Buffer.init(elidingEmpty: self.features)
@@ -182,7 +186,8 @@ extension SymbolGraph.Decl:BSONDocumentDecodable
182186
scalars: try bson[.signature_expanded_scalars]?.decode() ?? []),
183187
generics: Signature<Int32>.Generics.init(
184188
constraints: try bson[.signature_generics_constraints]?.decode() ?? [],
185-
parameters: try bson[.signature_generics_parameters]?.decode() ?? [])),
189+
parameters: try bson[.signature_generics_parameters]?.decode() ?? []),
190+
spis: try bson[.signature_spis]?.decode()),
186191

187192
location: try bson[.location]?.decode(),
188193
article: try bson[.article]?.decode(),

Sources/UnidocPages/Templates/Site.Docs.Decl.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ extension Site.Docs.Decl:ApplicationPage
141141
}
142142
}
143143

144+
if let _:[String] = self.master.signature.spis
145+
{
146+
main[.section, { $0.class = "spi" }]
147+
{
148+
$0[.p] = """
149+
This declaration is gated by at least one @_spi attribute.
150+
"""
151+
}
152+
}
153+
144154
let availability:Availability = self.master.signature.availability
145155
if let notice:String = availability.notice
146156
{

Sources/UnidocRecords/Masters/Volume.Master.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ extension Volume.Master
136136
/// This field is cheap (64-bit integer plus 3 bytes of keying overhead) and
137137
/// allows us to reuse compound indices for zone-bound queries by performing
138138
/// an equality match instead of a range match.
139-
case zone = "I"
139+
case zone = "Z"
140140

141141
/// Appears in ``Decl`` and ``File``.
142142
case symbol = "Y"
@@ -161,7 +161,7 @@ extension Volume.Master
161161
case module = "M"
162162

163163
/// Only appears in ``Decl``.
164-
case flags = "Z"
164+
case flags = "F"
165165
/// Only appears in ``Decl``.
166166
case signature_availability = "A"
167167
/// Only appears in ``Decl``.
@@ -175,6 +175,8 @@ extension Volume.Master
175175
case signature_generics_constraints = "g"
176176
/// Only appears in ``Decl``.
177177
case signature_generics_parameters = "G"
178+
/// Only appears in ``Decl``.
179+
case signature_spis = "I"
178180
/// Only appears in ``Decl``. The field contains a list of scalars.
179181
case requirements = "r"
180182
/// Only appears in ``Decl``. The field contains a list of scalars.
@@ -269,6 +271,8 @@ extension Volume.Master:BSONDocumentEncodable
269271
self.signature.generics.parameters.isEmpty ? nil :
270272
self.signature.generics.parameters
271273

274+
bson[.signature_spis] = self.signature.spis
275+
272276
bson[.stem] = self.stem
273277

274278
bson[.requirements] = self.requirements.isEmpty ? nil : self.requirements
@@ -359,7 +363,8 @@ extension Volume.Master:BSONDocumentDecodable
359363
scalars: try bson[.signature_expanded_scalars]?.decode() ?? []),
360364
generics: Signature<Unidoc.Scalar?>.Generics.init(
361365
constraints: try bson[.signature_generics_constraints]?.decode() ?? [],
362-
parameters: try bson[.signature_generics_parameters]?.decode() ?? [])),
366+
parameters: try bson[.signature_generics_parameters]?.decode() ?? []),
367+
spis: try bson[.signature_spis]?.decode()),
363368
symbol: try bson[.symbol].decode(),
364369
stem: try bson[.stem].decode(),
365370
requirements: try bson[.requirements]?.decode() ?? [],

Stylesheets/_Colors.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ $light-snippet-line-number: rgb(192, 192, 192);
1515
$light-swift: rgb(134, 134, 134);
1616
$light-accent-comment: $light-foreground-semi;
1717
$light-accent-barbie-pink: rgb(255, 86, 158);
18+
$light-accent-barbie-pink-shadow: rgb(209, 23, 104);
19+
1820
$light-accent-hot-pink: rgb(253, 39, 110);
1921
$light-accent-yellow: rgb(255, 123, 0);
2022
$light-accent-lavender: rgb(189, 108, 255);

0 commit comments

Comments
 (0)