Skip to content

Function body macros #70034

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

Merged
merged 2 commits into from
Nov 28, 2023
Merged

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Nov 27, 2023

Introduce function body macros, which are comprised of two similar macro roles:

  • Preamble macros introduce "preamble" code into a user-written function body, e.g., to perform tracing, logging, check additional preconditions, etc.
  • Body macros: introduce a function body into a function that has none or replace the existing function body

@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1874

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1874

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please build toolchain

Function body macros allow one to introduce a function body for a
particular function, either providing a body for a function that
doesn't have one, or wholesale replacing the body of a function that
was written with a new one.
Implement type checking support for preamble macros, which expands the
preamble macros and introduces them at the beginning of the function
body prior to type checking. Ensure that the resulting function bodies
type-check properly, including when composing multiple preamble macros
and with a preamble macro applied to the body of a function that
itself came from a body macro.
@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1874

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1874

@swift-ci please build toolchain

@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1874

@swift-ci please test macOS

@DougGregor
Copy link
Member Author

swiftlang/swift-syntax#1874

@swift-ci please test Windows

@DougGregor DougGregor marked this pull request as ready for review November 28, 2023 17:42
@DougGregor DougGregor merged commit 0eb71d1 into swiftlang:main Nov 28, 2023
@DougGregor DougGregor deleted the function-body-macros branch November 28, 2023 17:43
@DougGregor
Copy link
Member Author

I think this is in good-enough shape to land, so I've gone ahead and merged it. I'll iterate on the implementation on main alongside the discussions of the proposal

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