Skip to content

Commit 9c973ed

Browse files
committed
Rename QuoteContext to Quotes
`QuoteContext` is required on all signatures. To make it simpler to keep signatures on one line we shorten the name to `Quotes`. This name will usually be used in `(using Quotes)` which reads as _using quotes_ and descibes exactly why this contextual parameter is the. ```diff - def f[T: Type](x: Expr[T])(using QuoteContext): Expr[T] = ... + def f[T: Type](x: Expr[T])(using Quotes): Expr[T] = ... ```
1 parent 305216a commit 9c973ed

File tree

614 files changed

+1288
-1285
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

614 files changed

+1288
-1285
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ class Definitions {
797797
@tu lazy val QuotedExprClass: ClassSymbol = requiredClass("scala.quoted.Expr")
798798
@tu lazy val QuotedExprModule: Symbol = QuotedExprClass.companionModule
799799

800-
@tu lazy val QuoteContextClass: ClassSymbol = requiredClass("scala.quoted.QuoteContext")
800+
@tu lazy val QuoteContextClass: ClassSymbol = requiredClass("scala.quoted.Quotes")
801801

802802
@tu lazy val QuoteUnpicklerClass: ClassSymbol = requiredClass("scala.quoted.runtime.QuoteUnpickler")
803803
@tu lazy val QuoteUnpickler_unpickleExpr: Symbol = QuoteUnpicklerClass.requiredMethod("unpickleExpr")

compiler/src/dotty/tools/dotc/decompiler/DecompilationPrinter.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import dotty.tools.dotc.core.Phases.Phase
1111
import dotty.tools.dotc.core.tasty.TastyPrinter
1212
import dotty.tools.io.File
1313

14-
import scala.quoted.runtime.impl.QuoteContextImpl
14+
import scala.quoted.runtime.impl.QuotesImpl
1515

1616
/** Phase that prints the trees in all loaded compilation units.
1717
*
@@ -45,7 +45,7 @@ class DecompilationPrinter extends Phase {
4545
else {
4646
val unitFile = unit.source.toString.replace("\\", "/").replace(".class", ".tasty")
4747
out.println(s"/** Decompiled from $unitFile */")
48-
out.println(QuoteContextImpl.showDecompiledTree(unit.tpdTree))
48+
out.println(QuotesImpl.showDecompiledTree(unit.tpdTree))
4949
}
5050
}
5151
}

compiler/src/dotty/tools/dotc/decompiler/IDEDecompilerDriver.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dotty.tools.dotc.core._
77
import dotty.tools.dotc.core.tasty.TastyHTMLPrinter
88
import dotty.tools.dotc.reporting._
99

10-
import scala.quoted.runtime.impl.QuoteContextImpl
10+
import scala.quoted.runtime.impl.QuotesImpl
1111

1212
/**
1313
* Decompiler to be used with IDEs
@@ -35,7 +35,7 @@ class IDEDecompilerDriver(val settings: List[String]) extends dotc.Driver {
3535
run.printSummary()
3636
val unit = ctx.run.units.head
3737

38-
val decompiled = QuoteContextImpl.showDecompiledTree(unit.tpdTree)
38+
val decompiled = QuotesImpl.showDecompiledTree(unit.tpdTree)
3939
val tree = new TastyHTMLPrinter(unit.pickled.head._2()).showContents()
4040

4141
reporter.removeBufferedMessages.foreach(message => System.err.println(message))

compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ object PickledQuotes {
4141
/** Transform the expression into its fully spliced Tree */
4242
def quotedExprToTree[T](expr: quoted.Expr[T])(using Context): Tree = {
4343
val expr1 = expr.asInstanceOf[ExprImpl]
44-
expr1.checkScopeId(QuoteContextImpl.scopeId)
44+
expr1.checkScopeId(QuotesImpl.scopeId)
4545
changeOwnerOfTree(expr1.tree, ctx.owner)
4646
}
4747

