Skip to content

Remove quoted.matching.Sym #8486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ class Definitions {

@tu lazy val QuotedTypeModule: Symbol = QuotedTypeClass.companionModule

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

@tu lazy val Unpickler_unpickleExpr: Symbol = ctx.requiredMethod("scala.internal.quoted.Unpickler.unpickleExpr")
Expand Down
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,10 @@ trait QuotesAndSplices {
x => t.resType.subst(t, x).toFunctionType())
case t => t
}
val bindingExprTpe = AppliedType(defn.QuotedMatchingSymClass.typeRef, bindingType :: Nil)
assert(ddef.name.startsWith("$"))
val bindName = ddef.name.toString.stripPrefix("$").toTermName
val sym = ctx0.newPatternBoundSymbol(bindName, bindingExprTpe, ddef.span)
patBuf += Bind(sym, untpd.Ident(nme.WILDCARD).withType(bindingExprTpe)).withSpan(ddef.span)
val sym = ctx0.newPatternBoundSymbol(bindName, defn.StringType, ddef.span)
patBuf += Bind(sym, untpd.Ident(nme.WILDCARD).withType(defn.StringType)).withSpan(ddef.span)
}
super.transform(tree)
case tdef: TypeDef if tdef.symbol.hasAnnotation(defn.InternalQuoted_patternBindHoleAnnot) =>
Expand Down
3 changes: 1 addition & 2 deletions library/src/scala/internal/quoted/Matcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package scala.internal.quoted
import scala.annotation.internal.sharable

import scala.quoted._
import scala.quoted.matching.Sym

private[quoted] object Matcher {

Expand Down Expand Up @@ -134,7 +133,7 @@ private[quoted] object Matcher {
}

def bindingMatch(sym: Symbol) =
matched(new Sym(sym.name, sym))
matched(sym.name)

(scrutinee, pattern) match {

Expand Down
34 changes: 0 additions & 34 deletions library/src/scala/quoted/matching/Sym.scala

This file was deleted.

12 changes: 6 additions & 6 deletions tests/pos/quotedPatterns.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ object Test {
case '{ 1 + ($y: Int)} => y
case '{ val a = 1 + ($y: Int); 3 } => y
case '{ val $y: Int = $z; println(`$y`); 1 } =>
val a: quoted.matching.Sym[Int] = y
val a: String = y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If y is String, the semantics for the reference to y in println($y) becomes problematic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Could you elaborate

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion, now I see the $y in val $y = e has double meaning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, a $ can be in an expression position (Expr[T]), type position (Type[T]) or definition position (String)

z
case '{ (($y: Int) => 1 + `$y` + ($z: Int))(2) } =>
val a: quoted.matching.Sym[Int] = y
val a: String = y
z
case '{ def $ff: Int = $z; `$ff` } =>
val a: quoted.matching.Sym[Int] = ff
val a: String = ff
z
case '{ def $ff(i: Int): Int = $z; 2 } =>
val a: quoted.matching.Sym[Int => Int] = ff
val a: String = ff
z
case '{ def $ff(i: Int)(j: Int): Int = $z; 2 } =>
val a: quoted.matching.Sym[Int => Int => Int] = ff
val a: String = ff
z
case '{ def $ff[T](i: T): Int = $z; 2 } =>
val a: quoted.matching.Sym[[T] =>> T => Int] = ff
val a: String = ff
z
case '{ poly[$t]($x); 4 } => ???
case '{ type $X; poly[`$X`]($x); 4 } => ???
Expand Down
10 changes: 5 additions & 5 deletions tests/run-macros/quote-matcher-runtime.check
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Result: Some(List(Expr(((x: scala.Int) => "abc"))))

Scrutinee: ((x: scala.Int) => "abc")
Pattern: ((x: scala.Int @scala.internal.quoted.CompileTime.patternBindHole) => scala.internal.quoted.CompileTime.patternHole[scala.Predef.String])
Result: Some(List(Sym(x), Expr("abc")))
Result: Some(List(String(x), Expr("abc")))

Scrutinee: scala.StringContext.apply("abc", "xyz")
Pattern: scala.StringContext.apply("abc", "xyz")
Expand Down Expand Up @@ -270,7 +270,7 @@ Pattern: {
@scala.internal.quoted.CompileTime.patternBindHole val a: scala.Int = scala.internal.quoted.CompileTime.patternHole[scala.Int]
()
}
Result: Some(List(Sym(a), Expr(45)))
Result: Some(List(String(a), Expr(45)))

Scrutinee: {
val a: scala.Int = 45
Expand Down Expand Up @@ -502,7 +502,7 @@ Pattern: {
@scala.internal.quoted.CompileTime.patternBindHole def a: scala.Int = scala.internal.quoted.CompileTime.patternHole[scala.Int]
()
}
Result: Some(List(Sym(a), Expr(45)))
Result: Some(List(String(a), Expr(45)))

Scrutinee: {
def a(x: scala.Int): scala.Int = 45
Expand Down Expand Up @@ -572,7 +572,7 @@ Pattern: {
def a(x: scala.Int @scala.internal.quoted.CompileTime.patternBindHole): scala.Int = 45
()
}
Result: Some(List(Sym(x)))
Result: Some(List(String(x)))

Scrutinee: {
def a(x: scala.Int): scala.Int = 45
Expand All @@ -582,7 +582,7 @@ Pattern: {
def a(x: scala.Int @scala.internal.quoted.CompileTime.patternBindHole): scala.Int = 45
()
}
Result: Some(List(Sym(x)))
Result: Some(List(String(x)))

Scrutinee: {
def a(x: scala.Int): scala.Int = x
Expand Down
6 changes: 2 additions & 4 deletions tests/run-macros/quote-matcher-runtime/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import scala.quoted._
import scala.quoted.matching._


object Macros {

Expand All @@ -15,8 +13,8 @@ object Macros {
s"Expr(${r.unseal.show})"
case r: quoted.Type[_] =>
s"Type(${r.unseal.show})"
case r: Sym[_] =>
s"Sym(${r.name})"
case r: String =>
s"String($r)"
}
}

Expand Down
6 changes: 2 additions & 4 deletions tests/run-macros/quote-type-matcher/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import scala.quoted._
import scala.quoted.matching._


object Macros {

Expand All @@ -13,8 +11,8 @@ object Macros {
tup.toArray.toList.map {
case r: quoted.Type[_] =>
s"Type(${r.unseal.show})"
case r: Sym[_] =>
s"Sym(${r.name})"
case r: String =>
s"String($r)"
}
}

Expand Down