Is there a way to make the Kotlin compiler list it...
# compiler
m
Is there a way to make the Kotlin compiler list its phases? In Scala, for example, I can run
scalac -Xshow-phases
to get something like this:
Copy code
phase name  id  description
    ----------  --  -----------
        parser   1  parse source into ASTs, perform simple desugaring
         namer   2  resolve names, attach symbols to named trees
packageobjects   3  load package objects
         typer   4  the meat and potatoes: type the trees
👆 2
d
There is no such compiler key, and, actually there are no separate phases in current compiler. Here is main pipeline: 1. Parse source code to PSI (it's an AST that used in Intellij IDEA) 2. Collect info about all declarations to create scopes for different types 3. Resolve and check all bodies of all declarations 4. Generate backend IR (intermediate representation of soure code) 5. Run different lowerings over IR 6. Generate bytecode/js/llvm from it Parts 2-3 are called as "frontend" and 5-6 as "backend" In current compiler frontend we use lazy resolve that means that all resolve is performed on demand. E.g. in such code we will start resolve body of function
bar
while resolving call
(1)
Copy code
fun foo() {
    ...
    val x = bar()
    ...
}

fun bar() = run {
    ...    
    1
}
In new compiler frontend we refused lazy resolve because it kills performance and introduce separate phases over new intermediate representation named FIR (frontend IR). Here are they: 1. Building FIR from PSI 2. Resolve all imports in all files 3. Resolve supertypes of all classes 4. Resolve all declared types in signatures 5. Resolve bodies of declarations with implicit type (functions with expression body and properties with initializer and without declared type) 6. Resolve rest of declarations bodies 7. Run static analysis over resolved FIR (some call and declaration checkers, control flow analysis) 8. Transform resolved FIR to backed IR This scheme allows us to run most of this phases in parallel that may heavily increase compiler performance
👏 5
m
Thanks! That helps! :)
b
Is there a way to log these ? I would like to know where it is stuck in : https://youtrack.jetbrains.com/issue/KT-38489
u
BTW the new JVM IR compiler backend has explicit list of phases available via
-Xlist-phases
. But naturally those are only phases of the backend.
💯 2