Comments (2)
I prefer the current approach (unsurprisingly, because I designed it 🤣 ), here are some reasons:
- How does a macro get a "macro context"? Presumably, this essentially adds a 4th phase (for registering which phases you want to run in), with additional round trips and overhead (to register your macro in each phase) that isn't required with the current approach.
- Knowing all the phases a macro wants to operate in ahead of time allows you to more easily only run the necessary phases. As an example, the first phase cannot do introspection and never needs to be re-ran unless the current file changes. If you have to (or have the ability to) register which later phases you are going to run in during that phase, then it is more challenging to avoid redoing this work.
- The callback approach encourages retaining state between phases which we do not want macros to do. The (const) class based approach means you can only share global state, and won't implicitly capture local state like a callback would. In particular, objects retrieved from macro APIs are only valid in the current zone, attempting to cache them and use them in a later phase will cause problems.
- Similarly the callback approach is more prone to memory leaks - these callbacks have to be retained potentially indefinitely (especially if you want to try and avoid re-running earlier phases). And it is very easy for them to retain a bunch of state that isn't actually necessary, or shouldn't have been retained.
- I don't believe it actually makes the code meaningfully better. It won't be significantly shorter (the callbacks will be essentially the same as the implemented methods), the class header is short and replaces the explicit register calls.
- When written as a class the tooling is better because you write the interfaces you want to implement, and the tooling will create the stubs for you to fill in.
- Classes also enable the use of mixins etc which makes them easily composable.
from language.
I am going to close this one as not planned.
from language.
Related Issues (20)
- Is future returned immediatelly from async call? Inconsistency in docs HOT 3
- Allow augmenting member declarations immediately in the same body? HOT 7
- [parts-with-imports] Consider dropping the library name from the library directive HOT 1
- Infer the type of an optional parameter from the default value HOT 1
- Should digit separators be supported in int.fromEnvironment? HOT 1
- Support for Rust like #[cfg()] attributes HOT 10
- [parts-with-imports] Conditional part directives and the analyzer HOT 20
- Allow all variable augmentations to omit the initializing expression HOT 4
- `Error: Method not found` when running Flutter app with macro class HOT 2
- Allow a variable initializer to be unresolved, following the treatment of abstract members HOT 3
- Allow Iterators To Use The for-in Syntax HOT 5
- Macros: Emit diagnostics inside macro arguments HOT 2
- URI shorthands without internal whitespace. HOT 2
- URI shorthands, allow reserved words. HOT 8
- URI shorthands, more permissive HOT 2
- Inheriting a type parameter bound?
- Ordering of augmenting initializers and getters on late variables
- Generalize mixin inference to other superinterfaces? HOT 1
- [analyzer] Switch cases for destructured records do not promote types HOT 5
- False negative `unreachable_switch_case` diagnostic when using `switch` statements HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from language.