Skip to content

Commit 4cd4497

Browse files
committed
Replace scala.quoted.qctx with scala.quoted.reflect
1 parent c3ac180 commit 4cd4497

File tree

158 files changed

+252
-241
lines changed

Some content is hidden

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

158 files changed

+252
-241
lines changed

library/src-bootstrapped/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-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-
qctx.reflect.Term.betaReduce(expr.unseal) match
17+
reflect.Term.betaReduce(expr.unseal) match
1818
case Some(expr1) => expr1.asExpr.asInstanceOf[Expr[T]]
1919
case _ => expr
2020

@@ -23,7 +23,7 @@ object Expr {
2323
* will be equivalent to `'{ $s1; $s2; ...; $e }`.
2424
*/
2525
def block[T](statements: List[Expr[Any]], expr: Expr[T])(using qctx: QuoteContext): Expr[T] = {
26-
import qctx.reflect._
26+
import reflect._
2727
Block(statements.map(_.unseal), expr.unseal).asExpr.asInstanceOf[Expr[T]]
2828
}
2929

@@ -209,7 +209,7 @@ object Expr {
209209
* @param qctx current context
210210
*/
211211
def summon[T](using tpe: Type[T])(using qctx: QuoteContext): Option[Expr[T]] = {
212-
import qctx.reflect._
212+
import reflect._
213213
Implicits.search(TypeRepr.of[T]) match {
214214
case iss: ImplicitSearchSuccess => Some(iss.tree.asExpr.asInstanceOf[Expr[T]])
215215
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.apply` was not handled by PickleQuotes")

library/src-bootstrapped/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](_.unseal).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)

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

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

library/src/scala/quoted/qctx.scala

Lines changed: 0 additions & 4 deletions
This file was deleted.
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 qctx.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,11 +4,11 @@ object report:
44

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

99
/** Report an error at the on the position of `expr` */
1010
def error(msg: => String, expr: Expr[Any])(using qctx: QuoteContext): Unit =
11-
qctx.reflect.Reporting.error(msg, expr.unseal.pos)
11+
reflect.Reporting.error(msg, expr.unseal.pos)
1212

1313
/** Report an error at the position of the macro expansion and throws a StopQuotedContext */
1414
def throwError(msg: => String)(using qctx: QuoteContext): Nothing = {
@@ -23,11 +23,11 @@ object report:
2323

2424
/** Report a warning */
2525
def warning(msg: => String)(using qctx: QuoteContext): Unit =
26-
qctx.reflect.Reporting.warning(msg, qctx.reflect.Position.ofMacroExpansion)
26+
reflect.Reporting.warning(msg, reflect.Position.ofMacroExpansion)
2727

2828
/** Report a warning at the on the position of `expr` */
2929
def warning(msg: => String, expr: Expr[_])(using qctx: QuoteContext): Unit =
30-
qctx.reflect.Reporting.warning(msg, expr.unseal.pos)
30+
reflect.Reporting.warning(msg, expr.unseal.pos)
3131

3232
/** Throwable used to stop the expansion of a macro after an error was reported */
3333
class StopQuotedContext extends Throwable

library/src/scala/tasty/Reflection.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3447,7 +3447,7 @@ trait Reflection { reflection =>
34473447
*
34483448
* Usage:
34493449
* ```
3450-
* import qctx.reflect._
3450+
* import reflect._
34513451
* class MyTreeMap extends TreeMap {
34523452
* override def transformTree(tree: Tree)(using ctx: Context): Tree = ...
34533453
* }

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/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
}

tests/neg-macros/i8871b.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/*: Type[? <: AnyKind]*/ = TypeRepr.of[A].asType
66
'{ f[$tpe] } // error
77
}

tests/neg-macros/i9801/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ def impl(prog: Expr[Double])(using QuoteContext) : Expr[Double] =
1515
triggerStackOverflow(0)
1616
} catch {
1717
case e =>
18-
qctx.reflect.Reporting.error(e.getMessage, prog.unseal.pos)
18+
reflect.Reporting.error(e.getMessage, prog.unseal.pos)
1919
'{ 42.0 }
2020
}

tests/neg-macros/macros-in-same-project-6/Foo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Foo {
55
inline def myMacro(): Unit = ${ aMacroImplementation }
66

77
def aMacroImplementation(using qctx: QuoteContext) : Expr[Unit] = {
8-
import qctx.reflect._
8+
import reflect._
99
Reporting.error("some error", Position.ofMacroExpansion)
1010
throw new NoClassDefFoundError("Bar$")
1111
}

tests/neg-macros/tasty-macro-assert-1/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Asserts {
1313
${impl('cond)}
1414

1515
def impl(cond: Expr[Boolean])(using qctx: QuoteContext) : Expr[Unit] = {
16-
import qctx.reflect._
16+
import reflect._
1717

1818
val tree = cond.unseal
1919

tests/neg-macros/tasty-macro-assert-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Asserts {
1313
${ impl('cond) }
1414

1515
def impl(cond: Expr[Boolean])(using qctx: QuoteContext) : Expr[Unit] = {
16-
import qctx.reflect._
16+
import reflect._
1717

1818
val tree = cond.unseal
1919

tests/neg-macros/tasty-macro-error/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Macros {
55
inline def fun(x: Any): Unit = ${ impl('x) }
66

77
def impl(x: Expr[Any])(using qctx: QuoteContext) : Expr[Unit] = {
8-
import qctx.reflect._
8+
import reflect._
99
Reporting.error("here is the the argument is " + x.unseal.underlyingArgument.show, x.unseal.underlyingArgument.pos)
1010
'{}
1111
}

tests/neg-macros/tasty-macro-positions/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Macros {
55
inline def fun(x: Any): Unit = ${ impl('x) }
66

77
def impl(x: Expr[Any])(using qctx: QuoteContext) : Expr[Unit] = {
8-
import qctx.reflect._
8+
import reflect._
99
val pos = x.unseal.underlyingArgument.pos
1010
Reporting.error("here is the the argument is " + x.unseal.underlyingArgument.show, pos)
1111
Reporting.error("here (+5) is the the argument is " + x.unseal.underlyingArgument.show, pos.sourceFile, pos.start + 5, pos.end + 5)

tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Macro {
1010
object FIntepolator {
1111

1212
def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using qctx: QuoteContext) : Expr[String] = {
13-
import qctx.reflect._
13+
import reflect._
1414
Reporting.error("there are no parts", strCtxExpr.unseal.underlyingArgument.pos)
1515
'{ ($strCtxExpr).s($argsExpr: _*) }
1616
}

tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Macro {
99

1010
object FIntepolator {
1111
def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using qctx: QuoteContext) : Expr[String] = {
12-
import qctx.reflect._
12+
import reflect._
1313
Reporting.error("there are no args", argsExpr.unseal.underlyingArgument.pos)
1414
'{ ($strCtxExpr).s($argsExpr: _*) }
1515
}

0 commit comments

Comments
 (0)