Skip to content

Commit adc9f33

Browse files
committed
Make SyntaxArena SPI
Mark `SyntaxArena` and `ParsingSyntaxArena` with `@_spi(RawSyntax)`. `SyntaxArena` and its subclass `ParsingSyntaxArena` were only meant be used when dealing with `RawSyntax` which is already a SPI. Although type type itself was `public`, most initializers were SPI, also there was no way to retrieve it from existing types via public API. So we assume no one was actually using it directly.
1 parent eae92fe commit adc9f33

File tree

7 files changed

+10
-19
lines changed

7 files changed

+10
-19
lines changed

CodeGeneration/Sources/generate-swift-syntax/templates/swiftsyntax/SwiftSyntaxDoccIndexTemplate.md

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
6666
### Internals
6767

6868
- <doc:SwiftSyntax/SyntaxProtocol>
69-
- <doc:SwiftSyntax/SyntaxArena>
7069
- <doc:SwiftSyntax/SyntaxEnum>
7170
- <doc:SwiftSyntax/SyntaxHashable>
7271
- <doc:SwiftSyntax/SyntaxIdentifier>

Release Notes/602.md

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
- Migration steps: Replace uses of `ExpandEditorPlaceholdersToTrailingClosures` with `ExpandEditorPlaceholdersToLiteralClosures`. The initializer does not need to change: `.init(indentationWidth:)` on the new type provides the same behavior as the old type.
1515
- Notes: This improves code completion in a SourceKitLSP session where the trailing closure form may be undesirable. The nested placeholders offer more flexibility to end users, in editors that support it.
1616

17+
- `SyntaxArena` and `ParsingSyntaxArena` has changed to SPI
18+
- Description: `SyntaxArena` and the subclasses were only meant to be used when dealing with `RawSyntax` which is also SPI.
19+
- Pull Request: https://github.com/swiftlang/swift-syntax/pull/2930
20+
- Migration steps: Do not use `SyntaxArena` or `ParsingSyntaxArena` directly.
21+
- Notes: Although the type itself was `public`, most initializers were already SPI and there was no way to retrive them from existing types via public API.
22+
1723
## Template
1824

1925
- *Affected API or two word description*

Sources/SwiftParser/Parser.swift

