Skip to content

Commit f1d0b81

Browse files
Merge pull request #7332 from dotty-staging/disambiguate-reflect-bind
Rename scala.quoted.matching.{Bind => Sym}
2 parents 6c8b4b5 + 507418d commit f1d0b81

File tree

10 files changed

+34
-34
lines changed

10 files changed

+34
-34
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ class Definitions {
658658

659659
@tu lazy val QuotedTypeModule: Symbol = QuotedTypeClass.companionModule
660660

661-
@tu lazy val QuotedMatchingBindingClass: ClassSymbol = ctx.requiredClass("scala.quoted.matching.Bind")
661+
@tu lazy val QuotedMatchingSymClass: ClassSymbol = ctx.requiredClass("scala.quoted.matching.Sym")
662662
@tu lazy val TastyReflectionClass: ClassSymbol = ctx.requiredClass("scala.tasty.Reflection")
663663

664664
@tu lazy val Unpickler_unpickleExpr: Symbol = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleExpr")

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ trait QuotesAndSplices {
207207
x => t.resType.subst(t, x).toFunctionType())
208208
case t => t
209209
}
210-
val bindingExprTpe = AppliedType(defn.QuotedMatchingBindingClass.typeRef, bindingType :: Nil)
210+
val bindingExprTpe = AppliedType(defn.QuotedMatchingSymClass.typeRef, bindingType :: Nil)
211211
assert(ddef.name.startsWith("$"))
212212
val bindName = ddef.name.toString.stripPrefix("$").toTermName
213213
val sym = ctx0.newPatternBoundSymbol(bindName, bindingExprTpe, ddef.span)

library/src/scala/internal/quoted/Matcher.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package scala.internal.quoted
33
import scala.annotation.internal.sharable
44

55
import scala.quoted._
6-
import scala.quoted.matching.Bind
6+
import scala.quoted.matching.Sym
77

