Composing multiple macros

Swift supports creating a macro by composing multiple roles, but it doesn't support composing multiple macros.

Example: I have a Entity macro. It generates so many code that I often need to expand it in Xcode to remind myself what it does. That leads me to think that I should split it into multiple general macros and then compose them to create Entity macro. I mean an approach to expand this code:

@Entity
struct X {
    ...
}

to

@Foo @Bar @Baz
struct X {
    ...
}

To implement it I need a way to modify the attributes of the type declaration. Unfortunately Swift doesn't support it (it supports memberAttribute role, but that only works for member).

Currently the only way to implement the idea (spliting Enity macro into multiple general ones) is to share code at function level. Putting the functions of Foo, Bar, and Baz in a common package and use them to implement these macros (including Entity). That's less natural and way more tedious.

I think composing macros is a useful feature in general and helps to organize macro code. I wonder if it's possible to add this support?


Edit: I would hope the support allows macro author to compose macros programmatically. That means it needs be a new role, instead of some straightforward approach like the following:

// pseudo-code
macroalias Entity = Foo & Bar & Baz
1 Like