diff options
author | Paul Phillips <paulp@improving.org> | 2011-06-07 18:06:34 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-06-07 18:06:34 +0000 |
commit | 5fa1978fac07e62570409c649faf3021b2709a18 (patch) | |
tree | 8b19cfb63beae7651d5edfa562d313aa489c3860 /src | |
parent | fec42c1f3a6753f962a03b22c4728f8f791dbb66 (diff) | |
download | scala-5fa1978fac07e62570409c649faf3021b2709a18.tar.gz scala-5fa1978fac07e62570409c649faf3021b2709a18.tar.bz2 scala-5fa1978fac07e62570409c649faf3021b2709a18.zip |
Modified erasure not to generate instance tests...
Modified erasure not to generate instance tests for statically known
types. It appears the production of types like "Foo with Bar" in the
pattern matcher (where the scrutinee is known to be Foo) has been a
major contributor of suboptimal pattern matches. I will also fix it in
the matcher, but it makes sense to catch it in erasure as both a check
on the matcher and because they may come from elsewhere too. Review by
odersky.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Erasure.scala | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 915aba63db..2cf3d06866 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -1022,9 +1022,18 @@ abstract class Erasure extends AddInterfaces Apply(Select(qual, cmpOp), List(gen.mkAttributedQualifier(targ.tpe))) } case RefinedType(parents, decls) if (parents.length >= 2) => - gen.evalOnce(qual, currentOwner, unit) { q => + // Optimization: don't generate isInstanceOf tests if the static type + // conforms, because it always succeeds. (Or at least it had better.) + // At this writing the pattern matcher generates some instance tests + // involving intersections where at least one parent is statically known true. + // That needs fixing, but filtering the parents here adds an additional + // 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 => atPos(tree.pos) { - parents map mkIsInstanceOf(q) reduceRight gen.mkAnd + parentTests map mkIsInstanceOf(q) reduceRight gen.mkAnd } } case _ => |