Skip to content

Conversation

@DougGregor
Copy link
Member

@DougGregor DougGregor commented Mar 16, 2023

Introduce APIs to help with expanding a macro that is defined in terms of another macro, e.g.,

macro f(a: Int) = #g(a: a, b: "something")

There are effectively two new APIs:

  • MacroDeclSyntax.checkDefinition() checks that the definition of a macro is well-formed, producing a semantic representation suitable for expansion when it is, or produces error diagnostics when it isn't.
  • MacroDeclSyntax.expand which takes that semantic representation and a (well-formed) argument list or syntax node and performs the actual expansion.

@DougGregor
Copy link
Member Author

@swift-ci please test

Split the API for macro definition checking and expansion into two
distinct parts: a definition-checking operation that can fail
(producing error diagnostics) and an expansion operation that cannot
fail (for expansion). This better matches the structure that clients
(i.e., the compiler) should use.
We are likely to grow more of these utilities, and they might
eventually be sunk down into a common library, so keep the factored
out.
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

@DougGregor
Copy link
Member Author

I'm holding off on merging this until I have the compiler side of it implemented, to make sure we have the right API here.

@DougGregor DougGregor merged commit 2d42e8d into swiftlang:main Mar 22, 2023
@DougGregor DougGregor deleted the macro-expansion-nonexternal branch March 22, 2023 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant