Skip to content

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

Merged
merged 4 commits into from
Feb 20, 2020

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Feb 11, 2020

No description provided.

* 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
@nicolasstucki nicolasstucki marked this pull request as ready for review February 11, 2020 11:07
* 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)
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nicolasstucki nicolasstucki merged commit fd3e321 into scala:master Feb 20, 2020
@nicolasstucki nicolasstucki deleted the fix-#8045 branch February 20, 2020 06:31
@anatoliykmetyuk anatoliykmetyuk added this to the 0.23.0-RC1 milestone Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed unification of arguments, dependent from given arguments.
3 participants