Skip to content

Commit 96f3759

Browse files
committed
Replace scala.quoted.qctx with scala.quoted.reflect
1 parent e893fc1 commit 96f3759

File tree

154 files changed

+247
-227
lines changed

Some content is hidden

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

154 files changed

+247
-227
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ import scala.quoted._
55

66
object Extractors {
77

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

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

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

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

20-
def showFlags(using QuoteContext)(flags: qctx.reflect.Flags): String = {
21-
import qctx.reflect._
20+
def showFlags(using qctx: QuoteContext)(flags: reflect.Flags): String = {
21+
import 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"
@@ -58,7 +58,7 @@ object Extractors {
5858
}
5959

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

6363
private val sb: StringBuilder = new StringBuilder
6464

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

Lines changed: 7 additions & 7 deletions
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 QuoteContext)(tree: qctx.reflect.Tree)(syntaxHighlight: SyntaxHighlight): String =
9+
def showTree(using qctx: QuoteContext)(tree: reflect.Tree)(syntaxHighlight: SyntaxHighlight): String =
1010
new SourceCodePrinter[qctx.type](syntaxHighlight).printTree(tree).result()
1111

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

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

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

21-
def showFlags(using QuoteContext)(flags: qctx.reflect.Flags)(syntaxHighlight: SyntaxHighlight): String = {
22-
import qctx.reflect._
21+
def showFlags(using qctx: QuoteContext)(flags: reflect.Flags)(syntaxHighlight: SyntaxHighlight): String = {
22+
import 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 <: QuoteContext & Singleton](syntaxHighlight: SyntaxHighlight)(using val qctx: QCtx) {
6262
import syntaxHighlight._
63-
import qctx.reflect._
63+
import reflect._
6464

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

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

Lines changed: 3 additions & 3 deletions
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: QuoteContext): Expr[T] =
17-
import qctx.reflect._
17+
import 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: QuoteContext): Expr[T] = {
27-
import qctx.reflect._
27+
import 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: QuoteContext): Option[Expr[T]] = {
213-
import qctx.reflect._
213+
import 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

Lines changed: 1 addition & 1 deletion
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: QuoteContext, tpe: Type[T]): Expr[T] = {
10-
import qctx.reflect._
10+
import reflect._
1111
final class MapChildren() {
1212

1313
def transformStatement(tree: Statement)(using ctx: Context): Statement = {

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

Lines changed: 10 additions & 10 deletions
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 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 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 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 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 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 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 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 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 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 reflect._
9191
Ref(defn.Predef_classOf).appliedToType(TypeRepr.typeConstructorOf(x)).asExpr.asInstanceOf[Expr[Class[T]]]
9292
}
9393
}

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

Lines changed: 2 additions & 2 deletions
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 tp: Type[T])(using qctx: QuoteContext): String =
16-
qctx.reflect.TypeTree.of[T].show
16+
reflect.TypeTree.of[T].show
1717

1818
/** Shows the tree as fully typed source code colored with ANSI */
1919
def showAnsiColored[T](using tp: Type[T])(using qctx: QuoteContext): String =
20-
qctx.reflect.TypeTree.of[T].showAnsiColored
20+
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

Lines changed: 1 addition & 1 deletion
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: QuoteContext): Option[T] = {
18-
import qctx.reflect._
18+
import 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/QuoteContext.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package scala.quoted
66
* It contains the low-level Typed AST API metaprogramming API.
77
* This API does not have the static type guarantiees that `Expr` and `Type` provide.
88
*
9-
* @param tasty Typed AST API. Usage: `def f(qctx: QuoteContext) = { import qctx.reflect._; ... }`.
9+
* @param tasty Typed AST API. Usage: `def f(qctx: QuoteContext) = { import reflect._; ... }`.
1010
*/
1111
trait QuoteContext { self: internal.QuoteUnpickler & internal.QuoteMatching =>
1212

@@ -79,10 +79,10 @@ trait QuoteContext { self: internal.QuoteUnpickler & internal.QuoteMatching =>
7979
* to explicitly state that a context is nested as in the following example:
8080
*
8181
* ```scala
82-
* def run(using qctx: QuoteContext)(tree: qctx.reflect.Tree): Unit =
82+
* def run(using qctx: QuoteContext)(tree: reflect.Tree): Unit =
8383
* def nested()(using qctx.Nested): Expr[Int] = '{ ${ makeExpr(tree) } + 1 }
8484
* '{ ${ nested() } + 2 }
85-
* def makeExpr(using qctx: QuoteContext)(tree: qctx.reflect.Tree): Expr[Int] = ???
85+
* def makeExpr(using qctx: QuoteContext)(tree: reflect.Tree): Expr[Int] = ???
8686
* ```
8787
*/
8888
type Nested = QuoteContext {

library/src/scala/quoted/Reflection.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3453,7 +3453,7 @@ trait Reflection { reflection =>
34533453
*
34543454
* Usage:
34553455
* ```
3456-
* import qctx.reflect._
3456+
* import reflect._
34573457
* class MyTreeMap extends TreeMap {
34583458
* override def transformTree(tree: Tree)(using ctx: Context): Tree = ...
34593459
* }

library/src/scala/quoted/Varargs.scala

Lines changed: 2 additions & 2 deletions
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: QuoteContext): Expr[Seq[T]] = {
19-
import qctx.reflect._
19+
import 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: QuoteContext): Option[Seq[Expr[T]]] = {
36-
import qctx.reflect._
36+
import 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)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package scala.quoted
2+
3+
/** Current QuoteContext.reflect in scope
4+
*
5+
* Usage:
6+
* To use reflection inside a method
7+
* ```
8+
* def f(using QuoteContext) = { // or (using qctx: QuoteContext)
9+
* import reflect._ // equivalent to import reflect._
10+
* ...
11+
* }
12+
* ```
13+
* or to use reflection in the signature of a method
14+
* ```
15+
* def f(using QuoteContext)(tree: reflect.Tree): reflect.Position = ...
16+
* ```
17+
*/
18+
def reflect(using qctx: QuoteContext): qctx.reflect.type = qctx.reflect

library/src/scala/quoted/report.scala

Lines changed: 4 additions & 4 deletions
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: QuoteContext): Unit =
7-
import qctx.reflect._
7+
import 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: QuoteContext): Unit =
12-
import qctx.reflect._
12+
import reflect._
1313
Reporting.error(msg, Term.of(expr).pos)
1414

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

2626
/** Report a warning */
2727
def warning(msg: => String)(using qctx: QuoteContext): Unit =
28-
import qctx.reflect._
28+
import 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: QuoteContext): Unit =
33-
import qctx.reflect._
33+
import reflect._
3434
Reporting.warning(msg, Term.of(expr).pos)
3535

3636
/** Throwable used to stop the expansion of a macro after an error was reported */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ trait TastyInspector:
1818
self =>
1919

2020
/** Process a TASTy file using TASTy reflect */
21-
protected def processCompilationUnit(using QuoteContext)(root: qctx.reflect.Tree): Unit
21+
protected def processCompilationUnit(using QuoteContext)(root: reflect.Tree): Unit
2222

2323
/** Load and process TASTy files using TASTy reflect
2424
*

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

Lines changed: 1 addition & 1 deletion
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: QuoteContext): Expr[String] = {
10-
import qctx.reflect._
10+
import 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

Lines changed: 1 addition & 1 deletion
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: QuoteContext): Expr[Unit] = {
7-
import qctx.reflect._
7+
import reflect._
88
Implicits.search(TypeRepr.of[A]) match {
99
case x: ImplicitSearchSuccess =>
1010
'{}

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

Lines changed: 1 addition & 1 deletion
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: QuoteContext) : Expr[Unit] = {
7-
import qctx.reflect._
7+
import reflect._
88
Implicits.search(TypeRepr.of[A]) match {
99
case x: ImplicitSearchSuccess =>
1010
'{}

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

Lines changed: 1 addition & 1 deletion
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: QuoteContext) : Expr[Unit] = {
7-
import qctx.reflect._
7+
import reflect._
88
Implicits.search(TypeRepr.of[A]) match {
99
case x: ImplicitSearchSuccess =>
1010
'{}

tests/neg-macros/i6432/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Macro {
66
extension (inline sc: StringContext) inline def foo(args: String*): Unit = ${ impl('sc) }
77

88
def impl(sc: Expr[StringContext])(using qctx: QuoteContext) : Expr[Unit] = {
9-
import qctx.reflect._
9+
import reflect._
1010
sc match {
1111
case '{ StringContext(${Varargs(parts)}: _*) } =>
1212
for (part @ Const(s) <- parts)

tests/neg-macros/i6432b/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Macro {
66
extension (inline sc: StringContext) inline def foo(args: String*): Unit = ${ impl('sc) }
77

88
def impl(sc: Expr[StringContext])(using qctx: QuoteContext) : Expr[Unit] = {
9-
import qctx.reflect._
9+
import reflect._
1010
sc match {
1111
case '{ StringContext(${Varargs(parts)}: _*) } =>
1212
for (part @ Const(s) <- parts)

tests/neg-macros/i7698.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ trait Show[T] {
55
}
66

77
def showInterpolatorImpl(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using qctx: QuoteContext): Expr[String] =
8-
import qctx.reflect._
8+
import reflect._
99
Term.of(argsExpr) match
1010
case '{ $arg: $t } => // error
1111
case '[ Int ] => // error

tests/neg-macros/i7919.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.quoted._
22

33
object Test {
44
def staged[T](using qctx: QuoteContext) = {
5-
import qctx.reflect._
5+
import reflect._
66
given typeT as Type[T] // error
77
val tt = TypeRepr.of[T]
88
'{ "in staged" }

tests/neg-macros/i8871.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.quoted._
22
object Macro {
33
def impl[A : Type](using qctx: QuoteContext): Unit = {
4-
import qctx.reflect._
4+
import reflect._
55
val tpe = TypeRepr.of[A].asType.asInstanceOf[Type[_ <: AnyRef]]
66
'{ (a: ${tpe}) => ???} // error
77
}

0 commit comments

Comments
 (0)