Skip to content

Commit 6525787

Browse files
committed
Rename isHK -> isLambdaSub
1 parent ebaf7fb commit 6525787

File tree

7 files changed

+28
-23
lines changed

7 files changed

+28
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ object Config {
160160
final val showCompletions = false
161161

162162
/** If set, enables tracing */
163-
final val tracingEnabled = false
163+
final val tracingEnabled = true
164164

165165
/** Initial capacity of uniques HashMap.
166166
* Note: This MUST BE a power of two to work with util.HashSet

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class TypeApplications(val self: Type) extends AnyVal {
197197

198198
/** If `self` is a higher-kinded type, its type parameters, otherwise Nil */
199199
final def hkTypeParams(implicit ctx: Context): List[TypeParamInfo] =
200-
if (isHK) typeParams else Nil
200+
if (isLambdaSub) typeParams else Nil
201201

202202
/** If `self` is a generic class, its type parameter symbols, otherwise Nil */
203203
final def typeParamSymbols(implicit ctx: Context): List[TypeSymbol] = typeParams match {
@@ -207,10 +207,12 @@ class TypeApplications(val self: Type) extends AnyVal {
207207
case _ => Nil
208208
}
209209

210-
/** Is self type higher-kinded (i.e. of kind != "*")
211-
* or any-kinded (i.e. has AnyKind as upper bound)?
212-
*/
213-
def isHK(implicit ctx: Context): Boolean = hkResult.exists
210+
/** Is self type bounded by a type lambda or AnyKind? */
211+
def isLambdaSub(implicit ctx: Context): Boolean = hkResult.exists
212+
213+
/** Is self type of kind != "*"? */
214+
def hasHigherKind(implicit ctx: Context): Boolean =
215+
typeParams.nonEmpty || self.isRef(defn.AnyKindClass)
214216

215217
/** If self type is higher-kinded, its result type, otherwise NoType.
216218
* Note: The hkResult of an any-kinded type is again AnyKind.
@@ -268,9 +270,9 @@ class TypeApplications(val self: Type) extends AnyVal {
268270
//.ensuring(res => res.EtaReduce =:= self, s"res = $res, core = ${res.EtaReduce}, self = $self, hc = ${res.hashCode}")
269271
}
270272

271-
/** If self is not higher-kinded, eta expand it. */
272-
def ensureHK(implicit ctx: Context): Type =
273-
if (isHK) self else EtaExpansion(self)
273+
/** If self is not lambda-bound, eta expand it. */
274+
def ensureLambdaSub(implicit ctx: Context): Type =
275+
if (isLambdaSub) self else EtaExpansion(self)
274276

275277
/** Eta expand if `self` is a (non-lambda) class reference and `bound` is a higher-kinded type */
276278
def EtaExpandIfHK(bound: Type)(implicit ctx: Context): Type = {

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
380380
if (cls2.typeParams.isEmpty) {
381381
if (cls2 eq AnyKindClass) return true
382382
if (tp1.isRef(defn.NothingClass)) return true
383-
if (tp1.isHK) return false
383+
if (tp1.isLambdaSub) return false
384+
// Note: We would like to replace this by `if (tp1.hasHigherKind)`
385+
// but right now we cannot since some parts of the standard library rely on the
386+
// idiom that e.g. `List <: Any`. We have to bootstrap without scalac first.
384387
val base = tp1.baseType(cls2)
385388
if (base.exists && base.ne(tp1))
386389
return isSubType(base, tp2, if (tp1.isRef(cls2)) approx else approx.addLow)
@@ -391,7 +394,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
391394
val base = tp1.baseType(cls2)
392395
if (base.typeSymbol == cls2) return true
393396
}
394-
else if (tp1.isHK && !tp1.isRef(defn.AnyKindClass))
397+
else if (tp1.isLambdaSub && !tp1.isRef(defn.AnyKindClass))
395398
return recur(tp1, EtaExpansion(cls2.typeRef))
396399
}
397400
fourthTry
@@ -551,7 +554,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
551554
def compareTypeBounds = tp1 match {
552555
case tp1 @ TypeBounds(lo1, hi1) =>
553556
((lo2 eq NothingType) || isSubType(lo2, lo1)) &&
554-
((hi2 eq AnyType) && !hi1.isHK || (hi2 eq AnyKindType) || isSubType(hi1, hi2))
557+
((hi2 eq AnyType) && !hi1.isLambdaSub || (hi2 eq AnyKindType) || isSubType(hi1, hi2))
555558
case tp1: ClassInfo =>
556559
tp2 contains tp1
557560
case _ =>
@@ -621,7 +624,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
621624
case EtaExpansion(tycon1) => recur(tycon1, tp2)
622625
case _ => tp2 match {
623626
case tp2: HKTypeLambda => false // this case was covered in thirdTry
624-
case _ => tp2.isHK && isSubType(tp1.resultType, tp2.appliedTo(tp1.paramRefs))
627+
case _ => tp2.isLambdaSub && isSubType(tp1.resultType, tp2.appliedTo(tp1.paramRefs))
625628
}
626629
}
627630
compareHKLambda
@@ -729,7 +732,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
729732
tl => tp1base.tycon.appliedTo(args1.take(lengthDiff) ++
730733
tparams1.indices.toList.map(tl.paramRefs(_))))
731734
(ctx.mode.is(Mode.TypevarsMissContext) ||
732-
tryInstantiate(tycon2, tycon1.ensureHK)) &&
735+
tryInstantiate(tycon2, tycon1.ensureLambdaSub)) &&
733736
recur(tp1, tycon1.appliedTo(args2))
734737
}
735738
}
@@ -812,7 +815,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
812815
case param1: TypeParamRef =>
813816
def canInstantiate = tp2 match {
814817
case AppliedType(tycon2, args2) =>
815-
tryInstantiate(param1, tycon2.ensureHK) && isSubArgs(args1, args2, tp1, tycon2.typeParams)
818+
tryInstantiate(param1, tycon2.ensureLambdaSub) && isSubArgs(args1, args2, tp1, tycon2.typeParams)
816819
case _ =>
817820
false
818821
}
@@ -1227,8 +1230,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
12271230
if (tp1 eq tp2) tp1
12281231
else if (!tp1.exists) tp2
12291232
else if (!tp2.exists) tp1
1230-
else if ((tp1 isRef AnyClass) && !tp2.isHK || (tp1 isRef AnyKindClass) || (tp2 isRef NothingClass)) tp2
1231-
else if ((tp2 isRef AnyClass) && !tp1.isHK || (tp2 isRef AnyKindClass) || (tp1 isRef NothingClass)) tp1
1233+
else if ((tp1 isRef AnyClass) && !tp2.isLambdaSub || (tp1 isRef AnyKindClass) || (tp2 isRef NothingClass)) tp2
1234+
else if ((tp2 isRef AnyClass) && !tp1.isLambdaSub || (tp2 isRef AnyKindClass) || (tp1 isRef NothingClass)) tp1
12321235
else tp2 match { // normalize to disjunctive normal form if possible.
12331236
case OrType(tp21, tp22) =>
12341237
tp1 & tp21 | tp1 & tp22

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
356356
private def computeType(tp: Type): api.Type = {
357357
// TODO: Never dealias. We currently have to dealias because
358358
// sbt main class discovery relies on the signature of the main
359-
// method being fully dealiased. See https://github.com/sbt/zinc/issues/102
360-
val tp2 = if (!tp.isHK) tp.dealiasKeepAnnots else tp
359+
// method being fully dealiased. See https://github.com/sbt/zinc/isisLambdaSub/102
360+
val tp2 = if (!tp.isLambdaSub) tp.dealiasKeepAnnots else tp
361361
tp2 match {
362362
case NoPrefix | NoType =>
363363
Constants.emptyType

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object Checking {
4545
*/
4646
def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type)(implicit ctx: Context): Unit = {
4747
(args, boundss).zipped.foreach { (arg, bound) =>
48-
if (!bound.isHK && arg.tpe.isHK)
48+
if (!bound.isLambdaSub && arg.tpe.isLambdaSub)
4949
// see MissingTypeParameterFor
5050
ctx.error(ex"missing type parameter(s) for $arg", arg.pos)
5151
}
@@ -657,7 +657,7 @@ trait Checking {
657657

658658
/** Check that `tpt` does not define a higher-kinded type */
659659
def checkSimpleKinded(tpt: Tree)(implicit ctx: Context): Tree =
660-
if (tpt.tpe.isHK && !ctx.compilationUnit.isJava) {
660+
if (tpt.tpe.isLambdaSub && !ctx.compilationUnit.isJava) {
661661
// be more lenient with missing type params in Java,
662662
// needed to make pos/java-interop/t1196 work.
663663
errorTree(tpt, MissingTypeParameterFor(tpt.tpe))

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ trait TypeAssigner {
255255
*/
256256
def accessibleSelectionType(tree: untpd.RefTree, qual1: Tree)(implicit ctx: Context): Type = {
257257
var qualType = qual1.tpe.widenIfUnstable
258-
if (qualType.isHK) qualType = errorType(em"$qualType takes type parameters", qual1.pos)
258+
if (qualType.isLambdaSub) qualType = errorType(em"$qualType takes type parameters", qual1.pos)
259259
val ownType = selectionType(qualType, tree.name, tree.pos)
260260
ensureAccessible(ownType, qual1.isInstanceOf[Super], tree.pos)
261261
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ class Typer extends Namer
12371237
var res = typed(desugaredArg, argPt)
12381238
arg match {
12391239
case TypeBoundsTree(EmptyTree, EmptyTree)
1240-
if tparam.paramInfo.isHK &&
1240+
if tparam.paramInfo.isLambdaSub &&
12411241
tpt1.tpe.typeParamSymbols.nonEmpty &&
12421242
!ctx.mode.is(Mode.Pattern) =>
12431243
// An unbounded `_` automatically adapts to type parameter bounds. This means:

0 commit comments

Comments
 (0)