-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[sbt-dotty] Use sbt loader as parent of scala instance loader #10541
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
d675162
to
101ebf8
Compare
The new However Mill won't work until we apply the same logic inside it: Mill should create a So, before merging this PR, I will have to:
@sjrd and @smarter: Do you confirm this is the right direction? |
As a side note, here is the code in Mill that create the |
If this works well enough, could this be done upstream in sbt for Scala 2 too so we don't need a special case just for Scala 3? |
Yes absolutely I test it first in |
OK, I'd be interested in hearing the opinion of the sbt maintainers on this direction. |
My plan is to use a filtered version of Right now I am testing this in Can you confirm that this is the right direction? |
I found a similar implementation in Mill that is looking better to me: In our case, I'll give a try. |
This approach sounds correct to me without thinking too much about it. It may be helpful to look at the code that constructs the sbt metabuild loader as well: https://github.com/sbt/sbt/blob/develop/main/src/main/java/sbt/internal/MetaBuildLoader.java. It shows how the sbt meta build classloader is constructed. You may end up wanting to make a change there as well. |
} | ||
|
||
private class FilteringClassLoader(parent: ClassLoader) extends ClassLoader(parent) { | ||
private val exludePackages = List( |
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.
Listing the packages to include rather than the packages to exclude like you did in the first commit seems safer to me (for example, you're not excluding "dotty." which could be loaded by a future version of sbt). However in that commit you had to include all the JDK prefixes ("java.", "sun.", ...). Perhaps this can be avoided by replicating what CompilerClassLoader did before this PR: use null
as a parent for FilteringClassLoader so super.loadClass
will delegate to the system JDK classloader, and call loadClass on the sbt loader explicitly when needed instead.
b45548e
to
3c52fa4
Compare
Related PR in Mill: com-lihaoyi/mill#1019 |
…L-18861 fixed In Scala 3.0.0-RC1 in sbt-bridge they moved to new compiler interface `xsbti.CompilerInterface2`. Before Scala 3.0.0-RC1 `xsbt.CompilerClassLoader` was used. It resolved `xsbti.*` classes (e.g. xsbti.AnalysisCallback) to the classes from the CompileServer classloader (more specifically, they were taken from `zincRepackaged` aka `incremental-compiler.jar`). `compiler-interface.jar` is also included into Scala 3 compiler classpath. But it was simply ignored, because the classes were already loaded by the parent classloader. After Scala 3.0.0-RC1 `sbt.internal.inc.classpath.DualLoader` is used. (see sbt.internal.inc.AnalyzingCompiler.compile, see also sbt.internal.inc.AnalyzingCompiler.createDualLoader) `parentA` loader represents the compiler classloader. Scala3 compiler uses `xsbti.*` classes directly so it so it's loader needs to resolve the those classes. And they should be resolved to the same classes used in the Compile Server. Before this commit, the classes were resolved to the `compiler-interface` jar file in the compile classpath itself. This caused the LinkageError. To avoid those we delegate all `xsbti.*` classes loading to the SCS classlader. Closely related links: - [`[sbt-bridge] Upgrade to CompilerInterface2`](scala/scala3@5185d4d) - [`[sbt-dotty] Use sbt loader as parent of scala instance loader #10541`](scala/scala3#10541)
This PR is an attempt to get rid of the
CompilerClassLoader
hack insbt-bridge
(see origin of the problem). The underlying purpose being to implement the new ZincCompilerInterface2
so that we can fix a few bugs insbt-dotty
and benefit from the recent Zinc improvement in Scala 3.In short the problem is that the
ScalaInstance.loader
is incompatible with thesbt
loader because it loads its ownxsbti.*
classes.This PR fix the problem by using the sbt
ClassLoader
as a parent of theScalaInstance.loader
. But we filter out all the classes that are not binary compatible with theScalaInstance
, among them thescala-library-2.12
andcompiler-bridge-2.12
classes.[test_sbt]