Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traverser and Pickler improvements. #3033

Merged
merged 5 commits into from Oct 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
852 changes: 178 additions & 674 deletions src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/Namers.scala
Expand Up @@ -425,11 +425,10 @@ trait Namers extends MethodSynthesis {
sym
}

/** Enter a module symbol. The tree parameter can be either
* a module definition or a class definition.
/** Enter a module symbol.
*/
def enterModuleSymbol(tree : ModuleDef): Symbol = {
var m: Symbol = context.scope lookupAll tree.name find (_.isModule) getOrElse NoSymbol
var m: Symbol = context.scope lookupModule tree.name
val moduleFlags = tree.mods.flags | MODULE
if (m.isModule && !m.isPackage && inCurrentScope(m) && (currentRun.canRedefine(m) || m.isSynthetic)) {
updatePosFlags(m, tree.pos, moduleFlags)
Expand Down
8 changes: 5 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala
Expand Up @@ -283,6 +283,9 @@ abstract class TreeCheckers extends Analyzer {
}

private def traverseInternal(tree: Tree) {
if (!tree.canHaveAttrs)
return

checkSymbolRefsRespectScope(enclosingMemberDefs takeWhile (md => !md.symbol.hasPackageFlag), tree)
checkReturnReferencesDirectlyEnclosingDef(tree)

Expand Down Expand Up @@ -329,10 +332,9 @@ abstract class TreeCheckers extends Analyzer {
return
case _ =>
}

if (tree.canHaveAttrs && tree.pos == NoPosition)
if (tree.pos == NoPosition)
noPos(tree)
else if (tree.tpe == null && phase.id > currentRun.typerPhase.id)
else if (tree.tpe == null && isPastTyper)
noType(tree)
else if (tree.isDef) {
checkSym(tree)
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -13,7 +13,7 @@ package scala
package tools.nsc
package typechecker

import scala.collection.mutable
import scala.collection.{ mutable, immutable }
import scala.reflect.internal.util.{ BatchSourceFile, Statistics, shortClassOfInstance }
import mutable.ListBuffer
import symtab.Flags._
Expand Down Expand Up @@ -3405,7 +3405,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
else {
val annScope = annType.decls
.filter(sym => sym.isMethod && !sym.isConstructor && sym.isJavaDefined)
val names = new scala.collection.mutable.HashSet[Symbol]
val names = mutable.Set[Symbol]()
names ++= (if (isJava) annScope.iterator
else typedFun.tpe.params.iterator)

Expand All @@ -3418,7 +3418,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
val nvPairs = args map {
case arg @ AssignOrNamedArg(Ident(name), rhs) =>
val sym = if (isJava) annScope.lookup(name)
else typedFun.tpe.params.find(p => p.name == name).getOrElse(NoSymbol)
else findSymbol(typedFun.tpe.params)(_.name == name)
if (sym == NoSymbol) {
reportAnnotationError(UnknownAnnotationNameError(arg, name))
(nme.ERROR, None)
Expand Down Expand Up @@ -3545,8 +3545,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
while (o != owner && o != NoSymbol && !o.hasPackageFlag) o = o.owner
o == owner && !isVisibleParameter(sym)
}
var localSyms = scala.collection.immutable.Set[Symbol]()
var boundSyms = scala.collection.immutable.Set[Symbol]()
var localSyms = immutable.Set[Symbol]()
var boundSyms = immutable.Set[Symbol]()
def isLocal(sym: Symbol): Boolean =
if (sym == NoSymbol || sym.isRefinementClass || sym.isLocalDummy) false
else if (owner == NoSymbol) tree exists (defines(_, sym))
Expand Down Expand Up @@ -4126,7 +4126,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
NotAMemberError(tpt, TypeTree(tp), nme.CONSTRUCTOR)
setError(tpt)
}
else if (!( tp == sym.thisSym.tpe_* // when there's no explicit self type -- with (#3612) or without self variable
else if (!( tp == sym.typeOfThis // when there's no explicit self type -- with (#3612) or without self variable
// sym.thisSym.tpe == tp.typeOfThis (except for objects)
|| narrowRhs(tp) <:< tp.typeOfThis
|| phase.erasedTypes
Expand Down
28 changes: 21 additions & 7 deletions src/reflect/scala/reflect/api/Trees.scala
Expand Up @@ -2544,18 +2544,32 @@ trait Trees { self: Universe =>
class Traverser {
protected[scala] var currentOwner: Symbol = rootMirror.RootClass

/** Traverse something which Trees contain, but which isn't a Tree itself. */
def traverseName(name: Name): Unit = ()
def traverseConstant(c: Constant): Unit = ()
def traverseImportSelector(sel: ImportSelector): Unit = ()
def traverseModifiers(mods: Modifiers): Unit = traverseAnnotations(mods.annotations)

/** Traverses a single tree. */
def traverse(tree: Tree): Unit = itraverse(this, tree)
def traverse(tree: Tree): Unit = itraverse(this, tree)
def traversePattern(pat: Tree): Unit = traverse(pat)
def traverseGuard(guard: Tree): Unit = traverse(guard)
def traverseTypeAscription(tpt: Tree): Unit = traverse(tpt)
// Special handling of noSelfType necessary for backward compat: existing
// traversers break down when they see the unexpected tree.
def traverseSelfType(self: ValDef): Unit = if (self ne noSelfType) traverse(self)

/** Traverses a list of trees. */
def traverseTrees(trees: List[Tree]) {
trees foreach traverse
}
def traverseTrees(trees: List[Tree]): Unit = trees foreach traverse
def traverseTypeArgs(args: List[Tree]): Unit = traverseTrees(args)
def traverseParents(parents: List[Tree]): Unit = traverseTrees(parents)
def traverseCases(cases: List[CaseDef]): Unit = traverseTrees(cases)
def traverseAnnotations(annots: List[Tree]): Unit = traverseTrees(annots)

/** Traverses a list of lists of trees. */
def traverseTreess(treess: List[List[Tree]]) {
treess foreach traverseTrees
}
def traverseTreess(treess: List[List[Tree]]): Unit = treess foreach traverseTrees
def traverseParams(params: List[Tree]): Unit = traverseTrees(params)
def traverseParamss(vparamss: List[List[Tree]]): Unit = vparamss foreach traverseParams

/** Traverses a list of trees with a given owner symbol. */
def traverseStats(stats: List[Tree], exprOwner: Symbol) {
Expand Down
2 changes: 2 additions & 0 deletions src/reflect/scala/reflect/internal/AnnotationInfos.scala
Expand Up @@ -27,6 +27,8 @@ trait AnnotationInfos extends api.Annotations { self: SymbolTable =>
def filterAnnotations(p: AnnotationInfo => Boolean): Self // Retain only annotations meeting the condition.
def withoutAnnotations: Self // Remove all annotations from this type.

def staticAnnotations = annotations filter (_.isStatic)

/** Symbols of any @throws annotations on this symbol.
*/
def throwsAnnotations(): List[Symbol] = annotations collect {
Expand Down
4 changes: 2 additions & 2 deletions src/reflect/scala/reflect/internal/Scopes.scala
Expand Up @@ -221,8 +221,8 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
/** Lookup a module or a class, filtering out matching names in scope
* which do not match that requirement.
*/
def lookupModule(name: Name): Symbol = lookupAll(name.toTermName) find (_.isModule) getOrElse NoSymbol
def lookupClass(name: Name): Symbol = lookupAll(name.toTypeName) find (_.isClass) getOrElse NoSymbol
def lookupModule(name: Name): Symbol = findSymbol(lookupAll(name.toTermName))(_.isModule)
def lookupClass(name: Name): Symbol = findSymbol(lookupAll(name.toTypeName))(_.isClass)

/** True if the name exists in this scope, false otherwise. */
def containsName(name: Name) = lookupEntry(name) != null
Expand Down
5 changes: 5 additions & 0 deletions src/reflect/scala/reflect/internal/SymbolTable.scala
Expand Up @@ -41,6 +41,7 @@ abstract class SymbolTable extends macros.Universe
with StdCreators
with BuildUtils
with PrivateWithin
with pickling.Translations
{

val gen = new TreeGen { val global: SymbolTable.this.type = SymbolTable.this }
Expand Down Expand Up @@ -124,6 +125,10 @@ abstract class SymbolTable extends macros.Universe
result
}

@inline final def findSymbol(xs: TraversableOnce[Symbol])(p: Symbol => Boolean): Symbol = {
xs find p getOrElse NoSymbol
}

// For too long have we suffered in order to sort NAMES.
// I'm pretty sure there's a reasonable default for that.
// Notice challenge created by Ordering's invariance.
Expand Down
2 changes: 2 additions & 0 deletions src/reflect/scala/reflect/internal/Symbols.scala
Expand Up @@ -1859,6 +1859,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
*/
def thisSym: Symbol = this

def hasSelfType = thisSym.tpeHK != this.tpeHK

/** The type of `this` in a class, or else the type of the symbol itself. */
def typeOfThis = thisSym.tpe_*

Expand Down