+1-6
Original file line numberDiff line numberDiff line change
@@ -303,23 +303,18 @@ public struct Parser {
303303
/// if this is `nil`.
304304
/// - parseTransition: The previously recorded state for an incremental
305305
/// parse, or `nil`.
306-
/// - arena: Arena the parsing syntax are made into. If it's `nil`, a new
307-
/// arena is created automatically, and `input` copied into the
308-
/// arena. If non-`nil`, `input` must be within its registered
309-
/// source buffer or allocator.
310306
public init(
311307
_ input: UnsafeBufferPointer<UInt8>,
312308
maximumNestingLevel: Int? = nil,
313309
parseTransition: IncrementalParseTransition? = nil,
314-
arena: ParsingSyntaxArena? = nil,
315310
swiftVersion: SwiftVersion? = nil
316311
) {
317312
// Chain to the private buffer initializer.
318313
self.init(
319314
buffer: input,
320315
maximumNestingLevel: maximumNestingLevel,
321316
parseTransition: parseTransition,
322-
arena: arena,
317+
arena: nil,
323318
swiftVersion: swiftVersion,
324319
experimentalFeatures: []
325320
)

Sources/SwiftSyntax/Documentation.docc/Glossary.md

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ Glossary of terms and abbreviations used in SwiftSyntax
77
To avoid ongoing repetition of common long terms, SwiftSyntax uses a couple of abbreviations that are common in compiler projects.
88

99

10-
**Arena** See ``SyntaxArena``
11-
1210
**Decl** Abbreviation for *Declaration*
1311

1412
**Expr** Abbreviation for *Expression*

Sources/SwiftSyntax/Documentation.docc/generated/SwiftSyntax.md

-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
411411
### Internals
412412

413413
- <doc:SwiftSyntax/SyntaxProtocol>
414-
- <doc:SwiftSyntax/SyntaxArena>
415414
- <doc:SwiftSyntax/SyntaxEnum>
416415
- <doc:SwiftSyntax/SyntaxHashable>
417416
- <doc:SwiftSyntax/SyntaxIdentifier>

Sources/SwiftSyntax/MissingNodeInitializers.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
extension MissingDeclSyntax {
1414
public init(
1515
attributes: AttributeListSyntax,
16-
modifiers: DeclModifierListSyntax,
17-
arena: __shared SyntaxArena
16+
modifiers: DeclModifierListSyntax
1817
) {
1918
self.init(
2019
attributes: attributes,

Sources/SwiftSyntax/SyntaxArena.swift

+2-7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
/// As an added benefit of the ``SyntaxArena``, `RawSyntax` nodes don’t need to
4444
/// be reference-counted, further improving the performance of ``SwiftSyntax``
4545
/// when worked with at that level.
46+
@_spi(RawSyntax)
4647
public class SyntaxArena {
4748
/// Bump-pointer allocator for all "intern" methods.
4849
fileprivate let allocator: BumpPtrAllocator
@@ -105,7 +106,6 @@ public class SyntaxArena {
105106

106107
/// Copies the contents of a ``SyntaxText`` to the memory this arena manages,
107108
/// and return the ``SyntaxText`` in the destination.
108-
@_spi(RawSyntax)
109109
public func intern(_ value: SyntaxText) -> SyntaxText {
110110
// Return the passed-in value if it's already managed by this arena.
111111
if self.contains(text: value) {
@@ -119,7 +119,6 @@ public class SyntaxArena {
119119

120120
/// Copies a UTF8 sequence of `String` to the memory this arena manages, and
121121
/// returns the copied string as a ``SyntaxText``
122-
@_spi(RawSyntax)
123122
public func intern(_ value: String) -> SyntaxText {
124123
if value.isEmpty { return SyntaxText() }
125124
var value = value
@@ -173,8 +172,8 @@ public class SyntaxArena {
173172
}
174173

175174
/// SyntaxArena for parsing.
175+
@_spi(RawSyntax)
176176
public class ParsingSyntaxArena: SyntaxArena {
177-
@_spi(RawSyntax)
178177
public typealias ParseTriviaFunction = (_ source: SyntaxText, _ position: TriviaPosition) -> [RawTriviaPiece]
179178

180179
/// Source file buffer the Syntax tree represents.
@@ -185,7 +184,6 @@ public class ParsingSyntaxArena: SyntaxArena {
185184
/// - Important: Must never be changed to a mutable value. See `SyntaxArenaRef.parseTrivia`.
186185
private let parseTriviaFunction: ParseTriviaFunction
187186

188-
@_spi(RawSyntax)
189187
public init(parseTriviaFunction: @escaping ParseTriviaFunction) {
190188
self.sourceBuffer = .init(start: nil, count: 0)
191189
self.parseTriviaFunction = parseTriviaFunction
@@ -198,7 +196,6 @@ public class ParsingSyntaxArena: SyntaxArena {
198196
/// The interned buffer is guaranteed to be null-terminated.
199197
/// `contains(address _:)` is faster if the address is inside the memory
200198
/// range this function returned.
201-
@_spi(RawSyntax)
202199
public func internSourceBuffer(_ buffer: UnsafeBufferPointer<UInt8>) -> UnsafeBufferPointer<UInt8> {
203200
let allocated = allocator.allocate(
204201
UInt8.self,
@@ -214,7 +211,6 @@ public class ParsingSyntaxArena: SyntaxArena {
214211
return sourceBuffer
215212
}
216213

217-
@_spi(RawSyntax)
218214
public override func contains(text: SyntaxText) -> Bool {
219215
if let addr = text.baseAddress, self.sourceBufferContains(addr) {
220216
return true
@@ -230,7 +226,6 @@ public class ParsingSyntaxArena: SyntaxArena {
230226
}
231227

232228
/// Parse `source` into a list of ``RawTriviaPiece`` using `parseTriviaFunction`.
233-
@_spi(RawSyntax)
234229
public func parseTrivia(source: SyntaxText, position: TriviaPosition) -> [RawTriviaPiece] {
235230
// Must never access mutable state. See `SyntaxArenaRef.parseTrivia`.
236231
return self.parseTriviaFunction(source, position)

0 commit comments

Comments
 (0)