How can I deep copy a IR tree? It has to be a real...
# compiler
How can I deep copy a IR tree? It has to be a really deep copy, no references between trees shall be left. I've tried this:
Copy code
val symRemapper = DeepCopySymbolRemapper()
val moduleCopy = DeepCopyIrTreeWithSymbols(symRemapper, DeepCopyTypeRemapper(symRemapper)).visitModuleFragment(module)
But it gives me
java.lang.IllegalArgumentException: Non-remapped symbol FILE fqName:kotlin.ranges
What do you mean by "references between trees"? Deep copying will remap any internal references to symbols to the copied version, it will still refer to symbols outside of the tree, however, because there's no way to gracefully handle that at all.
I mean I want to load the IR tree (modules), duplicate it (n times) and be able to pass each copy to the compiler backend as though each copy was separately produced by frontend. Because frontend compilation is slow and cloning is fast. Actually I load them from klib, but that's still not that fast. So the resulting copies have to be independent at least in a way to be transparent to lowering. I guess shared symbols outside of the tree (though I don't quite what do you mean by that) should be fine?
I was thinking of a different use case where you copy a specific
. In that case I was thinking off, it can still refer to outside symbols. In your case, you can just do
and that should do the trick
I think the problem you are facing is that you didn't do
before copying it (it needs to find the symbols before executing the copy) As Youssef suggested before,
should work for you here