Skip to content

Commit 83f2644

Browse files
committed
Rename qctx to quotes
1 parent 2a7f19a commit 83f2644

File tree

181 files changed

+328
-321
lines changed

Some content is hidden

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

181 files changed

+328
-321
lines changed
Submodule dotty-cps-async updated 34 files

compiler/src/scala/quoted/runtime/impl/TypeImpl.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ final class TypeImpl(val typeTree: tpd.Tree, val scopeId: Int) extends Type[?] {
1313
case _ => false
1414
}
1515

16-
/** View this expression `quoted.Type[T]` as a `TypeTree` */
17-
def unseal(using Quotes): qctx.reflect.TypeTree =
18-
checkScopeId(qctx.hashCode)
19-
typeTree.asInstanceOf[qctx.reflect.TypeTree]
16+
/** View this expression `q.Type[T]` as a `TypeTree` */
17+
def unseal(using q: Quotes): q.reflect.TypeTree =
18+
checkScopeId(q.hashCode)
19+
typeTree.asInstanceOf[q.reflect.TypeTree]
2020

2121
def checkScopeId(expectedScopeId: Int): Unit =
2222
if expectedScopeId != scopeId then

compiler/src/scala/quoted/runtime/impl/printers/Extractors.scala

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import scala.quoted._
55

