Skip to content

Commit 325a113

Browse files
committed
wip
1 parent d61eabb commit 325a113

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,20 @@ object PickledQuotes {
3535
def quotedExprToTree[T](expr: quoted.Expr[T])(implicit ctx: Context): Tree = expr match {
3636
case expr: TastyExpr[_] =>
3737
val unpickled = unpickleExpr(expr)
38-
val force = new TreeTraverser {
39-
def traverse(tree: tpd.Tree)(implicit ctx: Context): Unit = traverseChildren(tree)
38+
val forceAndCleanArtifacts = new TreeMap {
39+
override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
40+
case tree: TypeDef if tree.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => Thicket()
41+
case tree =>
42+
val dealiasTypeTags = new TypeMap() {
43+
override def apply(tp: Type): Type = mapOver(tp match {
44+
case tp: TypeRef if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => tp.dealias
45+
case _ => tp
46+
})
47+
}
48+
super.transform(tree).withType(dealiasTypeTags(tree.tpe))
49+
}
4050
}
41-
force.traverse(unpickled)
42-
unpickled
51+
forceAndCleanArtifacts.transform(unpickled)
4352
case expr: LiftedExpr[T] =>
4453
expr.value match {
4554
case value: Class[_] => ref(defn.Predef_classOf).appliedToType(classToType(value))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,7 @@ class Typer extends Namer
20712071
Literal(Constant(typeBindings.nonEmpty)) ::
20722072
implicitArgTree(defn.QuoteContextType, quoteSpan) :: Nil,
20732073
patterns = splicePat :: Nil,
2074-
proto = defn.QuotedExprType.appliedTo(quoted1.tpe & quotedPt))
2074+
proto = defn.QuotedExprType.appliedTo(replaceBindings(quoted1.tpe) & quotedPt))
20752075
}
20762076

20772077
/** Split a typed quoted pattern is split into its type bindings, pattern expression and inner patterns.

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,6 @@ object Matcher {
8080
def normalize(tree: Tree): Tree = tree match {
8181
case Block(Nil, expr) => normalize(expr)
8282
case Block(stats1, Block(stats2, expr)) => normalize(Block(stats1 ::: stats2, expr))
83-
// case Block(stats, expr) =>
84-
// val stats1 = stats.filter { // TODO filterConserve
85-
// case IsTypeDef(s) =>
86-
// !s.symbol.annots.exists(_.symbol.owner == kernel.Definitions_InternalQuoted_quoteTypeTagAnnot) &&
87-
// !hasBindAnnotation(s.symbol)
88-
// case _ => true
89-
// }
90-
// if (stats1.isEmpty) normalize(expr)
91-
// else Block.copy(tree)(stats1, expr)
9283
case Inlined(_, Nil, expr) => normalize(expr)
9384
case _ => tree
9485
}

tests/run-macros/quote-matching-optimize-1.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Optimized: ls2.filter(((x: scala.Char) => x.<('c').&&(x.>('a'))))
77
Result: List(b)
88

99
Original: ls.filter(((x: scala.Int) => x.<(3))).filter(((x: scala.Int) => x.>(1))).filter(((x: scala.Int) => x.==(2)))
10-
Optimized: ls.filter(((x: scala.Int) => x.<(3))).filter(((x: scala.Int) => x.>(1).&&(x.==(2))))
10+
Optimized: ls.filter(((x: scala.Int) => x.<(3).&&(x.>(1).&&(x.==(2)))))
1111
Result: List(2)
1212

1313
1

tests/run-macros/quote-matching-optimize-2.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Optimized: ls2.filter(((x: scala.Char) => x.<('c').&&(x.>('a'))))
77
Result: List(b)
88

99
Original: ls.filter(((x: scala.Int) => x.<(3))).filter(((x: scala.Int) => x.>(1))).filter(((x: scala.Int) => x.==(2)))
10-
Optimized: ls.filter(((x: scala.Int) => x.<(3))).filter(((x: scala.Int) => x.>(1).&&(x.==(2))))
10+
Optimized: ls.filter(((x: scala.Int) => x.<(3).&&(x.>(1).&&(x.==(2)))))
1111
Result: List(2)
1212

1313
1

tests/run-macros/quote-matching-optimize-3.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Optimized: ls2.filter(((x: scala.Char) => ((x: scala.Char) => x.<('c')).apply(x)
77
Result: List(b)
88

99
Original: ls.filter(((x: scala.Int) => x.<(3))).filter(((x: scala.Int) => x.>(1))).filter(((x: scala.Int) => x.==(2)))
10-
Optimized: ls.filter(((x: scala.Int) => x.<(3))).filter(((x: scala.Int) => ((x: scala.Int) => x.>(1)).apply(x).&&(((x: scala.Int) => x.==(2)).apply(x))))
10+
Optimized: ls.filter(((x: scala.Int) => ((x: scala.Int) => x.<(3)).apply(x).&&(((x: scala.Int) => ((x: scala.Int) => x.>(1)).apply(x).&&(((x: scala.Int) => x.==(2)).apply(x))).apply(x))))
1111
Result: List(2)
1212

1313
1

0 commit comments

Comments
 (0)