Skip to content

Commit 721223f

Browse files
committed
Remove quoted.matching.Sym
Since quoted patterns do not return open quotes, this abstraction does not have any purpose. The only useful part of it is extracting the name of a binding, therefore instead of returning a Sym we return the name as a String directly.
1 parent aa0c87b commit 721223f

File tree

8 files changed

+18
-59
lines changed

8 files changed

+18
-59
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ class Definitions {
708708

709709
@tu lazy val QuotedTypeModule: Symbol = QuotedTypeClass.companionModule
710710

711-
@tu lazy val QuotedMatchingSymClass: ClassSymbol = ctx.requiredClass("scala.quoted.matching.Sym")
712711
@tu lazy val TastyReflectionClass: ClassSymbol = ctx.requiredClass("scala.tasty.Reflection")
713712

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

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,10 @@ trait QuotesAndSplices {
242242
x => t.resType.subst(t, x).toFunctionType())
243243
case t => t
244244
}
245-
val bindingExprTpe = AppliedType(defn.QuotedMatchingSymClass.typeRef, bindingType :: Nil)
246245
assert(ddef.name.startsWith("$"))
247246
val bindName = ddef.name.toString.stripPrefix("$").toTermName
248-
val sym = ctx0.newPatternBoundSymbol(bindName, bindingExprTpe, ddef.span)
249-
patBuf += Bind(sym, untpd.Ident(nme.WILDCARD).withType(bindingExprTpe)).withSpan(ddef.span)
247+
val sym = ctx0.newPatternBoundSymbol(bindName, defn.StringType, ddef.span)
248+
patBuf += Bind(sym, untpd.Ident(nme.WILDCARD).withType(defn.StringType)).withSpan(ddef.span)
250249
}
251250
super.transform(tree)
252251
case tdef: TypeDef if tdef.symbol.hasAnnotation(defn.InternalQuoted_patternBindHoleAnnot) =>

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

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

55
import scala.quoted._
6-
import scala.quoted.matching.Sym
76

87
private[quoted] object Matcher {
98

@@ -134,7 +133,7 @@ private[quoted] object Matcher {
134133
}
135134

136135
def bindingMatch(sym: Symbol) =
137-
matched(new Sym(sym.name, sym))
136+
matched(sym.name)
138137

139138
(scrutinee, pattern) match {
140139

library/src/scala/quoted/matching/Sym.scala

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

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.Sym[Int] = y
17+
val a: String = y
1818
z
1919
case '{ (($y: Int) => 1 + `$y` + ($z: Int))(2) } =>
20-
val a: quoted.matching.Sym[Int] = y
20+
val a: String = y
2121
z
2222
case '{ def $ff: Int = $z; `$ff` } =>
23-
val a: quoted.matching.Sym[Int] = ff
23+
val a: String = ff
2424
z
2525
case '{ def $ff(i: Int): Int = $z; 2 } =>
26-
val a: quoted.matching.Sym[Int => Int] = ff
26+
val a: String = ff
2727
z
2828
case '{ def $ff(i: Int)(j: Int): Int = $z; 2 } =>
29-
val a: quoted.matching.Sym[Int => Int => Int] = ff
29+
val a: String = ff
3030
z
3131
case '{ def $ff[T](i: T): Int = $z; 2 } =>
32-
val a: quoted.matching.Sym[[T] =>> T => Int] = ff
32+
val a: String = ff
3333
z
3434
case '{ poly[$t]($x); 4 } => ???
3535
case '{ type $X; poly[`$X`]($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.CompileTime.patternBindHole) => scala.internal.quoted.CompileTime.patternHole[scala.Predef.String])
241-
Result: Some(List(Sym(x), Expr("abc")))
241+
Result: Some(List(String(x), Expr("abc")))
242242

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

275275
Scrutinee: {
276276
val a: scala.Int = 45
@@ -502,7 +502,7 @@ Pattern: {
502502
@scala.internal.quoted.CompileTime.patternBindHole def a: scala.Int = scala.internal.quoted.CompileTime.patternHole[scala.Int]
503503
()
504504
}
505-
Result: Some(List(Sym(a), Expr(45)))
505+
Result: Some(List(String(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.CompileTime.patternBindHole): scala.Int = 45
573573
()
574574
}
575-
Result: Some(List(Sym(x)))
575+
Result: Some(List(String(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.CompileTime.patternBindHole): scala.Int = 45
583583
()
584584
}
585-
Result: Some(List(Sym(x)))
585+
Result: Some(List(String(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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.matching._
3-
42

53
object Macros {
64

@@ -15,8 +13,8 @@ object Macros {
1513
s"Expr(${r.unseal.show})"
1614
case r: quoted.Type[_] =>
1715
s"Type(${r.unseal.show})"
18-
case r: Sym[_] =>
19-
s"Sym(${r.name})"
16+
case r: String =>
17+
s"String($r)"
2018
}
2119
}
2220

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.matching._
3-
42

53
object Macros {
64

@@ -13,8 +11,8 @@ object Macros {
1311
tup.toArray.toList.map {
1412
case r: quoted.Type[_] =>
1513
s"Type(${r.unseal.show})"
16-
case r: Sym[_] =>
17-
s"Sym(${r.name})"
14+
case r: String =>
15+
s"String($r)"
1816
}
1917
}
2018

0 commit comments

Comments
 (0)