That an interesting thought. For most macros, showing the source macro code would not be very helpful; but defguard has sufficiently constrained inputs for that not to be the case. So there definitely are some defguard-specific opportunities in this proposal.
I can't think of a great way to implement it:
a. We'd need a macro-expansion-tracing compile-time metadata format similar to debug symbols
b. We'd need to make the runtime exception reporting mechanisms aware of this metadata
That seems heavy. I'm not creative enough to think of a better solution, in the face of these constraints:
a. Without radically changing the implementation of defguard as a macro, we'd have to implement metadata capture for all macros generically
- This raises questions of how to handle nested macro expansion in these scenarios
b. We can't add extra wrappers around just the product of defguards themselves, as their inputs are too constrained to do any sort of outputting or error handling, so the exception formatters themselves would have to do reporting on the metatdata of the original macro
- Again, how would this report if several macros produced the generated code
There are probably approaches I'm missing here, though.