Skip to content

Commit 87f7d52

Browse files
committed
Rename Binding to Bind
1 parent a806f71 commit 87f7d52

File tree

8 files changed

+41
-40
lines changed

8 files changed

+41
-40
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ class Definitions {
742742
lazy val QuotedTypeModuleRef: TermRef = ctx.requiredModuleRef("scala.quoted.Type")
743743
def QuotedTypeModule(implicit ctx: Context): Symbol = QuotedTypeModuleRef.symbol
744744

745-
lazy val QuotedMatchingBindingType: TypeRef = ctx.requiredClassRef("scala.quoted.matching.Binding")
745+
lazy val QuotedMatchingBindingType: TypeRef = ctx.requiredClassRef("scala.quoted.matching.Bind")
746746
def QuotedMatchingBindingClass(implicit ctx: Context): ClassSymbol = QuotedMatchingBindingType.symbol.asClass
747747

748748
def Unpickler_unpickleExpr: TermSymbol = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleExpr")

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

Lines changed: 9 additions & 8 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.Binding
6+
import scala.quoted.matching.Bind
77
import scala.tasty._
88

99
object Matcher {
@@ -31,7 +31,8 @@ object Matcher {
3131
* @return None if it did not match, `Some(tup)` if it matched where `tup` contains `Expr[Ti]``
3232
*/
3333
def unapply[Tup <: Tuple](scrutineeExpr: Expr[_])(implicit patternExpr: Expr[_], reflection: Reflection): Option[Tup] = {
34-
import reflection._
34+
import reflection.{Bind => BindPattern, _}
35+
3536
// TODO improve performance
3637

3738
/** Check that the trees match and return the contents from the pattern holes.
@@ -53,15 +54,15 @@ object Matcher {
5354
}
5455

5556
def bindingMatch(sym: Symbol) =
56-
Some(Tuple1(new Binding(sym.name, sym)))
57+
Some(Tuple1(new Bind(sym.name, sym)))
5758

58-
def hasBindingTypeAnnotation(tpt: TypeTree): Boolean = tpt match {
59+
def hasBindTypeAnnotation(tpt: TypeTree): Boolean = tpt match {
5960
case Annotated(tpt2, Apply(Select(New(TypeIdent("patternBindHole")), "<init>"), Nil)) => true
60-
case Annotated(tpt2, _) => hasBindingTypeAnnotation(tpt2)
61+
case Annotated(tpt2, _) => hasBindTypeAnnotation(tpt2)
6162
case _ => false
6263
}
6364

64-
def hasBindingAnnotation(sym: Symbol) =
65+
def hasBindAnnotation(sym: Symbol) =
6566
sym.annots.exists { case Apply(Select(New(TypeIdent("patternBindHole")),"<init>"),List()) => true; case _ => true }
6667

6768
def treesMatch(scrutinees: List[Tree], patterns: List[Tree]): Option[Tuple] =
@@ -156,7 +157,7 @@ object Matcher {
156157

157158
case (ValDef(_, tpt1, rhs1), ValDef(_, tpt2, rhs2)) if checkValFlags() =>
158159
val bindMatch =
159-
if (hasBindingAnnotation(pattern.symbol) || hasBindingTypeAnnotation(tpt2)) bindingMatch(scrutinee.symbol)
160+
if (hasBindAnnotation(pattern.symbol) || hasBindTypeAnnotation(tpt2)) bindingMatch(scrutinee.symbol)
160161
else Some(())
161162
val returnTptMatch = treeMatches(tpt1, tpt2)
162163
val rhsEnv = env + (scrutinee.symbol -> pattern.symbol)
@@ -169,7 +170,7 @@ object Matcher {
169170
if (paramss1.size != paramss2.size) None
170171
else foldMatchings(paramss1.zip(paramss2).map { (params1, params2) => treesMatch(params1, params2) }: _*)
171172
val bindMatch =
172-
if (hasBindingAnnotation(pattern.symbol)) bindingMatch(scrutinee.symbol)
173+
if (hasBindAnnotation(pattern.symbol)) bindingMatch(scrutinee.symbol)
173174
else Some(())
174175
val tptMatch = treeMatches(tpt1, tpt2)
175176
val rhsEnv =

library/src-bootstrapped/scala/quoted/matching/Binding.scala renamed to library/src-bootstrapped/scala/quoted/matching/Bind.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ package matching
33

44
import scala.tasty.Reflection // TODO do not depend on reflection directly
55

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

1313
override def equals(obj: Any): Boolean = obj match {
14-
case obj: Binding[_] => obj.id == id
14+
case obj: Bind[_] => obj.id == id
1515
case _ => false
1616
}
1717

1818
override def hashCode(): Int = id.hashCode()
1919

2020
}
2121

22-
object Binding {
22+
object Bind {
2323

24-
def unapply[T](expr: Expr[T])(implicit reflect: Reflection): Option[Binding[T]] = {
25-
import reflect._
24+
def unapply[T](expr: Expr[T])(implicit reflect: Reflection): Option[Bind[T]] = {
25+
import reflect.{Bind => BindPattern, _}
2626
expr.unseal match {
2727
case IsIdent(ref) =>
2828
val sym = ref.symbol
29-
Some(new Binding[T](sym.name, sym))
29+
Some(new Bind[T](sym.name, sym))
3030
case _ => None
3131
}
3232
}

library/src-non-bootstrapped/scala/quoted/matching/Binding.scala renamed to library/src-non-bootstrapped/scala/quoted/matching/Bind.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ package matching
33

44
import scala.tasty.Reflection // TODO do not depend on reflection directly
55

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

1313
override def equals(obj: Any): Boolean = obj match {
14-
case obj: Binding[_] => obj.id == id
14+
case obj: Bind[_] => obj.id == id
1515
case _ => false
1616
}
1717

1818
override def hashCode(): Int = id.hashCode()
1919

2020
}
2121

22-
object Binding {
22+
object Bind {
2323

24-
def unapply[T](expr: Expr[T])(implicit reflect: Reflection): Option[Binding[T]] = {
25-
import reflect._
24+
def unapply[T](expr: Expr[T])(implicit reflect: Reflection): Option[Bind[T]] = {
25+
import reflect.{Bind => BindPattern, _}
2626
expr.unseal match {
2727
case IsIdent(ref) =>
2828
val sym = ref.symbol
29-
Some(new Binding[T](sym.name, sym))
29+
Some(new Bind[T](sym.name, sym))
3030
case _ => None
3131
}
3232
}

tests/pos/quotedPatterns.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ object Test {
1717
// I believe this is because implicit arguments are not taken
1818
// into account when checking whether we have already seen an `unapply` before.
1919
case '{ val $y: Int = $z; 1 } =>
20-
val a: quoted.matching.Binding[Int] = y
20+
val a: quoted.matching.Bind[Int] = y
2121
z
2222
case '{ (($y: Int) => 1 + y + ($z: Int))(2) } =>
23-
val a: quoted.matching.Binding[Int] = y
23+
val a: quoted.matching.Bind[Int] = y
2424
z
2525
case '{ def $ff: Int = $z; ff } =>
26-
val a: quoted.matching.Binding[Int] = ff
26+
val a: quoted.matching.Bind[Int] = ff
2727
z
2828
case '{ def $ff(i: Int): Int = $z; 2 } =>
29-
val a: quoted.matching.Binding[Int => Int] = ff
29+
val a: quoted.matching.Bind[Int => Int] = ff
3030
z
3131
case '{ def $ff(i: Int)(j: Int): Int = $z; 2 } =>
32-
val a: quoted.matching.Binding[Int => Int => Int] = ff
32+
val a: quoted.matching.Bind[Int => Int => Int] = ff
3333
z
3434
case '{ def $ff[T](i: T): Int = $z; 2 } =>
35-
val a: quoted.matching.Binding[[T] => T => Int] = ff
35+
val a: quoted.matching.Bind[[T] => T => Int] = ff
3636
z
3737
case _ => '{1}
3838
}

tests/run-with-compiler/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(Binding(x), Expr("abc")))
241+
Result: Some(List(Bind(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(Binding(a), Expr(45)))
273+
Result: Some(List(Bind(a), Expr(45)))
274274

275275
Scrutinee: {
276276
val a: scala.Int = 45
@@ -470,7 +470,7 @@ Pattern: {
470470
@scala.internal.Quoted.patternBindHole def a: scala.Int = scala.internal.Quoted.patternHole[scala.Int]
471471
()
472472
}
473-
Result: Some(List(Binding(a), Expr(45)))
473+
Result: Some(List(Bind(a), Expr(45)))
474474

475475
Scrutinee: {
476476
def a(x: scala.Int): scala.Int = 45
@@ -540,7 +540,7 @@ Pattern: {
540540
def a(x: scala.Int @scala.internal.Quoted.patternBindHole): scala.Int = 45
541541
()
542542
}
543-
Result: Some(List(Binding(x)))
543+
Result: Some(List(Bind(x)))
544544

545545
Scrutinee: {
546546
def a(x: scala.Int): scala.Int = 45
@@ -550,7 +550,7 @@ Pattern: {
550550
def a(x: scala.Int @scala.internal.Quoted.patternBindHole): scala.Int = 45
551551
()
552552
}
553-
Result: Some(List(Binding(x)))
553+
Result: Some(List(Bind(x)))
554554

555555
Scrutinee: {
556556
def a(x: scala.Int): scala.Int = x

tests/run-with-compiler/quote-matcher-runtime/quoted_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ object Macros {
88
inline def matches[A, B](a: => A, b: => B): Unit = ${impl('a, 'b)}
99

1010
private def impl[A, B](a: Expr[A], b: Expr[B])(implicit reflect: Reflection): Expr[Unit] = {
11-
import reflect._
11+
import reflect.{Bind => _, _}
1212

1313
val res = scala.internal.quoted.Matcher.unapply[Tuple](a)(b, reflect).map { tup =>
1414
tup.toArray.toList.map {
1515
case r: Expr[_] =>
1616
s"Expr(${r.unseal.show})"
1717
case r: quoted.Type[_] =>
1818
s"Type(${r.unseal.show})"
19-
case r: Binding[_] =>
20-
s"Binding(${r.name})"
19+
case r: Bind[_] =>
20+
s"Bind(${r.name})"
2121
}
2222
}
2323

tests/run-with-compiler/quote-matcher-symantics-2/quoted_1.scala

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

1414
private def impl[T: Type](sym: Symantics[T], a: Expr[DSL])(implicit reflect: Reflection): Expr[T] = {
1515

16-
def lift(e: Expr[DSL])(implicit env: Map[Binding[DSL], Expr[T]]): Expr[T] = e match {
16+
def lift(e: Expr[DSL])(implicit env: Map[Bind[DSL], Expr[T]]): Expr[T] = e match {
1717

1818
case '{ LitDSL(${Literal(c)}) } => sym.value(c)
1919

@@ -25,15 +25,15 @@ object Macros {
2525

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

28-
case Binding(b) if env.contains(b) => env(b)
28+
case Bind(b) if env.contains(b) => env(b)
2929

3030
case _ =>
3131
import reflect._
3232
error("Expected explicit DSL", e.unseal.pos)
3333
???
3434
}
3535

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

0 commit comments

Comments
 (0)