From 7c0ee3acb4f0319040e21c242c10c819db7490ff Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Mon, 22 Nov 2010 15:02:08 +0000 Subject: Some cleanup (mainly in Typers). --- .../scala/tools/nsc/symtab/SymbolTable.scala | 9 ---- .../scala/tools/nsc/typechecker/Contexts.scala | 9 ++-- .../scala/tools/nsc/typechecker/Namers.scala | 3 +- .../scala/tools/nsc/typechecker/RefChecks.scala | 4 ++ .../scala/tools/nsc/typechecker/Typers.scala | 57 ++++++++-------------- 5 files changed, 27 insertions(+), 55 deletions(-) diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala b/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala index 281a3174f9..918f1b37ba 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala @@ -39,15 +39,6 @@ abstract class SymbolTable extends reflect.generic.Universe /** Are we compiling for .NET ? */ def forMSIL: Boolean - protected def trackTypeIDE(sym : Symbol) : Boolean = true - def compare(sym : Symbol, name : Name) = sym.name == name - def verifyAndPrioritize[T](g : Symbol => Symbol)(pt : Type)(f : => T) = f - def trackSetInfo[T <: Symbol](sym : T)(info : Type) : T = { - sym.setInfo(info); sym - } - def notifyImport(what : Name, container : Type, from : Name, to : Name) : Unit = {} - def sanitize(tree : Tree) : Tree = tree - /** A period is an ordinal number for a phase in a run. * Phases in later runs have higher periods than phases in earlier runs. * Later phases have higher periods than earlier phases in the same run. diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index ef0f38a341..f5033dc58c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -93,8 +93,8 @@ trait Contexts { self: Analyzer => class Context private[typechecker] { var unit: CompilationUnit = _ - var tree: Tree = _ // Tree associated with this context - var owner: Symbol = NoSymbol// The current owner + var tree: Tree = _ // Tree associated with this context + var owner: Symbol = NoSymbol // The current owner var scope: Scope = _ // The current scope var outer: Context = _ // The next outer context var enclClass: Context = _ // The next outer context whose tree is a @@ -150,7 +150,7 @@ trait Contexts { self: Analyzer => scope: Scope, imports: List[ImportInfo]): Context = { val c = new Context c.unit = unit - c.tree = /*sanitize*/(tree) // used to be for IDE + c.tree = tree c.owner = owner c.scope = scope @@ -588,9 +588,6 @@ trait Contexts { self: Analyzer => var renamed = false var selectors = tree.selectors while (selectors != Nil && result == NoSymbol) { -// if (selectors.head.name != nme.WILDCARD) // used to be for IDE -// notifyImport(name, qual.tpe, selectors.head.name, selectors.head.rename) - if (selectors.head.rename == name.toTermName) result = qual.tpe.nonLocalMember( // new to address #2733: consider only non-local members for imports if (name.isTypeName) selectors.head.name.toTypeName else selectors.head.name) diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index d2a5523093..0d614af3ac 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -147,8 +147,7 @@ trait Namers { self: Analyzer => newS.name.length==1 && newS.name(0)=='_') //@M: allow repeated use of `_' for higher-order type params } - // IDE hook - protected def setInfo[Sym <: Symbol](sym : Sym)(tpe : LazyType) : Sym = sym.setInfo(tpe) + private def setInfo[Sym <: Symbol](sym : Sym)(tpe : LazyType) : Sym = sym.setInfo(tpe) private def doubleDefError(pos: Position, sym: Symbol) { context.error(pos, diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index b524f2e99a..f12d7939ea 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -976,6 +976,10 @@ abstract class RefChecks extends InfoTransform { } } else { def lazyNestedObjectTrees(transformedInfo: Boolean) = { + // transformedInfo flag is necessary here because it is possible + // that the object info was already run through the transformInfo. + // Since we do not want to have duplicate lazy accessors + // (through duplicate nested object -> lazy val transformation) we have this check here. val cdef = ClassDef(mods | MODULE, name, List(), impl) .setPos(tree.pos) .setSymbol(if (!transformedInfo) sym.moduleClass else sym.lazyAccessor) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1d685a88e7..47e3686592 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -69,10 +69,9 @@ trait Typers { self: Analyzer => } } */ - // IDE hooks + def newTyper(context: Context): Typer = new NormalTyper(context) private class NormalTyper(context : Context) extends Typer(context) - // hooks for auto completion // A transient flag to mark members of anonymous classes // that are turned private by typedBlock @@ -637,7 +636,6 @@ trait Typers { self: Analyzer => * 1. Check that non-function pattern expressions are stable * 2. Check that packages and static modules are not used as values * 3. Turn tree type into stable type if possible and required by context. - * */ private def stabilize(tree: Tree, pre: Type, mode: Int, pt: Type): Tree = { if (tree.symbol.isOverloaded && (mode & FUNmode) == 0) @@ -832,7 +830,7 @@ trait Typers { self: Analyzer => if(settings.YdepMethTpes.value) mt.approximate else mt, // if we are looking for a manifest, instantiate type to Nothing anyway, // as we would get ambiguity errors otherwise. Example - // Looking for a manifest of Nil: This mas many potential types, + // Looking for a manifest of Nil: This has many potential types, // so we need to instantiate to minimal type List[Nothing]. keepNothings = false, // retract Nothing's that indicate failure, ambiguities in manifests are dealt with in manifestOfType checkCompat = isWeaklyCompatible) // #3808 @@ -932,7 +930,6 @@ trait Typers { self: Analyzer => val clazz = unapplyParameterType(unapply) if (unapply.isCase && clazz.isCase && !(clazz.ancestors exists (_.isCase))) { - if (!phase.erasedTypes) checkStable(tree) // todo: do we need to demand this? // convert synthetic unapply of case class to case class constructor val prefix = tree.tpe.prefix val tree1 = TypeTree(clazz.primaryConstructor.tpe.asSeenFrom(prefix, clazz.owner)) @@ -1318,9 +1315,8 @@ trait Typers { self: Analyzer => if (phase.id <= currentRun.typerPhase.id) { for (ann <- clazz.getAnnotation(DeprecatedAttr)) { val m = companionModuleOf(clazz, context) - if (m != NoSymbol) { + if (m != NoSymbol) m.moduleClass.addAnnotation(AnnotationInfo(ann.atp, ann.args, List())) - } } } treeCopy.ClassDef(cdef, typedMods, cdef.name, tparams1, impl2) @@ -1549,7 +1545,7 @@ trait Typers { self: Analyzer => * into the symbol's ``annotations'' in the type completer / namer) */ def removeAnnotations(mods: Modifiers): Modifiers = - Modifiers(mods.flags, mods.privateWithin, Nil, mods.positions) + mods.copy(annotations = Nil) /** * @param vdef ... @@ -1615,8 +1611,7 @@ trait Typers { self: Analyzer => val params = fn.tpe.params val args2 = if (params.isEmpty || !isRepeatedParamType(params.last.tpe)) args else args.take(params.length - 1) ::: List(EmptyTree) - if (args2.length != params.length) - assert(false, "mismatch " + clazz + " " + (params map (_.tpe)) + " " + args2)//debug + assert(args2.length == params.length, "mismatch " + clazz + " " + (params map (_.tpe)) + " " + args2)//debug (superConstr, args1 ::: args2) case Block(stats, expr) if !stats.isEmpty => decompose(stats.last) @@ -1878,8 +1873,6 @@ trait Typers { self: Analyzer => } } - protected def typedFunctionIDE(fun : Function, txt : Context) = {} - /** * @param block ... * @param mode ... @@ -2451,18 +2444,11 @@ trait Typers { self: Analyzer => } } - if (fun.symbol == List_apply && args.isEmpty && !onlyPresentation) { - atPos(tree.pos) { gen.mkNil setType restpe } - } else { - constfold(treeCopy.Apply(tree, fun, args1).setType(ifPatternSkipFormals(restpe))) - } - /* Would like to do the following instead, but curiously this fails; todo: investigate - if (fun.symbol.name == nme.apply && fun.symbol.owner == ListClass && args.isEmpty) { + if (fun.hasSymbol && fun.symbol.name == nme.apply && + fun.symbol.owner == ListClass && args.isEmpty && !onlyPresentation) atPos(tree.pos) { gen.mkNil setType restpe } - } else { + else constfold(treeCopy.Apply(tree, fun, args1).setType(ifPatternSkipFormals(restpe))) - } - */ } else if (needsInstantiation(tparams, formals, args)) { //println("needs inst "+fun+" "+tparams+"/"+(tparams map (_.info))) @@ -2811,10 +2797,12 @@ trait Typers { self: Analyzer => val name = if (sym.isType) sym.name else newTypeName(sym.name+".type") val bound = sym.existentialBound val sowner = if (isRawParameter(sym)) context.owner else sym.owner - val quantified: Symbol = sowner.newAbstractType(sym.pos, name) - trackSetInfo(quantified setFlag EXISTENTIAL)(bound.cloneInfo(quantified)) + val quantified: Symbol = sowner.newAbstractType(sym.pos, name).setFlag(EXISTENTIAL) + + quantified.setInfo(bound.cloneInfo(quantified)) + quantified } - val typeParamTypes = typeParams map (_.tpe) // don't trackSetInfo here, since type already set! + val typeParamTypes = typeParams map (_.tpe) //println("ex trans "+rawSyms+" . "+tp+" "+typeParamTypes+" "+(typeParams map (_.info)))//DEBUG for (tparam <- typeParams) tparam.setInfo(tparam.info.subst(rawSyms, typeParamTypes)) (typeParams, tp.subst(rawSyms, typeParamTypes)) @@ -3055,11 +3043,6 @@ trait Typers { self: Analyzer => TypeTree(ann.tpe) setOriginal tree } } else { - // An annotated term, created with annotation ascription - // term : @annot() - def annotTypeTree(ainfo: AnnotationInfo): Tree = //TR: function not used ?? - TypeTree(arg1.tpe.withAnnotation(ainfo)) setOriginal tree - if (ann.tpe == null) { val annotInfo = typedAnnotation(ann, annotMode) ann.tpe = arg1.tpe.withAnnotation(annotInfo) @@ -3083,7 +3066,6 @@ trait Typers { self: Analyzer => val rawInfo = vble.rawInfo vble = if (vble.name == nme.WILDCARD.toTypeName) context.scope.enter(vble) else namer.enterInScope(vble) - trackSetInfo(vble)(rawInfo) tree setSymbol vble setType vble.tpe } else { if (vble == NoSymbol) @@ -3094,7 +3076,7 @@ trait Typers { self: Analyzer => vble = namer.enterInScope(vble) } val body1 = typed(body, mode, pt) - trackSetInfo(vble)( + vble.setInfo( if (treeInfo.isSequenceValued(body)) seqType(body1.tpe) else body1.tpe) treeCopy.Bind(tree, name, body1) setSymbol vble setType body1.tpe // burak, was: pt @@ -3350,6 +3332,10 @@ trait Typers { self: Analyzer => res.tpe = res.tpe.notNull } */ + // TODO: In theory we should be able to call: + //if (fun2.hasSymbol && fun2.symbol.name == nme.apply && fun2.symbol.owner == ArrayClass) { + // But this causes cyclic reference for Array class in Cleanup. It is easy to overcome this + // by calling here ArrayClass.info here (or some other place before specialize). if (fun2.symbol == Array_apply) { val checked = gen.mkCheckInit(res) // this check is needed to avoid infinite recursion in Duplicators @@ -3357,11 +3343,6 @@ trait Typers { self: Analyzer => if (checked ne res) typed { atPos(tree.pos)(checked) } else res } else res - /* Would like to do the following instead, but curiously this fails; todo: investigate - if (fun2.symbol.name == nme.apply && fun2.symbol.owner == ArrayClass) - typed { atPos(tree.pos) { gen.mkCheckInit(res) } } - else res - */ case ex: TypeError => fun match { case Select(qual, name) @@ -3452,7 +3433,7 @@ trait Typers { self: Analyzer => if (clazz == NoSymbol) setError(tree) else { def findMixinSuper(site: Type): Type = { - val ps = site.parents filter (p => compare(p.typeSymbol, mix)) + val ps = site.parents filter (_.typeSymbol.name == mix) if (ps.isEmpty) { if (settings.debug.value) Console.println(site.parents map (_.typeSymbol.name))//debug -- cgit v1.2.3