Skip to content

Commit f0d2719

Browse files
committed
Don't change parents in specializeFunctions
1 parent 87954f1 commit f0d2719

File tree

3 files changed

+20
-54
lines changed

3 files changed

+20
-54
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ object NameOps {
248248
/** This method is to be used on **type parameters** from a class, since
249249
* this method does sorting based on their names
250250
*/
251-
def specializedFor(classTargs: List[Types.Type], classTargsNames: List[Name], methodTargs: List[Types.Type], methodTarsNames: List[Name])(implicit ctx: Context): name.ThisName = {
251+
def specializedFor(classTargs: List[Types.Type], classTargsNames: List[Name], methodTargs: List[Types.Type], methodTarsNames: List[Name])(implicit ctx: Context): Name = {
252252
val methodTags: Seq[Name] = (methodTargs zip methodTarsNames).sortBy(_._2).map(x => typeToTag(x._1))
253253
val classTags: Seq[Name] = (classTargs zip classTargsNames).sortBy(_._2).map(x => typeToTag(x._1))
254254

@@ -263,7 +263,7 @@ object NameOps {
263263
*
264264
* `<return type><first type><second type><...>`
265265
*/
266-
def specializedFunction(ret: Types.Type, args: List[Types.Type])(implicit ctx: Context): name.ThisName =
266+
def specializedFunction(ret: Types.Type, args: List[Types.Type])(implicit ctx: Context): Name =
267267
name ++ nme.specializedTypeNames.prefix ++
268268
nme.specializedTypeNames.separator ++ typeToTag(ret) ++
269269
args.map(typeToTag).fold(nme.EMPTY)(_ ++ _) ++ nme.specializedTypeNames.suffix

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ object Names {
3838
abstract class Name extends Designator with PreName { self =>
3939

4040
/** A type for names of the same kind as this name */
41-
type ThisName <: Name { type ThisName = self.ThisName }
41+
type ThisName <: Name
4242

4343
/** Is this name a type name? */
4444
def isTypeName: Boolean

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

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -32,49 +32,39 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
3232
case tp: ClassInfo if !sym.is(Flags.Package) && (tp.decls ne EmptyScope) => {
3333
var newApplys = Map.empty[Name, Symbol]
3434

35-
val newParents = tp.parents.mapConserve { parent =>
36-
List(0, 1, 2, 3).flatMap { arity =>
35+
tp.parents.foreach { parent =>
36+
List(0, 1, 2, 3).foreach { arity =>
3737
val func = defn.FunctionClass(arity)
3838
if (!parent.derivesFrom(func)) Nil
3939
else {
4040
val typeParams = tp.cls.typeRef.baseType(func).argInfos
41-
val interface = specInterface(typeParams)
41+
val interface = specInterface(typeParams)
4242

4343
if (interface.exists) {
4444
if (tp.decls.lookup(nme.apply).exists) {
4545
val specializedMethodName = nme.apply.specializedFunction(typeParams.last, typeParams.init)
46-
newApplys = newApplys + (specializedMethodName -> interface)
46+
newApplys += (specializedMethodName -> interface)
4747
}
48-
49-
if (parent.isRef(func)) List(interface.typeRef)
50-
else Nil
5148
}
52-
else Nil
5349
}
5450
}
55-
.headOption
56-
.getOrElse(parent)
5751
}
5852

5953
def newDecls =
60-
if (newApplys.isEmpty) tp.decls
61-
else
62-
newApplys.toList.map { case (name, interface) =>
63-
ctx.newSymbol(
64-
sym,
65-
name,
66-
Flags.Override | Flags.Method,
67-
interface.info.decls.lookup(name).info
68-
)
69-
}
70-
.foldLeft(tp.decls.cloneScope) {
71-
(scope, sym) => scope.enter(sym); scope
72-
}
54+
newApplys.toList.map { case (name, interface) =>
55+
ctx.newSymbol(
56+
sym,
57+
name,
58+
Flags.Override | Flags.Method,
59+
interface.info.decls.lookup(name).info
60+
)
61+
}
62+
.foldLeft(tp.decls.cloneScope) {
63+
(scope, sym) => scope.enter(sym); scope
64+
}
7365

74-
tp.derivedClassInfo(
75-
classParents = newParents,
76-
decls = newDecls
77-
)
66+
if (newApplys.isEmpty) tp
67+
else tp.derivedClassInfo(decls = newDecls)
7868
}
7969

8070
case _ => tp
@@ -95,15 +85,6 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
9585
)
9686

9787
val specializedApply = tree.symbol.enclosingClass.info.decls.lookup(specName)//member(specName).symbol
98-
//val specializedApply = tree.symbol.enclosingClass.info.member(specName).symbol
99-
100-
if (false) {
101-
println(tree.symbol.enclosingClass.show)
102-
println("'" + specName.show + "'")
103-
println(specializedApply)
104-
println(specializedApply.exists)
105-
}
106-
10788

10889
if (specializedApply.exists) {
10990
val apply = specializedApply.asTerm
@@ -126,22 +107,7 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
126107
case x => x
127108
}
128109

129-
val missing: List[TypeTree] = List(0, 1, 2, 3).flatMap { arity =>
130-
val func = defn.FunctionClass(arity)
131-
val tr = tree.symbol.enclosingClass.typeRef
132-
133-
if (!tr.parents.exists(_.isRef(func))) Nil
134-
else {
135-
val typeParams = tr.baseType(func).argInfos
136-
val interface = specInterface(typeParams)
137-
138-
if (interface.exists) List(interface.info)
139-
else Nil
140-
}
141-
}.map(TypeTree _)
142-
143110
cpy.Template(tree)(
144-
parents = tree.parents ++ missing,
145111
body = applyBuf.toList ++ newBody
146112
)
147113
}

0 commit comments

Comments
 (0)