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

Specify type explicitly in KotlinCoreProjectEnvironment.createCoreFil… #4069

Merged
merged 1 commit into from Feb 2, 2021

Conversation

MarcinAman
Copy link
Contributor

…eManager to allow overriding this method with different implementation

Right now the type is KotlinCliJavaFileManagerImpl which defeats the point of inheritance since no one is able to substitute the result with own implementation.

…eManager to allow overriding this method with different implementation
@udalov udalov self-assigned this Feb 1, 2021
@udalov udalov added the Compiler label Feb 1, 2021
@udalov
Copy link
Member

udalov commented Feb 1, 2021

Hi! Thanks for the contribution. Could you please explain why you need this change?

@MarcinAman
Copy link
Contributor Author

I don't strictly need it, it is more of a nice nice addition.
To give you some background story: In dokka we have a quite peculiar issue with trove hashing that i think comes from the compiler itself: Kotlin/dokka#1599

As far as i can tell it is related to multithreaded use of the analysis. For us specially KotlinCliJavaFileManagerImpl and JvmDependenciesIndexImpl classes are quite problematic since they sometimes fail the whole analysis. I've debugged this a little bit and it appears that trove is not suitable for multithreaded use and if it encounters a duplicate value during rehashing it simply throws an exception. Imho duplicates occur when multiple instances of object with same hashcode are added in 'the same time'.
So, as a way to mitigate this issue for now i'd like to add synchronised use for trove maps in those files and add them to dokka analysis. Right now we use:

fun createForProduction(
            parentDisposable: Disposable, configuration: CompilerConfiguration, configFiles: EnvironmentConfigFiles
        ): KotlinCoreEnvironment

To get environment but i thought that i'd just use:

fun createForProduction(
            projectEnvironment: JavaCoreProjectEnvironment, configuration: CompilerConfiguration, configFiles: EnvironmentConfigFiles
        ): KotlinCoreEnvironment

to get environment and pass it my class that inherits from KotlinCoreProjectEnvironment and overrides createCoreFileManager with my, synchronised, implementation.

This approach unfortunately fails because i am obligated to provide KotlinCliJavaFileManagerImpl in createCoreFileManager and it can be inherited.

Because of that i think that it is not the best approach to enforce the implementation in the return type.

As for the whole multithreaded trove issue: i will probably create a PR for that (at least for discussion) but i am not entirely sure how to unhack 1 thing there :D
Ofc for now we just shadowed yours classes on classpath with our synchronised versions but this is quite unfortunate solution as we just wanted to have a build.

@udalov
Copy link
Member

udalov commented Feb 2, 2021

Thanks!

@udalov udalov merged commit d953a03 into JetBrains:master Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants