mcpiroman
04/18/2023, 2:03 PMIvan Kylchik
04/21/2023, 8:24 AMIrElements
are all used to represent different code. I will try to explain the hierarchy.
1. IrBody
. Used to represent function bodies. It has 3 implementations
• IrBlockBody
represents function body inside curly braces.
• IrExpressionBody
represents function body with single expression after =
sign (see Single-expression functions).
• IrSyntheticBody
represents a body that wasn’t presented in source code. I don’t know much about this type but as I can see it is used only for enums.
2. IrBlock
. Represents some block of code inside function. Has 3 implementations:
• IrBlockImpl
. Basic implementation that is used to represent all blocks of the form if (true) { /* this is IrBlockImpl */ }
.
• IrReturnableBlock
. This is block of code that can have inner return in it. After return
was executed we appear at the end of this block. Don’t confuse it with IrBlockBody
. It is synthetic block, that can appear after some code transformations. I remember two cases when we create such block type: the first one after inlining to represent early returns and the second one in some try-catch cases.
• IrInlinedFunctionBlock
. This one is used to mark a code that was inlined. We store there some additional info to remember that was before inlining.
3. IrComposite
. Mostly the same as IrBlock
. Difference between these two elements is that after exiting IrBlock
we “forget” about all declared entities inside that block. This is not the case for IrComposite
. This is needed, for example, to store variables after transforming destructing declaration.