aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-11-15 19:33:18 +0100
committerMartin Odersky <odersky@gmail.com>2013-11-15 19:33:18 +0100
commit3d01335c750de022e87914f44e017051abac290f (patch)
treeee97f48087be9fcf4298139a05ca0093a39ccc06
parent6ca5d414e729a509a00ddc508f2abf3d24da56ca (diff)
downloaddotty-3d01335c750de022e87914f44e017051abac290f.tar.gz
dotty-3d01335c750de022e87914f44e017051abac290f.tar.bz2
dotty-3d01335c750de022e87914f44e017051abac290f.zip
Converting most uses of NamedType to select.
Select reduces refinetype/typeref pairs and is therefore preferable over raw NamedType. Still need to do the same for TypeRefs.
-rw-r--r--src/dotty/tools/dotc/ast/TypedTrees.scala28
-rw-r--r--src/dotty/tools/dotc/core/Annotations.scala2
-rw-r--r--src/dotty/tools/dotc/core/Substituters.scala2
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala2
-rw-r--r--src/dotty/tools/dotc/core/Types.scala31
-rw-r--r--src/dotty/tools/dotc/core/pickling/UnPickler.scala12
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala8
8 files changed, 48 insertions, 39 deletions
diff --git a/src/dotty/tools/dotc/ast/TypedTrees.scala b/src/dotty/tools/dotc/ast/TypedTrees.scala
index 58c650f41..8a966696f 100644
--- a/src/dotty/tools/dotc/ast/TypedTrees.scala
+++ b/src/dotty/tools/dotc/ast/TypedTrees.scala
@@ -18,10 +18,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
underlyingIfRepeated(untpd.Ident(tp.name) withType tp).checked
def Select(qualifier: Tree, name: Name)(implicit ctx: Context): Select =
- Select(qualifier, NamedType(qualifier.tpe, name))
+ untpd.Select(qualifier, name).withType(qualifier.tpe select name)
- def Select(pre: Tree, tp: NamedType)(implicit ctx: Context): Select =
- untpd.Select(pre, tp.name).withType(tp).checked
+ def Select(qualifier: Tree, tp: NamedType)(implicit ctx: Context): Select =
+ untpd.Select(qualifier, tp.name).withType(tp).checked
def SelectWithSig(qualifier: Tree, name: Name, sig: Signature)(implicit ctx: Context) =
untpd.SelectWithSig(qualifier, name, sig)
@@ -173,7 +173,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
untpd.SingletonTypeTree(ref).withType(ref.tpe).checked
def SelectFromTypeTree(qualifier: Tree, name: Name)(implicit ctx: Context): SelectFromTypeTree =
- SelectFromTypeTree(qualifier, NamedType(qualifier.tpe, name))
+ untpd.SelectFromTypeTree(qualifier, name).withType(qualifier.tpe select name).checked
def SelectFromTypeTree(qualifier: Tree, tp: NamedType)(implicit ctx: Context): SelectFromTypeTree =
untpd.SelectFromTypeTree(qualifier, tp.name).withType(tp).checked
@@ -201,7 +201,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
untpd.TypeBoundsTree(lo, hi).withType(TypeBounds(lo.tpe, hi.tpe)).checked
def Bind(sym: TermSymbol, body: Tree)(implicit ctx: Context): Bind =
- untpd.Bind(sym.name, body).withType(refType(sym)).checked
+ untpd.Bind(sym.name, body).withType(sym.symRef).checked
def Alternative(trees: List[Tree])(implicit ctx: Context): Alternative =
untpd.Alternative(trees).withType(ctx.typeComparer.lub(trees map (_.tpe))).checked
@@ -215,7 +215,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
}
def ValDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): ValDef =
- untpd.ValDef(Modifiers(sym), sym.name, TypeTree(sym.info), rhs).withType(refType(sym)).checked
+ untpd.ValDef(Modifiers(sym), sym.name, TypeTree(sym.info), rhs).withType(sym.symRef).checked
def DefDef(sym: TermSymbol, rhs: Tree = EmptyTree)(implicit ctx: Context): DefDef =
DefDef(sym, Function.const(rhs) _)
@@ -243,12 +243,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
untpd.DefDef(
Modifiers(sym), sym.name, tparams map TypeDef,
vparamss map (_ map (ValDef(_))), TypeTree(rtp), rhsFn(argss))
- .withType(refType(sym)).checked
+ .withType(sym.symRef).checked
}
def TypeDef(sym: TypeSymbol)(implicit ctx: Context): TypeDef =
untpd.TypeDef(Modifiers(sym), sym.name, TypeTree(sym.info))
- .withType(refType(sym)).checked
+ .withType(sym.symRef).checked
def ClassDef(cls: ClassSymbol, constr: DefDef, body: List[Tree])(implicit ctx: Context): TypeDef = {
val parents = cls.info.parents map (TypeTree(_))
@@ -265,16 +265,16 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
val localDummy = ((NoSymbol: Symbol) /: body)(findLocalDummy)
.orElse(ctx.newLocalDummy(cls))
val impl = untpd.Template(constr, parents, selfType, newTypeParams ++ body)
- .withType(refType(localDummy)).checked
+ .withType(localDummy.symRef).checked
untpd.TypeDef(Modifiers(cls), cls.name, impl)
- .withType(refType(cls)).checked
+ .withType(cls.symRef).checked
}
def Import(expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import =
- untpd.Import(expr, selectors).withType(refType(ctx.newImportSymbol(SharedTree(expr)))).checked
+ untpd.Import(expr, selectors).withType(ctx.newImportSymbol(SharedTree(expr)).symRef).checked
def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef =
- untpd.PackageDef(pid, stats).withType(refType(pid.symbol)).checked
+ untpd.PackageDef(pid, stats).withType(pid.symbol.symRef).checked
def Annotated(annot: Tree, arg: Tree)(implicit ctx: Context): Annotated =
untpd.Annotated(annot, arg).withType(AnnotatedType(Annotation(annot), arg.tpe)).checked
@@ -284,8 +284,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
// ------ Making references ------------------------------------------------------
- def refType(sym: Symbol)(implicit ctx: Context): NamedType = NamedType.withSym(sym.owner.thisType, sym)
-
/** A tree representing the same reference as the given type */
def ref(tp: NamedType)(implicit ctx: Context): NameTree =
if (tp.symbol.isStatic) Ident(tp)
@@ -419,7 +417,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
val newOwner = ownerMap(sym.owner)
val newInfo = typeMap(sym.info)
if ((newOwner ne sym.owner) || (newInfo ne sym.info))
- bind.withType(tpd.refType(sym.copy(owner = newOwner, info = newInfo)))
+ bind.withType(sym.copy(owner = newOwner, info = newInfo).symRef)
else
bind
case tree1 =>
diff --git a/src/dotty/tools/dotc/core/Annotations.scala b/src/dotty/tools/dotc/core/Annotations.scala
index 8b7cb7bd7..90b916971 100644
--- a/src/dotty/tools/dotc/core/Annotations.scala
+++ b/src/dotty/tools/dotc/core/Annotations.scala
@@ -58,7 +58,7 @@ object Annotations {
apply(defn.AliasAnnot, List(Ident(TermRef.withSig(sym.owner.thisType, sym.name, sym.signature).withDenot(sym))))
def makeChild(sym: Symbol)(implicit ctx: Context) =
- apply(defn.ChildAnnot.typeConstructor.appliedTo(NamedType(sym.owner.thisType, sym.name).withDenot(sym)), Nil)
+ apply(defn.ChildAnnot.typeConstructor.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil)
}
def ThrowsAnnotation(cls: ClassSymbol)(implicit ctx: Context) = {
diff --git a/src/dotty/tools/dotc/core/Substituters.scala b/src/dotty/tools/dotc/core/Substituters.scala
index 27a2722f2..763c3eea7 100644
--- a/src/dotty/tools/dotc/core/Substituters.scala
+++ b/src/dotty/tools/dotc/core/Substituters.scala
@@ -88,7 +88,7 @@ trait Substituters { this: Context =>
var fs = from
var ts = to
while (fs.nonEmpty) {
- if (fs.head eq sym) return NamedType.withSym(tp.prefix, ts.head)
+ if (fs.head eq sym) return tp.prefix select ts.head
fs = fs.tail
ts = ts.tail
}
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index af2e6a8ca..de4a1d8e3 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -651,7 +651,7 @@ object SymDenotations {
TermRef.withSym(owner.thisType, symbol.asTerm)
def symRef(implicit ctx: Context): NamedType =
- NamedType.withSym(owner.thisType, symbol)
+ if (isType) symTypeRef else symTermRef
/** The variance of this type parameter or type member as an Int, with
* +1 = Covariant, -1 = Contravariant, 0 = Nonvariant, or not a type parameter
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 2cb14bf8f..d6dc81d4e 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -679,17 +679,31 @@ object Types {
}
/** The type <this . name> , reduced if possible */
- def select(name: Name)(implicit ctx: Context): Type = {
- val res = lookupRefined(this, name)
- if (res.exists) res else NamedType(this, name)
+ def select(name: Name)(implicit ctx: Context): Type = name match {
+ case name: TermName =>
+ TermRef(this, name)
+ case name: TypeName =>
+ val res = lookupRefined(this, name)
+ if (res.exists) res else TypeRef(this, name)
}
- /** The type <this . name> with given symbol, reduced if possible */
- def select(sym: Symbol)(implicit ctx: Context): Type = {
- val res = lookupRefined(this, sym.name)
- if (res.exists) res else NamedType.withSym(this, sym)
+ /** The type <this . name> , reduced if possible, with given denotation if undreduced */
+ def select(name: Name, denot: Denotation)(implicit ctx: Context): Type = name match {
+ case name: TermName =>
+ TermRef(this, name).withDenot(denot)
+ case name: TypeName =>
+ val res = lookupRefined(this, name)
+ if (res.exists) res else TypeRef(this, name).withDenot(denot)
}
+ /** The type <this . name> with given symbol, reduced if possible */
+ def select(sym: Symbol)(implicit ctx: Context): Type =
+ if (sym.isTerm) TermRef.withSym(this, sym.asTerm)
+ else {
+ val res = lookupRefined(this, sym.name)
+ if (res.exists) res else TypeRef.withSym(this, sym.asType)
+ }
+
protected def lookupRefined(pre: Type, name: Name)(implicit ctx: Context): Type = pre.stripTypeVar match {
case pre: RefinedType =>
if (pre.refinedName ne name) lookupRefined(pre.parent, name)
@@ -1551,9 +1565,6 @@ object Types {
def apply(prefix: Type, name: Name)(implicit ctx: Context) =
if (name.isTermName) TermRef(prefix, name.asTermName)
else TypeRef(prefix, name.asTypeName)
- def withSym(prefix: Type, sym: Symbol)(implicit ctx: Context) =
- if (sym.isTerm) TermRef.withSym(prefix, sym.asTerm)
- else TypeRef.withSym(prefix, sym.asType)
}
object TermRef {
diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
index 465e4a060..400fcba86 100644
--- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala
+++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
@@ -934,7 +934,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
val ldef = DefDef(symbol.asTerm, rhs)
def isCaseLabel(sym: Symbol) = sym.name.startsWith(nme.CASEkw)
if (isCaseLabel(symbol)) ldef
- else Block(ldef :: Nil, Apply(Ident(refType(symbol)), Nil))
+ else Block(ldef :: Nil, Apply(Ident(symbol.symRef), Nil))
case IMPORTtree =>
setSym()
@@ -955,7 +955,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
val self = readValDefRef()
val body = until(end, readTreeRef)
untpd.Template(???, parents, self, body) // !!! TODO: pull out primary constructor
- .withType(refType(symbol))
+ .withType(symbol.symRef)
case BLOCKtree =>
val expr = readTreeRef()
@@ -1016,7 +1016,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
case RETURNtree =>
setSym()
- Return(readTreeRef(), Ident(refType(symbol)))
+ Return(readTreeRef(), Ident(symbol.symRef))
case TREtree =>
val block = readTreeRef()
@@ -1072,11 +1072,11 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
setSym()
val qualifier = readTreeRef()
val selector = readNameRef()
- Select(qualifier, refType(symbol))
+ Select(qualifier, symbol.symRef)
case IDENTtree =>
setSymName()
- Ident(refType(symbol))
+ Ident(symbol.symRef)
case LITERALtree =>
Literal(readConstantRef())
@@ -1095,7 +1095,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
case SELECTFROMTYPEtree =>
val qualifier = readTreeRef()
val selector = readTypeNameRef()
- SelectFromTypeTree(qualifier, refType(symbol))
+ SelectFromTypeTree(qualifier, symbol.symRef)
case COMPOUNDTYPEtree =>
readTemplateRef()
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index ba67d2b1e..9d6df553c 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -206,7 +206,7 @@ trait Applications extends Compatibility { self: Typer =>
cx.denotNamed(methRef.name).hasAltWith(_.symbol == meth)) {
val denot = cx.denotNamed(getterName)
assert(denot.exists)
- NamedType(cx.owner.thisType, getterName).withDenot(denot)
+ cx.owner.thisType.select(getterName, denot)
} else findDefault(cx.outer)
}
findDefault(ctx)
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index bf9572a46..9780e8d2e 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -68,10 +68,10 @@ class Typer extends Namer with Applications with Implicits {
private var importedFromRoot: Set[Symbol] = Set()
def selectionType(site: Type, name: Name, pos: Position)(implicit ctx: Context): Type = {
- val ref =
+ val refDenot =
if (name == nme.CONSTRUCTOR) site.decl(name)
else site.member(name)
- if (ref.exists) NamedType(site, name).withDenot(ref)
+ if (refDenot.exists) site.select(name, refDenot)
else {
if (!site.isErroneous)
ctx.error(
@@ -253,7 +253,7 @@ class Typer extends Namer with Applications with Implicits {
val pre = imp.site
if (!isDisabled(imp, pre)) {
val denot = pre.member(name)
- if (denot.exists) return NamedType(pre, name).withDenot(denot)
+ if (denot.exists) return pre.select(name, denot)
}
}
NoType
@@ -275,7 +275,7 @@ class Typer extends Namer with Applications with Implicits {
val defDenot = ctx.denotNamed(name)
if (defDenot.exists) {
val curOwner = ctx.owner
- val found = NamedType(curOwner.thisType, name) withDenot defDenot
+ val found = curOwner.thisType.select(name, defDenot)
if (!(curOwner is Package) || (defDenot.symbol is Package) || isDefinedInCurrentUnit(defDenot))
return checkNewOrShadowed(found, definition) // no need to go further out, we found highest prec entry
else if (prevPrec < packageClause)