Skip to content

Commit 1979749

Browse files
committed
Rename Expr.reduce to Expr.betaReduce
1 parent 40b785c commit 1979749

File tree

26 files changed

+103
-103
lines changed

26 files changed

+103
-103
lines changed

docs/docs/reference/metaprogramming/macros.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,20 @@ expressiveness.
135135

136136
### From `Expr`s to Functions and Back
137137

138-
The `Expr` companion object contains a `reduce` conversion that turns a tree
138+
The `Expr` companion object contains a `betaReduce` conversion that turns a tree
139139
describing a function into a function mapping trees to trees.
140140
```scala
141141
object Expr {
142142
...
143-
def reduce[...](...)(...): ... =
143+
def betaReduce[...](...)(...): ... = ...
144144
}
145145
```
146-
The definition of `Expr.reduce(f)(x)` is assumed to be functionally the same as
146+
The definition of `Expr.betaReduce(f)(x)` is assumed to be functionally the same as
147147
`'{($f)($x)}`, however it should optimize this call by returning the
148148
result of beta-reducing `f(x)` if `f` is a known lambda expression.
149-
`Expr.reduce` distributes applications of `Expr` over function arrows:
149+
`Expr.betaReduce` distributes applications of `Expr` over function arrows:
150150
```scala
151-
Expr.reduce(_): Expr[(T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
151+
Expr.betaReduce(_): Expr[(T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
152152
```
153153
Its dual, let’s call it `reflect`, can be defined as follows:
154154
```scala

library/src/scala/quoted/Expr.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,29 @@ package quoted {
2828
/** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */
2929
type TupleOfExpr[Tup <: Tuple] = Tuple.Map[Tup, [X] =>> (given QuoteContext) => Expr[X]]
3030

31-
/** `Expr.reduce(f)(x1, ..., xn)` is functionally the same as `'{($f)($x1, ..., $xn)}`, however it optimizes this call
31+
/** `Expr.betaReduce(f)(x1, ..., xn)` is functionally the same as `'{($f)($x1, ..., $xn)}`, however it optimizes this call
3232
* by returning the result of beta-reducing `f(x1, ..., xn)` if `f` is a known lambda expression.
3333
*
34-
* `Expr.reduce` distributes applications of `Expr` over function arrows
34+
* `Expr.betaReduce` distributes applications of `Expr` over function arrows
3535
* ```scala
36-
* Expr.reduce(_): Expr[(T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
36+
* Expr.betaReduce(_): Expr[(T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
3737
* ```
3838
*/
39-
def reduce[F, Args <: Tuple, R, G](f: Expr[F])(given tf: TupledFunction[F, Args => R], tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]], qctx: QuoteContext): G = {
39+
def betaReduce[F, Args <: Tuple, R, G](f: Expr[F])(given tf: TupledFunction[F, Args => R], tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]], qctx: QuoteContext): G = {
4040
import qctx.tasty._
4141
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]])
4242
}
4343

44-
/** `Expr.reduceGiven(f)(x1, ..., xn)` is functionally the same as `'{($f)(given $x1, ..., $xn)}`, however it optimizes this call
44+
/** `Expr.betaReduceGiven(f)(x1, ..., xn)` is functionally the same as `'{($f)(given $x1, ..., $xn)}`, however it optimizes this call
4545
* by returning the result of beta-reducing `f(given x1, ..., xn)` if `f` is a known lambda expression.
4646
*
47-
* `Expr.reduceGiven` distributes applications of `Expr` over function arrows
47+
* `Expr.betaReduceGiven` distributes applications of `Expr` over function arrows
4848
* ```scala
49-
* Expr.reduceGiven(_): Expr[(given T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
49+
* Expr.betaReduceGiven(_): Expr[(given T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R])
5050
* ```
51-
* Note: The
51+
* Note: The
5252
*/
53-
def reduceGiven[F, Args <: Tuple, R, G](f: Expr[F])(given tf: TupledFunction[F, (given Args) => R], tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]], qctx: QuoteContext): G = {
53+
def betaReduceGiven[F, Args <: Tuple, R, G](f: Expr[F])(given tf: TupledFunction[F, (given Args) => R], tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]], qctx: QuoteContext): G = {
5454
import qctx.tasty._
5555
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]])
5656
}

tests/pos/i6783.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-
def testImpl(f: Expr[(Int, Int) => Int])(given QuoteContext): Expr[Int] = Expr.reduce(f)('{1}, '{2})
3+
def testImpl(f: Expr[(Int, Int) => Int])(given QuoteContext): Expr[Int] = Expr.betaReduce(f)('{1}, '{2})
44

55
inline def test(f: (Int, Int) => Int) = ${
66
testImpl('f)

tests/run-macros/gestalt-optional-staging/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object Optional {
2424
// FIXME fix issue #5097 and enable private
2525
/*private*/ def mapImpl[A >: Null : Type, B >: Null : Type](opt: Expr[Optional[A]], f: Expr[A => B])(given QuoteContext): Expr[Optional[B]] = '{
2626
if ($opt.isEmpty) new Optional(null)
27-
else new Optional(${Expr.reduce(f)('{$opt.value})})
27+
else new Optional(${Expr.betaReduce(f)('{$opt.value})})
2828
}
2929

3030
}

tests/run-macros/i4734/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Macros {
1515
for (j <- new UnrolledRange(0, unrollSize)) '{
1616
val index = i + $j
1717
val element = ($seq)(index)
18-
${ Expr.reduce(f)('element) } // or `($f)(element)` if `f` should not be inlined
18+
${ Expr.betaReduce(f)('element) } // or `($f)(element)` if `f` should not be inlined
1919
}
2020
}
2121
i += ${unrollSize}

tests/run-macros/i4735/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Macro {
1717
${
1818
for (j <- new UnrolledRange(0, unrollSize)) '{
1919
val element = ($seq)(i + ${j})
20-
${Expr.reduce(f)('element)} // or `($f)(element)` if `f` should not be inlined
20+
${Expr.betaReduce(f)('element)} // or `($f)(element)` if `f` should not be inlined
2121
}
2222
}
2323
i += ${unrollSize}

tests/run-macros/i7008/macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def mcrProxy(expr: Expr[Boolean])(given QuoteContext): Expr[Unit] = {
1515
def mcrImpl[T](func: Expr[Seq[Box[T]] => Unit], expr: Expr[T])(given ctx: QuoteContext, tt: Type[T]): Expr[Unit] = {
1616
import ctx.tasty._
1717
val arg = Expr.ofSeq(Seq('{(Box($expr))}))
18-
Expr.reduce(func)(arg)
18+
Expr.betaReduce(func)(arg)
1919
}

tests/run-macros/quote-inline-function/quoted_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ object Macros {
1212
var i = $start
1313
val j = $end
1414
while (i < j) {
15-
${Expr.reduce(f)('i)}
15+
${Expr.betaReduce(f)('i)}
1616
i += 1
1717
}
1818
while {
19-
${Expr.reduce(f)('i)}
19+
${Expr.betaReduce(f)('i)}
2020
i += 1
2121
i < j
2222
} do ()

tests/run-macros/quote-matcher-symantics-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ object StringNum extends Symantics[String] {
7272
def value(x: Int)(given QuoteContext): Expr[String] = Expr(x.toString)
7373
def plus(x: Expr[String], y: Expr[String])(given QuoteContext): Expr[String] = '{ s"${$x} + ${$y}" } // '{ x + " + " + y }
7474
def times(x: Expr[String], y: Expr[String])(given QuoteContext): Expr[String] = '{ s"${$x} * ${$y}" }
75-
def app(f: Expr[String => String], x: Expr[String])(given QuoteContext): Expr[String] = Expr.reduce(f)(x)
75+
def app(f: Expr[String => String], x: Expr[String])(given QuoteContext): Expr[String] = Expr.betaReduce(f)(x)
7676
def lam(body: Expr[String] => Expr[String])(given QuoteContext): Expr[String => String] = '{ (x: String) => ${body('x)} }
7777
}
7878

0 commit comments

Comments
 (0)