-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow nested Quotes with a different owners #13652
Allow nested Quotes with a different owners #13652
Conversation
28ea733
to
ae85c48
Compare
ae85c48
to
bf5b2b5
Compare
* override def transformTerm(tree: Term)(owner: Symbol): Term = | ||
* tree match | ||
* case ... => | ||
* given Quotes = owner.asQuotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still looks easy too easy to miss and hard to teach to me, is there no way to automatically use the correct Quotes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(also if we do go with this solution, it would need to be explained in details in the documentation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still looks easy too easy to miss and hard to teach to me, is there no way to automatically use the correct Quotes?
We can do this only if we use the quotes API alone. We could not find a good way to do this when reflection is involved. That is one of the reasons why we introduced the changeOwner
. This is an alternative to changeOwner
that does not require post-processing. Both of these need be explained in detail in the documentation and both require the same understanding of the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do this only if we use the quotes API alone.
What about the discussion in #12309 (comment) ? /cc @odersky, @LPTK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a way to avoid the costly change of owners mentioned in #12309 (comment). It provides a way to construct the quotes under the correct owner which means that when we will only need to check that the owner is correct and not change it. Currently, if we create a quote that goes into a reflection constructor we always end up taking the slow path and need to change the owners.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, if we create a quote that goes into a reflection constructor we always end up taking the slow path and need to change the owners.
But presumably this isn't always working if #13571 emits an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #13571 -Xcheck-macros
detects the bug in the user code. There we show how they can fix the owner after the fact. This addition allows the users to set the correct owner before the creation of the quote and avoid having to do the extra work to fix the owner.
bf5b2b5
to
50d5fc3
Compare
50d5fc3
to
6a81479
Compare
6a81479
to
8015e82
Compare
84ca549
to
ee74a94
Compare
ee74a94
to
2610b91
Compare
59c27fb
to
a108104
Compare
a108104
to
663d77b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the documentation of TreeMap and/or the general meta-programming doc point to this method? Otherwise it will be hard for users to discover.
25e41b9
to
1c6d96d
Compare
8ea64e1
to
ad7f2d2
Compare
Updated documentation |
@smarter could you have a quick look before merging? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM!
* } | ||
* } | ||
* ``` | ||
* @syntax markdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think @syntax markdown
is required in the library doc anymore, it should be the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove it in a separate PR. There is a total of 27 of these in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up in #14759
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
ad7f2d2
to
e0989a0
Compare
This makes it possible to create
Expr
s with different owners to avoid a call tochangeOwner
.See #13571