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