aboutsummaryrefslogtreecommitdiff
path: root/src/dotty
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-06-30 18:42:29 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-11 13:35:07 +0200
commit34a068b7f6039637d6f1330e3d071f5bf75e9cec (patch)
treeef7b435c50e4110971721836ebdaf9e0d07b4328 /src/dotty
parent32c0135b59fe02a70ed0b1a693251a0028d479c8 (diff)
downloaddotty-34a068b7f6039637d6f1330e3d071f5bf75e9cec.tar.gz
dotty-34a068b7f6039637d6f1330e3d071f5bf75e9cec.tar.bz2
dotty-34a068b7f6039637d6f1330e3d071f5bf75e9cec.zip
Drop Config.checkKinds
Allows us to drop also the involved knownHK method. Lots of other cleanups.
Diffstat (limited to 'src/dotty')
-rw-r--r--src/dotty/tools/dotc/config/Config.scala7
-rw-r--r--src/dotty/tools/dotc/core/TypeApplications.scala75
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala2
-rw-r--r--src/dotty/tools/dotc/core/Types.scala5
-rw-r--r--src/dotty/tools/dotc/core/tasty/TastyFormat.scala1
-rw-r--r--src/dotty/tools/dotc/core/tasty/TreePickler.scala7
-rw-r--r--src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala9
-rw-r--r--src/dotty/tools/dotc/transform/ElimRepeated.scala2
-rw-r--r--src/dotty/tools/dotc/transform/PostTyper.scala3
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala4
-rw-r--r--src/dotty/tools/dotc/typer/Checking.scala8
-rw-r--r--src/dotty/tools/dotc/typer/Implicits.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Inferencing.scala2
13 files changed, 20 insertions, 107 deletions
diff --git a/src/dotty/tools/dotc/config/Config.scala b/src/dotty/tools/dotc/config/Config.scala
index 796a2e693..3cc3091b5 100644
--- a/src/dotty/tools/dotc/config/Config.scala
+++ b/src/dotty/tools/dotc/config/Config.scala
@@ -77,13 +77,6 @@ object Config {
*/
final val checkProjections = false
- /** If this flag is set, it is checked that &/| only apply to types
- * that are either both hk types or both * types. Should be used
- * only for debugging as the assertion may be violated by Implicits.liftToClasses,
- * which can produce an And over a generic class without arguments.
- */
- final val checkKinds = false
-
/** The recursion depth for showing a summarized string */
final val summarizeDepth = 2
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala
index 94ca7a3ac..580cd6569 100644
--- a/src/dotty/tools/dotc/core/TypeApplications.scala
+++ b/src/dotty/tools/dotc/core/TypeApplications.scala
@@ -209,7 +209,7 @@ class TypeApplications(val self: Type) extends AnyVal {
}
}
- /** If `self` is a higher-kinded type, its type parameters $hk_i, otherwise Nil */
+ /** If `self` is a higher-kinded type, its type parameters, otherwise Nil */
final def hkTypeParams(implicit ctx: Context): List[TypeParamInfo] =
if (isHK) typeParams else Nil
@@ -295,57 +295,10 @@ class TypeApplications(val self: Type) extends AnyVal {
case _ => false
}
- /** Computes the kind of `self` without forcing anything.
- * @return 1 if type is known to be higher-kinded
- * -1 if type is known to be a * type
- * 0 if kind of `self` is unknown (because symbols have not yet completed)
- */
- def knownHK(implicit ctx: Context): Int = self match {
- case self: TypeRef =>
- val tsym = self.symbol
- if (tsym.isClass) -1
- else tsym.infoOrCompleter match {
- case completer: TypeParamsCompleter =>
- if (completer.completerTypeParams(tsym).nonEmpty) 1 else -1
- case _ =>
- if (!tsym.isCompleting || tsym.isAliasType) tsym.info.knownHK
- else 0
- }
- case self: RefinedType => -1
- case self: TypeLambda => 1
- case self: HKApply => -1
- case self: SingletonType => -1
- case self: TypeVar => self.origin.knownHK
- case self: WildcardType => self.optBounds.knownHK
- case self: TypeProxy => self.underlying.knownHK
- case NoType | _: LazyType => 0
- case _ => -1
- }
-
- /** True if it can be determined without forcing that the class symbol
- * of this application exists. Equivalent to
- *
- * self.classSymbol.exists
- *
- * but without forcing anything.
- */
- def safeIsClassRef(implicit ctx: Context): Boolean = self.stripTypeVar match {
- case self: RefinedOrRecType =>
- self.parent.safeIsClassRef
- case self: TypeRef =>
- self.denot.exists && {
- val sym = self.symbol
- sym.isClass ||
- sym.isCompleted && self.info.isAlias
- }
- case _ =>
- false
- }
-
/** Dealias type if it can be done without forcing the TypeRef's info */
def safeDealias(implicit ctx: Context): Type = self match {
case self: TypeRef if self.denot.exists && self.symbol.isAliasType =>
- self.info.bounds.hi.stripTypeVar.safeDealias
+ self.superType.stripTypeVar.safeDealias
case _ =>
self
}
@@ -389,14 +342,6 @@ class TypeApplications(val self: Type) extends AnyVal {
//.ensuring(res => res.EtaReduce =:= self, s"res = $res, core = ${res.EtaReduce}, self = $self, hc = ${res.hashCode}")
}
- /** Eta expand the prefix in front of any refinements. */
- def EtaExpandCore(implicit ctx: Context): Type = self.stripTypeVar match {
- case self: RefinedType =>
- self.derivedRefinedType(self.parent.EtaExpandCore, self.refinedName, self.refinedInfo)
- case _ =>
- self.EtaExpand(self.typeParamSymbols)
- }
-
/** If self is not higher-kinded, eta expand it. */
def ensureHK(implicit ctx: Context): Type =
if (isHK) self else EtaExpansion(self)
@@ -566,7 +511,8 @@ class TypeApplications(val self: Type) extends AnyVal {
*/
final def baseArgInfos(base: Symbol)(implicit ctx: Context): List[Type] =
if (self derivesFrom base)
- self match {
+ self.dealias match {
+ case self: TypeRef if !self.symbol.isClass => self.superType.baseArgInfos(base)
case self: HKApply => self.superType.baseArgInfos(base)
case _ => base.typeParams.map(param => self.member(param.name).info.argInfo)
}
@@ -591,17 +537,6 @@ class TypeApplications(val self: Type) extends AnyVal {
final def baseArgTypesHi(base: Symbol)(implicit ctx: Context): List[Type] =
baseArgInfos(base) mapConserve boundsToHi
- /** The first type argument of the base type instance wrt `base` of this type */
- final def firstBaseArgInfo(base: Symbol)(implicit ctx: Context): Type = base.typeParams match {
- case param :: _ if self derivesFrom base =>
- self match {
- case self: HKApply => self.superType.firstBaseArgInfo(base)
- case _ => self.member(param.name).info.argInfo
- }
- case _ =>
- NoType
- }
-
/** The base type including all type arguments and applicable refinements
* of this type. Refinements are applicable if they refine a member of
* the parent type which furthermore is not a name-mangled type parameter.
@@ -711,6 +646,6 @@ class TypeApplications(val self: Type) extends AnyVal {
def elemType(implicit ctx: Context): Type = self match {
case defn.ArrayOf(elemtp) => elemtp
case JavaArrayType(elemtp) => elemtp
- case _ => firstBaseArgInfo(defn.SeqClass)
+ case _ => baseArgInfos(defn.SeqClass).headOption.getOrElse(NoType)
}
}
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index 34fe8629e..d310bd844 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -1353,7 +1353,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
case _ => tp.show
}
if (true) throw new MergeError(s"cannot merge ${showType(tp1)} with ${showType(tp2)}", tp1, tp2)
- else throw new Error(s"cannot merge ${showType(tp1)} with ${showType(tp2)}")
+ else throw new Error(s"cannot merge ${showType(tp1)} with ${showType(tp2)}") // flip condition for debugging
}
/** Merge two lists of names. If names in corresponding positions match, keep them,
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 85c8fd623..786c74069 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -1744,7 +1744,7 @@ object Types {
type ThisType = TypeRef
override def underlying(implicit ctx: Context): Type = info
-
+
override def superType(implicit ctx: Context): Type = info match {
case TypeBounds(_, hi) => hi
case _ => info
@@ -2203,8 +2203,6 @@ object Types {
object AndType {
def apply(tp1: Type, tp2: Type)(implicit ctx: Context) = {
assert(tp1.isInstanceOf[ValueType] && tp2.isInstanceOf[ValueType], i"$tp1 & $tp2 / " + s"$tp1 & $tp2")
- if (Config.checkKinds)
- assert((tp1.knownHK - tp2.knownHK).abs <= 1, i"$tp1 & $tp2 / " + s"$tp1 & $tp2")
unchecked(tp1, tp2)
}
def unchecked(tp1: Type, tp2: Type)(implicit ctx: Context) = {
@@ -2239,7 +2237,6 @@ object Types {
object OrType {
def apply(tp1: Type, tp2: Type)(implicit ctx: Context) = {
assertUnerased()
- if (Config.checkKinds) assert((tp1.knownHK - tp2.knownHK).abs <= 1, i"$tp1 | $tp2")
unique(new CachedOrType(tp1, tp2))
}
def make(tp1: Type, tp2: Type)(implicit ctx: Context): Type =
diff --git a/src/dotty/tools/dotc/core/tasty/TastyFormat.scala b/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
index d9006eda9..394d8f11a 100644
--- a/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
+++ b/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
@@ -499,7 +499,6 @@ object TastyFormat {
SELFDEF | REFINEDtype => 1
case RENAMED | PARAMtype => 2
case POLYtype | METHODtype => -1
- case TYPEBOUNDS => -2
case _ => 0
}
diff --git a/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/src/dotty/tools/dotc/core/tasty/TreePickler.scala
index a4fdb2751..be3999533 100644
--- a/src/dotty/tools/dotc/core/tasty/TreePickler.scala
+++ b/src/dotty/tools/dotc/core/tasty/TreePickler.scala
@@ -158,7 +158,7 @@ class TreePickler(pickler: TastyPickler) {
case ConstantType(value) =>
pickleConstant(value)
case tpe: TypeRef if tpe.info.isAlias && tpe.symbol.is(Flags.AliasPreferred) =>
- pickleType(tpe.info.bounds.hi)
+ pickleType(tpe.superType)
case tpe: WithFixedSym =>
val sym = tpe.symbol
def pickleRef() =
@@ -240,10 +240,7 @@ class TreePickler(pickler: TastyPickler) {
}
case tpe: TypeBounds =>
writeByte(TYPEBOUNDS)
- withLength {
- pickleType(tpe.lo, richTypes)
- pickleType(tpe.hi, richTypes)
- }
+ withLength { pickleType(tpe.lo, richTypes); pickleType(tpe.hi, richTypes) }
case tpe: AnnotatedType =>
writeByte(ANNOTATED)
withLength { pickleType(tpe.tpe, richTypes); pickleTree(tpe.annot.tree) }
diff --git a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala
index 1da92d723..e8f3d63a9 100644
--- a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala
+++ b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala
@@ -135,13 +135,6 @@ object Scala2Unpickler {
denot.info = ClassInfo( // final info, except possibly for typeparams ordering
denot.owner.thisType, denot.classSymbol, parentRefs, decls, ost)
denot.updateTypeParams(tparams)
-
- // Curiously the following line is needed to make pos/i859.scala compile.
- // This test simply accesses scala.tools.nsc.Global. I could not track down why
- // the reference is needed - referencing any field of the type parameter
- // does the trick, no completion is needed (in fact such completion would
- // cause cyclic references elsewhere).
- assert(denot.typeParams.forall(_.exists))
}
}
@@ -593,7 +586,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
val tag = readByte()
val end = readNat() + readIndex
if (tag == POLYtpe) {
- val unusedRestperef = readNat()
+ val unusedRestpeRef = readNat()
until(end, readSymbolRef).asInstanceOf[List[TypeSymbol]]
} else Nil
}
diff --git a/src/dotty/tools/dotc/transform/ElimRepeated.scala b/src/dotty/tools/dotc/transform/ElimRepeated.scala
index 30778267d..258b7f234 100644
--- a/src/dotty/tools/dotc/transform/ElimRepeated.scala
+++ b/src/dotty/tools/dotc/transform/ElimRepeated.scala
@@ -74,7 +74,7 @@ class ElimRepeated extends MiniPhaseTransform with InfoTransformer with Annotati
case SeqLiteral(elems, elemtpt) =>
JavaSeqLiteral(elems, elemtpt)
case _ =>
- val elemType = tree.tpe.firstBaseArgInfo(defn.SeqClass)
+ val elemType = tree.tpe.elemType
var elemClass = elemType.classSymbol
if (defn.PhantomClasses contains elemClass) elemClass = defn.ObjectClass
ref(defn.DottyArraysModule)
diff --git a/src/dotty/tools/dotc/transform/PostTyper.scala b/src/dotty/tools/dotc/transform/PostTyper.scala
index 057026a67..b71284049 100644
--- a/src/dotty/tools/dotc/transform/PostTyper.scala
+++ b/src/dotty/tools/dotc/transform/PostTyper.scala
@@ -13,6 +13,7 @@ import Types._, Contexts._, Constants._, Names._, NameOps._, Flags._, DenotTrans
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Scopes._, Denotations._
import util.Positions._
import Decorators._
+import config.Printers._
import Symbols._, TypeUtils._
/** A macro transform that runs immediately after typer and that performs the following functions:
@@ -121,7 +122,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
*/
private def fixSignature[T <: Tree](tree: T)(implicit ctx: Context): T = tree.tpe match {
case tpe: TermRefWithSignature if tpe.signature.isUnderDefined =>
- println(i"fixing $tree with type ${tree.tpe.widen.toString} with sig ${tpe.signature} to ${tpe.widen.signature}")
+ typr.println(i"fixing $tree with type ${tree.tpe.widen.toString} with sig ${tpe.signature} to ${tpe.widen.signature}")
tree.withType(TermRef.withSig(tpe.prefix, tpe.name, tpe.widen.signature)).asInstanceOf[T]
case _ => tree
}
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index caae422d3..aba073f3d 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -67,7 +67,7 @@ object Applications {
if (extractorMemberType(unapplyResult, nme.isDefined, pos) isRef defn.BooleanClass) {
if (getTp.exists)
if (unapplyFn.symbol.name == nme.unapplySeq) {
- val seqArg = boundsToHi(getTp.firstBaseArgInfo(defn.SeqClass))
+ val seqArg = boundsToHi(getTp.elemType)
if (seqArg.exists) return args map Function.const(seqArg)
}
else return getUnapplySelectors(getTp, args, pos)
@@ -629,7 +629,7 @@ trait Applications extends Compatibility { self: Typer =>
def typedTypeApply(tree: untpd.TypeApply, pt: Type)(implicit ctx: Context): Tree = track("typedTypeApply") {
val isNamed = hasNamedArg(tree.args)
- var typedArgs = if (isNamed) typedNamedArgs(tree.args) else tree.args.mapconserve(typedType(_))
+ val typedArgs = if (isNamed) typedNamedArgs(tree.args) else tree.args.mapconserve(typedType(_))
val typedFn = typedExpr(tree.fun, PolyProto(typedArgs.tpes, pt))
typedFn.tpe.widen match {
case pt: PolyType =>
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala
index e77222beb..3aa63aeeb 100644
--- a/src/dotty/tools/dotc/typer/Checking.scala
+++ b/src/dotty/tools/dotc/typer/Checking.scala
@@ -34,7 +34,8 @@ object Checking {
import tpd._
/** A general checkBounds method that can be used for TypeApply nodes as
- * well as for AppliedTypeTree nodes.
+ * well as for AppliedTypeTree nodes. Also checks that type arguments to
+ * *-type parameters are fully applied.
*/
def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type)(implicit ctx: Context) = {
(args, boundss).zipped.foreach { (arg, bound) =>
@@ -223,9 +224,6 @@ object Checking {
val checker = new CheckNonCyclicMap(sym, reportErrors)(ctx.addMode(Mode.CheckCyclic))
try checker.checkInfo(info)
catch {
- case ex: AssertionError =>
- println(s"assertion error for $info")
- throw ex
case ex: CyclicReference =>
if (reportErrors) {
ctx.error(i"illegal cyclic reference: ${checker.where} ${checker.lastChecked} of $sym refers back to the type itself", sym.pos)
@@ -364,7 +362,7 @@ object Checking {
// try to dealias to avoid a leak error
val savedErrors = errors
errors = prevErrors
- val tp2 = apply(tp.info.bounds.hi)
+ val tp2 = apply(tp.superType)
if (errors eq prevErrors) tp1 = tp2
else errors = savedErrors
}
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala
index 91a67de9a..feed398aa 100644
--- a/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/src/dotty/tools/dotc/typer/Implicits.scala
@@ -772,7 +772,7 @@ class SearchHistory(val searchDepth: Int, val seen: Map[ClassSymbol, Int]) {
case tp: RefinedType =>
foldOver(n + 1, tp)
case tp: TypeRef if tp.info.isAlias =>
- apply(n, tp.info.bounds.hi)
+ apply(n, tp.superType)
case _ =>
foldOver(n, tp)
}
diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala
index e024192c3..c60f4c1f2 100644
--- a/src/dotty/tools/dotc/typer/Inferencing.scala
+++ b/src/dotty/tools/dotc/typer/Inferencing.scala
@@ -176,7 +176,7 @@ object Inferencing {
/** Recursively widen and also follow type declarations and type aliases. */
def widenForMatchSelector(tp: Type)(implicit ctx: Context): Type = tp.widen match {
case tp: TypeRef if !tp.symbol.isClass =>
- widenForMatchSelector(tp.info.bounds.hi)
+ widenForMatchSelector(tp.superType)
case tp: HKApply =>
widenForMatchSelector(tp.superType)
case tp: AnnotatedType =>