diff options
author | Martin Odersky <odersky@gmail.com> | 2013-04-22 17:17:52 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-04-22 17:22:20 +0200 |
commit | 7bca39c57e31da15478033ac4d581705cbeb4bc9 (patch) | |
tree | 42940077a21d5d067583449ff8a2dffa7491c32a | |
parent | 4a93c8c132941ff3dae9ebf2dc27b37cd4f7cdec (diff) | |
download | dotty-7bca39c57e31da15478033ac4d581705cbeb4bc9.tar.gz dotty-7bca39c57e31da15478033ac4d581705cbeb4bc9.tar.bz2 dotty-7bca39c57e31da15478033ac4d581705cbeb4bc9.zip |
Some annotations and changes prompted by the code walkthrough.
-rw-r--r-- | src/dotty/tools/dotc/core/Denotations.scala | 7 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeOps.scala | 11 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 18 |
3 files changed, 22 insertions, 14 deletions
diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index 74140f028..66baeef55 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -74,6 +74,8 @@ object Denotations { * would have signature * * List("scala.Int".toTypeName, "scala.collection.immutable.List".toTypeName) + * + * TODO: discriminate on result type as well !!! */ type Signature = List[TypeName] @@ -85,11 +87,6 @@ object Denotations { /** A denotation is the result of resolving * a name (either simple identifier or select) during a given period. * - * Denotation has two subclasses: MultiDenotation and SingleDenotation. - * - * A SingleDenotation refers to a `symbol` and a type (`info`) that the symbol has - * when seen from the reference. - * * Denotations can be combined with `&` and `|`. * & is conjunction, | is disjunction. * diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index d3cfaba69..164335554 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -27,7 +27,16 @@ trait TypeOps { this: Context => if (sym.isStatic) tp else { val tp1 = tp.derivedNamedType(asSeenFrom(tp.prefix, pre, cls, theMap)) - // short-circuit instantiated type parameters + // Here's an explanation why we short-circuit instantiated type parameters. + // Say you have This is translated to: + // + // class List[type T] ==> class List { type T; val hd: T } + // xs: List[Int] ==> List { type T = Int } + // + // Then with the line above, xs.hd would have type xs.T + // + // But in Scala 2.x, its type is Int, which is the dealiased version + // of xs.T. With the logic below, we get the same outcome as for 2.x. if ((tp1 ne tp) && (sym is (TypeParam, butNot = Deferred))) tp1.dealias else tp1 } diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index dc61195b5..a2d8d596b 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -178,7 +178,8 @@ object Types { case _ => NoSymbol } - /** The least non-trait class of which this type is a subtype. NoSymbol is none exists. */ + /** The least non-trait class of which this type is a subtype. NoSymbol is none exists. + * Note: can't do the same for traits as that would be ambiguous. */ final def classSymbol(implicit ctx: Context): Symbol = this match { case tp: ClassInfo => if (tp.cls is Trait) @@ -188,7 +189,7 @@ object Types { } else tp.cls case tp: TypeProxy => - tp.underlying.typeSymbol + tp.underlying.classSymbol case AndType(l, r) => val lsym = l.classSymbol val rsym = r.classSymbol @@ -400,7 +401,7 @@ object Types { * - Either both types are polytypes with the same number of * type parameters and their result types match after renaming * corresponding type parameters - * - Or both types are (possibly nullary) method types with equivalent type parameter types + * - Or both types are (possibly nullary) method types with equivalent parameter types * and matching result types * - Or both types are equivalent * - Or phase.erasedTypes is false and both types are neither method nor @@ -512,7 +513,7 @@ object Types { } /** The type parameter with given `name`. This tries first `decls` - * in order not to provoke a cylce by forcing the info. If that yields + * in order not to provoke a cycle by forcing the info. If that yields * no symbol it tries `member` as an alternative. */ def typeParamNamed(name: TypeName)(implicit ctx: Context): Symbol = @@ -591,7 +592,7 @@ object Types { println(s"precomplete decls = ${typeSymbol.decls.toList.map(_.denot).mkString("\n ")}") } val tparam = tparams.head - val tp1 = RefinedType(tp, tparam.name, arg.toRHS(tparam)) + val tp1 = RefinedType(tp, tparam.name, arg.toBounds(tparam)) recur(tp1, tparams.tail, args1) case nil => tp } @@ -662,7 +663,7 @@ object Types { /** Turn this type, which is used as an argument for * type parameter `tparam`, into a TypeBounds RHS */ - final def toRHS(tparam: Symbol)(implicit ctx: Context): TypeBounds = { + final def toBounds(tparam: Symbol)(implicit ctx: Context): TypeBounds = { val v = tparam.variance if (v > 0) TypeBounds.upper(this) else if (v < 0) TypeBounds.lower(this) @@ -1086,6 +1087,7 @@ object Types { final class CachedThisType(cls: ClassSymbol) extends ThisType(cls) + // TODO: consider hash before constructing types? object ThisType { def apply(cls: ClassSymbol)(implicit ctx: Context) = unique(new CachedThisType(cls)) @@ -1340,7 +1342,7 @@ object Types { case class PolyType(paramNames: List[TypeName])(paramBoundsExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type) extends UncachedGroundType with BindingType with TermType { - lazy val paramBounds = paramBoundsExp(this) + lazy val paramBounds = paramBoundsExp(this) // TODO !!! this captures context, consider forcing the vals! override lazy val resultType = resultTypeExp(this) override def signature(implicit ctx: Context) = resultType.signature @@ -1425,7 +1427,7 @@ object Types { // ------ ClassInfo, Type Bounds ------------------------------------------------------------ /** The info of a class during a period, roughly - * @param pre The prefix on which parents, decls, and selfType need to be rebased. + * @param prefix The prefix on which parents, decls, and selfType need to be rebased. * @param cls The class symbol. * @param classParents The parent types of this class. * These are all normalized to be TypeRefs by moving any refinements |