Skip to content

Commit 5bf0df0

Browse files
committed
Drop Config.checkKinds
Allows us to drop also the involved knownHK method. Lots of other cleanups.
1 parent 41abffe commit 5bf0df0

File tree

13 files changed

+20
-107
lines changed

13 files changed

+20
-107
lines changed

src/dotty/tools/dotc/config/Config.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ object Config {
7777
*/
7878
final val checkProjections = false
7979

80-
/** If this flag is set, it is checked that &/| only apply to types
81-
* that are either both hk types or both * types. Should be used
82-
* only for debugging as the assertion may be violated by Implicits.liftToClasses,
83-
* which can produce an And over a generic class without arguments.
84-
*/
85-
final val checkKinds = false
86-
8780
/** The recursion depth for showing a summarized string */
8881
final val summarizeDepth = 2
8982

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class TypeApplications(val self: Type) extends AnyVal {
209209
}
210210
}
211211

212-
/** If `self` is a higher-kinded type, its type parameters $hk_i, otherwise Nil */
212+
/** If `self` is a higher-kinded type, its type parameters, otherwise Nil */
213213
final def hkTypeParams(implicit ctx: Context): List[TypeParamInfo] =
214214
if (isHK) typeParams else Nil
215215

@@ -295,57 +295,10 @@ class TypeApplications(val self: Type) extends AnyVal {
295295
case _ => false
296296
}
297297

298-
/** Computes the kind of `self` without forcing anything.
299-
* @return 1 if type is known to be higher-kinded
300-
* -1 if type is known to be a * type
301-
* 0 if kind of `self` is unknown (because symbols have not yet completed)
302-
*/
303-
def knownHK(implicit ctx: Context): Int = self match {
304-
case self: TypeRef =>
305-
val tsym = self.symbol
306-
if (tsym.isClass) -1
307-
else tsym.infoOrCompleter match {
308-
case completer: TypeParamsCompleter =>
309-
if (completer.completerTypeParams(tsym).nonEmpty) 1 else -1
310-
case _ =>
311-
if (!tsym.isCompleting || tsym.isAliasType) tsym.info.knownHK
312-
else 0
313-
}
314-
case self: RefinedType => -1
315-
case self: TypeLambda => 1
316-
case self: HKApply => -1
317-
case self: SingletonType => -1
318-
case self: TypeVar => self.origin.knownHK
319-
case self: WildcardType => self.optBounds.knownHK
320-
case self: TypeProxy => self.underlying.knownHK
321-
case NoType | _: LazyType => 0
322-
case _ => -1
323-
}
324-
325-
/** True if it can be determined without forcing that the class symbol
326-
* of this application exists. Equivalent to
327-
*
328-
* self.classSymbol.exists
329-
*
330-
* but without forcing anything.
331-
*/
332-
def safeIsClassRef(implicit ctx: Context): Boolean = self.stripTypeVar match {
333-
case self: RefinedOrRecType =>
334-
self.parent.safeIsClassRef
335-
case self: TypeRef =>
336-
self.denot.exists && {
337-
val sym = self.symbol
338-
sym.isClass ||
339-
sym.isCompleted && self.info.isAlias
340-
}
341-
case _ =>
342-
false
343-
}
344-
345298
/** Dealias type if it can be done without forcing the TypeRef's info */
346299
def safeDealias(implicit ctx: Context): Type = self match {
347300
case self: TypeRef if self.denot.exists && self.symbol.isAliasType =>
348-
self.info.bounds.hi.stripTypeVar.safeDealias
301+
self.superType.stripTypeVar.safeDealias
349302
case _ =>
350303
self
351304
}
@@ -389,14 +342,6 @@ class TypeApplications(val self: Type) extends AnyVal {
389342
//.ensuring(res => res.EtaReduce =:= self, s"res = $res, core = ${res.EtaReduce}, self = $self, hc = ${res.hashCode}")
390343
}
391344