4848
/** Transform the expression into its fully spliced TypeTree */
4949
def quotedTypeToTree(tpe: quoted.Type[?])(using Context): Tree = {
5050
val tpe1 = tpe.asInstanceOf[TypeImpl]
51-
tpe1.checkScopeId(QuoteContextImpl.scopeId)
51+
tpe1.checkScopeId(QuotesImpl.scopeId)
5252
changeOwnerOfTree(tpe1.typeTree, ctx.owner)
5353
}
5454

@@ -74,11 +74,11 @@ object PickledQuotes {
7474
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match {
7575
case Hole(isTerm, idx, args) =>
7676
val reifiedArgs = args.map { arg =>
77-
if (arg.isTerm) (using qctx: QuoteContext) => new ExprImpl(arg, QuoteContextImpl.scopeId)
78-
else new TypeImpl(arg, QuoteContextImpl.scopeId)
77+
if (arg.isTerm) (using qctx: QuoteContext) => new ExprImpl(arg, QuotesImpl.scopeId)
78+
else new TypeImpl(arg, QuotesImpl.scopeId)
7979
}
8080
if isTerm then
81-
val quotedExpr = termHole(idx, reifiedArgs, QuoteContextImpl())
81+
val quotedExpr = termHole(idx, reifiedArgs, QuotesImpl())
8282
val filled = PickledQuotes.quotedExprToTree(quotedExpr)
8383

8484
// We need to make sure a hole is created with the source file of the surrounding context, even if

compiler/src/dotty/tools/dotc/transform/Splicer.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ object Splicer {
5252

5353
// Some parts of the macro are evaluated during the unpickling performed in quotedExprToTree
5454
val interpretedExpr = interpreter.interpret[QuoteContext => scala.quoted.Expr[Any]](tree)
55-
val interpretedTree = interpretedExpr.fold(tree)(macroClosure => PickledQuotes.quotedExprToTree(macroClosure(QuoteContextImpl())))
55+
val interpretedTree = interpretedExpr.fold(tree)(macroClosure => PickledQuotes.quotedExprToTree(macroClosure(QuotesImpl())))
5656

5757
checkEscapedVariables(interpretedTree, macroOwner)
5858
} finally {
@@ -325,10 +325,10 @@ object Splicer {
325325
}
326326

327327
private def interpretQuote(tree: Tree)(implicit env: Env): Object =
328-
new ExprImpl(Inlined(EmptyTree, Nil, QuoteUtils.changeOwnerOfTree(tree, ctx.owner)).withSpan(tree.span), QuoteContextImpl.scopeId)
328+
new ExprImpl(Inlined(EmptyTree, Nil, QuoteUtils.changeOwnerOfTree(tree, ctx.owner)).withSpan(tree.span), QuotesImpl.scopeId)
329329

330330
private def interpretTypeQuote(tree: Tree)(implicit env: Env): Object =
331-
new TypeImpl(QuoteUtils.changeOwnerOfTree(tree, ctx.owner), QuoteContextImpl.scopeId)
331+
new TypeImpl(QuoteUtils.changeOwnerOfTree(tree, ctx.owner), QuotesImpl.scopeId)
332332

333333
private def interpretLiteral(value: Any)(implicit env: Env): Object =
334334
value.asInstanceOf[Object]

compiler/src/scala/quoted/runtime/impl/QuoteContextImpl.scala renamed to compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

+28-28
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import scala.quoted.runtime.impl.printers._
2121

2222
import scala.reflect.TypeTest
2323

24-
object QuoteContextImpl {
24+
object QuotesImpl {
2525

2626
type ScopeId = Int
2727

2828
def apply()(using Context): QuoteContext =
29-
new QuoteContextImpl
29+
new QuotesImpl
3030

3131
def showDecompiledTree(tree: tpd.Tree)(using Context): String = {
32-
val qctx: QuoteContextImpl = new QuoteContextImpl(using MacroExpansion.context(tree))
32+
val qctx: QuotesImpl = new QuotesImpl(using MacroExpansion.context(tree))
3333
if ctx.settings.color.value == "always" then
3434
qctx.reflect.TreeMethodsImpl.temporaryShowAnsiColored(tree)
3535
else
@@ -43,7 +43,7 @@ object QuoteContextImpl {
4343

4444
}
4545

46-
class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, QuoteUnpickler, QuoteMatching:
46+
class QuotesImpl private (using val ctx: Context) extends QuoteContext, QuoteUnpickler, QuoteMatching:
4747

4848
private val yCheck: Boolean =
4949
ctx.settings.Ycheck.value(using ctx).exists(x => x == "all" || x == "macros")
@@ -92,11 +92,11 @@ class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, Qu
9292
def pos: Position = self.sourcePos
9393
def symbol: Symbol = self.symbol
9494
def showExtractors: String =
95-
Extractors.showTree(using QuoteContextImpl.this)(self)
95+
Extractors.showTree(using QuotesImpl.this)(self)
9696
def show: String =
97-
SourceCode.showTree(using QuoteContextImpl.this)(self)(SyntaxHighlight.plain)
97+
SourceCode.showTree(using QuotesImpl.this)(self)(SyntaxHighlight.plain)
9898
def showAnsiColored: String =
99-
SourceCode.showTree(using QuoteContextImpl.this)(self)(SyntaxHighlight.ANSI)
99+
SourceCode.showTree(using QuotesImpl.this)(self)(SyntaxHighlight.ANSI)
100100
def isExpr: Boolean =
101101
self match
102102
case TermTypeTest(self) =>
@@ -106,15 +106,15 @@ class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, Qu
106106
case _ => false
107107
def asExpr: scala.quoted.Expr[Any] =
108108
if self.isExpr then
109-
new ExprImpl(self, QuoteContextImpl.this.hashCode)
109+
new ExprImpl(self, QuotesImpl.this.hashCode)
110110
else self match
111111
case TermTypeTest(self) => throw new Exception("Expected an expression. This is a partially applied Term. Try eta-expanding the term first.")
112112
case _ => throw new Exception("Expected a Term but was: " + self)
113113
end extension
114114

115115
extension [T](self: Tree)
116116
def asExprOf(using tp: scala.quoted.Type[T]): scala.quoted.Expr[T] =
117-
QuoteContextImpl.this.asExprOf[T](self.asExpr)(using tp)
117+
QuotesImpl.this.asExprOf[T](self.asExpr)(using tp)
118118
end extension
119119

120120
extension [ThisTree <: Tree](self: ThisTree):
@@ -332,7 +332,7 @@ class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, Qu
332332
object Term extends TermModule:
333333
def of(expr: Expr[Any]): Term =
334334
val exprImpl = expr.asInstanceOf[ExprImpl]
335-
exprImpl.checkScopeId(QuoteContextImpl.this.hashCode)
335+
exprImpl.checkScopeId(QuotesImpl.this.hashCode)
336336
exprImpl.tree
337337

338338
def betaReduce(tree: Term): Option[Term] =
@@ -352,11 +352,11 @@ class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, Qu
352352
object TermMethodsImpl extends TermMethods:
353353
extension (self: Term):
354354
def seal: scala.quoted.Expr[Any] =
355-
if self.isExpr then new ExprImpl(self, QuoteContextImpl.this.hashCode)
355+
if self.isExpr then new ExprImpl(self, QuotesImpl.this.hashCode)
356356
else throw new Exception("Cannot seal a partially applied Term. Try eta-expanding the term first.")
357357

358358
def sealOpt: Option[scala.quoted.Expr[Any]] =
359-
if self.isExpr then Some(new ExprImpl(self, QuoteContextImpl.this.hashCode))
359+
if self.isExpr then Some(new ExprImpl(self, QuotesImpl.this.hashCode))
360360
else None
361361

362362
def tpe: TypeRepr = self.tpe
@@ -1559,18 +1559,18 @@ class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, Qu
15591559
object TypeReprMethodsImpl extends TypeReprMethods:
15601560
extension (self: TypeRepr):
15611561
def showExtractors: String =
1562-
Extractors.showType(using QuoteContextImpl.this)(self)
1562+
Extractors.showType(using QuotesImpl.this)(self)
15631563

15641564
def show: String =
1565-
SourceCode.showType(using QuoteContextImpl.this)(self)(SyntaxHighlight.plain)
1565+
SourceCode.showType(using QuotesImpl.this)(self)(SyntaxHighlight.plain)
15661566

15671567
def showAnsiColored: String =
1568-
SourceCode.showType(using QuoteContextImpl.this)(self)(SyntaxHighlight.ANSI)
1568+
SourceCode.showType(using QuotesImpl.this)(self)(SyntaxHighlight.ANSI)
15691569

15701570
def seal: scala.quoted.Type[_] = self.asType
15711571

15721572
def asType: scala.quoted.Type[?] =
1573-
new TypeImpl(Inferred(self), QuoteContextImpl.this.hashCode)
1573+
new TypeImpl(Inferred(self), QuotesImpl.this.hashCode)
15741574

15751575
def =:=(that: TypeRepr): Boolean = self =:= that
15761576
def <:<(that: TypeRepr): Boolean = self <:< that
@@ -2124,11 +2124,11 @@ class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, Qu
21242124
extension (self: Constant):
21252125
def value: Any = self.value
21262126
def showExtractors: String =
2127-
Extractors.showConstant(using QuoteContextImpl.this)(self)
2127+
Extractors.showConstant(using QuotesImpl.this)(self)
21282128
def show: String =
2129-
SourceCode.showConstant(using QuoteContextImpl.this)(self)(SyntaxHighlight.plain)
2129+
SourceCode.showConstant(using QuotesImpl.this)(self)(SyntaxHighlight.plain)
21302130
def showAnsiColored: String =
2131-
SourceCode.showConstant(using QuoteContextImpl.this)(self)(SyntaxHighlight.ANSI)
2131+
SourceCode.showConstant(using QuotesImpl.this)(self)(SyntaxHighlight.ANSI)
21322132
end extension
21332133
end ConstantMethodsImpl
21342134

@@ -2330,11 +2330,11 @@ class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, Qu
23302330
def children: List[Symbol] = self.denot.children
23312331

23322332
def showExtractors: String =
2333-
Extractors.showSymbol(using QuoteContextImpl.this)(self)
2333+
Extractors.showSymbol(using QuotesImpl.this)(self)
23342334
def show: String =
2335-
SourceCode.showSymbol(using QuoteContextImpl.this)(self)(SyntaxHighlight.plain)
2335+
SourceCode.showSymbol(using QuotesImpl.this)(self)(SyntaxHighlight.plain)
23362336
def showAnsiColored: String =
2337-
SourceCode.showSymbol(using QuoteContextImpl.this)(self)(SyntaxHighlight.ANSI)
2337+
SourceCode.showSymbol(using QuotesImpl.this)(self)(SyntaxHighlight.ANSI)
23382338

23392339
end extension
23402340

@@ -2467,11 +2467,11 @@ class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, Qu
24672467
def |(that: Flags): Flags = dotc.core.Flags.or(self, that) // TODO: Replace with dotc.core.Flags.|(self)(that) once extension names have stabilized
24682468
def &(that: Flags): Flags = dotc.core.Flags.and(self, that)// TODO: Replace with dotc.core.Flags.&(self)(that) once extension names have stabilized
24692469
def showExtractors: String =
2470-
Extractors.showFlags(using QuoteContextImpl.this)(self)
2470+
Extractors.showFlags(using QuotesImpl.this)(self)
24712471
def show: String =
2472-
SourceCode.showFlags(using QuoteContextImpl.this)(self)(SyntaxHighlight.plain)
2472+
SourceCode.showFlags(using QuotesImpl.this)(self)(SyntaxHighlight.plain)
24732473
def showAnsiColored: String =
2474-
SourceCode.showFlags(using QuoteContextImpl.this)(self)(SyntaxHighlight.ANSI)
2474+
SourceCode.showFlags(using QuotesImpl.this)(self)(SyntaxHighlight.ANSI)
24752475
end extension
24762476
end FlagsMethodsImpl
24772477

@@ -2643,7 +2643,7 @@ class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, Qu
26432643
ctx1.gadt.addToConstraint(typeHoles)
26442644
ctx1
26452645

2646-
val qctx1 = QuoteContextImpl()(using ctx1)
2646+
val qctx1 = QuotesImpl()(using ctx1)
26472647

26482648
val matcher = new Matcher.QuoteMatcher[qctx1.type](qctx1) {
26492649
def patternHoleSymbol: qctx1.reflect.Symbol = dotc.core.Symbols.defn.QuotedRuntimePatterns_patternHole.asInstanceOf
@@ -2667,7 +2667,7 @@ class QuoteContextImpl private (using val ctx: Context) extends QuoteContext, Qu
26672667
}
26682668
}
26692669

2670-
private[this] val hash = QuoteContextImpl.scopeId(using ctx)
2670+
private[this] val hash = QuotesImpl.scopeId(using ctx)
26712671
override def hashCode: Int = hash
26722672

2673-
end QuoteContextImpl
2673+
end QuotesImpl

docs/docs/reference/changed-features/numeric-literals.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ no code that can be executed at runtime. That is why we define an intermediary c
206206
method in the `FromDigits` given instance. That method is defined in terms of a macro
207207
implementation method `fromDigitsImpl`. Here is its definition:
208208
```scala
209-
private def fromDigitsImpl(digits: Expr[String])(using ctx: QuoteContext): Expr[BigFloat] =
209+
private def fromDigitsImpl(digits: Expr[String])(using ctx: Quotes): Expr[BigFloat] =
210210
digits match {
211211
case Const(ds) =>
212212
try {

docs/docs/reference/contextual/derivation-macro.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ we need to implement a method `Eq.derived` on the companion object of `Eq` that
2525
produces a quoted instance for `Eq[T]`. Here is a possible signature,
2626

2727
```scala
28-
given derived[T: Type](using qctx: QuoteContext) as Expr[Eq[T]]
28+
given derived[T: Type](using qctx: Quotes) as Expr[Eq[T]]
2929
```
3030

3131
and for comparison reasons we give the same signature we had with `inline`:
@@ -41,7 +41,7 @@ from the signature. The body of the `derived` method is shown below:
4141

4242

4343
```scala
44-
given derived[T: Type](using qctx: QuoteContext) as Expr[Eq[T]] = {
44+
given derived[T: Type](using qctx: Quotes) as Expr[Eq[T]] = {
4545
import qctx.reflect._
4646

4747
val ev: Expr[Mirror.Of[T]] = Expr.summon[Mirror.Of[T]].get
@@ -91,7 +91,7 @@ The implementation of `summonAll` as a macro can be show below assuming that we
9191
have the given instances for our primitive types:
9292

9393
```scala
94-
def summonAll[T: Type](using qctx: QuoteContext): List[Expr[Eq[_]]] = Type.of[T] match {
94+
def summonAll[T: Type](using qctx: Quotes): List[Expr[Eq[_]]] = Type.of[T] match {
9595
case '[String *: tpes] => '{ summon[Eq[String]] } :: summonAll[tpes]
9696
case '[Int *: tpes] => '{ summon[Eq[Int]] } :: summonAll[tpes]
9797
case '[tpe *: tpes] => derived[tpe] :: summonAll[tpes]
@@ -169,14 +169,14 @@ object Eq {
169169
def eqv(x: T, y: T): Boolean = body(x, y)
170170
}
171171

172-
def summonAll[T: Type](using qctx: QuoteContext): List[Expr[Eq[_]]] = Type.of[T] match {
172+
def summonAll[T: Type](using qctx: Quotes): List[Expr[Eq[_]]] = Type.of[T] match {
173173
case '[String *: tpes] => '{ summon[Eq[String]] } :: summonAll[tpes]
174174
case '[Int *: tpes] => '{ summon[Eq[Int]] } :: summonAll[tpes]
175175
case '[tpe *: tpes] => derived[tpe] :: summonAll[tpes]
176176
case '[EmptyTuple] => Nil
177177
}
178178

179-
given derived[T: Type](using qctx: QuoteContext) as Expr[Eq[T]] = {
179+
given derived[T: Type](using qctx: Quotes) as Expr[Eq[T]] = {
180180
import qctx.reflect._
181181

182182
val ev: Expr[Mirror.Of[T]] = Expr.summon[Mirror.Of[T]].get

0 commit comments

Comments
 (0)