Skip to content

Use simpler desugaring for splices #8660

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 2 commits into from
Apr 7, 2020

Conversation

nicolasstucki
Copy link
Contributor

This allows writing explicitly the context function of a splice. It will make the desugaring simpler to explain as one can write it explicitly.

The downside is that each nested context will get a generic "evidence" name which might be visible to the users. Though this is general limitation of context functions that might need a general fix.

@nicolasstucki nicolasstucki self-assigned this Apr 4, 2020
@nicolasstucki nicolasstucki force-pushed the simple-splice-desugaring branch from f3af5ea to 317a376 Compare April 4, 2020 15:42
@nicolasstucki nicolasstucki marked this pull request as ready for review April 4, 2020 18:26
@nicolasstucki nicolasstucki requested a review from liufengyun April 4, 2020 18:26
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.

Otherwise, LGTM

@@ -53,7 +53,7 @@ trait QuotesAndSplices {
ctx.error(em"Quotes require stable QuoteContext, but found non stable $qctx", qctx.sourcePos)

val tree1 =
if ctx.mode.is(Mode.Pattern) && level == 0 then
if ctx.mode.is(Mode.Pattern) then
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove level == 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because if we are in a pattern and we go in the other branch we might generate some non-pattern trees (after some error has been emitted) which leads to crashes later in typer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tests/neg/i8052.scala had this issue. With this change, the error message is also more informative.

Copy link
Contributor

Choose a reason for hiding this comment

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

If level == 0 is a correct check, it seems better to keep it, and fix crash & error message elsewhere. The reason is that we don't know whether the removal introduces crashes for more ill-formed programs or not.

Copy link
Contributor Author

@nicolasstucki nicolasstucki Apr 6, 2020

Choose a reason for hiding this comment

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

The point is that is was not a correct check. The level checks happen later in the Staging phase.

case Some(qctxRef) => untpd.Apply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprNestedSplice.termRef), qctxRef), expr)
case _ => untpd.Apply(untpd.ref(defn.InternalQuoted_exprSplice.termRef), expr)
case Some(qctxRef) => untpd.Apply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprNestedSplice.termRef), qctxRef), tree.expr)
case _ => untpd.Apply(untpd.ref(defn.InternalQuoted_exprSplice.termRef), tree.expr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice simplification 👍

This allows writing explicitly the context function of a splice. It will make the desugaring simpler to explain as one can write it explicitly.

The downside is that each nested context will get a generic "evidence" name which might be visible to the users. Though this is general limitation of context functions that might need a general fix.
@nicolasstucki nicolasstucki force-pushed the simple-splice-desugaring branch from 317a376 to 926905d Compare April 6, 2020 05:20
@nicolasstucki nicolasstucki merged commit 2352d90 into scala:master Apr 7, 2020
@nicolasstucki nicolasstucki deleted the simple-splice-desugaring branch April 7, 2020 15:35
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.

2 participants