https://kotlinlang.org logo
#python-contributors
Title
# python-contributors
p

Piotr Krzemiński

07/26/2021, 12:29 PM
Hi folks, I'm struggling to modify an existing lowering to work with Python. See this PR - 4 box tests complain about e.g.
Copy code
UnboundLocalError: local variable 'properties_initialized_utf8Encoding_kt' referenced before assignment
The lowering in question is PropertyLazyInitLowering.kt. Why it happens: the lowering produces initialization functions like
Copy code
def init_properties_utf8Encoding_kt():
    if not (properties_initialized_utf8Encoding_kt):
        properties_initialized_utf8Encoding_kt = True
        tmp0_byteArrayOf_0 = visitConst_other_Byte
        REPLACEMENT_BYTE_SEQUENCE = tmp0_byteArrayOf_0
and before reaching
if not (properties_initialized_utf8Encoding_kt):
, Python has to have
properties_initialized_utf8Encoding_kt
assigned to some value (here
False
would make sense). I wanted to add
properties_initialized_utf8Encoding_kt = False
just before this function definition, but I'm lost in the structure of IR elements hierarchy. I cannot spot a place where the function is added to the IR output. Even if I use some transformers that compile fine, I don't see them do their job in the output. Could you help me figure it out? Side-questions: are there any materials where I could learn more about the internal compiler API regarding IR entities, or only browsing the code is the way to go?
s

SerVB

07/30/2021, 6:00 PM
Some time ago @ bashor told me to look into
compiler/testData/ir/irText
to understand which KT text goes to which IR, but I haven't tried it yet. And for the reverse direction, IR to KT,
dumpKotlinLike
should help. Regarding the first question, I have no idea, but if you want I can take a look too...
👍 1
p

Piotr Krzemiński

07/30/2021, 7:00 PM
Thanks, will check!
A note to myself: check other lowerings, we probably need to create a lowering that inherits from
DeclarationTransformer
or
IrElementTransformerVoid
3 Views