392-
/** Eta expand the prefix in front of any refinements. */
393-
def EtaExpandCore(implicit ctx: Context): Type = self.stripTypeVar match {
394-
case self: RefinedType =>
395-
self.derivedRefinedType(self.parent.EtaExpandCore, self.refinedName, self.refinedInfo)
396-
case _ =>
397-
self.EtaExpand(self.typeParamSymbols)
398-
}
399-
400345
/** If self is not higher-kinded, eta expand it. */
401346
def ensureHK(implicit ctx: Context): Type =
402347
if (isHK) self else EtaExpansion(self)
@@ -566,7 +511,8 @@ class TypeApplications(val self: Type) extends AnyVal {
566511
*/
567512
final def baseArgInfos(base: Symbol)(implicit ctx: Context): List[Type] =
568513
if (self derivesFrom base)
569-
self match {
514+
self.dealias match {
515+
case self: TypeRef if !self.symbol.isClass => self.superType.baseArgInfos(base)
570516
case self: HKApply => self.superType.baseArgInfos(base)
571517
case _ => base.typeParams.map(param => self.member(param.name).info.argInfo)
572518
}
@@ -591,17 +537,6 @@ class TypeApplications(val self: Type) extends AnyVal {
591537
final def baseArgTypesHi(base: Symbol)(implicit ctx: Context): List[Type] =
592538
baseArgInfos(base) mapConserve boundsToHi
593539

594-
/** The first type argument of the base type instance wrt `base` of this type */
595-
final def firstBaseArgInfo(base: Symbol)(implicit ctx: Context): Type = base.typeParams match {
596-
case param :: _ if self derivesFrom base =>
597-
self match {
598-
case self: HKApply => self.superType.firstBaseArgInfo(base)
599-
case _ => self.member(param.name).info.argInfo
600-
}
601-
case _ =>
602-
NoType
603-
}
604-
605540
/** The base type including all type arguments and applicable refinements
606541
* of this type. Refinements are applicable if they refine a member of
607542
* the parent type which furthermore is not a name-mangled type parameter.
@@ -711,6 +646,6 @@ class TypeApplications(val self: Type) extends AnyVal {
711646
def elemType(implicit ctx: Context): Type = self match {
712647
case defn.ArrayOf(elemtp) => elemtp
713648
case JavaArrayType(elemtp) => elemtp
714-
case _ => firstBaseArgInfo(defn.SeqClass)
649+
case _ => baseArgInfos(defn.SeqClass).headOption.getOrElse(NoType)
715650
}
716651
}

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
13531353
case _ => tp.show
13541354
}
13551355
if (true) throw new MergeError(s"cannot merge ${showType(tp1)} with ${showType(tp2)}", tp1, tp2)
1356-
else throw new Error(s"cannot merge ${showType(tp1)} with ${showType(tp2)}")
1356+
else throw new Error(s"cannot merge ${showType(tp1)} with ${showType(tp2)}") // flip condition for debugging
13571357
}
13581358

13591359
/** Merge two lists of names. If names in corresponding positions match, keep them,

src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ object Types {
17441744
type ThisType = TypeRef
17451745

17461746
override def underlying(implicit ctx: Context): Type = info
1747-
1747+
17481748
override def superType(implicit ctx: Context): Type = info match {
17491749
case TypeBounds(_, hi) => hi
17501750
case _ => info
@@ -2203,8 +2203,6 @@ object Types {
22032203
object AndType {
22042204
def apply(tp1: Type, tp2: Type)(implicit ctx: Context) = {
22052205
assert(tp1.isInstanceOf[ValueType] && tp2.isInstanceOf[ValueType], i"$tp1 & $tp2 / " + s"$tp1 & $tp2")
2206-
if (Config.checkKinds)
2207-
assert((tp1.knownHK - tp2.knownHK).abs <= 1, i"$tp1 & $tp2 / " + s"$tp1 & $tp2")
22082206
unchecked(tp1, tp2)
22092207
}
22102208
def unchecked(tp1: Type, tp2: Type)(implicit ctx: Context) = {
@@ -2239,7 +2237,6 @@ object Types {
22392237
object OrType {
22402238
def apply(tp1: Type, tp2: Type)(implicit ctx: Context) = {
22412239
assertUnerased()
2242-
if (Config.checkKinds) assert((tp1.knownHK - tp2.knownHK).abs <= 1, i"$tp1 | $tp2")
22432240
unique(new CachedOrType(tp1, tp2))
22442241
}
22452242
def make(tp1: Type, tp2: Type)(implicit ctx: Context): Type =

src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@ object TastyFormat {
499499
SELFDEF | REFINEDtype => 1
500500
case RENAMED | PARAMtype => 2
501501
case POLYtype | METHODtype => -1
502-
case TYPEBOUNDS => -2
503502
case _ => 0
504503
}
505504

src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class TreePickler(pickler: TastyPickler) {
158158
case ConstantType(value) =>
159159
pickleConstant(value)
160160
case tpe: TypeRef if tpe.info.isAlias && tpe.symbol.is(Flags.AliasPreferred) =>
161-
pickleType(tpe.info.bounds.hi)
161+
pickleType(tpe.superType)
162162
case tpe: WithFixedSym =>
163163
val sym = tpe.symbol
164164
def pickleRef() =
@@ -240,10 +240,7 @@ class TreePickler(pickler: TastyPickler) {
240240
}
241241
case tpe: TypeBounds =>
242242
writeByte(TYPEBOUNDS)
243-
withLength {
244-
pickleType(tpe.lo, richTypes)
245-
pickleType(tpe.hi, richTypes)
246-
}
243+
withLength { pickleType(tpe.lo, richTypes); pickleType(tpe.hi, richTypes) }
247244
case tpe: AnnotatedType =>
248245
writeByte(ANNOTATED)
249246
withLength { pickleType(tpe.tpe, richTypes); pickleTree(tpe.annot.tree) }

src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,6 @@ object Scala2Unpickler {
135135
denot.info = ClassInfo( // final info, except possibly for typeparams ordering
136136
denot.owner.thisType, denot.classSymbol, parentRefs, decls, ost)
137137
denot.updateTypeParams(tparams)
138-
139-
// Curiously the following line is needed to make pos/i859.scala compile.
140-
// This test simply accesses scala.tools.nsc.Global. I could not track down why
141-
// the reference is needed - referencing any field of the type parameter
142-
// does the trick, no completion is needed (in fact such completion would
143-
// cause cyclic references elsewhere).
144-
assert(denot.typeParams.forall(_.exists))
145138
}
146139
}
147140

@@ -593,7 +586,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
593586
val tag = readByte()
594587
val end = readNat() + readIndex
595588
if (tag == POLYtpe) {
596-
val unusedRestperef = readNat()
589+
val unusedRestpeRef = readNat()
597590
until(end, readSymbolRef).asInstanceOf[List[TypeSymbol]]
598591
} else Nil
599592
}

src/dotty/tools/dotc/transform/ElimRepeated.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ElimRepeated extends MiniPhaseTransform with InfoTransformer with Annotati
7474
case SeqLiteral(elems, elemtpt) =>
7575
JavaSeqLiteral(elems, elemtpt)
7676
case _ =>
77-
val elemType = tree.tpe.firstBaseArgInfo(defn.SeqClass)
77+
val elemType = tree.tpe.elemType
7878
var elemClass = elemType.classSymbol
7979
if (defn.PhantomClasses contains elemClass) elemClass = defn.ObjectClass
8080
ref(defn.DottyArraysModule)

src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Types._, Contexts._, Constants._, Names._, NameOps._, Flags._, DenotTrans
1313
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Scopes._, Denotations._
1414
import util.Positions._
1515
import Decorators._
16+
import config.Printers._
1617
import Symbols._, TypeUtils._
1718

1819
/** 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
121122
*/
122123
private def fixSignature[T <: Tree](tree: T)(implicit ctx: Context): T = tree.tpe match {
123124
case tpe: TermRefWithSignature if tpe.signature.isUnderDefined =>
124-
println(i"fixing $tree with type ${tree.tpe.widen.toString} with sig ${tpe.signature} to ${tpe.widen.signature}")
125+
typr.println(i"fixing $tree with type ${tree.tpe.widen.toString} with sig ${tpe.signature} to ${tpe.widen.signature}")
125126
tree.withType(TermRef.withSig(tpe.prefix, tpe.name, tpe.widen.signature)).asInstanceOf[T]
126127
case _ => tree
127128
}

src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object Applications {
6767
if (extractorMemberType(unapplyResult, nme.isDefined, pos) isRef defn.BooleanClass) {
6868
if (getTp.exists)
6969
if (unapplyFn.symbol.name == nme.unapplySeq) {
70-
val seqArg = boundsToHi(getTp.firstBaseArgInfo(defn.SeqClass))
70+
val seqArg = boundsToHi(getTp.elemType)
7171
if (seqArg.exists) return args map Function.const(seqArg)
7272
}
7373
else return getUnapplySelectors(getTp, args, pos)
@@ -629,7 +629,7 @@ trait Applications extends Compatibility { self: Typer =>
629629

630630
def typedTypeApply(tree: untpd.TypeApply, pt: Type)(implicit ctx: Context): Tree = track("typedTypeApply") {
631631
val isNamed = hasNamedArg(tree.args)
632-
var typedArgs = if (isNamed) typedNamedArgs(tree.args) else tree.args.mapconserve(typedType(_))
632+
val typedArgs = if (isNamed) typedNamedArgs(tree.args) else tree.args.mapconserve(typedType(_))
633633
val typedFn = typedExpr(tree.fun, PolyProto(typedArgs.tpes, pt))
634634
typedFn.tpe.widen match {
635635
case pt: PolyType =>

src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ object Checking {
3434
import tpd._
3535

3636
/** A general checkBounds method that can be used for TypeApply nodes as
37-
* well as for AppliedTypeTree nodes.
37+
* well as for AppliedTypeTree nodes. Also checks that type arguments to
38+
* *-type parameters are fully applied.
3839
*/
3940
def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type)(implicit ctx: Context) = {
4041
(args, boundss).zipped.foreach { (arg, bound) =>
@@ -223,9 +224,6 @@ object Checking {
223224
val checker = new CheckNonCyclicMap(sym, reportErrors)(ctx.addMode(Mode.CheckCyclic))
224225
try checker.checkInfo(info)
225226
catch {
226-
case ex: AssertionError =>
227-
println(s"assertion error for $info")
228-
throw ex
229227
case ex: CyclicReference =>
230228
if (reportErrors) {
231229
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 {
364362
// try to dealias to avoid a leak error
365363
val savedErrors = errors
366364
errors = prevErrors
367-
val tp2 = apply(tp.info.bounds.hi)
365+
val tp2 = apply(tp.superType)
368366
if (errors eq prevErrors) tp1 = tp2
369367
else errors = savedErrors
370368
}

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ class SearchHistory(val searchDepth: Int, val seen: Map[ClassSymbol, Int]) {
772772
case tp: RefinedType =>
773773
foldOver(n + 1, tp)
774774
case tp: TypeRef if tp.info.isAlias =>
775-
apply(n, tp.info.bounds.hi)
775+
apply(n, tp.superType)
776776
case _ =>
777777
foldOver(n, tp)
778778
}

src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ object Inferencing {
176176
/** Recursively widen and also follow type declarations and type aliases. */
177177
def widenForMatchSelector(tp: Type)(implicit ctx: Context): Type = tp.widen match {
178178
case tp: TypeRef if !tp.symbol.isClass =>
179-
widenForMatchSelector(tp.info.bounds.hi)
179+
widenForMatchSelector(tp.superType)
180180
case tp: HKApply =>
181181
widenForMatchSelector(tp.superType)
182182
case tp: AnnotatedType =>

0 commit comments

Comments
 (0)