Skip to content

Commit 803ce81

Browse files
committed
WIP widen 3
1 parent 80f578b commit 803ce81

File tree

7 files changed

+29
-28
lines changed

7 files changed

+29
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class TupleOptimizations extends MiniPhase with IdentityDenotTransformer {
191191
private def knownTupleFromElements(tpes: List[Type], elements: List[Tree])(using Context) = {
192192
val size = elements.size
193193
assert(0 < size && size <= MaxTupleArity)
194-
val tupleModule = defn.TupleType(size).classSymbol.companionModule
194+
val tupleModule = defn.TupleType(size).widen.classSymbol.companionModule
195195
ref(tupleModule).select(nme.apply).appliedToTypes(tpes).appliedToArgs(elements)
196196
}
197197

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ object TypeTestsCasts {
148148
recur(tp1, P) && recur(tp2, P)
149149
case _ =>
150150
// always false test warnings are emitted elsewhere
151-
X.classSymbol.exists && P.classSymbol.exists &&
152-
!X.classSymbol.asClass.mayHaveCommonChild(P.classSymbol.asClass) ||
151+
X.widen.classSymbol.exists && P.widen.classSymbol.exists &&
152+
!X.widen.classSymbol.asClass.mayHaveCommonChild(P.widen.classSymbol.asClass) ||
153153
// first try without striping type parameters for performance
154154
typeArgsTrivial(X, tpe) ||
155155
typeArgsTrivial(stripTypeParam(X), tpe)
@@ -175,15 +175,15 @@ object TypeTestsCasts {
175175
else {
176176
val sym = tree.symbol
177177

178-
def isPrimitive(tp: Type) = tp.classSymbol.isPrimitiveValueClass
178+
def isPrimitive(tp: Type) = tp.widen.classSymbol.isPrimitiveValueClass
179179

180180
def derivedTree(expr1: Tree, sym: Symbol, tp: Type) =
181181
cpy.TypeApply(tree)(expr1.select(sym).withSpan(expr.span), List(TypeTree(tp)))
182182

183183
def effectiveClass(tp: Type): Symbol =
184184
if tp.isRef(defn.PairClass) then effectiveClass(erasure(tp))
185185
else if tp.isRef(defn.AnyValClass) then defn.AnyClass
186-
else tp.classSymbol
186+
else tp.widen.classSymbol
187187

188188
def foundClasses(tp: Type, acc: List[Symbol]): List[Symbol] = tp.dealias match
189189
case OrType(tp1, tp2) => foundClasses(tp2, foundClasses(tp1, acc))

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object TypeUtils {
1919
self.isInstanceOf[ErasedValueType]
2020

2121
def isPrimitiveValueType(using Context): Boolean =
22-
self.classSymbol.isPrimitiveValueClass
22+
self.widen.classSymbol.isPrimitiveValueClass
2323

2424
def isByName: Boolean =
2525
self.isInstanceOf[ExprType]
@@ -41,9 +41,9 @@ object TypeUtils {
4141
case AppliedType(tycon, _ :: tl :: Nil) if tycon.isRef(defn.PairClass) =>
4242
val arity = tl.tupleArity
4343
if (arity < 0) arity else arity + 1
44-
case self: TermRef if self.symbol == defn.EmptyTupleModule =>
45-
0
46-
case self if defn.isTupleClass(self.classSymbol) =>
44+
case self: SingletonType =>
45+
if self.termSymbol == defn.EmptyTupleModule then 0 else -1
46+
case self if defn.isTupleClass(self.widen.classSymbol) =>
4747
self.dealias.argInfos.length
4848
case _ =>
4949
-1
@@ -53,9 +53,10 @@ object TypeUtils {
5353
def tupleElementTypes(using Context): List[Type] = self match {
5454
case AppliedType(tycon, hd :: tl :: Nil) if tycon.isRef(defn.PairClass) =>
5555
hd :: tl.tupleElementTypes
56-
case self: TermRef if self.symbol == defn.EmptyTupleModule =>
56+
case self: SingletonType =>
57+
assert(self.termSymbol == defn.EmptyTupleModule, "not a tuple")
5758
Nil
58-
case self if defn.isTupleClass(self.classSymbol) =>
59+
case self if defn.isTupleClass(self.widen.classSymbol) =>
5960
self.dealias.argInfos
6061
case _ =>
6162
throw new AssertionError("not a tuple")

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
535535
|| sym.owner == defn.StringClass
536536
|| defn.pureMethods.contains(sym)
537537
val isCaseClassApply = {
538-
val cls = tree.tpe.classSymbol
538+
val cls = tree.tpe.widen.classSymbol
539539
val meth = fn.symbol
540540
meth.name == nme.apply &&
541541
meth.flags.is(Synthetic) &&
@@ -787,9 +787,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
787787
case Apply(fn, args) =>
788788
fn match {
789789
case Select(New(tpt), nme.CONSTRUCTOR) =>
790-
Some((tpt.tpe.classSymbol, args, Nil, false))
790+
Some((tpt.tpe.widen.classSymbol, args, Nil, false))
791791
case TypeApply(Select(New(tpt), nme.CONSTRUCTOR), _) =>
792-
Some((tpt.tpe.classSymbol, args, Nil, false))
792+
Some((tpt.tpe.widen.classSymbol, args, Nil, false))
793793
case _ =>
794794
val meth = fn.symbol
795795
if (meth.name == nme.apply &&
@@ -1105,7 +1105,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
11051105
}
11061106

11071107
val paramType = mt.paramInfos.head
1108-
val paramCls = paramType.classSymbol
1108+
val paramCls = paramType.widen.classSymbol
11091109
if (paramCls.is(Case) && unapp.symbol.is(Synthetic) && scrut <:< paramType) {
11101110
val caseAccessors =
11111111
if (paramCls.is(Scala2x)) paramCls.caseAccessors.filter(_.is(Method))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ class Namer { typer: Typer =>
784784

785785
if denot.isClass && !sym.isEnumAnonymClass && !sym.isRefinementClass then
786786
val child = if (denot.is(Module)) denot.sourceModule else denot.symbol
787-
denot.asClass.classParents.foreach { parent => register(child, parent.classSymbol.asClass) }
787+
denot.asClass.classParents.foreach { parent => register(child, parent.widen.classSymbol.asClass) }
788788
else if denot.is(CaseVal, butNot = Method | Module) then
789789
assert(denot.is(Enum), denot)
790790
denot.info.classSymbols.foreach { parent => register(denot.symbol, parent) }
@@ -1235,7 +1235,7 @@ class Namer { typer: Typer =>
12351235
case Apply(fn, _) => typedAheadAnnotationClass(fn)
12361236
case TypeApply(fn, _) => typedAheadAnnotationClass(fn)
12371237
case Select(qual, nme.CONSTRUCTOR) => typedAheadAnnotationClass(qual)
1238-
case New(tpt) => typedAheadType(tpt).tpe.classSymbol
1238+
case New(tpt) => typedAheadType(tpt).tpe.widen.classSymbol
12391239
}
12401240

12411241
/** Enter and typecheck parameter list */

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,19 @@ object RefChecks {
9999
def checkSelfConforms(other: ClassSymbol, category: String, relation: String) = {
100100
val otherSelf = other.declaredSelfTypeAsSeenFrom(cls.thisType)
101101
if otherSelf.exists && !(cinfo.selfType <:< otherSelf) then
102-
report.error(DoesNotConformToSelfType(category, cinfo.selfType, cls, otherSelf, relation, other.classSymbol),
102+
report.error(DoesNotConformToSelfType(category, cinfo.selfType, cls, otherSelf, relation, other),
103103
cls.srcPos)
104104
}
105105
val parents = cinfo.classParents
106106
for (parent <- parents)
107-
checkSelfConforms(parent.classSymbol.asClass, "illegal inheritance", "parent")
107+
checkSelfConforms(parent.widen.classSymbol.asClass, "illegal inheritance", "parent")
108108
for (reqd <- cinfo.cls.givenSelfType.classSymbols)
109109
checkSelfConforms(reqd, "missing requirement", "required")
110110

111111
// Prevent wrong `extends` of java.lang.Enum
112112
if !migrateTo3 &&
113113
!cls.isOneOf(Enum | Trait) &&
114-
parents.exists(_.classSymbol == defn.JavaEnumClass)
114+
parents.exists(_.widen.classSymbol == defn.JavaEnumClass)
115115
then
116116
report.error(CannotExtendJavaEnum(cls), cls.sourcePos)
117117

@@ -656,7 +656,7 @@ object RefChecks {
656656
if (mbr.isTerm && !mbr.isOneOf(Synthetic | Bridge) && mbr.memberCanMatchInheritedSymbols &&
657657
!membersToCheck.contains(mbr.name))
658658
membersToCheck += mbr.name
659-
cls.info.parents.map(_.classSymbol)
659+
cls.info.parents.map(_.widen.classSymbol)
660660
.filter(_.isOneOf(AbstractOrTrait))
661661
.dropWhile(_.isOneOf(JavaDefined | Scala2x))
662662
.foreach(addDecls)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
214214
/** A path referencing the companion of class type `clsType` */
215215
private def companionPath(clsType: Type, span: Span)(using Context) =
216216
val ref = pathFor(clsType.companionRef)
217-
assert(ref.symbol.is(Module) && (clsType.classSymbol.is(ModuleClass) || (ref.symbol.companionClass == clsType.classSymbol)))
217+
assert(ref.symbol.is(Module) && (clsType.widen.classSymbol.is(ModuleClass) || (ref.symbol.companionClass == clsType.widen.classSymbol)))
218218
ref.withSpan(span)
219219

220220
private def checkFormal(formal: Type)(using Context): Boolean =
@@ -240,15 +240,15 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
240240
if mirroredType.termSymbol.is(CaseVal) then
241241
val module = mirroredType.termSymbol
242242
val modulePath = pathFor(mirroredType).withSpan(span)
243-
if module.info.classSymbol.is(Scala2x) then
243+
if module.info.widen.classSymbol.is(Scala2x) then
244244
val mirrorType = mirrorCore(defn.Mirror_SingletonProxyClass, mirroredType, mirroredType, module.name, formal)
245245
val mirrorRef = New(defn.Mirror_SingletonProxyClass.typeRef, modulePath :: Nil)
246246
mirrorRef.cast(mirrorType)
247247
else
248248
val mirrorType = mirrorCore(defn.Mirror_SingletonClass, mirroredType, mirroredType, module.name, formal)
249249
modulePath.cast(mirrorType)
250-
else if mirroredType.classSymbol.isGenericProduct then
251-
val cls = mirroredType.classSymbol
250+
else if mirroredType.widen.classSymbol.isGenericProduct then
251+
val cls = mirroredType.widen.classSymbol
252252
val accessors = cls.caseAccessors.filterNot(_.isAllOf(PrivateLocal))
253253
val elemLabels = accessors.map(acc => ConstantType(Constant(acc.name.toString)))
254254
val (monoType, elemsType) = mirroredType match
@@ -278,8 +278,8 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
278278
end productMirror
279279

280280
private def sumMirror(mirroredType: Type, formal: Type, span: Span)(using Context): Tree =
281-
if mirroredType.classSymbol.isGenericSum then
282-
val cls = mirroredType.classSymbol
281+
if mirroredType.widen.classSymbol.isGenericSum then
282+
val cls = mirroredType.widen.classSymbol
283283
val elemLabels = cls.children.map(c => ConstantType(Constant(c.name.toString)))
284284

285285
def solve(sym: Symbol): Type = sym match
@@ -365,7 +365,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
365365
formal.member(tpnme.MirroredType).info match
366366
case TypeBounds(mirroredType, _) =>
367367
if mirroredType.termSymbol.is(CaseVal)
368-
|| mirroredType.classSymbol.isGenericProduct
368+
|| mirroredType.widen.classSymbol.isGenericProduct
369369
then
370370
synthesizedProductMirror(formal, span)
371371
else

0 commit comments

Comments
 (0)