Skip to content

Support non-local Java compiler use in mixed Java/Scala compilation#2231

Merged
lefou merged 2 commits intocom-lihaoyi:mainfrom
lefou:zinc-non-local-java
Jan 4, 2023
Merged

Support non-local Java compiler use in mixed Java/Scala compilation#2231
lefou merged 2 commits intocom-lihaoyi:mainfrom
lefou:zinc-non-local-java

Conversation

@lefou
Copy link
Member

@lefou lefou commented Jan 4, 2023

We need this feature to support SemanticDB generation (#2227) via a Java compiler plugin in mixed Scala/Java projects.

We already introduced non-local Java compilers in #1988. This change now also allows the use of a non-local Java compiler in mixed Java/Scala modules, if any -J option is given.

As compilers are cached, I added the hashCode of the relevant runtime javacOptions to the cache key.

I took the opportunity to remove non-relevant options from the existing Java compiler cache, to reduce the amount of cached compiler instances.

/CC @ckipp01 who implemented #1988.

@lefou
Copy link
Member Author

lefou commented Jan 4, 2023

Currently, we maintain two different caches, one for Scala/Mixed usage, and one for Java-only usage. But technically, the same Java compiler can be used in both setups.

Thus we could avoid holding additional Javac instances in the Scala-compilers-cache, by retrieving the instance from the javac-only-cache first.

Copy link
Contributor

@ckipp01 ckipp01 left a comment

Choose a reason for hiding this comment

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

O nice! It doesn't take much at all to support this. This is great!

@lefou
Copy link
Member Author

lefou commented Jan 4, 2023

Currently, we maintain two different caches, one for Scala/Mixed usage, and one for Java-only usage. But technically, the same Java compiler can be used in both setups.

Thus we could avoid holding additional Javac instances in the Scala-compilers-cache, by retrieving the instance from the javac-only-cache first.

I think we should work on this separately, as it probably involves further refactoring. We currently cache Compilers which is a pair of Scala and Java compile tools, whereas we want to re-use the same JavaTools in multiple Compilers.

@lefou lefou merged commit d35e049 into com-lihaoyi:main Jan 4, 2023
@lefou lefou deleted the zinc-non-local-java branch January 4, 2023 15:59
@lefou lefou added this to the 0.11.0-M2 milestone Jan 4, 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.

2 participants