-
Notifications
You must be signed in to change notification settings - Fork 121
[WIP] POC - Decouple dependency phase #509
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
… use it. e.g. bazelbuild/rules_scala strict_deps feature. issues: 1. LocalToNonLocalClass cache should somehow still be shared with other phases. 2. CallbackGlobal can not be part of the dependency analysis phase as it is zinc-specific. 3. callback interface can probalby still be used, but should be split to only declare dependency related methods
Hi @natansil, Thank you for your contribution! We really value the time you've taken to put this together. Before we proceed with reviewing this pull request, please sign the Lightbend Contributors License Agreement: |
also, please note that I've managed to successfully use the dependency analysis logic in |
I think decoupling callbacks for the Dependency phase makes sense. What's your long-term idea to use that code from zinc? Depend on a zinc jar and use the |
phase.id <= sbtDependency.ownPhase.id, | ||
s"Tried to resolve ${s.fullName} to a non local classes but the resolution works up to sbtDependency phase. We're at ${phase.name}" | ||
) | ||
// assert( |
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.
I suspect we need to be creative here, instead of commenting this code.
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.
absolutely.
Seems like one solution can be to split LocalToNonLocalClass
to CallbackLocalToNonLocalClass
which handles the zinc-specific logic (and knows of CallbackGlobal
) and InternalLocalToNonLocalClass
which handles the caching logic (and only knows of Global
). CallbackLocalToNonLocalClass
can be a wrapper for InternalLocalToNonLocalClass
.
of-course maybe other refactoring options for the shared cache issues can be more elegant...
What is the exact use case for this decoupling? I'm interested to hear more about how you plan on improving support for strict dependencies. |
@gkossakowski, for Regarding higher-level apis, I'm not sure what you mean. In this PR, iv'e tried to split the actual dependency analysis logic from the Plugin boiler-plate, but the way |
@jvican regarding support for strict deps in
The rules_scala plugin also receives information on the jars from Bazel - for this unit ( We would like to change the dependency analysis to work on the AST itself, which should mitigate the two disadvantages I described above |
Is this just a guess or do you have data to back up that the loading is too agressive? I know for sure that the compiler is aggresive on loading symbols from the Java namespace (because of macros), but I think this is not the case for libraries code. In any case, if you want to avoid that, you need to improve the class loaders in the compiler. If you try to remove from the classpath things that would be loaded by the compiler, wouldn't compilation fail? I guess I'll need more details on this topic to be able to make an educated guess of what's going on.
So is this a disadvantage of the way you want to work around the fact that the compiler loads aggressively? |
I don't think compilation will fail, because the fixes that will be introduced by
|
I think the fix in https://github.com/scalacenter/classpath-shrinker tells you everything that was loaded intentionally by the compiler for a given compilation unit; if you try to be smarter and remove some of the symbols that were loaded, without changing the compiler, I would expect the symbol loaders in the compiler to fail compilation. (I'm not an expert in this area, so take my word with a pinch of salt, I'm just trying to provide useful information in this discussion. I suggest you have concrete examples to work on and you prove that there is too much unnecessary loading going on and that you can avoid it by removing the jars from the classpath.)
Aha, I see. Have you looked into other ways of getting that information that does not require adding this decoupling? I think doing the |
This has been sitting in the queue for quite a while. Let's reopen if activity in the code or the comments restarts 😄 |
POC - Decouple dependency phase so other build tools would be able to use it and code will not be duplicated and maintained several times.
e.g.
bazelbuild/rules_scala
strict_deps feature.changes:
CallbackGlobal can not be part of the dependency analysis phase as it is zinc-specific, so the
DependencyAnalyzer
logic should only know of Global.AnalysisCallback
interface should be split in two, so that there will be an interface that only declare dependency related methodspending issues:
LocalToNonLocalClass
cache should somehow still be shared with other phases (this branch just creates a standalone instance of the cache for theDependencyAnalyzer
due to technical issue relatingSymbol
type conflicts).@gkossakowski @stuhood @ittaiz @johnynek
WDYT?