-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Annotation macros in Dotty #1694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Good timing. See #1693 for a partial answer :-) |
From a practical point of view, I'll take the simpler approach and assume macros annotations are pre-compiled. This assumption has been and will continue to be valid for some time. Most importantly, it unblocks me. When time is mature (with an interpreter), we can refactor the impl to weaken the assumption. To further simplify implementation, I assume all annotations which extend |
Sorry to have missed this discussion. This all happened right when I was moving to SF, so it seemed to fall through cracks. Anyway, speaking of problem 2. Why do we need to inspect the AST of the annotation to figure out whether it has |
This is because checking There could be Giving all these complex protocols, |
I suggest we limit ourselves to just The main problem with |
@xeno-by if we can afford not checking |
I think it's probably better to reintroduce import scala.`meta`._ That doesn't look nice. We reverted back to I'm not sure if it's possible to compromise the two? For example, loosen the parser to accept keywords in import statements? Ideas @xeno-by @DarkDimius @odersky ? |
I'd vote for keeping it a method. Other methods also have significant importance in the compiler, e.g. |
Thanks @odersky . While I agree keeping it a method will be the simplest way, For now I'm happy to keep it as a method, we can come back to this small decision later. It should be easy to change. |
This discussion is out of date now. Follow the link below for the latest discussion about annotation macros: https://contributors.scala-lang.org/t/annotation-macros/1211/20 |
We had a discussion before about annotation macros, the idea then was to transform the following annotation macros:
to:
There are some problems with the scheme above. For example, given the code:
The namer has a difficulty to determine whether
@main
is a macros or not and how to expand it. It needs to do as least follows:main
to a symbol (typedIndent
)main
is defined in the same compilation runmain
extendsscala.annotation.StaticAnnotation
main
has a memberinline def apply(defn: Any): Any
, and rhs begins withmeta
.@main
is defined without tasty (e.g. Scala2).meta
to get the implementation method.main$inline.meta
, thus no need to inspect ASTs, which can impose a performance penalty by deserializing tasty.It seems that annotation macros are somewhat special, different from def macros, inlining never happens for annotation macros. It seems to me that current
paradise
implementation of annotation macros is simpler (avoids problem 2 & 3), it translates the code:to:
My question is:
inline def apply(defn: Any): Any = meta {...}
, and ignore other possibleinline/meta
methods, as they don't make sense for annotation macros?WDYT @odersky @xeno-by @DarkDimius ?
The text was updated successfully, but these errors were encountered: