I'm finding a need to mark methods with metadata for use in a SwiftSyntax-based compiler plugin, and the thought occurred to me of using a “no-op” macro to do it. That is, a macro that does nothing to transform the method it’s attached to, but only serves to add nodes to the syntax tree around it (and thus some data for my compiler plug-in to use).
It would be nice to be able to create these macros without writing the no-op implementation. Would it make sense to add something like @noop or @attached(member, noop) or @annotation capability to macro declarations? That could inform the compiler to skip invoking the macro at all, and just insert the syntax nodes for it.
You only need a single no-op macro implementation for all of your markers, but I do agree it'd be nice to not need it at all (and to skip the extra bit of build-time work).
It seems any macro that gets processed by the system gets removed from the source, even if its implementation doesn’t do anything. Since macro expansion isn’t transitive, I don’t think that’s an issue for my use cases.
Your request sounds like a compile-time version of custom reflection metadata. IIRC, the Reflection feature was delayed because its connection with macros, and thus the integration of this (currently) runtime feature with compile-time operations, is being investigated.
Yes! It certainly does, and that proposal would also solve the problem I’m currently trying to solve. I didn't read the whole thing closely, but I very much want the ability to enumerate things (types, methods, properties) that are annotated with custom annotations (reflectionMetadata).