kotlin-python icon indicating copy to clipboard operation
kotlin-python copied to clipboard

Remove unneeded lowerings and refactor needed ones

Open krzema12 opened this issue 2 years ago • 1 comments

Lowerings are a big part of backend logic, so let's ensure we know what happens there and that we don't have anything surplus or weird.

  • #95
  • [x] analyze lowerings and dependencies between them
  • [ ] iteratively remove lowerings to get a minimal list of needed ones
  • [ ] remove unneeded Gradle module dependencies
  • [ ] add unit tests for each lowering, if possible. It's to be able to understand what they really do, so it serves documentation purposes
  • [ ] think outside the box: maybe for some case, the JS way is not the correct one? E. g. constructors, it may be a better way to lower them for Python. Now we base on JS version

krzema12 avatar Dec 23 '21 08:12 krzema12

Thanks to the below snippet I was able to generate a dependency diagram of lowerings:

(to be pasted in compiler/ir/backend.py/src/org/jetbrains/kotlin/ir/backend/py/JsLoweringPhases.kt)

fun main() {
    println("@startuml")
    println("skinparam componentStyle rectangle")
    println("left to right direction")

    loweringList.forEach { lowering ->
        println("component \"${lowering.modulePhase.name}\"")
        lowering.modulePhase.prerequisite.forEach { prerequisite ->
            println("component \"${prerequisite.name}\"")
            println("[${lowering.modulePhase.name}] --> [${prerequisite.name}]")
        }
    }

    println("@enduml")
}

The generated code can be rendered with any PlantUML renderer, e.g. http://www.plantuml.com/

image

krzema12 avatar Dec 27 '21 21:12 krzema12