Skip to content

Commit cde1464

Browse files
committed
Refactor scala.quoted.matching
Importing `scala.quoted._` should give access to all the basic functionalities, but currently some half of them need the extra import for `scala.quoted.matching._`. * Move `scala.quoted.matching.summonExpr` to `scala.quoted.Expr.summon` * Move basic quote extractors from `scala.quoted.matching` to `scala.quoted`
1 parent a2abd6c commit cde1464

File tree

57 files changed

+96
-76
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+96
-76
lines changed

library/src-bootstrapped/dotty/internal/StringContextMacro.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
package dotty.internal
44

55
import scala.quoted._
6-
import scala.quoted.matching._
7-
import reflect._
86

97
object StringContextMacro {
108

library/src-non-bootstrapped/dotty/internal/StringContextMacro.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
package dotty.internal
44

55
import scala.quoted._
6-
import scala.quoted.matching._
7-
import reflect._
86

97
object StringContextMacro {
108

library/src/scala/quoted/matching/Const.scala renamed to library/src/scala/quoted/Const.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package scala.quoted
2-
package matching
32

43
/** Matches expressions containing literal constant values and extracts the value.
54
* It may match expressions of type Boolean, Byte, Short, Int, Long,

library/src/scala/quoted/matching/ConstSeq.scala renamed to library/src/scala/quoted/ConstSeq.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package scala.quoted
2-
package matching
32

43
/** Literal sequence of literal constant value expressions */
54
object ConstSeq {

library/src/scala/quoted/Expr.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ object Expr {
100100
}
101101

102102
/** Lift a value into an expression containing the construction of that value */
103-
def apply[T: Liftable](x: T)(using qctx: QuoteContext): Expr[T] = summon[Liftable[T]].toExpr(x)
103+
def apply[T](x: T)(using qctx: QuoteContext, lift: Liftable[T]): Expr[T] = lift.toExpr(x)
104104

105105
/** Lifts this sequence of expressions into an expression of a sequence
106106
*
@@ -197,4 +197,20 @@ object Expr {
197197
ofTuple(elems).cast[Tuple.InverseMap[T, Expr]]
198198
}
199199

200+
/** Find an implicit of type `T` in the current scope given by `qctx`.
201+
* Return `Some` containing the expression of the implicit or
202+
* `None` if implicit resolution failed.
203+
*
204+
* @tparam T type of the implicit parameter
205+
* @param tpe quoted type of the implicit parameter
206+
* @param qctx current context
207+
*/
208+
def summon[T](using tpe: Type[T])(using qctx: QuoteContext): Option[Expr[T]] = {
209+
import qctx.tasty.{_, given _}
210+
searchImplicit(tpe.unseal.tpe) match {
211+
case iss: ImplicitSearchSuccess => Some(iss.tree.seal.asInstanceOf[Expr[T]])
212+
case isf: ImplicitSearchFailure => None
213+
}
214+
}
215+
200216
}

library/src/scala/quoted/matching/ExprSeq.scala renamed to library/src/scala/quoted/ExprSeq.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package scala.quoted
2-
package matching
32

43
/** Literal sequence of expressions */
54
object ExprSeq {

library/src/scala/quoted/matching/Lambda.scala renamed to library/src/scala/quoted/Lambda.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package scala.quoted
2-
package matching
32

43
/** Lambda expression extractor */
54
object Lambda {

library/src/scala/quoted/matching/Value.scala renamed to library/src/scala/quoted/Value.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package scala.quoted
2-
package matching
32

43
/** Value expressions */
54
object Value {

library/src/scala/quoted/ValueOfExpr.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package scala.quoted
22

3-
import scala.quoted.matching._
4-
53
/** A typeclass for types that can be turned from a `quoted.Expr[T]` to a `T` */
64
trait ValueOfExpr[T] {
75

@@ -29,7 +27,7 @@ object ValueOfExpr {
2927

3028
private class PrimitiveValueOfExpr[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends ValueOfExpr[T] {
3129
/** Lift a quoted primitive value `'{ n }` into `n` */
32-
def apply(x: Expr[T])(using qctx: QuoteContext): Option[T] = matching.Const.unapply(x)
30+
def apply(x: Expr[T])(using qctx: QuoteContext): Option[T] = Const.unapply(x)
3331
}
3432

3533
given Option_delegate[T](using Type[T], ValueOfExpr[T]) as ValueOfExpr[Option[T]] = new {

library/src/scala/quoted/matching/ValueSeq.scala renamed to library/src/scala/quoted/ValueSeq.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package scala.quoted
2-
package matching
32

43
/** Value sequence of value expressions */
54
object ValueSeq {

0 commit comments

Comments
 (0)