Hi all. I'm looking to do compile time validation ...
# compiler
b
Hi all. I'm looking to do compile time validation that when a function has a particular annotation, somewhere down the call stack another function will be called. Is this possible to do? It's tough to find documentation about using ASTNodes.
d
The problem you are describing is very close to the Halting problem which is principally unsolvable (but I could be wrong here) You can try to achieve it with some restrictions (e.g. don't consider generic calls, ignore library calls, etc), but it will be extremely slow: to perform such kind of analysis you need to build the cross-function CFG graph either from the entrypoint of the program or from each call-site you are interested. Size of this graph would be quite big (the size of the whole program), and traversals over it would be quite slow. Also for such a task you need to track values, as they affect what exactly will be executed:
Copy code
fun foo() {
    bar(1)
}

fun bar(x: Int) {
    if (x > 1) {
        annotatedBaz()
    }
}
And these values make things more interesting if they are coming from outside
As for technical details, I recommend you to take a look at
IrGenerationExtension
. It gives you access to the whole program which is being compiled and contains already resolved information. Other extension points won't suite for such a global analysis