-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
library/src-bootstrapped/scala/internal/quoted/CompileTime.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package scala.internal.quoted | ||
|
||
import scala.annotation.{Annotation, compileTimeOnly} | ||
import scala.quoted._ | ||
|
||
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime`") | ||
object CompileTime { | ||
|
||
/** A term quote is desugared by the compiler into a call to this method */ | ||
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.exprQuote`") | ||
def exprQuote[T](x: T): QuoteContext ?=> Expr[T] = ??? | ||
|
||
/** A term splice is desugared by the compiler into a call to this method */ | ||
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.exprSplice`") | ||
def exprSplice[T, QCtx <: QuoteContext](x: QCtx ?=> Expr[T]): T = ??? | ||
|
||
/** A type quote is desugared by the compiler into a call to this method */ | ||
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.typeQuote`") | ||
def typeQuote[T <: AnyKind]: Type[T] = ??? | ||
|
||
/** A splice in a quoted pattern is desugared by the compiler into a call to this method */ | ||
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternHole`") | ||
def patternHole[T]: T = ??? | ||
|
||
/** A splice of a name in a quoted pattern is desugared by wrapping getting this annotation */ | ||
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternBindHole`") | ||
class patternBindHole extends Annotation | ||
|
||
/** A splice of a name in a quoted pattern is that marks the definition of a type splice */ | ||
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.patternType`") | ||
class patternType extends Annotation | ||
|
||
/** A type pattern that must be aproximated from above */ | ||
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.fromAbove`") | ||
class fromAbove extends Annotation | ||
|
||
/** Artifact of pickled type splices | ||
* | ||
* During quote reification a quote `'{ ... F[$t] ... }` will be transformed into | ||
* `'{ @quoteTypeTag type T$1 = $t ... F[T$1] ... }` to have a tree for `$t`. | ||
* This artifact is removed during quote unpickling. | ||
* | ||
* See ReifyQuotes.scala and PickledQuotes.scala | ||
*/ | ||
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.quoteTypeTag`") | ||
class quoteTypeTag extends Annotation | ||
|
||
} |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import scala.quoted._ | ||
object Test | ||
def run(using qctx: QuoteContext)(tree: qctx.tasty.Tree): Unit = | ||
'{ ${ makeExpr(tree) } + 1 } | ||
def makeExpr(using qctx: QuoteContext)(tree: qctx.tasty.Tree): Expr[Int] = ??? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import scala.quoted._ | ||
object Test | ||
def run(using qctx: QuoteContext)(tree: qctx.tasty.Tree): Unit = | ||
def nested()(using qctx.NestedContext): Expr[Int] = | ||
'{ ${ makeExpr(tree) } + 1 } | ||
'{ ${ nested() } + 2 } | ||
|
||
def makeExpr(using qctx: QuoteContext)(tree: qctx.tasty.Tree): Expr[Int] = ??? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
((qctx: scala.quoted.QuoteContext) ?=> { | ||
val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4).apply(using qctx) | ||
((qctx1_$1: scala.quoted.QuoteContext) ?=> a).apply(using qctx) | ||
((qctx1_$1: qctx.NestedContext) ?=> a).asInstanceOf[scala.ContextFunction1[scala.quoted.QuoteContext, scala.quoted.Expr[scala.Int]]].apply(using qctx) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
((qctx: scala.quoted.QuoteContext) ?=> { | ||
val a: scala.quoted.Expr[scala.Int] = scala.internal.quoted.CompileTime.exprQuote[scala.Int](4).apply(using qctx) | ||
((qctx2: scala.quoted.QuoteContext) ?=> ((qctx1_$1: scala.quoted.QuoteContext) ?=> a).apply(using qctx2)).apply(using qctx) | ||
((qctx2: scala.quoted.QuoteContext) ?=> ((qctx1_$1: qctx2.NestedContext) ?=> a).asInstanceOf[scala.ContextFunction1[scala.quoted.QuoteContext, scala.quoted.Expr[scala.Int]]].apply(using qctx2)).apply(using qctx) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 inspliceContext
andquoteContext
. This may cause accidental errors when used without care. Maybe removespliceContext
andquoteContext
, 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
andReifyQuotes
. There we only need to track the level.