Skip to content

Commit dbece72

Browse files
committed
Rename qctx to quotes
1 parent 90a3a79 commit dbece72

File tree

167 files changed

+294
-285
lines changed

Some content is hidden

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

167 files changed

+294
-285
lines changed

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[QCtx <: Quotes & Singleton](using val quotes: QCtx) { self =>
61+
import quotes.reflect._
6262

6363
private val sb: StringBuilder = new StringBuilder
6464

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

+10-10
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"
@@ -60,7 +60,7 @@ object SourceCode {
6060

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

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

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

+3-3
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 qctx: 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 qctx: 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

@@ -210,7 +210,7 @@ object Expr {
210210
* @param qctx current context
211211
*/
212212
def summon[T](using tpe: Type[T])(using qctx: Quotes): Option[Expr[T]] = {
213-
import qctx.reflect._
213+
import quotes.reflect._
214214
Implicits.search(TypeRepr.of[T]) match {
215215
case iss: ImplicitSearchSuccess => Some(iss.tree.asExpr.asInstanceOf[Expr[T]])
216216
case isf: ImplicitSearchFailure => None

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

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

88
/** Map subexpressions an expression `e` with a type `tpe` */
99
def transformChildren[T](e: Expr[T])(using qctx: Quotes, tpe: 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 = {

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/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 qctx: 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

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

library/src/scala/quoted/Varargs.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object Varargs {
1616
* ```
1717
*/
1818
def apply[T](xs: Seq[Expr[T]])(using tp: Type[T], qctx: Quotes): Expr[Seq[T]] = {
19-
import qctx.reflect._
19+
import quotes.reflect._
2020
Repeated(xs.map(Term.of).toList, TypeTree.of[T]).asExpr.asInstanceOf[Expr[Seq[T]]]
2121
}
2222

@@ -33,7 +33,7 @@ object Varargs {
3333
* ```
3434
*/
3535
def unapply[T](expr: Expr[Seq[T]])(using qctx: Quotes): Option[Seq[Expr[T]]] = {
36-
import qctx.reflect._
36+
import quotes.reflect._
3737
def rec(tree: Term): Option[Seq[Expr[T]]] = tree match {
3838
case Typed(Repeated(elems, _), _) => Some(elems.map(x => x.asExpr.asInstanceOf[Expr[T]]))
3939
case Block(Nil, e) => rec(e)

library/src/scala/quoted/qctx.scala

-4
This file was deleted.

library/src/scala/quoted/report.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ object report:
44

55
/** Report an error at the position of the macro expansion */
66
def error(msg: => String)(using qctx: Quotes): Unit =
7-
import qctx.reflect._
7+
import quotes.reflect._
88
Reporting.error(msg, Position.ofMacroExpansion)
99

1010
/** Report an error at the on the position of `expr` */
1111
def error(msg: => String, expr: Expr[Any])(using qctx: Quotes): Unit =
12-
import qctx.reflect._
12+
import quotes.reflect._
1313
Reporting.error(msg, Term.of(expr).pos)
1414

1515
/** Report an error at the position of the macro expansion and throws a StopMacroExpansion */
@@ -25,12 +25,12 @@ object report:
2525

2626
/** Report a warning */
2727
def warning(msg: => String)(using qctx: Quotes): Unit =
28-
import qctx.reflect._
28+
import quotes.reflect._
2929
Reporting.warning(msg, Position.ofMacroExpansion)
3030

3131
/** Report a warning at the on the position of `expr` */
3232
def warning(msg: => String, expr: Expr[Any])(using qctx: Quotes): Unit =
33-
import qctx.reflect._
33+
import quotes.reflect._
3434
Reporting.warning(msg, Term.of(expr).pos)
3535

3636
end report

scala3doc/src/dotty/dokka/tasty/SymOps.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class SymOps[Q <: Quotes](val q: Q):
5050
// TODO: #49 Remove it after TASTY-Reflect release with published flag Extension
5151
def hackIsOpen: Boolean = {
5252
import dotty.tools.dotc
53-
given dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
53+
given dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
5454
val symbol = sym.asInstanceOf[dotc.core.Symbols.Symbol]
5555
symbol.is(dotc.core.Flags.Open)
5656
}

scala3doc/src/dotty/dokka/tasty/comments/MemberLookup.scala

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ trait MemberLookup {
66

77
def lookup(using Quotes)(
88
query: Query,
9-
owner: qctx.reflect.Symbol,
10-
): Option[(qctx.reflect.Symbol, String)] = lookupOpt(query, Some(owner))
9+
owner: quotes.reflect.Symbol,
10+
): Option[(quotes.reflect.Symbol, String)] = lookupOpt(query, Some(owner))
1111

1212
def lookupOpt(using Quotes)(
1313
query: Query,
14-
ownerOpt: Option[qctx.reflect.Symbol],
15-
): Option[(qctx.reflect.Symbol, String)] =
14+
ownerOpt: Option[quotes.reflect.Symbol],
15+
): Option[(quotes.reflect.Symbol, String)] =
1616
try
17-
import qctx.reflect._
17+
import quotes.reflect._
1818

1919
def nearestClass(sym: Symbol): Symbol =
2020
if sym.isClassDef then sym else nearestClass(sym.owner)
@@ -59,25 +59,25 @@ trait MemberLookup {
5959
println(s"[WARN] Unable to find a link for ${query} ${ownerOpt.fold("")(o => "in " + o.name)}")
6060
None
6161

62-
private def hackMembersOf(using Quotes)(rsym: qctx.reflect.Symbol) = {
63-
import qctx.reflect._
62+
private def hackMembersOf(using Quotes)(rsym: quotes.reflect.Symbol) = {
63+
import quotes.reflect._
6464
import dotty.tools.dotc
65-
given dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
65+
given dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
6666
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
6767
val members = sym.info.decls.iterator.filter(_.isCompleted)
6868
// println(s"members of ${sym.show} : ${members.map(_.show).mkString(", ")}")
6969
members.asInstanceOf[Iterator[Symbol]]
7070
}
7171

72-
private def hackIsNotAbsent(using Quotes)(rsym: qctx.reflect.Symbol) = {
72+
private def hackIsNotAbsent(using Quotes)(rsym: quotes.reflect.Symbol) = {
7373
import dotty.tools.dotc
74-
given dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
74+
given dotc.core.Contexts.Context = quotes.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
7575
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
7676
sym.isCompleted
7777
}
7878

79-
private def localLookup(using Quotes)(query: String, owner: qctx.reflect.Symbol): Option[qctx.reflect.Symbol] = {
80-
import qctx.reflect._
79+
private def localLookup(using Quotes)(query: String, owner: quotes.reflect.Symbol): Option[quotes.reflect.Symbol] = {
80+
import quotes.reflect._
8181

8282
inline def whenExists(s: Symbol)(otherwise: => Option[Symbol]): Option[Symbol] =
8383
if s.exists then Some(s) else otherwise
@@ -129,7 +129,7 @@ trait MemberLookup {
129129
}
130130
}
131131

132-
private def downwardLookup(using Quotes)(query: List[String], owner: qctx.reflect.Symbol): Option[qctx.reflect.Symbol] =
132+
private def downwardLookup(using Quotes)(query: List[String], owner: quotes.reflect.Symbol): Option[quotes.reflect.Symbol] =
133133
query match {
134134
case Nil => None
135135
case q :: Nil => localLookup(q, owner)

tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait TastyInspector:
2020
self =>
2121

2222
/** Process a TASTy file using TASTy reflect */
23-
protected def processCompilationUnit(using Quotes)(root: qctx.reflect.Tree): Unit
23+
protected def processCompilationUnit(using Quotes)(root: quotes.reflect.Tree): Unit
2424

2525
/** Called after all compilation units are processed */
2626
protected def postProcess(using Quotes): Unit = ()

tests/disabled/pos-macros/i7853/SummonJsonEncoderTest_2.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object SummonJsonEncoderTest {
77
inline def encodeAndMessAroundType[T](value: =>T): String = ${ encodeAndMessAroundTypeImpl('value) }
88

99
def encodeAndMessAroundTypeImpl[T: Type](value: Expr[T])(using qctx: Quotes): Expr[String] = {
10-
import qctx.reflect._
10+
import quotes.reflect._
1111

1212
val mirrorExpr = Expr.summon[Mirror.Of[T]] match {
1313
case Some(mirror) => mirror

tests/neg-macros/delegate-match-1/Macro_1.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.quoted._
44
inline def f: Any = ${ fImpl }
55

66
private def fImpl(using qctx: Quotes): Expr[Unit] = {
7-
import qctx.reflect._
7+
import quotes.reflect._
88
Implicits.search(TypeRepr.of[A]) match {
99
case x: ImplicitSearchSuccess =>
1010
'{}

tests/neg-macros/delegate-match-2/Macro_1.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.quoted._
44
inline def f: Any = ${ fImpl }
55

66
private def fImpl (using qctx: Quotes) : Expr[Unit] = {
7-
import qctx.reflect._
7+
import quotes.reflect._
88
Implicits.search(TypeRepr.of[A]) match {
99
case x: ImplicitSearchSuccess =>
1010
'{}

0 commit comments

Comments
 (0)