Skip to content

Replace the[...] by summon[...] #7205

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 1 commit into from
Sep 12, 2019
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
2 changes: 1 addition & 1 deletion docs/docs/reference/metaprogramming/inline.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ Consequently, if we summon an `Ordering[String]` the code above will return a
new instance of `TreeSet[String]`.

```scala
the[Ordering[String]]
summon[Ordering[String]]

println(setFor[String].getClass) // prints class scala.collection.immutable.TreeSet
```
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/reference/metaprogramming/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ splicing the `Type` value `t`. This operation _is_ splice correct -- there
is one quote and one splice between the use of `t` and its definition.

To avoid clutter, the Scala implementation tries to convert any phase-incorrect
reference to a type `T` to a type-splice, by rewriting `T` to `${ the[Type[T]] }`.
reference to a type `T` to a type-splice, by rewriting `T` to `${ summon[Type[T]] }`.
For instance, the user-level definition of `reflect`:

```scala
Expand All @@ -192,7 +192,7 @@ For instance, the user-level definition of `reflect`:
would be rewritten to
```scala
def reflect[T: Type, U: Type](f: Expr[T] => Expr[U]): Expr[T => U] =
'{ (x: ${ the[Type[T]] }) => ${ f('x) } }
'{ (x: ${ summon[Type[T]] }) => ${ f('x) } }
```
The `the` query succeeds because there is a given instance of
type `Type[T]` available (namely the given parameter corresponding
Expand Down Expand Up @@ -252,7 +252,7 @@ The `toExpr` extension method is defined in package `quoted`:
package quoted

given ExprOps {
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x)
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = summon[Liftable[T]].toExpr(x)
...
}
```
Expand Down Expand Up @@ -334,12 +334,12 @@ that are not defined in the current stage? Here, we cannot construct
the `Type[T]` tree directly, so we need to get it from a recursive
implicit search. For instance, to implement
```scala
the[Type[List[T]]]
summon[Type[List[T]]]
```
where `T` is not defined in the current stage, we construct the type constructor
of `List` applied to the splice of the result of searching for a given instance for `Type[T]`:
```scala
'[ List[ ${ the[Type[T]] } ] ]
'[ List[ ${ summon[Type[T]] } ] ]
```
This is exactly the algorithm that Scala 2 uses to search for type tags.
In fact Scala 2's type tag feature can be understood as a more ad-hoc version of
Expand Down
8 changes: 4 additions & 4 deletions library/src-bootstrapped/scala/quoted/Liftable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object Liftable {

given ArrayIsLiftable[T: Type: Liftable: ClassTag] as Liftable[Array[T]] = new Liftable[Array[T]] {
def toExpr(arr: Array[T]): given QuoteContext => Expr[Array[T]] =
'{ Array[T](${arr.toSeq.toExpr}: _*)(${the[ClassTag[T]].toExpr}) }
'{ Array[T](${arr.toSeq.toExpr}: _*)(${summon[ClassTag[T]].toExpr}) }
}

given ArrayOfBooleanIsLiftable as Liftable[Array[Boolean]] = new Liftable[Array[Boolean]] {
Expand Down Expand Up @@ -110,12 +110,12 @@ object Liftable {

given [T: Type: Liftable] as Liftable[Seq[T]] = new Liftable[Seq[T]] {
def toExpr(xs: Seq[T]): given QuoteContext => Expr[Seq[T]] =
xs.map(the[Liftable[T]].toExpr).toExprOfSeq
xs.map(summon[Liftable[T]].toExpr).toExprOfSeq
}

given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] {
def toExpr(xs: List[T]): given QuoteContext => Expr[List[T]] =
xs.map(the[Liftable[T]].toExpr).toExprOfList
xs.map(summon[Liftable[T]].toExpr).toExprOfList
}

given [T: Type: Liftable] as Liftable[Set[T]] = new Liftable[Set[T]] {
Expand Down Expand Up @@ -290,7 +290,7 @@ object Liftable {

given [H: Type: Liftable, T <: Tuple: Type: Liftable] as Liftable[H *: T] = new {
def toExpr(tup: H *: T): given QuoteContext => Expr[H *: T] =
'{ ${the[Liftable[H]].toExpr(tup.head)} *: ${the[Liftable[T]].toExpr(tup.tail)} }
'{ ${summon[Liftable[H]].toExpr(tup.head)} *: ${summon[Liftable[T]].toExpr(tup.tail)} }
// '{ ${tup.head.toExpr} *: ${tup.tail.toExpr} } // TODO figure out why this fails during CI documentation
}

Expand Down
2 changes: 1 addition & 1 deletion library/src-bootstrapped/scala/quoted/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package object quoted {
}

implicit object ExprOps {
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x)
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = summon[Liftable[T]].toExpr(x)

/** Lifts this sequence of expressions into an expression of a sequence
*
Expand Down
3 changes: 2 additions & 1 deletion library/src/dotty/DottyPredef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ object DottyPredef {
case ev: ValueOf[T] => ev.value
}

inline def the[T] given (x: T): x.type = x
inline def summon[T] given (x: T): x.type = x

inline def the[T] given (x: T): x.type = x
}
2 changes: 1 addition & 1 deletion library/src/scala/tasty/reflect/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ trait Printers
inBlock(printCases(cases, lineBreak()))

case ImpliedMatch(cases) =>
this += highlightKeyword("delegate match")
this += highlightKeyword("delegate match") // TODO: drop
inBlock(printCases(cases, lineBreak()))

case Try(body, cases, finallyOpt) =>
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/i5978.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ object Testcase {
import TextParser._

val tp_v: TokenParser[Char, Position[CharSequence]] = TextParser.TP
val tp_i = the[TokenParser[Char, Position[CharSequence]]] // error
val co_i = the[Conversion[Char, Position[CharSequence]]] // error
val tp_i = summon[TokenParser[Char, Position[CharSequence]]] // error
val co_i = summon[Conversion[Char, Position[CharSequence]]] // error
val co_x : Position[CharSequence] = 'x' // error

{
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/implicit-params.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Test {

def g0(x: Int) given (c: C) (y: Int) = x + c.x + y // error

def g(x: Int) given (c: C) given D = x + c.x + the[D].x // OK
def g(x: Int) given (c: C) given D = x + c.x + summon[D].x // OK

def h(x: Int) given () = x // error

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/implied-for.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ object Test extends App {
val x: B = b // OK
println(c) // error: not found

the[C] // error
summon[C] // error

}
14 changes: 7 additions & 7 deletions tests/neg/mirror-implicit-scope.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ object Test {
case class ISB(i: Int, s: String, b: Boolean)
case class BI(b: Boolean, i: Int)

val v0 = the[Mirror.ProductOf[ISB]] // OK
val v1 = the[SomeClass & Mirror.ProductOf[ISB]] // error
val v2 = the[Mirror.ProductOf[ISB] & Mirror.ProductOf[BI]] // error
val v3 = the[Mirror.Product { type MirroredType = ISB ; def foo: Int }] // error
val v4 = the[Mirror.Product { type MirroredType = ISB ; def foo(i: Int): Int }] // error
val v5 = the[Mirror.Product { type MirroredType = ISB ; def foo[T](t: T): T }] // error // error
val v6 = the[Mirror.Product { type MirroredType = ISB ; val foo: Int }] // error
val v0 = summon[Mirror.ProductOf[ISB]] // OK
val v1 = summon[SomeClass & Mirror.ProductOf[ISB]] // error
val v2 = summon[Mirror.ProductOf[ISB] & Mirror.ProductOf[BI]] // error
val v3 = summon[Mirror.Product { type MirroredType = ISB ; def foo: Int }] // error
val v4 = summon[Mirror.Product { type MirroredType = ISB ; def foo(i: Int): Int }] // error
val v5 = summon[Mirror.Product { type MirroredType = ISB ; def foo[T](t: T): T }] // error // error
val v6 = summon[Mirror.Product { type MirroredType = ISB ; val foo: Int }] // error
}
Loading