Skip to content

Remove scala.quoted.autolift implicit conversion #9304

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
merged 1 commit into from
Jul 7, 2020
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
7 changes: 2 additions & 5 deletions docs/docs/reference/metaprogramming/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,6 @@ def showExpr[T](expr: Expr[T])(using QuoteContext): Expr[String] = {
That is, the `showExpr` method converts its `Expr` argument to a string (`code`), and lifts
the result back to an `Expr[String]` using `Expr.apply`.

**Note**: Lifting `String` to `Expr[String]` using `Expr(code)` can be omitted by importing an implicit
conversion with `import scala.quoted.autolift`. The programmer is able to
declutter slightly the code at the cost of readable _phase distinction_ between
stages.

### Lifting Types

Expand Down Expand Up @@ -376,7 +372,8 @@ object Macros {
${ assertImpl('expr) }

def assertImpl(expr: Expr[Boolean])(using QuoteContext) =
'{ if !($expr) then throw new AssertionError("failed assertion: " + ${expr.show}) } // autolift is applied
val failMsg: Expr[String] = Expr("failed assertion: " + expr.show)
'{ if !($expr) then throw new AssertionError($failMsg) }
}

object App {
Expand Down
4 changes: 0 additions & 4 deletions library/src-bootstrapped/scala/quoted/autolift.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.quoted.autolift

object Macros {

Expand Down
1 change: 0 additions & 1 deletion tests/disabled/run/xml-interpolation-3/XmlQuote_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.quoted.autolift

import scala.language.implicitConversions

Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i6432/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import scala.quoted._
import scala.quoted.autolift


object Macro {
Expand Down
1 change: 0 additions & 1 deletion tests/neg-macros/i6432b/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import scala.quoted._
import scala.quoted.autolift


object Macro {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import scala.quoted._
import scala.quoted.autolift


object E {
Expand All @@ -27,7 +26,7 @@ trait E[T] {
}

case class I(n: Int) extends E[Int] {
def lift (using QuoteContext): Expr[Int] = n
def lift (using QuoteContext): Expr[Int] = Expr(n)
}

case class Plus[T](x: E[T], y: E[T])(implicit op: Plus2[T]) extends E[T] {
Expand Down
45 changes: 22 additions & 23 deletions tests/neg-macros/inline-tuples-1/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@

import scala.quoted._
import scala.quoted.autolift

object Macros {
def tup1(tup: Expr[Tuple1[Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup2(tup: Expr[Tuple2[Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup3(tup: Expr[Tuple3[Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup4(tup: Expr[Tuple4[Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup5(tup: Expr[Tuple5[Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup6(tup: Expr[Tuple6[Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup7(tup: Expr[Tuple7[Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup8(tup: Expr[Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup9(tup: Expr[Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup10(tup: Expr[Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup11(tup: Expr[Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup12(tup: Expr[Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup13(tup: Expr[Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup14(tup: Expr[Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup15(tup: Expr[Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup16(tup: Expr[Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup17(tup: Expr[Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup18(tup: Expr[Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup19(tup: Expr[Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup20(tup: Expr[Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup21(tup: Expr[Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup22(tup: Expr[Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup1(tup: Expr[Tuple1[Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup2(tup: Expr[Tuple2[Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup3(tup: Expr[Tuple3[Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup4(tup: Expr[Tuple4[Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup5(tup: Expr[Tuple5[Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup6(tup: Expr[Tuple6[Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup7(tup: Expr[Tuple7[Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup8(tup: Expr[Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup9(tup: Expr[Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup10(tup: Expr[Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup11(tup: Expr[Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup12(tup: Expr[Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup13(tup: Expr[Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup14(tup: Expr[Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup15(tup: Expr[Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup16(tup: Expr[Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup17(tup: Expr[Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup18(tup: Expr[Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup19(tup: Expr[Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup20(tup: Expr[Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup21(tup: Expr[Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
def tup22(tup: Expr[Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = Expr(tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum)
}
3 changes: 1 addition & 2 deletions tests/neg-macros/quote-interpolator-core-old.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.quoted.autolift

// This test checks the correct interpretation of the inlined value class

Expand All @@ -18,7 +17,7 @@ object FInterpolation {
}

def fInterpolation(sc: StringContext, args: Seq[Expr[Any]])(using QuoteContext): Expr[String] = {
val str: Expr[String] = sc.parts.mkString("")
val str: Expr[String] = Expr(sc.parts.mkString(""))
val args1: Expr[Seq[Any]] = liftSeq(args)
'{ $str.format($args1: _*) }
}
Expand Down
7 changes: 3 additions & 4 deletions tests/neg-macros/quote-macro-splice.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import scala.quoted._
import scala.quoted.autolift

object Test {

inline def foo1: Int = { // error
println()
${ impl(1) }
${ impl('{1}) }
}

inline def foo2: Int = { // error
${ impl(1) }
${ impl(2) }
${ impl('{1}) }
${ impl('{2}) }
}

inline def foo3: Int = { // error
Expand Down
3 changes: 1 addition & 2 deletions tests/neg-macros/splice-in-top-level-splice-1.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import scala.quoted._
import scala.quoted.autolift

object Foo {
inline def foo(): Int = ${bar(${x})} // error
def x(using QuoteContext): Expr[Int] = '{1}
def bar(i: Int)(using QuoteContext): Expr[Int] = i
def bar(i: Int)(using QuoteContext): Expr[Int] = Expr(i)
}
3 changes: 1 addition & 2 deletions tests/neg-staging/quote-run-in-macro-1/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import scala.quoted._
import scala.quoted.staging._
import scala.quoted.autolift

object Macros {

given Toolbox = Toolbox.make(getClass.getClassLoader)
inline def foo(i: => Int): Int = ${ fooImpl('i) }
def fooImpl(i: Expr[Int])(using QuoteContext): Expr[Int] = {
val y: Int = run(i)
y
Expr(y)
}
}
1 change: 0 additions & 1 deletion tests/pending/run/tasty-comments/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.quoted.autolift


object Macros {
Expand Down
3 changes: 1 addition & 2 deletions tests/pos-macros/i6803b/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package blah

import scala.language.implicitConversions
import scala.quoted._
import scala.quoted.autolift

object AsObject {
final class LineNo(val lineNo: Int)
Expand All @@ -11,7 +10,7 @@ object AsObject {
inline given x as LineNo = ${impl}
private def impl(using qctx: QuoteContext) : Expr[LineNo] = {
import qctx.tasty._
'{unsafe(${rootPosition.startLine})}
'{unsafe(${Expr(rootPosition.startLine)})}
}
}
}
1 change: 0 additions & 1 deletion tests/pos-macros/quote-nested-object/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import scala.quoted._
import scala.quoted.autolift

object Macro {

Expand Down
3 changes: 1 addition & 2 deletions tests/pos-staging/quote-0.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import scala.quoted._
import scala.quoted.staging._
import scala.quoted.autolift

object Macros {

Expand All @@ -12,7 +11,7 @@ object Macros {
'{ if !($expr) then throw new AssertionError(s"failed assertion: ${${showExpr(expr)}}") }


def showExpr[T](expr: Expr[T])(using QuoteContext): Expr[String] = expr.toString
def showExpr[T](expr: Expr[T])(using QuoteContext): Expr[String] = Expr(expr.toString)

inline def power(inline n: Int, x: Double) = ${ powerCode('n, 'x) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.quoted.autolift

object Foo {

Expand All @@ -9,8 +8,8 @@ object Foo {
def inspectBodyImpl(x: Expr[Int])(using qctx: QuoteContext) : Expr[String] = {
import qctx.tasty._
x.unseal match {
case Inlined(None, Nil, arg) => arg.symbol.tree.showExtractors
case arg => arg.symbol.tree.showExtractors // TODO should all by name parameters be in an inline node?
case Inlined(None, Nil, arg) => Expr(arg.symbol.tree.showExtractors)
case arg => Expr(arg.symbol.tree.showExtractors) // TODO should all by name parameters be in an inline node?
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.quoted.autolift

object Foo {

Expand All @@ -9,8 +8,8 @@ object Foo {
def inspectBodyImpl(x: Expr[Int])(using qctx: QuoteContext) : Expr[String] = {
import qctx.tasty._
x.unseal match {
case Inlined(None, Nil, arg) => arg.symbol.tree.showExtractors
case arg => arg.symbol.tree.showExtractors // TODO should all by name parameters be in an inline node?
case Inlined(None, Nil, arg) => Expr(arg.symbol.tree.showExtractors)
case arg => Expr(arg.symbol.tree.showExtractors) // TODO should all by name parameters be in an inline node?
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.quoted.autolift

object Macros {

Expand All @@ -15,7 +14,7 @@ object Macros {

val tree = x.unseal
output.traverseTree(tree)
'{print(${buff.result()})}
'{print(${Expr(buff.result())})}
}

class MyTraverser[R <: scala.tasty.Reflection & Singleton](val reflect: R)(buff: StringBuilder) extends scala.tasty.reflect.TreeTraverser {
Expand Down
5 changes: 2 additions & 3 deletions tests/run-macros/f-interpolation-1/FQuote_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.quoted.autolift

import scala.language.implicitConversions

Expand Down Expand Up @@ -48,12 +47,12 @@ object FQuote {

for ((arg, part) <- allArgs.zip(parts.tail)) {
if (part.startsWith("%d") && !(arg.tpe <:< defn.IntType)) {
return '{s"`${${arg.show}}` is not of type Int"}
return '{s"`${${Expr(arg.show)}}` is not of type Int"}
}

}

val string = parts.mkString("")
'{ new collection.immutable.StringOps(${string}).format($args: _*) }
'{ new collection.immutable.StringOps(${Expr(string)}).format($args: _*) }
}
}
11 changes: 5 additions & 6 deletions tests/run-macros/f-interpolator-neg/Macros_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.quoted.autolift


import scala.language.implicitConversions
Expand Down Expand Up @@ -33,25 +32,25 @@ object Macro {
private[this] var oldReported = false
def partError(message : String, index : Int, offset : Int) : Unit = {
reported = true
errors += '{ Tuple5(true, 0, $index, $offset, $message) }
errors += '{ Tuple5(true, 0, ${Expr(index)}, ${Expr(offset)}, ${Expr(message)}) }
Copy link
Contributor

@liufengyun liufengyun Jul 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For such use cases, it seems we lose a little usability here.

However, from my experience with Scala 3 macros, it is always good to be explicit, as it is so easy to make mistakes and write difficult to understand code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the verbosity in only there because I made sure to not change the semantics in the tests.
Seen this one would immediately try to make it shorter and the natural way would be to write:

errors += Expr(Tuple5(true, 0, index, offset, message))

}
def partWarning(message : String, index : Int, offset : Int) : Unit = {
reported = true
errors += '{ Tuple5(false, 0, $index, $offset, $message) }
errors += '{ Tuple5(false, 0, ${Expr(index)}, ${Expr(offset)}, ${Expr(message)}) }
}

def argError(message : String, index : Int) : Unit = {
reported = true
errors += '{ Tuple5(true, 1, $index, 0, $message) }
errors += '{ Tuple5(true, 1, ${Expr(index)}, 0, ${Expr(message)}) }
}

def strCtxError(message : String) : Unit = {
reported = true
errors += '{ Tuple5(true, 2, -1, 0, $message) }
errors += '{ Tuple5(true, 2, -1, 0, ${Expr(message)}) }
}
def argsError(message : String) : Unit = {
reported = true
errors += '{ Tuple5(true, 3, -1, 0, $message) }
errors += '{ Tuple5(true, 3, -1, 0, ${Expr(message)}) }
}

def hasReported() : Boolean = {
Expand Down
7 changes: 3 additions & 4 deletions tests/run-macros/i4734/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import scala.annotation.tailrec
import scala.quoted._
import scala.quoted.autolift

object Macros {
inline def unrolledForeach(seq: IndexedSeq[Int], f: => Int => Unit, inline unrollSize: Int): Unit = // or f: Int => Unit
Expand All @@ -11,17 +10,17 @@ object Macros {

def unrolledForeachImpl(seq: Expr[IndexedSeq[Int]], f: Expr[Int => Unit], unrollSize: Int)(using QuoteContext): Expr[Unit] = '{
val size = ($seq).length
assert(size % (${unrollSize}) == 0) // for simplicity of the implementation
assert(size % (${Expr(unrollSize)}) == 0) // for simplicity of the implementation
var i = 0
while (i < size) {
${
for (j <- new UnrolledRange(0, unrollSize)) '{
val index = i + $j
val index = i + ${Expr(j)}
val element = ($seq)(index)
${ Expr.betaReduce(f)('element) } // or `($f)(element)` if `f` should not be inlined
}
}
i += ${unrollSize}
i += ${Expr(unrollSize)}
}

}
Expand Down
3 changes: 1 addition & 2 deletions tests/run-macros/i4735/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.annotation.tailrec
import scala.quoted.autolift

import scala.quoted._

Expand All @@ -16,7 +15,7 @@ object Macro {
println("<log> start loop")
${
for (j <- new UnrolledRange(0, unrollSize.unliftOrError)) '{
val element = ($seq)(i + ${j})
val element = ($seq)(i + ${Expr(j)})
${Expr.betaReduce(f)('element)} // or `($f)(element)` if `f` should not be inlined
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/run-macros/i5119/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import scala.quoted._
import scala.quoted.autolift

object Macro {
class StringContextOps(sc: => StringContext) {
Expand All @@ -8,6 +7,6 @@ object Macro {
implicit inline def XmlQuote(inline sc: StringContext): StringContextOps = new StringContextOps(sc)
def impl(sc: Expr[StringContext], args: Expr[Seq[Any]])(using qctx: QuoteContext) : Expr[String] = {
import qctx.tasty._
(sc.unseal.underlyingArgument.showExtractors + "\n" + args.unseal.underlyingArgument.showExtractors)
Expr(sc.unseal.underlyingArgument.showExtractors + "\n" + args.unseal.underlyingArgument.showExtractors)
}
}
Loading