Skip to content
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

Use original Evaluators to preserve their association with modules in BSP to avoid using the wrong evaluator #2692

Merged
merged 15 commits into from Aug 15, 2023

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented Aug 14, 2023

Should fix #2643.

The basic problem is previously BSP always used the frame(0) evaluator passed in to updateEvaluator, which is meant specifically for evaluating user tasks in the root ./build.sc. However, BSP also querying of modules and tasks both in build.sc as well as meta-builds in mill-build/build.sc and nested meta-builds. This ends up evaluating the meta-builds in the same out/ folder as the main build, rather than in the out/mill-build/ folders they should be evaluated in.

This PR avoids using the Evaluator given in updateEvaluator, and instead preserves the Evaluators we already construct as part of MillBuildBootstrap in mill.bsp.worker.State, and passes them as a Seq[Evaluator] from the enclosing MillBuildBootstrap code all the way to the Mill-BSP code so we can associate each Module with its respective Ealuator. We then use those associated Evaluators to perform the actual evaluation throughout the Mill{Scala,Java,Jvm,}BuildServer implementations. There's some additional re-shaping, so that in case a single BSP API call wants to query modules/tasks from multiple evaluators at once we properly group the tasks/modules together according to their respective evaluators for evaluation.

By passing the Seq[Evaluator] from the enclosing MillBuildBootstrap, this also lets us remove the now-redundant call to MillBuildBootstrap buried within State.scala. We already have all the necessary data structures from the enclosing MillBuildBootstrap and its evaluators, so we don't need to re-run the bootstrap process and re-construct all of it from scratch just for BSP

I haven't managed to reproduce the original error, so confirming the fix will have to wait until this lands in master and people can try it out. But I have manually tested using VSCode to load and jump around example/basic/1-simple-scala/ and example/scalabuilds/10-scala-realistic/, and it seems all the references and modules work and are set up correctly. So at least we have some confidence that this doesn't cause any regressions.

This should also supersede #2648, since we now no longer need to re-run the MillBuildBootstrap/RootModuleFinder logic at all since we just take the existing list of Evaluators from the enclosing bootstrap process

@lihaoyi lihaoyi requested a review from lefou August 14, 2023 03:10
@lihaoyi lihaoyi changed the title Preserve the association between modules and evaluators in BSP to avoid sometimes using the wrong evaluator Use original Evaluators to preserve their association with modules in BSP to avoid using the wrong evaluator Aug 14, 2023
Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

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

This looks good to me. I added some small nits.

disableCallgraphInvalidation = disableCallgraphInvalidation,
needBuildSc = true
).evaluate()
lazy val rootModules = evaluators.map(_.rootModule)
Copy link
Member

Choose a reason for hiding this comment

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

Type needed

main/eval/src/mill/eval/Evaluator.scala Outdated Show resolved Hide resolved
runner/src/mill/runner/RunnerState.scala Outdated Show resolved Hide resolved
Comment on lines 45 to 47
implicit def millAllEvaluatorsTokenReader[T]: mainargs.TokensReader[Seq[Evaluator]] =
new mill.main.AllEvaluatorsTokenReader[T]()

Copy link
Member

Choose a reason for hiding this comment

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

Using a Seq[Evaluator] to express the wish to get all evaluators is a bit vague. A Seq can hold almost everything, also nothing. Should we introduce a dedicated type to hold all evaluators instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I'll wrap it in Evaluator.AllBootstrapEvaluators(value: Seq[Evaluator])

@lihaoyi lihaoyi merged commit ead8bb4 into com-lihaoyi:main Aug 15, 2023
37 checks passed
@lefou lefou added this to the 0.11.2 milestone Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CompletionException in BSP server for buildTarget/jvmRunEnvironment request
2 participants