What is the alternative to `FirMetadataSerializerP...
# compiler
s
What is the alternative to
FirMetadataSerializerPlugin
API? My use case is I rewrite function parameters, body, along with function names to prevent signature clashes. I want to attach some mapping in FIR that this symbol will be rewritten as following, and have that accessible to downstream compilations.
d
You can generate new functions instead and put @Deprecated(HIDDEN) on the original one. All of it could be done at IR level and registered as visible in metadata.
s
The way I'm planning my plugin is to reduce allocations by internally convert immutable short-lived data classes with a mutable carrier that is entirely kept internal. Hence if it is not rewriting, I'll end up almost doubling the total list of functions and lambdas.
If I understand this correctly, it means the replacement function should have the same IdSignature, even if the function name is changed in IR. Did I understand it correctly?
d
Hm, in this case you potentially could do something like this: • let's say you optimize only functions annotated with
@Ann
• for all annotated functions create
_optimized
versions, which are invisible for callers • replace all call-sites to original functions with optimized versions • you can do it even for functions from dependencies, if they were compiled with your plugin
Copy code
// original code
@Ann
fun foo(x: Point<Int, Int>): String { ... }

fun test() {
    foo(1 to 2)
}
Copy code
// transformed by plugin
@Ann
fun foo(x: Point<Int, Int>): String {
    return foo_optimized(x.first, x.second)
}

@Deprecated(HIDDEN) // invisible for users, visible for the compiler
fun foo_optimized(x: Int, y: Int) { ... }

fun test() {
    foo_optimized(1, 2)
}