88
private[quoted] object Matcher {
99

@@ -12,7 +12,7 @@ private[quoted] object Matcher {
1212

1313
private final val debug = false
1414

15-
import qctx.tasty.{Bind => BindPattern, _}
15+
import qctx.tasty._
1616
import Matching._
1717

1818
private type Env = Set[(Symbol, Symbol)]
@@ -126,7 +126,7 @@ private[quoted] object Matcher {
126126
}
127127

128128
def bindingMatch(sym: Symbol) =
129-
matched(new Bind(sym.name, sym))
129+
matched(new Sym(sym.name, sym))
130130

131131
(scrutinee, pattern) match {
132132

library/src/scala/quoted/matching/Bind.scala renamed to library/src/scala/quoted/matching/Sym.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
package scala.quoted
22
package matching
33

4-
/** Bind of an Expr[T] used to know if some Expr[T] is a reference to the binding
4+
/** Sym of an Expr[T] used to know if some Expr[T] is a reference to the symbol
55
*
6-
* @param name string name of this binding
6+
* @param name string name of this symbol
77
* @param id unique id used for equality
88
*/
9-
class Bind[T <: AnyKind] private[scala](val name: String, private[Bind] val id: Object) { self =>
9+
class Sym[T <: AnyKind] private[scala](val name: String, private[Sym] val id: Object) { self =>
1010

1111
override def equals(obj: Any): Boolean = obj match {
12-
case obj: Bind[_] => obj.id == id
12+
case obj: Sym[_] => obj.id == id
1313
case _ => false
1414
}
1515

1616
override def hashCode(): Int = id.hashCode()
1717

1818
}
1919

20-
object Bind {
20+
object Sym {
2121

22-
def unapply[T](expr: Expr[T])(given qctx: QuoteContext): Option[Bind[T]] = {
23-
import qctx.tasty.{Bind => BindPattern, _}
22+
def unapply[T](expr: Expr[T])(given qctx: QuoteContext): Option[Sym[T]] = {
23+
import qctx.tasty._
2424
expr.unseal match {
2525
case IsIdent(ref) =>
2626
val sym = ref.symbol
27-
Some(new Bind[T](sym.name, sym))
27+
Some(new Sym[T](sym.name, sym))
2828
case _ => None
2929
}
3030
}

tests/pos/quotedPatterns.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ object Test {
1414
case '{ 1 + ($y: Int)} => y
1515
case '{ val a = 1 + ($y: Int); 3 } => y
1616
case '{ val $y: Int = $z; println(`$y`); 1 } =>
17-
val a: quoted.matching.Bind[Int] = y
17+
val a: quoted.matching.Sym[Int] = y
1818
z
1919
case '{ (($y: Int) => 1 + `$y` + ($z: Int))(2) } =>
20-
val a: quoted.matching.Bind[Int] = y
20+
val a: quoted.matching.Sym[Int] = y
2121
z
2222
case '{ def $ff: Int = $z; `$ff` } =>
23-
val a: quoted.matching.Bind[Int] = ff
23+
val a: quoted.matching.Sym[Int] = ff
2424
z
2525
case '{ def $ff(i: Int): Int = $z; 2 } =>
26-
val a: quoted.matching.Bind[Int => Int] = ff
26+
val a: quoted.matching.Sym[Int => Int] = ff
2727
z
2828
case '{ def $ff(i: Int)(j: Int): Int = $z; 2 } =>
29-
val a: quoted.matching.Bind[Int => Int => Int] = ff
29+
val a: quoted.matching.Sym[Int => Int => Int] = ff
3030
z
3131
case '{ def $ff[T](i: T): Int = $z; 2 } =>
32-
val a: quoted.matching.Bind[[T] =>> T => Int] = ff
32+
val a: quoted.matching.Sym[[T] =>> T => Int] = ff
3333
z
3434
case '{ poly[$t]($x); 4 } => ???
3535
case '{ poly[${Foo(t)}]($x); 4 } => ???

tests/run-macros/quote-matcher-runtime.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ Result: Some(List(Expr(((x: scala.Int) => "abc"))))
238238

239239
Scrutinee: ((x: scala.Int) => "abc")
240240
Pattern: ((x: scala.Int @scala.internal.Quoted.patternBindHole) => scala.internal.Quoted.patternHole[scala.Predef.String])
241-
Result: Some(List(Bind(x), Expr("abc")))
241+
Result: Some(List(Sym(x), Expr("abc")))
242242

243243
Scrutinee: scala.StringContext.apply(("abc", "xyz": scala.<repeated>[scala.Predef.String]))
244244
Pattern: scala.StringContext.apply(("abc", "xyz": scala.<repeated>[scala.Predef.String]))
@@ -270,7 +270,7 @@ Pattern: {
270270
@scala.internal.Quoted.patternBindHole val a: scala.Int = scala.internal.Quoted.patternHole[scala.Int]
271271
()
272272
}
273-
Result: Some(List(Bind(a), Expr(45)))
273+
Result: Some(List(Sym(a), Expr(45)))
274274

275275
Scrutinee: {
276276
val a: scala.Int = 45
@@ -502,7 +502,7 @@ Pattern: {
502502
@scala.internal.Quoted.patternBindHole def a: scala.Int = scala.internal.Quoted.patternHole[scala.Int]
503503
()
504504
}
505-
Result: Some(List(Bind(a), Expr(45)))
505+
Result: Some(List(Sym(a), Expr(45)))
506506

507507
Scrutinee: {
508508
def a(x: scala.Int): scala.Int = 45
@@ -572,7 +572,7 @@ Pattern: {
572572
def a(x: scala.Int @scala.internal.Quoted.patternBindHole): scala.Int = 45
573573
()
574574
}
575-
Result: Some(List(Bind(x)))
575+
Result: Some(List(Sym(x)))
576576

577577
Scrutinee: {
578578
def a(x: scala.Int): scala.Int = 45
@@ -582,7 +582,7 @@ Pattern: {
582582
def a(x: scala.Int @scala.internal.Quoted.patternBindHole): scala.Int = 45
583583
()
584584
}
585-
Result: Some(List(Bind(x)))
585+
Result: Some(List(Sym(x)))
586586

587587
Scrutinee: {
588588
def a(x: scala.Int): scala.Int = x

tests/run-macros/quote-matcher-runtime/quoted_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ object Macros {
1515
s"Expr(${r.unseal.show})"
1616
case r: quoted.Type[_] =>
1717
s"Type(${r.unseal.show})"
18-
case r: Bind[_] =>
19-
s"Bind(${r.name})"
18+
case r: Sym[_] =>
19+
s"Sym(${r.name})"
2020
}
2121
}
2222

tests/run-macros/quote-matcher-symantics-2/quoted_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Macros {
1111

1212
private def impl[T: Type](sym: Symantics[T], a: Expr[DSL])(given qctx: QuoteContext): Expr[T] = {
1313

14-
def lift(e: Expr[DSL])(implicit env: Map[Bind[DSL], Expr[T]]): Expr[T] = e match {
14+
def lift(e: Expr[DSL])(implicit env: Map[Sym[DSL], Expr[T]]): Expr[T] = e match {
1515

1616
case '{ LitDSL(${Const(c)}) } => sym.value(c)
1717

@@ -23,15 +23,15 @@ object Macros {
2323

2424
case '{ val $x: DSL = $value; $body: DSL } => lift(body)(env + (x -> lift(value)))
2525

26-
case Bind(b) if env.contains(b) => env(b)
26+
case Sym(b) if env.contains(b) => env(b)
2727

2828
case _ =>
2929
import qctx.tasty._
3030
error("Expected explicit DSL", e.unseal.pos)
3131
???
3232
}
3333

34-
def liftFun(e: Expr[DSL => DSL])(implicit env: Map[Bind[DSL], Expr[T]]): Expr[T => T] = e match {
34+
def liftFun(e: Expr[DSL => DSL])(implicit env: Map[Sym[DSL], Expr[T]]): Expr[T => T] = e match {
3535
case '{ ($x: DSL) => ($body: DSL) } =>
3636
sym.lam((y: Expr[T]) => lift(body)(env + (x -> y)))
3737

tests/run-macros/quote-matcher-symantics-3/quoted_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ object Macros {
1313

1414
given ev0 : Env = Map.empty
1515

16-
def envWith[T](id: Bind[T], ref: Expr[R[T]])(given env: Env): Env =
16+
def envWith[T](id: Sym[T], ref: Expr[R[T]])(given env: Env): Env =
1717
env.updated(id, ref)
1818

1919
object FromEnv {
20-
def unapply[T](id: Bind[T])(given Env): Option[Expr[R[T]]] =
20+
def unapply[T](id: Sym[T])(given Env): Option[Expr[R[T]]] =
2121
summon[Env].get(id).asInstanceOf[Option[Expr[R[T]]]] // We can only add binds that have the same type as the refs
2222
}
2323

@@ -50,7 +50,7 @@ object Macros {
5050
case '{ Symantics.fix[$t, $u]($f) } =>
5151
'{ $sym.fix[$t, $u]((x: R[$t => $u]) => $sym.app(${lift(f)}, x)).asInstanceOf[R[T]] }
5252

53-
case Bind(FromEnv(expr)) => expr.asInstanceOf[Expr[R[T]]]
53+
case Sym(FromEnv(expr)) => expr.asInstanceOf[Expr[R[T]]]
5454

5555
case _ =>
5656
summon[QuoteContext].error("Expected explicit value but got: " + e.show, e)

tests/run-macros/quote-type-matcher/quoted_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ object Macros {
1313
tup.toArray.toList.map {
1414
case r: quoted.Type[_] =>
1515
s"Type(${r.unseal.show})"
16-
case r: Bind[_] =>
17-
s"Bind(${r.name})"
16+
case r: Sym[_] =>
17+
s"Sym(${r.name})"
1818
}
1919
}
2020

0 commit comments

Comments
 (0)