Skip to content

Commit 90b3446

Browse files
committed
WIP widen
1 parent ade3ae3 commit 90b3446

13 files changed

+33
-33
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -998,11 +998,10 @@ class Definitions {
998998
FunctionType(args.length, isContextual, isErased).appliedTo(args ::: resultType :: Nil)
999999
def unapply(ft: Type)(using Context): Option[(List[Type], Type, Boolean, Boolean)] = {
10001000
val tsym = ft.typeSymbol
1001-
if (isFunctionClass(tsym)) {
1001+
if isFunctionClass(tsym) && ft.isRef(tsym) then
10021002
val targs = ft.dealias.argInfos
10031003
if (targs.isEmpty) None
10041004
else Some(targs.init, targs.last, tsym.name.isContextFunction, tsym.name.isErasedFunction)
1005-
}
10061005
else None
10071006
}
10081007
}
@@ -1379,15 +1378,16 @@ class Definitions {
13791378
/** Is `tp` (an alias) of either a scala.FunctionN or a scala.ContextFunctionN
13801379
* instance?
13811380
*/
1382-
def isNonRefinedFunction(tp: Type)(using Context): Boolean = {
1381+
def isNonRefinedFunction(tp: Type)(using Context): Boolean =
13831382
val arity = functionArity(tp)
13841383
val sym = tp.dealias.typeSymbol
13851384

1386-
arity >= 0 &&
1387-
isFunctionClass(sym) &&
1388-
tp.isRef(FunctionType(arity, sym.name.isContextFunction, sym.name.isErasedFunction).typeSymbol) &&
1389-
!tp.isInstanceOf[RefinedType]
1390-
}
1385+
arity >= 0
1386+
&& isFunctionClass(sym)
1387+
&& tp.isRef(
1388+
FunctionType(arity, sym.name.isContextFunction, sym.name.isErasedFunction).typeSymbol,
1389+
skipRefined = false)
1390+
end isNonRefinedFunction
13911391

13921392
/** Is `tp` a representation of a (possibly dependent) function type or an alias of such? */
13931393
def isFunctionType(tp: Type)(using Context): Boolean =
@@ -1460,9 +1460,9 @@ class Definitions {
14601460
if ctx.erasedTypes then
14611461
atPhase(erasurePhase)(unapply(tp))
14621462
else
1463-
val tp1 = tp.dealias
1464-
if isContextFunctionClass(tp1.typeSymbol) then
1465-
val args = asContextFunctionType(tp).dropDependentRefinement.argInfos
1463+
val tp1 = asContextFunctionType(tp)
1464+
if tp1.exists then
1465+
val args = tp1.dropDependentRefinement.argInfos
14661466
Some((args.init, args.last, tp1.typeSymbol.name.isErasedFunction))
14671467
else None
14681468

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ class TypeApplications(val self: Type) extends AnyVal {
445445
* otherwise return Nil.
446446
* Existential types in arguments are returned as TypeBounds instances.
447447
*/
448-
final def argInfos(using Context): List[Type] = self.stripTypeVar.stripAnnots match {
448+
final def argInfos(using Context): List[Type] = self.stripped match {
449449
case AppliedType(tycon, args) => args
450450
case _ => Nil
451451
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ object TypeErasure {
232232
* at top-level, treating opaque aliases as transparent.
233233
*/
234234
def classify(tp: Type)(using Context): Type =
235-
if (tp.typeSymbol.isClass) tp
235+
if (tp.widen.typeSymbol.isClass) tp
236236
else tp match {
237237
case tp: TypeProxy => classify(tp.translucentSuperType)
238238
case tp: AndOrType => tp.derivedAndOrType(classify(tp.tp1), classify(tp.tp2))
@@ -571,7 +571,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
571571
/** The erasure of a function result type. */
572572
private def eraseResult(tp: Type)(using Context): Type = tp match {
573573
case tp: TypeRef =>
574-
val sym = tp.typeSymbol
574+
val sym = tp.symbol
575575
if (sym eq defn.UnitClass) sym.typeRef
576576
// For a value class V, "new V(x)" should have type V for type adaptation to work
577577
// correctly (see SIP-15 and [[Erasure.Boxing.adaptToType]]), so the return type of a

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,15 +675,15 @@ class TreeUnpickler(reader: TastyReader,
675675
(flags, annotFns.reverse, privateWithin)
676676
}
677677

678-
private def readWithin(using Context): Symbol = readType().typeSymbol
678+
private def readWithin(using Context): Symbol = readType().widen.typeSymbol
679679

680680
private def readAnnot(using Context): Symbol => Annotation =
681681
readByte()
682682
val end = readEnd()
683683
val tp = readType()
684684
val lazyAnnotTree = readLaterWithOwner(end, _.readTerm())
685685
owner =>
686-
Annotation.deferredSymAndTree(tp.typeSymbol)(lazyAnnotTree(owner).complete)
686+
Annotation.deferredSymAndTree(tp.widen.typeSymbol)(lazyAnnotTree(owner).complete)
687687

688688
/** Create symbols for the definitions in the statement sequence between
689689
* current address and `end`.
@@ -1107,7 +1107,7 @@ class TreeUnpickler(reader: TastyReader,
11071107
case SUPER =>
11081108
val qual = readTerm()
11091109
val (mixId, mixTpe) = ifBefore(end)(readQualId(), (untpd.EmptyTypeIdent, NoType))
1110-
tpd.Super(qual, mixId, mixTpe.typeSymbol)
1110+
tpd.Super(qual, mixId, mixTpe.widen.typeSymbol)
11111111
case APPLY =>
11121112
val fn = readTerm()
11131113
tpd.Apply(fn, until(end)(readTerm()))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
977977
val start = readIndex
978978
val atp = readTypeRef()
979979
val phase = ctx.phase
980-
Annotation.deferred(atp.typeSymbol)(
980+
Annotation.deferred(atp.widen.typeSymbol)(
981981
atReadPos(start, () => atPhase(phase)(readAnnotationContents(end))))
982982
}
983983

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ object Formatting {
119119
*/
120120
def followAlias(e1: Recorded): Recorded = e1 match {
121121
case e1: Symbol if e1.isAliasType =>
122-
val underlying = e1.typeRef.underlyingClassRef(refinementOK = false).typeSymbol
122+
val underlying = e1.typeRef.underlyingClassRef(refinementOK = false).widen.typeSymbol
123123
if (underlying.name == e1.name) underlying else e1
124124
case _ => e1
125125
}

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
6161
case tp: LazyRef =>
6262
homogenize(tp.ref)
6363
case tp @ AppliedType(tycon, args) =>
64-
if (defn.isCompiletimeAppliedType(tycon.typeSymbol)) tp.tryCompiletimeConstantFold
64+
if (defn.isCompiletimeAppliedType(tycon.widen.typeSymbol)) tp.tryCompiletimeConstantFold
6565
else tycon.dealias.appliedTo(args)
6666
case _ =>
6767
tp

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
167167
def isInfixType(tp: Type): Boolean = tp match {
168168
case AppliedType(tycon, args) =>
169169
args.length == 2 &&
170-
tycon.typeSymbol.getAnnotation(defn.ShowAsInfixAnnot).map(_.argumentConstant(0).forall(_.booleanValue))
171-
.getOrElse(!Character.isUnicodeIdentifierStart(tycon.typeSymbol.name.toString.head))
170+
tycon.widen.typeSymbol.getAnnotation(defn.ShowAsInfixAnnot).map(_.argumentConstant(0).forall(_.booleanValue))
171+
.getOrElse(!Character.isUnicodeIdentifierStart(tycon.widen.typeSymbol.name.toString.head))
172172
case _ => false
173173
}
174174

175-
def tyconName(tp: Type): Name = tp.typeSymbol.name
175+
def tyconName(tp: Type): Name = tp.widen.typeSymbol.name
176176
def checkAssocMismatch(tp: Type, isRightAssoc: Boolean) = tp match {
177177
case AppliedType(tycon, _) => isInfixType(tp) && tyconName(tycon).endsWith(":") != isRightAssoc
178178
case AndType(_, _) => isRightAssoc
@@ -194,7 +194,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
194194

195195
homogenize(tp) match {
196196
case tp @ AppliedType(tycon, args) =>
197-
val cls = tycon.typeSymbol
197+
val cls = tycon.widen.typeSymbol
198198
if (tycon.isRepeatedParam) toTextLocal(args.head) ~ "*"
199199
else if (defn.isFunctionClass(cls)) toTextFunction(args, cls.name.isContextFunction, cls.name.isErasedFunction)
200200
else if (tp.tupleArity >= 2 && !printDebug) toTextTuple(tp.tupleElementTypes)

compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ object PickledQuotes {
147147
tp.derivedClassInfo(classParents = tp.classParents.map(apply))
148148
case tp: TypeRef =>
149149
typeSpliceMap.get(tp.symbol) match
150-
case Some(t) if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => mapOver(t)
150+
case Some(t) if tp.widen.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => mapOver(t)
151151
case _ => mapOver(tp)
152152
case _ =>
153153
mapOver(tp)

compiler/src/dotty/tools/dotc/transform/ElimOpaque.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ElimOpaque extends MiniPhase with DenotTransformer {
6666
if sym == defn.Any_== || sym == defn.Any_!= then
6767
tree match
6868
case Apply(Select(receiver, name: TermName), args)
69-
if atPhase(thisPhase)(receiver.tpe.widen.dealias.typeSymbol.isOpaqueAlias) =>
69+
if atPhase(thisPhase)(receiver.tpe.widenDealias.typeSymbol.isOpaqueAlias) =>
7070
applyOverloaded(receiver, name, args, Nil, defn.BooleanType)
7171
case _ =>
7272
tree

compiler/src/dotty/tools/dotc/transform/ElimPolyFunction.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ElimPolyFunction extends MiniPhase with DenotTransformer {
3333
val cinfo = ref.classInfo
3434
val newParent = functionTypeOfPoly(cinfo)
3535
val newParents = cinfo.classParents.map(parent =>
36-
if (parent.typeSymbol == defn.PolyFunctionClass)
36+
if (parent.widen.typeSymbol == defn.PolyFunctionClass)
3737
newParent
3838
else
3939
parent
@@ -51,7 +51,7 @@ class ElimPolyFunction extends MiniPhase with DenotTransformer {
5151

5252
override def transformTemplate(tree: Template)(using Context): Tree = {
5353
val newParents = tree.parents.mapconserve(parent =>
54-
if (parent.tpe.typeSymbol == defn.PolyFunctionClass) {
54+
if (parent.tpe.widen.typeSymbol == defn.PolyFunctionClass) {
5555
val cinfo = tree.symbol.owner.asClass.classInfo
5656
tpd.TypeTree(functionTypeOfPoly(cinfo))
5757
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,6 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
325325
val array = tp.translateFromRepeated(toArray = true) // Array[? <: T]
326326
val element = array.elemType.hiBound // T
327327

328-
if element <:< defn.AnyRefType || element.typeSymbol.isPrimitiveValueClass then array
328+
if element <:< defn.AnyRefType || element.widen.typeSymbol.isPrimitiveValueClass then array
329329
else defn.ArrayOf(TypeBounds.upper(AndType(element, defn.AnyRefType))) // Array[? <: T & AnyRef]
330330
}

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ object Erasure {
273273
if (tree.tpe isRef defn.NullClass)
274274
adaptToType(tree, underlying)
275275
else if (!(tree.tpe <:< tycon)) {
276-
assert(!(tree.tpe.typeSymbol.isPrimitiveValueClass))
276+
assert(!(tree.tpe.widen.typeSymbol.isPrimitiveValueClass))
277277
val nullTree = nullLiteral
278278
val unboxedNull = adaptToType(nullTree, underlying)
279279

@@ -434,8 +434,8 @@ object Erasure {
434434
def autoAdaptedParam(tp: Type) = !tp.isErasedValueType && !tp.isPrimitiveValueType
435435
val explicitSAMType = implClosure.tpt.tpe.exists
436436
def autoAdaptedResult(tp: Type) = !tp.isErasedValueType &&
437-
(!explicitSAMType || tp.typeSymbol != defn.UnitClass)
438-
def sameSymbol(tp1: Type, tp2: Type) = tp1.typeSymbol == tp2.typeSymbol
437+
(!explicitSAMType || tp.widen.typeSymbol != defn.UnitClass)
438+
def sameSymbol(tp1: Type, tp2: Type) = tp1.widen.typeSymbol == tp2.widen.typeSymbol
439439

440440
val paramAdaptationNeeded =
441441
implParamTypes.lazyZip(samParamTypes).exists((implType, samType) =>
@@ -959,7 +959,7 @@ object Erasure {
959959
}
960960

961961
override def typedClosure(tree: untpd.Closure, pt: Type)(using Context): Tree = {
962-
val xxl = defn.isXXLFunctionClass(tree.typeOpt.typeSymbol)
962+
val xxl = defn.isXXLFunctionClass(tree.typeOpt.widen.typeSymbol)
963963
var implClosure = super.typedClosure(tree, pt).asInstanceOf[Closure]
964964
if (xxl) implClosure = cpy.Closure(implClosure)(tpt = TypeTree(defn.FunctionXXLClass.typeRef))
965965
adaptClosure(implClosure)

0 commit comments

Comments
 (0)