-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lambda in REPL (using object-wrappers) + concurrency = deadlock #9076
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9076?orig=1 |
@retronym said: object iw extends Object {
private[this] val res0: scala.runtime.BoxedUnit = _;
<stable> <accessor> def res0(): Unit = ();
final def apply$body$1(s: String): String = s.+(s);
def <init>(): type = {
iw.super.<init>();
iw.this.res0 = {
Test.test({
new <$anon: java.util.function.Function>()
});
scala.runtime.BoxedUnit.UNIT
};
()
}
};
@SerialVersionUID(value = 0) final class anonfun$1 extends Object with java.util.function.Function with Serializable {
final override <synthetic> def apply(s: String): String = $line3.iw.apply$body$1(s);
final override <synthetic> <bridge> <artifact> def apply(x$1: Object): Object = anonfun$1.this.apply(x$1.$asInstanceOf[String]());
def <init>(): <$anon: java.util.function.Function> = {
anonfun$1.super.<init>();
()
}
} The Indeed this terminates again under
|
@retronym said: scala> () => Test.test(s => s + s)
res0: () => Unit = <function0>
scala> res0()
Splitting from [0 5)
Could not split [0 3)
Could not split [3 5)
Trying at 3 [3, 5)
Trying at 0 [0, 3)
Trying at 1 [0, 3)
Trying at 4 [3, 5)
Trying at 2 [0, 3)
Trying at 5 [3, 5)
Trying at 3 [0, 3)
Optional[twotwo] |
@retronym said: /cc @som-snytt Do you think we could encode my workaround above into the object based wrappers to make the default REPL less prone to this problem? |
@som-snytt said: |
@SethTisue said: |
Dave Gurnell (davegurnell) said (edited on Mar 1, 2017 10:35:25 AM UTC): import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
// This works fine:
val x = Future(42)
Await.result(x, 1.second)
// This throws a TimeoutException:
Await.result(Future(42), 1.second) Adding The problem can also result in a [tut] compiling: /Users/dave/dev/projects/advanced-scala/src/pages/test.md
java.lang.NoClassDefFoundError: Could not initialize class $line4.$read$$iw$$iw$$iw$$iw$$iw$$iw$
at scala.runtime.java8.JFunction0$mcI$sp.apply(JFunction0$mcI$sp.java:12)
at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:653)
at scala.util.Success.$anonfun$map$1(Try.scala:251)
at scala.util.Success.map(Try.scala:209)
at scala.concurrent.Future.$anonfun$map$1(Future.scala:287)
... manually elided for brevity
[tut] *** Error reported at /Users/dave/dev/projects/advanced-scala/src/pages/monads/test.md:6
java.util.concurrent.TimeoutException: Futures timed out after [1 second]
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:255)
at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:259)
at scala.concurrent.Await$.$anonfun$result$1(package.scala:190)
at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53)
at scala.concurrent.Await$.result(package.scala:123)
... 88 elided
[error] (run-main-0) java.lang.Exception: Tut execution failed.
[trace] Stack trace suppressed: run last *:streams for the full output.
[trace] Stack trace suppressed: run last *:tutOnly for the full output.
[error] (*:tutOnly) Nonzero exit code: 1
[error] Total time: 5 s, completed 27-Feb-2017 09:38:19 |
Probably a wontfix in 2.12, but should consider this as we improve the repl in 2.13 (where we'll standardize on some form of class-based wrapping). |
should this still be on the 2.13.0-RC1 milestone, or shall we push it out to 2.13.x or 2.14? |
It's indeed fixed in Dotty: scala/scala-dev#195 :) |
Re-scheduling for 2.13 in the context of scala/scala-dev#325 and a commercial support request. First we should finish the jline 3 upgrade, but then let's look into improving the encoding. |
@retronym suggested a few alternative solutions -- one is to type check using the current object wrappers, and then have a repl phase that does the class-based encoding? This would avoid breaking anyone that relies on the current repl tree shapes during typer. Have to check how this affects serialization in Spark. |
The following code is a test of generating and using java.util.Spliterator to create a java.util.stream.Stream:
This compiles and runs successfully. However, when the contents of
main
are entered in the REPL, the last line hangs. Stack trace:Explicitly creating the SAM like so:
solves the issue. (Note: I have not tried this on 2.11.5; I assumed 2.12.x was up to date in anything relevant.)
The text was updated successfully, but these errors were encountered: