[Pitch] Declaration macros

Hey all,

I appreciate all of the design discussion here! I've gone ahead and revised the pitch. The changes are, roughly:

  • Split peer/member/accessor macro implementations into separate protocols and attribute spellings, so the compiler can query them in a more fine-grained manner.
  • Removed function-body macros... for the moment. We'll come back to them.
  • Add example showing composition of different macro roles for the same macro to effect property-wrappers behavior.

That last example is really fun. Alongside this, @hborla and I have prototyped some of these syntactic transformations in swift-syntax, and @rxwei has made progress on an implementation of freestanding macros in the compiler:

EDIT: Lots more interesting cases to consider, so I've updated the document again with:

  • "Body" macros to supply or alter the body of a function/initializer/accessor/closure.
  • Default-witness macros to help with synthesis of protocols.
  • Member-attribute macros to allow one to add attributes to the members of a type/extension.

This is too big for one proposal, but I'd rather not trickle out ideas one-by-one. Rather, there's a lot in here covering a large space of what is possible, and we can tease it apart later into more-easily-reviewable chunks.

Doug

10 Likes