66
object Extractors {
77

8-
def showTree(using Quotes)(tree: qctx.reflect.Tree): String =
9-
new ExtractorsPrinter[qctx.type]().visitTree(tree).result()
8+
def showTree(using Quotes)(tree: quotes.reflect.Tree): String =
9+
new ExtractorsPrinter[quotes.type]().visitTree(tree).result()
1010

11-
def showType(using Quotes)(tpe: qctx.reflect.TypeRepr): String =
12-
new ExtractorsPrinter[qctx.type]().visitType(tpe).result()
11+
def showType(using Quotes)(tpe: quotes.reflect.TypeRepr): String =
12+
new ExtractorsPrinter[quotes.type]().visitType(tpe).result()
1313

14-
def showConstant(using Quotes)(const: qctx.reflect.Constant): String =
15-
new ExtractorsPrinter[qctx.type]().visitConstant(const).result()
14+
def showConstant(using Quotes)(const: quotes.reflect.Constant): String =
15+
new ExtractorsPrinter[quotes.type]().visitConstant(const).result()
1616

17-
def showSymbol(using Quotes)(symbol: qctx.reflect.Symbol): String =
18-
new ExtractorsPrinter[qctx.type]().visitSymbol(symbol).result()
17+
def showSymbol(using Quotes)(symbol: quotes.reflect.Symbol): String =
18+
new ExtractorsPrinter[quotes.type]().visitSymbol(symbol).result()
1919

20-
def showFlags(using Quotes)(flags: qctx.reflect.Flags): String = {
21-
import qctx.reflect._
20+
def showFlags(using Quotes)(flags: quotes.reflect.Flags): String = {
21+
import quotes.reflect._
2222
val flagList = List.newBuilder[String]
2323
if (flags.is(Flags.Abstract)) flagList += "Flags.Abstract"
2424
if (flags.is(Flags.Artifact)) flagList += "Flags.Artifact"
@@ -57,8 +57,8 @@ object Extractors {
5757
flagList.result().mkString(" | ")
5858
}
5959

60-
private class ExtractorsPrinter[QCtx <: Quotes & Singleton](using val qctx: QCtx) { self =>
61-
import qctx.reflect._
60+
private class ExtractorsPrinter[Q <: Quotes & Singleton](using val quotes: Q) { self =>
61+
import quotes.reflect._
6262

6363
private val sb: StringBuilder = new StringBuilder
6464

compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ import scala.annotation.switch
66
/** Printer for fully elaborated representation of the source code */
77
object SourceCode {
88

9-
def showTree(using Quotes)(tree: qctx.reflect.Tree)(syntaxHighlight: SyntaxHighlight): String =
10-
new SourceCodePrinter[qctx.type](syntaxHighlight).printTree(tree).result()
9+
def showTree(using Quotes)(tree: quotes.reflect.Tree)(syntaxHighlight: SyntaxHighlight): String =
10+
new SourceCodePrinter[quotes.type](syntaxHighlight).printTree(tree).result()
1111

12-
def showType(using Quotes)(tpe: qctx.reflect.TypeRepr)(syntaxHighlight: SyntaxHighlight): String =
13-
new SourceCodePrinter[qctx.type](syntaxHighlight).printType(tpe)(using None).result()
12+
def showType(using Quotes)(tpe: quotes.reflect.TypeRepr)(syntaxHighlight: SyntaxHighlight): String =
13+
new SourceCodePrinter[quotes.type](syntaxHighlight).printType(tpe)(using None).result()
1414

15-
def showConstant(using Quotes)(const: qctx.reflect.Constant)(syntaxHighlight: SyntaxHighlight): String =
16-
new SourceCodePrinter[qctx.type](syntaxHighlight).printConstant(const).result()
15+
def showConstant(using Quotes)(const: quotes.reflect.Constant)(syntaxHighlight: SyntaxHighlight): String =
16+
new SourceCodePrinter[quotes.type](syntaxHighlight).printConstant(const).result()
1717

18-
def showSymbol(using Quotes)(symbol: qctx.reflect.Symbol)(syntaxHighlight: SyntaxHighlight): String =
18+
def showSymbol(using Quotes)(symbol: quotes.reflect.Symbol)(syntaxHighlight: SyntaxHighlight): String =
1919
symbol.fullName
2020

21-
def showFlags(using Quotes)(flags: qctx.reflect.Flags)(syntaxHighlight: SyntaxHighlight): String = {
22-
import qctx.reflect._
21+
def showFlags(using Quotes)(flags: quotes.reflect.Flags)(syntaxHighlight: SyntaxHighlight): String = {
22+
import quotes.reflect._
2323
val flagList = List.newBuilder[String]
2424
if (flags.is(Flags.Abstract)) flagList += "abstract"
2525
if (flags.is(Flags.Artifact)) flagList += "artifact"
@@ -58,9 +58,9 @@ object SourceCode {
5858
flagList.result().mkString("/*", " ", "*/")
5959
}
6060

61-
private class SourceCodePrinter[QCtx <: Quotes & Singleton](syntaxHighlight: SyntaxHighlight)(using val qctx: QCtx) {
61+
private class SourceCodePrinter[Q <: Quotes & Singleton](syntaxHighlight: SyntaxHighlight)(using val quotes: Q) {
6262
import syntaxHighlight._
63-
import qctx.reflect._
63+
import quotes.reflect._
6464

6565
private[this] val sb: StringBuilder = new StringBuilder
6666

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ from the signature. The body of the `derived` method is shown below:
4242

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

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

@@ -177,7 +177,7 @@ object Eq {
177177
}
178178

179179
given derived[T: Type](using q: Quotes) as Expr[Eq[T]] = {
180-
import qctx.reflect._
180+
import quotes.reflect._
181181

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

docs/docs/reference/metaprogramming/tasty-reflect.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ guarantees and may fail at macro expansion time, hence additional explicit
2020
checks must be done.
2121

2222
To provide reflection capabilities in macros we need to add an implicit
23-
parameter of type `scala.quoted.Quotes` and import `qctx.reflect._` from it in
23+
parameter of type `scala.quoted.Quotes` and import `quotes.reflect._` from it in
2424
the scope where it is used.
2525

2626
```scala
@@ -29,19 +29,19 @@ import scala.quoted._
2929
inline def natConst(inline x: Int): Int = ${natConstImpl('{x})}
3030

3131
def natConstImpl(x: Expr[Int])(using Quotes): Expr[Int] = {
32-
import qctx.reflect._
32+
import quotes.reflect._
3333
...
3434
}
3535
```
3636

3737
### Extractors
3838

39-
`import qctx.reflect._` will provide all extractors and methods on TASTy Reflect
39+
`import quotes.reflect._` will provide all extractors and methods on TASTy Reflect
4040
trees. For example the `Literal(_)` extractor used below.
4141

4242
```scala
4343
def natConstImpl(x: Expr[Int])(using Quotes): Expr[Int] = {
44-
import qctx.reflect._
44+
import quotes.reflect._
4545
val xTree: Term = Term.of(x)
4646
xTree match {
4747
case Inlined(_, _, Literal(Constant(n: Int))) =>
@@ -59,9 +59,9 @@ def natConstImpl(x: Expr[Int])(using Quotes): Expr[Int] = {
5959
```
6060

6161
To easily know which extractors are needed, the `showExtractors` method on a
62-
`qctx.reflect.Term` returns the string representation of the extractors.
62+
`quotes.reflect.Term` returns the string representation of the extractors.
6363

64-
The methods `qctx.reflect.Term.{asExpr, asExprOf}` provide a way to go back to a `quoted.Expr`.
64+
The methods `quotes.reflect.Term.{asExpr, asExprOf}` provide a way to go back to a `quoted.Expr`.
6565
Note that `asExpr` returns a `Expr[Any]`.
6666
On the other hand `asExprOf[T]` returns a `Expr[T]`, if the type does not conform to it an exception will be thrown at runtime.
6767

@@ -75,8 +75,8 @@ such as the start line, the end line or even the source code at the expansion
7575
point.
7676

7777
```scala
78-
def macroImpl()(qctx: Quotes): Expr[Unit] = {
79-
import qctx.reflect._
78+
def macroImpl()(quotes: Quotes): Expr[Unit] = {
79+
import quotes.reflect._
8080
val pos = rootPosition
8181

8282
val path = pos.sourceFile.jpath.toString

library/src-bootstrapped/scala/quoted/Expr.scala

+4-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Expr {
1414
* Some bindings may be elided as an early optimization.
1515
*/
1616
def betaReduce[T](expr: Expr[T])(using Quotes): Expr[T] =
17-
import qctx.reflect._
17+
import quotes.reflect._
1818
Term.betaReduce(Term.of(expr)) match
1919
case Some(expr1) => expr1.asExpr.asInstanceOf[Expr[T]]
2020
case _ => expr
@@ -24,7 +24,7 @@ object Expr {
2424
* will be equivalent to `'{ $s1; $s2; ...; $e }`.
2525
*/
2626
def block[T](statements: List[Expr[Any]], expr: Expr[T])(using Quotes): Expr[T] = {
27-
import qctx.reflect._
27+
import quotes.reflect._
2828
Block(statements.map(Term.of), Term.of(expr)).asExpr.asInstanceOf[Expr[T]]
2929
}
3030

@@ -40,7 +40,7 @@ object Expr {
4040
* `'{ Seq($e1, $e2, ...) }` typed as an `Expr[Seq[T]]`
4141
* ```
4242
*/
43-
def ofSeq[T](xs: Seq[Expr[T]])(using tp: Type[T], qctx: Quotes): Expr[Seq[T]] =
43+
def ofSeq[T](xs: Seq[Expr[T]])(using Type[T])(using Quotes): Expr[Seq[T]] =
4444
Varargs(xs)
4545

4646
/** Lifts this list of expressions into an expression of a list
@@ -208,11 +208,9 @@ object Expr {
208208
* `None` if implicit resolution failed.
209209
*
210210
* @tparam T type of the implicit parameter
211-
* @param tpe quoted type of the implicit parameter
212-
* @param qctx current context
213211
*/
214212
def summon[T](using Type[T])(using Quotes): Option[Expr[T]] = {
215-
import qctx.reflect._
213+
import quotes.reflect._
216214
Implicits.search(TypeRepr.of[T]) match {
217215
case iss: ImplicitSearchSuccess => Some(iss.tree.asExpr.asInstanceOf[Expr[T]])
218216
case isf: ImplicitSearchFailure => None

library/src-bootstrapped/scala/quoted/ExprMap.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait ExprMap:
77

88
/** Map subexpressions an expression `e` with a type `T` */
99
def transformChildren[T](e: Expr[T])(using Quotes, Type[T]): Expr[T] = {
10-
import qctx.reflect._
10+
import quotes.reflect._
1111
final class MapChildren() {
1212

1313
def transformStatement(tree: Statement)(owner: Symbol): Statement = {
@@ -102,7 +102,7 @@ trait ExprMap:
102102
type X
103103
val expr = tree.asExpr.asInstanceOf[Expr[X]]
104104
val t = tpe.asType.asInstanceOf[Type[X]]
105-
val transformedExpr = transform(expr)(using qctx, t)
105+
val transformedExpr = transform(expr)(using quotes, t)
106106
Term.of(transformedExpr)
107107
case _ =>
108108
transformTermChildren(tree, tpe)(owner)

library/src-bootstrapped/scala/quoted/Liftable.scala

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,70 +24,70 @@ object Liftable {
2424
/** Default liftable for Boolean */
2525
given BooleanLiftable[T <: Boolean] as Liftable[T] {
2626
def toExpr(x: T) =
27-
import qctx.reflect._
27+
import quotes.reflect._
2828
Literal(Constant.Boolean(x)).asExpr.asInstanceOf[Expr[T]]
2929
}
3030

3131
/** Default liftable for Byte */
3232
given ByteLiftable[T <: Byte] as Liftable[T] {
3333
def toExpr(x: T) =
34-
import qctx.reflect._
34+
import quotes.reflect._
3535
Literal(Constant.Byte(x)).asExpr.asInstanceOf[Expr[T]]
3636
}
3737

3838
/** Default liftable for Short */
3939
given ShortLiftable[T <: Short] as Liftable[T] {
4040
def toExpr(x: T) =
41-
import qctx.reflect._
41+
import quotes.reflect._
4242
Literal(Constant.Short(x)).asExpr.asInstanceOf[Expr[T]]
4343
}
4444

4545
/** Default liftable for Int */
4646
given IntLiftable[T <: Int] as Liftable[T] {
4747
def toExpr(x: T) =
48-
import qctx.reflect._
48+
import quotes.reflect._
4949
Literal(Constant.Int(x)).asExpr.asInstanceOf[Expr[T]]
5050
}
5151

5252
/** Default liftable for Long */
5353
given LongLiftable[T <: Long] as Liftable[T] {
5454
def toExpr(x: T) =
55-
import qctx.reflect._
55+
import quotes.reflect._
5656
Literal(Constant.Long(x)).asExpr.asInstanceOf[Expr[T]]
5757
}
5858

5959
/** Default liftable for Float */
6060
given FloatLiftable[T <: Float] as Liftable[T] {
6161
def toExpr(x: T) =
62-
import qctx.reflect._
62+
import quotes.reflect._
6363
Literal(Constant.Float(x)).asExpr.asInstanceOf[Expr[T]]
6464
}
6565

6666
/** Default liftable for Double */
6767
given DoubleLiftable[T <: Double] as Liftable[T] {
6868
def toExpr(x: T) =
69-
import qctx.reflect._
69+
import quotes.reflect._
7070
Literal(Constant.Double(x)).asExpr.asInstanceOf[Expr[T]]
7171
}
7272

7373
/** Default liftable for Char */
7474
given CharLiftable[T <: Char] as Liftable[T] {
7575
def toExpr(x: T) =
76-
import qctx.reflect._
76+
import quotes.reflect._
7777
Literal(Constant.Char(x)).asExpr.asInstanceOf[Expr[T]]
7878
}
7979

8080
/** Default liftable for String */
8181
given StringLiftable[T <: String] as Liftable[T] {
8282
def toExpr(x: T) =
83-
import qctx.reflect._
83+
import quotes.reflect._
8484
Literal(Constant.String(x)).asExpr.asInstanceOf[Expr[T]]
8585
}
8686

8787
/** Default liftable for Class[T] */
8888
given ClassLiftable[T] as Liftable[Class[T]] = new Liftable[Class[T]] {
8989
def toExpr(x: Class[T]) = {
90-
import qctx.reflect._
90+
import quotes.reflect._
9191
Ref(defn.Predef_classOf).appliedToType(TypeRepr.typeConstructorOf(x)).asExpr.asInstanceOf[Expr[Class[T]]]
9292
}
9393
}

library/src-bootstrapped/scala/quoted/Type.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ object Type:
1313

1414
/** Show a source code like representation of this type without syntax highlight */
1515
def show[T](using Type[T])(using Quotes): String =
16-
qctx.reflect.TypeTree.of[T].show
16+
quotes.reflect.TypeTree.of[T].show
1717

1818
/** Shows the tree as fully typed source code colored with ANSI */
1919
def showAnsiColored[T](using Type[T])(using Quotes): String =
20-
qctx.reflect.TypeTree.of[T].showAnsiColored
20+
quotes.reflect.TypeTree.of[T].showAnsiColored
2121

2222
/** Return a quoted.Type with the given type */
2323
@compileTimeOnly("Reference to `scala.quoted.Type.of` was not handled by PickleQuotes")

library/src/scala/quoted/Const.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Const {
1515
* ```
1616
*/
1717
def unapply[T](expr: Expr[T])(using Quotes): Option[T] = {
18-
import qctx.reflect._
18+
import quotes.reflect._
1919
def rec(tree: Term): Option[T] = tree match {
2020
case Literal(c) => Some(c.value.asInstanceOf[T])
2121
case Block(Nil, e) => rec(e)

library/src/scala/quoted/Quotes.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package scala.quoted
22

33
import scala.reflect.TypeTest
44

5+
/** Current Quotes in scope */
6+
inline def quotes(using q: Quotes): q.type = q
7+
58
/** Quotation context provided by a macro expansion or in the scope of `scala.quoted.run`.
69
* Used to perform all operations on quoted `Expr` or `Type`.
710
*
811
* It contains the low-level Typed AST API metaprogramming API.
912
* This API does not have the static type guarantiees that `Expr` and `Type` provide.
1013
*
11-
* @param tasty Typed AST API. Usage: `def f(qctx: Quotes) = { import qctx.reflect._; ... }`.
14+
* @param tasty Typed AST API. Usage: `def f(qctx: Quotes) = { import quotes.reflect._; ... }`.
1215
*/
1316
trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
1417

@@ -3534,7 +3537,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
35343537
*
35353538
* Usage:
35363539
* ```
3537-
* import qctx.reflect._
3540+
* import quotes.reflect._
35383541
* class MyTreeMap extends TreeMap {
35393542
* override def transformTree(tree: Tree)(owner: Symbol): Tree = ...
35403543
* }

0 commit comments

Comments
 (0)