Skip to content

Commit

Permalink
[backport] Fix SI-6637 (misoptimization in erasure)
Browse files Browse the repository at this point in the history
commit f9ef5300ab561628e53c654df9000c75f488d74a
Author: Jan Niehusmann <jan@gondor.com>
Date:   Fri Nov 9 15:05:58 2012 +0100

    Fix SI-6637 (misoptimization in erasure)

    Move the optimization one level deeper so the expression
    being tested with isInstanceOf is always evaluated.
    (cherry picked from commit b540aae)
  • Loading branch information
retronym committed Jan 22, 2013
1 parent 884737c commit 4dceb22
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/compiler/scala/tools/nsc/transform/Erasure.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1057,17 +1057,17 @@ abstract class Erasure extends AddInterfaces
Apply(Select(qual, cmpOp), List(gen.mkAttributedQualifier(targ.tpe))) Apply(Select(qual, cmpOp), List(gen.mkAttributedQualifier(targ.tpe)))
} }
case RefinedType(parents, decls) if (parents.length >= 2) => case RefinedType(parents, decls) if (parents.length >= 2) =>
// Optimization: don't generate isInstanceOf tests if the static type gen.evalOnce(qual, currentOwner, unit) { q =>
// conforms, because it always succeeds. (Or at least it had better.) // Optimization: don't generate isInstanceOf tests if the static type
// At this writing the pattern matcher generates some instance tests // conforms, because it always succeeds. (Or at least it had better.)
// involving intersections where at least one parent is statically known true. // At this writing the pattern matcher generates some instance tests
// That needs fixing, but filtering the parents here adds an additional // involving intersections where at least one parent is statically known true.
// level of robustness (in addition to the short term fix.) // That needs fixing, but filtering the parents here adds an additional
val parentTests = parents filterNot (qual.tpe <:< _) // level of robustness (in addition to the short term fix.)

val parentTests = parents filterNot (qual.tpe <:< _)
if (parentTests.isEmpty) Literal(Constant(true))
else gen.evalOnce(qual, currentOwner, unit) { q => if (parentTests.isEmpty) Literal(Constant(true))
atPos(tree.pos) { else atPos(tree.pos) {
parentTests map mkIsInstanceOf(q) reduceRight gen.mkAnd parentTests map mkIsInstanceOf(q) reduceRight gen.mkAnd
} }
} }
Expand Down
1 change: 1 addition & 0 deletions test/files/run/t6637.check
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
ok
8 changes: 8 additions & 0 deletions test/files/run/t6637.scala
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,8 @@

object Test extends App {
try {
class A ; class B ; List().head.isInstanceOf[A with B]
} catch {
case _ :java.util.NoSuchElementException => println("ok")
}
}

0 comments on commit 4dceb22

Please sign in to comment.