Skip to content

Conversation

@adriaanm
Copy link
Contributor

@adriaanm adriaanm commented Nov 6, 2017

The scala library (core and reflect) now depends only on the compact1 profile.

jdeps -s -profile /Users/adriaan/.ivy2/local/org.scala-lang/scala-{library,reflect}/2.13.0-bin-local-07ff7ac/jars/scala-*.jar                                                                                                               
scala-library.jar -> java.base (compact1)
scala-reflect.jar -> java.base (compact1)
scala-reflect.jar -> /Users/adriaan/.ivy2/local/org.scala-lang/scala-library/2.13.0-bin-local-07ff7ac/jars/scala-library.jar

See scala/bug#10559

@scala-jenkins scala-jenkins added this to the 2.13.0-M3 milestone Nov 6, 2017
@adriaanm adriaanm force-pushed the modularize-drop-remote branch from 6047d9b to e8d03d9 Compare November 6, 2017 22:36
The `@remote` annotation will be removed in 2.13.
It was deprecated in 2.12, and will be gone entirely in 2.13.0-M4,
but first we must release a milestone that no longer refers to it
(so that the compiler can bootstrap without a definition for `@remote`).

This cuts tie 1 of 3 to the Java profiles beyond compact1.
The `BeanInfo` generation was deprecated in 2.12 and will be removed in 2.13.
First, we cut ties from the compiler in M3, so that we can remove the
classes `scala.beans.{BeanInfo, ScalaBeanInfo}` entirely in M4, along with
`scala.beans.{BeanInfoSkip, BeanDescription, BeanDisplayName}`, which
were part of the deprecated feature. (Note: for good measure, we should
deprecate all of them in 2.12.5, instead of just the entry point).

