Overall nice first step, great to see this!
I'd personally want to see a "vision" going along with this initial part, because the long term here is alluded to, but not really explored much. I'm a bit worried about offering such "partial" API, missing features to discover methods etc, even if just for registering them for later execution etc.
There is also overlap between reflection APIs and macros "compile time reflection", and it would be good to explore this overlap if we can at least provide similar (or shared!) APIs -- it would be a bit annoying if the runtime reflection API shape ends up completely different from the compile time one.
Specifically, I'm looking at this having worked with Scala reflection and macros before; where the two APIs were attempting to surface some common interfaces. Scala 2's reflect API offered an abstract API scala.reflect.api
what had a subset of things that are accessible both from a macro "universe" as well as a runtime "universe". This may or may not be desirable for Swift, but it might be worth an invesigation -- especially as we're developing macros and reflection right now at the same time.
A particularly interesting aspect of macros is that they are based on the same API used also for Scala’s runtime reflection, provided in package
scala.reflect.api
. This enables the sharing of generic code between macros and implementations that utilize runtime reflection.
Similarly, Scala 3 also allows macros to access to the full reflection API from the macro runtime via the quotes.reflect
module: Reflection | Macros in Scala 3 | Scala Documentation
I bring this up here now, since the initial expression macros pitch explicitly didn't cover any Type
interactions yet, so there is room to make sure we make the best possible API happen.
For example, would it make sense to be able to get a Reflection.Type
from a MacroEvaluationContext
, by querying the compiler to resolve a given AST nodes type? Access to types will most definitely be necessary in more advanced macros, so it'd be interested to see if we can marry the two rather than each have their own almost-the-same "Type".