From 031110befdb3a5e6268b96dbb5b438b33fbc2358 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 21 Jun 2019 13:49:57 +0200 Subject: [PATCH 1/2] Move tasty.Reflection in QuoteContext --- .../dotty/tools/dotc/core/Definitions.scala | 6 ++ .../dotc/transform/PCPCheckAndHeal.scala | 1 + .../dotty/tools/dotc/transform/Splicer.scala | 6 ++ .../dotty/tools/dotc/typer/Implicits.scala | 8 ++- .../src/dotty/tools/dotc/typer/Typer.scala | 2 +- .../metaprogramming/tasty-reflect.md | 28 +++++----- .../scala/internal/quoted/Matcher.scala | 8 +-- library/src-3.x/scala/quoted/Expr.scala | 4 +- .../src-3.x/scala/quoted/matching/Bind.scala | 6 +- .../src-3.x/scala/quoted/matching/Const.scala | 11 ++-- .../scala/quoted/matching/ConstSeq.scala | 9 +-- .../scala/quoted/matching/ExprSeq.scala | 11 ++-- .../dotty/internal/StringContextMacro.scala | 30 +++++----- .../scala/testing/typeChecks.scala | 6 +- .../dotty/internal/StringContextMacro.scala | 16 ++++++ .../scala/testing/typeChecks.scala | 4 ++ library/src/scala/quoted/QuoteContext.scala | 16 +++++- library/src/scala/tasty/Reflection.scala | 8 +-- tests/neg-macros/i6432/Macro_1.scala | 4 +- tests/neg-macros/i6432b/Macro_1.scala | 4 +- .../tasty-macro-assert-1/quoted_1.scala | 4 +- .../tasty-macro-assert-2/quoted_1.scala | 4 +- .../tasty-macro-error/quoted_1.scala | 4 +- .../tasty-macro-positions/quoted_1.scala | 4 +- .../Macro_1.scala | 4 +- .../Macro_1.scala | 4 +- tests/neg-with-compiler/i5941/macro_1.scala | 4 +- tests/neg/quotedPatterns-1.scala | 2 +- tests/neg/quotedPatterns-2.scala | 2 +- tests/neg/quotedPatterns-3.scala | 2 +- tests/neg/quotedPatterns-4.scala | 4 +- tests/patmat/i6255.scala | 2 +- tests/patmat/i6255b.scala | 2 +- .../pending/run/tasty-comments/quoted_1.scala | 4 +- tests/pos-macros/i6171/Macro_1.scala | 4 +- tests/pos-macros/i6535/Macro_1.scala | 4 +- .../tasty-constant-type/Macro_1.scala | 4 +- tests/pos/i6214.scala | 2 +- tests/pos/i6214b.scala | 2 +- tests/pos/i6253.scala | 2 +- tests/pos/i6435.scala | 2 +- tests/pos/quotedPatterns.scala | 2 +- .../tasty-definitions-2/Macro_1.scala | 4 +- .../tasty-definitions-3/Macro_1.scala | 4 +- .../tasty-extractors-owners/quoted_1.scala | 4 +- .../tasty-load-tree-1/quoted_1.scala | 4 +- .../tasty-load-tree-2/quoted_1.scala | 4 +- .../f-interpolation-1/FQuote_1.scala | 4 +- .../f-interpolator-neg/Macros_1.scala | 5 +- .../Macro_1.scala | 56 +++++++++---------- tests/run-macros/i4515b/Macro_1.scala | 4 +- tests/run-macros/i5119/Macro_1.scala | 4 +- tests/run-macros/i5119b/Macro_1.scala | 4 +- tests/run-macros/i5533/Macro_1.scala | 4 +- tests/run-macros/i5533b/Macro_1.scala | 4 +- tests/run-macros/i5536/Macro_1.scala | 4 +- tests/run-macros/i5629/Macro_1.scala | 10 ++-- tests/run-macros/i5715/Macro_1.scala | 4 +- tests/run-macros/i5941/macro_1.scala | 18 +++--- tests/run-macros/i6171/Macro_1.scala | 4 +- tests/run-macros/i6253-b/quoted_1.scala | 2 +- tests/run-macros/i6253/quoted_1.scala | 2 +- tests/run-macros/i6518/Macro_1.scala | 4 +- .../inferred-repeated-result/test_1.scala | 4 +- .../quote-impure-by-name/quoted_1.scala | 3 +- .../quote-inline-function/quoted_1.scala | 4 +- .../quote-matcher-runtime/quoted_1.scala | 6 +- .../quoted_1.scala | 2 +- .../quoted_1.scala | 2 +- .../quoted_1.scala | 2 +- .../quote-matcher-symantics-1/quoted_1.scala | 4 +- .../quote-matcher-symantics-2/quoted_1.scala | 8 +-- .../quoted-expr-block/quoted_1.scala | 2 +- tests/run-macros/reflect-dsl/assert_1.scala | 4 +- .../reflect-isFunctionType/macro_1.scala | 16 +++--- .../run-macros/reflect-pos-fun/assert_1.scala | 4 +- .../reflect-select-constructor/assert_1.scala | 4 +- .../reflect-select-copy/assert_1.scala | 4 +- .../reflect-select-copy/assert_1.scala | 4 +- .../assert_1.scala | 4 +- .../reflect-select-value-class/assert_1.scala | 4 +- .../reflect-typeChecks/assert_1.scala | 4 +- .../tasty-argument-tree-1/quoted_1.scala | 4 +- .../tasty-custom-show/quoted_1.scala | 10 ++-- tests/run-macros/tasty-dealias/quoted_1.scala | 4 +- .../tasty-definitions-1/quoted_1.scala | 4 +- tests/run-macros/tasty-eval/quoted_1.scala | 10 ++-- .../tasty-extractors-1/quoted_1.scala | 4 +- .../tasty-extractors-2/quoted_1.scala | 4 +- .../tasty-extractors-3/quoted_1.scala | 4 +- .../quoted_1.scala | 2 +- .../tasty-extractors-types/quoted_1.scala | 4 +- .../Macro_1.scala | 10 ++-- tests/run-macros/tasty-getfile/Macro_1.scala | 4 +- .../Macro_1.scala | 6 +- .../tasty-indexed-map/quoted_1.scala | 4 +- .../tasty-interpolation-1/Macro.scala | 20 +++---- .../tasty-linenumber-2/quoted_1.scala | 4 +- .../tasty-linenumber/quoted_1.scala | 4 +- .../run-macros/tasty-location/quoted_1.scala | 4 +- .../tasty-macro-assert/quoted_1.scala | 4 +- .../tasty-macro-const/quoted_1.scala | 4 +- .../tasty-macro-positions/quoted_1.scala | 16 +++--- .../tasty-original-source/Macros_1.scala | 4 +- .../tasty-positioned/quoted_1.scala | 6 +- .../tasty-seal-method/quoted_1.scala | 8 +-- .../Macros_1.scala | 11 ++-- .../run-macros/tasty-subtyping/quoted_1.scala | 8 +-- .../run-macros/tasty-tree-map/quoted_1.scala | 4 +- tests/run-macros/tasty-typeof/Macro_1.scala | 4 +- tests/run-macros/type-show/Macro_1.scala | 4 +- .../xml-interpolation-1/XmlQuote_1.scala | 4 +- .../xml-interpolation-2/XmlQuote_1.scala | 5 +- tests/run-with-compiler/i6201/macro_1.scala | 4 +- tests/run-with-compiler/i6270/Macro_1.scala | 8 +-- .../reflect-inline/assert_1.scala | 9 ++- .../staged-tuples/StagedTuple.scala | 2 +- .../quoted_1.scala | 4 +- .../tasty-unsafe-let/quoted_1.scala | 6 +- 119 files changed, 368 insertions(+), 347 deletions(-) rename library/{src-3.x => src-bootstrapped}/dotty/internal/StringContextMacro.scala (97%) rename library/{src-3.x => src-bootstrapped}/scala/testing/typeChecks.scala (53%) create mode 100644 library/src-non-bootstrapped/dotty/internal/StringContextMacro.scala create mode 100644 library/src-non-bootstrapped/scala/testing/typeChecks.scala diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index f0d6177e09b0..b4f79426b813 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -762,6 +762,12 @@ class Definitions { @threadUnsafe lazy val QuotedExprType: TypeRef = ctx.requiredClassRef("scala.quoted.Expr") def QuotedExprClass(implicit ctx: Context): ClassSymbol = QuotedExprType.symbol.asClass + @threadUnsafe lazy val QuoteContextType: TypeRef = ctx.requiredClassRef("scala.quoted.QuoteContext") + def QuoteContextClass(implicit ctx: Context): ClassSymbol = QuoteContextType.symbol.asClass + + @threadUnsafe lazy val QuoteContextModule: TermSymbol = ctx.requiredModule("scala.quoted.QuoteContext") + @threadUnsafe lazy val QuoteContext_macroContext: TermSymbol = QuoteContextModule.requiredMethod("macroContext") + @threadUnsafe lazy val InternalQuotedModuleRef: TermRef = ctx.requiredModuleRef("scala.internal.Quoted") def InternalQuotedModule: Symbol = InternalQuotedModuleRef.symbol @threadUnsafe lazy val InternalQuoted_exprQuoteR: TermRef = InternalQuotedModule.requiredMethodRef("exprQuote") diff --git a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala index 1dec5e16b95e..342b8f844fe5 100644 --- a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala +++ b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala @@ -166,6 +166,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( l == level || level == -1 && ( sym == defn.TastyReflection_macroContext || + sym == defn.QuoteContext_macroContext || // here we assume that Splicer.canBeSpliced was true before going to level -1, // this implies that all non-inline arguments are quoted and that the following two cases are checked // on inline parameters or type parameters. diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index 291054059ddf..600f9c5063e6 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -114,6 +114,8 @@ object Splicer { args.toSeq protected def interpretTastyContext()(implicit env: Env): Object = ReflectionImpl(ctx, pos) + protected def interpretQuoteContext()(implicit env: Env): Object = + new scala.quoted.QuoteContext(ReflectionImpl(ctx, pos)) protected def interpretStaticMethodCall(moduleClass: Symbol, fn: Symbol, args: => List[Object])(implicit env: Env): Object = { val (inst, clazz) = @@ -308,6 +310,7 @@ object Splicer { protected def interpretLiteral(value: Any)(implicit env: Env): Result protected def interpretVarargs(args: List[Result])(implicit env: Env): Result protected def interpretTastyContext()(implicit env: Env): Result + protected def interpretQuoteContext()(implicit env: Env): Result protected def interpretStaticMethodCall(module: Symbol, fn: Symbol, args: => List[Result])(implicit env: Env): Result protected def interpretModuleAccess(fn: Symbol)(implicit env: Env): Result protected def interpretNew(fn: Symbol, args: => List[Result])(implicit env: Env): Result @@ -333,6 +336,9 @@ object Splicer { case _ if tree.symbol == defn.TastyReflection_macroContext => interpretTastyContext() + case _ if tree.symbol == defn.QuoteContext_macroContext => + interpretQuoteContext() + case Call(fn, args) => if (fn.symbol.isConstructor && fn.symbol.owner.owner.is(Package)) { interpretNew(fn.symbol, args.map(interpretTree)) diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index a34379260c0d..42caa2a3f7e8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -707,6 +707,11 @@ trait Implicits { self: Typer => if (ctx.inInlineMethod || enclosingInlineds.nonEmpty) ref(defn.TastyReflection_macroContext) else EmptyTree + lazy val synthesizedQuoteContext: SpecialHandler = + (formal, span) => implicit ctx => + if (ctx.inInlineMethod || enclosingInlineds.nonEmpty) ref(defn.QuoteContext_macroContext) + else EmptyTree + lazy val synthesizedTupleFunction: SpecialHandler = (formal, span) => implicit ctx => formal match { case AppliedType(_, funArgs @ fun :: tupled :: Nil) => @@ -1033,9 +1038,10 @@ trait Implicits { self: Typer => mySpecialHandlers = List( defn.ClassTagClass -> synthesizedClassTag, defn.QuotedTypeClass -> synthesizedTypeTag, + defn.QuoteContextClass -> synthesizedQuoteContext, defn.TastyReflectionClass -> synthesizedTastyContext, defn.EqlClass -> synthesizedEq, - defn.TupledFunctionClass -> synthesizedTupleFunction, + defn.TupledFunctionClass -> synthesizedTupleFunction, defn.ValueOfClass -> synthesizedValueOf, defn.Mirror_ProductClass -> synthesizedProductMirror, defn.Mirror_SumClass -> synthesizedSumMirror, diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 5f84d83c33ea..3bedadb255c8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1978,7 +1978,7 @@ class Typer extends Namer fun = ref(defn.InternalQuotedMatcher_unapplyR).appliedToType(patType), implicits = ref(defn.InternalQuoted_exprQuoteR).appliedToType(shape.tpe).appliedTo(shape) :: - implicitArgTree(defn.TastyReflectionType, tree.span) :: Nil, + implicitArgTree(defn.QuoteContextType, tree.span) :: Nil, patterns = splicePat :: Nil, proto = pt) } diff --git a/docs/docs/reference/metaprogramming/tasty-reflect.md b/docs/docs/reference/metaprogramming/tasty-reflect.md index b303462e7f0b..cf9207f2d5a4 100644 --- a/docs/docs/reference/metaprogramming/tasty-reflect.md +++ b/docs/docs/reference/metaprogramming/tasty-reflect.md @@ -20,7 +20,7 @@ guarantees and may fail at macro expansion time, hence additional explicit checks must be done. To provide reflection capabilities in macros we need to add an implicit -parameter of type `scala.tasty.Reflection` and import it in the scope where it +parameter of type `scala.quoted.QuoteContext` and import `tasty._` from it in the scope where it is used. ```scala @@ -29,23 +29,23 @@ import scala.tasty._ inline def natConst(x: => Int): Int = ${natConstImpl('{x})} -def natConstImpl(x: Expr[Int])(implicit reflection: Reflection): Expr[Int] = { - import reflection._ +def natConstImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[Int] = { + import qctx.tasty._ ... } ``` ### Sealing and Unsealing -`import reflection._` will provide an `unseal` extension method on `quoted.Expr` -and `quoted.Type` which returns a `reflection.Term` that represents the tree of -the expression and `reflection.TypeTree` that represents the tree of the type +`import qctx.tasty._` will provide an `unseal` extension method on `quoted.Expr` +and `quoted.Type` which returns a `qctx.tasty.Term` that represents the tree of +the expression and `qctx.tasty.TypeTree` that represents the tree of the type respectively. It will also import all extractors and methods on TASTy Reflect trees. For example the `Literal(_)` extractor used below. ```scala -def natConstImpl(x: Expr[Int])(implicit reflection: Reflection): Expr[Int] = { - import reflection._ +def natConstImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[Int] = { + import qctx.tasty._ val xTree: Term = x.unseal xTree match { case Term.Literal(Constant.Int(n)) => @@ -58,10 +58,10 @@ def natConstImpl(x: Expr[Int])(implicit reflection: Reflection): Expr[Int] = { } ``` -To easily know which extractors are needed, the `reflection.Term.show` method +To easily know which extractors are needed, the `qctx.tasty.Term.show` method returns the string representation of the extractors. -The method `reflection.Term.seal[T]` provides a way to go back to a +The method `qctx.tasty.Term.seal[T]` provides a way to go back to a `quoted.Expr[Any]`. Note that the type is `Expr[Any]`. Consequently, the type must be set explicitly with a checked `cast` call. If the type does not conform to it an exception will be thrown. In the code above, we could have replaced @@ -77,8 +77,8 @@ operation expression passed while calling the `macro` below. ```scala inline def macro(param: => Boolean): Unit = ${ macroImpl('param) } -def macroImpl(param: Expr[Boolean])(implicit refl: Reflection): Expr[Unit] = { - import refl._ +def macroImpl(param: Expr[Boolean]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ import util._ param.unseal.underlyingArgument match { @@ -99,8 +99,8 @@ such as the start line, the end line or even the source code at the expansion point. ```scala -def macroImpl()(reflect: Reflection): Expr[Unit] = { - import reflect.{Position => _, _} +def macroImpl()(qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val pos = rootPosition val path = pos.sourceFile.jpath.toString diff --git a/library/src-3.x/scala/internal/quoted/Matcher.scala b/library/src-3.x/scala/internal/quoted/Matcher.scala index 161127851a83..383779742151 100644 --- a/library/src-3.x/scala/internal/quoted/Matcher.scala +++ b/library/src-3.x/scala/internal/quoted/Matcher.scala @@ -4,7 +4,6 @@ import scala.annotation.internal.sharable import scala.quoted._ import scala.quoted.matching.Bind -import scala.tasty._ object Matcher { @@ -27,12 +26,11 @@ object Matcher { * * @param scrutineeExpr `Expr[_]` on which we are pattern matching * @param patternExpr `Expr[_]` containing the pattern tree - * @param reflection instance of the reflection API (implicitly provided by the macro) + * @param qctx the current QuoteContext * @return None if it did not match, `Some(tup)` if it matched where `tup` contains `Expr[Ti]`` */ - def unapply[Tup <: Tuple](scrutineeExpr: Expr[_])(implicit patternExpr: Expr[_], reflection: Reflection): Option[Tup] = { - // TODO improve performance - import reflection.{Bind => BindPattern, _} + def unapply[Tup <: Tuple](scrutineeExpr: Expr[_])(implicit patternExpr: Expr[_], qctx: QuoteContext): Option[Tup] = { + import qctx.tasty.{Bind => BindPattern, _} import Matching._ type Env = Set[(Symbol, Symbol)] diff --git a/library/src-3.x/scala/quoted/Expr.scala b/library/src-3.x/scala/quoted/Expr.scala index f4b158ff76f0..6f5472ad129a 100644 --- a/library/src-3.x/scala/quoted/Expr.scala +++ b/library/src-3.x/scala/quoted/Expr.scala @@ -48,8 +48,8 @@ package quoted { * Given list of statements `s1 :: s2 :: ... :: Nil` and an expression `e` the resulting expression * will be equivalent to `'{ $s1; $s2; ...; $e }`. */ - def block[T](statements: List[Expr[_]], expr: Expr[T])(implicit refl: tasty.Reflection): Expr[T] = { - import refl._ + def block[T](statements: List[Expr[_]], expr: Expr[T])(implicit qctx: QuoteContext): Expr[T] = { + import qctx.tasty._ Block(statements.map(_.unseal), expr.unseal).seal.asInstanceOf[Expr[T]] } diff --git a/library/src-3.x/scala/quoted/matching/Bind.scala b/library/src-3.x/scala/quoted/matching/Bind.scala index d36b8b24f0de..024810a8b8b4 100644 --- a/library/src-3.x/scala/quoted/matching/Bind.scala +++ b/library/src-3.x/scala/quoted/matching/Bind.scala @@ -1,8 +1,6 @@ package scala.quoted package matching -import scala.tasty.Reflection // TODO do not depend on reflection directly - /** Bind of an Expr[T] used to know if some Expr[T] is a reference to the binding * * @param name string name of this binding @@ -21,8 +19,8 @@ class Bind[T <: AnyKind] private[scala](val name: String, private[Bind] val id: object Bind { - def unapply[T](expr: Expr[T])(implicit reflect: Reflection): Option[Bind[T]] = { - import reflect.{Bind => BindPattern, _} + def unapply[T](expr: Expr[T]) given (qctx: QuoteContext): Option[Bind[T]] = { + import qctx.tasty.{Bind => BindPattern, _} expr.unseal match { case IsIdent(ref) => val sym = ref.symbol diff --git a/library/src-3.x/scala/quoted/matching/Const.scala b/library/src-3.x/scala/quoted/matching/Const.scala index 87371217a025..1680ce396d0f 100644 --- a/library/src-3.x/scala/quoted/matching/Const.scala +++ b/library/src-3.x/scala/quoted/matching/Const.scala @@ -1,8 +1,5 @@ -package scala.quoted.matching - -import scala.quoted.Expr - -import scala.tasty.Reflection // TODO do not depend on reflection directly +package scala.quoted +package matching /** Matches expressions containing literal constant values and extracts the value. * It may match expressions of type Boolean, Byte, Short, Int, Long, @@ -17,8 +14,8 @@ import scala.tasty.Reflection // TODO do not depend on reflection directly */ object Const { - def unapply[T](expr: Expr[T])(implicit reflect: Reflection): Option[T] = { - import reflect._ + def unapply[T](expr: Expr[T]) given (qctx: QuoteContext): Option[T] = { + import qctx.tasty._ def rec(tree: Term): Option[T] = tree match { case Literal(c) => Some(c.value.asInstanceOf[T]) case Block(Nil, e) => rec(e) diff --git a/library/src-3.x/scala/quoted/matching/ConstSeq.scala b/library/src-3.x/scala/quoted/matching/ConstSeq.scala index 8e337cc531bf..1d343e8bee61 100644 --- a/library/src-3.x/scala/quoted/matching/ConstSeq.scala +++ b/library/src-3.x/scala/quoted/matching/ConstSeq.scala @@ -1,14 +1,11 @@ -package scala.quoted.matching - -import scala.quoted.Expr - -import scala.tasty.Reflection // TODO do not depend on reflection directly +package scala.quoted +package matching /** Literal sequence of literal constant value expressions */ object ConstSeq { /** Matches literal sequence of literal constant value expressions */ - def unapply[T](expr: Expr[Seq[T]]) given Reflection: Option[Seq[T]] = expr match { + def unapply[T](expr: Expr[Seq[T]]) given (qctx: QuoteContext): Option[Seq[T]] = expr match { case ExprSeq(elems) => elems.foldRight(Option(List.empty[T])) { (elem, acc) => (elem, acc) match { diff --git a/library/src-3.x/scala/quoted/matching/ExprSeq.scala b/library/src-3.x/scala/quoted/matching/ExprSeq.scala index f0d1e20af648..2f15640e9900 100644 --- a/library/src-3.x/scala/quoted/matching/ExprSeq.scala +++ b/library/src-3.x/scala/quoted/matching/ExprSeq.scala @@ -1,15 +1,12 @@ -package scala.quoted.matching - -import scala.quoted.Expr - -import scala.tasty.Reflection // TODO do not depend on reflection directly +package scala.quoted +package matching /** Literal sequence of expressions */ object ExprSeq { /** Matches a literal sequence of expressions */ - def unapply[T](expr: Expr[Seq[T]])(implicit reflect: Reflection): Option[Seq[Expr[T]]] = { - import reflect._ + def unapply[T](expr: Expr[Seq[T]]) given (qctx: QuoteContext): Option[Seq[Expr[T]]] = { + import qctx.tasty._ def rec(tree: Term): Option[Seq[Expr[T]]] = tree match { case Typed(Repeated(elems, _), _) => Some(elems.map(x => x.seal.asInstanceOf[Expr[T]])) case Block(Nil, e) => rec(e) diff --git a/library/src-3.x/dotty/internal/StringContextMacro.scala b/library/src-bootstrapped/dotty/internal/StringContextMacro.scala similarity index 97% rename from library/src-3.x/dotty/internal/StringContextMacro.scala rename to library/src-bootstrapped/dotty/internal/StringContextMacro.scala index ba087917b922..d97f022f3b8c 100644 --- a/library/src-3.x/dotty/internal/StringContextMacro.scala +++ b/library/src-bootstrapped/dotty/internal/StringContextMacro.scala @@ -1,8 +1,9 @@ +// ALWAYS KEEP THIS FILE IN src-bootstrapped, DO NOT MOVE TO src + package dotty.internal import scala.quoted._ import scala.quoted.matching._ -import scala.tasty.Reflection import reflect._ object StringContextMacro { @@ -58,7 +59,7 @@ object StringContextMacro { * @return the String contained in the given Expr * quotes an error if the given Expr does not contain a String */ - private def literalToString(expression : Expr[String])(implicit reflect: Reflection) : String = expression match { + private def literalToString(expression : Expr[String]) given (ctx: QuoteContext) : String = expression match { case Const(string : String) => string case _ => QuoteError("Expected statically known literal", expression) } @@ -69,8 +70,7 @@ object StringContextMacro { * @return a list of Expr containing Strings, each corresponding to one parts of the given StringContext * quotes an error if the given Expr does not correspond to a StringContext */ - def getPartsExprs(strCtxExpr : Expr[scala.StringContext])(implicit reflect : Reflection): List[Expr[String]] = { - import reflect._ + def getPartsExprs(strCtxExpr : Expr[scala.StringContext]) given QuoteContext: List[Expr[String]] = { strCtxExpr match { case '{ StringContext(${ExprSeq(parts)}: _*) } => parts.toList case '{ new StringContext(${ExprSeq(parts)}: _*) } => parts.toList @@ -84,8 +84,8 @@ object StringContextMacro { * @return a list of Expr containing arguments * quotes an error if the given Expr does not contain a list of arguments */ - def getArgsExprs(argsExpr: Expr[Seq[Any]])(implicit reflect: Reflection): List[Expr[Any]] = { - import reflect._ + def getArgsExprs(argsExpr: Expr[Seq[Any]]) given (qctx: QuoteContext): List[Expr[Any]] = { + import qctx.tasty._ argsExpr.unseal.underlyingArgument match { case Typed(Repeated(args, _), _) => args.map(_.seal) case tree => QuoteError("Expected statically known argument list", argsExpr) @@ -98,8 +98,8 @@ object StringContextMacro { * @param args the Expr that holds the sequence of arguments to interpolate to the String in the correct format * @return the Expr containing the formatted and interpolated String or an error/warning if the parameters are not correct */ - private def interpolate(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + private def interpolate(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ val sourceFile = strCtxExpr.unseal.pos.sourceFile val partsExpr = getPartsExprs(strCtxExpr) @@ -111,27 +111,27 @@ object StringContextMacro { def partError(message : String, index : Int, offset : Int) : Unit = { reported = true val positionStart = partsExpr(index).unseal.pos.start + offset - reflect.error(message, sourceFile, positionStart, positionStart) + error(message, sourceFile, positionStart, positionStart) } def partWarning(message : String, index : Int, offset : Int) : Unit = { reported = true val positionStart = partsExpr(index).unseal.pos.start + offset - reflect.warning(message, sourceFile, positionStart, positionStart) + warning(message, sourceFile, positionStart, positionStart) } def argError(message : String, index : Int) : Unit = { reported = true - reflect.error(message, args(index).unseal.pos) + error(message, args(index).unseal.pos) } def strCtxError(message : String) : Unit = { reported = true val positionStart = strCtxExpr.unseal.pos.start - reflect.error(message, sourceFile, positionStart, positionStart) + error(message, sourceFile, positionStart, positionStart) } def argsError(message : String) : Unit = { reported = true - reflect.error(message, argsExpr.unseal.pos) + error(message, argsExpr.unseal.pos) } def hasReported() : Boolean = { @@ -158,8 +158,8 @@ object StringContextMacro { * @param reporter the reporter to return any error/warning when a problem is encountered * @return the Expr containing the formatted and interpolated String or an error/warning report if the parameters are not correct */ - def interpolate(partsExpr : List[Expr[String]], args : List[Expr[Any]], argsExpr: Expr[Seq[Any]], reporter : Reporter)(implicit reflect: Reflection) : Expr[String] = { - import reflect._ + def interpolate(partsExpr : List[Expr[String]], args : List[Expr[Any]], argsExpr: Expr[Seq[Any]], reporter : Reporter) given (qctx: QuoteContext) : Expr[String] = { + import qctx.tasty._ /** Checks if the number of arguments are the same as the number of formatting strings * diff --git a/library/src-3.x/scala/testing/typeChecks.scala b/library/src-bootstrapped/scala/testing/typeChecks.scala similarity index 53% rename from library/src-3.x/scala/testing/typeChecks.scala rename to library/src-bootstrapped/scala/testing/typeChecks.scala index a95c70a92137..a2d8a7275129 100644 --- a/library/src-3.x/scala/testing/typeChecks.scala +++ b/library/src-bootstrapped/scala/testing/typeChecks.scala @@ -1,12 +1,10 @@ package scala.testing import scala.quoted._ -import scala.tasty.Reflection inline def typeChecks(inline code: String): Boolean = ${ typeChecksImpl(code) } -private def typeChecksImpl(code: String)(implicit reflect: Reflection): Expr[Boolean] = { - import reflect._ +private def typeChecksImpl(code: String) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ typing.typeChecks(code).toExpr } - diff --git a/library/src-non-bootstrapped/dotty/internal/StringContextMacro.scala b/library/src-non-bootstrapped/dotty/internal/StringContextMacro.scala new file mode 100644 index 000000000000..1a869f912c47 --- /dev/null +++ b/library/src-non-bootstrapped/dotty/internal/StringContextMacro.scala @@ -0,0 +1,16 @@ +// ALWAYS KEEP THIS FILE IN src-non-bootstrapped + +package dotty.internal + +import scala.quoted._ +import scala.quoted.matching._ +import scala.tasty.Reflection +import reflect._ + +object StringContextMacro { + + /** Implementation of scala.StringContext.f used in Dotty */ + inline def f(sc: => StringContext)(args: Any*): String = + scala.compiletime.error("Cannot expand f interpolator while bootstrapping the compiler") + +} diff --git a/library/src-non-bootstrapped/scala/testing/typeChecks.scala b/library/src-non-bootstrapped/scala/testing/typeChecks.scala new file mode 100644 index 000000000000..0d5c73a40428 --- /dev/null +++ b/library/src-non-bootstrapped/scala/testing/typeChecks.scala @@ -0,0 +1,4 @@ +package scala.testing + +inline def typeChecks(inline code: String): Boolean = + scala.compiletime.error("Cannot expand typeChecks while bootstrapping the compiler") diff --git a/library/src/scala/quoted/QuoteContext.scala b/library/src/scala/quoted/QuoteContext.scala index f3436f86ed47..0423044a7d47 100644 --- a/library/src/scala/quoted/QuoteContext.scala +++ b/library/src/scala/quoted/QuoteContext.scala @@ -2,16 +2,26 @@ package scala.quoted import scala.quoted.show.SyntaxHighlight -class QuoteContext(reflection: tasty.Reflection) { +class QuoteContext(val tasty: scala.tasty.Reflection) { def show[T](expr: Expr[T], syntaxHighlight: SyntaxHighlight): String = { - import reflection._ + import tasty._ expr.unseal.show(syntaxHighlight) } def show[T](tpe: Type[T], syntaxHighlight: SyntaxHighlight): String = { - import reflection._ + import tasty._ tpe.unseal.show(syntaxHighlight) } } + +object QuoteContext { + // TODO remove in 0.18 + // For backward compat with macros + @deprecated("Provide scala.quoted.QuoteContext instead of using a scala.tasty.Reflection", "0.17") + implicit def reflectionToQuoteContext(implicit reflect: tasty.Reflection): scala.quoted.QuoteContext = + new scala.quoted.QuoteContext(reflect) + + def macroContext: QuoteContext = throw new Exception("Not in inline macro.") +} diff --git a/library/src/scala/tasty/Reflection.scala b/library/src/scala/tasty/Reflection.scala index 503e61ebd7d6..cf4f88f7288f 100644 --- a/library/src/scala/tasty/Reflection.scala +++ b/library/src/scala/tasty/Reflection.scala @@ -26,6 +26,7 @@ class Reflection(val kernel: Kernel) def typeOf[T: scala.quoted.Type]: Type = implicitly[scala.quoted.Type[T]].unseal.tpe + // TODO move out of Reflection object typing { /** Whether the code type checks in the given context? * @@ -38,18 +39,15 @@ class Reflection(val kernel: Kernel) def typeChecks(code: String)(implicit ctx: Context): Boolean = kernel.typeChecks(code)(ctx) } + // TODO integrate with TreeUtils val util: reflect.utils.TreeUtils { val reflect: self.type } = new reflect.utils.TreeUtils { val reflect: self.type = self } - // TODO remove - // For backward compat with macros - implicit def reflectionToQuoteContext(implicit reflect: Reflection): scala.quoted.QuoteContext = - new scala.quoted.QuoteContext(reflect) - } object Reflection { /** Compiler tasty context available in a top level ~ of an inline macro */ + @deprecated("Use scala.quoted.QuoteContext instead", "0.17") def macroContext: Reflection = throw new Exception("Not in inline macro.") } diff --git a/tests/neg-macros/i6432/Macro_1.scala b/tests/neg-macros/i6432/Macro_1.scala index 02c6461e78f2..f2f3b04c5d25 100644 --- a/tests/neg-macros/i6432/Macro_1.scala +++ b/tests/neg-macros/i6432/Macro_1.scala @@ -6,8 +6,8 @@ import scala.quoted.matching._ object Macro { inline def (sc: => StringContext) foo (args: String*): Unit = ${ impl('sc) } - def impl(sc: Expr[StringContext])(implicit reflect: tasty.Reflection): Expr[Unit] = { - import reflect._ + def impl(sc: Expr[StringContext]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ sc match { case '{ StringContext(${ExprSeq(parts)}: _*) } => for (part @ Const(s) <- parts) diff --git a/tests/neg-macros/i6432b/Macro_1.scala b/tests/neg-macros/i6432b/Macro_1.scala index 02c6461e78f2..f2f3b04c5d25 100644 --- a/tests/neg-macros/i6432b/Macro_1.scala +++ b/tests/neg-macros/i6432b/Macro_1.scala @@ -6,8 +6,8 @@ import scala.quoted.matching._ object Macro { inline def (sc: => StringContext) foo (args: String*): Unit = ${ impl('sc) } - def impl(sc: Expr[StringContext])(implicit reflect: tasty.Reflection): Expr[Unit] = { - import reflect._ + def impl(sc: Expr[StringContext]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ sc match { case '{ StringContext(${ExprSeq(parts)}: _*) } => for (part @ Const(s) <- parts) diff --git a/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala b/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala index 01f7b1d0a229..d91f253e9828 100644 --- a/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala @@ -14,8 +14,8 @@ object Asserts { inline def macroAssert(cond: => Boolean): Unit = ${impl('cond)} - def impl(cond: Expr[Boolean])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl(cond: Expr[Boolean]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = cond.unseal diff --git a/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala b/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala index 0cd616eaf32c..3a79b8bf7214 100644 --- a/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala @@ -14,8 +14,8 @@ object Asserts { inline def macroAssert(cond: => Boolean): Unit = ${ impl('cond) } - def impl(cond: Expr[Boolean])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl(cond: Expr[Boolean]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = cond.unseal diff --git a/tests/neg-macros/tasty-macro-error/quoted_1.scala b/tests/neg-macros/tasty-macro-error/quoted_1.scala index 1df04315c127..d980cd1c0f06 100644 --- a/tests/neg-macros/tasty-macro-error/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-error/quoted_1.scala @@ -6,8 +6,8 @@ object Macros { inline def fun(x: Any): Unit = ${ impl('x) } - def impl(x: Expr[Any])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl(x: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ error("here is the the argument is " + x.unseal.underlyingArgument.show, x.unseal.underlyingArgument.pos) '{} } diff --git a/tests/neg-macros/tasty-macro-positions/quoted_1.scala b/tests/neg-macros/tasty-macro-positions/quoted_1.scala index b8c4232310a6..9cfdf2930fc7 100644 --- a/tests/neg-macros/tasty-macro-positions/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-positions/quoted_1.scala @@ -6,8 +6,8 @@ object Macros { inline def fun(x: Any): Unit = ${ impl('x) } - def impl(x: Expr[Any])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl(x: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val pos = x.unseal.underlyingArgument.pos error("here is the the argument is " + x.unseal.underlyingArgument.show, pos) error("here (+5) is the the argument is " + x.unseal.underlyingArgument.show, pos.sourceFile, pos.start + 5, pos.end + 5) diff --git a/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala b/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala index 62c1ce166d81..6e7a985d0314 100644 --- a/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala +++ b/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala @@ -10,8 +10,8 @@ object Macro { object FIntepolator { - def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ error("there are no parts", strCtxExpr.unseal.underlyingArgument.pos) '{ ($strCtxExpr).s($argsExpr: _*) } } diff --git a/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala b/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala index bee2e93d6d7c..942429eff106 100644 --- a/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala +++ b/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala @@ -9,8 +9,8 @@ object Macro { } object FIntepolator { - def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ error("there are no args", argsExpr.unseal.underlyingArgument.pos) '{ ($strCtxExpr).s($argsExpr: _*) } } diff --git a/tests/neg-with-compiler/i5941/macro_1.scala b/tests/neg-with-compiler/i5941/macro_1.scala index e5f7ca7c2768..1e286b8de780 100644 --- a/tests/neg-with-compiler/i5941/macro_1.scala +++ b/tests/neg-with-compiler/i5941/macro_1.scala @@ -12,9 +12,9 @@ object Lens { def set(t: T, s: S): S = _set(t)(s) } - def impl[S: Type, T: Type](getter: Expr[S => T])(implicit refl: Reflection): Expr[Lens[S, T]] = { + def impl[S: Type, T: Type](getter: Expr[S => T]) given (qctx: QuoteContext): Expr[Lens[S, T]] = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(this.getClass.getClassLoader) - import refl._ + import qctx.tasty._ import util._ // obj.copy(field = value) def setterBody(obj: Expr[S], value: Expr[T], field: String): Expr[S] = diff --git a/tests/neg/quotedPatterns-1.scala b/tests/neg/quotedPatterns-1.scala index a7f90e07c6e8..3c8de6020bb3 100644 --- a/tests/neg/quotedPatterns-1.scala +++ b/tests/neg/quotedPatterns-1.scala @@ -1,5 +1,5 @@ object Test { - def test(x: quoted.Expr[Int]) given tasty.Reflection = x match { + def test(x: quoted.Expr[Int]) given scala.quoted.QuoteContext = x match { case '{ val a = '{ println($y) }; 0 } => ??? // error: Not found: y case _ => } diff --git a/tests/neg/quotedPatterns-2.scala b/tests/neg/quotedPatterns-2.scala index dcb5fa06c64f..6bfc3cf9932a 100644 --- a/tests/neg/quotedPatterns-2.scala +++ b/tests/neg/quotedPatterns-2.scala @@ -1,5 +1,5 @@ object Test { - def test(x: quoted.Expr[Int]) given tasty.Reflection = x match { + def test(x: quoted.Expr[Int]) given scala.quoted.QuoteContext = x match { case '{ val a = 4; '{ a }; $y } => y // error: access to value a from wrong staging level case _ => } diff --git a/tests/neg/quotedPatterns-3.scala b/tests/neg/quotedPatterns-3.scala index cce479de5055..bdc092f15189 100644 --- a/tests/neg/quotedPatterns-3.scala +++ b/tests/neg/quotedPatterns-3.scala @@ -1,5 +1,5 @@ object Test { - def test(x: quoted.Expr[Int]) given tasty.Reflection = x match { + def test(x: quoted.Expr[Int]) given scala.quoted.QuoteContext = x match { case '{ val `$y`: Int = 2; 1 } => y // error: Not found: y case '{ ((`$y`: Int) => 3); 2 } => diff --git a/tests/neg/quotedPatterns-4.scala b/tests/neg/quotedPatterns-4.scala index d1fae244c94d..bdee6a64b932 100644 --- a/tests/neg/quotedPatterns-4.scala +++ b/tests/neg/quotedPatterns-4.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Test { - def impl(receiver: Expr[StringContext])(implicit reflect: scala.tasty.Reflection) = { - import reflect.Repeated + def impl(receiver: Expr[StringContext]) given (qctx: scala.quoted.QuoteContext) = { + import qctx.tasty.Repeated receiver match { case '{ StringContext(${Repeated(parts)}: _*) } => // error } diff --git a/tests/patmat/i6255.scala b/tests/patmat/i6255.scala index c93ef05adb16..b36c0a640830 100644 --- a/tests/patmat/i6255.scala +++ b/tests/patmat/i6255.scala @@ -1,5 +1,5 @@ class Foo { - def foo(x: quoted.Expr[Int]) given scala.tasty.Reflection: Unit = x match { + def foo(x: quoted.Expr[Int]) given scala.quoted.QuoteContext: Unit = x match { case '{ 1 } => case '{ 2 } => case _ => diff --git a/tests/patmat/i6255b.scala b/tests/patmat/i6255b.scala index cd3dc0257945..fd643d69d346 100644 --- a/tests/patmat/i6255b.scala +++ b/tests/patmat/i6255b.scala @@ -1,5 +1,5 @@ class Foo { - def foo(x: quoted.Expr[Int]) given scala.tasty.Reflection: Unit = x match { + def foo(x: quoted.Expr[Int]) given scala.quoted.QuoteContext: Unit = x match { case '{ 1 } => case '{ 2 } => } diff --git a/tests/pending/run/tasty-comments/quoted_1.scala b/tests/pending/run/tasty-comments/quoted_1.scala index 8484ab781744..3146df70573c 100644 --- a/tests/pending/run/tasty-comments/quoted_1.scala +++ b/tests/pending/run/tasty-comments/quoted_1.scala @@ -8,8 +8,8 @@ object Macros { inline def printComment[T](t: => T): Unit = ${ impl('t) } - def impl[T](x: Expr[T])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl[T](x: Expr[T]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = x.unseal tree.symbol.comment.map(_.raw) match { diff --git a/tests/pos-macros/i6171/Macro_1.scala b/tests/pos-macros/i6171/Macro_1.scala index 3f0969a1f56e..49282050158d 100644 --- a/tests/pos-macros/i6171/Macro_1.scala +++ b/tests/pos-macros/i6171/Macro_1.scala @@ -5,8 +5,8 @@ object scalatest { inline def assert(x: => Any): Unit = ${ assertImpl('x) } - def assertImpl(x: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(x: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ x.unseal.underlyingArgument '{ () } } diff --git a/tests/pos-macros/i6535/Macro_1.scala b/tests/pos-macros/i6535/Macro_1.scala index 10042e56adc3..85f2e9788671 100644 --- a/tests/pos-macros/i6535/Macro_1.scala +++ b/tests/pos-macros/i6535/Macro_1.scala @@ -5,8 +5,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition) } - def assertImpl(cond: Expr[Boolean])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(cond: Expr[Boolean]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ import util._ cond.unseal.underlyingArgument match { diff --git a/tests/pos-macros/tasty-constant-type/Macro_1.scala b/tests/pos-macros/tasty-constant-type/Macro_1.scala index 10217d9db8a6..934b6d51f727 100644 --- a/tests/pos-macros/tasty-constant-type/Macro_1.scala +++ b/tests/pos-macros/tasty-constant-type/Macro_1.scala @@ -6,8 +6,8 @@ object Macro { inline def ff[A <: Int, B <: Int]() <: AddInt[A, B] = ${ impl('[A], '[B]) } - def impl[A <: Int : Type, B <: Int : Type](a: Type[A], b: Type[B])(implicit r: tasty.Reflection): Expr[AddInt[A, B]] = { - import r._ + def impl[A <: Int : Type, B <: Int : Type](a: Type[A], b: Type[B]) given (qctx: QuoteContext): Expr[AddInt[A, B]] = { + import qctx.tasty._ val Type.ConstantType(Constant.Int(v1)) = a.unseal.tpe val Type.ConstantType(Constant.Int(v2)) = b.unseal.tpe diff --git a/tests/pos/i6214.scala b/tests/pos/i6214.scala index 16e6140e3e82..c45409435ea5 100644 --- a/tests/pos/i6214.scala +++ b/tests/pos/i6214.scala @@ -1,6 +1,6 @@ import scala.quoted._ object Test { - def res(x: quoted.Expr[Int]) given tasty.Reflection: quoted.Expr[Int] = x match { + def res(x: quoted.Expr[Int]) given QuoteContext: quoted.Expr[Int] = x match { case '{ val a: Int = $y; 1} => y // owner of `y` is `res` case _ => '{ val b: Int = ${val c = 2; c.toExpr}; 1} // owner of `c` is `b`, but that seems to be OK } diff --git a/tests/pos/i6214b.scala b/tests/pos/i6214b.scala index 276367fe350a..2aa8920846fd 100644 --- a/tests/pos/i6214b.scala +++ b/tests/pos/i6214b.scala @@ -1,5 +1,5 @@ object Test { - def res(x: quoted.Expr[Int]) given tasty.Reflection: quoted.Expr[Int] = x match { + def res(x: quoted.Expr[Int]) given scala.quoted.QuoteContext: quoted.Expr[Int] = x match { case '{ val a: Int = ${ Foo('{ val b: Int = $y; b }) }; a } => y // owner of y is res } object Foo { diff --git a/tests/pos/i6253.scala b/tests/pos/i6253.scala index 8d006ab30be7..a11e7b9dcebf 100644 --- a/tests/pos/i6253.scala +++ b/tests/pos/i6253.scala @@ -1,7 +1,7 @@ import scala.quoted._ import scala.tasty.Reflection object Macros { - def impl(self: Expr[StringContext]) given Reflection: Expr[String] = self match { + def impl(self: Expr[StringContext]) given QuoteContext: Expr[String] = self match { case '{ StringContext() } => '{""} case '{ StringContext($part1) } => part1 case '{ StringContext($part1, $part2) } => '{ $part1 + $part2 } diff --git a/tests/pos/i6435.scala b/tests/pos/i6435.scala index 5b433035c844..f1352fc34f14 100644 --- a/tests/pos/i6435.scala +++ b/tests/pos/i6435.scala @@ -1,7 +1,7 @@ class Foo { import scala.quoted._ import scala.quoted.matching._ - def f(sc: quoted.Expr[StringContext]) given tasty.Reflection: Unit = { + def f(sc: quoted.Expr[StringContext]) given QuoteContext: Unit = { val '{ StringContext(${parts}: _*) } = sc val ps0: Expr[Seq[String]] = parts diff --git a/tests/pos/quotedPatterns.scala b/tests/pos/quotedPatterns.scala index 51ab38df54be..238a173bd9d1 100644 --- a/tests/pos/quotedPatterns.scala +++ b/tests/pos/quotedPatterns.scala @@ -5,7 +5,7 @@ object Test { def f(x: Int) = x def g(x: Int, y: Int) = x * y - def res given tasty.Reflection: quoted.Expr[Int] = x match { + def res given scala.quoted.QuoteContext: quoted.Expr[Int] = x match { case '{1 + 2} => '{0} case '{f($y)} => y case '{g($y, $z)} => '{$y * $z} diff --git a/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala b/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala index 016997e12c3e..70d7e372ae64 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala @@ -7,8 +7,8 @@ object Foo { inline def inspectBody(i: => Int): String = ${ inspectBodyImpl('i) } - def inspectBodyImpl(x: Expr[Int])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + def inspectBodyImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ def definitionString(tree: Tree): Expr[String] = tree.symbol match { case IsDefDefSymbol(sym) => sym.tree.showExtractors case IsValDefSymbol(sym) => sym.tree.showExtractors diff --git a/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala b/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala index d32df868176f..e0105c2ad9ea 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala @@ -7,8 +7,8 @@ object Foo { inline def inspectBody(i: => Int): String = ${ inspectBodyImpl('i) } - def inspectBodyImpl(x: Expr[Int])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + def inspectBodyImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ def definitionString(tree: Tree): Expr[String] = tree.symbol match { case IsDefDefSymbol(sym) => sym.tree.showExtractors case IsValDefSymbol(sym) => sym.tree.showExtractors diff --git a/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala index 7d61ab585773..34a0d3b42ebf 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala @@ -8,8 +8,8 @@ object Macros { implicit inline def printOwners[T](x: => T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl[T](x: Expr[T]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val buff = new StringBuilder diff --git a/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala index fb6911f7e2f3..4a316d60bf27 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala @@ -7,8 +7,8 @@ object Foo { inline def inspectBody(i: => Int): String = ${ inspectBodyImpl('i) } - def inspectBodyImpl(x: Expr[Int])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + def inspectBodyImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ def definitionString(tree: Tree): Expr[String] = tree.symbol match { case IsClassDefSymbol(sym) => sym.tree.showExtractors.toExpr diff --git a/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala index 93e7277adcf6..5c97f8ef05bd 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala @@ -7,8 +7,8 @@ object Foo { inline def inspectBody(i: => Int): String = ${ inspectBodyImpl('i) } - def inspectBodyImpl(x: Expr[Int])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + def inspectBodyImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ def definitionString(tree: Tree): Expr[String] = tree.symbol match { case IsClassDefSymbol(sym) => sym.tree.showExtractors.toExpr diff --git a/tests/run-macros/f-interpolation-1/FQuote_1.scala b/tests/run-macros/f-interpolation-1/FQuote_1.scala index 3d6404504fbd..d6f514285c08 100644 --- a/tests/run-macros/f-interpolation-1/FQuote_1.scala +++ b/tests/run-macros/f-interpolation-1/FQuote_1.scala @@ -10,8 +10,8 @@ object FQuote { inline def ff(args: => Any*): String = ${impl('this, 'args)} } - /*private*/ def impl(receiver: Expr[SCOps], args: Expr[Seq[Any]])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + /*private*/ def impl(receiver: Expr[SCOps], args: Expr[Seq[Any]]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ def liftListOfAny(lst: List[Term]): Expr[List[Any]] = lst match { case x :: xs => diff --git a/tests/run-macros/f-interpolator-neg/Macros_1.scala b/tests/run-macros/f-interpolator-neg/Macros_1.scala index 2752945ff75e..284c960920ec 100644 --- a/tests/run-macros/f-interpolator-neg/Macros_1.scala +++ b/tests/run-macros/f-interpolator-neg/Macros_1.scala @@ -1,7 +1,6 @@ import scala.quoted._ import scala.quoted.autolift._ import scala.quoted.matching._ -import scala.tasty.Reflection import scala.language.implicitConversions @@ -13,7 +12,7 @@ object TestFooErrors { // Defined in tests object Macro { - def fooErrors(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given (reflect: Reflection): Expr[List[(Boolean, Int, Int, Int, String)]] = { + def fooErrors(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given QuoteContext: Expr[List[(Boolean, Int, Int, Int, String)]] = { (strCtxExpr, argsExpr) match { case ('{ StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) => fooErrorsImpl(parts, args, argsExpr) @@ -22,7 +21,7 @@ object Macro { } } - def fooErrorsImpl(parts : Seq[Expr[String]], args: Seq[Expr[Any]], argsExpr: Expr[Seq[Any]]) given (reflect: Reflection)= { + def fooErrorsImpl(parts : Seq[Expr[String]], args: Seq[Expr[Any]], argsExpr: Expr[Seq[Any]]) given QuoteContext= { val errors = List.newBuilder[Expr[(Boolean, Int, Int, Int, String)]] // true if error, false if warning // 0 if part, 1 if arg, 2 if strCtx, 3 if args diff --git a/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala b/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala index 888b6e66cd97..51e96aeb6118 100644 --- a/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala +++ b/tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala @@ -7,32 +7,32 @@ import scala.tasty._ object TypeToolbox { /** are the two types equal? */ inline def =:=[A, B]: Boolean = ${tpEqImpl('[A], '[B])} - private def tpEqImpl[A, B](a: Type[A], b: Type[B])(implicit reflect: Reflection): Expr[Boolean] = { - import reflect._ + private def tpEqImpl[A, B](a: Type[A], b: Type[B]) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ val res = a.unseal.tpe =:= b.unseal.tpe res.toExpr } /** is `tp1` a subtype of `tp2` */ inline def <:<[A, B]: Boolean = ${tpLEqImpl('[A], '[B])} - private def tpLEqImpl[A, B](a: Type[A], b: Type[B])(implicit reflect: Reflection): Expr[Boolean] = { - import reflect._ + private def tpLEqImpl[A, B](a: Type[A], b: Type[B]) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ val res = a.unseal.tpe <:< b.unseal.tpe res.toExpr } /** type associated with the tree */ inline def typeOf[T, Expected](a: T): Boolean = ${typeOfImpl('a, '[Expected])} - private def typeOfImpl(a: Expr[_], expected: Type[_])(implicit reflect: Reflection): Expr[Boolean] = { - import reflect._ + private def typeOfImpl(a: Expr[_], expected: Type[_]) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ val res = a.unseal.tpe =:= expected.unseal.tpe res.toExpr } /** does the type refer to a case class? */ inline def isCaseClass[A]: Boolean = ${isCaseClassImpl('[A])} - private def isCaseClassImpl(tp: Type[_])(implicit reflect: Reflection): Expr[Boolean] = { - import reflect._ + private def isCaseClassImpl(tp: Type[_]) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ val res = tp.unseal.symbol match { case IsClassDefSymbol(sym) => sym.flags.is(Flags.Case) case _ => false @@ -42,67 +42,67 @@ object TypeToolbox { /** val fields of a case class Type -- only the ones declared in primary constructor */ inline def caseFields[T]: List[String] = ${caseFieldsImpl('[T])} - private def caseFieldsImpl(tp: Type[_])(implicit reflect: Reflection): Expr[List[String]] = { - import reflect._ + private def caseFieldsImpl(tp: Type[_]) given (qctx: QuoteContext): Expr[List[String]] = { + import qctx.tasty._ val fields = tp.unseal.symbol.asClassDef.caseFields.map(_.name) fields.toExpr } inline def fieldIn[T](inline mem: String): String = ${fieldInImpl('[T], mem)} - private def fieldInImpl(t: Type[_], mem: String)(implicit reflect: Reflection): Expr[String] = { - import reflect._ + private def fieldInImpl(t: Type[_], mem: String) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ val field = t.unseal.symbol.asClassDef.field(mem) field.map(_.name).getOrElse("").toExpr } inline def fieldsIn[T]: Seq[String] = ${fieldsInImpl('[T])} - private def fieldsInImpl(t: Type[_])(implicit reflect: Reflection): Expr[Seq[String]] = { - import reflect._ + private def fieldsInImpl(t: Type[_]) given (qctx: QuoteContext): Expr[Seq[String]] = { + import qctx.tasty._ val fields = t.unseal.symbol.asClassDef.fields fields.map(_.name).toList.toExpr } inline def methodIn[T](inline mem: String): Seq[String] = ${methodInImpl('[T], mem)} - private def methodInImpl(t: Type[_], mem: String)(implicit reflect: Reflection): Expr[Seq[String]] = { - import reflect._ + private def methodInImpl(t: Type[_], mem: String) given (qctx: QuoteContext): Expr[Seq[String]] = { + import qctx.tasty._ t.unseal.symbol.asClassDef.classMethod(mem).map(_.name).toExpr } inline def methodsIn[T]: Seq[String] = ${methodsInImpl('[T])} - private def methodsInImpl(t: Type[_])(implicit reflect: Reflection): Expr[Seq[String]] = { - import reflect._ + private def methodsInImpl(t: Type[_]) given (qctx: QuoteContext): Expr[Seq[String]] = { + import qctx.tasty._ t.unseal.symbol.asClassDef.classMethods.map(_.name).toExpr } inline def method[T](inline mem: String): Seq[String] = ${methodImpl('[T], mem)} - private def methodImpl(t: Type[_], mem: String)(implicit reflect: Reflection): Expr[Seq[String]] = { - import reflect._ + private def methodImpl(t: Type[_], mem: String) given (qctx: QuoteContext): Expr[Seq[String]] = { + import qctx.tasty._ t.unseal.symbol.asClassDef.method(mem).map(_.name).toExpr } inline def methods[T]: Seq[String] = ${methodsImpl('[T])} - private def methodsImpl(t: Type[_])(implicit reflect: Reflection): Expr[Seq[String]] = { - import reflect._ + private def methodsImpl(t: Type[_]) given (qctx: QuoteContext): Expr[Seq[String]] = { + import qctx.tasty._ t.unseal.symbol.asClassDef.methods.map(_.name).toExpr } inline def typeTag[T](x: T): String = ${typeTagImpl('[T])} - private def typeTagImpl(tp: Type[_])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + private def typeTagImpl(tp: Type[_]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ val res = tp.unseal.tpe.show res.toExpr } inline def companion[T1, T2]: Boolean = ${companionImpl('[T1], '[T2])} - private def companionImpl(t1: Type[_], t2: Type[_])(implicit reflect: Reflection): Expr[Boolean] = { - import reflect._ + private def companionImpl(t1: Type[_], t2: Type[_]) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ val res = t1.unseal.symbol.asClassDef.companionModule.contains(t2.unseal.symbol) res.toExpr } inline def companionName[T1]: String = ${companionNameImpl('[T1])} - private def companionNameImpl(tp: Type[_])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + private def companionNameImpl(tp: Type[_]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ val companionClassOpt = tp.unseal.symbol match { case IsClassDefSymbol(sym) => sym.companionClass case IsValDefSymbol(sym) => sym.companionClass diff --git a/tests/run-macros/i4515b/Macro_1.scala b/tests/run-macros/i4515b/Macro_1.scala index ed345bd69bb5..4bd2ec012e4f 100644 --- a/tests/run-macros/i4515b/Macro_1.scala +++ b/tests/run-macros/i4515b/Macro_1.scala @@ -1,6 +1,6 @@ -import scala.tasty.Reflection +import scala.quoted._ object Macro { inline def foo: Unit = ${ fooImpl } - def fooImpl(implicit reflect: Reflection): quoted.Expr[Unit] = '{} + def fooImpl given QuoteContext: Expr[Unit] = '{} } diff --git a/tests/run-macros/i5119/Macro_1.scala b/tests/run-macros/i5119/Macro_1.scala index 6915a604267b..37e854cb27c5 100644 --- a/tests/run-macros/i5119/Macro_1.scala +++ b/tests/run-macros/i5119/Macro_1.scala @@ -7,8 +7,8 @@ object Macro { inline def ff(args: => Any*): String = ${ Macro.impl('sc, 'args) } } implicit inline def XmlQuote(sc: => StringContext): StringContextOps = new StringContextOps(sc) - def impl(sc: Expr[StringContext], args: Expr[Seq[Any]])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + def impl(sc: Expr[StringContext], args: Expr[Seq[Any]]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ (sc.unseal.underlyingArgument.showExtractors + "\n" + args.unseal.underlyingArgument.showExtractors) } } diff --git a/tests/run-macros/i5119b/Macro_1.scala b/tests/run-macros/i5119b/Macro_1.scala index 7c251e549246..b8896a1f514f 100644 --- a/tests/run-macros/i5119b/Macro_1.scala +++ b/tests/run-macros/i5119b/Macro_1.scala @@ -7,8 +7,8 @@ object Macro { inline def ff(arg1: Any, arg2: Any): String = ${ Macro.impl('{arg1}, '{arg2}) } - def impl(arg1: Expr[Any], arg2: Expr[Any])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + def impl(arg1: Expr[Any], arg2: Expr[Any]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ (arg1.unseal.underlyingArgument.showExtractors + "\n" + arg2.unseal.underlyingArgument.showExtractors) } diff --git a/tests/run-macros/i5533/Macro_1.scala b/tests/run-macros/i5533/Macro_1.scala index 9b74f3b5954a..35395dc22257 100644 --- a/tests/run-macros/i5533/Macro_1.scala +++ b/tests/run-macros/i5533/Macro_1.scala @@ -8,8 +8,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${assertImpl('condition)} - def assertImpl(condition: Expr[Boolean])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(condition: Expr[Boolean]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = condition.unseal diff --git a/tests/run-macros/i5533b/Macro_1.scala b/tests/run-macros/i5533b/Macro_1.scala index f57626b258a0..b73027c05047 100644 --- a/tests/run-macros/i5533b/Macro_1.scala +++ b/tests/run-macros/i5533b/Macro_1.scala @@ -7,8 +7,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${assertImpl('condition)} - def assertImpl(condition: Expr[Boolean])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(condition: Expr[Boolean]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = condition.unseal def exprStr: String = condition.show diff --git a/tests/run-macros/i5536/Macro_1.scala b/tests/run-macros/i5536/Macro_1.scala index b3f280c14117..236e5268bc4b 100644 --- a/tests/run-macros/i5536/Macro_1.scala +++ b/tests/run-macros/i5536/Macro_1.scala @@ -4,8 +4,8 @@ import scala.tasty._ object scalatest { inline def assert(condition: => Boolean): Unit = ${assertImpl('condition)} - def assertImpl(condition: Expr[Boolean])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(condition: Expr[Boolean]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = condition.unseal def exprStr: String = condition.show diff --git a/tests/run-macros/i5629/Macro_1.scala b/tests/run-macros/i5629/Macro_1.scala index eb4a0ae6e77e..e32f00d1e632 100644 --- a/tests/run-macros/i5629/Macro_1.scala +++ b/tests/run-macros/i5629/Macro_1.scala @@ -5,16 +5,16 @@ object Macros { inline def assert(condition: => Boolean): Unit = ${ assertImpl('{condition}, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val b = cond.unseal.underlyingArgument.seal.cast[Boolean] '{ scala.Predef.assert($b) } } inline def thisLineNumber = ${ thisLineNumberImpl } - def thisLineNumberImpl(implicit refl: Reflection): Expr[Int] = { - import refl._ - refl.rootPosition.startLine.toExpr + def thisLineNumberImpl given (qctx: QuoteContext): Expr[Int] = { + import qctx.tasty._ + rootPosition.startLine.toExpr } } diff --git a/tests/run-macros/i5715/Macro_1.scala b/tests/run-macros/i5715/Macro_1.scala index 73b5f3346b4c..1b92a1adefaa 100644 --- a/tests/run-macros/i5715/Macro_1.scala +++ b/tests/run-macros/i5715/Macro_1.scala @@ -5,8 +5,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ cond.unseal.underlyingArgument match { case app @ Apply(sel @ Select(lhs, op), rhs :: Nil) => diff --git a/tests/run-macros/i5941/macro_1.scala b/tests/run-macros/i5941/macro_1.scala index 15a9c87db863..d715206cecf0 100644 --- a/tests/run-macros/i5941/macro_1.scala +++ b/tests/run-macros/i5941/macro_1.scala @@ -12,8 +12,8 @@ object Lens { def set(t: T, s: S): S = _set(t)(s) } - def impl[S: Type, T: Type](getter: Expr[S => T])(implicit refl: Reflection): Expr[Lens[S, T]] = { - import refl._ + def impl[S: Type, T: Type](getter: Expr[S => T]) given (qctx: QuoteContext): Expr[Lens[S, T]] = { + import qctx.tasty._ import util._ // obj.copy(a = obj.a.copy(b = a.b.copy(c = v))) @@ -90,8 +90,8 @@ object Iso { def to(s: S): A = _to(s) } - def impl[S: Type, A: Type](implicit refl: Reflection): Expr[Iso[S, A]] = { - import refl._ + def impl[S: Type, A: Type] given (qctx: QuoteContext): Expr[Iso[S, A]] = { + import qctx.tasty._ import util._ val tpS = typeOf[S] @@ -126,8 +126,8 @@ object Iso { } } - def implUnit[S: Type](implicit refl: Reflection): Expr[Iso[S, 1]] = { - import refl._ + def implUnit[S: Type] given (qctx: QuoteContext): Expr[Iso[S, 1]] = { + import qctx.tasty._ import util._ val tpS = typeOf[S] @@ -161,7 +161,7 @@ object Iso { } // TODO: require whitebox macro - def implFields[S: Type](implicit refl: Reflection): Expr[Iso[S, Any]] = ??? + def implFields[S: Type] given (qctx: QuoteContext): Expr[Iso[S, Any]] = ??? } object GenIso { @@ -196,8 +196,8 @@ object Prism { def apply(a: A): S = app(a) } - def impl[S: Type, A <: S : Type](implicit refl: Reflection): Expr[Prism[S, A]] = { - import refl._ + def impl[S: Type, A <: S : Type] given (qctx: QuoteContext): Expr[Prism[S, A]] = { + import qctx.tasty._ import util._ '{ diff --git a/tests/run-macros/i6171/Macro_1.scala b/tests/run-macros/i6171/Macro_1.scala index 1d83825d0f4e..67ae0babb46a 100644 --- a/tests/run-macros/i6171/Macro_1.scala +++ b/tests/run-macros/i6171/Macro_1.scala @@ -5,8 +5,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ import util._ def isImplicitMethodType(tp: Type): Boolean = diff --git a/tests/run-macros/i6253-b/quoted_1.scala b/tests/run-macros/i6253-b/quoted_1.scala index baeea7df659d..160892a8c855 100644 --- a/tests/run-macros/i6253-b/quoted_1.scala +++ b/tests/run-macros/i6253-b/quoted_1.scala @@ -7,7 +7,7 @@ object Macros { inline def (self: => StringContext) xyz(args: => String*): String = ${impl('self, 'args)} - private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(implicit reflect: Reflection): Expr[String] = { + private def impl(self: Expr[StringContext], args: Expr[Seq[String]]) given QuoteContext: Expr[String] = { self match { case '{ StringContext($parts: _*) } => '{ diff --git a/tests/run-macros/i6253/quoted_1.scala b/tests/run-macros/i6253/quoted_1.scala index e3162fd042de..0e57a5d6cf09 100644 --- a/tests/run-macros/i6253/quoted_1.scala +++ b/tests/run-macros/i6253/quoted_1.scala @@ -7,7 +7,7 @@ object Macros { inline def (self: => StringContext) xyz(args: => String*): String = ${impl('self, 'args)} - private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(implicit reflect: Reflection): Expr[String] = { + private def impl(self: Expr[StringContext], args: Expr[Seq[String]]) given QuoteContext: Expr[String] = { self match { case '{ StringContext($parts: _*) } => '{ StringContext($parts: _*).s($args: _*) } diff --git a/tests/run-macros/i6518/Macro_1.scala b/tests/run-macros/i6518/Macro_1.scala index 48e134762919..10d77ce49eee 100644 --- a/tests/run-macros/i6518/Macro_1.scala +++ b/tests/run-macros/i6518/Macro_1.scala @@ -6,8 +6,8 @@ object Macros { inline def test(): String = ${ testImpl } - private def testImpl(implicit reflect: Reflection): Expr[String] = { - import reflect._ + private def testImpl given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ val classSym = typeOf[Function1[_, _]].classSymbol.get classSym.classMethod("apply") classSym.classMethods diff --git a/tests/run-macros/inferred-repeated-result/test_1.scala b/tests/run-macros/inferred-repeated-result/test_1.scala index e1e2404a8555..5a353c4712b7 100644 --- a/tests/run-macros/inferred-repeated-result/test_1.scala +++ b/tests/run-macros/inferred-repeated-result/test_1.scala @@ -4,8 +4,8 @@ object Macros { import scala.tasty._ inline def go[T](t: => T) = ${ impl('t) } - def impl[T](expr: Expr[T])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl[T](expr: Expr[T]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = expr.unseal diff --git a/tests/run-macros/quote-impure-by-name/quoted_1.scala b/tests/run-macros/quote-impure-by-name/quoted_1.scala index 947521db9f98..b6a6fa0b4093 100644 --- a/tests/run-macros/quote-impure-by-name/quoted_1.scala +++ b/tests/run-macros/quote-impure-by-name/quoted_1.scala @@ -12,8 +12,7 @@ object Index { implicit inline def succ[K, H, T](implicit prev: => Index[K, T]): Index[K, (H, T)] = ${ succImpl[K, H, T]('prev) } - def succImpl[K, H, T](prev: Expr[Index[K, T]])(implicit k: Type[K], h: Type[H], t: Type[T], relection: Reflection): Expr[Index[K, (H, T)]] = { - import relection._ + def succImpl[K: Type, H: Type, T: Type](prev: Expr[Index[K, T]]) given QuoteContext: Expr[Index[K, (H, T)]] = { val value = s"1 + {${prev.show}}" '{new Index(${value})} } diff --git a/tests/run-macros/quote-inline-function/quoted_1.scala b/tests/run-macros/quote-inline-function/quoted_1.scala index e5d6ebee92f3..92669be3d12d 100644 --- a/tests/run-macros/quote-inline-function/quoted_1.scala +++ b/tests/run-macros/quote-inline-function/quoted_1.scala @@ -7,8 +7,8 @@ object Macros { inline def foreach1(start: Int, end: Int, f: Int => Unit): String = ${impl('start, 'end, 'f)} inline def foreach2(start: Int, end: Int, f: => Int => Unit): String = ${impl('start, 'end, 'f)} - def impl(start: Expr[Int], end: Expr[Int], f: Expr[Int => Unit])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + def impl(start: Expr[Int], end: Expr[Int], f: Expr[Int => Unit]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ val res = '{ var i = $start val j = $end diff --git a/tests/run-macros/quote-matcher-runtime/quoted_1.scala b/tests/run-macros/quote-matcher-runtime/quoted_1.scala index 8e2ef4d8a071..e23939bcdecb 100644 --- a/tests/run-macros/quote-matcher-runtime/quoted_1.scala +++ b/tests/run-macros/quote-matcher-runtime/quoted_1.scala @@ -7,10 +7,10 @@ object Macros { inline def matches[A, B](a: => A, b: => B): Unit = ${impl('a, 'b)} - private def impl[A, B](a: Expr[A], b: Expr[B])(implicit reflect: Reflection): Expr[Unit] = { - import reflect.{Bind => _, _} + private def impl[A, B](a: Expr[A], b: Expr[B]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty.{Bind => _, _} - val res = scala.internal.quoted.Matcher.unapply[Tuple](a)(b, reflect).map { tup => + val res = scala.internal.quoted.Matcher.unapply[Tuple](a)(b, qctx).map { tup => tup.toArray.toList.map { case r: Expr[_] => s"Expr(${r.unseal.show})" diff --git a/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala b/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala index 0aad1b3532ca..62413775fe02 100644 --- a/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala +++ b/tests/run-macros/quote-matcher-string-interpolator-2/quoted_1.scala @@ -7,7 +7,7 @@ object Macros { inline def (self: => StringContext) xyz(args: => String*): String = ${impl('self, 'args)} - private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(implicit reflect: Reflection): Expr[String] = { + private def impl(self: Expr[StringContext], args: Expr[Seq[String]]) given QuoteContext: Expr[String] = { (self, args) match { case ('{ StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args1)) => val strParts = parts.map { case Const(str) => str.reverse } diff --git a/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala b/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala index 2b98a358cd68..d04ce3225687 100644 --- a/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala +++ b/tests/run-macros/quote-matcher-string-interpolator-3/quoted_1.scala @@ -7,7 +7,7 @@ object Macros { inline def (self: => StringContext) S(args: => String*): String = ${impl('self, 'args)} - private def impl(self: Expr[StringContext], args: Expr[Seq[String]]) given Reflection: Expr[String] = { + private def impl(self: Expr[StringContext], args: Expr[Seq[String]]) given QuoteContext: Expr[String] = { self match { case '{ StringContext(${ConstSeq(parts)}: _*) } => val upprerParts: List[String] = parts.toList.map(_.toUpperCase) diff --git a/tests/run-macros/quote-matcher-string-interpolator/quoted_1.scala b/tests/run-macros/quote-matcher-string-interpolator/quoted_1.scala index 4f5fe71778f4..beab437e983f 100644 --- a/tests/run-macros/quote-matcher-string-interpolator/quoted_1.scala +++ b/tests/run-macros/quote-matcher-string-interpolator/quoted_1.scala @@ -7,7 +7,7 @@ object Macros { inline def (self: => StringContext) xyz(args: => String*): String = ${impl('self, 'args)} - private def impl(self: Expr[StringContext], args: Expr[Seq[String]])(implicit reflect: Reflection): Expr[String] = { + private def impl(self: Expr[StringContext], args: Expr[Seq[String]]) given QuoteContext: Expr[String] = { self match { case '{ StringContext(${ExprSeq(parts)}: _*) } => val parts2 = parts.map(x => '{ $x.reverse }).toList.toExprOfList diff --git a/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala index a0203b4a3196..8658580efe29 100644 --- a/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala @@ -9,7 +9,7 @@ object Macros { inline def lift[T](sym: Symantics[T])(a: => DSL): T = ${impl[T]('sym, 'a)} - private def impl[T: Type](sym: Expr[Symantics[T]], a: Expr[DSL])(implicit reflect: Reflection): Expr[T] = { + private def impl[T: Type](sym: Expr[Symantics[T]], a: Expr[DSL]) given (qctx: QuoteContext): Expr[T] = { def lift(e: Expr[DSL]): Expr[T] = e match { @@ -26,7 +26,7 @@ object Macros { '{ $sym.times(${lift(x)}, ${lift(y)}) } case _ => - import reflect._ + import qctx.tasty._ error("Expected explicit DSL", e.unseal.pos) '{ ??? } diff --git a/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala index b8ca2125a33b..a7666247db05 100644 --- a/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala @@ -1,8 +1,6 @@ import scala.quoted._ import scala.quoted.matching._ -import scala.tasty.Reflection - object Macros { inline def liftString(a: => DSL): String = ${impl(StringNum, 'a)} @@ -11,7 +9,7 @@ object Macros { inline def liftAST(a: => DSL): ASTNum = ${impl(ASTNum, 'a)} - private def impl[T: Type](sym: Symantics[T], a: Expr[DSL])(implicit reflect: Reflection): Expr[T] = { + private def impl[T: Type](sym: Symantics[T], a: Expr[DSL]) given (qctx: QuoteContext): Expr[T] = { def lift(e: Expr[DSL])(implicit env: Map[Bind[DSL], Expr[T]]): Expr[T] = e match { @@ -28,7 +26,7 @@ object Macros { case Bind(b) if env.contains(b) => env(b) case _ => - import reflect._ + import qctx.tasty._ error("Expected explicit DSL", e.unseal.pos) ??? } @@ -38,7 +36,7 @@ object Macros { sym.lam((y: Expr[T]) => lift(body)(env + (x -> y))) case _ => - import reflect._ + import qctx.tasty._ error("Expected explicit DSL => DSL", e.unseal.pos) ??? } diff --git a/tests/run-macros/quoted-expr-block/quoted_1.scala b/tests/run-macros/quoted-expr-block/quoted_1.scala index 06a6b4036043..d405938d058b 100644 --- a/tests/run-macros/quoted-expr-block/quoted_1.scala +++ b/tests/run-macros/quoted-expr-block/quoted_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ inline def replicate(inline times: Int, code: => Any) = ${replicateImpl(times, 'code)} -private def replicateImpl(times: Int, code: Expr[Any]) given tasty.Reflection = { +private def replicateImpl(times: Int, code: Expr[Any]) given QuoteContext = { @annotation.tailrec def loop(n: Int, accum: List[Expr[Any]]): List[Expr[Any]] = if (n > 0) loop(n - 1, code :: accum) else accum Expr.block(loop(times, Nil), '{}) diff --git a/tests/run-macros/reflect-dsl/assert_1.scala b/tests/run-macros/reflect-dsl/assert_1.scala index f1e60b925e0b..837e568651cf 100644 --- a/tests/run-macros/reflect-dsl/assert_1.scala +++ b/tests/run-macros/reflect-dsl/assert_1.scala @@ -5,8 +5,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ import util._ def isImplicitMethodType(tp: Type): Boolean = diff --git a/tests/run-macros/reflect-isFunctionType/macro_1.scala b/tests/run-macros/reflect-isFunctionType/macro_1.scala index 19f4a0a34aaf..c9522f9a0ce5 100644 --- a/tests/run-macros/reflect-isFunctionType/macro_1.scala +++ b/tests/run-macros/reflect-isFunctionType/macro_1.scala @@ -4,31 +4,31 @@ import scala.tasty._ inline def isFunctionType[T:Type]: Boolean = ${ isFunctionTypeImpl('[T]) } -def isFunctionTypeImpl[T](tp: Type[T])(implicit refl: Reflection): Expr[Boolean] = { - import refl._ +def isFunctionTypeImpl[T](tp: Type[T]) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ tp.unseal.tpe.isFunctionType.toExpr } inline def isImplicitFunctionType[T:Type]: Boolean = ${ isImplicitFunctionTypeImpl('[T]) } -def isImplicitFunctionTypeImpl[T](tp: Type[T])(implicit refl: Reflection): Expr[Boolean] = { - import refl._ +def isImplicitFunctionTypeImpl[T](tp: Type[T]) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ tp.unseal.tpe.isImplicitFunctionType.toExpr } inline def isErasedFunctionType[T:Type]: Boolean = ${ isErasedFunctionTypeImpl('[T]) } -def isErasedFunctionTypeImpl[T](tp: Type[T])(implicit refl: Reflection): Expr[Boolean] = { - import refl._ +def isErasedFunctionTypeImpl[T](tp: Type[T]) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ tp.unseal.tpe.isErasedFunctionType.toExpr } inline def isDependentFunctionType[T:Type]: Boolean = ${ isDependentFunctionTypeImpl('[T]) } -def isDependentFunctionTypeImpl[T](tp: Type[T])(implicit refl: Reflection): Expr[Boolean] = { - import refl._ +def isDependentFunctionTypeImpl[T](tp: Type[T]) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ tp.unseal.tpe.isDependentFunctionType.toExpr } diff --git a/tests/run-macros/reflect-pos-fun/assert_1.scala b/tests/run-macros/reflect-pos-fun/assert_1.scala index 298f0891c93d..6e418b676f9f 100644 --- a/tests/run-macros/reflect-pos-fun/assert_1.scala +++ b/tests/run-macros/reflect-pos-fun/assert_1.scala @@ -5,8 +5,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition) } - def assertImpl(cond: Expr[Boolean])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(cond: Expr[Boolean]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ import util._ cond.unseal.underlyingArgument match { diff --git a/tests/run-macros/reflect-select-constructor/assert_1.scala b/tests/run-macros/reflect-select-constructor/assert_1.scala index f73a53a5937c..bd33d6ac2d35 100644 --- a/tests/run-macros/reflect-select-constructor/assert_1.scala +++ b/tests/run-macros/reflect-select-constructor/assert_1.scala @@ -5,8 +5,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ import util._ def isImplicitMethodType(tp: Type): Boolean = diff --git a/tests/run-macros/reflect-select-copy/assert_1.scala b/tests/run-macros/reflect-select-copy/assert_1.scala index 56a489edb7be..87e0252e1506 100644 --- a/tests/run-macros/reflect-select-copy/assert_1.scala +++ b/tests/run-macros/reflect-select-copy/assert_1.scala @@ -5,8 +5,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ cond.unseal.underlyingArgument match { case Apply(sel @ Select(lhs, op), rhs :: Nil) => diff --git a/tests/run-macros/reflect-select-copy/reflect-select-copy/assert_1.scala b/tests/run-macros/reflect-select-copy/reflect-select-copy/assert_1.scala index b8a9d7f0e5b3..4ee21ff1cb3d 100644 --- a/tests/run-macros/reflect-select-copy/reflect-select-copy/assert_1.scala +++ b/tests/run-macros/reflect-select-copy/reflect-select-copy/assert_1.scala @@ -5,8 +5,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ import util._ def isImplicitMethodType(tp: Type): Boolean = diff --git a/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala b/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala index 140f890dd102..27541de03230 100644 --- a/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala +++ b/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala @@ -5,8 +5,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ import util._ def isImplicitMethodType(tp: Type): Boolean = diff --git a/tests/run-macros/reflect-select-value-class/assert_1.scala b/tests/run-macros/reflect-select-value-class/assert_1.scala index f73a53a5937c..bd33d6ac2d35 100644 --- a/tests/run-macros/reflect-select-value-class/assert_1.scala +++ b/tests/run-macros/reflect-select-value-class/assert_1.scala @@ -5,8 +5,8 @@ object scalatest { inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition, '{""}) } - def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(cond: Expr[Boolean], clue: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ import util._ def isImplicitMethodType(tp: Type): Boolean = diff --git a/tests/run-macros/reflect-typeChecks/assert_1.scala b/tests/run-macros/reflect-typeChecks/assert_1.scala index b9ab4733bbfe..1f65f528f31e 100644 --- a/tests/run-macros/reflect-typeChecks/assert_1.scala +++ b/tests/run-macros/reflect-typeChecks/assert_1.scala @@ -6,8 +6,8 @@ object scalatest { inline def assertCompile(inline code: String): Unit = ${ assertImpl(code, true) } inline def assertNotCompile(inline code: String): Unit = ${ assertImpl(code, false) } - def assertImpl(code: String, expect: Boolean)(implicit refl: Reflection): Expr[Unit] = { - import refl._ + def assertImpl(code: String, expect: Boolean) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val actual = typing.typeChecks(code) diff --git a/tests/run-macros/tasty-argument-tree-1/quoted_1.scala b/tests/run-macros/tasty-argument-tree-1/quoted_1.scala index bd3326147e58..145c3ee0be82 100644 --- a/tests/run-macros/tasty-argument-tree-1/quoted_1.scala +++ b/tests/run-macros/tasty-argument-tree-1/quoted_1.scala @@ -7,8 +7,8 @@ object Macros { inline def inspect[T](x: T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl[T](x: Expr[T]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = x.unseal '{ println() diff --git a/tests/run-macros/tasty-custom-show/quoted_1.scala b/tests/run-macros/tasty-custom-show/quoted_1.scala index a0b25049478d..7ec8c7255815 100644 --- a/tests/run-macros/tasty-custom-show/quoted_1.scala +++ b/tests/run-macros/tasty-custom-show/quoted_1.scala @@ -8,8 +8,8 @@ object Macros { implicit inline def printOwners[T](x: => T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl[T](x: Expr[T]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val buff = new StringBuilder @@ -39,15 +39,15 @@ object Macros { '{print(${buff.result()})} } - def dummyShow(implicit reflect: Reflection): reflect.Printer = { - import reflect._ + def dummyShow given (qctx: QuoteContext): qctx.tasty.Printer = { + import qctx.tasty._ new Printer { def showTree(tree: Tree)(implicit ctx: Context): String = "Tree" def showPattern(pattern: Pattern)(implicit ctx: Context): String = "Pattern" def showTypeOrBounds(tpe: TypeOrBounds)(implicit ctx: Context): String = "TypeOrBounds" def showConstant(const: Constant)(implicit ctx: Context): String = "Constant" def showSymbol(symbol: Symbol)(implicit ctx: Context): String = "Symbol" - def showFlags(flags: Flags)(implicit ctx: reflect.Context): String = "Flags" + def showFlags(flags: Flags)(implicit ctx: Context): String = "Flags" } } diff --git a/tests/run-macros/tasty-dealias/quoted_1.scala b/tests/run-macros/tasty-dealias/quoted_1.scala index 6db89647e58a..753e4e75bcd5 100644 --- a/tests/run-macros/tasty-dealias/quoted_1.scala +++ b/tests/run-macros/tasty-dealias/quoted_1.scala @@ -5,8 +5,8 @@ object Macros { inline def dealias[T]: String = ${ impl('[T]) } - def impl[T](x: quoted.Type[T])(implicit reflect: Reflection): Expr[String] = { - import reflect._ + def impl[T](x: quoted.Type[T]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ x.unseal.tpe.dealias.show.toExpr } } diff --git a/tests/run-macros/tasty-definitions-1/quoted_1.scala b/tests/run-macros/tasty-definitions-1/quoted_1.scala index 44dba48ec467..f3edcaa18530 100644 --- a/tests/run-macros/tasty-definitions-1/quoted_1.scala +++ b/tests/run-macros/tasty-definitions-1/quoted_1.scala @@ -7,8 +7,8 @@ object Macros { inline def testDefinitions(): Unit = ${testDefinitionsImpl} - def testDefinitionsImpl(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def testDefinitionsImpl given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val buff = List.newBuilder[String] def printout(x: => String): Unit = { diff --git a/tests/run-macros/tasty-eval/quoted_1.scala b/tests/run-macros/tasty-eval/quoted_1.scala index 2ba5f2424f35..826e118211b9 100644 --- a/tests/run-macros/tasty-eval/quoted_1.scala +++ b/tests/run-macros/tasty-eval/quoted_1.scala @@ -8,19 +8,19 @@ object Macros { implicit inline def foo(i: Int): String = ${ impl('i) } - def impl(i: Expr[Int])(implicit reflect: Reflection): Expr[String] = { + def impl(i: Expr[Int]) given QuoteContext: Expr[String] = { value(i).toString } - inline implicit def value[X](e: Expr[X])(implicit reflect: Reflection, ev: Valuable[X]): Option[X] = ev.value(e) + inline implicit def value[X](e: Expr[X])(implicit qctx: QuoteContext, ev: Valuable[X]): Option[X] = ev.value(e) trait Valuable[X] { - def value(e: Expr[X])(implicit reflect: Reflection): Option[X] + def value(e: Expr[X]) given QuoteContext: Option[X] } implicit def intIsEvalable: Valuable[Int] = new Valuable[Int] { - override def value(e: Expr[Int])(implicit reflect: Reflection): Option[Int] = { - import reflect._ + override def value(e: Expr[Int]) given (qctx: QuoteContext): Option[Int] = { + import qctx.tasty._ e.unseal.tpe match { case Type.SymRef(IsValDefSymbol(sym), pre) => diff --git a/tests/run-macros/tasty-extractors-1/quoted_1.scala b/tests/run-macros/tasty-extractors-1/quoted_1.scala index 01f821d86b20..f35e3fbe3ea2 100644 --- a/tests/run-macros/tasty-extractors-1/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-1/quoted_1.scala @@ -8,8 +8,8 @@ object Macros { implicit inline def printTree[T](x: => T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl[T](x: Expr[T]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = x.unseal val treeStr = tree.showExtractors diff --git a/tests/run-macros/tasty-extractors-2/quoted_1.scala b/tests/run-macros/tasty-extractors-2/quoted_1.scala index 0743500f210c..5a6b8dedf802 100644 --- a/tests/run-macros/tasty-extractors-2/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-2/quoted_1.scala @@ -8,8 +8,8 @@ object Macros { implicit inline def printTree[T](x: => T): Unit = ${ impl('x) } - def impl[T](x: Expr[T])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl[T](x: Expr[T]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = x.unseal diff --git a/tests/run-macros/tasty-extractors-3/quoted_1.scala b/tests/run-macros/tasty-extractors-3/quoted_1.scala index b46d59f8744d..531f95f15313 100644 --- a/tests/run-macros/tasty-extractors-3/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-3/quoted_1.scala @@ -8,8 +8,8 @@ object Macros { implicit inline def printTypes[T](x: => T): Unit = ${impl('x)} - def impl[T](x: Expr[T])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl[T](x: Expr[T]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val buff = new StringBuilder val traverser = new TreeTraverser { diff --git a/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala b/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala index 7fbb2a96bde6..19730a72fca9 100644 --- a/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-constants-1/quoted_1.scala @@ -10,7 +10,7 @@ object Macros { implicit inline def testMacro: Unit = ${impl} - def impl(implicit reflect: Reflection): Expr[Unit] = { + def impl given QuoteContext: Expr[Unit] = { val buff = new StringBuilder def stagedPrintln(x: Any): Unit = buff append java.util.Objects.toString(x) append "\n" diff --git a/tests/run-macros/tasty-extractors-types/quoted_1.scala b/tests/run-macros/tasty-extractors-types/quoted_1.scala index 39f065026123..97243af0b9c7 100644 --- a/tests/run-macros/tasty-extractors-types/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-types/quoted_1.scala @@ -7,8 +7,8 @@ object Macros { implicit inline def printType[T]: Unit = ${ impl('[T]) } - def impl[T](x: Type[T])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl[T](x: Type[T]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = x.unseal '{ diff --git a/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala b/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala index efd7289fc89e..7c17e3fac9d9 100644 --- a/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala +++ b/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala @@ -1,19 +1,17 @@ import scala.quoted._ import scala.quoted.autolift._ -import scala.tasty.Reflection - object SourceFiles { - type Macro[X] = given Reflection => Expr[X] - def tastyContext(implicit ctx: Reflection): Reflection = ctx + type Macro[X] = given QuoteContext => Expr[X] + def tastyContext given (qctx: QuoteContext): QuoteContext = qctx implicit inline def getThisFile: String = ${getThisFileImpl} def getThisFileImpl: Macro[String] = { - val reflect = tastyContext - import reflect._ + val qctx = tastyContext + import qctx.tasty._ rootContext.source.getFileName.toString } diff --git a/tests/run-macros/tasty-getfile/Macro_1.scala b/tests/run-macros/tasty-getfile/Macro_1.scala index d9ae5d0b790f..a5959ae486a9 100644 --- a/tests/run-macros/tasty-getfile/Macro_1.scala +++ b/tests/run-macros/tasty-getfile/Macro_1.scala @@ -8,8 +8,8 @@ object SourceFiles { implicit inline def getThisFile: String = ${getThisFileImpl} - private def getThisFileImpl(implicit reflect: Reflection): Expr[String] = { - import reflect._ + private def getThisFileImpl given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ rootContext.source.getFileName.toString } diff --git a/tests/run-macros/tasty-implicit-fun-context-2/Macro_1.scala b/tests/run-macros/tasty-implicit-fun-context-2/Macro_1.scala index 9d1713005148..8dc4b4643009 100644 --- a/tests/run-macros/tasty-implicit-fun-context-2/Macro_1.scala +++ b/tests/run-macros/tasty-implicit-fun-context-2/Macro_1.scala @@ -3,13 +3,13 @@ import scala.tasty.Reflection object Foo { - type Macro[X] = given Reflection => Expr[X] - type Tastier[X] = given Reflection => X + type Macro[X] = given QuoteContext => Expr[X] + type Tastier[X] = given QuoteContext => X implicit inline def foo: String = ${fooImpl} - def fooImpl(implicit reflect: Reflection): given Reflection => Tastier[given Reflection => Macro[String]] = { + def fooImpl given QuoteContext: given QuoteContext => Tastier[given QuoteContext => Macro[String]] = { '{"abc"} } diff --git a/tests/run-macros/tasty-indexed-map/quoted_1.scala b/tests/run-macros/tasty-indexed-map/quoted_1.scala index 2e2b6a00517b..9974db0f76bc 100644 --- a/tests/run-macros/tasty-indexed-map/quoted_1.scala +++ b/tests/run-macros/tasty-indexed-map/quoted_1.scala @@ -27,8 +27,8 @@ object Index { implicit inline def succ[K, H, T](implicit prev: => Index[K, T]): Index[K, (H, T)] = ${succImpl[K, H, T]} - def succImpl[K, H, T](implicit reflect: Reflection, k: Type[K], h: Type[H], t: Type[T]): Expr[Index[K, (H, T)]] = { - import reflect._ + def succImpl[K, H, T](implicit qctx: QuoteContext, k: Type[K], h: Type[H], t: Type[T]): Expr[Index[K, (H, T)]] = { + import qctx.tasty._ def name(tp: TypeOrBounds): String = tp match { case Type.ConstantType(Constant.String(str)) => str diff --git a/tests/run-macros/tasty-interpolation-1/Macro.scala b/tests/run-macros/tasty-interpolation-1/Macro.scala index 099a9c766853..56bca47ca958 100644 --- a/tests/run-macros/tasty-interpolation-1/Macro.scala +++ b/tests/run-macros/tasty-interpolation-1/Macro.scala @@ -15,24 +15,24 @@ object Macro { } object SIntepolator extends MacroStringInterpolator[String] { - protected def interpolate(strCtx: StringContext, args: List[Expr[Any]])(implicit reflect: Reflection): Expr[String] = + protected def interpolate(strCtx: StringContext, args: List[Expr[Any]]) given QuoteContext: Expr[String] = '{(${strCtx}).s(${args.toExprOfList}: _*)} } object RawIntepolator extends MacroStringInterpolator[String] { - protected def interpolate(strCtx: StringContext, args: List[Expr[Any]])(implicit reflect: Reflection): Expr[String] = + protected def interpolate(strCtx: StringContext, args: List[Expr[Any]]) given QuoteContext: Expr[String] = '{(${strCtx}).raw(${args.toExprOfList}: _*)} } object FooIntepolator extends MacroStringInterpolator[String] { - protected def interpolate(strCtx: StringContext, args: List[Expr[Any]])(implicit reflect: Reflection): Expr[String] = + protected def interpolate(strCtx: StringContext, args: List[Expr[Any]]) given QuoteContext: Expr[String] = '{(${strCtx}).s(${args.map(_ => '{"foo"}).toExprOfList}: _*)} } // TODO put this class in the stdlib or separate project? abstract class MacroStringInterpolator[T] { - final def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(implicit reflect: Reflection): Expr[T] = { + final def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given QuoteContext: Expr[T] = { try interpolate(strCtxExpr, argsExpr) catch { case ex: NotStaticlyKnownError => @@ -47,13 +47,13 @@ abstract class MacroStringInterpolator[T] { } } - protected def interpolate(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(implicit reflect: Reflection): Expr[T] = + protected def interpolate(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given QuoteContext: Expr[T] = interpolate(getStaticStringContext(strCtxExpr), getArgsList(argsExpr)) - protected def interpolate(strCtx: StringContext, argExprs: List[Expr[Any]])(implicit reflect: Reflection): Expr[T] + protected def interpolate(strCtx: StringContext, argExprs: List[Expr[Any]]) given QuoteContext: Expr[T] - protected def getStaticStringContext(strCtxExpr: Expr[StringContext])(implicit reflect: Reflection): StringContext = { - import reflect._ + protected def getStaticStringContext(strCtxExpr: Expr[StringContext]) given (qctx: QuoteContext): StringContext = { + import qctx.tasty._ strCtxExpr.unseal.underlyingArgument match { case Select(Typed(Apply(_, List(Apply(_, List(Typed(Repeated(strCtxArgTrees, _), Inferred()))))), _), _) => val strCtxArgs = strCtxArgTrees.map { @@ -66,8 +66,8 @@ abstract class MacroStringInterpolator[T] { } } - protected def getArgsList(argsExpr: Expr[Seq[Any]])(implicit reflect: Reflection): List[Expr[Any]] = { - import reflect._ + protected def getArgsList(argsExpr: Expr[Seq[Any]]) given (qctx: QuoteContext): List[Expr[Any]] = { + import qctx.tasty._ argsExpr.unseal.underlyingArgument match { case Typed(Repeated(args, _), _) => args.map(_.seal) case tree => throw new NotStaticlyKnownError("Expected statically known argument list", tree.seal) diff --git a/tests/run-macros/tasty-linenumber-2/quoted_1.scala b/tests/run-macros/tasty-linenumber-2/quoted_1.scala index 9ed4720466f9..eaf1c379c523 100644 --- a/tests/run-macros/tasty-linenumber-2/quoted_1.scala +++ b/tests/run-macros/tasty-linenumber-2/quoted_1.scala @@ -11,8 +11,8 @@ object LineNumber { implicit inline def line: LineNumber = ${lineImpl} - def lineImpl(implicit reflect: Reflection): Expr[LineNumber] = { - import reflect._ + def lineImpl given (qctx: QuoteContext): Expr[LineNumber] = { + import qctx.tasty._ '{new LineNumber(${rootPosition.startLine})} } diff --git a/tests/run-macros/tasty-linenumber/quoted_1.scala b/tests/run-macros/tasty-linenumber/quoted_1.scala index 67192075dd28..520fe9ea5752 100644 --- a/tests/run-macros/tasty-linenumber/quoted_1.scala +++ b/tests/run-macros/tasty-linenumber/quoted_1.scala @@ -12,8 +12,8 @@ object LineNumber { implicit inline def line[T >: Unit <: Unit]: LineNumber = ${lineImpl('[T])} - def lineImpl(x: Type[Unit])(implicit reflect: Reflection): Expr[LineNumber] = { - import reflect._ + def lineImpl(x: Type[Unit]) given (qctx: QuoteContext): Expr[LineNumber] = { + import qctx.tasty._ '{new LineNumber(${rootPosition.startLine})} } diff --git a/tests/run-macros/tasty-location/quoted_1.scala b/tests/run-macros/tasty-location/quoted_1.scala index bd4a7138fcc3..849425e6c832 100644 --- a/tests/run-macros/tasty-location/quoted_1.scala +++ b/tests/run-macros/tasty-location/quoted_1.scala @@ -9,8 +9,8 @@ object Location { implicit inline def location: Location = ${impl} - def impl(implicit reflect: Reflection): Expr[Location] = { - import reflect._ + def impl given (qctx: QuoteContext): Expr[Location] = { + import qctx.tasty._ def listOwnerNames(sym: Symbol, acc: List[String]): List[String] = if (sym == definitions.RootClass || sym == definitions.EmptyPackageClass) acc diff --git a/tests/run-macros/tasty-macro-assert/quoted_1.scala b/tests/run-macros/tasty-macro-assert/quoted_1.scala index e81cc01473da..33d929f61c8f 100644 --- a/tests/run-macros/tasty-macro-assert/quoted_1.scala +++ b/tests/run-macros/tasty-macro-assert/quoted_1.scala @@ -14,8 +14,8 @@ object Asserts { inline def macroAssert(cond: => Boolean): Unit = ${impl('cond)} - def impl(cond: Expr[Boolean])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl(cond: Expr[Boolean]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val tree = cond.unseal diff --git a/tests/run-macros/tasty-macro-const/quoted_1.scala b/tests/run-macros/tasty-macro-const/quoted_1.scala index 51f7bc31af81..29e5638a6bdc 100644 --- a/tests/run-macros/tasty-macro-const/quoted_1.scala +++ b/tests/run-macros/tasty-macro-const/quoted_1.scala @@ -5,8 +5,8 @@ object Macros { inline def natConst(x: Int): Int = ${ natConstImpl('x) } - def natConstImpl(x: Expr[Int])(implicit reflection: Reflection): Expr[Int] = { - import reflection._ + def natConstImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[Int] = { + import qctx.tasty._ val xTree: Term = x.unseal xTree match { case Inlined(_, _, Literal(Constant.Int(n))) => diff --git a/tests/run-macros/tasty-macro-positions/quoted_1.scala b/tests/run-macros/tasty-macro-positions/quoted_1.scala index f8cb071a9bee..3661d24fc9b2 100644 --- a/tests/run-macros/tasty-macro-positions/quoted_1.scala +++ b/tests/run-macros/tasty-macro-positions/quoted_1.scala @@ -10,28 +10,28 @@ object Macros { inline def fun3[T]: Unit = ${ impl2('[T]) } - def impl(x: Expr[Any])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl(x: Expr[Any]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val pos = x.unseal.underlyingArgument.pos val code = x.unseal.underlyingArgument.show '{ - println(${posStr(reflect)(pos)}) + println(${posStr(qctx)(pos)}) println(${code.toExpr}) } } - def impl2[T](x: quoted.Type[T])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + def impl2[T](x: quoted.Type[T]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val pos = x.unseal.pos val code = x.unseal.show '{ - println(${posStr(reflect)(pos)}) + println(${posStr(qctx)(pos)}) println(${code.toExpr}) } } - def posStr(relfection: Reflection)(pos: relfection.Position): Expr[String] = { - import relfection._ + def posStr(qctx: QuoteContext)(pos: qctx.tasty.Position): Expr[String] = { + import qctx.tasty._ s"${pos.sourceFile.jpath.getFileName.toString}:[${pos.start}..${pos.end}]".toExpr } } diff --git a/tests/run-macros/tasty-original-source/Macros_1.scala b/tests/run-macros/tasty-original-source/Macros_1.scala index 27229744dfcb..5d2cf19fbd6c 100644 --- a/tests/run-macros/tasty-original-source/Macros_1.scala +++ b/tests/run-macros/tasty-original-source/Macros_1.scala @@ -7,8 +7,8 @@ object Macros { implicit inline def withSource(arg: Any): (String, Any) = ${ impl('arg) } - private def impl(arg: Expr[Any])(implicit reflect: Reflection): Expr[(String, Any)] = { - import reflect._ + private def impl(arg: Expr[Any]) given (qctx: QuoteContext): Expr[(String, Any)] = { + import qctx.tasty._ val source = arg.unseal.underlyingArgument.pos.sourceCode.toString '{Tuple2($source, $arg)} } diff --git a/tests/run-macros/tasty-positioned/quoted_1.scala b/tests/run-macros/tasty-positioned/quoted_1.scala index 5e1473f8c93c..45ab025a8c8f 100644 --- a/tests/run-macros/tasty-positioned/quoted_1.scala +++ b/tests/run-macros/tasty-positioned/quoted_1.scala @@ -1,8 +1,6 @@ import scala.quoted._ import scala.quoted.autolift._ -import scala.tasty._ - case class Position(path: String, start: Int, end: Int, startLine: Int, startColumn: Int, endLine: Int, endColumn: Int) @@ -12,8 +10,8 @@ object Positioned { implicit inline def apply[T](x: => T): Positioned[T] = ${impl('x)} - def impl[T](x: Expr[T])(implicit ev: Type[T], reflect: Reflection): Expr[Positioned[T]] = { - import reflect.{Position => _, _} + def impl[T](x: Expr[T])(implicit ev: Type[T], qctx: QuoteContext): Expr[Positioned[T]] = { + import qctx.tasty.{Position => _, _} val pos = rootPosition val path = pos.sourceFile.jpath.toString diff --git a/tests/run-macros/tasty-seal-method/quoted_1.scala b/tests/run-macros/tasty-seal-method/quoted_1.scala index 2713d4979f6f..75ffa8a4b201 100644 --- a/tests/run-macros/tasty-seal-method/quoted_1.scala +++ b/tests/run-macros/tasty-seal-method/quoted_1.scala @@ -8,8 +8,8 @@ object Asserts { ${ zeroLastArgsImpl('x) } /** Replaces last argument list by 0s */ - def zeroLastArgsImpl(x: Expr[Int])(implicit reflect: Reflection): Expr[Int] = { - import reflect._ + def zeroLastArgsImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[Int] = { + import qctx.tasty._ // For simplicity assumes that all parameters are Int and parameter lists have no more than 3 elements x.unseal.underlyingArgument match { case Apply(fn, args) => @@ -30,8 +30,8 @@ object Asserts { ${ zeroAllArgsImpl('x) } /** Replaces all argument list by 0s */ - def zeroAllArgsImpl(x: Expr[Int])(implicit reflect: Reflection): Expr[Int] = { - import reflect._ + def zeroAllArgsImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[Int] = { + import qctx.tasty._ // For simplicity assumes that all parameters are Int and parameter lists have no more than 3 elements def rec(term: Term): Term = term match { case Apply(fn, args) => diff --git a/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala b/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala index 622947491904..748995c56702 100644 --- a/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala +++ b/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala @@ -1,7 +1,6 @@ import scala.quoted._ import scala.quoted.autolift._ import scala.quoted.matching._ -import scala.tasty.Reflection import scala.language.implicitConversions @@ -20,12 +19,12 @@ object TestFooErrors { // Defined in tests object Macro { - def foo(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given (reflect: Reflection): Expr[String] = { + def foo(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given (qctx: QuoteContext): Expr[String] = { (sc, argsExpr) match { case ('{ StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) => val reporter = new Reporter { def errorOnPart(msg: String, partIdx: Int): Unit = { - import reflect._ + import qctx.tasty._ error(msg, parts(partIdx).unseal.pos) } } @@ -33,13 +32,13 @@ object Macro { } } - def fooErrors(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given (reflect: Reflection): Expr[List[(Int, Int, Int, String)]] = { + def fooErrors(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]]) given (qctx: QuoteContext): Expr[List[(Int, Int, Int, String)]] = { (sc, argsExpr) match { case ('{ StringContext(${ExprSeq(parts)}: _*) }, ExprSeq(args)) => val errors = List.newBuilder[Expr[(Int, Int, Int, String)]] val reporter = new Reporter { def errorOnPart(msg: String, partIdx: Int): Unit = { - import reflect._ + import qctx.tasty._ val pos = parts(partIdx).unseal.pos errors += '{ Tuple4($partIdx, ${pos.start}, ${pos.end}, $msg) } } @@ -52,7 +51,7 @@ object Macro { } - private def fooCore(parts: Seq[Expr[String]], args: Seq[Expr[Any]], reporter: Reporter) given Reflection: Expr[String] = { + private def fooCore(parts: Seq[Expr[String]], args: Seq[Expr[Any]], reporter: Reporter) given QuoteContext: Expr[String] = { for ((part, idx) <- parts.zipWithIndex) { val Const(v: String) = part if (v.contains("#")) diff --git a/tests/run-macros/tasty-subtyping/quoted_1.scala b/tests/run-macros/tasty-subtyping/quoted_1.scala index b9cbed0696fb..984839764892 100644 --- a/tests/run-macros/tasty-subtyping/quoted_1.scala +++ b/tests/run-macros/tasty-subtyping/quoted_1.scala @@ -11,14 +11,14 @@ object Macros { inline def isSubTypeOf[T, U]: Boolean = ${isSubTypeOfImpl('[T], '[U])} - def isTypeEqualImpl[T, U](t: Type[T], u: Type[U])(implicit reflect: Reflection): Expr[Boolean] = { - import reflect._ + def isTypeEqualImpl[T, U](t: Type[T], u: Type[U]) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ val isTypeEqual = t.unseal.tpe =:= u.unseal.tpe isTypeEqual } - def isSubTypeOfImpl[T, U](t: Type[T], u: Type[U])(implicit reflect: Reflection): Expr[Boolean] = { - import reflect._ + def isSubTypeOfImpl[T, U](t: Type[T], u: Type[U]) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ val isTypeEqual = t.unseal.tpe <:< u.unseal.tpe isTypeEqual } diff --git a/tests/run-macros/tasty-tree-map/quoted_1.scala b/tests/run-macros/tasty-tree-map/quoted_1.scala index d8cceb031073..8e2aa3e50ac5 100644 --- a/tests/run-macros/tasty-tree-map/quoted_1.scala +++ b/tests/run-macros/tasty-tree-map/quoted_1.scala @@ -5,8 +5,8 @@ object Macros { implicit inline def identityMaped[T](x: => T): T = ${ impl('x) } - def impl[T: Type](x: Expr[T])(implicit reflection: Reflection): Expr[T] = { - import reflection._ + def impl[T: Type](x: Expr[T]) given (qctx: QuoteContext): Expr[T] = { + import qctx.tasty._ val identityMap = new TreeMap { } val transformed = identityMap.transformTerm(x.unseal).seal.cast[T] transformed diff --git a/tests/run-macros/tasty-typeof/Macro_1.scala b/tests/run-macros/tasty-typeof/Macro_1.scala index 365f02a62d0d..d6163e25b9c7 100644 --- a/tests/run-macros/tasty-typeof/Macro_1.scala +++ b/tests/run-macros/tasty-typeof/Macro_1.scala @@ -6,8 +6,8 @@ object Macros { inline def testTypeOf(): Unit = ${ testTypeOfImpl } - private def testTypeOfImpl(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + private def testTypeOfImpl given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ '{ assert(${(typeOf[Unit] =:= definitions.UnitType)}, "Unit") assert(${(typeOf[Byte] =:= definitions.ByteType)}, "Byte") diff --git a/tests/run-macros/type-show/Macro_1.scala b/tests/run-macros/type-show/Macro_1.scala index ddfc00328580..539e4a40a411 100644 --- a/tests/run-macros/type-show/Macro_1.scala +++ b/tests/run-macros/type-show/Macro_1.scala @@ -3,8 +3,8 @@ import scala.tasty._ object TypeToolbox { inline def show[A]: String = ${ showImpl('[A]) } - private def showImpl[A, B](a: Type[A])(implicit refl: Reflection): Expr[String] = { - import refl._ + private def showImpl[A, B](a: Type[A]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ a.show.toExpr } } diff --git a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala index b7e80c333003..6f5f3aac0824 100644 --- a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala @@ -14,8 +14,8 @@ object XmlQuote { } def impl(receiver: Expr[SCOps], args: Expr[Seq[Any]]) - (implicit reflect: Reflection): Expr[Xml] = { - import reflect._ + given (qctx: QuoteContext): Expr[Xml] = { + import qctx.tasty._ def abort(msg: String): Nothing = QuoteError(msg) diff --git a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala index 78d92f8c6293..0f1066044c21 100644 --- a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala @@ -15,9 +15,8 @@ object XmlQuote { } implicit inline def SCOps(ctx: => StringContext): SCOps = new SCOps(ctx) - def impl(receiver: Expr[SCOps], args: Expr[Seq[Any]]) - (implicit reflect: Reflection): Expr[Xml] = { - import reflect._ + def impl(receiver: Expr[SCOps], args: Expr[Seq[Any]]) given (qctx: QuoteContext): Expr[Xml] = { + import qctx.tasty._ // for debugging purpose def pp(tree: Tree): Unit = { diff --git a/tests/run-with-compiler/i6201/macro_1.scala b/tests/run-with-compiler/i6201/macro_1.scala index 85fc35d598e6..52c6a693943d 100644 --- a/tests/run-with-compiler/i6201/macro_1.scala +++ b/tests/run-with-compiler/i6201/macro_1.scala @@ -4,12 +4,12 @@ import scala.tasty._ inline def (inline x: String) strip: String = ${ stripImpl(x) } -def stripImpl(x: String)(implicit refl: Reflection): Expr[String] = +def stripImpl(x: String) given (qctx: QuoteContext): Expr[String] = x.stripMargin.toExpr inline def isHello(inline x: String): Boolean = ${ isHelloImpl(x) } -def isHelloImpl(x: String)(implicit refl: Reflection): Expr[Boolean] = +def isHelloImpl(x: String) given (qctx: QuoteContext): Expr[Boolean] = if (x == "hello") true.toExpr else false.toExpr diff --git a/tests/run-with-compiler/i6270/Macro_1.scala b/tests/run-with-compiler/i6270/Macro_1.scala index 4ffeb31078e6..2f151b4e8674 100644 --- a/tests/run-with-compiler/i6270/Macro_1.scala +++ b/tests/run-with-compiler/i6270/Macro_1.scala @@ -6,16 +6,16 @@ object api { inline def (x: => String) reflect : String = ${ reflImpl('x) } - private def reflImpl(x: Expr[String])(implicit refl: Reflection): Expr[String] = { - import refl._ + private def reflImpl(x: Expr[String]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ x.show.toExpr } inline def (x: => String) reflectColor : String = ${ reflImplColor('x) } - private def reflImplColor(x: Expr[String])(implicit refl: Reflection): Expr[String] = { - import refl._ + private def reflImplColor(x: Expr[String]) given (qctx: QuoteContext): Expr[String] = { + import qctx.tasty._ x.show(ANSI).toExpr } } diff --git a/tests/run-with-compiler/reflect-inline/assert_1.scala b/tests/run-with-compiler/reflect-inline/assert_1.scala index 020b7379977b..28f80331011d 100644 --- a/tests/run-with-compiler/reflect-inline/assert_1.scala +++ b/tests/run-with-compiler/reflect-inline/assert_1.scala @@ -1,18 +1,17 @@ import scala.quoted._ -import scala.tasty._ object api { inline def (inline x: String) stripMargin: String = ${ stripImpl(x) } - private def stripImpl(x: String)(implicit refl: Reflection): Expr[String] = + private def stripImpl(x: String) given (qctx: QuoteContext): Expr[String] = x.stripMargin.toExpr inline def typeChecks(inline x: String): Boolean = ${ typeChecksImpl(x) } - private def typeChecksImpl(x: String)(implicit refl: Reflection): Expr[Boolean] = { - import refl._ - if (refl.typing.typeChecks(x)) true.toExpr else false.toExpr + private def typeChecksImpl(x: String) given (qctx: QuoteContext): Expr[Boolean] = { + import qctx.tasty._ + if (qctx.tasty.typing.typeChecks(x)) true.toExpr else false.toExpr } } diff --git a/tests/run-with-compiler/staged-tuples/StagedTuple.scala b/tests/run-with-compiler/staged-tuples/StagedTuple.scala index a8a5d57c5f48..0fbd68cad1e5 100644 --- a/tests/run-with-compiler/staged-tuples/StagedTuple.scala +++ b/tests/run-with-compiler/staged-tuples/StagedTuple.scala @@ -125,7 +125,7 @@ object StagedTuple { } } - def applyStaged[Tup <: NonEmptyTuple : Type, N <: Int : Type](tup: Expr[Tup], size: Option[Int], n: Expr[N], nValue: Option[Int])(implicit reflect: tasty.Reflection): Expr[Elem[Tup, N]] = { + def applyStaged[Tup <: NonEmptyTuple : Type, N <: Int : Type](tup: Expr[Tup], size: Option[Int], n: Expr[N], nValue: Option[Int]) given (qctx: QuoteContext): Expr[Elem[Tup, N]] = { import reflect._ if (!specialize) '{dynamicApply($tup, $n)} diff --git a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala index 0d9acbd30ab4..3210112f7c51 100644 --- a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala +++ b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala @@ -8,7 +8,7 @@ object Macros { inline def testMacro: Unit = ${impl} - def impl(implicit reflect: Reflection): Expr[Unit] = { + def impl given QuoteContext: Expr[Unit] = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) // 2 is a lifted constant val show1 = withQuoteContext(power(2, 3.0).show) @@ -44,7 +44,7 @@ object Macros { } } - def power(n: Expr[Int], x: Expr[Double])(implicit reflect: Reflection): Expr[Double] = { + def power(n: Expr[Int], x: Expr[Double]) given QuoteContext: Expr[Double] = { import quoted.matching.Const n match { case Const(n1) => powerCode(n1, x) diff --git a/tests/run-with-compiler/tasty-unsafe-let/quoted_1.scala b/tests/run-with-compiler/tasty-unsafe-let/quoted_1.scala index 2ae9ed319fc4..9717f7c74546 100644 --- a/tests/run-with-compiler/tasty-unsafe-let/quoted_1.scala +++ b/tests/run-with-compiler/tasty-unsafe-let/quoted_1.scala @@ -7,12 +7,12 @@ object Macros { inline def let[T](rhs: T)(body: => T => Unit): Unit = ${ impl('rhs, 'body) } - private def impl[T](rhs: Expr[T], body: Expr[T => Unit])(implicit reflect: Reflection): Expr[Unit] = { - import reflect._ + private def impl[T](rhs: Expr[T], body: Expr[T => Unit]) given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ val rhsTerm = rhs.unseal - import reflect.util.{let => letTerm} + import qctx.tasty.util.{let => letTerm} letTerm(rhsTerm) { rhsId => body(rhsId.seal.asInstanceOf[Expr[T]]).unseal // Dangerous uncheked cast! }.seal.cast[Unit] From f9346599d9400f4c1883127fcae519d0b1233c99 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 1 Jul 2019 10:02:13 +0200 Subject: [PATCH 2/2] Add docs --- library/src/scala/quoted/QuoteContext.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/src/scala/quoted/QuoteContext.scala b/library/src/scala/quoted/QuoteContext.scala index 0423044a7d47..8e17ce9e1ab2 100644 --- a/library/src/scala/quoted/QuoteContext.scala +++ b/library/src/scala/quoted/QuoteContext.scala @@ -2,6 +2,14 @@ package scala.quoted import scala.quoted.show.SyntaxHighlight +/** Quotation context provided by a macro expansion or in the scope of `scala.quoted.run`. + * Used to perform all operations on quoted `Expr` or `Type`. + * + * It contains the low-level Typed AST API `tasty` meta-programming API. + * This API does not have the static type guarantiees that `Expr` and `Type` provide. + * + * @param tasty Typed AST API. Usage: `def f(qctx: QuoteContext) = { import qctx.tasty._; ... }`. + */ class QuoteContext(val tasty: scala.tasty.Reflection) { def show[T](expr: Expr[T], syntaxHighlight: SyntaxHighlight): String = {