Skip to content

Commit b393a89

Browse files
authored
Merge pull request #7205 from dotty-staging/change-the-summon
Replace the[...] by summon[...]
2 parents 60c3a12 + 8601895 commit b393a89

Some content is hidden

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

50 files changed

+268
-267
lines changed

docs/docs/reference/metaprogramming/inline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ Consequently, if we summon an `Ordering[String]` the code above will return a
465465
new instance of `TreeSet[String]`.
466466

467467
```scala
468-
the[Ordering[String]]
468+
summon[Ordering[String]]
469469

470470
println(setFor[String].getClass) // prints class scala.collection.immutable.TreeSet
471471
```

docs/docs/reference/metaprogramming/macros.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ splicing the `Type` value `t`. This operation _is_ splice correct -- there
182182
is one quote and one splice between the use of `t` and its definition.
183183

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

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

254254
given ExprOps {
255-
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x)
255+
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = summon[Liftable[T]].toExpr(x)
256256
...
257257
}
258258
```
@@ -334,12 +334,12 @@ that are not defined in the current stage? Here, we cannot construct
334334
the `Type[T]` tree directly, so we need to get it from a recursive
335335
implicit search. For instance, to implement
336336
```scala
337-
the[Type[List[T]]]
337+
summon[Type[List[T]]]
338338
```
339339
where `T` is not defined in the current stage, we construct the type constructor
340340
of `List` applied to the splice of the result of searching for a given instance for `Type[T]`:
341341
```scala
342-
'[ List[ ${ the[Type[T]] } ] ]
342+
'[ List[ ${ summon[Type[T]] } ] ]
343343
```
344344
This is exactly the algorithm that Scala 2 uses to search for type tags.
345345
In fact Scala 2's type tag feature can be understood as a more ad-hoc version of

library/src-bootstrapped/scala/quoted/Liftable.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ object Liftable {
5252

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

5858
given ArrayOfBooleanIsLiftable as Liftable[Array[Boolean]] = new Liftable[Array[Boolean]] {
@@ -110,12 +110,12 @@ object Liftable {
110110

111111
given [T: Type: Liftable] as Liftable[Seq[T]] = new Liftable[Seq[T]] {
112112
def toExpr(xs: Seq[T]): given QuoteContext => Expr[Seq[T]] =
113-
xs.map(the[Liftable[T]].toExpr).toExprOfSeq
113+
xs.map(summon[Liftable[T]].toExpr).toExprOfSeq
114114
}
115115

116116
given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] {
117117
def toExpr(xs: List[T]): given QuoteContext => Expr[List[T]] =
118-
xs.map(the[Liftable[T]].toExpr).toExprOfList
118+
xs.map(summon[Liftable[T]].toExpr).toExprOfList
119119
}
120120

121121
given [T: Type: Liftable] as Liftable[Set[T]] = new Liftable[Set[T]] {
@@ -290,7 +290,7 @@ object Liftable {
290290

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

library/src-bootstrapped/scala/quoted/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package object quoted {
77
}
88

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

1212
/** Lifts this sequence of expressions into an expression of a sequence
1313
*

library/src/dotty/DottyPredef.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ object DottyPredef {
3636
case ev: ValueOf[T] => ev.value
3737
}
3838

39-
inline def the[T] given (x: T): x.type = x
39+
inline def summon[T] given (x: T): x.type = x
4040

41+
inline def the[T] given (x: T): x.type = x
4142
}

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ trait Printers
927927
inBlock(printCases(cases, lineBreak()))
928928

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

933933
case Try(body, cases, finallyOpt) =>

tests/neg/i5978.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ object Testcase {
1717
import TextParser._
1818

1919
val tp_v: TokenParser[Char, Position[CharSequence]] = TextParser.TP
20-
val tp_i = the[TokenParser[Char, Position[CharSequence]]] // error
21-
val co_i = the[Conversion[Char, Position[CharSequence]]] // error
20+
val tp_i = summon[TokenParser[Char, Position[CharSequence]]] // error
21+
val co_i = summon[Conversion[Char, Position[CharSequence]]] // error
2222
val co_x : Position[CharSequence] = 'x' // error
2323

2424
{

tests/neg/implicit-params.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Test {
77

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

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

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

tests/neg/implied-for.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ object Test extends App {
1414
val x: B = b // OK
1515
println(c) // error: not found
1616

17-
the[C] // error
17+
summon[C] // error
1818

1919
}

tests/neg/mirror-implicit-scope.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ object Test {
55
case class ISB(i: Int, s: String, b: Boolean)
66
case class BI(b: Boolean, i: Int)
77

8-
val v0 = the[Mirror.ProductOf[ISB]] // OK
9-
val v1 = the[SomeClass & Mirror.ProductOf[ISB]] // error
10-
val v2 = the[Mirror.ProductOf[ISB] & Mirror.ProductOf[BI]] // error
11-
val v3 = the[Mirror.Product { type MirroredType = ISB ; def foo: Int }] // error
12-
val v4 = the[Mirror.Product { type MirroredType = ISB ; def foo(i: Int): Int }] // error
13-
val v5 = the[Mirror.Product { type MirroredType = ISB ; def foo[T](t: T): T }] // error // error
14-
val v6 = the[Mirror.Product { type MirroredType = ISB ; val foo: Int }] // error
8+
val v0 = summon[Mirror.ProductOf[ISB]] // OK
9+
val v1 = summon[SomeClass & Mirror.ProductOf[ISB]] // error
10+
val v2 = summon[Mirror.ProductOf[ISB] & Mirror.ProductOf[BI]] // error
11+
val v3 = summon[Mirror.Product { type MirroredType = ISB ; def foo: Int }] // error
12+
val v4 = summon[Mirror.Product { type MirroredType = ISB ; def foo(i: Int): Int }] // error
13+
val v5 = summon[Mirror.Product { type MirroredType = ISB ; def foo[T](t: T): T }] // error // error
14+
val v6 = summon[Mirror.Product { type MirroredType = ISB ; val foo: Int }] // error
1515
}

0 commit comments

Comments
 (0)