-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Kotlin/JS codegen compiler extension #4925
base: master
Are you sure you want to change the base?
Conversation
Add ir2js extensions to test infrastructure Code cleanup (compiler core)
Enabling interop between KotlinJS and JSweet (transpiled Java) would be a major improvement to Kotlin. The same apply for the J2CL project |
@LifeIsStrange I think you should write it on YouTrack |
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.
@Soarex16 thank you for your pull request!
For ease of review and to increase the chance of this being merged, please split this into two PRs: one for introducing the extension point, and another for the web workers plugin.
@broadwaylamb, I've split this PR into smaller parts: #4989 and #4988 |
Motivation
Currently, the code generation process (IR to JS conversion) is fixed and cannot be modified by plugins. This on the one hand leaves flexibility for compiler developers, but at the same time does not allows to customize transformations at later stages of compilation.
For example, currently, there is no way to generate multiple .js files for one module. Such abilities a very useful in some scenarios like Web Workers API.
This PR aims to provide some basic implementation for such extension points.
Safe harbor
It's also worth noting that the changes I'm suggesting don't consider many edge cases - for example, incremental compilation, bundle size, etc. Therefore, I propose to join the discussion to design a better solution that considers various use cases.
The main question - why can't this be done at the IR level? This is due to the fact that in some situations, plugin developers need the ability to perform platform optimizations and have access to the infrastructure of the corresponding backend.
As far as I know, the compiler has bytecode post-processing for the JVM platform, but this tool is not available for plugins. There is no such functionality in the JS IR backend (to be more precise, it is not highlighted as an explicit post-processing stage).
Proposed compiler changes
The following must be taken into account here:
Worker
constructor accepts script URL. It is worth mentioning that support for web workers is a separate issue and for now I will not touch on the details of implementing their support in Kotlin.Use cases
The main reason to inject into code generation process - there is currently no way to emit multiple .js files for a single module. The community needs this functionality because its absence makes it difficult to implement Kotlin/JS in the following scenarios:
importScripts(...)
to include dependencies in worker context.Samples
This PR also includes a sample plugin to demonstrate the process of generating multiple .js files for a single module.