diff options
author | Paul Phillips <paulp@improving.org> | 2012-02-22 19:54:36 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-02-22 20:09:40 -0800 |
commit | 06384c052ec31db4bd094b949bed0f3cb3fb644b (patch) | |
tree | 221fe6e2905ebfdf186cc7c828c729ea65450789 /src/compiler/scala/reflect/internal/TreeGen.scala | |
parent | a983f2b30c352f3d62f0ac615044dcd45b1b1618 (diff) | |
download | scala-06384c052ec31db4bd094b949bed0f3cb3fb644b.tar.gz scala-06384c052ec31db4bd094b949bed0f3cb3fb644b.tar.bz2 scala-06384c052ec31db4bd094b949bed0f3cb3fb644b.zip |
Reworked and restored elidable.
Found a better elidable implementation which is robust against other
parts of the compiler doing their things. Calls to elidable methods are
replaced with zero of the same type. Elidable methods themselves remain
in place, but with their body replaced with a zero of the method return
type.
Thus is everything to be found where it is expected to be found, but
nothing will be found where nothing ought to be found. Nothing of course
will never be found.
Diffstat (limited to 'src/compiler/scala/reflect/internal/TreeGen.scala')
-rw-r--r-- | src/compiler/scala/reflect/internal/TreeGen.scala | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/compiler/scala/reflect/internal/TreeGen.scala b/src/compiler/scala/reflect/internal/TreeGen.scala index e537c6b83f..cc882ad5ed 100644 --- a/src/compiler/scala/reflect/internal/TreeGen.scala +++ b/src/compiler/scala/reflect/internal/TreeGen.scala @@ -250,20 +250,19 @@ abstract class TreeGen { * var x: T = _ * which is appropriate to the given Type. */ - def mkZero(tp: Type): Tree = { - val tree = tp.typeSymbol match { - case UnitClass => Literal(Constant()) - case BooleanClass => Literal(Constant(false)) - case FloatClass => Literal(Constant(0.0f)) - case DoubleClass => Literal(Constant(0.0d)) - case ByteClass => Literal(Constant(0.toByte)) - case ShortClass => Literal(Constant(0.toShort)) - case IntClass => Literal(Constant(0)) - case LongClass => Literal(Constant(0L)) - case CharClass => Literal(Constant(0.toChar)) - case _ => Literal(Constant(null)) - } - tree setType tp + def mkZero(tp: Type): Tree = Literal(mkConstantZero(tp)) setType tp + + def mkConstantZero(tp: Type): Constant = tp.typeSymbol match { + case UnitClass => Constant(()) + case BooleanClass => Constant(false) + case FloatClass => Constant(0.0f) + case DoubleClass => Constant(0.0d) + case ByteClass => Constant(0.toByte) + case ShortClass => Constant(0.toShort) + case IntClass => Constant(0) + case LongClass => Constant(0L) + case CharClass => Constant(0.toChar) + case _ => Constant(null) } def mkZeroContravariantAfterTyper(tp: Type): Tree = { |