From 0b565c0a808ba6213a41f82b318285855c6836f0 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Fri, 23 Mar 2012 16:36:37 +0100 Subject: splice in typed, dup'ed, trees for TRUE and FALSE sharing trees is bad also, substing in untyped trees into typed outer trees is not good for your health --- src/compiler/scala/tools/nsc/ast/TreeDSL.scala | 5 +++++ src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala | 6 +++--- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala index 0d19b781e2..8703de4e18 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala @@ -44,6 +44,11 @@ trait TreeDSL { def NULL = LIT(null) def UNIT = LIT(()) + // for those preferring boring, predictable lives, without the thrills of tree-sharing + // (but with the perk of typed trees) + def TRUE_typed = LIT(true) setType ConstantType(Constant(true)) + def FALSE_typed = LIT(false) setType ConstantType(Constant(false)) + object WILD { def empty = Ident(nme.WILDCARD) def apply(tpe: Type) = Ident(nme.WILDCARD) setType tpe diff --git a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala index 2091221916..4c5719b33c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala @@ -918,10 +918,10 @@ class Foo(x: Other) { x._1 } // no error in this order // one alternative may still generate multiple trees (e.g., an extractor call + equality test) // (for now,) alternatives may not bind variables (except wildcards), so we don't care about the final substitution built internally by makeTreeMakers val combinedAlts = altss map (altTreeMakers => - ((casegen: Casegen) => combineExtractors(altTreeMakers :+ TrivialTreeMaker(casegen.one(TRUE)))(casegen)) + ((casegen: Casegen) => combineExtractors(altTreeMakers :+ TrivialTreeMaker(casegen.one(TRUE_typed)))(casegen)) ) - val findAltMatcher = codegenAlt.matcher(EmptyTree, NoSymbol, BooleanClass.tpe)(combinedAlts, Some(x => FALSE)) + val findAltMatcher = codegenAlt.matcher(EmptyTree, NoSymbol, BooleanClass.tpe)(combinedAlts, Some(x => FALSE_typed)) codegenAlt.ifThenElseZero(findAltMatcher, substitution(next)) } } @@ -1713,7 +1713,7 @@ class Foo(x: Other) { x._1 } // no error in this order def flatMapCondStored(cond: Tree, condSym: Symbol, res: Tree, nextBinder: Symbol, next: Tree): Tree = ifThenElseZero(cond, BLOCK( - condSym === TRUE, + condSym === TRUE_typed, nextBinder === res, next )) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index b061f4cbc3..47d5107f18 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2203,7 +2203,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { import CODE._ // need to duplicate the cases before typing them to generate the apply method, or the symbols will be all messed up - val casesTrue = if (isPartial) cases map (c => deriveCaseDef(c)(x => TRUE).duplicate) else Nil + val casesTrue = if (isPartial) cases map (c => deriveCaseDef(c)(x => TRUE_typed).duplicate) else Nil val applyMethod = { // rig the show so we can get started typing the method body -- later we'll correct the infos... @@ -2241,7 +2241,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { methodSym setInfoAndEnter MethodType(paramSyms, BooleanClass.tpe) val (selector1, selectorTp, casesAdapted, resTp, doTranslation) = methodBodyTyper.prepareTranslateMatch(selector, casesTrue, mode, BooleanClass.tpe) - val body = methodBodyTyper.translateMatch(selector1, selectorTp, casesAdapted, resTp, doTranslation, Some(scrutinee => FALSE)) + val body = methodBodyTyper.translateMatch(selector1, selectorTp, casesAdapted, resTp, doTranslation, Some(scrutinee => FALSE_typed)) DefDef(methodSym, body) } -- cgit v1.2.3