diff options
Diffstat (limited to 'src/main/scala/scala/async/internal/AsyncTransform.scala')
-rw-r--r-- | src/main/scala/scala/async/internal/AsyncTransform.scala | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/main/scala/scala/async/internal/AsyncTransform.scala b/src/main/scala/scala/async/internal/AsyncTransform.scala index af290e4..feb1ea7 100644 --- a/src/main/scala/scala/async/internal/AsyncTransform.scala +++ b/src/main/scala/scala/async/internal/AsyncTransform.scala @@ -26,6 +26,9 @@ trait AsyncTransform { val anfTree = futureSystemOps.postAnfTransform(anfTree0) + cleanupContainsAwaitAttachments(anfTree) + containsAwait = containsAwaitCached(anfTree) + val applyDefDefDummyBody: DefDef = { val applyVParamss = List(List(ValDef(Modifiers(Flag.PARAM), name.tr, TypeTree(futureSystemOps.tryType[Any]), EmptyTree))) DefDef(NoMods, name.apply, Nil, applyVParamss, TypeTree(definitions.UnitTpe), literalUnit) @@ -46,8 +49,16 @@ trait AsyncTransform { List(emptyConstructor, stateVar) ++ resultAndAccessors ++ List(execContextValDef) ++ List(applyDefDefDummyBody, apply0DefDef) } - val tryToUnit = appliedType(definitions.FunctionClass(1), futureSystemOps.tryType[Any], typeOf[Unit]) - val template = Template(List(tryToUnit, typeOf[() => Unit]).map(TypeTree(_)), emptyValDef, body) + val customParents = futureSystemOps.stateMachineClassParents + val tycon = if (customParents.exists(!_.typeSymbol.asClass.isTrait)) { + // prefer extending a class to reduce the class file size of the state machine. + symbolOf[scala.runtime.AbstractFunction1[Any, Any]] + } else { + // ... unless a custom future system already extends some class + symbolOf[scala.Function1[Any, Any]] + } + val tryToUnit = appliedType(tycon, futureSystemOps.tryType[Any], typeOf[Unit]) + val template = Template((futureSystemOps.stateMachineClassParents ::: List(tryToUnit, typeOf[() => Unit])).map(TypeTree(_)), emptyValDef, body) val t = ClassDef(NoMods, name.stateMachineT, Nil, template) typecheckClassDef(t) @@ -148,10 +159,13 @@ trait AsyncTransform { case ValDef(_, _, _, rhs) if liftedSyms(tree.symbol) => api.atOwner(api.currentOwner) { val fieldSym = tree.symbol - val lhs = atPos(tree.pos) { - gen.mkAttributedStableRef(thisType(fieldSym.owner.asClass), fieldSym) + if (fieldSym.asTerm.isLazy) Literal(Constant(())) + else { + val lhs = atPos(tree.pos) { + gen.mkAttributedStableRef(thisType(fieldSym.owner.asClass), fieldSym) + } + treeCopy.Assign(tree, lhs, api.recur(rhs)).setType(definitions.UnitTpe).changeOwner(fieldSym, api.currentOwner) } - treeCopy.Assign(tree, lhs, api.recur(rhs)).setType(definitions.UnitTpe).changeOwner(fieldSym, api.currentOwner) } case _: DefTree if liftedSyms(tree.symbol) => EmptyTree @@ -165,7 +179,7 @@ trait AsyncTransform { } val liftablesUseFields = liftables.map { - case vd: ValDef => vd + case vd: ValDef if !vd.symbol.asTerm.isLazy => vd case x => typingTransform(x, stateMachineClass)(useFields) } |