-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Can't use Symbol.tree to access DefDef body with blackbox macro using Tasty reflect #7592
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
Tagging @nicolasstucki after some further discussion on Gitter |
Also, for further reference adding that the MatchError I get when I run this code shows this tree: |
This is a limitation of expanding macros during typed and not after. We have discussed the idea of only expanding white box macros in typed and delay the expansion of black box. That would fix this issue. |
When a tree is not available for a symbol we synthesize it with an empty body. |
@nicolasstucki Thanks for the explanation. This is a significant blocker for me - I would label current behaviour as very counter-intuitive, and it makes it effectively impossible to write interprocedural code folding macros. I am prepared to patch the compiler / implement the change you describe for black box macros myself, since I can't meaningfully move forward on my project without this kind of functionality. Let me know how you think it would be best to proceed. |
Turns out there's a workaround available in the form of the For those like me who didn't know how to pass options to Dotty in sbt:
|
Even with that flag there might be local definitions that do not have a tree yet. @fhackett does that pose a blocker for you? Doing the change I proposed might be a bit involved and might require some design decisions. |
@nicolasstucki luckily I can live without the local definitions - generally I would expect As it is, it seems I can keep going with my project with that little caveat in mind. That said, let me know if I can be of any help with design/test/etc. I'll also hopefully be able to link my full-scale use case soon (currently doing some design decisions of my own in that area). |
This is a starting point. There are still a few tests that need to be fixed. I will not have time to look at it this week. https://github.com/dotty-staging/dotty/tree/move-blackbox-macro-exapnsion-to-reify-quotes |
@nicolasstucki thanks for the link - I have looked at it superficially, but will likewise have to get back to it. meanwhile, here's a link to my work-in-progress that uses this feature (with the compiler flag) |
@nicolasstucki with the current state of #7626 it seems I am once again at an impasse. I also have a much more precise idea of what I need that Dotty doesn't have. Pushing forward on my own project's design was worth it in that sense. Since I am not (yet) an official contributor, where should I start? I know about the CLA etc, I mean what would be the best use of my time for the issues I'm focusing on? I'm confident in my independent learning, but it would help a lot to have "go read this file/class/function" pointers or a description of what you've already done + what is still TODO. Your thoughts are appreciated. |
A simple place to start which would have a high value would be #6280. |
@nicolasstucki that like a good place to start. I see there is existing work - is there a specific branch I should start with, or do I just fork+branch from master and work from there? |
Just fork+branch from master. |
Closes scala#7592
(you may recognise this from the Gitter chat, bumping because it seems to have gone unaddressed)never mindminimized code
The macro:
The usage (in a different package):
expectation
The
compile
macro should be able to inspect the body ofreturn1
, allowing it to inline the method body into the macro expansion.Currently the DefDef body is matched as None, preventing this. I know some DefDefs don't have bodies, but this one does. I'm at a loss as to how to achieve the effect I want.
Is there some undocumented thing I should be doing or is this a bug?
The text was updated successfully, but these errors were encountered: