Skip to content

Commit 5d46d33

Browse files
committed
Remove asTree
1 parent 53f0bcc commit 5d46d33

File tree

29 files changed

+35
-44
lines changed

29 files changed

+35
-44
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
8080
object reflect extends reflectModule:
8181

8282
extension (expr: Expr[Any]):
83-
def asTree: Tree = expr.asTerm
8483
def asTerm: Term =
8584
val exprImpl = expr.asInstanceOf[ExprImpl]
8685
exprImpl.checkScopeId(QuotesImpl.this.hashCode)

library/src/scala/quoted/Quotes.scala

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
7979
* import scala.quoted._
8080
* def f(expr: Expr[Int])(using Quotes) =
8181
* import quotes.reflect._
82-
* val ast: Term = expr.asTerm // or `expr.asTree`
82+
* val ast: Term = expr.asTerm
8383
* ...
8484
* ```
8585
*
@@ -204,18 +204,10 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
204204
*/
205205
trait reflectModule { self: reflect.type =>
206206

207-
extension (expr: Expr[Any]):
208-
209-
/** Returns the `Tree` representation this expression.
210-
* Same as `asTerm` but typed as a `Tree`.
211-
*/
212-
def asTree: Tree
213-
214-
/** Returns the `Term` representation this expression */
207+
/** Returns the `Term` representation this expression */
208+
extension (expr: Expr[Any])
215209
def asTerm: Term
216210

217-
end extension
218-
219211
///////////////
220212
// TREES //
221213
///////////////
@@ -229,8 +221,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
229221
/** Methods of the module object `val Tree` */
230222
trait TreeModule { this: Tree.type =>
231223
/** Returns the Term representation this expression */
232-
@deprecated("Use `expr.asTree` instead (must `import quotes.reflect._`). This will be removed in 3.0.0-RC1", "3.0.0-M3")
233-
def of(expr: Expr[Any]): Tree = expr.asTree
224+
@deprecated("Use `expr.asTerm` instead (must `import quotes.reflect._`). This will be removed in 3.0.0-RC1", "3.0.0-M3")
225+
def of(expr: Expr[Any]): Tree = expr.asTerm
234226
}
235227

236228
/** Makes extension methods on `Tree` available without any imports */

tests/neg-macros/i6432/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Macro {
1010
sc match {
1111
case '{ StringContext(${Varargs(parts)}: _*) } =>
1212
for (part @ Const(s) <- parts)
13-
report.error(s, part.asTree.pos)
13+
report.error(s, part.asTerm.pos)
1414
}
1515
'{}
1616
}

tests/neg-macros/i6432b/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Macro {
1010
sc match {
1111
case '{ StringContext(${Varargs(parts)}: _*) } =>
1212
for (part @ Const(s) <- parts)
13-
report.error(s, part.asTree.pos)
13+
report.error(s, part.asTerm.pos)
1414
}
1515
'{}
1616
}

tests/neg-macros/i6976/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ object macros {
77

88
def mcrImpl(body: Expr[Any])(using ctx: Quotes) : Expr[Any] = {
99
import ctx.reflect._
10-
body.asTree match { case Block(_, _) => '{2} }
10+
body.asTerm match { case Block(_, _) => '{2} }
1111
}
1212
}

tests/neg-macros/i7698.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ trait Show[T] {
66

77
def showInterpolatorImpl(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes): Expr[String] =
88
import quotes.reflect._
9-
argsExpr.asTree match
9+
argsExpr.asTerm match
1010
case '{ $arg: $t } => // error
1111
case '[ Int ] => // error
1212
???

tests/neg-macros/i9801/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def impl(prog: Expr[Double])(using Quotes) : Expr[Double] =
1616
triggerStackOverflow(0)
1717
} catch {
1818
case e =>
19-
quotes.reflect.report.error(e.getMessage, prog.asTree.pos)
19+
quotes.reflect.report.error(e.getMessage, prog.asTerm.pos)
2020
'{ 42.0 }
2121
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Asserts {
1515
def impl(cond: Expr[Boolean])(using Quotes) : Expr[Unit] = {
1616
import quotes.reflect._
1717

18-
val tree = cond.asTree
18+
val tree = cond.asTerm
1919

2020
def isOps(tpe: TypeRepr): Boolean = tpe match {
2121
case tpe: TermRef => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Asserts {
1515
def impl(cond: Expr[Boolean])(using Quotes) : Expr[Unit] = {
1616
import quotes.reflect._
1717

18-
val tree = cond.asTree
18+
val tree = cond.asTerm
1919

2020
def isOps(tpe: TypeRepr): Boolean = tpe match {
2121
case tpe: TermRef => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts

tests/pending/run/tasty-comments/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Macros {
99
def impl[T](x: Expr[T])(using Quotes) : Expr[Unit] = {
1010
import quotes.reflect._
1111

12-
val tree = x.asTree
12+
val tree = x.asTerm
1313
tree.symbol.comment.map(_.raw) match {
1414
case Some(str) => '{ println(${str}) }
1515
case None => '{ println() }

tests/pos-macros/i8325/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object A:
1313

1414
def transformImplExpr[A:Type](using Quotes)(expr: Expr[A]): Expr[A] = {
1515
import quotes.reflect._
16-
expr.asTree match {
16+
expr.asTerm match {
1717
case Inlined(x,y,z) => transformImplExpr(z.asExpr.asInstanceOf[Expr[A]])
1818
case Apply(fun,args) => '{ A.pure(${Apply(fun,args).asExpr.asInstanceOf[Expr[A]]}) }
1919
case other => expr

tests/pos-macros/i9251/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object Async {
2121
def checkPrintTypeImpl[F[_]:Type,T:Type](f: Expr[T])(using Quotes): Expr[Unit] =
2222
import quotes.reflect._
2323

24-
val fu = f.asTree
24+
val fu = f.asTerm
2525
fu match
2626
case Inlined(_,_,Block(_,Apply(TypeApply(Select(q,n),tparams),List(param)))) =>
2727
param.tpe match

tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Foo {
77

88
def inspectBodyImpl(x: Expr[Int])(using Quotes) : Expr[String] = {
99
import quotes.reflect._
10-
x.asTree match {
10+
x.asTerm match {
1111
case Inlined(None, Nil, arg) => Expr(arg.symbol.tree.showExtractors)
1212
case arg => Expr(arg.symbol.tree.showExtractors) // TODO should all by name parameters be in an inline node?
1313
}

tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Foo {
77

88
def inspectBodyImpl(x: Expr[Int])(using Quotes) : Expr[String] = {
99
import quotes.reflect._
10-
x.asTree match {
10+
x.asTerm match {
1111
case Inlined(None, Nil, arg) => Expr(arg.symbol.tree.showExtractors)
1212
case arg => Expr(arg.symbol.tree.showExtractors) // TODO should all by name parameters be in an inline node?
1313
}

tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Macros {
1212

1313
val output = myTraverser(buff)
1414

15-
val tree = x.asTree
15+
val tree = x.asTerm
1616
output.traverseTree(tree)(Symbol.spliceOwner)
1717
'{print(${Expr(buff.result())})}
1818
}

tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Foo {
1313
if sym.isClassDef || sym.isDefDef || sym.isValDef then Expr(sym.tree.showExtractors)
1414
else '{"NO DEFINTION"}
1515

16-
x.asTree match {
16+
x.asTerm match {
1717
case Inlined(None, Nil, arg) => definitionString(arg.symbol)
1818
case arg => definitionString(arg.symbol) // TODO should all by name parameters be in an inline node
1919
}

tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Foo {
1212
if sym.isClassDef || sym.isDefDef || sym.isValDef then Expr(sym.tree.showExtractors)
1313
else '{"NO DEFINTION"}
1414

15-
x.asTree match {
15+
x.asTerm match {
1616
case Inlined(None, Nil, arg) => definitionString(arg.symbol)
1717
case arg => definitionString(arg.symbol) // TODO should all by name parameters be in an inline node
1818
}

tests/run-macros/exports/Macro_2.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ private def visitExportsTreeMapImpl[T: Type](e: Expr[T], f: Expr[T => Any])(usin
1818

1919
private def visitExportsShowImpl[T: Type](e: Expr[T])(using Quotes): Expr[Any] =
2020
import quotes.reflect._
21-
'{println(${Expr(e.asTree.show)})}
21+
'{println(${Expr(e.asTerm.show)})}
2222

2323
private def visitExportsShowExtractImpl[T: Type](e: Expr[T])(using Quotes): Expr[Any] =
2424
import quotes.reflect._
25-
'{println(${Expr(e.asTree.showExtractors)})}
25+
'{println(${Expr(e.asTerm.showExtractors)})}
2626

2727
private object IdempotentExprMap extends ExprMap {
2828

@@ -43,7 +43,7 @@ private def traverseExportsImpl(e: Expr[Any], f: Expr[String => Any])(using Quot
4343
}
4444

4545
val res =
46-
ExportAccumulator.foldTree(mutable.Buffer.empty, e.asTree)(Symbol.spliceOwner).mkString(", ")
46+
ExportAccumulator.foldTree(mutable.Buffer.empty, e.asTerm)(Symbol.spliceOwner).mkString(", ")
4747

4848
'{ $f(${Expr(res)}) }
4949
}

tests/run-macros/i10011/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ inline def printPos[T](inline expr: T): (Int, Int) =
55

66
private def printPos[T](expr: Expr[T])(using Quotes): Expr[(Int, Int)] =
77
import quotes.reflect._
8-
val pos = expr.asTree.pos
8+
val pos = expr.asTerm.pos
99
Expr((pos.start, pos.end))

tests/run-macros/i5533/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object scalatest {
1010
def assertImpl(condition: Expr[Boolean])(using Quotes) : Expr[Unit] = {
1111
import quotes.reflect._
1212

13-
val tree = condition.asTree
13+
val tree = condition.asTerm
1414

1515
val expr = tree.asExprOf[Boolean]
1616

tests/run-macros/i5941/macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ object Lens {
4646
}
4747

4848
// exception: getter.asTerm.underlyingArgument
49-
getter.asTree match {
49+
getter.asTerm match {
5050
case Function(param :: Nil, Path(o, parts)) if o.symbol == param.symbol =>
5151
'{
5252
val setter = (t: T) => (s: S) => ${ setterBody('s.asTerm, 't.asTerm, parts).asExprOf[S] }

tests/run-macros/i6679/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def makeMatch[A: Type](head : Expr[A])(using qctx : Quotes) : Expr[Unit] = {
44
import quotes.reflect._
55

66
val sacrifice = '{ $head match { case _ => ??? } }
7-
sacrifice.asTree
7+
sacrifice.asTerm
88

99
'{ println("Ok") }
1010
}

tests/run-macros/i7887/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def myMacroImpl(a: quoted.Expr[_])(using qctx: quoted.Quotes) = {
44
implicit val t: quoted.Type[A] = a.asTerm.tpe.widen.asType.asInstanceOf[quoted.Type[A]]
55
'{
66
type T = A
7-
${a.asTree.asExprOf[T]}
7+
${a.asTerm.asExprOf[T]}
88
}
99
}
1010

tests/run-macros/paramSymss/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ inline def showParamSyms(inline x: Any): String =
66
def showParamSymsExpr(using Quotes)(x: Expr[Any]): Expr[String] =
77
import quotes.reflect._
88
val '{ $y: Any } = x // Drop Inlined not to access the symbol
9-
val sym = y.asTree.symbol
9+
val sym = y.asTerm.symbol
1010
Expr(
1111
s"""sym: ${sym.show}
1212
|paramSymss: ${sym.paramSymss.map(_.map(_.show))}

tests/run-macros/quote-matcher-runtime/quoted_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ object Macros {
1717
}
1818

1919
'{
20-
println("Scrutinee: " + ${Expr(a.asTree.show)})
21-
println("Pattern: " + ${Expr(b.asTree.show)})
20+
println("Scrutinee: " + ${Expr(a.asTerm.show)})
21+
println("Pattern: " + ${Expr(b.asTerm.show)})
2222
println("Result: " + ${Expr(res.toString)})
2323
println()
2424
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object Macros {
2121

2222
case _ =>
2323
import quotes.reflect._
24-
report.error("Expected explicit DSL", e.asTree.pos)
24+
report.error("Expected explicit DSL", e.asTerm.pos)
2525
'{ ??? }
2626

2727
}

tests/run-macros/reflect-sourceCode/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ object api {
66

77
private def reflImpl[T](x: Expr[T])(implicit qctx: Quotes): Expr[String] = {
88
import quotes.reflect._
9-
Expr(x.asTree.pos.sourceCode.get)
9+
Expr(x.asTerm.pos.sourceCode.get)
1010
}
1111
}

tests/run-macros/tasty-extractors-3/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object Macros {
2525
}
2626
}
2727

28-
val tree = x.asTree
28+
val tree = x.asTerm
2929
traverser.traverseTree(tree)(Symbol.spliceOwner)
3030
'{print(${Expr(buff.result())})}
3131
}

tests/run-macros/tasty-macro-assert/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Asserts {
1515
def impl(cond: Expr[Boolean])(using Quotes) : Expr[Unit] = {
1616
import quotes.reflect._
1717

18-
val tree = cond.asTree
18+
val tree = cond.asTerm
1919

2020
def isOps(tpe: TypeRepr): Boolean = tpe match {
2121
case tpe: TermRef => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts

0 commit comments

Comments
 (0)