Skip to content

Commit 0293b06

Browse files
committed
WIP widen2
1 parent 90b3446 commit 0293b06

10 files changed

+33
-33
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ object GenericSignatures {
4848
// a signature should always start with a class
4949
def ensureClassAsFirstParent(tps: List[Type]) = tps match {
5050
case Nil => defn.ObjectType :: Nil
51-
case head :: tail if isInterfaceOrTrait(head.typeSymbol) => defn.ObjectType :: tps
51+
case head :: tail if isInterfaceOrTrait(head.widen.typeSymbol) => defn.ObjectType :: tps
5252
case _ => tps
5353
}
5454

@@ -66,7 +66,7 @@ object GenericSignatures {
6666
def boxedSig(tp: Type): Unit = jsig(tp.widenDealias, primitiveOK = false)
6767

6868
def boundsSig(bounds: List[Type]): Unit = {
69-
val (isTrait, isClass) = bounds partition (_.typeSymbol.is(Trait))
69+
val (isTrait, isClass) = bounds partition (_.widen.typeSymbol.is(Trait))
7070
isClass match {
7171
case Nil => builder.append(':') // + boxedSig(ObjectTpe)
7272
case x :: _ => builder.append(':'); boxedSig(x)
@@ -97,7 +97,7 @@ object GenericSignatures {
9797

9898
def methodResultSig(restpe: Type): Unit = {
9999
val finalType = restpe.finalResultType
100-
val sym = finalType.typeSymbol
100+
val sym = finalType.widen.typeSymbol
101101
if (sym == defn.UnitClass || sym == defn.BoxedUnitModule || sym0.isConstructor)
102102
builder.append(ClassfileConstants.VOID_TAG)
103103
else
@@ -133,7 +133,7 @@ object GenericSignatures {
133133
case PolyType(_, res) =>
134134
builder.append('*') // scala/bug#7932
135135
case _: HKTypeLambda =>
136-
fullNameInSig(tp.typeSymbol)
136+
fullNameInSig(tp.widen.typeSymbol)
137137
builder.append(';')
138138
case _ =>
139139
boxedSig(tp)
@@ -148,7 +148,7 @@ object GenericSignatures {
148148
builder.delete(builder.length() - 1, builder.length())// delete ';'
149149
// If the prefix is a module, drop the '$'. Classes (or modules) nested in modules
150150
// are separated by a single '$' in the filename: `object o { object i }` is o$i$.
151-
if (preRebound.typeSymbol.is(ModuleClass))
151+
if (preRebound.widen.typeSymbol.is(ModuleClass))
152152
builder.delete(builder.length() - 1, builder.length())
153153

154154
// Ensure every '.' in the generated signature immediately follows
@@ -324,10 +324,10 @@ object GenericSignatures {
324324
private def intersectionDominator(parents: List[Type])(using Context): Type =
325325
if (parents.isEmpty) defn.ObjectType
326326
else {
327-
val psyms = parents map (_.typeSymbol)
327+
val psyms = parents map (_.widen.typeSymbol)
328328
if (psyms contains defn.ArrayClass)
329329
// treat arrays specially
330-
defn.ArrayType.appliedTo(intersectionDominator(parents.filter(_.typeSymbol == defn.ArrayClass).map(t => t.argInfos.head)))
330+
defn.ArrayType.appliedTo(intersectionDominator(parents.filter(_.widen.typeSymbol == defn.ArrayClass).map(t => t.argInfos.head)))
331331
else {
332332
// implement new spec for erasure of refined types.
333333
def isUnshadowed(psym: Symbol) =
@@ -350,12 +350,12 @@ object GenericSignatures {
350350
var leaves = collection.mutable.ListBuffer.empty[Type] += parents.head
351351
while (rest.nonEmpty) {
352352
val candidate = rest.head
353-
val candidateSym = candidate.typeSymbol
354-
// val required = requiredDirect(candidateSym) || !leaves.exists(t => t.typeSymbol isSubClass candidateSym)
355-
val required = !leaves.exists(t => t.typeSymbol.isSubClass(candidateSym))
353+
val candidateSym = candidate.widen.typeSymbol
354+
// val required = requiredDirect(candidateSym) || !leaves.exists(t => t.widen.typeSymbol isSubClass candidateSym)
355+
val required = !leaves.exists(t => t.widen.typeSymbol.isSubClass(candidateSym))
356356
if (required) {
357357
leaves = leaves filter { t =>
358-
val ts = t.typeSymbol
358+
val ts = t.widen.typeSymbol
359359
!(ts.is(Trait) || ts.is(PureInterface)) || !candidateSym.isSubClass(ts)
360360
// requiredDirect(ts) || !ts.isTraitOrInterface || !candidateSym.isSubClass(ts)
361361
}
@@ -400,14 +400,14 @@ object GenericSignatures {
400400
private object RefOrAppliedType {
401401
def unapply(tp: Type)(using Context): Option[(Symbol, Type, List[Type])] = tp match {
402402
case TypeParamRef(_, _) =>
403-
Some((tp.typeSymbol, tp, Nil))
403+
Some((tp.widen.typeSymbol, tp, Nil))
404404
case TermParamRef(_, _) =>
405405
Some((tp.termSymbol, tp, Nil))
406-
case TypeRef(pre, _) if !tp.typeSymbol.isAliasType =>
407-
val sym = tp.typeSymbol
406+
case TypeRef(pre, _) if !tp.widen.typeSymbol.isAliasType =>
407+
val sym = tp.widen.typeSymbol
408408
Some((sym, pre, Nil))
409409
case AppliedType(pre, args) =>
410-
Some((pre.typeSymbol, pre, args))
410+
Some((pre.widen.typeSymbol, pre, args))
411411
case _ =>
412412
None
413413
}
@@ -423,11 +423,11 @@ object GenericSignatures {
423423
if (!x)
424424
tp match {
425425
case RefinedType(parent, refinedName, refinedInfo) =>
426-
val sym = parent.typeSymbol
426+
val sym = parent.widen.typeSymbol
427427
if (sym == defn.ArrayClass) foldOver(x, refinedInfo)
428428
else true
429429
case tref @ TypeRef(pre, name) =>
430-
val sym = tref.typeSymbol
430+
val sym = tref.widen.typeSymbol
431431
if (sym.is(TypeParam) || sym.typeParams.nonEmpty) true
432432
else if (sym.isClass) foldOver(x, rebindInnerClass(pre, sym)) // #2585
433433
else foldOver(x, pre)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase
111111
def needsHoist(tree: Tree) = tree match {
112112
case _: DefDef => true
113113
case _: Template => true
114-
case _: New => !tree.tpe.typeSymbol.isStatic
114+
case _: New => !tree.tpe.widen.typeSymbol.isStatic
115115
case _: RefTree | _: This => refNeedsHoist(tree.tpe)
116116
case _ => false
117117
}
@@ -130,7 +130,7 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase
130130
case _ if arg.existsSubTree(needsHoist) =>
131131
val superMeth = newSuperArgMethod(arg.tpe)
132132
val superArgDef = polyDefDef(superMeth, trefs => vrefss => {
133-
val paramSyms = trefs.map(_.typeSymbol) ::: vrefss.flatten.map(_.symbol)
133+
val paramSyms = trefs.map(_.widen.typeSymbol) ::: vrefss.flatten.map(_.symbol)
134134
val tmap = new TreeTypeMap(
135135
typeMap = new TypeMap {
136136
lazy val origToParam = origParams.zip(paramSyms).toMap

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ object LambdaLift {
213213
def captureImplicitThis(x: Type): Unit =
214214
x match {
215215
case tr@TermRef(x, _) if (!tr.termSymbol.isStatic) => captureImplicitThis(x)
216-
case x: ThisType if (!x.tref.typeSymbol.isStaticOwner) => narrowTo(x.tref.typeSymbol.asClass)
216+
case x: ThisType if (!x.tref.widen.typeSymbol.isStaticOwner) => narrowTo(x.tref.typeSymbol.asClass)
217217
case _ =>
218218
}
219219
captureImplicitThis(tree.tpe)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@ class ReifyQuotes extends MacroTransform {
327327
/** Remove references to local types that will not be defined in this quote */
328328
def getTypeHoleType(using Context) = new TypeMap() {
329329
override def apply(tp: Type): Type = tp match
330-
case tp: TypeRef if tp.typeSymbol.isTypeSplice =>
330+
case tp: TypeRef if tp.widen.typeSymbol.isTypeSplice =>
331331
apply(tp.dealias)
332332
case tp @ TypeRef(pre, _) if pre == NoPrefix || pre.termSymbol.isLocal =>
333-
val hiBound = tp.typeSymbol.info match
333+
val hiBound = tp.widen.typeSymbol.info match
334334
case info @ ClassInfo(_, _, classParents, _, _) => classParents.reduce(_ & _)
335335
case info => info.hiBound
336336
apply(hiBound)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Staging extends MacroTransform {
6363
}
6464

6565
tree.tpe match {
66-
case tpe @ TypeRef(prefix, _) if tpe.typeSymbol.isTypeSplice =>
66+
case tpe @ TypeRef(prefix, _) if tpe.widen.typeSymbol.isTypeSplice =>
6767
// Type splices must have a know term ref, usually to an implicit argument
6868
// This is mostly intended to catch `quoted.Type[T]#splice` types which should just be `T`
6969
assert(prefix.isInstanceOf[TermRef] || prefix.isInstanceOf[ThisType], prefix)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ object SymUtils {
6161

6262
def derivesFromJavaEnum(using Context) =
6363
self.is(Enum, butNot = Case) &&
64-
self.info.parents.exists(p => p.typeSymbol == defn.JavaEnumClass)
64+
self.info.parents.exists(p => p.widen.typeSymbol == defn.JavaEnumClass)
6565

6666
/** Is this a case class for which a product mirror is generated?
6767
* Excluded are value classes, abstract classes and case classes with more than one

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
206206
pinfo == defn.StringType
207207
case _ => false
208208
}
209-
val constructor = ioob.typeSymbol.info.decls.find(filterStringConstructor _).asTerm
209+
val constructor = ioob.widen.typeSymbol.info.decls.find(filterStringConstructor _).asTerm
210210
val stringIndex = Apply(Select(index, nme.toString_), Nil)
211211
val error = Throw(New(ioob, constructor, List(stringIndex)))
212212

@@ -241,7 +241,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
241241
def wildcardAscription(tp: Type) = Typed(Underscore(tp), TypeTree(tp))
242242
val pattern = Bind(thatAsClazz, wildcardAscription(AnnotatedType(clazzType, Annotation(defn.UncheckedAnnot)))) // x$0 @ (_: C @unchecked)
243243
// compare primitive fields first, slow equality checks of non-primitive fields can be skipped when primitives differ
244-
val sortedAccessors = accessors.sortBy(accessor => if (accessor.info.typeSymbol.isPrimitiveValueClass) 0 else 1)
244+
val sortedAccessors = accessors.sortBy(accessor => if (accessor.info.widen.typeSymbol.isPrimitiveValueClass) 0 else 1)
245245
val comparisons = sortedAccessors.map { accessor =>
246246
This(clazz).select(accessor).equal(ref(thatAsClazz).select(accessor)) }
247247
val rhs = // this.x == this$0.x && this.y == x$0.y
@@ -413,7 +413,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
413413

414414
/** Is this an anonymous class deriving from an enum definition? */
415415
extension (cls: ClassSymbol) private def isEnumValueImplementation(using Context): Boolean =
416-
cls.isAnonymousClass && cls.classParents.head.typeSymbol.is(Enum) // asserted in Typer
416+
cls.isAnonymousClass && cls.classParents.head.widen.typeSymbol.is(Enum) // asserted in Typer
417417

418418
/** If this is the class backing a serializable singleton enum value with base class `MyEnum`,
419419
* and not deriving from `java.lang.Enum` add the method:

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ object TypeTestsCasts {
5353
* 8. otherwise, TRUE
5454
*/
5555
def checkable(X: Type, P: Type, span: Span)(using Context): Boolean = {
56-
def isAbstract(P: Type) = !P.dealias.typeSymbol.isClass
56+
def isAbstract(P: Type) = !P.dealias.widen.typeSymbol.isClass
5757

5858
def replaceP(tp: Type)(using Context) = new TypeMap {
5959
def apply(tp: Type) = tp match {
60-
case tref: TypeRef if tref.typeSymbol.isPatternBound =>
60+
case tref: TypeRef if tref.widen.typeSymbol.isPatternBound =>
6161
WildcardType
6262
case AnnotatedType(_, annot) if annot.symbol == defn.UncheckedAnnot =>
6363
WildcardType
@@ -67,7 +67,7 @@ object TypeTestsCasts {
6767

6868
def replaceX(tp: Type)(using Context) = new TypeMap {
6969
def apply(tp: Type) = tp match {
70-
case tref: TypeRef if tref.typeSymbol.isPatternBound =>
70+
case tref: TypeRef if tref.widen.typeSymbol.isPatternBound =>
7171
if (variance == 1) tref.info.hiBound
7272
else if (variance == -1) tref.info.loBound
7373
else OrType(defn.AnyType, defn.NothingType)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class VCElideAllocations extends MiniPhase with IdentityDenotTransformer {
2525
override def transformApply(tree: Apply)(using Context): Tree =
2626
def hasUserDefinedEquals(tp: Type): Boolean =
2727
val eql = atPhase(erasurePhase) {
28-
defn.Any_equals.matchingMember(tp.typeSymbol.thisType)
28+
defn.Any_equals.matchingMember(tp.widen.typeSymbol.thisType)
2929
}
3030
eql.owner != defn.AnyClass && !eql.is(Synthetic)
3131

@@ -34,7 +34,7 @@ class VCElideAllocations extends MiniPhase with IdentityDenotTransformer {
3434
// (We don't handle != because it has been eliminated by InterceptedMethods)
3535
case BinaryOp(NewWithArgs(tp1, List(u1)), op, NewWithArgs(tp2, List(u2)))
3636
if (tp1 eq tp2) && (op eq defn.Any_==)
37-
&& isDerivedValueClass(tp1.typeSymbol)
37+
&& isDerivedValueClass(tp1.widen.typeSymbol)
3838
&& !hasUserDefinedEquals(tp1) =>
3939
// == is overloaded in primitive classes
4040
u1.equal(u2)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ object ValueClasses {
6060
def isCyclic(cls: ClassSymbol)(using Context): Boolean = {
6161
def recur(seen: Set[Symbol], clazz: ClassSymbol)(using Context): Boolean =
6262
(seen contains clazz) || {
63-
val unboxed = underlyingOfValueClass(clazz).typeSymbol
63+
val unboxed = underlyingOfValueClass(clazz).widen.typeSymbol
6464
(isDerivedValueClass(unboxed)) && recur(seen + clazz, unboxed.asClass)
6565
}
6666

0 commit comments

Comments
 (0)