-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix undercompilation upon ctor change #19911
Conversation
**Problem** Scala 3 compiler registers special `zincMangledName` for constructors for the purpose of incremental compilation. Currently the `zincMangledName` contains the package name, which does not match the use site tracking, thereby causing undercompilation during incremental compilation after a ctor change, like adding a parameter. There is an existing scripted test, but coincidentally the test class does NOT include packages, so the test ends up passing. **Solution** This PR reproduces the issue by adding package name to the test. This also fixes the problem by changing the `zincMangedName` to `sym.owner.name ++ ";init;"`.
Hmm, but shouldn't the use-site tracking also go through zincMangledName? If it isn't right now, then can we avoid this discrepancy? sbt/zinc#288 also takes the package name into account so it seems like it should be possible in theory. |
Yes, you're right. As far as I can tell, the undercompilation bug does not exist in Scala 2.x, and adding a new parameter correctly fails to compile using the https://github.com/sake92/metals-mill-scala3-class-params-repro example on Scala 2.12.19: [info] compiling 1 Scala source to /private/tmp/metals-mill-scala3-class-params-repro/scalaHelloWorld/target/scala-2.12/classes ...
[error] /private/tmp/metals-mill-scala3-class-params-repro/scalaHelloWorld/src/main/scala/example/Hello.scala:5:17: not enough arguments for constructor MyService: (str: String, x: Int)example.MyService.
[error] Unspecified value parameter x.
[error] val service = new MyService("fssdfs")
[error] ^
[error] one error found
[error] (hello / Compile / compileIncremental) Compilation failed Also Scala 3 scala3/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala Lines 338 to 339 in a9bb881
so something about Scala 3 bridge is causing this. |
I did some extra testing and it seems the actual problem is the |
@bishabosha Feel free to take whatever from this PR and send a new one, or add commits to your liking on this PR. |
@sjrd I added a new name kind, kept it private to |
e44c89a
to
e12bc65
Compare
If the problem is the |
@@ -306,7 +306,7 @@ class ExtractUsedNamesSpecification { | |||
// All classes extend Object | |||
"Object", | |||
// All classes have a default constructor called <init> | |||
"java.lang.Object;init;", | |||
"java::lang::Object;init;", |
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.
It might be useful to use ;
as a separator like in sbt/zinc#288 so that builds involving both scala2 and scala3 projects have incremental compilation working correctly? (Which makes me wonder if sbt/zinc#288 is missing a change in the java api extractor)
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.
oh that's a good point seeing as dependency tracking is across modules
e12bc65
to
73ee8b4
Compare
@smarter @sjrd now I avoid the new name kind, and we use The main problem is that ExtractDependencies uses the name as a key in the cache, which is more efficient than converting names to string, so we would maybe need a new structure that can accommodate strings and names |
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.
Thanks everyone!
Instead of avoiding fully qualified names, use a different separator in zincMangledName.
73ee8b4
to
0f7de67
Compare
Thanks @bishabosha for getting this across the finish line! |
Backports #19911 to the LTS branch. PR submitted by the release tooling. [skip ci]
Fixes #19910
Fixes sbt/zinc#1334
Problem
Scala 3 compiler registers special
zincMangledName
for constructors for the purpose of incremental compilation. Currently thezincMangledName
contains the package name, which does not match the use site tracking,thereby causing undercompilation during incremental compilation after a ctor change, like adding a parameter.
There is an existing scripted test, but coincidentally the test class does NOT include packages, so the test ends up passing.
Solution
zincMangedName
tosym.owner.name ++ ";init;"
.Note about zincMangedName
zincMangedName
in general is a good idea, which adds the class name into otherwise common name<init>
.By making the name more unique it prevents overcompilation when one of the ctors changes in a file.