krzema12 / kotlin-python

Python target for the Kotlin Programming Language. See https://github.com/krzema12/kotlin-python/tree/python-backend/python
https://discuss.kotlinlang.org/t/idea-python-backend/19852
48 stars 1 forks source link

Get rid of lists of expr since only single expr is needed everywhere #25

Closed SerVB closed 3 years ago

SerVB commented 3 years ago

This PR includes commits from #24, so let's deal with this PR after we deal with #24.

Here we get rid of lists in expr transformer and use plain expr now. That's because I've noticed that I always have to box expressions in listOf and then unbox them via .single. Logically, we don't need list of expressions since an expression is a single thing.

It was true for almost every IR element but for vararg. I've adjusted vararg a bit and see we have some positive changes in the out_ir.py and also we have +1 passed box test now :)

For statements, I've left lists as it's quite reasonable to me (but maybe in the future we will decide that it's more handy to have plain stmt, but we will need to do something with stmt* body appearing in multiple places, maybe extract a function that handles them).

Piotr, don't you remember why it was decided to use lists for expressions? Maybe I just don't see something...

krzema12 commented 3 years ago

Piotr, don't you remember why it was decided to use lists for expressions? Maybe I just don't see something...

By checking git history, I see this commit: https://github.com/krzema12/kotlin-python/commit/1aab214e39f85788d3437c0ae4b22327de5da644 (Make IrElementToPyExpressionTransformer return List), however I didn't put any meaningful commit message. It seems to be a preparation for the next commit https://github.com/krzema12/kotlin-python/commit/0acc431c0088498152167df5d5bec1bb44eb9e19 (Map IrBlock) where I don't really use the fact of making expr a List<expr>. So yeah, this change seems to be not well thought-through :sweat_smile: I was iterating and experimenting very quickly back then. With your PR you proved that we can simplify it :+1: The box tests are an excellent safety net in case of such refactorings.