Skip to content

Commit 24c8f91

Browse files
committed
Mark Syntax.Info.info as nonisolated(unsafe)
1 parent ec82c81 commit 24c8f91

File tree

9 files changed

+38
-19
lines changed

9 files changed

+38
-19
lines changed

CodeGeneration/Sources/SyntaxSupport/Node.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ public class Node {
233233
// This will repeat the syntax type before and after the dot, which is
234234
// a little unfortunate, but it's the only way I found to get docc to
235235
// generate a fully-qualified type + member.
236-
return " - \($0.node.doccLink).``\($0.node.syntaxType)/\(childName)``"
236+
if $0.node.isAvailableInDocc {
237+
return " - \($0.node.doccLink).``\($0.node.syntaxType)/\(childName)``"
238+
} else {
239+
return " - \($0.node.doccLink).`\($0.node.syntaxType)/\(childName)`"
240+
}
237241
} else {
238242
return " - \($0.node.doccLink)"
239243
}

CodeGeneration/Sources/SyntaxSupport/SyntaxNodeKind.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,25 @@ public enum SyntaxNodeKind: String, CaseIterable {
355355
}
356356
}
357357

358+
/// Whether the node is public API and not underscored/deprecated and can thus be referenced in docc links.
359+
public var isAvailableInDocc: Bool {
360+
if let node = SYNTAX_NODE_MAP[self], node.isExperimental {
361+
return false
362+
} else if isDeprecated {
363+
return false
364+
} else {
365+
return true
366+
}
367+
}
368+
358369
/// If this node is non-experimental a docc link wrapped in two backticks.
359370
///
360371
/// For experimental nodes, the node's type name in code font.
361372
public var doccLink: String {
362-
if let node = SYNTAX_NODE_MAP[self], node.isExperimental {
363-
return "`\(syntaxType)`"
364-
} else {
373+
if isAvailableInDocc {
365374
return "``\(syntaxType)``"
375+
} else {
376+
return "`\(syntaxType)`"
366377
}
367378
}
368379

Sources/SwiftParser/Declarations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ extension Parser {
711711
extension Parser {
712712
mutating func parseMemberBlockItem() -> RawMemberBlockItemSyntax? {
713713
let startToken = self.currentToken
714-
if let syntax = self.loadCurrentSyntaxNodeFromCache(for: .memberBlockItemList) {
714+
if let syntax = self.loadCurrentSyntaxNodeFromCache(for: .memberBlockItem) {
715715
self.registerNodeForIncrementalParse(node: syntax.raw, startToken: startToken)
716716
return RawMemberBlockItemSyntax(syntax.raw)
717717
}

Sources/SwiftSyntax/Syntax.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public struct Syntax: SyntaxProtocol, SyntaxHashable {
4646
/// - Important: Must only be set to `nil` when `Syntax.Info` is used in a memory recycling pool
4747
/// (eg. in `SyntaxVisitor`). In that case the `Syntax.Info` is considered garbage memory that can be re-used
4848
/// later. `info` needs to be set to a real value when `Syntax.Info` is recycled from the memory recycling pool.
49+
#if compiler(>=6.0)
50+
nonisolated(unsafe) var info: InfoImpl!
51+
#else
4952
var info: InfoImpl!
53+
#endif
5054
}
5155

5256
/// Reference to the node's parent or, if this node is the root of a tree, a reference to the `SyntaxArena` to keep

Sources/SwiftSyntax/generated/SyntaxRewriter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,14 @@ open class SyntaxRewriter {
283283
return StmtSyntax(visitChildren(node))
284284
}
285285

286-
/// Visit a ``_CanImportExprSyntax``.
286+
/// Visit a `_CanImportExprSyntax`.
287287
/// - Parameter node: the node that is being visited
288288
/// - Returns: the rewritten node
289289
open func visit(_ node: _CanImportExprSyntax) -> ExprSyntax {
290290
return ExprSyntax(visitChildren(node))
291291
}
292292

293-
/// Visit a ``_CanImportVersionInfoSyntax``.
293+
/// Visit a `_CanImportVersionInfoSyntax`.
294294
/// - Parameter node: the node that is being visited
295295
/// - Returns: the rewritten node
296296
open func visit(_ node: _CanImportVersionInfoSyntax) -> ExprSyntax {

Sources/SwiftSyntax/generated/SyntaxVisitor.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,26 +377,26 @@ open class SyntaxVisitor {
377377
open func visitPost(_ node: BreakStmtSyntax) {
378378
}
379379

380-
/// Visiting ``_CanImportExprSyntax`` specifically.
380+
/// Visiting `_CanImportExprSyntax` specifically.
381381
/// - Parameter node: the node we are visiting.
382382
/// - Returns: how should we continue visiting.
383383
open func visit(_ node: _CanImportExprSyntax) -> SyntaxVisitorContinueKind {
384384
return .visitChildren
385385
}
386386

387-
/// The function called after visiting ``_CanImportExprSyntax`` and its descendants.
387+
/// The function called after visiting `_CanImportExprSyntax` and its descendants.
388388
/// - node: the node we just finished visiting.
389389
open func visitPost(_ node: _CanImportExprSyntax) {
390390
}
391391

392-
/// Visiting ``_CanImportVersionInfoSyntax`` specifically.
392+
/// Visiting `_CanImportVersionInfoSyntax` specifically.
393393
/// - Parameter node: the node we are visiting.
394394
/// - Returns: how should we continue visiting.
395395
open func visit(_ node: _CanImportVersionInfoSyntax) -> SyntaxVisitorContinueKind {
396396
return .visitChildren
397397
}
398398

399-
/// The function called after visiting ``_CanImportVersionInfoSyntax`` and its descendants.
399+
/// The function called after visiting `_CanImportVersionInfoSyntax` and its descendants.
400400
/// - node: the node we just finished visiting.
401401
open func visitPost(_ node: _CanImportVersionInfoSyntax) {
402402
}

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesC.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/// - `canImportKeyword`: `canImport`
2020
/// - `leftParen`: `(`
2121
/// - `importPath`: `<identifier>`
22-
/// - `versionInfo`: ``_CanImportVersionInfoSyntax``?
22+
/// - `versionInfo`: `_CanImportVersionInfoSyntax`?
2323
/// - `rightParen`: `)`
2424
public struct _CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExprSyntaxNodeProtocol {
2525
public let _syntaxNode: Syntax
@@ -229,7 +229,7 @@ public struct _CanImportExprSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExp
229229
///
230230
/// ### Contained in
231231
///
232-
/// - ``_CanImportExprSyntax``.``_CanImportExprSyntax/versionInfo``
232+
/// - `_CanImportExprSyntax`.`_CanImportExprSyntax/versionInfo`
233233
public struct _CanImportVersionInfoSyntax: ExprSyntaxProtocol, SyntaxHashable, _LeafExprSyntaxNodeProtocol {
234234
public let _syntaxNode: Syntax
235235

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3796,7 +3796,7 @@ public struct VersionComponentSyntax: SyntaxProtocol, SyntaxHashable, _LeafSynta
37963796
/// ### Contained in
37973797
///
37983798
/// - ``AvailabilityLabeledArgumentSyntax``.``AvailabilityLabeledArgumentSyntax/value``
3799-
/// - ``_CanImportVersionInfoSyntax``.``_CanImportVersionInfoSyntax/version``
3799+
/// - `_CanImportVersionInfoSyntax`.`_CanImportVersionInfoSyntax/version`
38003800
/// - ``PlatformVersionSyntax``.``PlatformVersionSyntax/version``
38013801
public struct VersionTupleSyntax: SyntaxProtocol, SyntaxHashable, _LeafSyntaxNodeProtocol {
38023802
public let _syntaxNode: Syntax

Tests/SwiftParserTest/IncrementalParsingTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class IncrementalParsingTests: ParserTestCase {
2323
struct A⏩️⏸️A⏪️ { func f() {
2424
""",
2525
reusedNodes: [
26-
ReusedNodeSpec("func f() {", kind: .memberDeclListItem)
26+
ReusedNodeSpec("func f() {", kind: .memberBlockItem)
2727
]
2828
)
2929
}
@@ -191,10 +191,10 @@ class IncrementalParsingTests: ParserTestCase {
191191
}
192192
""",
193193
reusedNodes: [
194-
ReusedNodeSpec("let a: Int", kind: .memberDeclListItem),
195-
ReusedNodeSpec("let b: Int", kind: .memberDeclListItem),
196-
ReusedNodeSpec("let c: Int", kind: .memberDeclListItem),
197-
ReusedNodeSpec("let g: Int", kind: .memberDeclListItem),
194+
ReusedNodeSpec("let a: Int", kind: .memberBlockItem),
195+
ReusedNodeSpec("let b: Int", kind: .memberBlockItem),
196+
ReusedNodeSpec("let c: Int", kind: .memberBlockItem),
197+
ReusedNodeSpec("let g: Int", kind: .memberBlockItem),
198198
]
199199
)
200200
}

0 commit comments

Comments
 (0)