-
Notifications
You must be signed in to change notification settings - Fork 53
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
typechecking annottees inside a macroTransform crashes the compiler #67
Comments
Unfortunately, c.typecheck inside macro annotations is pretty unreliable at our current level of technology. It often works, but sometimes it produces the unpleasant effects similar to what you've described. Therefore, a typical approach to typechecking is (if possible) trying to move it to def macros (typecheck there has a much higher chance to work correctly). So, a macro annotation could expand into a bunch of calls to def macros, who, in their turn, would call c.typecheck and the collect necessary info. Do you think that this pattern would be implementable for your scenario? |
Well on the face of it, I shouldn't really care if the macro annotation would expand to a more vanilla |
Macro annotations expand at a very sensitive point during typechecking, at which some of the contexts are already initialized and some contexts (notably, the very enclosing context of the annotated member being expanded) are in progress. Therefore, Def macros expand when all the relevant contexts are already set up, so Therefore, if your macro annotation expands, say, a class into the same class with all its methods wrapped to calls to def macros, then calling |
Thanks, In my naive testing, everything works as intended in my macro annotations - Is there grounds to believe this would typically be the case - with scala This can be fine. It is hopefully very simple to rerun compilation without Thanks, On Fri, May 8, 2015 at 2:27 PM, Eugene Burmako [email protected]
|
Well, since scalac uses a highly mutable architecture to implement signature computations and typechecking, As for you idea, it would be really hard to separate macro annotation expansion from this particular crash, since the crash happens at |
What I suggested in the email, is having
Expand into
Then, expansions of |
Okay, thought so. I'll try that when I come back to it, hopefully I can provide the AST from |
Why do |
Okay I think I got it, coming back to this, and am working on this approach. |
I've merged this issue into #75 and will close this issue now. If this is a blocker for you, please let me know, and we'll think of something. |
Hi,
It seems if I
typecheck
theannottees: c.Expr[Any]*
inside amacroTransform
implementation, then eventually I crash compilation, whenever one or more case classes are being annotated. As if implying that typechecking has some mutable adverse effect, as the scala compiler seems to ultimately call paradise'sorg.scalamacros.paradise.typechecker
, which crashes with the error copied below.I type check the annottees as follows, as my macro needs to have type information availabe to it:
val typeCheckedAnnottees = annottees.map(a => c.typecheck(a.tree, silent = false))
I have yet to encounter the same crash eventually happening when the annottee is not a case class (e.g. a regular class or an object), and I wonder whether I really grasp the meaning of type checking inside a
macroTransform
, whether it is at all safe to do.This is reproducible in my fork of the example project
May you please advise?
I get this with every version of macro paradise I have tried for scala 2.11.
The text was updated successfully, but these errors were encountered: