Skip to content

Commit 0e04ce0

Browse files
committed
Try micro-optimization for transformDefDef
1 parent 85d5ac6 commit 0e04ce0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,26 @@ class SpecializeFunctions extends MiniPhase {
2222
/** Create forwarders from the generic applys to the specialized ones.
2323
*/
2424
override def transformDefDef(ddef: DefDef)(using Context) = {
25-
val sym = ddef.symbol
26-
2725
if ddef.name != nme.apply
28-
|| sym.is(Flags.Deferred)
2926
|| ddef.vparamss.length != 1
3027
|| ddef.vparamss.head.length > 2
31-
|| !sym.owner.isClass
28+
|| !ctx.owner.isClass
3229
then
3330
return ddef
3431

35-
val cls = sym.owner.asClass
36-
val paramTypes = ddef.vparamss.head.map(_.symbol.info)
37-
val retType = sym.info.finalResultType
38-
val specName = nme.apply.specializedFunction(retType, paramTypes)
32+
val sym = ddef.symbol
33+
val cls = ctx.owner.asClass
34+
35+
var specName: Name = null
36+
37+
def isSpecializable = {
38+
val paramTypes = ddef.vparamss.head.map(_.symbol.info)
39+
val retType = sym.info.finalResultType
40+
specName = nme.apply.specializedFunction(retType, paramTypes)
41+
defn.isSpecializableFunction(cls, paramTypes, retType)
42+
}
3943

40-
val isSpecializable = defn.isSpecializableFunction(cls, paramTypes, retType)
41-
if (!isSpecializable || cls.info.decls.lookup(specName).exists) return ddef
44+
if (sym.is(Flags.Deferred) || !isSpecializable) return ddef
4245

4346
val specializedApply = newSymbol(
4447
cls,

0 commit comments

Comments
 (0)