Is there any way to force some code to be run non-lazily when the JS file is loaded? Even when using
-Xir-property-lazy-initialization
.
With
-Xir-per-module
I need to know if a certain module was already loaded. The only which comes to mind is to set a global variable when loading that module, and check if that variable set from other modules.
s
Svyatoslav Kuzmich [JB]
02/18/2021, 6:21 PM
Currently there are two custom things that run during module load with `-Xir-property-lazy-initialization`:
• top-level main function
• tests annotated with kotlin.test.Test
Either should work
Copy code
import kotlin.test.Test
class Foo {
@Test
fun foo() {
thisModuleIsLoaded = true
}
}
// At most one main function per module
fun main() {
thisModuleIsLoaded = true
}
🙏 1
m
Marc Knaup
03/15/2021, 4:11 PM
@Svyatoslav Kuzmich [JB] unfortunately it doesn’t work with “top-level main function” when also using
-Xir-per-module
.
The
main
functions of modules get dead-code-eliminated.
I can force-keep it with with
@JsExport
but then I run into another issue because multiple modules export a symbol with the same name `main`:
Copy code
IllegalStateException: IrSimpleFunctionPublicSymbolImpl for public /main|-4284757841571462650[0] is already bound: FUN name:main visibility:public modality:FINAL <> () returnType:<Uninitialized>
Any other ideas how to run code when such a module loads?