IR: Fixed some parents
This commit is contained in:
@@ -305,6 +305,11 @@ fun IrDeclarationContainer.addChild(declaration: IrDeclaration) {
|
||||
declaration.accept(SetDeclarationsParentVisitor, this)
|
||||
}
|
||||
|
||||
fun <T: IrElement> T.setDeclarationsParent(parent: IrDeclarationParent): T {
|
||||
accept(SetDeclarationsParentVisitor, parent)
|
||||
return this
|
||||
}
|
||||
|
||||
object SetDeclarationsParentVisitor : IrElementVisitor<Unit, IrDeclarationParent> {
|
||||
override fun visitElement(element: IrElement, data: IrDeclarationParent) {
|
||||
if (element !is IrDeclarationParent) {
|
||||
|
||||
+1
@@ -86,6 +86,7 @@ class SharedVariablesLowering(val context: BackendContext) : FunctionLoweringPas
|
||||
if (declaration !in sharedVariables) return declaration
|
||||
|
||||
val newDeclaration = context.sharedVariablesManager.declareSharedVariable(declaration)
|
||||
newDeclaration.parent = irFunction
|
||||
transformedDescriptors[declaration.symbol] = newDeclaration.symbol
|
||||
|
||||
return context.sharedVariablesManager.defineSharedValue(declaration, newDeclaration)
|
||||
|
||||
+2
-2
@@ -53,7 +53,7 @@ private fun lowerTailRecursionCalls(context: BackendContext, irFunction: IrFunct
|
||||
irFunction.body = builder.irBlockBody {
|
||||
// Define variables containing current values of parameters:
|
||||
val parameterToVariable = parameters.associate {
|
||||
it to irTemporaryVar(irGet(it), nameHint = it.symbol.suggestVariableName(), parent = irFunction)
|
||||
it to irTemporaryVar(irGet(it), nameHint = it.symbol.suggestVariableName())
|
||||
}
|
||||
// (these variables are to be updated on any tail call).
|
||||
|
||||
@@ -65,7 +65,7 @@ private fun lowerTailRecursionCalls(context: BackendContext, irFunction: IrFunct
|
||||
// Read variables containing current values of parameters:
|
||||
val parameterToNew = parameters.associate {
|
||||
val variable = parameterToVariable[it]!!
|
||||
it to irTemporary(irGet(variable), nameHint = it.symbol.suggestVariableName()).also { it.parent = irFunction }
|
||||
it to irTemporary(irGet(variable), nameHint = it.symbol.suggestVariableName())
|
||||
}
|
||||
|
||||
val transformer = BodyTransformer(
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.assertedCast
|
||||
|
||||
val IrBuilderWithScope.parent get() = scope.getLocalDeclarationParent()
|
||||
|
||||
inline fun IrBuilderWithScope.irLet(
|
||||
value: IrExpression,
|
||||
@@ -68,11 +69,9 @@ fun <T : IrElement> IrStatementsBuilder<T>.defineTemporary(value: IrExpression,
|
||||
fun <T : IrElement> IrStatementsBuilder<T>.irTemporaryVar(
|
||||
value: IrExpression,
|
||||
nameHint: String? = null,
|
||||
typeHint: KotlinType? = null,
|
||||
parent: IrDeclarationParent? = null
|
||||
typeHint: KotlinType? = null
|
||||
): IrVariable {
|
||||
val temporary = scope.createTemporaryVariable(value, nameHint, isMutable = true, type = typeHint)
|
||||
parent?.let { temporary.parent = it }
|
||||
+temporary
|
||||
return temporary
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
class Scope(val scopeOwnerSymbol: IrSymbol) {
|
||||
val scopeOwner: DeclarationDescriptor get() = scopeOwnerSymbol.descriptor
|
||||
|
||||
private fun getVariableParent(): IrDeclarationParent {
|
||||
fun getLocalDeclarationParent(): IrDeclarationParent {
|
||||
if (!scopeOwnerSymbol.isBound) throw AssertionError("Unbound symbol: $scopeOwner")
|
||||
val scopeOwnerElement = scopeOwnerSymbol.owner
|
||||
return when (scopeOwnerElement) {
|
||||
@@ -87,7 +87,7 @@ class Scope(val scopeOwnerSymbol: IrSymbol) {
|
||||
irType ?: irExpression.type,
|
||||
irExpression
|
||||
).apply {
|
||||
parent = getVariableParent()
|
||||
parent = getLocalDeclarationParent()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -299,24 +299,23 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
val localSerialDesc = irTemporary(irGet(descriptorGetterSymbol.owner.returnType, irThis(), descriptorGetterSymbol), "desc")
|
||||
|
||||
// workaround due to unavailability of labels (KT-25386)
|
||||
val flagVar = irTemporaryVar(irBoolean(true), "flag", parent = loadFunc)
|
||||
val flagVar = irTemporaryVar(irBoolean(true), "flag")
|
||||
|
||||
val indexVar = irTemporaryVar(irInt(0), "index", parent = loadFunc)
|
||||
val indexVar = irTemporaryVar(irInt(0), "index")
|
||||
// val readAll = irTemporaryVar(irBoolean(false), "readAll", parent = loadFunc)
|
||||
//
|
||||
// calculating bit mask vars
|
||||
val blocksCnt = orderedProperties.size / 32 + 1
|
||||
|
||||
// var bitMask0 = 0, bitMask1 = 0...
|
||||
val bitMasks = (0 until blocksCnt).map { irTemporaryVar(irInt(0), "bitMask$it", parent = loadFunc) }
|
||||
val bitMasks = (0 until blocksCnt).map { irTemporaryVar(irInt(0), "bitMask$it") }
|
||||
// var local0 = null, local1 = null ...
|
||||
val localProps = orderedProperties.mapIndexed { i, prop ->
|
||||
val (expr, type) = defaultValueAndType(prop)
|
||||
irTemporaryVar(
|
||||
expr,
|
||||
"local$i",
|
||||
typeHint = type,
|
||||
parent = loadFunc
|
||||
typeHint = type
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user