Skip to content

Commit 671c0a9

Browse files
committed
Cleanup
1 parent 2808cbe commit 671c0a9

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object Names {
3535
* in a name table. A derived term name adds a tag, and possibly a number
3636
* or a further simple name to some other name.
3737
*/
38-
abstract class Name extends Designator with PreName { self =>
38+
abstract class Name extends Designator with PreName {
3939

4040
/** A type for names of the same kind as this name */
4141
type ThisName <: Name

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

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,23 @@ import scala.collection.mutable
1414
class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
1515
import ast.tpd._
1616
val phaseName = "specializeFunctions"
17+
override def runsAfter = Set(classOf[ElimByName])
1718

18-
/** Transforms the type to include decls for specialized applys and replace
19-
* the class parents with specialized versions.
20-
*/
19+
/** Transforms the type to include decls for specialized applys */
2120
def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context) = tp match {
22-
case tp: ClassInfo if !sym.is(Flags.Package) && (tp.decls ne EmptyScope) => {
21+
case tp: ClassInfo if !sym.is(Flags.Package) && (tp.decls ne EmptyScope) =>
2322
var newApplys = Map.empty[Name, Symbol]
2423

2524
tp.parents.foreach { parent =>
2625
List(0, 1, 2, 3).foreach { arity =>
2726
val func = defn.FunctionClass(arity)
28-
if (!parent.derivesFrom(func)) Nil
29-
else {
27+
if (parent.derivesFrom(func)) {
3028
val typeParams = tp.cls.typeRef.baseType(func).argInfos
3129
val interface = specInterface(typeParams)
3230

33-
if (interface.exists) {
34-
if (tp.decls.lookup(nme.apply).exists) {
35-
val specializedMethodName = nme.apply.specializedFunction(typeParams.last, typeParams.init)
36-
newApplys += (specializedMethodName -> interface)
37-
}
31+
if (interface.exists && tp.decls.lookup(nme.apply).exists) {
32+
val specializedMethodName = nme.apply.specializedFunction(typeParams.last, typeParams.init)
33+
newApplys += (specializedMethodName -> interface)
3834
}
3935
}
4036
}
@@ -45,7 +41,7 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
4541
ctx.newSymbol(
4642
sym,
4743
name,
48-
Flags.Override | Flags.Method,
44+
Flags.Override | Flags.Method | Flags.Synthetic,
4945
interface.info.decls.lookup(name).info
5046
)
5147
}
@@ -55,20 +51,18 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
5551

5652
if (newApplys.isEmpty) tp
5753
else tp.derivedClassInfo(decls = newDecls)
58-
}
5954

6055
case _ => tp
6156
}
6257

6358
/** Transforms the `Template` of the classes to contain forwarders from the
64-
* generic applys to the specialized ones. Also replaces parents of the
65-
* class on the tree level and inserts the specialized applys in the
66-
* template body.
59+
* generic applys to the specialized ones. Also inserts the specialized applys
60+
* in the template body.
6761
*/
6862
override def transformTemplate(tree: Template)(implicit ctx: Context, info: TransformerInfo) = {
6963
val applyBuf = new mutable.ListBuffer[Tree]
7064
val newBody = tree.body.mapConserve {
71-
case dt: DefDef if dt.name == nme.apply && dt.vparamss.length == 1 => {
65+
case dt: DefDef if dt.name == nme.apply && dt.vparamss.length == 1 =>
7266
val specName = nme.apply.specializedFunction(
7367
dt.tpe.widen.finalResultType,
7468
dt.vparamss.head.map(_.symbol.info)
@@ -93,7 +87,7 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
9387
.appliedToArgs(dt.vparamss.head.map(vparam => ref(vparam.symbol)))
9488
})
9589
} else dt
96-
}
90+
9791
case x => x
9892
}
9993

@@ -105,31 +99,30 @@ class SpecializeFunctions extends MiniPhaseTransform with InfoTransformer {
10599
/** Dispatch to specialized `apply`s in user code when available */
106100
override def transformApply(tree: Apply)(implicit ctx: Context, info: TransformerInfo) =
107101
tree match {
108-
case app @ Apply(fun, args)
102+
case Apply(fun, args)
109103
if fun.symbol.name == nme.apply &&
110104
fun.symbol.owner.derivesFrom(defn.FunctionClass(args.length))
111-
=> {
105+
=>
112106
val params = (fun.tpe.widen.firstParamTypes :+ tree.tpe).map(_.widenSingleton.dealias)
113107
val specializedApply = specializedName(nme.apply, params)
114108

115109
if (!params.exists(_.isInstanceOf[ExprType]) && fun.symbol.owner.info.decls.lookup(specializedApply).exists) {
116110
val newSel = fun match {
117111
case Select(qual, _) =>
118112
qual.select(specializedApply)
119-
case _ => {
113+
case _ =>
120114
(fun.tpe: @unchecked) match {
121115
case TermRef(prefix: ThisType, name) =>
122116
tpd.This(prefix.cls).select(specializedApply)
123117
case TermRef(prefix: NamedType, name) =>
124118
tpd.ref(prefix).select(specializedApply)
125119
}
126-
}
127120
}
128121

129122
newSel.appliedToArgs(args)
130123
}
131124
else tree
132-
}
125+
133126
case _ => tree
134127
}
135128

tests/run/t2857.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ object Test extends dotty.runtime.LegacyApp {
55
m.removeBinding(6, "Foo")
66
println(m.contains(6))
77
}
8+
9+

0 commit comments

Comments
 (0)