-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #8045: Refine QuoteContext{val tasty} provided by splices #8281
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
Conversation
ceb0cbe
to
2f1bd68
Compare
* Avoids leaking implementation details of scala.internal.quoted.CompileTime.exprQuote, such as exprQuote returning a ?=> function argument
``` given qctx as QuoteContex = ??? '{ ${ myExpr(summon[QuoteContext]) } } ``` is now encoded as ``` given qctx as QuoteContex = ??? exprQuote { exprSplice { (qctx0_$1: qctx.NestedContext) ?=> myExpr(summon[QuoteContext](qctx0_$1)) } }(given qctx) ``` Before `qctx0_$1` was typed as `QuoteContext`. Intuitively, `qctx0_$1` is a sub-context of `qctx` where both share the same reflection interface
ba25250
to
1b24694
Compare
* The quotation stack could be empty if we are in a top level splice or an eroneous splice directly witin a top level splice. | ||
*/ | ||
def popQuoteContext()(implicit ctx: Context): (Option[tpd.Tree], Context) = | ||
val ctx1 = ctx.fresh.setProperty(QuotationLevel, level - 1) |
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.
The property QuotationLevel
is also mutated in spliceContext
and quoteContext
. This may cause accidental errors when used without care. Maybe remove spliceContext
and quoteContext
, since they are not used.
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 use those in PCPCheckAndHeal
and ReifyQuotes
. There we only need to track the level.
def pushQuoteContext(qctxRef: tpd.Tree)(implicit ctx: Context): Context = | ||
val old = ctx.property(QuoteQontextStack).getOrElse(List.empty) | ||
ctx.fresh.setProperty(QuotationLevel, level + 1) | ||
.setProperty(QuoteQontextStack, qctxRef :: old) |
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'm wondering if the stack can be avoided using scoping rules for implicits.
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.
Yes, it could but we would need to track a level context and a splice context. The errors when those implicit are not found would also be hard to interpret.
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.
LGTM
No description provided.