-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use simpler desugaring for splices #8660
Conversation
f3af5ea
to
317a376
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.
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 |
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.
Why remove level == 0
?
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.
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.
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.
tests/neg/i8052.scala
had this issue. With this change, the error message is also more informative.
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.
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.
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 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) |
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.
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.
317a376
to
926905d
Compare
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.