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
inlining fails under separate compilation in empty package #8580
Comments
Imported From: https://issues.scala-lang.org/browse/SI-8580?orig=1
|
@retronym said: |
@xeno-by said: package foo
final class Optional[A >: Null](val value: A) extends AnyVal {
def get: A = value
def isEmpty = value == null
@inline final def getOrElse[B >: A](alt: => B): B = if (isEmpty) alt else value
} package foo
class C
object Test {
def foo: Unit = {
val x = new Optional(null)
println(x.getOrElse(new C))
}
} 18:03 ~/Projects/211x/sandbox (2.11.x)$ scalac Macros.scala && scalac Test.scala && javap -v foo.Test$
...
public void foo();
flags: ACC_PUBLIC
Code:
stack=5, locals=2, args_size=1
0: aconst_null
1: astore_1
2: getstatic #18 // Field scala/Predef$.MODULE$:Lscala/Predef$;
5: getstatic #23 // Field foo/Optional$.MODULE$:Lfoo/Optional$;
8: aload_1
9: pop
10: aconst_null
11: new #25 // class foo/Test$$anonfun$foo$1
14: dup
15: invokespecial #26 // Method foo/Test$$anonfun$foo$1."<init>":()V
18: invokevirtual #30 // Method foo/Optional$.getOrElse$extension:(Ljava/lang/Object;Lscala/Function0;)Ljava/lang/Object;
21: invokevirtual #34 // Method scala/Predef$.println:(Ljava/lang/Object;)V
24: return
... |
@xeno-by said: public void foo();
flags: ACC_PUBLIC
Code:
stack=3, locals=3, args_size=1
0: getstatic #18 // Field scala/Predef$.MODULE$:Lscala/Predef$;
3: getstatic #23 // Field foo/Optional$.MODULE$:Lfoo/Optional$;
6: aconst_null
7: invokevirtual #27 // Method foo/Optional$.isEmpty$extension:(Ljava/lang/Object;)Z
10: ifne 17
13: aconst_null
14: goto 24
17: new #29 // class foo/C
20: dup
21: invokespecial #30 // Method foo/C."<init>":()V
24: astore_2
25: astore_1
26: getstatic #35 // Field scala/Console$.MODULE$:Lscala/Console$;
29: aload_2
30: invokevirtual #39 // Method scala/Console$.println:(Ljava/lang/Object;)V
33: return |
@retronym said:
|
Jim Kleckner (jkleckner) said: This non-stationary behavior makes bisecting infeasible and I burned a lot of time until I realized that the compiler wasn't invariant. Coupled with the inability to point to a file/line number, it is impractical to isolate a bit of code to demonstrate the problem. I notice the OP's error message likewise has no file/line info but the names are suggestive. Can we improve the error message at least? Suggestions? From sbt: > clean
[success] Total time: 0 s, completed Nov 25, 2014 5:41:56 AM
> compile
[info] Updating {file:/Users/jim/dev/tesla/}hawking...
[info] Updating {file:/Users/jim/dev/tesla/}rosen...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Updating {file:/Users/jim/dev/tesla/}main...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[warn] At the end of the day, could not inline @inline-marked method ->$extension
[warn] one warning found
[success] Total time: 19 s, completed Nov 25, 2014 5:42:19 AM
>
> sbtVersion
[info] rosen/*:sbtVersion
[info] 0.13.1
[info] hawking/*:sbtVersion
[info] 0.13.1
[info] main/*:sbtVersion
[info] 0.13.1
> scalaVersion
[info] rosen/*:scalaVersion
[info] 2.10.4
[info] hawking/*:scalaVersion
[info] 2.10.4
[info] main/*:scalaVersion
[info] 2.10.4
> |
@retronym said: That warning is almost certainly about the -> extension method used for tuple creation. See SI-6723 and the proposed fix, scala/scala#4041. The workaround is to use (a, b) instead of More generally, inline warnings aren't really something that you can always seek to reduce to zero. They are just a tool to help you understand why inlining isn't happening in certain places. |
Jim Kleckner (jkleckner) said: Your conjecture that #6723 may be the root cause is plausible since exceeding inline counts could explain why a "global compile" fails when an "incremental compile" succeeds. FYI, I tried using sbt 13.6 but that didn't put any line numbers into the warning output, not surprisingly. |
is still this relevant in 2.12, with the new inliner? |
works in 2.12 |
The text was updated successfully, but these errors were encountered: