Leandro Ocampo

    Leandro Ocampo

    1 year ago
    Hello people! hope you are having a great day. I have some questions related to using arrow meta in the IR phase. First of all I am the one who wrote this question in the github repo: https://github.com/arrow-kt/arrow-meta/issues/767. Sorry for that. I had no idea where I could ask for help 😅. At the moment I am having some issues when trying to transform code in the IR phase. I can see that the code is being changed when I use irDump but it fails when I test with quoteOutputMatches. I used this code:
    val Meta.irLogTest: CliPlugin
        get() =
            "IR log CLI" {
                meta(
                    enableIr(),
                    irBody { this.irLogBody(it) },
                    irDump()
                )
            }
    
    fun IrUtils.irLogBody(irBody: IrBody): IrBody? {...}
    So my questions are: 1- are those extension phases enough to transform the code? Assuming irLogBody is applying some transformation. In this case by using
    irBody.transformChildrenVoid
    2- is it okay to test this changes with quoteOutputMatches? As far I can see it should, but maybe I am missing something. I was able to achieve this result with Arrow meta in the parsing phase.
    raulraja

    raulraja

    1 year ago
    Hi Leandro 🙂, Quotes are unrelated to IR. Quotes are the AST transformation of Kotlin Sources to generate new sources or mutate them in place. By the time a Kotlin program gets to IR and IR gets transformed there is no longer an association between the original sources and the resulting program. quoteOutputMatches only checks source contents and will not work for comparing backend IR trees. The suite for IR tests at the moment is limited to check if they get invoked but we don’t have facilities similar to quoteOutputMatches. If you want to contribute the feature we can help but essentially the meta test DSL does not yet have a way to compare IR transformed trees and it would definitely be useful to compiler plugin authors.
    To answer your first question, yes those should be enough, you don’t need the dump but you need to enable IR either programmatically or via compiler flag
    Leandro Ocampo

    Leandro Ocampo

    1 year ago
    Thank you so much! that saved me a lot of time as things were working but I was just assuming they were not based on the tests 😂
    Also, something worth mentioning is that actually the ir transformation was not working because I was trying to transform a function call coming from a library that was compiled with kotlin 1.3.72... as soon as I changed that by a class created in my own project with 1.4.10 then I could see the changes
    raulraja

    raulraja

    1 year ago
    Yes, the IR format is not backward compatible in the compiler across releases at the moment.
    Leandro Ocampo

    Leandro Ocampo

    1 year ago
    Great! I will write all this information in the github issue I opened and close it. Thank you so much