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

Add support for asynchronous macro expansion #2896

Open
wants to merge 3 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 @@ -26,6 +26,9 @@ private let swiftParserGeneratedDir = ["SwiftParser", generatedDirName]
private let swiftParserDiagnosticsGeneratedDir = ["SwiftParserDiagnostics", generatedDirName]
private let swiftSyntaxGeneratedDir = ["SwiftSyntax", generatedDirName]
private let swiftSyntaxBuilderGeneratedDir = ["SwiftSyntaxBuilder", generatedDirName]
private let swiftSyntaxMacroExpansionGeneratedDir = ["SwiftSyntaxMacroExpansion", generatedDirName]
private let swiftSyntaxMacrosGenericTestSupportGeneratedDir = ["SwiftSyntaxMacrosGenericTestSupport", generatedDirName]
private let swiftSyntaxMacrosTestSupportGeneratedDir = ["SwiftSyntaxMacrosTestSupport", generatedDirName]
private let BASE_KIND_FILES: [SyntaxNodeKind: String] = [
.decl: "SyntaxDeclNodes.swift",
.expr: "SyntaxExprNodes.swift",
Expand Down Expand Up @@ -129,6 +132,15 @@ struct GenerateSwiftSyntax: AsyncParsableCommand {
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxEnum.swift"], syntaxEnumFile),
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxKind.swift"], syntaxKindFile),
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxRewriter.swift"], syntaxRewriterFile),
GeneratedFileSpec(
swiftSyntaxGeneratedDir + ["AsyncSyntaxRewriter.swift"],
makeSyntaxRewriterFile(
className: "AsyncSyntaxRewriter",
functionEffectSpecifiers: "async",
functionCallOperators: "await",
spiName: "MacroExpansion"
)
),
GeneratedFileSpec(swiftSyntaxGeneratedDir + ["SyntaxTraits.swift"], syntaxTraitsFile),
GeneratedFileSpec(
swiftSyntaxGeneratedDir + ["SyntaxVisitor.swift"],
Expand All @@ -151,6 +163,28 @@ struct GenerateSwiftSyntax: AsyncParsableCommand {
swiftSyntaxBuilderGeneratedDir + ["RenamedChildrenBuilderCompatibility.swift"],
renamedChildrenBuilderCompatibilityFile
),

// SwiftSyntaxMacroExpansion
GeneratedFileSpec(
swiftSyntaxMacroExpansionGeneratedDir + ["MacroExpansion.swift"],
macroExpansionFile
),
GeneratedFileSpec(
swiftSyntaxMacroExpansionGeneratedDir + ["MacroSystem.swift"],
macroSystemFile
),

// SwiftSyntaxMacrosGenericTestSupport
GeneratedFileSpec(
swiftSyntaxMacrosGenericTestSupportGeneratedDir + ["Assertions.swift"],
genericMacroAssertionsFile
),

// SwiftSyntaxMacrosTestSupport
GeneratedFileSpec(
swiftSyntaxMacrosTestSupportGeneratedDir + ["Assertions.swift"],
macroAssertionsFile
),
]
// This split of letters produces files for the syntax nodes that have about equal size, which improves compile time

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code.
- <doc:SwiftSyntax/SyntaxVisitor>
- <doc:SwiftSyntax/SyntaxAnyVisitor>
- <doc:SwiftSyntax/SyntaxRewriter>
- <doc:SwiftSyntax/AsyncSyntaxRewriter>
- <doc:SwiftSyntax/SyntaxTreeViewMode>
- <doc:SwiftSyntax/SyntaxVisitorContinueKind>
- <doc:SwiftSyntax/ReversedTokenSequence>
Expand Down
Loading