This cuts tie 2 of 3 to the Java profiles beyond compact1.
scala-{library,reflect} now depend only on the compact1 profile.
@adriaanm adriaanm changed the title Remove compiler dependency on @remote Restrict library and reflect to compact1 profile Nov 6, 2017
@adriaanm adriaanm force-pushed the modularize-drop-remote branch from e8d03d9 to 07ff7ac Compare November 6, 2017 23:43
@adriaanm adriaanm requested a review from lrytz November 6, 2017 23:43
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @nilskp for the removal of BeanInfo, since you recently voiced your interest in that feature (https://users.scala-lang.org/t/beaninfo-alternative/1301). I guess the same functionality could be implemented with a compiler plugin.

@adriaanm how did you identify implementations that use classes outside the compact1 profile? How can we prevent new references from sneaking in?

def javaVmArguments: List[String] = {
import scala.collection.JavaConverters._

java.lang.management.ManagementFactory.getRuntimeMXBean.getInputArguments.asScala.toList
Copy link
Member

@lrytz lrytz Nov 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this method is not deprecated in 2.12, we could do a reflective implementation

scala> import scala.collection.JavaConverters._
import scala.collection.JavaConverters._

scala> val mxb = Class.forName("java.lang.management.ManagementFactory").getMethod("getRuntimeMXBean").invoke(null)
mxb: Object = sun.management.RuntimeImpl@4447c594

scala> Class.forName("java.lang.management.RuntimeMXBean").getMethod("getInputArguments").invoke(mxb).asInstanceOf[java.util.List[String]].asScala.toList
res19: List[String] = List(-Xmx1536m, -Xms1536m, -Xss5m, -XX:+UseCompressedOops, -XX:+UseParallelGC, -Xbootclasspath/a:/Users/luc/scala/scala-2.12.3/lib/jline-2.14.4.jar:/Users/luc/scala/scala-2.12.3/lib/scala-compiler.jar:/Users/luc/scala/scala-2.12.3/lib/scala-library.jar:/Users/luc/scala/scala-2.12.3/lib/scala-parser-combinators_2.12-1.0.6.jar:/Users/luc/scala/scala-2.12.3/lib/scala-reflect.jar:/Users/luc/scala/scala-2.12.3/lib/scala-swing_2.12-2.0.0.jar:/Users/luc/scala/scala-2.12.3/lib/scala-xml_2.12-1.0.6.jar:/Users/luc/scala/scala-2.12.3/lib/scalap-2.12.3.jar, -Dscala.boot.class.path=/Users/luc/scala/scala-2.12.3/lib/jline-2.14.4.jar:/Users/luc/scala/scala-2.12.3/lib/scala-compiler.jar:/Users/luc/scala/scala-2.12.3/lib/scala-library.jar:/Users/luc/scala/...

This would fail with java.lang.ClassNotFoundException if the classes are not available, which is probably comparable to what currently happens.

We can deprecate the method at the same time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you're deprecating it for 2.12.5; I guess either way is fine.

@lrytz
Copy link
Member

lrytz commented Nov 10, 2017

Ah, jdeps!

@dwijnand
Copy link
Member

How can we prevent new references from sneaking in?

👍 jdeps should be used to enforce nothing sneaks in (I don't mean necessarily in this PR).

@adriaanm
Copy link
Contributor Author

adriaanm commented Nov 13, 2017

I can't figure out how to add a test to our build that checks that jdeps -s -P build/pack/lib/scala-{library,reflect}.jar | grep -v build/pack | perl -pe 's/.*\((.*)\)$/$1/' | sort | uniq outputs (only) compact1. @szeiger, could you take a stab at that please?

So far, I have something like:

lazy val jdeps = taskKey[Unit]("Run jdeps to check dependencies")
lazy val restrictDeps = project
  .dependsOn(library, reflect)
  .settings(commonSettings)
  .settings(disableDocs)
  .settings(disablePublishing)
  .settings(
    Keys.test in Test := (Keys.test in Test).dependsOn(jdeps).value,
    jdeps := {
      import Process._
      val profilePart = ".*\\((.*)\\)$".r
      val jdepsOut = s"jdeps -s -P ${(packageBin in library in Compile).value.getPath} ${(packageBin in reflect in Compile).value.getPath}".lines_!
      val profiles = jdepsOut.flatMap(line => line.split(" -> ", 2) match { case Array(_, profilePart(profile)) => Some(profile) case s => None }).toSet
      if (profiles != Set("compact1")) streams.value.log.error("Detected dependency outside of compact1:\n"+jdepsOut.mkString("\n")) // TODO how to report error?
    }
  )

Not sure how to run this as a test and report the error

@dwijnand
Copy link
Member

Task failure is reported by throwing an exception.

@szeiger
Copy link
Contributor

szeiger commented Nov 14, 2017

I suggest the following:

    jdeps := {
      val profilePart = ".*\\((.*)\\)$".r
      val jdepsOut = Process("jdeps", Seq("-s", "-P", (packageBin in library in Compile).value.getPath, (packageBin in reflect in Compile).value.getPath)).lines_!
      val profiles = jdepsOut.flatMap(line => line.split(" -> ", 2) match { case Array(_, profilePart(profile)) => Some(profile) case s => None }).toSet
      if (profiles != Set("compact1"))
        throw new RuntimeException("Detected dependency outside of compact1:\n"+jdepsOut.mkString("\n"))
    },

Errors are reported as Exceptions. I've also changed the Process call to avoid command line parsing. The other version would fail with spaces in the base directory. IMHO this is bad API design in sbt: doing the wrong thing is easier than doing the right thing.

I don't see any reason for the special restrictDeps project. I simply put it into root for testing. I'd rather call this kind of "extra" test from testAll instead of running it with the standard test command.

@dwijnand Does sbt have any code for localizing javac that could be co-opted for jdeps or do you simply call whatever javac is on the path?

@dwijnand
Copy link
Member

By default it uses what it finds on the PATH, with support for a custom javaHome setting. But I wouldn't bother getting fancy until you need it.

smarter added a commit to dotty-staging/scala that referenced this pull request Dec 7, 2017
This mirror similar changes done by Adriaan Moors in
scala#6164
smarter added a commit to dotty-staging/scala that referenced this pull request Dec 7, 2017
This was already partially done in
31f9681. This mirror similar changes
done by Adriaan Moors in scala#6164
smarter added a commit to dotty-staging/dotty that referenced this pull request Dec 7, 2017
As verify by running `jdep -s -P` on the dotty-compiler jar. See
scala/bug#10559 for why this is useful and
scala/scala#6164 for how this was implemented in
scalac.
smarter added a commit to dotty-staging/dotty that referenced this pull request Dec 7, 2017
As verify by running `jdep -s -P` on the dotty-compiler jar. See
scala/bug#10559 for why this is useful and
scala/scala#6164 for how this was implemented in
scalac.
smarter added a commit to dotty-staging/dotty that referenced this pull request Dec 7, 2017
As verify by running `jdep -s -P` on the dotty-compiler jar. See
scala/bug#10559 for why this is useful and
scala/scala#6164 for how this was implemented in
scalac.
vitorsvieira pushed a commit to vitorsvieira/dotty that referenced this pull request Dec 11, 2017
As verify by running `jdep -s -P` on the dotty-compiler jar. See
scala/bug#10559 for why this is useful and
scala/scala#6164 for how this was implemented in
scalac.
@adriaanm
Copy link
Contributor Author

I won't have time to implement the test for this. Tracking as scala/scala-dev#460

@adriaanm adriaanm merged commit 2f3791c into scala:2.13.x Dec 13, 2017
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Dec 13, 2017
dwijnand added a commit to dwijnand/scala-partest that referenced this pull request Dec 14, 2017
See scala/scala#6164
Ref scala/scala-dev#461 (still need to release partest & upgrade)
lrytz pushed a commit to lrytz/scala-partest that referenced this pull request May 9, 2018
See scala/scala#6164
Ref scala/scala-dev#461 (still need to release partest & upgrade)
lrytz pushed a commit to lrytz/scala-partest that referenced this pull request May 9, 2018
See scala/scala#6164
Ref scala/scala-dev#461 (still need to release partest & upgrade)
lrytz pushed a commit to lrytz/scala that referenced this pull request May 9, 2018
See scala#6164
Ref scala/scala-dev#461 (still need to release partest & upgrade)
lrytz pushed a commit to lrytz/scala that referenced this pull request May 9, 2018
See scala#6164
Ref scala/scala-dev#461 (still need to release partest & upgrade)
dwijnand added a commit to dwijnand/scala that referenced this pull request Jun 14, 2018
Enforcement of scala#6164

Tested manually by reverting the sys.process.javaVmArguments change
07ff7ac and then running testJDepsImpl:

    > testJDeps
    [info] Compiling 1 Scala source to /d/scala/build/quick/classes/library...
    [info] Packaging /d/scala/build/pack/lib/scala-library.jar ...
    [info] Packaging /d/scala/build/pack/lib/scala-reflect.jar ...
    [info] Done packaging.
    [info] Done packaging.
    [trace] Stack trace suppressed: run last root/*:testJDeps for the full output.
    [error] (root/*:testJDeps) Detected dependency outside of compact1:
    [error] scala-library.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/rt.jar (compact3)
    [error] scala-reflect.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/rt.jar (compact1)
    [error] scala-reflect.jar -> /d/scala/build/pack/lib/scala-library.jar
    [error] Total time: 4 s, completed 14-Jun-2018 14:20:02

Fixes scala/scala-dev#437
Fixes scala/bug#10559
dwijnand added a commit to dwijnand/scala that referenced this pull request Jun 14, 2018
Enforcement of scala#6164

Tested manually by reverting the sys.process.javaVmArguments change
07ff7ac and then running testJDepsImpl:

    > testJDeps
    [info] Compiling 1 Scala source to /d/scala/build/quick/classes/library...
    [info] Packaging /d/scala/build/pack/lib/scala-library.jar ...
    [info] Packaging /d/scala/build/pack/lib/scala-reflect.jar ...
    [info] Done packaging.
    [info] Done packaging.
    [trace] Stack trace suppressed: run last root/*:testJDeps for the full output.
    [error] (root/*:testJDeps) Detected dependency outside of compact1:
    [error] scala-library.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/rt.jar (compact3)
    [error] scala-reflect.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/rt.jar (compact1)
    [error] scala-reflect.jar -> /d/scala/build/pack/lib/scala-library.jar
    [error] Total time: 4 s, completed 14-Jun-2018 14:20:02

Fixes scala/scala-dev#437
Fixes scala/bug#10559
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes worth highlighting in next release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants