-
-
Notifications
You must be signed in to change notification settings - Fork 417
Move the semanticdb generation logic to compile
and make sure it's shared where possible
#5841
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
Open
arturaz
wants to merge
19
commits into
com-lihaoyi:main
Choose a base branch
from
arturaz:fix/semanticdb-generation-on-compile
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Move the semanticdb generation logic to compile
and make sure it's shared where possible
#5841
arturaz
wants to merge
19
commits into
com-lihaoyi:main
from
arturaz:fix/semanticdb-generation-on-compile
+694
−423
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ration-on-compile # Conflicts: # libs/javalib/src/mill/javalib/SemanticDbJavaModule.scala # libs/javalib/src/mill/javalib/UnresolvedPath.scala
….com/arturaz/mill into fix/semanticdb-generation-on-compile
…ration-on-compile # Conflicts: # libs/daemon/server/src/mill/server/Server.scala # libs/javalib/src/mill/javalib/SemanticDbJavaModule.scala
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR optimizes and reworks the compilation pipeline, with regards to SemanticDB generation.
Pre-PR situation
compile
andsemanticDbDetailed
tasks.compile
performed the compilation without semantic DB plugin.semanticDbDetailed
performed the compilation with the semantic DB plugin, but did not reuse thecompile
's output.Which meant that if any of these happened:
compile
and thensemanticDbData
.compile
and then any other task that required the semantic db, or vice-versa.The compilation would have been performed twice, wasting CPU cycles and worsening the developer experience.
Post PR situation
Mill now smartly chooses whether
compile
produces semanticdb data or not. semanticdb is produced if:compile
was directly invoked by a task that needs semanticdb.Implementation details
Introduction of
MILL_BSP_OUTPUT_DIR
Previously you could use
MILL_OUTPUT_DIR
environment variable to set both regular and bsp mill's output directory to a certain folder.Because regular mill now needs to know the location of the BSP folder, having one variable is problematic:
MILL_OUTPUT_DIR=out_bsp ./mill --bsp ...
MILL_OUTPUT_DIR=out_bsp ./mill ...
changes the regular mill out folder.Thus
MILL_BSP_OUTPUT_DIR
is introduced, which allows you to:MILL_BSP_OUTPUT_DIR=out_bsp ./mill --bsp ...
MILL_BSP_OUTPUT_DIR=out_bsp ./mill ... # this still uses the regular out/ folder, but knows where bsp mill out/ folder is located
BuildCtx.bspSemanticDbSessionsFolder
Folder in the filesystem where Mill's BSP sessions that require semanticdb store an indicator file (name = process PID, contents are irrelevant) to communicate to main Mill daemon and other BSP sessions that there is at least one Mill session that will need the semanticdb.
The reasoning is that if at least one of Mill's clients requests semanticdb, then there is no point in running regular
compile
without semanticdb, as eventually we will have to rerun it with semanticdb, and thus we should compile with semanticdb upfront to avoid paying the price of compling twice (without semanticdb and then with it).CompilationResult.semanticDbFiles
Because we can't change the return type of
compile
due to binary compatibility,semanticDbFiles
field was added toCompilationResult
andcompile
fills it in if the compilation happened with semanticdb enabled.Removal of
CompileFor
and related tasksThese are not needed anymore with the single
compile
task.Removal of separate
SemanticDbJavaModule.semanticDbDataDetailed
taskIt's functionality was merged to
compileInternal
, which takes acompileSemanticDb
parameter.There also was a lot of code duplication between
compile
andsemanticDbDataDetailed
tasks, for both java and scala modules.Replace the implicit
Task.dest
usage inZincWorker
with explicitcompileTo
argumentThis makes it clearer what the parameter is used for and allows to reuse the same value in
SemanticDbJavaModule.enhanceCompilationResultWithSemanticDb
invocation.Misc changes
JavaModule#resolveRelativeToOut
instance method toUnresolvedPath.resolveRelativeToOut
.Server
to provide better debugging output if the server cannot be launched.testScala212Version
updated to2.12.20
because new semanticdb plugin is not provided for the ancient2.12.6
version that was used.Things to discuss
A side-effect of this PR is that now
compile
always depends onsemanticDbEnablePluginScalacOptions
:Which means that Mill's task planner will run it, even if
compileSemanticDb
is always false.Which then can result in errors like this:
Which can be surprising, as "I am just running
compile
, why is this searching for semanticdb?".Unfortunately, as
protected def semanticDbEnablePluginScalacOptions: T[Seq[String]]
is exposed in public binary API, we can't change the method signature toprotected def semanticDbEnablePluginScalacOptions: Task[() => Seq[String]]
so we could actually defer the running of the task.One option is to crawl https://repo1.maven.org/maven2/org/scalameta/ and build a baked-in map of Scala version to last supported
semanticdb-scalac
version and use that instead ofSemanticDbJavaModuleApi.buildTimeSemanticDbVersion
.Which also raises the question: why does default implementation of
semanticDbVersion
chooses built in semanticdb, even if user providesSEMANTICDB_VERSION
environment variable?Fixes: #5744