puniverse / quasar

Fibers, Channels and Actors for the JVM
http://docs.paralleluniverse.co/quasar/
Other
4.56k stars 574 forks source link

Problems with Kotlin lambda (minimal A/B) #257

Open fab1an opened 7 years ago

fab1an commented 7 years ago

Here are two examples of extensions in Kotlin. The first one works, the second one gives instrumentation warnings. For the first one I replaced FlatMappingReceivePort with an implementation that uses a lambda directly instead of the guava function.

/* works */
@Suspendable
fun <T, R> ReceivePort<T>.flatMapWorks(block: (T) -> ReceivePort<R>): ReceivePort<R> =
    FlatMappingReceivePort2(this, block)

/* instrumentation warning */
@Suspendable
fun <T, R> ReceivePort<T>.flatMapDoesntWork(block: (T) -> ReceivePort<R>): ReceivePort<R> =
    FlatMappingReceivePort(this,  Function<T, ReceivePort<R>> @Suspendable { block(it!!) })

Here is the generated byte-code for the solution that works:

screen shot 2017-03-22 at 08 12 34

Here is the one using the Function<...> @Suspenable {..} notation:

screen shot 2017-03-22 at 08 12 43

The second one instantiates an anonymous inner class flatMap$1. Since constructors can't be instrumented, this might be where the bug lies. The agent doesn't report any warnings though.

pron commented 7 years ago

Does this work with the new release (0.7.9)?