Skip to content

Commit 634c454

Browse files
committed
Use AbstractFunction as a base class to emit leaner code
Avoids mixing in all the specialized apply variants. We could go further and create an base class for all state machines, but that would require scala-async to be on the runtime classpath, which currently isn't a requirement. For now, I'm keeping it this way.
1 parent e28832d commit 634c454

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: src/main/scala/scala/async/internal/AsyncTransform.scala

+9-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ trait AsyncTransform {
4949
List(emptyConstructor, stateVar) ++ resultAndAccessors ++ List(execContextValDef) ++ List(applyDefDefDummyBody, apply0DefDef)
5050
}
5151

52-
val tryToUnit = appliedType(definitions.FunctionClass(1), futureSystemOps.tryType[Any], typeOf[Unit])
52+
val customParents = futureSystemOps.stateMachineClassParents
53+
val tycon = if (customParents.exists(!_.typeSymbol.asClass.isTrait)) {
54+
// prefer extending a class to reduce the class file size of the state machine.
55+
symbolOf[scala.runtime.AbstractFunction1[Any, Any]]
56+
} else {
57+
// ... unless a custom future system already extends some class
58+
symbolOf[scala.Function1[Any, Any]]
59+
}
60+
val tryToUnit = appliedType(tycon, futureSystemOps.tryType[Any], typeOf[Unit])
5361
val template = Template((futureSystemOps.stateMachineClassParents ::: List(tryToUnit, typeOf[() => Unit])).map(TypeTree(_)), emptyValDef, body)
5462

5563
val t = ClassDef(NoMods, name.stateMachineT, Nil, template)

0 commit comments

Comments
 (0)