Will Dart 3 - static Metaprogramming make reflectable obsolete? #306
Replies: 3 comments 9 replies
-
Surprise... They did not 🥲 |
Beta Was this translation helpful? Give feedback.
-
Static metaprogramming is definitely happening, but there's a lot of work to do before it's mature enough to become a regular language feature. So right now we have just released, as an experimental feature, the ability to use a single macro. More to come. Reflectable and static metaprogramming are somewhat orthogonal: Reflectable generates code that enables reflective actions at run time whereas static metaprogramming, as indicated by its very name, is completed before the program starts running. This means that there is no way static metaprogramming can emulate the dynamic semantics of reflectable, short of actually reimplementing the code generator of reflectable as a huge macro. For example, reflectable allows us to do things like receiving a On the other hand, static metaprogramming will complete its work at compile time, which means that it will run at full speed at run time, we will never do things like comparing two strings in order to determine whether or not we've found the right method of a given object. So it's a big difference that one is doing static metaprogramming and the other is doing dynamic metaprogramming (neither of which is "better", they are just good at different things, in addition to a lot of things that they can both do). Another difference is that the static metaprogramming support in Dart will rely on the statically known scopes to enable operations. In other words, if you're working on a library L1 that imports another library L2 then a macro applied to a declaration in L1 will have access to information from L2 and information provided with the macro itself. This means that static metaprogramming can perform operations on source code entities which are valid for the given set of reachable declarations. In particular, the generated code would be equally correct for any program that contains L1. In contrast, reflectable performs a closed-world analysis. This means that reflectable code generation needs to be performed with respect to a particular program, and we need to run the reflectable code generator afresh if we're considering a different program, even in the case where the two programs both contain many of the same libraries. In return for this need to run the analysis for a specific program, reflectable supports a number of global properties. For instance, reflectable allows us to specify that "every subtype of a given type T is handled by this reflector". Static metaprogramming which is based on the available imports will never be able to do that, because we can (ignoring I think they'll both continue to exist, and be useful. You would probably prefer to use static metaprogramming for the cases where that is sufficient, and you'd use reflectable in other situations where a global analysis is required, or in situations where some operations that we need to perform require some run-time information. |
Beta Was this translation helpful? Give feedback.
-
I wonder how much of reflectable that could be implemented as a macro? Are macros powerful enough to do the closed-world inspection of the program to create the support data structures for the reflectable runtime? |
Beta Was this translation helpful? Give feedback.
-
Hi, I recently heard that in Dart-3 they are planning to introduce Static MetaProgramming wondering if that would make reflectable obsolete?
Beta Was this translation helpful? Give feedback.
All reactions