Skip to content

Remove unnecessary given imports #8502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object StringContextMacro {
* @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]])(using qctx: QuoteContext): Expr[String] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
val sourceFile = strCtxExpr.unseal.pos.sourceFile

def notStatic =
Expand Down Expand Up @@ -135,7 +135,7 @@ object StringContextMacro {
* @return the Expr containing the formatted and interpolated String or an error/warning report if the parameters are not correct
*/
def interpolate(parts0 : List[String], args : Seq[Expr[Any]], argsExpr: Expr[Seq[Any]], reporter : Reporter)(using qctx: QuoteContext) : Expr[String] = {
import qctx.tasty.{_, given _}
import qctx.tasty._

/** Checks if the number of arguments are the same as the number of formatting strings
*
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/internal/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ 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.{_, given _}
import qctx.tasty._
new Matcher.QuoteMatcher[qctx.type].termMatch(scrutineeExpr.unseal, patternExpr.unseal, hasTypeSplices).asInstanceOf[Option[Tup]]
}

Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/internal/quoted/Matcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private[quoted] object Matcher {
// TODO use flag from qctx.tasty.rootContext. Maybe -debug or add -debug-macros
private final val debug = false

import qctx.tasty.{_, given _}
import qctx.tasty._
import Matching._

/** A map relating equivalent symbols from the scrutinee and the pattern
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/internal/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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.{_, given _}
import qctx.tasty._
new Matcher.QuoteMatcher[qctx.type].typeTreeMatch(scrutineeType.unseal, patternType.unseal, hasTypeSplices).asInstanceOf[Option[Tup]]
}

Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/quoted/Const.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object Const {
* ```
*/
def unapply[T](expr: Expr[T])(using qctx: QuoteContext): Option[T] = {
import qctx.tasty.{_, given _}
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)
Expand Down
14 changes: 7 additions & 7 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object Expr {
* ```
*/
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.{_, given _}
import qctx.tasty._
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[_]](qctx).unseal)).seal.asInstanceOf[Expr[R]])
}

Expand All @@ -74,19 +74,19 @@ object Expr {
* ```
*/
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.{_, given _}
import qctx.tasty._
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 ?=> {
import qctx.tasty.{_, given _}
import qctx.tasty._
Literal(Constant(null)).seal.asInstanceOf[Expr[Null]]
}

/** Returns a unit expresssion equivalent to `'{}` or `'{()}` */
def unitExpr: QuoteContext ?=> Expr[Unit] = qctx ?=> {
import qctx.tasty.{_, given _}
import qctx.tasty._
Literal(Constant(())).seal.asInstanceOf[Expr[Unit]]
}

Expand All @@ -95,7 +95,7 @@ object Expr {
* will be equivalent to `'{ $s1; $s2; ...; $e }`.
*/
def block[T](statements: List[Expr[_]], expr: Expr[T])(using qctx: QuoteContext): Expr[T] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
Block(statements.map(_.unseal), expr.unseal).seal.asInstanceOf[Expr[T]]
}

Expand Down Expand Up @@ -184,7 +184,7 @@ 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.{_, given _}
import qctx.tasty._
val elems: Seq[Expr[_]] = tup.asInstanceOf[Product].productIterator.toSeq.asInstanceOf[Seq[Expr[_]]]
ofTuple(elems).cast[Tuple.InverseMap[T, Expr]]
}
Expand All @@ -198,7 +198,7 @@ object Expr {
* @param qctx current context
*/
def summon[T](using tpe: Type[T])(using qctx: QuoteContext): Option[Expr[T]] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
searchImplicit(tpe.unseal.tpe) match {
case iss: ImplicitSearchSuccess => Some(iss.tree.seal.asInstanceOf[Expr[T]])
case isf: ImplicitSearchFailure => None
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/quoted/Lambda.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Lambda {
* ```
*/
def unapply[F, Args <: Tuple, Res, G](expr: Expr[F])(using qctx: QuoteContext, tf: TupledFunction[F, Args => Res], tg: TupledFunction[G, Tuple.Map[Args, Expr] => Expr[Res]], functionType: Type[F]): Option[/*QuoteContext ?=>*/ G] = {
import qctx.tasty.{_, given _ }
import qctx.tasty._
val argTypes = functionType.unseal.tpe match
case AppliedType(_, functionArguments) => functionArguments.init.asInstanceOf[List[Type]]
qctx.tasty.internal.lambdaExtractor(expr.unseal, argTypes).map { fn =>
Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/quoted/Liftable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ object Liftable {
private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] {
/** Lift a primitive value `n` into `'{ n }` */
def toExpr(x: T) = qctx ?=> {
import qctx.tasty.{_, given _}
import qctx.tasty._
Literal(Constant(x)).seal.asInstanceOf[Expr[T]]
}
}

given ClassIsLiftable[T] as Liftable[Class[T]] = new Liftable[Class[T]] {
/** Lift a `Class[T]` into `'{ classOf[T] }` */
def toExpr(x: Class[T]) = qctx ?=> {
import qctx.tasty.{_, given _}
import qctx.tasty._
Ref(defn.Predef_classOf).appliedToType(Type(x)).seal.asInstanceOf[Expr[Class[T]]]
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/quoted/QuoteContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scala.quoted.show.SyntaxHighlight
* 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.{_, given _}; ... }`.
* @param tasty Typed AST API. Usage: `def f(qctx: QuoteContext) = { import qctx.tasty._; ... }`.
*/
class QuoteContext(val tasty: scala.tasty.Reflection) { self =>

Expand Down
18 changes: 9 additions & 9 deletions library/src/scala/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,47 @@ class Type[T <: AnyKind] private[scala] {
object Type {

given UnitTag(using qctx: QuoteContext) as Type[Unit] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]]
}

given BooleanTag(using qctx: QuoteContext) as Type[Boolean] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
defn.BooleanType.seal.asInstanceOf[quoted.Type[Boolean]]
}

given ByteTag(using qctx: QuoteContext) as Type[Byte] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
defn.ByteType.seal.asInstanceOf[quoted.Type[Byte]]
}

given CharTag(using qctx: QuoteContext) as Type[Char] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
defn.CharType.seal.asInstanceOf[quoted.Type[Char]]
}

given ShortTag(using qctx: QuoteContext) as Type[Short] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
defn.ShortType.seal.asInstanceOf[quoted.Type[Short]]
}

given IntTag(using qctx: QuoteContext) as Type[Int] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
defn.IntType.seal.asInstanceOf[quoted.Type[Int]]
}

given LongTag(using qctx: QuoteContext) as Type[Long] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
defn.LongType.seal.asInstanceOf[quoted.Type[Long]]
}

given FloatTag(using qctx: QuoteContext) as Type[Float] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
defn.FloatType.seal.asInstanceOf[quoted.Type[Float]]
}

given DoubleTag(using qctx: QuoteContext) as Type[Double] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
defn.DoubleType.seal.asInstanceOf[quoted.Type[Double]]
}

Expand Down
4 changes: 2 additions & 2 deletions library/src/scala/quoted/Varargs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Varargs {
* ```
*/
def apply[T](xs: Seq[Expr[T]])(using tp: Type[T], qctx: QuoteContext): Expr[Seq[T]] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
Repeated(xs.map[Term](_.unseal).toList, tp.unseal).seal.asInstanceOf[Expr[Seq[T]]]
}

Expand All @@ -33,7 +33,7 @@ object Varargs {
* ```
*/
def unapply[T](expr: Expr[Seq[T]])(using qctx: QuoteContext): Option[Seq[Expr[T]]] = {
import qctx.tasty.{_, given _}
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)
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/quoted/matching/Sym.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Sym[T <: AnyKind] private[scala](val name: String, private[Sym] val id: Ob
object Sym {

def unapply[T](expr: Expr[T])(using qctx: QuoteContext): Option[Sym[T]] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
expr.unseal match {
case ref: Ident =>
val sym = ref.symbol
Expand Down
12 changes: 6 additions & 6 deletions library/src/scala/quoted/unsafe/UnsafeExpr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object UnsafeExpr {
* 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.{given _, _}
import qctx.tasty._
expr.unseal.underlyingArgument.seal.asInstanceOf[Expr[T]]
}

Expand All @@ -39,31 +39,31 @@ 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.{given _, _}
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.{given _, _}
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.{given _, _}
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]])
}

private def paramsAndBody[R](using qctx: QuoteContext)(f: Expr[Any]): (List[qctx.tasty.ValDef], Expr[R]) = {
import qctx.tasty.{given _, _}
import qctx.tasty._
val Block(List(DefDef("$anonfun", Nil, List(params), _, Some(body))), Closure(Ident("$anonfun"), None)) = f.unseal.etaExpand
(params, body.seal.asInstanceOf[Expr[R]])
}

private def bodyFn[t](using qctx: QuoteContext)(e: qctx.tasty.Term, params: List[qctx.tasty.ValDef], args: List[qctx.tasty.Term]): qctx.tasty.Term = {
import qctx.tasty.{given _, _}
import qctx.tasty._
val map = params.map(_.symbol).zip(args).toMap
new TreeMap {
override def transformTerm(tree: Term)(using ctx: Context): Term =
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/quoted/util/ExprMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait ExprMap {

/** Map subexpressions an expression `e` with a type `tpe` */
def transformChildren[T](e: Expr[T])(using qctx: QuoteContext, tpe: Type[T]): Expr[T] = {
import qctx.tasty.{_, given _}
import qctx.tasty._
final class MapChildren() {

def transformStatement(tree: Statement)(using ctx: Context): Statement = {
Expand Down
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object MyScalaJSPlugin extends AutoPlugin {
}

object Build {
val referenceVersion = "0.23.0-bin-20200222-811dc19-NIGHTLY"
val referenceVersion = "0.23.0-bin-20200305-84f2e41-NIGHTLY"

val baseVersion = "0.23.0"
val baseSbtDottyVersion = "0.4.0"
Expand Down