Skip to content

Commit 4cbced0

Browse files
committed
Update TASTy Reflect to summon and given
1 parent af6823e commit 4cbced0

File tree

15 files changed

+129
-129
lines changed

15 files changed

+129
-129
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,62 +1885,62 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
18851885
// IMPLICITS
18861886
//
18871887

1888-
type ImplicitSearchResult = Tree
1888+
type GivenSearchResult = Tree
18891889

1890-
def searchImplicit(tpe: Type)(given ctx: Context): ImplicitSearchResult =
1890+
def searchGiven(tpe: Type)(given ctx: Context): GivenSearchResult =
18911891
ctx.typer.inferImplicitArg(tpe, rootPosition.span)
18921892

1893-
type ImplicitSearchSuccess = Tree
1894-
def isInstanceOfImplicitSearchSuccess(given ctx: Context): IsInstanceOf[ImplicitSearchSuccess] = new {
1895-
def runtimeClass: Class[?] = classOf[ImplicitSearchSuccess]
1896-
override def unapply(x: Any): Option[ImplicitSearchSuccess] = x match
1893+
type GivenSearchSuccess = Tree
1894+
def isInstanceOfGivenSearchSuccess(given ctx: Context): IsInstanceOf[GivenSearchSuccess] = new {
1895+
def runtimeClass: Class[?] = classOf[GivenSearchSuccess]
1896+
override def unapply(x: Any): Option[GivenSearchSuccess] = x match
18971897
case x: Tree =>
18981898
x.tpe match
18991899
case _: SearchFailureType => None
19001900
case _ => Some(x)
19011901
case _ => None
19021902
}
1903-
def ImplicitSearchSuccess_tree(self: ImplicitSearchSuccess)(given Context): Term = self
1903+
def GivenSearchSuccess_tree(self: GivenSearchSuccess)(given Context): Term = self
19041904

1905-
type ImplicitSearchFailure = Tree
1906-
def isInstanceOfImplicitSearchFailure(given ctx: Context): IsInstanceOf[ImplicitSearchFailure] = new {
1907-
def runtimeClass: Class[?] = classOf[ImplicitSearchFailure]
1908-
override def unapply(x: Any): Option[ImplicitSearchFailure] = x match
1905+
type GivenSearchFailure = Tree
1906+
def isInstanceOfGivenSearchFailure(given ctx: Context): IsInstanceOf[GivenSearchFailure] = new {
1907+
def runtimeClass: Class[?] = classOf[GivenSearchFailure]
1908+
override def unapply(x: Any): Option[GivenSearchFailure] = x match
19091909
case x: Tree =>
19101910
x.tpe match
19111911
case _: SearchFailureType => Some(x)
19121912
case _ => None
19131913
case _ => None
19141914
}
1915-
def ImplicitSearchFailure_explanation(self: ImplicitSearchFailure)(given Context): String =
1915+
def GivenSearchFailure_explanation(self: GivenSearchFailure)(given Context): String =
19161916
self.tpe.asInstanceOf[SearchFailureType].explanation
19171917

1918-
type DivergingImplicit = Tree
1919-
def isInstanceOfDivergingImplicit(given ctx: Context): IsInstanceOf[DivergingImplicit] = new {
1920-
def runtimeClass: Class[?] = classOf[DivergingImplicit]
1921-
override def unapply(x: Any): Option[DivergingImplicit] = x match
1918+
type DivergingGiven = Tree
1919+
def isInstanceOfDivergingGiven(given ctx: Context): IsInstanceOf[DivergingGiven] = new {
1920+
def runtimeClass: Class[?] = classOf[DivergingGiven]
1921+
override def unapply(x: Any): Option[DivergingGiven] = x match
19221922
case x: Tree =>
19231923
x.tpe match
19241924
case _: Implicits.DivergingImplicit => Some(x)
19251925
case _ => None
19261926
case _ => None
19271927
}
19281928

1929-
type NoMatchingImplicits = Tree
1930-
def isInstanceOfNoMatchingImplicits(given ctx: Context): IsInstanceOf[NoMatchingImplicits] = new {
1931-
def runtimeClass: Class[?] = classOf[NoMatchingImplicits]
1932-
override def unapply(x: Any): Option[NoMatchingImplicits] = x match
1929+
type NoMatchingGiven = Tree
1930+
def isInstanceOfNoMatchingGiven(given ctx: Context): IsInstanceOf[NoMatchingGiven] = new {
1931+
def runtimeClass: Class[?] = classOf[NoMatchingGiven]
1932+
override def unapply(x: Any): Option[NoMatchingGiven] = x match
19331933
case x: Tree =>
19341934
x.tpe match
19351935
case _: Implicits.NoMatchingImplicits => Some(x)
19361936
case _ => None
19371937
case _ => None
19381938
}
19391939

1940-
type AmbiguousImplicits = Tree
1941-
def isInstanceOfAmbiguousImplicits(given ctx: Context): IsInstanceOf[AmbiguousImplicits] = new {
1942-
def runtimeClass: Class[?] = classOf[AmbiguousImplicits]
1943-
override def unapply(x: Any): Option[AmbiguousImplicits] = x match
1940+
type AmbiguousGiven = Tree
1941+
def isInstanceOfAmbiguousGiven(given ctx: Context): IsInstanceOf[AmbiguousGiven] = new {
1942+
def runtimeClass: Class[?] = classOf[AmbiguousGiven]
1943+
override def unapply(x: Any): Option[AmbiguousGiven] = x match
19441944
case x: Tree =>
19451945
x.tpe match
19461946
case _: Implicits.AmbiguousImplicits => Some(x)

docs/docs/reference/metaprogramming/macros.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,13 +569,13 @@ sum
569569
### Find implicits within a macro
570570

571571
Similarly to the `summonFrom` construct, it is possible to make implicit search available
572-
in a quote context. For this we simply provide `scala.quoted.matching.searchImplicitExpr:
572+
in a quote context. For this we simply provide `scala.quoted.matching.summonExpr:
573573

574574
```scala
575575
inline def setFor[T]: Set[T] = ${ setForExpr[T] }
576576

577577
def setForExpr[T: Type](given QuoteContext): Expr[Set[T]] = {
578-
searchImplicitExpr[Ordering[T]] match {
578+
summonExpr[Ordering[T]] match {
579579
case Some(ord) => '{ new TreeSet[T]()($ord) }
580580
case _ => '{ new HashSet[T] }
581581
}

library/src/scala/quoted/matching/package.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ package object matching {
1010
* @param tpe quoted type of the implicit parameter
1111
* @param qctx current context
1212
*/
13-
def searchImplicitExpr[T](given tpe: Type[T], qctx: QuoteContext): Option[Expr[T]] = {
13+
def summonExpr[T](given tpe: Type[T], qctx: QuoteContext): Option[Expr[T]] = {
1414
import qctx.tasty.{_, given}
15-
searchImplicit(tpe.unseal.tpe) match {
16-
case iss: ImplicitSearchSuccess => Some(iss.tree.seal.asInstanceOf[Expr[T]])
17-
case isf: ImplicitSearchFailure => None
15+
searchGiven(tpe.unseal.tpe) match {
16+
case iss: GivenSearchSuccess => Some(iss.tree.seal.asInstanceOf[Expr[T]])
17+
case isf: GivenSearchFailure => None
1818
}
1919
}
2020

library/src/scala/tasty/Reflection.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Reflection(private[scala] val internal: CompilerInterface)
1010
with CommentOps
1111
with FlagsOps
1212
with IdOps
13-
with ImplicitsOps
13+
with GivenOps
1414
with ImportSelectorOps
1515
with QuotedOps
1616
with PositionOps
@@ -25,6 +25,6 @@ class Reflection(private[scala] val internal: CompilerInterface)
2525
with TypeOrBoundsOps { self =>
2626

2727
def typeOf[T: scala.quoted.Type]: Type =
28-
implicitly[scala.quoted.Type[T]].unseal.tpe
28+
summon[scala.quoted.Type[T]].unseal.tpe
2929

3030
}

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,32 +1416,32 @@ trait CompilerInterface {
14161416
// IMPLICITS
14171417
//
14181418

1419-
type ImplicitSearchResult <: AnyRef
1419+
type GivenSearchResult <: AnyRef
14201420

1421-
type ImplicitSearchSuccess <: ImplicitSearchResult
1422-
def isInstanceOfImplicitSearchSuccess(given ctx: Context): IsInstanceOf[ImplicitSearchSuccess]
1423-
def ImplicitSearchSuccess_tree(self: ImplicitSearchSuccess)(given ctx: Context): Term
1421+
type GivenSearchSuccess <: GivenSearchResult
1422+
def isInstanceOfGivenSearchSuccess(given ctx: Context): IsInstanceOf[GivenSearchSuccess]
1423+
def GivenSearchSuccess_tree(self: GivenSearchSuccess)(given ctx: Context): Term
14241424

1425-
type ImplicitSearchFailure <: ImplicitSearchResult
1426-
def isInstanceOfImplicitSearchFailure(given ctx: Context): IsInstanceOf[ImplicitSearchFailure]
1427-
def ImplicitSearchFailure_explanation(self: ImplicitSearchFailure)(given ctx: Context): String
1425+
type GivenSearchFailure <: GivenSearchResult
1426+
def isInstanceOfGivenSearchFailure(given ctx: Context): IsInstanceOf[GivenSearchFailure]
1427+
def GivenSearchFailure_explanation(self: GivenSearchFailure)(given ctx: Context): String
14281428

1429-
type DivergingImplicit <: ImplicitSearchFailure
1430-
def isInstanceOfDivergingImplicit(given ctx: Context): IsInstanceOf[DivergingImplicit]
1429+
type DivergingGiven <: GivenSearchFailure
1430+
def isInstanceOfDivergingGiven(given ctx: Context): IsInstanceOf[DivergingGiven]
14311431

1432-
type NoMatchingImplicits <: ImplicitSearchFailure
1433-
def isInstanceOfNoMatchingImplicits(given ctx: Context): IsInstanceOf[NoMatchingImplicits]
1432+
type NoMatchingGiven <: GivenSearchFailure
1433+
def isInstanceOfNoMatchingGiven(given ctx: Context): IsInstanceOf[NoMatchingGiven]
14341434

1435-
type AmbiguousImplicits <: ImplicitSearchFailure
1436-
def isInstanceOfAmbiguousImplicits(given ctx: Context): IsInstanceOf[AmbiguousImplicits]
1435+
type AmbiguousGiven <: GivenSearchFailure
1436+
def isInstanceOfAmbiguousGiven(given ctx: Context): IsInstanceOf[AmbiguousGiven]
14371437

14381438
/** Find an implicit of type `T` in the current scope given by `ctx`.
1439-
* Return an `ImplicitSearchResult`.
1439+
* Return an `GivenSearchResult`.
14401440
*
14411441
* @param tpe type of the implicit parameter
14421442
* @param ctx current context
14431443
*/
1444-
def searchImplicit(tpe: Type)(given ctx: Context): ImplicitSearchResult
1444+
def searchGiven(tpe: Type)(given ctx: Context): GivenSearchResult
14451445

14461446
/** Inline fn if it is an explicit closure possibly nested inside the expression of a block.
14471447
* Otherwise apply the arguments to the closure.

library/src/scala/tasty/reflect/Core.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,16 @@ trait Core {
399399
/** FlagSet of a Symbol */
400400
type Flags = internal.Flags
401401

402-
type ImplicitSearchResult = internal.ImplicitSearchResult
402+
type GivenSearchResult = internal.GivenSearchResult
403403

404-
type ImplicitSearchSuccess = internal.ImplicitSearchSuccess
404+
type GivenSearchSuccess = internal.GivenSearchSuccess
405405

406-
type ImplicitSearchFailure = internal.ImplicitSearchFailure
406+
type GivenSearchFailure = internal.GivenSearchFailure
407407

408-
type DivergingImplicit = internal.DivergingImplicit
408+
type DivergingGiven = internal.DivergingGiven
409409

410-
type NoMatchingImplicits = internal.NoMatchingImplicits
410+
type NoMatchingGiven = internal.NoMatchingGiven
411411

412-
type AmbiguousImplicits = internal.AmbiguousImplicits
412+
type AmbiguousGiven = internal.AmbiguousGiven
413413

414414
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package scala.tasty.reflect
2+
3+
trait GivenOps extends Core {
4+
5+
def searchGiven(tpe: Type)(given ctx: Context): GivenSearchResult =
6+
internal.searchGiven(tpe)
7+
8+
given (given Context): IsInstanceOf[GivenSearchSuccess] = internal.isInstanceOfGivenSearchSuccess
9+
10+
object IsGivenSearchSuccess
11+
@deprecated("Use _: GivenSearchSuccess", "")
12+
def unapply(isr: GivenSearchSuccess)(given ctx: Context): Option[GivenSearchSuccess] = Some(isr)
13+
14+
given successOps: extension (self: GivenSearchSuccess) {
15+
def tree(given ctx: Context): Term = internal.GivenSearchSuccess_tree(self)
16+
}
17+
18+
given (given Context): IsInstanceOf[GivenSearchFailure] = internal.isInstanceOfGivenSearchFailure
19+
20+
object IsGivenSearchFailure
21+
@deprecated("Use _: GivenSearchFailure", "")
22+
def unapply(isr: GivenSearchFailure)(given ctx: Context): Option[GivenSearchFailure] = Some(isr)
23+
24+
given failureOps: extension (self: GivenSearchFailure) {
25+
def explanation(given ctx: Context): String = internal.GivenSearchFailure_explanation(self)
26+
}
27+
28+
given (given Context): IsInstanceOf[DivergingGiven] = internal.isInstanceOfDivergingGiven
29+
30+
object IsDivergingGiven
31+
@deprecated("Use _: DivergingGiven", "")
32+
def unapply(isr: DivergingGiven)(given ctx: Context): Option[DivergingGiven] = Some(isr)
33+
34+
given (given Context): IsInstanceOf[NoMatchingGiven] = internal.isInstanceOfNoMatchingGiven
35+
36+
object IsNoMatchingGiven
37+
@deprecated("Use _: NoMatchingGiven", "")
38+
def unapply(isr: NoMatchingGiven)(given ctx: Context): Option[NoMatchingGiven] = Some(isr)
39+
40+
given (given Context): IsInstanceOf[AmbiguousGiven] = internal.isInstanceOfAmbiguousGiven
41+
42+
object IsAmbiguousGiven
43+
@deprecated("Use _: AmbiguousGiven", "")
44+
def unapply(isr: AmbiguousGiven)(given ctx: Context): Option[AmbiguousGiven] = Some(isr)
45+
46+
}

library/src/scala/tasty/reflect/ImplicitsOps.scala

Lines changed: 0 additions & 46 deletions
This file was deleted.

tests/neg-macros/delegate-match-1.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
-- Error: tests/neg-macros/delegate-match-1/Test_2.scala:6:2 -----------------------------------------------------------
33
6 | f // error
44
| ^
5-
| AmbiguousImplicits
5+
| AmbiguousGiven
66
| both value a1 in class Test1 and value a2 in class Test1 match type A
77
| This location contains code that was inlined from Test_2.scala:6

tests/neg-macros/delegate-match-1/Macro_1.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ inline def f: Any = ${ fImpl }
55

66
private def fImpl(given qctx: QuoteContext): Expr[Unit] = {
77
import qctx.tasty.{_, given}
8-
searchImplicit(('[A]).unseal.tpe) match {
9-
case x: ImplicitSearchSuccess =>
8+
searchGiven(('[A]).unseal.tpe) match {
9+
case x: GivenSearchSuccess =>
1010
'{}
11-
case x: DivergingImplicit => '{}
12-
error("DivergingImplicit\n" + x.explanation, rootPosition)
11+
case x: DivergingGiven => '{}
12+
error("DivergingGiven\n" + x.explanation, rootPosition)
1313
'{}
14-
case x: NoMatchingImplicits =>
15-
error("NoMatchingImplicits\n" + x.explanation, rootPosition)
14+
case x: NoMatchingGiven =>
15+
error("NoMatchingGiven\n" + x.explanation, rootPosition)
1616
'{}
17-
case x: AmbiguousImplicits =>
18-
error("AmbiguousImplicits\n" + x.explanation, rootPosition)
17+
case x: AmbiguousGiven =>
18+
error("AmbiguousGiven\n" + x.explanation, rootPosition)
1919
'{}
2020
}
2121
}

tests/neg-macros/delegate-match-2.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
-- Error: tests/neg-macros/delegate-match-2/Test_2.scala:5:2 -----------------------------------------------------------
33
5 | f // error
44
| ^
5-
| DivergingImplicit
5+
| DivergingGiven
66
| method a1 in class Test produces a diverging implicit search when trying to match type A
77
| This location contains code that was inlined from Test_2.scala:5

tests/neg-macros/delegate-match-2/Macro_1.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ inline def f: Any = ${ fImpl }
55

66
private def fImpl(given qctx: QuoteContext): Expr[Unit] = {
77
import qctx.tasty.{_, given}
8-
searchImplicit(('[A]).unseal.tpe) match {
9-
case x: ImplicitSearchSuccess =>
8+
searchGiven(('[A]).unseal.tpe) match {
9+
case x: GivenSearchSuccess =>
1010
'{}
11-
case x: DivergingImplicit => '{}
12-
error("DivergingImplicit\n" + x.explanation, rootPosition)
11+
case x: DivergingGiven => '{}
12+
error("DivergingGiven\n" + x.explanation, rootPosition)
1313
'{}
14-
case x: NoMatchingImplicits =>
15-
error("NoMatchingImplicits\n" + x.explanation, rootPosition)
14+
case x: NoMatchingGiven =>
15+
error("NoMatchingGiven\n" + x.explanation, rootPosition)
1616
'{}
17-
case x: AmbiguousImplicits =>
18-
error("AmbiguousImplicits\n" + x.explanation, rootPosition)
17+
case x: AmbiguousGiven =>
18+
error("AmbiguousGiven\n" + x.explanation, rootPosition)
1919
'{}
2020
}
2121
}

tests/neg-macros/delegate-match-3.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
-- Error: tests/neg-macros/delegate-match-3/Test_2.scala:3:2 -----------------------------------------------------------
33
3 | f // error
44
| ^
5-
| NoMatchingImplicits
5+
| NoMatchingGiven
66
| no implicit values were found that match type A
77
| This location contains code that was inlined from Test_2.scala:3

0 commit comments

Comments
 (0)