From 385422801cdd657a65e3eac0e83977fbb7281eed Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 11 Mar 2020 11:43:47 +0100 Subject: [PATCH] Remove unnecessary imports --- library/src/scala/internal/quoted/Expr.scala | 1 - library/src/scala/internal/quoted/Type.scala | 1 - library/src/scala/quoted/Expr.scala | 9 +-- library/src/scala/quoted/Type.scala | 70 +++++++------------ .../src/scala/quoted/unsafe/UnsafeExpr.scala | 7 +- 5 files changed, 29 insertions(+), 59 deletions(-) diff --git a/library/src/scala/internal/quoted/Expr.scala b/library/src/scala/internal/quoted/Expr.scala index efd4be87d1c1..703111280ba1 100644 --- a/library/src/scala/internal/quoted/Expr.scala +++ b/library/src/scala/internal/quoted/Expr.scala @@ -34,7 +34,6 @@ object Expr { */ def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutineeExpr: scala.quoted.Expr[_])(using patternExpr: scala.quoted.Expr[_], hasTypeSplices: Boolean, qctx: QuoteContext): Option[Tup] = { - import qctx.tasty._ new Matcher.QuoteMatcher[qctx.type].termMatch(scrutineeExpr.unseal, patternExpr.unseal, hasTypeSplices).asInstanceOf[Option[Tup]] } diff --git a/library/src/scala/internal/quoted/Type.scala b/library/src/scala/internal/quoted/Type.scala index 4d6e35809c46..52da804b8a6d 100644 --- a/library/src/scala/internal/quoted/Type.scala +++ b/library/src/scala/internal/quoted/Type.scala @@ -26,7 +26,6 @@ object Type { */ def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutineeType: scala.quoted.Type[_])(using patternType: scala.quoted.Type[_], hasTypeSplices: Boolean, qctx: QuoteContext): Option[Tup] = { - import qctx.tasty._ new Matcher.QuoteMatcher[qctx.type].typeTreeMatch(scrutineeType.unseal, patternType.unseal, hasTypeSplices).asInstanceOf[Option[Tup]] } diff --git a/library/src/scala/quoted/Expr.scala b/library/src/scala/quoted/Expr.scala index c4138e9575c6..e0f1a9de8269 100644 --- a/library/src/scala/quoted/Expr.scala +++ b/library/src/scala/quoted/Expr.scala @@ -60,10 +60,8 @@ object Expr { * Expr.betaReduce(_): Expr[(T1, ..., Tn) => R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R]) * ``` */ - def betaReduce[F, Args <: Tuple, R, G](f: Expr[F])(using tf: TupledFunction[F, Args => R], tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]], qctx: QuoteContext): G = { - import qctx.tasty._ + def betaReduce[F, Args <: Tuple, R, G](f: Expr[F])(using tf: TupledFunction[F, Args => R], tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]], qctx: QuoteContext): G = tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]]) - } /** `Expr.betaReduceGiven(f)(x1, ..., xn)` is functionally the same as `'{($f)(using $x1, ..., $xn)}`, however it optimizes this call * by returning the result of beta-reducing `f(using x1, ..., xn)` if `f` is a known lambda expression. @@ -73,10 +71,8 @@ object Expr { * Expr.betaReduceGiven(_): Expr[(T1, ..., Tn) ?=> R] => ((Expr[T1], ..., Expr[Tn]) => Expr[R]) * ``` */ - def betaReduceGiven[F, Args <: Tuple, R, G](f: Expr[F])(using tf: TupledFunction[F, Args ?=> R], tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]], qctx: QuoteContext): G = { - import qctx.tasty._ + def betaReduceGiven[F, Args <: Tuple, R, G](f: Expr[F])(using tf: TupledFunction[F, Args ?=> R], tg: TupledFunction[G, TupleOfExpr[Args] => Expr[R]], qctx: QuoteContext): G = tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]]) - } /** Returns a null expresssion equivalent to `'{null}` */ def nullExpr: QuoteContext ?=> Expr[Null] = qctx ?=> { @@ -184,7 +180,6 @@ object Expr { /** Given a tuple of the form `(Expr[A1], ..., Expr[An])`, outputs a tuple `Expr[(A1, ..., An)]`. */ def ofTuple[T <: Tuple: Tuple.IsMappedBy[Expr]: Type](tup: T)(using qctx: QuoteContext): Expr[Tuple.InverseMap[T, Expr]] = { - import qctx.tasty._ val elems: Seq[Expr[_]] = tup.asInstanceOf[Product].productIterator.toSeq.asInstanceOf[Seq[Expr[_]]] ofTuple(elems).cast[Tuple.InverseMap[T, Expr]] } diff --git a/library/src/scala/quoted/Type.scala b/library/src/scala/quoted/Type.scala index c2074f0a9f14..eca708bc64ef 100644 --- a/library/src/scala/quoted/Type.scala +++ b/library/src/scala/quoted/Type.scala @@ -21,49 +21,31 @@ class Type[T <: AnyKind] private[scala] { /** Some basic type tags, currently incomplete */ object Type { - given UnitTag(using qctx: QuoteContext) as Type[Unit] = { - import qctx.tasty._ - defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]] - } - - given BooleanTag(using qctx: QuoteContext) as Type[Boolean] = { - import qctx.tasty._ - defn.BooleanType.seal.asInstanceOf[quoted.Type[Boolean]] - } - - given ByteTag(using qctx: QuoteContext) as Type[Byte] = { - import qctx.tasty._ - defn.ByteType.seal.asInstanceOf[quoted.Type[Byte]] - } - - given CharTag(using qctx: QuoteContext) as Type[Char] = { - import qctx.tasty._ - defn.CharType.seal.asInstanceOf[quoted.Type[Char]] - } - - given ShortTag(using qctx: QuoteContext) as Type[Short] = { - import qctx.tasty._ - defn.ShortType.seal.asInstanceOf[quoted.Type[Short]] - } - - given IntTag(using qctx: QuoteContext) as Type[Int] = { - import qctx.tasty._ - defn.IntType.seal.asInstanceOf[quoted.Type[Int]] - } - - given LongTag(using qctx: QuoteContext) as Type[Long] = { - import qctx.tasty._ - defn.LongType.seal.asInstanceOf[quoted.Type[Long]] - } - - given FloatTag(using qctx: QuoteContext) as Type[Float] = { - import qctx.tasty._ - defn.FloatType.seal.asInstanceOf[quoted.Type[Float]] - } - - given DoubleTag(using qctx: QuoteContext) as Type[Double] = { - import qctx.tasty._ - defn.DoubleType.seal.asInstanceOf[quoted.Type[Double]] - } + given UnitTag(using qctx: QuoteContext) as Type[Unit] = + qctx.tasty.defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]] + + given BooleanTag(using qctx: QuoteContext) as Type[Boolean] = + qctx.tasty.defn.BooleanType.seal.asInstanceOf[quoted.Type[Boolean]] + + given ByteTag(using qctx: QuoteContext) as Type[Byte] = + qctx.tasty.defn.ByteType.seal.asInstanceOf[quoted.Type[Byte]] + + given CharTag(using qctx: QuoteContext) as Type[Char] = + qctx.tasty.defn.CharType.seal.asInstanceOf[quoted.Type[Char]] + + given ShortTag(using qctx: QuoteContext) as Type[Short] = + qctx.tasty.defn.ShortType.seal.asInstanceOf[quoted.Type[Short]] + + given IntTag(using qctx: QuoteContext) as Type[Int] = + qctx.tasty.defn.IntType.seal.asInstanceOf[quoted.Type[Int]] + + given LongTag(using qctx: QuoteContext) as Type[Long] = + qctx.tasty.defn.LongType.seal.asInstanceOf[quoted.Type[Long]] + + given FloatTag(using qctx: QuoteContext) as Type[Float] = + qctx.tasty.defn.FloatType.seal.asInstanceOf[quoted.Type[Float]] + + given DoubleTag(using qctx: QuoteContext) as Type[Double] = + qctx.tasty.defn.DoubleType.seal.asInstanceOf[quoted.Type[Double]] } diff --git a/library/src/scala/quoted/unsafe/UnsafeExpr.scala b/library/src/scala/quoted/unsafe/UnsafeExpr.scala index 4a8db58d514d..9ff004356997 100644 --- a/library/src/scala/quoted/unsafe/UnsafeExpr.scala +++ b/library/src/scala/quoted/unsafe/UnsafeExpr.scala @@ -19,10 +19,8 @@ object UnsafeExpr { * Warning: Using the undelying argument directly in the expansion of a macro may * change the parameter semantics as by-value parameter could be re-evaluated. */ - def underlyingArgument[T](expr: Expr[T])(using qctx: QuoteContext): Expr[T] = { - import qctx.tasty._ + def underlyingArgument[T](expr: Expr[T])(using qctx: QuoteContext): Expr[T] = expr.unseal.underlyingArgument.seal.asInstanceOf[Expr[T]] - } // TODO generalize for any function arity (see Expr.betaReduce) /** Allows inspection or transformation of the body of the expression of function. @@ -39,19 +37,16 @@ object UnsafeExpr { * ``` */ def open[T1, R, X](f: Expr[T1 => R])(content: (Expr[R], [t] => Expr[t] => Expr[T1] => Expr[t]) => X)(using qctx: QuoteContext): X = { - import qctx.tasty._ val (params, bodyExpr) = paramsAndBody[R](f) content(bodyExpr, [t] => (e: Expr[t]) => (v: Expr[T1]) => bodyFn[t](e.unseal, params, List(v.unseal)).seal.asInstanceOf[Expr[t]]) } def open[T1, T2, R, X](f: Expr[(T1, T2) => R])(content: (Expr[R], [t] => Expr[t] => (Expr[T1], Expr[T2]) => Expr[t]) => X)(using qctx: QuoteContext)(using DummyImplicit): X = { - import qctx.tasty._ val (params, bodyExpr) = paramsAndBody[R](f) content(bodyExpr, [t] => (e: Expr[t]) => (v1: Expr[T1], v2: Expr[T2]) => bodyFn[t](e.unseal, params, List(v1.unseal, v2.unseal)).seal.asInstanceOf[Expr[t]]) } def open[T1, T2, T3, R, X](f: Expr[(T1, T2, T3) => R])(content: (Expr[R], [t] => Expr[t] => (Expr[T1], Expr[T2], Expr[T3]) => Expr[t]) => X)(using qctx: QuoteContext)(using DummyImplicit, DummyImplicit): X = { - import qctx.tasty._ val (params, bodyExpr) = paramsAndBody[R](f) content(bodyExpr, [t] => (e: Expr[t]) => (v1: Expr[T1], v2: Expr[T2], v3: Expr[T3]) => bodyFn[t](e.unseal, params, List(v1.unseal, v2.unseal, v3.unseal)).seal.asInstanceOf[Expr[t]]) }