-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix undercompilation when depending on inner class #9694
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
Conversation
5e9488e
to
bb2dee8
Compare
not sure what Is happening, [info] [info] Compiling 1 Scala source to /private/var/folders/m4/4dsrk6zn74v3zzpk34nj11mh0000gn/T/sbt_e6a419e4/inner-class/project/target/scala-2.12/sbt-1.0/classes ...
[info] [info] Done compiling.
[info] [info] loading settings for project inner-class from build.sbt ...
[info] [info] set current project to inner-class (in build file:/private/var/folders/m4/4dsrk6zn74v3zzpk34nj11mh0000gn/T/sbt_e6a419e4/inner-class/)
[info] [info] Compiling 2 Scala sources to /private/var/folders/m4/4dsrk6zn74v3zzpk34nj11mh0000gn/T/sbt_e6a419e4/inner-class/target/scala-0.28/classes ...
[info] [info] Done compiling.
[info] [info] running B
[info] 1
[info] [success] Total time: 3 s, completed Sep 2, 2020 2:32:47 PM
[info] [info] Compiling 1 Scala source to /private/var/folders/m4/4dsrk6zn74v3zzpk34nj11mh0000gn/T/sbt_e6a419e4/inner-class/target/scala-0.28/classes ...
[info] [info] Done compiling.
[info] [success] Total time: 0 s, completed Sep 2, 2020 2:32:47 PM
[info] [info] Compiling 1 Scala source to /private/var/folders/m4/4dsrk6zn74v3zzpk34nj11mh0000gn/T/sbt_e6a419e4/inner-class/target/scala-0.28/classes ...
[info] [info] Done compiling.
[info] [info] running B
[info] [error] (run-main-1) java.lang.NoSuchMethodError: A$InnerClass.foo()I
[info] [error] java.lang.NoSuchMethodError: A$InnerClass.foo()I
[info] [error] at B$.main(B.scala:4)
[info] [error] at B.main(B.scala)
[info] [error] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[info] [error] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[info] [error] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[info] [error] at java.lang.reflect.Method.invoke(Method.java:498)
[info] [error] stack trace is suppressed; run 'last Compile / bgRun' for the full output
[info] [error] Nonzero exit code: 1
[info] [error] (Compile / run) Nonzero exit code: 1
[info] [error] Total time: 0 s, completed Sep 2, 2020 2:32:47 PM |
bb2dee8
to
1d29924
Compare
Oops, I broke it before pushing it, should be good now. |
Ping for review. |
when i run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like static members of java classes are computed with a $
suffix on the binary class name
1d29924
to
fe1781a
Compare
seems a lot of PRs have hanging workflows |
There's only one Windows CI runner currently, so windows jobs spend a long time in the queue. |
0252e4b
to
fe1781a
Compare
... or maybe the windows CI runner is not running currently? looking at https://github.com/lampepfl/dotty/actions I can't find any job where it's running right now /cc @liufengyun |
I'll try to add a new runner on the same machine and see if we get some speedup. Otherwise, we can either (1) run Windows CI only on master merged; or (2) add more physical machines. |
To communicate to sbt a dependency between a class currently being compiled and some other class on the classpath, we use the `binaryDependency` callback which requires passing the "binary class name": for a class A in a package pkg, this is just "pkg.A", but for an inner class B in A, that would be "pkg.A$B", in other words the last component of the binary class name is the name of the corresponding classfile. Before this commit, we computed this name by extracting it from the path of the `associatedFile` but it turns out that `associatedFile` for an inner Scala class returns the classfile of the corresponding top-level class! This happens because the compiler never actually reads inner Scala classfiles since all the information is present in the top-level .class and .tasty files. This means that under separate compilation a dependency to an inner class was not recorded which could lead to undercompilation (see added tests). This commit fixes this by computing binary class names manually: they're just made of the fullName of the enclosing package, followed by ".", followed by the flatName of the current class. This is similar to what is done in the Scala 2 compiler bridge in Zinc.
fe1781a
to
0e350d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me
To communicate to sbt a dependency between a class currently being
compiled and some other class on the classpath, we use the
binaryDependency
callback which requires passing the "binary classname": for a class A in a package pkg, this is just "pkg.A", but for an
inner class B in A, that would be "pkg.A$B", in other words the last
component of the binary class name is the name of the corresponding
classfile.
Before this commit, we computed this name by extracting it from the path
of the
associatedFile
but it turns out thatassociatedFile
for aninner Scala class returns the classfile of the corresponding top-level
class! This happens because the compiler never actually reads inner
Scala classfiles since all the information is present in the top-level
.class and .tasty files. This means that under separate compilation a
dependency to an inner class was not recorded which could lead to
undercompilation (see added tests).
This commit fixes this by computing binary class names manually: they're
just made of the fullName of the enclosing package, followed by ".",
followed by the flatName of the current class. This is similar to what
is done in the Scala 2 compiler bridge in Zinc.