Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC] Rename 'SyntaxArena' to 'RawSyntaxArena' #2926

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func rawSyntaxNodesFile(nodesStartingWith: [Character]) -> SourceFileSyntax {
let element = node.elementChoices.only != nil ? node.elementChoices.only!.raw.syntaxType : "Element"
DeclSyntax(
"""
public init(elements: [\(element)], arena: __shared SyntaxArena) {
public init(elements: [\(element)], arena: __shared RawSyntaxArena) {
let raw = RawSyntax.makeLayout(
kind: .\(node.memberCallName), uninitializedCount: elements.count, arena: arena) { layout in
guard var ptr = layout.baseAddress else { return }
Expand Down Expand Up @@ -154,7 +154,7 @@ func rawSyntaxNodesFile(nodesStartingWith: [Character]) -> SourceFileSyntax {
)
}

FunctionParameterSyntax("arena: __shared SyntaxArena")
FunctionParameterSyntax("arena: __shared RawSyntaxArena")
}
try InitializerDeclSyntax("public init(\(params))") {
if !node.children.isEmpty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
calledExpression: ExprSyntax("withExtendedLifetime"),
leftParen: .leftParenToken(),
arguments: LabeledExprListSyntax {
LabeledExprSyntax(expression: ExprSyntax("(SyntaxArena(), (\(parameters)))"))
LabeledExprSyntax(expression: ExprSyntax("(RawSyntaxArena(), (\(parameters)))"))
},
rightParen: .rightParenToken(),
trailingClosure: ClosureExprSyntax(signature: closureSignature) {
Expand Down Expand Up @@ -163,7 +163,7 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
AccessorDeclSyntax(
"""
set(value) {
self = Syntax(self).replacingChild(at: \(raw: index), with: Syntax(value), arena: SyntaxArena()).cast(\(node.kind.syntaxType).self)
self = Syntax(self).replacingChild(at: \(raw: index), with: Syntax(value), rawAllocationArena: RawSyntaxArena()).cast(\(node.kind.syntaxType).self)
}
"""
)
Expand Down Expand Up @@ -192,15 +192,15 @@ func syntaxNode(nodesStartingWith: [Character]) -> SourceFileSyntax {
@available(*, deprecated, message: "Use node.\(child.identifier).append(newElement) instead")
public func add\(raw: childElt)(_ element: \(childEltType)) -> \(node.kind.syntaxType) {
var collection: RawSyntax
let arena = SyntaxArena()
let arena = RawSyntaxArena()
if let col = raw.layoutView!.children[\(raw: index)] {
collection = col.layoutView!.appending(element.raw, arena: arena)
} else {
collection = RawSyntax.makeLayout(kind: SyntaxKind.\(childNode.memberCallName),
from: [element.raw], arena: arena)
}
return Syntax(self)
.replacingChild(at: \(raw: index), with: collection, rawNodeArena: arena, allocationArena: arena)
.replacingChild(at: \(raw: index), with: collection, rawNodeArena: arena, rawAllocationArena: arena)
.cast(\(node.kind.syntaxType).self)
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,30 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
DeclSyntax("public let viewMode: SyntaxTreeViewMode")
DeclSyntax(
"""
/// The arena in which the parents of rewritten nodes should be allocated.
/// The raw arena in which the parents of rewritten nodes should be allocated.
///
/// The `SyntaxRewriter` subclass is responsible for generating the rewritten nodes. To incorporate them into the
/// tree, all of the rewritten node's parents also need to be re-created. This is the arena in which those
/// intermediate nodes should be allocated.
private let arena: SyntaxArena?
/// intermediate raw nodes should be allocated.
private let rawArena: RawSyntaxArena?
"""
)

DeclSyntax(
"""
public init(viewMode: SyntaxTreeViewMode = .sourceAccurate) {
self.viewMode = viewMode
self.arena = nil
self.rawArena = nil
}
"""
)

DeclSyntax(
"""
@_spi(RawSyntax)
public init(viewMode: SyntaxTreeViewMode = .sourceAccurate, arena: SyntaxArena? = nil) {
public init(viewMode: SyntaxTreeViewMode = .sourceAccurate, rawAllocationArena: RawSyntaxArena? = nil) {
self.viewMode = viewMode
self.arena = arena
self.rawArena = rawAllocationArena
}
"""
)
Expand All @@ -71,7 +71,7 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
}

return withExtendedLifetime(rewritten) {
return Syntax(node).replacingSelf(rewritten.raw, rawNodeArena: rewritten.raw.arenaReference.retained, allocationArena: SyntaxArena())
return Syntax(node).replacingSelf(rewritten.raw, rawNodeArena: rewritten.raw.arenaReference.retained, rawAllocationArena: RawSyntaxArena())
}
}
"""
Expand Down Expand Up @@ -319,9 +319,9 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
// nodes are being collected.
var newLayout: UnsafeMutableBufferPointer<RawSyntax?> = .init(start: nil, count: 0)

// Keep 'SyntaxArena' of rewritten nodes alive until they are wrapped
// Keep 'RawSyntaxArena' of rewritten nodes alive until they are wrapped
// with 'Syntax'
var rewrittens: ContiguousArray<RetainedSyntaxArena> = []
var rewrittens: ContiguousArray<RetainedRawSyntaxArena> = []

for case let childDataRef? in node.layoutBuffer where viewMode.shouldTraverse(node: childDataRef.pointee.raw) {

Expand All @@ -347,13 +347,13 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
if newLayout.baseAddress != nil {
// A child node was rewritten. Build the updated node.

let arena = self.arena ?? SyntaxArena()
let newRaw = node.raw.layoutView!.replacingLayout(with: newLayout, arena: arena)
let rawArena = self.rawArena ?? RawSyntaxArena()
let newRaw = node.raw.layoutView!.replacingLayout(with: newLayout, arena: rawArena)
newLayout.deinitialize()
newLayout.deallocate()
// 'withExtendedLifetime' to keep 'SyntaxArena's of them alive until here.
// 'withExtendedLifetime' to keep 'RawSyntaxArena's of them alive until here.
return withExtendedLifetime(rewrittens) {
Syntax(raw: newRaw, rawNodeArena: arena)
Syntax(raw: newRaw, rawNodeArena: rawArena)
}
} else {
// No child node was rewritten. So no need to change this node as well.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ let triviaPiecesFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {

try FunctionDeclSyntax(
"""
static func make(_ piece: TriviaPiece, arena: SyntaxArena) -> RawTriviaPiece
static func make(_ piece: TriviaPiece, arena: RawSyntaxArena) -> RawTriviaPiece
"""
) {
try SwitchExprSyntax("switch piece") {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftIDEUtils/SyntaxClassifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private struct ClassificationVisitor {
self.targetRange = range
self.classifications = []

// `withExtendedLifetime` to make sure ``SyntaxArena`` for the node alive
// `withExtendedLifetime` to make sure ``RawSyntaxArena`` for the node alive
// during the visit.
withExtendedLifetime(node) {
_ = self.visit(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/Attributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ extension RawLabeledExprSyntax {
identifier: RawTokenSyntax,
_ unexpectedBetweenIdentifierAndTrailingComma: RawUnexpectedNodesSyntax? = nil,
trailingComma: RawTokenSyntax? = nil,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
) {
self.init(
label: nil,
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftParser/CollectionNodes+Parsable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fileprivate extension SyntaxCollection {
static func parse(
from parser: inout Parser,
parse: (_ parser: inout Parser) -> some RawSyntaxNodeProtocol,
makeMissing: (_ remainingTokens: [RawSyntax], _ arena: SyntaxArena) -> some RawSyntaxNodeProtocol
makeMissing: (_ remainingTokens: [RawSyntax], _ arena: RawSyntaxArena) -> some RawSyntaxNodeProtocol
) -> Self {
// Keep the parser alive so that the arena in which `raw` is allocated
// doesn’t get deallocated before we have a chance to create a syntax node
Expand Down
12 changes: 6 additions & 6 deletions Sources/SwiftParser/Nominals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protocol NominalTypeDeclarationTrait {
inheritanceClause: RawInheritanceClauseSyntax?,
genericWhereClause: RawGenericWhereClauseSyntax?,
memberBlock: RawMemberBlockSyntax,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
)

static func parsePrimaryOrGenerics(_ parser: inout Parser) -> PrimaryOrGenerics?
Expand All @@ -48,7 +48,7 @@ extension RawProtocolDeclSyntax: NominalTypeDeclarationTrait {
inheritanceClause: RawInheritanceClauseSyntax?,
genericWhereClause: RawGenericWhereClauseSyntax?,
memberBlock: RawMemberBlockSyntax,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
) {
self.init(
attributes: attributes,
Expand Down Expand Up @@ -82,7 +82,7 @@ extension RawClassDeclSyntax: NominalTypeDeclarationTrait {
inheritanceClause: RawInheritanceClauseSyntax?,
genericWhereClause: RawGenericWhereClauseSyntax?,
memberBlock: RawMemberBlockSyntax,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
) {
self.init(
attributes: attributes,
Expand Down Expand Up @@ -116,7 +116,7 @@ extension RawActorDeclSyntax: NominalTypeDeclarationTrait {
inheritanceClause: RawInheritanceClauseSyntax?,
genericWhereClause: RawGenericWhereClauseSyntax?,
memberBlock: RawMemberBlockSyntax,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
) {
self.init(
attributes: attributes,
Expand Down Expand Up @@ -150,7 +150,7 @@ extension RawStructDeclSyntax: NominalTypeDeclarationTrait {
inheritanceClause: RawInheritanceClauseSyntax?,
genericWhereClause: RawGenericWhereClauseSyntax?,
memberBlock: RawMemberBlockSyntax,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
) {
self.init(
attributes: attributes,
Expand Down Expand Up @@ -184,7 +184,7 @@ extension RawEnumDeclSyntax: NominalTypeDeclarationTrait {
inheritanceClause: RawInheritanceClauseSyntax?,
genericWhereClause: RawGenericWhereClauseSyntax?,
memberBlock: RawMemberBlockSyntax,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
) {
self.init(
attributes: attributes,
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftParser/Parameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension RawEnumCaseParameterSyntax: RawParameterTrait {}
protocol RawParameterListTrait: RawSyntaxNodeProtocol {
associatedtype ParameterSyntax: RawParameterTrait

init(elements: [ParameterSyntax], arena: __shared SyntaxArena)
init(elements: [ParameterSyntax], arena: __shared RawSyntaxArena)
}

extension RawFunctionParameterListSyntax: RawParameterListTrait {}
Expand All @@ -47,7 +47,7 @@ protocol RawParameterClauseTrait: RawSyntaxNodeProtocol {
_ unexpectedBetweenParameterListAndRightParen: RawUnexpectedNodesSyntax?,
rightParen: RawTokenSyntax,
_ unexpectedAfterRightParen: RawUnexpectedNodesSyntax?,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
)
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftParser/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
/// tokens as needed to disambiguate a parse. However, because lookahead
/// operates on a copy of the lexical stream, no input tokens are lost..
public struct Parser {
var arena: ParsingSyntaxArena
var arena: ParsingRawSyntaxArena

/// A view of the sequence of lexemes in the input.
var lexemes: Lexer.LexemeSequence
Expand Down Expand Up @@ -222,7 +222,7 @@ public struct Parser {
buffer input: UnsafeBufferPointer<UInt8>,
maximumNestingLevel: Int?,
parseTransition: IncrementalParseTransition?,
arena: ParsingSyntaxArena?,
arena: ParsingRawSyntaxArena?,
swiftVersion: SwiftVersion?,
experimentalFeatures: ExperimentalFeatures
) {
Expand All @@ -231,7 +231,7 @@ public struct Parser {
self.arena = arena
precondition(arena.contains(text: SyntaxText(baseAddress: input.baseAddress, count: input.count)))
} else {
self.arena = ParsingSyntaxArena(parseTriviaFunction: TriviaParser.parseTrivia)
self.arena = ParsingRawSyntaxArena(parseTriviaFunction: TriviaParser.parseTrivia)
input = self.arena.internSourceBuffer(input)
}

Expand Down Expand Up @@ -347,7 +347,7 @@ public struct Parser {
_ input: UnsafeBufferPointer<UInt8>,
maximumNestingLevel: Int? = nil,
parseTransition: IncrementalParseTransition? = nil,
arena: ParsingSyntaxArena? = nil,
arena: ParsingRawSyntaxArena? = nil,
swiftVersion: SwiftVersion? = nil,
experimentalFeatures: ExperimentalFeatures
) {
Expand Down Expand Up @@ -831,7 +831,7 @@ extension Parser {

/// Creates a replicate of `syntax` with all tokens marked as missing.
func withAllTokensMarkedMissing<T: RawSyntaxNodeProtocol>(syntax: T) -> T {
let tokenMissingMaker = TokenMissingMaker(arena: self.arena)
let tokenMissingMaker = TokenMissingMaker(rawAllocationArena: self.arena)
let allMissing = tokenMissingMaker.rewrite(
Syntax(raw: RawSyntax(syntax), rawNodeArena: self.arena)
).raw
Expand Down
14 changes: 7 additions & 7 deletions Sources/SwiftParser/Specifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ protocol RawMisplacedEffectSpecifiersTrait {
init(
asyncSpecifier: RawTokenSyntax?,
throwsClause: RawThrowsClauseSyntax?,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
)

func withMisplaced(
async misplacedAsyncKeyword: RawTokenSyntax?,
throws misplacedThrowsClause: RawThrowsClauseSyntax?,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
) -> Self
}

Expand All @@ -188,15 +188,15 @@ protocol RawEffectSpecifiersTrait: RawMisplacedEffectSpecifiersTrait {
_ unexpectedBetweenAsyncSpecifierAndThrowsClause: RawUnexpectedNodesSyntax?,
throwsClause: RawThrowsClauseSyntax?,
_ unexpectedAfterThrowsClause: RawUnexpectedNodesSyntax?,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
)
}

extension RawEffectSpecifiersTrait {
init(
asyncSpecifier: RawTokenSyntax?,
throwsClause: RawThrowsClauseSyntax?,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
) {
self.init(
nil,
Expand All @@ -211,7 +211,7 @@ extension RawEffectSpecifiersTrait {
func withMisplaced(
async misplacedAsyncKeyword: RawTokenSyntax?,
throws misplacedThrowsClause: RawThrowsClauseSyntax?,
arena: __shared SyntaxArena
arena: __shared RawSyntaxArena
) -> Self {
return Self.init(
self.unexpectedBeforeAsyncSpecifier,
Expand Down Expand Up @@ -543,7 +543,7 @@ extension RawDeinitializerEffectSpecifiersSyntax: RawMisplacedEffectSpecifiersTr
init(
asyncSpecifier: RawTokenSyntax?,
throwsClause: RawThrowsClauseSyntax?,
arena: __shared SwiftSyntax.SyntaxArena
arena: __shared SwiftSyntax.RawSyntaxArena
) {
// `throwsSpecifier` should never be present because `parseMisplacedEffectSpecifiers()` only creates missing tokens
// and `CorrectThrowsTokenKinds` is an empty `TokenSpecSet`.
Expand All @@ -561,7 +561,7 @@ extension RawDeinitializerEffectSpecifiersSyntax: RawMisplacedEffectSpecifiersTr
func withMisplaced(
async misplacedAsyncKeyword: RawTokenSyntax?,
throws misplacedThrowsClause: RawThrowsClauseSyntax?,
arena: SyntaxArena
arena: RawSyntaxArena
) -> RawDeinitializerEffectSpecifiersSyntax {
// `throwsClause` should never be present because `parseMisplacedEffectSpecifiers()` only creates missing tokens
// and `CorrectThrowsTokenKinds` is an empty `TokenSpecSet`.
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftParser/StringLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
fileprivate class StringLiteralExpressionIndentationChecker {
// MARK: Entry

init(expectedIndentation: SyntaxText, arena: SyntaxArena) {
init(expectedIndentation: SyntaxText, arena: RawSyntaxArena) {
self.expectedIndentation = expectedIndentation
self.arena = arena
}
Expand All @@ -37,7 +37,7 @@ fileprivate class StringLiteralExpressionIndentationChecker {
// MARK: Implementation

private let expectedIndentation: SyntaxText
private let arena: SyntaxArena
private let arena: RawSyntaxArena

private func visit(node: RawSyntax) -> RawSyntax? {
if node.isToken {
Expand Down
Loading