I'm working on a pitch to support function body macros on closures. The pitch is still pretty rough, but the type checking questions are super interesting, so I wanted to get the discussion started now for opinions.
I don't have any specific ideas in mind (yet) but I could definitely see this being useful in Swift Testing.
I'd be interested to know more about what you and your colleagues are thinking in terms of type checking improvements. As you can probably guess from our offline discussions, type checking during macro expansion is particularly impactful to us. Is any of the work in that area generalizable to other macro flavours?
Could a closure body macro be implicitly applied to a closure similar to result builder applied to a function closure argument?
I've played with implementing result builder using function body macro here and this would be nice to achieve the same usability as built-in result builder.
Why the departure from the proposed future direction in the original pitch on syntax? I find it rather more desirable that body macros are declared in the same place syntacticly.
Type checking has already been brought up, would this see expansion to implementing wrapper macros which would help?
One thing that jumped out at me is that it seems now body macro implementations will need to implement both the function body requirement and the closure body requirement. This seems suboptimal, both due to repeated work and potential for subtle divergence. It feels like most implementations will want to have a generic method that is called from both the function-body method and the closure-body method. Perhaps it makes sense to just come up with a single thing that can support both and standardize that?
If this were a valid application of the macro, this makes me think that we don't even need the separate concrete implementation for closures. Then, wouldClosureSignatureSyntax: WithOptionalCodeBlockSyntax make sense? Conformers would just then be able to check whether the body is being applied to FunctionDeclSyntax or ClosureSignatureSyntax.