scala / slip

obsolete — archival use only
67 stars 15 forks source link

Add SLIP-22 Async converted from SIP 22 #18

Closed dickwall closed 8 years ago

dickwall commented 9 years ago

Decided to not wait for @retronym or @phaller to convert this across so I just went ahead. We can still run the same rails through the process otherwise, but it's time this was in the SLIP mechanism.

phaller commented 9 years ago

Thanks a lot, @dickwall!

SethTisue commented 8 years ago

I think it would be good if the SLIP addressed, at least briefly, the questions raised by Karl Heinrichmeyer on this thread: Why is scala.continuations discontinued and scala.async actively developed?

phaller commented 8 years ago

@SethTisue These questions have been raised before, and they have been discussed also on the mailing lists. I agree, though, that it would be good to add a summary to the SLIP document which addresses the main points.

I believe the three main points are:

First, the continuations plugin follows a type-based design, where types carry additional annotations. As a result, types and also error messages can become more complicated compared to Async which does not add type annotations.

Second, the annotated types introduced by the continuations plugin have to be propagated correctly by the annotation processor that is part of the plugin. However, annotation processing and propagation tends to be brittle in current Scala 2.x, in particular in connection with type inference which is required in the case of the continuations plugin. (@lrytz can probably share some additional experience with effect systems based on annotations.) In contrast, Async follows an approach that is purely syntactic. Types do not have to be annotated, and therefore, no annotation processing is required. This is a boon to robustness.

Third, the fact that Async does not do a standard CPS transform side-steps an issue with current Scala 2.x where closures sometimes hold on to more of their environment than strictly necessary. As a result, compilation using the continuations plugin can introduce memory leaks into programs that would not have memory leaks without the CPS transform. I believe this aspect alone is motivation enough for the alternative approach followed by Async (at least for Scala 2.x; a hypothetical new design of Async for Dotty might use a standard CPS transform instead, but this would not change the programming model anyway).

phaller commented 8 years ago

@retronym @SethTisue This is just a first comment, I'm probably missing other important points.

lrytz commented 8 years ago

The internals of propagating type annotations in the compiler that Philipp mentions are described in some more detail in Section 5.4 of my thesis: https://dl.dropboxusercontent.com/u/4881107/website/thesis-rytz.pdf