SE-0415 (second review): Function Body Macros

Hello, Swift community!

The second review of SE-0415: Function Body Macros begins now and runs through May 20, 2024.

The original proposal was returned for revision based on feedback during the review about whether the proposed body and preamble macros were sufficient to meet the needs of macro authors, with many community members expressing a desire for "wrapper" macros similar to Python decorators. Based on early experimentation, the proposal authors believe that there may be a path toward wrapper macros that could provide the same or more expressivity as was originally proposed for preamble macros.

The authors also believe that body macros from the original proposal are useful in their own right, even if future work allows some of their use cases to be absorbed by more specific types of function macros introduced later.

For this reason, the Language Steering Group is running a second review of this proposal which has been scoped more narrowly to include only the body macros feature. The proposal has been updated to move the discussion of preamble macros to the future directions section and also to add a discussion of wrapper macros there.

A diff of the proposal can be found here.

Reviews are an important part of the Swift evolution process. All review feedback should be either on this forum thread or, if you would like to keep your feedback private, directly to me as the review manager by DM. When contacting the review manager directly, please put "SE-0415" in the subject line.

Trying it out

If you'd like to try this proposal out, you can download a toolchain supporting it from Swift.org; the most recent Trunk Development (main) snapshots support the feature. You will need to add -enable-experimental-feature BodyMacros to your build flags.

What goes into a review?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:

  • What is your evaluation of the proposal?
  • Is the problem being addressed significant enough to warrant a change to Swift?
  • Does this proposal fit well with the feel and direction of Swift?
  • If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
  • How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

More information about the Swift evolution process is available at

swift-evolution/process.md at main ยท apple/swift-evolution ยท GitHub

Thank you,

Tony Allevato
Review Manager

12 Likes

Love the new simpler, more flexible approach.

I wonder if a popular macro doing something insane like the SQL example given, might affect the ability to evolve the language syntax?

1 Like

I'm happy to see the "body" version of these macros made it through review rounds, it is the most powerful and while the limitation of not composing with others is bound to pop up eventually, at least then we'll have concrete examples of use cases and can tune the composable ones if and when the time comes.

In some ways they're also the "simple" approach here to be honest... Give the macro the power to do things, without the "introduces names: ..." etc complications which we were a bit unsure about, and might have over-fitted the examples we had thought.

I expect we may want to do some form of precondition like macros which preambles would be nice for, but it's good to prototype with body macros and then we can revisit.

Review Summary:
I have spent time prototyping tracing macros with the proposed macros and the proposed shape will allow us the most exploration and interesting approach, including introducing names into the body scope (like the span that the body may then refer to), so this gets a wholehearted +1 :slight_smile:

5 Likes

I don't think it will. When we add new syntax, it is very rare that we invalidate any existing syntax.

Doug

1 Like

Hi all,

This proposal has been accepted. Thanks for participating in the review!

1 Like