Skip to content

Commit aa207ff

Browse files
authored
Change function signatures of expansion functions of macros to be synchronous (#2546)
The different macro proposals have been inconsistent about whether the expansion function should be synchronous or asynchronous. - Synchronous - SE-0415 Function Body Macros - SE-0402 Extension Macros - SE-0407 Member Macro Conformances - SE-0397 Freestanding Declaration Macros (but future directions uses `async` function) - Async - SE-0389 Attached Macros - SE-0382 Expression Macros swift-syntax has always implemented synchronous expansion functions. Update the proposals to consistently use synchronous expansion functions to reflect that.
1 parent c8dbf85 commit aa207ff

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

proposals/0382-expression-macros.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public protocol ExpressionMacro: FreestandingMacro {
9292
static func expansion(
9393
of node: some FreestandingMacroExpansionSyntax,
9494
in context: some MacroExpansionContext
95-
) async throws -> ExprSyntax
95+
) throws -> ExprSyntax
9696
}
9797
```
9898

@@ -250,7 +250,7 @@ public protocol ExpressionMacro: FreestandingMacro {
250250
static func expansion(
251251
of node: some FreestandingMacroExpansionSyntax,
252252
in context: some MacroExpansionContext
253-
) async throws -> ExprSyntax
253+
) throws -> ExprSyntax
254254
}
255255
```
256256

@@ -260,8 +260,6 @@ Macro definitions should conform to the `ExpressionMacro` protocol and implement
260260

261261
If the macro expansion cannot proceed for some reason, the `expansion(of:in:)` operation can throw an error rather than try to produce a new syntax node. The compiler will then report the error to the user. More detailed diagnostics can be provided via the macro expansion context.
262262

263-
The macro expansion operation is asynchronous, to account for potentially-asynchronous operations that will eventually be added to `MacroExpansionContext`. For example, operations that require additional communication with the compiler to get types of subexpressions, access files in the program, and so on.
264-
265263
#### `MacroExpansionContext`
266264

267265
The macro expansion context provides additional information about the environment in which the macro is being expanded. This context can be queried as part of the macro expansion:
@@ -567,6 +565,8 @@ Expressions are just one place in the language where macros could be valuable. O
567565

568566
## Revision History
569567

568+
* Revision after acceptance:
569+
* Make the `ExpressionMacro.expansion(of:in:)` requirement non-`async`.
570570
* Revisions based on review feedback:
571571
* Switch `@expression` to `@freestanding(expression)` to align with the other macros proposals and vision document.
572572
* Make the `ExpressionMacro.expansion(of:in:)` requirement `async`.

proposals/0389-attached-macros.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public PeerMacro: AttachedMacro {
7171
of node: AttributeSyntax,
7272
providingPeersOf declaration: some DeclSyntaxProtocol,
7373
in context: some MacroExpansionContext
74-
) async throws -> [DeclSyntax]
74+
) throws -> [DeclSyntax]
7575
}
7676
```
7777

@@ -163,7 +163,7 @@ protocol MemberMacro: AttachedMacro {
163163
of node: AttributeSyntax,
164164
providingMembersOf declaration: some DeclGroupSyntax,
165165
in context: some MacroExpansionContext
166-
) async throws -> [DeclSyntax]
166+
) throws -> [DeclSyntax]
167167
}
168168
```
169169

@@ -232,7 +232,7 @@ protocol AccessorMacro: AttachedMacro {
232232
of node: AttributeSyntax,
233233
providingAccessorsOf declaration: some DeclSyntaxProtocol,
234234
in context: some MacroExpansionContext
235-
) async throws -> [AccessorDeclSyntax]
235+
) throws -> [AccessorDeclSyntax]
236236
}
237237
```
238238

@@ -294,7 +294,7 @@ protocol MemberAttributeMacro: AttachedMacro {
294294
attachedTo declaration: some DeclGroupSyntax,
295295
providingAttributesOf member: some DeclSyntaxProtocol,
296296
in context: some MacroExpansionContext
297-
) async throws -> [AttributeSyntax]
297+
) throws -> [AttributeSyntax]
298298
}
299299
```
300300

@@ -660,6 +660,8 @@ It might be possible to provide a macro implementation API that is expressed in
660660

661661
## Revision History
662662

663+
* Revision after acceptance:
664+
* Make the `expansion` requirements non-`async`.
663665
* After the first pitch:
664666
* Added conformance macros, to produce conformances
665667
* Moved the discussion of macro-introduced names from the freestanding macros proposal here.

proposals/0397-freestanding-declaration-macros.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public protocol CodeItemMacro: FreestandingMacro {
323323
static func expansion(
324324
of node: some FreestandingMacroExpansionSyntax,
325325
in context: some MacroExpansionContext
326-
) async throws -> [CodeBlockItemSyntax]
326+
) throws -> [CodeBlockItemSyntax]
327327
}
328328
```
329329

0 commit comments

Comments
 (0)