diff options
author | Paul Phillips <paulp@improving.org> | 2012-01-14 12:41:40 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-01-14 14:34:46 -0800 |
commit | 3024efcbf902417017b6ec0a442a3db4cf930d22 (patch) | |
tree | 1eacda2125fe6da847db5959c047ba2df86ecbdf /src/compiler | |
parent | 2ca7d4ff90fedcd2dba654100bd8d6ce1f1ad36b (diff) | |
download | scala-3024efcbf902417017b6ec0a442a3db4cf930d22.tar.gz scala-3024efcbf902417017b6ec0a442a3db4cf930d22.tar.bz2 scala-3024efcbf902417017b6ec0a442a3db4cf930d22.zip |
Putting some of the symbol potential to work.
Renamed the parameter to all the newXXX symbol creators to "newFlags"
because I've seen too many bugs which arose from having a parameter name
which shadows a field and where mistakes can inflict subtle bugs which
won't be found until much later (yes I'm trying to describe "flags" right
now.) Opportunistically cleaned up some symbol creations.
Diffstat (limited to 'src/compiler')
10 files changed, 141 insertions, 153 deletions
diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index f4abb8cad3..d38b62cbb4 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -16,14 +16,12 @@ trait Definitions extends reflect.api.StandardDefinitions { private def newClass(owner: Symbol, name: TypeName, parents: List[Type], flags: Long = 0L): Symbol = { val clazz = owner.newClassSymbol(name, NoPosition, flags) - clazz setInfo ClassInfoType(parents, new Scope, clazz) - owner.info.decls enter clazz + clazz setInfoAndEnter ClassInfoType(parents, new Scope, clazz) } private def newMethod(owner: Symbol, name: TermName, formals: List[Type], restpe: Type, flags: Long = 0L): Symbol = { val msym = owner.newMethod(name.encode, NoPosition, flags) val params = msym.newSyntheticValueParams(formals) - msym setInfo MethodType(params, restpe) - owner.info.decls enter msym + msym setInfoAndEnter MethodType(params, restpe) } // the scala value classes @@ -130,7 +128,7 @@ trait Definitions extends reflect.api.StandardDefinitions { // the source level, but _root_ is essentially a function () => <root>. lazy val RootPackage: Symbol = { val rp = ( - NoSymbol.newValue(nme.ROOTPKG, flags = FINAL | MODULE | PACKAGE | JAVA) + NoSymbol.newValue(nme.ROOTPKG, NoPosition, FINAL | MODULE | PACKAGE | JAVA) setInfo NullaryMethodType(RootClass.tpe) ) RootClass.sourceModule = rp @@ -139,11 +137,11 @@ trait Definitions extends reflect.api.StandardDefinitions { // This is the actual root of everything, including the package _root_. lazy val RootClass: ModuleClassSymbol = ( - NoSymbol.newModuleClassSymbol(tpnme.ROOT, flags = FINAL | MODULE | PACKAGE | JAVA) + NoSymbol.newModuleClassSymbol(tpnme.ROOT, NoPosition, FINAL | MODULE | PACKAGE | JAVA) setInfo rootLoader ) // The empty package, which holds all top level types without given packages. - lazy val EmptyPackage = RootClass.newPackage(nme.EMPTY_PACKAGE_NAME, flags = FINAL) + lazy val EmptyPackage = RootClass.newPackage(nme.EMPTY_PACKAGE_NAME, NoPosition, FINAL) lazy val EmptyPackageClass = EmptyPackage.moduleClass lazy val JavaLangPackage = getModule(sn.JavaLang) @@ -208,8 +206,7 @@ trait Definitions extends reflect.api.StandardDefinitions { sealed abstract class BottomClassSymbol(name: TypeName, parent: Symbol) extends ClassSymbol(ScalaPackageClass, NoPosition, name) { locally { this initFlags ABSTRACT | TRAIT | FINAL - this setInfo ClassInfoType(List(parent.tpe), new Scope, this) - owner.info.decls enter this + this setInfoAndEnter ClassInfoType(List(parent.tpe), new Scope, this) } final override def isBottomClass = true } @@ -829,12 +826,8 @@ trait Definitions extends reflect.api.StandardDefinitions { ClassInfoType(List(AnyRefClass.tpe, p), new Scope, clazz))) } - private def newAlias(owner: Symbol, name: TypeName, alias: Type): Symbol = { - val tpsym = owner.newAliasType(name) - tpsym.setInfo(alias) - owner.info.decls.enter(tpsym) - tpsym - } + private def newAlias(owner: Symbol, name: TypeName, alias: Type): Symbol = + owner.newAliasType(name) setInfoAndEnter alias /** tcon receives the type parameter symbol as argument */ private def newPolyMethod(owner: Symbol, name: TermName, tcon: Symbol => Type): Symbol = diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index df6720d497..1b9ff54141 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -44,8 +44,8 @@ trait Symbols extends api.Symbols { self: SymbolTable => } /** Create a new free variable. Its owner is NoSymbol. */ - def newFreeVar(name: TermName, tpe: Type, value: Any, flags: Long = 0L): FreeVar = - new FreeVar(name, value) initFlags flags setInfo tpe + def newFreeVar(name: TermName, tpe: Type, value: Any, newFlags: Long = 0L): FreeVar = + new FreeVar(name, value) initFlags newFlags setInfo tpe /** The original owner of a class. Used by the backend to generate * EnclosingMethod attributes. @@ -53,9 +53,9 @@ trait Symbols extends api.Symbols { self: SymbolTable => val originalOwner = perRunCaches.newMap[Symbol, Symbol]() abstract class AbsSymbolImpl extends AbsSymbol { this: Symbol => - def newNestedSymbol(name: Name, pos: Position, flags: Long) = name match { - case n: TermName => newTermSymbol(n, pos, flags) - case n: TypeName => newTypeSymbol(n, pos, flags) + def newNestedSymbol(name: Name, pos: Position, newFlags: Long) = name match { + case n: TermName => newTermSymbol(n, pos, newFlags) + case n: TypeName => newTypeSymbol(n, pos, newFlags) } def typeSig: Type = info def typeSigIn(site: Type): Type = site.memberInfo(this) @@ -99,24 +99,24 @@ trait Symbols extends api.Symbols { self: SymbolTable => // ------ creators ------------------------------------------------------------------- - final def newValue(name: TermName, pos: Position = NoPosition, flags: Long = 0L): TermSymbol = - newTermSymbol(name, pos, flags) - final def newVariable(name: TermName, pos: Position = NoPosition, flags: Long = 0L): TermSymbol = - newTermSymbol(name, pos, MUTABLE | flags) - final def newValueParameter(name: TermName, pos: Position = NoPosition, flags: Long = 0L): TermSymbol = - newTermSymbol(name, pos, PARAM | flags) + final def newValue(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): TermSymbol = + newTermSymbol(name, pos, newFlags) + final def newVariable(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): TermSymbol = + newTermSymbol(name, pos, MUTABLE | newFlags) + final def newValueParameter(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): TermSymbol = + newTermSymbol(name, pos, PARAM | newFlags) /** Create local dummy for template (owner of local blocks) */ final def newLocalDummy(pos: Position) = newTermSymbol(nme.localDummyName(this), pos) setInfo NoType - final def newMethod(name: TermName, pos: Position = NoPosition, flags: Long = 0L): MethodSymbol = - newMethodSymbol(name, pos, METHOD | flags) + final def newMethod(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): MethodSymbol = + newMethodSymbol(name, pos, METHOD | newFlags) final def newLabel(name: TermName, pos: Position = NoPosition): MethodSymbol = newMethod(name, pos, LABEL) /** Propagates ConstrFlags (JAVA, specifically) from owner to constructor. */ - final def newConstructor(pos: Position, flags: Long = 0L) = - newMethod(nme.CONSTRUCTOR, pos, getFlag(ConstrFlags) | flags) + final def newConstructor(pos: Position, newFlags: Long = 0L) = + newMethod(nme.CONSTRUCTOR, pos, getFlag(ConstrFlags) | newFlags) /** Static constructor with info set. */ def newStaticConstructor(pos: Position) = @@ -131,19 +131,19 @@ trait Symbols extends api.Symbols { self: SymbolTable => if (isPackage || !settings.overrideObjects.value) MODULE | FINAL else MODULE ) - def newLinkedModule(clazz: Symbol, flags: Long = 0L): ModuleSymbol = { - val m = newModuleSymbol(clazz.name.toTermName, clazz.pos, ModuleFlags | flags) + def newLinkedModule(clazz: Symbol, newFlags: Long = 0L): ModuleSymbol = { + val m = newModuleSymbol(clazz.name.toTermName, clazz.pos, ModuleFlags | newFlags) connectModuleToClass(m, clazz.asInstanceOf[ClassSymbol]) } - final def newModule(name: TermName, pos: Position = NoPosition, flags: Long = 0L): ModuleSymbol = { - val m = newModuleSymbol(name, pos, flags | ModuleFlags) + final def newModule(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleSymbol = { + val m = newModuleSymbol(name, pos, newFlags | ModuleFlags) val clazz = newModuleClassSymbol(name.toTypeName, pos, (m getFlag ModuleToClassFlags) | MODULE) connectModuleToClass(m, clazz) } - final def newPackage(name: TermName, pos: Position = NoPosition, flags: Long = 0L): ModuleSymbol = { + final def newPackage(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleSymbol = { assert(name == nme.ROOT || isPackageClass, this) - newModule(name, pos, JAVA | PACKAGE | flags) + newModule(name, pos, JAVA | PACKAGE | newFlags) } final def newThisSym(pos: Position) = newTermSymbol(nme.this_, pos, SYNTHETIC) @@ -153,41 +153,41 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** Direct symbol factories. * For internal use; these are unlikely to be what you want. */ - def newTermSymbol(name: TermName, pos: Position = NoPosition, flags: Long = 0L): TermSymbol = - new TermSymbol(this, pos, name) initFlags flags + def newTermSymbol(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): TermSymbol = + new TermSymbol(this, pos, name) initFlags newFlags - def newAbstractTypeSymbol(name: TypeName, pos: Position = NoPosition, flags: Long = 0L): AbstractTypeSymbol = - new AbstractTypeSymbol(this, pos, name) initFlags flags + def newAbstractTypeSymbol(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): AbstractTypeSymbol = + new AbstractTypeSymbol(this, pos, name) initFlags newFlags - def newAliasTypeSymbol(name: TypeName, pos: Position = NoPosition, flags: Long = 0L): AliasTypeSymbol = - new AliasTypeSymbol(this, pos, name) initFlags flags + def newAliasTypeSymbol(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): AliasTypeSymbol = + new AliasTypeSymbol(this, pos, name) initFlags newFlags - def newModuleSymbol(name: TermName, pos: Position = NoPosition, flags: Long = 0L): ModuleSymbol = - new ModuleSymbol(this, pos, name) initFlags flags + def newModuleSymbol(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleSymbol = + new ModuleSymbol(this, pos, name) initFlags newFlags - def newMethodSymbol(name: TermName, pos: Position = NoPosition, flags: Long = 0L): MethodSymbol = - new MethodSymbol(this, pos, name) initFlags flags + def newMethodSymbol(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): MethodSymbol = + new MethodSymbol(this, pos, name) initFlags newFlags - def newClassSymbol(name: TypeName, pos: Position = NoPosition, flags: Long = 0L): ClassSymbol = - new ClassSymbol(this, pos, name) initFlags flags + def newClassSymbol(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): ClassSymbol = + new ClassSymbol(this, pos, name) initFlags newFlags - def newModuleClassSymbol(name: TypeName, pos: Position = NoPosition, flags: Long = 0L): ModuleClassSymbol = - new ModuleClassSymbol(this, pos, name) initFlags flags + def newModuleClassSymbol(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleClassSymbol = + new ModuleClassSymbol(this, pos, name) initFlags newFlags /** Derive whether it is an abstract type from the flags; after creation * the DEFERRED flag will be ignored. */ - def newTypeSymbol(name: TypeName, pos: Position = NoPosition, flags: Long = 0L): TypeSymbol = - if ((flags & DEFERRED) == 0L) - newAliasTypeSymbol(name, pos, flags) + def newTypeSymbol(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): TypeSymbol = + if ((newFlags & DEFERRED) == 0L) + newAliasTypeSymbol(name, pos, newFlags) else - newAbstractTypeSymbol(name, pos, flags) + newAbstractTypeSymbol(name, pos, newFlags) - def newTypeSkolemSymbol(name: TypeName, origin: AnyRef, pos: Position = NoPosition, flags: Long = 0L): TypeSkolem = - if ((flags & DEFERRED) == 0L) - new TypeSkolem(this, pos, name, origin) initFlags flags + def newTypeSkolemSymbol(name: TypeName, origin: AnyRef, pos: Position = NoPosition, newFlags: Long = 0L): TypeSkolem = + if ((newFlags & DEFERRED) == 0L) + new TypeSkolem(this, pos, name, origin) initFlags newFlags else - new TypeSkolem(this, pos, name, origin) with AbstractTypeMixin initFlags flags + new TypeSkolem(this, pos, name, origin) with AbstractTypeMixin initFlags newFlags /** @param pre type relative to which alternatives are seen. * for instance: @@ -228,18 +228,18 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** Symbol of a type definition type T = ... */ - final def newAliasType(name: TypeName, pos: Position = NoPosition, flags: Long = 0L): Symbol = - newAliasTypeSymbol(name, pos, flags) + final def newAliasType(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): Symbol = + newAliasTypeSymbol(name, pos, newFlags) /** Symbol of an abstract type type T >: ... <: ... */ - final def newAbstractType(name: TypeName, pos: Position = NoPosition, flags: Long = 0L): Symbol = - newAbstractTypeSymbol(name, pos, DEFERRED | flags) + final def newAbstractType(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): Symbol = + newAbstractTypeSymbol(name, pos, DEFERRED | newFlags) /** Symbol of a type parameter */ - final def newTypeParameter(name: TypeName, pos: Position = NoPosition, flags: Long = 0L) = - newAbstractType(name, pos, PARAM | flags) + final def newTypeParameter(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L) = + newAbstractType(name, pos, PARAM | newFlags) /** Synthetic value parameters when parameter symbols are not available */ @@ -257,8 +257,8 @@ trait Symbols extends api.Symbols { self: SymbolTable => skolem setInfo (basis.info cloneInfo skolem) } - final def newExistential(name: TypeName, pos: Position = NoPosition, flags: Long = 0L): Symbol = - newAbstractType(name, pos, EXISTENTIAL | flags) + final def newExistential(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): Symbol = + newAbstractType(name, pos, EXISTENTIAL | newFlags) final def freshExistential(suffix: String): Symbol = newExistential(freshExistentialName(suffix), pos) @@ -283,8 +283,8 @@ trait Symbols extends api.Symbols { self: SymbolTable => final def newTypeSkolem: Symbol = owner.newTypeSkolemSymbol(name.toTypeName, this, pos, flags) - final def newClass(name: TypeName, pos: Position = NoPosition) = - newClassSymbol(name, pos) + final def newClass(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L) = + newClassSymbol(name, pos, newFlags) final def newModuleClass(name: TypeName, pos: Position = NoPosition) = newModuleClassSymbol(name, pos) @@ -292,11 +292,11 @@ trait Symbols extends api.Symbols { self: SymbolTable => final def newAnonymousClass(pos: Position) = newClassSymbol(tpnme.ANON_CLASS_NAME, pos) - final def newAnonymousFunctionClass(pos: Position, flags: Long = 0L) = - newClassSymbol(tpnme.ANON_FUN_NAME, pos, FINAL | SYNTHETIC | flags) + final def newAnonymousFunctionClass(pos: Position, newFlags: Long = 0L) = + newClassSymbol(tpnme.ANON_FUN_NAME, pos, FINAL | SYNTHETIC | newFlags) - final def newAnonymousFunctionValue(pos: Position, flags: Long = 0L) = - newTermSymbol(nme.ANON_FUN_NAME, pos, SYNTHETIC | flags) setInfo NoType + final def newAnonymousFunctionValue(pos: Position, newFlags: Long = 0L) = + newTermSymbol(nme.ANON_FUN_NAME, pos, SYNTHETIC | newFlags) setInfo NoType /** Refinement types P { val x: String; type T <: Number } * also have symbols, they are refinementClasses @@ -307,7 +307,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** Create a new getter for current symbol (which must be a field) */ final def newGetter: Symbol = ( - owner.newMethod(nme.getterName(name.toTermName), flags = getterFlags(flags)) + owner.newMethod(nme.getterName(name.toTermName), NoPosition, getterFlags(flags)) setPrivateWithin privateWithin setInfo MethodType(Nil, tpe) ) @@ -1002,6 +1002,13 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** Substitute second list of symbols for first in current info. */ def substInfo(syms0: List[Symbol], syms1: List[Symbol]) = modifyInfo(_.substSym(syms0, syms1)) def setInfoOwnerAdjusted(info: Type): this.type = setInfo(info atOwner this) + + /** Set the info and enter this symbol into the owner's scope. */ + def setInfoAndEnter(info: Type): this.type = { + setInfo(info) + owner.info.decls enter this + this + } /** Set new info valid from start of this phase. */ final def updateInfo(info: Type): Symbol = { diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 3bcd36131d..3d3dd81f1b 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -1814,13 +1814,18 @@ trait Types extends api.Types { self: SymbolTable => override def typeConstructor = this // eta-expand, subtyping relies on eta-expansion of higher-kinded types - // override protected def normalizeImpl: Type = - // if (isHigherKinded) etaExpand else super.normalizeImpl + + override protected def normalizeImpl: Type = + if (isHigherKinded) etaExpand else super.normalizeImpl } trait ClassTypeRef extends TypeRef { // !!! There are scaladoc-created symbols arriving which violate this require. // require(sym.isClass, sym) + + override protected def normalizeImpl: Type = + if (sym.isRefinementClass) sym.info.normalize // I think this is okay, but see #1241 (r12414), #2208, and typedTypeConstructor in Typers + else super.normalizeImpl override def baseType(clazz: Symbol): Type = if (sym == clazz) this @@ -1873,8 +1878,20 @@ trait Types extends api.Types { self: SymbolTable => override def typeSymbol = if (this ne normalize) normalize.typeSymbol else sym // beta-reduce, but don't do partial application -- cycles have been checked in typeRef - // override protected zzImpl = - // if (typeParamsMatchArgs) betaReduce.normalize else ErrorType + override protected def normalizeImpl = + if (typeParamsMatchArgs) betaReduce.normalize + else if (isHigherKinded) super.normalizeImpl + else ErrorType + + // isHKSubType0 introduces synthetic type params so that + // betaReduce can first apply sym.info to typeArgs before calling + // asSeenFrom. asSeenFrom then skips synthetic type params, which + // are used to reduce HO subtyping to first-order subtyping, but + // which can't be instantiated from the given prefix and class. + // + // this crashes pos/depmet_implicit_tpbetareduce.scala + // appliedType(sym.info, typeArgs).asSeenFrom(pre, sym.owner) + def betaReduce = transform(sym.info.resultType) // #3731: return sym1 for which holds: pre bound sym.name to sym and // pre1 now binds sym.name to sym1, conceptually exactly the same @@ -1961,33 +1978,20 @@ trait Types extends api.Types { self: SymbolTable => // corresponding type parameters (unbound type variables) def transform(tp: Type): Type - private def normalize0: Type = ( - if (pre eq WildcardType) WildcardType // arises when argument-dependent types are approximated (see def depoly in implicits) - else if (isHigherKinded) etaExpand // eta-expand, subtyping relies on eta-expansion of higher-kinded types - else if (sym.isAliasType && typeParamsMatchArgs) betaReduce.normalize // beta-reduce, but don't do partial application -- cycles have been checked in typeRef - else if (sym.isRefinementClass) sym.info.normalize // I think this is okay, but see #1241 (r12414), #2208, and typedTypeConstructor in Typers - else if (sym.isAliasType) ErrorType //println("!!error: "+(pre, sym, sym.info, sym.info.typeParams, args)) - else super.normalize - ) + // eta-expand, subtyping relies on eta-expansion of higher-kinded types + protected def normalizeImpl: Type = if (isHigherKinded) etaExpand else super.normalize - // TODO: test case that is compiled in a specific order and in different runs - override def normalize: Type = { - if (phase.erasedTypes) normalize0 + // TODO: test case that is compiled in a specific order and in different runs + final override def normalize: Type = { + // arises when argument-dependent types are approximated (see def depoly in implicits) + if (pre eq WildcardType) WildcardType + else if (phase.erasedTypes) normalizeImpl else { if (normalized eq null) - normalized = normalize0 + normalized = normalizeImpl normalized } } - // isHKSubType0 introduces synthetic type params so that - // betaReduce can first apply sym.info to typeArgs before calling - // asSeenFrom. asSeenFrom then skips synthetic type params, which - // are used to reduce HO subtyping to first-order subtyping, but - // which can't be instantiated from the given prefix and class. - // - // this crashes pos/depmet_implicit_tpbetareduce.scala - // appliedType(sym.info, typeArgs).asSeenFrom(pre, sym.owner) - def betaReduce = transform(sym.info.resultType) def etaExpand: Type = { // must initialise symbol, see test/files/pos/ticket0137.scala diff --git a/src/compiler/scala/reflect/runtime/JavaToScala.scala b/src/compiler/scala/reflect/runtime/JavaToScala.scala index 627bad632e..cd87d6331b 100644 --- a/src/compiler/scala/reflect/runtime/JavaToScala.scala +++ b/src/compiler/scala/reflect/runtime/JavaToScala.scala @@ -337,8 +337,7 @@ trait JavaToScala extends ConversionUtil { self: SymbolTable => if (pkg == NoSymbol) { pkg = owner.newPackage(name) pkg.moduleClass setInfo new LazyPackageType - pkg setInfo pkg.moduleClass.tpe - owner.info.decls enter pkg + pkg setInfoAndEnter pkg.moduleClass.tpe info("made Scala "+pkg) } else if (!pkg.isPackage) throw new ReflectError(pkg+" is not a package") diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index eedc68fb46..b6eef8c0bb 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -465,11 +465,9 @@ abstract class ClassfileParser { } ss = name.subName(0, start) owner.info.decls lookup ss orElse { - sym = owner.newClass(NoPosition, ss.toTypeName) setInfo completer - if (opt.verboseDebug) - println("loaded "+sym+" from file "+file) - - owner.info.decls enter sym + sym = owner.newClass(NoPosition, ss.toTypeName) setInfoAndEnter completer + debuglog("loaded "+sym+" from file "+file) + sym } } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala index 767b2f1101..3c97122c9c 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala @@ -102,8 +102,7 @@ abstract class ICodeReader extends ClassfileParser { log("Could not find symbol for " + name + ": " + tpe) log(owner.info.member(name).tpe + " : " + tpe) sym = if (field) owner.newValue(name, owner.pos, toScalaFieldFlags(jflags)) else dummySym - sym setInfo tpe - owner.info.decls.enter(sym) + sym setInfoAndEnter tpe log("added " + sym + ": " + sym.tpe) } (jflags, sym) diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala index c59a819b02..8a8131c0f4 100644 --- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala +++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala @@ -247,8 +247,8 @@ abstract class AddInterfaces extends InfoTransform { addMixinConstructorDef(clazz, templ.body map implMemberDef)) .setSymbol(clazz.newLocalDummy(templ.pos)) } - new ChangeOwnerTraverser(templ.symbol.owner, clazz)( - new ChangeOwnerTraverser(templ.symbol, templ1.symbol)(templ1)) + templ1.changeOwner(templ.symbol.owner -> clazz, templ.symbol -> templ1.symbol) + templ1 } def implClassDefs(trees: List[Tree]): List[Tree] = { diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala index 4d4f4f4c27..2b3e5f311f 100644 --- a/src/compiler/scala/tools/nsc/transform/Constructors.scala +++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala @@ -105,8 +105,7 @@ abstract class Constructors extends Transform with ast.TreeDSL { // Move tree into constructor, take care of changing owner from `oldowner` to constructor symbol def intoConstructor(oldowner: Symbol, tree: Tree) = - intoConstructorTransformer.transform( - new ChangeOwnerTraverser(oldowner, constr.symbol)(tree)) + intoConstructorTransformer transform tree.changeOwner(oldowner -> constr.symbol) // Should tree be moved in front of super constructor call? def canBeMoved(tree: Tree) = tree match { @@ -454,28 +453,24 @@ abstract class Constructors extends Transform with ast.TreeDSL { def delayedInitClosure(stats: List[Tree]) = localTyper.typed { atPos(impl.pos) { - val closureClass = clazz.newClass(impl.pos, nme.delayedInitArg.toTypeName) - .setFlag(SYNTHETIC | FINAL) + val closureClass = clazz.newClass(nme.delayedInitArg.toTypeName, impl.pos, SYNTHETIC | FINAL) val closureParents = List(AbstractFunctionClass(0).tpe, ScalaObjectClass.tpe) - closureClass.setInfo(new ClassInfoType(closureParents, new Scope, closureClass)) - - val outerField = closureClass.newValue(impl.pos, nme.OUTER) - .setFlag(PrivateLocal | PARAMACCESSOR) - .setInfo(clazz.tpe) - - val applyMethod = closureClass.newMethod(impl.pos, nme.apply) - .setFlag(FINAL) - .setInfo(MethodType(List(), ObjectClass.tpe)) - - closureClass.info.decls enter outerField - closureClass.info.decls enter applyMethod - - val outerFieldDef = ValDef(outerField) - - val changeOwner = new ChangeOwnerTraverser(impl.symbol, applyMethod) + closureClass setInfoAndEnter new ClassInfoType(closureParents, new Scope, closureClass) + + val outerField = ( + closureClass + newValue(nme.OUTER, impl.pos, PrivateLocal | PARAMACCESSOR) + setInfoAndEnter clazz.tpe + ) + val applyMethod = ( + closureClass + newMethod(nme.apply, impl.pos, FINAL) + setInfoAndEnter MethodType(Nil, ObjectClass.tpe) + ) + val outerFieldDef = ValDef(outerField) val closureClassTyper = localTyper.atOwner(closureClass) - val applyMethodTyper = closureClassTyper.atOwner(applyMethod) + val applyMethodTyper = closureClassTyper.atOwner(applyMethod) val constrStatTransformer = new Transformer { override def transform(tree: Tree): Tree = tree match { @@ -507,8 +502,7 @@ abstract class Constructors extends Transform with ast.TreeDSL { } else tree case _ => - changeOwner.changeOwner(tree) - tree + tree.changeOwner(impl.symbol -> applyMethod) } } } diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala index 2180fd4f3a..0f11161914 100644 --- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala +++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala @@ -213,17 +213,14 @@ abstract class LambdaLift extends InfoTransform { atPhase(phase.next) { for ((owner, freeValues) <- free.toList) { + val newFlags = SYNTHETIC | ( if (owner.isClass) PARAMACCESSOR | PrivateLocal else PARAM ) debuglog("free var proxy: %s, %s".format(owner.fullLocationString, freeValues.toList.mkString(", "))) - - proxies(owner) = - for (fv <- freeValues.toList) yield { - val proxy = owner.newValue(owner.pos, fv.name) - .setFlag(if (owner.isClass) PARAMACCESSOR | PrivateLocal else PARAM) - .setFlag(SYNTHETIC) - .setInfo(fv.info); - if (owner.isClass) owner.info.decls enter proxy; - proxy - } + proxies(owner) = + for (fv <- freeValues.toList) yield { + val proxy = owner.newValue(fv.name, owner.pos, newFlags) setInfo fv.info + if (owner.isClass) owner.info.decls enter proxy + proxy + } } } } @@ -409,12 +406,12 @@ abstract class LambdaLift extends InfoTransform { } else tree1 case Block(stats, expr0) => - val (lzyVals, rest) = stats.partition { - case stat@ValDef(_, _, _, _) if stat.symbol.isLazy => true - case stat@ValDef(_, _, _, _) if stat.symbol.hasFlag(MODULEVAR) => true - case _ => false - } - treeCopy.Block(tree, lzyVals:::rest, expr0) + val (lzyVals, rest) = stats partition { + case stat: ValDef => stat.symbol.isLazy || stat.symbol.isModuleVar + case _ => false + } + if (lzyVals.isEmpty) tree + else treeCopy.Block(tree, lzyVals ::: rest, expr0) case _ => tree } diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 78b3446157..4c14031da3 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1166,12 +1166,9 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R } def createStaticModuleAccessor() = atPhase(phase.next) { val method = ( - sym.owner.newMethod(sym.pos, sym.name.toTermName) - setFlag (sym.flags | STABLE) - resetFlag MODULE - setInfo NullaryMethodType(sym.moduleClass.tpe) + sym.owner.newMethod(sym.name.toTermName, sym.pos, (sym.flags | STABLE) & ~MODULE) + setInfoAndEnter NullaryMethodType(sym.moduleClass.tpe) ) - sym.owner.info.decls enter method localTyper.typedPos(tree.pos)(gen.mkModuleAccessDef(method, sym)) } def createInnerModuleAccessor(vdef: Tree) = List( |