swiftlang / swiftlang/swift-syntax
[macros] Further improve specializing generics in macros
- Dominant language
- Swift
- Stars
- 3.7k
- Forks
- 553
- Avg merge
- 5d 13h
- Merged PRs (30d)
- 16
Description
### Description
In https://github.com/apple/swift-syntax/pull/2450 we introduced
```
@freestanding(expression)
public macro checkGeneric_root() = #externalMacro(module: "MacroDefinition", type: "GenericToVoidMacro")
@freestanding(expression)
public macro checkGeneric() = #checkGeneric_root()
```
such that the DAS gets replaced in every expansion:
```
checkGeneric -> checkGeneric_root
```
---
but the following cases are not replaced yet:
Would it make sense to specialize macros with types that aren’t part of the second-level macro? Ie. would the following make sense?
```
macro gen(a: T) = #externalMacro …
macro genString(a: String) = #gen(a: a)
```
And then #genString(a: "x") would have the intermediate expansion step #gen(a: "x")
-------
Similarly, would it make sense to allow generic nesting in a second-level macro definition? Ie. would something like the following make sense?
```
macro gen(a: T) = #externalMacro …
macro genArray(a: [T]) = #gen>(a: a)
```
And then #genArray(a: [1]) would have the intermediate expansion step #gen>(a: [1])
----
https://github.com/apple/swift-syntax/pull/2450#discussion_r1479217425
### Steps to Reproduce
_No response_
#### Radar
rdar://122364628
Contributor guide
Assessment
This issue has not been assessed yet.