Skip to content

Remove unnecessary imports #8510

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
1 change: 0 additions & 1 deletion library/src/scala/internal/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
}

Expand Down
1 change: 0 additions & 1 deletion library/src/scala/internal/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
}

Expand Down
9 changes: 2 additions & 7 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 ?=> {
Expand Down Expand Up @@ -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]]
}
Expand Down
70 changes: 26 additions & 44 deletions library/src/scala/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

}
7 changes: 1 addition & 6 deletions library/src/scala/quoted/unsafe/UnsafeExpr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]])
}
Expand Down