Skip to content

Commit bd9a3b9

Browse files
committed
Rename ValueOfExpr to Unliftable
As the dual of Liftable, the concept should be named Unliftable. Additionally when programmers did not know about ValueOfExpr, they have been asking is the was an unliftable/unlift.
1 parent ff476f7 commit bd9a3b9

File tree

10 files changed

+81
-81
lines changed

10 files changed

+81
-81
lines changed

library/src/scala/quoted/Expr.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ class Expr[+T] private[scala] {
1616
* Returns `None` if the expression does not contain a value or contains side effects.
1717
* Otherwise returns the `Some` of the value.
1818
*/
19-
final def getValue[U >: T](using qctx: QuoteContext, valueOf: ValueOfExpr[U]): Option[U] = valueOf(this)
19+
final def getValue[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): Option[U] = unlift(this)
2020

2121
/** Return the value of this expression.
2222
*
2323
* Emits an error error and throws if the expression does not contain a value or contains side effects.
2424
* Otherwise returns the value.
2525
*/
26-
final def value[U >: T](using qctx: QuoteContext, valueOf: ValueOfExpr[U]): U =
27-
valueOf(this).getOrElse(qctx.throwError(s"Expected a known value. \n\nThe value of: $show\ncould not be recovered using $valueOf", this))
26+
final def value[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): U =
27+
unlift(this).getOrElse(qctx.throwError(s"Expected a known value. \n\nThe value of: $show\ncould not be recovered using $unlift", this))
2828

2929
/** Pattern matches `this` against `that`. Effectively performing a deep equality check.
3030
* It does the equivalent of

library/src/scala/quoted/ValueOfExpr.scala renamed to library/src/scala/quoted/Unliftable.scala

Lines changed: 63 additions & 63 deletions
Large diffs are not rendered by default.

library/src/scala/quoted/Value.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Value {
1212
* }
1313
* ```
1414
*/
15-
def unapply[T](expr: Expr[T])(using valueOf: ValueOfExpr[T], qxtc: QuoteContext): Option[T] =
16-
valueOf(expr)
15+
def unapply[T](expr: Expr[T])(using unlift: Unliftable[T], qxtc: QuoteContext): Option[T] =
16+
unlift(expr)
1717

1818
}

library/src/scala/quoted/Values.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Values {
1515
* }
1616
* ```
1717
*/
18-
def unapply[T](exprs: Seq[Expr[T]])(using valueOf: ValueOfExpr[T], qctx: QuoteContext): Option[Seq[T]] =
18+
def unapply[T](exprs: Seq[Expr[T]])(using unlift: Unliftable[T], qctx: QuoteContext): Option[Seq[T]] =
1919
exprs.foldRight(Option(List.empty[T])) { (elem, acc) =>
2020
(elem, acc) match {
2121
case (Value(value), Some(lst)) => Some(value :: lst)

library/src/scala/quoted/matching/ValueSeq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object ValueSeq {
1717
* ```
1818
*/
1919
@deprecated("use scala.quoted.Varargs(scala.quoted.Value(_)) instead", "0.23.0")
20-
def unapply[T](expr: Expr[Seq[T]])(using valueOf: ValueOfExpr[T], qctx: QuoteContext): Option[Seq[T]] =
20+
def unapply[T](expr: Expr[Seq[T]])(using unlift: Unliftable[T], qctx: QuoteContext): Option[Seq[T]] =
2121
import scala.quoted.Const
2222
expr match
2323
case Varargs(Values(elems)) => Some(elems)

library/src/scala/quoted/matching/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ package object matching {
2626
@deprecated("use scala.quoted.Value instead", "0.23.0")
2727
val Value: quoted.Value.type = quoted.Value
2828

29-
@deprecated("use scala.quoted.ValueOfExpr instead", "0.23.0")
30-
val ValueOfExpr: quoted.ValueOfExpr.type = quoted.ValueOfExpr
29+
@deprecated("use scala.quoted.Value instead", "0.23.0")
30+
val ValueOfExpr: quoted.Value.type = quoted.Value
3131

3232
}

tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object E {
99

1010
def impl[T: Type](x: Expr[E[T]]) (using QuoteContext): Expr[T] = x.value.lift
1111

12-
implicit def ev1[T: Type]: ValueOfExpr[E[T]] = new ValueOfExpr {
12+
implicit def ev1[T: Type]: Unliftable[E[T]] = new Unliftable {
1313
def apply(x: Expr[E[T]]) (using QuoteContext): Option[E[T]] = x match {
1414
case '{ I(${Const(n)}) } => Some(I(n).asInstanceOf[E[T]])
1515
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]])
@@ -18,7 +18,7 @@ object E {
1818
}
1919

2020
object Value {
21-
def unapply[T, U >: T](expr: Expr[T])(using ValueOfExpr[U], QuoteContext): Option[U] = expr.getValue
21+
def unapply[T, U >: T](expr: Expr[T])(using Unliftable[U], QuoteContext): Option[U] = expr.getValue
2222
}
2323
}
2424

tests/run-macros/i7964/Macro_1.scala

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

3-
enum Num { // TODO derive a quoted.ValueOfExpr
3+
enum Num { // TODO derive a quoted.Unliftable
44
case One
55
case Two
66
}

tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object E {
99
def impl[T: Type](expr: Expr[E[T]]) (using QuoteContext): Expr[T] =
1010
expr.value.lift
1111

12-
implicit def ev1[T: Type]: ValueOfExpr[E[T]] = new ValueOfExpr { // TODO use type class derivation
12+
implicit def ev1[T: Type]: Unliftable[E[T]] = new Unliftable { // TODO use type class derivation
1313
def apply(x: Expr[E[T]]) (using QuoteContext): Option[E[T]] = (x match {
1414
case '{ I(${Const(n)}) } => Some(I(n))
1515
case '{ D(${Const(n)}) } => Some(D(n))
@@ -22,7 +22,7 @@ object E {
2222
}
2323

2424
object Value {
25-
def unapply[T, U >: T](expr: Expr[T])(using ValueOfExpr[U], QuoteContext): Option[U] = expr.getValue
25+
def unapply[T, U >: T](expr: Expr[T])(using Unliftable[U], QuoteContext): Option[U] = expr.getValue
2626
}
2727

2828
}

tests/run-staging/quote-valueof-list.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Test {
77

88
def main(args: Array[String]): Unit = withQuoteContext {
99

10-
implicit def ValueOfExprInt: ValueOfExpr[Int] = new {
10+
implicit def UnliftableInt: Unliftable[Int] = new {
1111
def apply(n: Expr[Int])(using QuoteContext): Option[Int] = n match {
1212
case '{ 0 } => Some(0)
1313
case '{ 1 } => Some(1)
@@ -16,15 +16,15 @@ object Test {
1616
}
1717
}
1818

19-
implicit def ValueOfExprBoolean: ValueOfExpr[Boolean] = new ValueOfExpr[Boolean] {
19+
implicit def UnliftableBoolean: Unliftable[Boolean] = new Unliftable[Boolean] {
2020
def apply(b: Expr[Boolean])(using QuoteContext): Option[Boolean] = b match {
2121
case '{ true } => Some(true)
2222
case '{ false } => Some(false)
2323
case _ => None
2424
}
2525
}
2626

27-
implicit def ValueOfExprList[T: ValueOfExpr: Type]: ValueOfExpr[List[T]] = new {
27+
implicit def UnliftableList[T: Unliftable: Type]: Unliftable[List[T]] = new {
2828
def apply(xs: Expr[List[T]])(using QuoteContext): Option[List[T]] = (xs: Expr[Any]) match {
2929
case '{ ($xs1: List[T]).::($x) } =>
3030
for { head <- x.getValue; tail <- xs1.getValue }
@@ -34,7 +34,7 @@ object Test {
3434
}
3535
}
3636

37-
implicit def ValueOfExprOption[T: ValueOfExpr: Type]: ValueOfExpr[Option[T]] = new {
37+
implicit def UnliftableOption[T: Unliftable: Type]: Unliftable[Option[T]] = new {
3838
def apply(expr: Expr[Option[T]])(using QuoteContext): Option[Option[T]] = expr match {
3939
case '{ Some[T]($x) } => for (v <- x.getValue) yield Some(v)
4040
case '{ None } => Some(None)

0 commit comments

Comments
 (0)