Skip to content

Commit de4dd2c

Browse files
Fix t4859
1 parent ce50cfe commit de4dd2c

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

compiler/src/dotty/tools/dotc/transform/linker/Simplify.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
245245
case _ => fun
246246
}
247247
val constructor = a.symbol.owner.companionClass.primaryConstructor.asTerm
248-
rollInArgs(argss.tail, New(a.tpe.widenDealias, constructor, argss.head))
248+
evalReciever(a, rollInArgs(argss.tail, New(a.tpe.widenDealias, constructor, argss.head)))
249249

250250
// For synthetic dotty unapplies on case classes:
251251
// - CC.unapply(arg): CC → arg
@@ -1207,12 +1207,12 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
12071207
// Either a duplicate or a read through series of immutable fields
12081208
val copies = mutable.HashMap[Symbol, Tree]()
12091209
def visitType(tp: Type): Unit = {
1210-
tp.foreachPart(x => x match {
1211-
case TermRef(NoPrefix, _) =>
1212-
val b4 = timesUsedAsType.getOrElseUpdate(x.termSymbol, 0)
1213-
timesUsedAsType.put(x.termSymbol, b4 + 1)
1214-
case _ =>
1215-
})
1210+
tp.foreachPart(x => x match {
1211+
case TermRef(NoPrefix, _) =>
1212+
val b4 = timesUsedAsType.getOrElseUpdate(x.termSymbol, 0)
1213+
timesUsedAsType.put(x.termSymbol, b4 + 1)
1214+
case _ =>
1215+
})
12161216
}
12171217
def doVisit(tree: Tree, used: mutable.HashMap[Symbol, Int]): Unit = tree match {
12181218
case valdef: ValDef if !valdef.symbol.is(Param | Mutable | Module | Lazy) &&
@@ -1237,8 +1237,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
12371237

12381238
case valdef: ValDef => visitType(valdef.symbol.info)
12391239
case t: DefDef => visitType(t.symbol.info)
1240-
case t: Typed =>
1241-
visitType(t.tpt.tpe)
1240+
case t: Typed => visitType(t.tpt.tpe)
12421241
case t: TypeApply => t.args.foreach(x => visitType(x.tpe))
12431242
case t: RefTree =>
12441243
val b4 = used.getOrElseUpdate(t.symbol, 0)

compiler/test/dotty/tools/dotc/SimplifyTests.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ class DottyBytecodeOptimisedTest extends DottyBytecodeTest {
2020
}
2121

2222
trait SimplifyEquivalences { self: DottyBytecodeTest =>
23-
def check(expr1: String, expr2: String, shared: String = ""): Unit = {
23+
def check(source: String, expected: String, shared: String = ""): Unit = {
2424
import ASMConverters._
25-
val source =
25+
val src =
2626
s"""
2727
$shared
2828
|class A {
2929
| def main(): Unit = {
30-
$expr1
30+
$source
3131
| }
3232
|}
3333
|class B {
3434
| def main(): Unit = {
35-
$expr2
35+
$expected
3636
| }
3737
|}
3838
""".stripMargin
39-
checkBCode(source) { dir =>
39+
checkBCode(src) { dir =>
4040
def instructions(clazz: String): List[Instruction] = {
4141
val clsIn = dir.lookupName(s"$clazz.class", directory = false).input
4242
val clsNode = loadClassNode(clsIn)
@@ -46,9 +46,9 @@ trait SimplifyEquivalences { self: DottyBytecodeTest =>
4646
val B = instructions("B")
4747
val diff = diffInstructions(A, B)
4848
if (this.isInstanceOf[DottyBytecodeOptimisedTest])
49-
assert(A == B, s"Bytecode wasn't same:\n$diff")
49+
assert(A == B, s"Bytecode doesn't match: (lhs = source, rhs = expected) \n$diff")
5050
else
51-
assert(A != B, s"Bytecode was the same:\n$diff")
51+
assert(A != B, s"Same Bytecodes without -optimise: you are testing the wrong thing!")
5252
}
5353
}
5454

@@ -62,9 +62,9 @@ trait SimplifyEquivalences { self: DottyBytecodeTest =>
6262

6363
@Test def inlineCaseIntrinsicsDottyApply =
6464
check(
65-
expr1 = "CC.apply(1, 2)",
66-
expr2 = "new CC(1, 2)",
67-
shared = "case class CC(i: Int, j: Int)")
65+
source = "CC.apply(1, 2)",
66+
expected = "new CC(1, 2)",
67+
shared = "case class CC(i: Int, j: Int)")
6868

6969
@Test def inlineCaseIntrinsicsScalacApply =
7070
check("::.apply(1, Nil)", "new ::(1, Nil)")

0 commit comments

Comments
 (0)