Skip to content

Remove library methods deprecated in M3 #10830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions library/src-bootstrapped/scala/quoted/Unlifted.scala

This file was deleted.

21 changes: 0 additions & 21 deletions library/src/scala/deriving/Helpers.scala

This file was deleted.

38 changes: 0 additions & 38 deletions library/src/scala/quoted/Const.scala

This file was deleted.

30 changes: 0 additions & 30 deletions library/src/scala/quoted/Consts.scala

This file was deleted.

13 changes: 0 additions & 13 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
*/
def matches(that: Expr[Any]): Boolean

@deprecated("Use `.value` instead. This will be removed in 3.0.0-RC1", "3.0.0-M3")
def unlift(using FromExpr[T]): Option[T] = self.value

@deprecated("Use `.valueOrError` instead. This will be removed in 3.0.0-RC1", "3.0.0-M3")
def unliftOrError(using FromExpr[T]): T = self.valueOrError

/** Return the value of this expression.
*
* Returns `None` if the expression does not represent a value or possibly contains side effects.
Expand Down Expand Up @@ -228,9 +222,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>

/** Methods of the module object `val Tree` */
trait TreeModule { this: Tree.type =>
/** Returns the Term representation this expression */
@deprecated("Use `expr.asTerm` instead (must `import quotes.reflect._`). This will be removed in 3.0.0-RC1", "3.0.0-M3")
def of(expr: Expr[Any]): Tree = expr.asTerm
}

/** Makes extension methods on `Tree` available without any imports */
Expand Down Expand Up @@ -523,10 +514,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
/** Methods of the module object `val Term` */
trait TermModule { this: Term.type =>

/** Returns the Term representation this expression */
@deprecated("Use `expr.asTerm` instead (must `import quotes.reflect._`). This will be removed in 3.0.0-RC1", "3.0.0-M3")
def of(expr: Expr[Any]): Term = expr.asTerm

/** Returns a term that is functionally equivalent to `t`,
* however if `t` is of the form `((y1, ..., yn) => e2)(e1, ..., en)`
* then it optimizes this the top most call by returning the `Some`
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/string-interpolation-macro/Macro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Macro {
var res: Expr[String] = null
for _ <- 0 to 5_000 do
(strCtxExpr, argsExpr) match {
case ('{ StringContext(${Varargs(Consts(parts))}: _*) }, Varargs(Consts(args))) =>
case ('{ StringContext(${Varargs(Exprs(parts))}: _*) }, Varargs(Exprs(args))) =>
res = Expr(StringContext(parts: _*).s(args: _*))
case _ => ???
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i6432/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Macro {
import quotes.reflect._
sc match {
case '{ StringContext(${Varargs(parts)}: _*) } =>
for (part @ Const(s) <- parts)
for (part @ Expr(s) <- parts)
report.error(s, part.asTerm.pos)
}
'{}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i6432b/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Macro {
import quotes.reflect._
sc match {
case '{ StringContext(${Varargs(parts)}: _*) } =>
for (part @ Const(s) <- parts)
for (part @ Expr(s) <- parts)
report.error(s, part.asTerm.pos)
}
'{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object E {

implicit def ev1[T: Type]: FromExpr[E[T]] = new FromExpr {
def unapply(x: Expr[E[T]])(using Quotes) = x match {
case '{ I(${Const(n)}) } => Some(I(n).asInstanceOf[E[T]])
case '{ I(${Expr(n)}) } => Some(I(n).asInstanceOf[E[T]])
case '{ Plus[T](${Value(x)}, ${Value(y)})(using $op) } if op.matches('{Plus2.IPlus}) => Some(Plus(x, y)(using Plus2.IPlus.asInstanceOf[Plus2[T]]).asInstanceOf[E[T]])
case _ => None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import scala.quoted._
import Even._

object EvenFromDigitsImpl:
def apply(digits: Expr[String])(using Quotes): Expr[Even] = digits match {
case Const(ds) =>
def apply(digits: Expr[String])(using Quotes): Expr[Even] = digits.value match {
case Some(ds) =>
val ev =
try evenFromDigits(ds)
catch {
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/expr-map-1/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private def stringRewriter(e: Expr[Any])(using Quotes): Expr[Any] =
private object StringRewriter extends ExprMap {

def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = e match
case Const(s: String) =>
case '{ ${Expr(s)}: String } =>
Expr(s.reverse) match
case '{ $x: T } => x
case _ => e // e had a singlton String type
Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/flops-rewrite-2/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ private def rewriteMacro[T: Type](x: Expr[T])(using Quotes): Expr[T] = {
case (_, Some(_)) => '{ $y * $x }
case _ => '{ $x * $y }
}
case '{ power(${Const(x)}, ${Const(y)}) } =>
case '{ power(${Expr(x)}, ${Expr(y)}) } =>
Expr(power(x, y))
case '{ power($x, ${Const(y)}) } =>
case '{ power($x, ${Expr(y)}) } =>
if y == 0 then '{1}
else '{ times($x, power($x, ${Expr(y-1)})) }
}),
Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/flops-rewrite-3/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ private def rewriteMacro[T: Type](x: Expr[T])(using Quotes): Expr[T] = {
case (_, Some(_)) => '{ $y * $x }
case _ => '{ $x * $y }
}
case '{ power(${Const(x)}, ${Const(y)}) } =>
case '{ power(${Expr(x)}, ${Expr(y)}) } =>
Expr(power(x, y))
case '{ power($x, ${Const(y)}) } =>
case '{ power($x, ${Expr(y)}) } =>
if y == 0 then '{1}
else '{ times($x, power($x, ${Expr(y-1)})) }
}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i6270/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ object api {

private def reflImplColor(x: Expr[String])(using Quotes) : Expr[String] = {
import quotes.reflect._
Expr(Term.of(x).show(using Printer.TreeAnsiCode))
Expr(x.asTerm.show(using Printer.TreeAnsiCode))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ object E {

implicit def ev1[T: Type]: FromExpr[E[T]] = new FromExpr { // TODO use type class derivation
def unapply(x: Expr[E[T]])(using Quotes) = (x match {
case '{ I(${Const(n)}) } => Some(I(n))
case '{ D(${Const(n)}) } => Some(D(n))
case '{ I(${Expr(n)}) } => Some(I(n))
case '{ D(${Expr(n)}) } => Some(D(n))
case '{ Plus[Int](${Value(x)}, ${Value(y)})(using $op) } => Some(Plus(x, y)(using Plus2.IPlus))
case '{ Plus[Double](${Value(x)}, ${Value(y)})(using $op) } => Some(Plus(x, y)(using Plus2.DPlus))
case '{ Times[Int](${Value(x)}, ${Value(y)})(using $op) } => Some(Times(x, y)(using Times2.ITimes))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Macros {

private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(using Quotes): Expr[String] = {
self match {
case '{ StringContext(${Varargs(Consts(parts))}: _*) } =>
case '{ StringContext(${Varargs(Exprs(parts))}: _*) } =>
val upprerParts: List[String] = parts.toList.map(_.toUpperCase)
val upprerPartsExpr: Expr[List[String]] = Expr.ofList(upprerParts.map(Expr(_)))
'{ StringContext($upprerPartsExpr: _*).s($args: _*) }
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/quote-matcher-symantics-1/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Macros {

def lift(e: Expr[DSL]): Expr[T] = e match {

case '{ LitDSL(${ Const(c) }) } =>
case '{ LitDSL(${ Expr(c) }) } =>
'{ $sym.value(${Expr(c)}) }

case '{ ($x: DSL) + ($y: DSL) } =>
Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/quote-matcher-symantics-2/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object Macros {

def lift(e: Expr[DSL])(implicit env: Map[Int, Expr[T]]): Expr[T] = e match {

case '{ LitDSL(${Const(c)}) } => sym.value(c)
case '{ LitDSL(${Expr(c)}) } => sym.value(c)

case '{ ($x: DSL) + ($y: DSL) } => sym.plus(lift(x), lift(y))

Expand All @@ -35,7 +35,7 @@ object Macros {
lift(close(body1)(nEnvVar))(env + (i -> lift(value)))
}

case '{ envVar(${Const(i)}) } => env(i)
case '{ envVar(${Expr(i)}) } => env(i)

case _ =>
import quotes.reflect._
Expand Down
19 changes: 18 additions & 1 deletion tests/run-macros/quote-matcher-symantics-3/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Macros {
object FromEnv {
def unapply[T](e: Expr[Any])(using env: Env): Option[Expr[R[T]]] =
e match
case '{envVar[t](${Const(id)})} =>
case '{envVar[t](${Expr(id)})} =>
env.get(id).asInstanceOf[Option[Expr[R[T]]]] // We can only add binds that have the same type as the refs
case _ =>
None
Expand Down Expand Up @@ -122,3 +122,20 @@ trait Symantics {
object Symantics {
def fix[A, B](f: (A => B) => (A => B)): A => B = throw new Exception("Must be used inside of `lift`")
}

object Const {
def unapply[T](expr: Expr[T])(using Quotes): Option[T] = {
import quotes.reflect._
def rec(tree: Term): Option[T] = tree match {
case Literal(c) =>
c match
case NullConstant() | UnitConstant() | ClassOfConstant(_) => None
case _ => Some(c.value.asInstanceOf[T])
case Block(Nil, e) => rec(e)
case Typed(e, _) => rec(e)
case Inlined(_, Nil, e) => rec(e)
case _ => None
}
rec(expr.asTerm)
}
}
2 changes: 1 addition & 1 deletion tests/run-macros/quoted-matching-docs/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private def sumExprShow(argsExpr: Expr[Seq[Int]]) (using Quotes): Expr[String] =

private def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes) : Expr[Int] = {
UnsafeExpr.underlyingArgument(argsExpr) match {
case Varargs(Consts(args)) => // args is of type Seq[Int]
case Varargs(Exprs(args)) => // args is of type Seq[Int]
Expr(args.sum) // precompute result of sum
case Varargs(argExprs) => // argExprs is of type Seq[Expr[Int]]
val staticSum: Int = argExprs.map(_.value.getOrElse(0)).sum
Expand Down
1 change: 0 additions & 1 deletion tests/run-macros/tasty-extractors-constants-1.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
4
abc
null
OK
8 changes: 3 additions & 5 deletions tests/run-macros/tasty-extractors-constants-1/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ object Macros {
val buff = new StringBuilder
def stagedPrintln(x: Any): Unit = buff append java.util.Objects.toString(x) append "\n"

Expr(3) match { case Const(n) => stagedPrintln(n) }
'{4} match { case Const(n) => stagedPrintln(n) }
'{"abc"} match { case Const(n) => stagedPrintln(n) }
Expr(3) match { case Expr(n) => stagedPrintln(n) }
'{4} match { case Expr(n) => stagedPrintln(n) }
'{"abc"} match { case Expr(n) => stagedPrintln(n) }
'{null} match { case '{null} => stagedPrintln(null) }

'{new Object} match { case Const(n) => println(n); case _ => stagedPrintln("OK") }

'{print(${Expr(buff.result())})}
}
}