Youssef Shoaib [MOD]
03/21/2021, 5:39 PMlet
from the standard library), compile that as part of the normal code compilation, and then access it's body in IR? I just need a way to inspect inside the code of a function coming in from a different compilation unit in IR instead of having to look into its bytecode. Even if it is a copy of the function and not 100% what the function itself is that's still absolutely fine because I just need to read through it's IR without editing it, and so it's fine with me if I'm taking it's source files and compiling just the ones with the functions that I need to read that IR. So yeah is there any way to get a library's included sources and compile that?shikasd
03/21/2021, 8:05 PMYoussef Shoaib [MOD]
03/21/2021, 8:50 PMYoussef Shoaib [MOD]
03/21/2021, 8:58 PMshikasd
03/21/2021, 9:43 PMYoussef Shoaib [MOD]
03/21/2021, 10:15 PMval
s to just allow them to never need to be actual Function
objects. Part of that is, for example, allowing a let
call on a lambda. This (and any other inline function that generically uses an object) currently results in the lambda being "boxed" (if you will). The plan, which does work already for functions in the same compilation unit, is to inline any inline function where, at the call site, a lambda is based in the place of a generic parameter so that then my other plugin code can take that inlined body, replace every IrGet
on the parameter with the copied IrFunctionExpression
that is the lambda, and then let the platform's respective compiler do the rest of inlining for me (I do also have special cases for calling invoke
on the lambda directly but whatever that's just irrelevant details).
The body of the function is also needed if the function receives the lambda as an extension receiver because, for some reason, the compiler just doesn't optimise that by default. The future plan for this is to also support inling `@JvmInline value class`es with a lambda backing field and possibly then even transforming normal classes into lambda-backed classes with the ultimate goal of providing something similar to the idea of structs but much more powerful with great performance.
More info about the optimisation itself is available at KT-44530 and the plugin itself is open-source on githubYoussef Shoaib [MOD]
03/21/2021, 10:16 PMYoussef Shoaib [MOD]
03/21/2021, 10:20 PMjvmResolveLibraries
which errors out when I try to get it to give me a result for the stdlib
It seems like the Klib route is the right direction here but 1) it doesn't seem like any klib files get generated for jvm compilations and 2) I can't seem to figure out how to even find the klib files for a specific libraryshikasd
03/21/2021, 11:06 PMYoussef Shoaib [MOD]
03/21/2021, 11:18 PMFunctionInlining
lowering of JS and Native and just rewrote it to work with an IrPluginContext
and it works flawlessly for anything in the same compilation unit. I don't wanna fork the compiler because the plan is to release this as a compiler plugin for the time being at least until (hopefully) this optimisation gets implemented into the main Kotlin compiler itself. i know that I can probably do this as a bytecode transformation, but then there's a million other headaches to deal with like `ObjectRef`s and undoing some optimisations that the compiler made like converting capturing lambdas into classes-with-fields and a load of other things that would be automatically taken-care of if done at the IR level. I think I might try to recompile some of the libraries, or possibly I can resort to not optimising inline functions from other libraries that weren't compiled with my plugin, and then in my plugin I could perhaps create a klib for the jvm compilation of a library and place it inside of the jar so that my plugin can pick it up and deserialise it from consumers of that library. I might also just try to recompile a part of the library like you said, and perhaps that can be a fallback if a library wasn't compiled with my plugin as a form of like compile-time performance for run-time performance trade-off (as in for example parts of the stdlib will be recompiled to be optimised so that at runtime you get the most performance possible). Well down another rabbit hole I go I guess lol!shikasd
03/21/2021, 11:38 PMirGet
and copied one with irFunctionExpression
. Then in another module, you could choose a function based on the type argument and "just" replace a call.