[IR] Fixed a bunch of wrong parents

This commit is contained in:
Igor Chevdar
2019-06-24 19:48:44 +03:00
parent 440c03035d
commit a747678992
6 changed files with 30 additions and 22 deletions
@@ -287,7 +287,7 @@ internal class EnumClassLowering(val context: Context) : ClassLoweringPass {
putValueArgument(0, irInt(it.index))
}
val initializer = it.value.initializerExpression!!
initializer.patchDeclarationParents(constructor)
initializer.setDeclarationsParent(constructor)
when {
initializer is IrConstructorCall -> +initInstanceCall(instance, initializer)
@@ -24,10 +24,7 @@ import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.dump
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.ir.util.patchDeclarationParents
import org.jetbrains.kotlin.ir.util.transformFlat
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
import org.jetbrains.kotlin.name.Name
@@ -103,7 +100,7 @@ internal class EnumConstructorsLowering(val context: Context) : ClassLoweringPas
val defaultValue = parameter.defaultValue ?: continue
defaultValue.transformChildrenVoid(ParameterMapper(enumConstructor, loweredEnumConstructor, true))
loweredEnumConstructor.valueParameters[parameter.loweredIndex].defaultValue = defaultValue
defaultValue.patchDeclarationParents(loweredEnumConstructor)
defaultValue.setDeclarationsParent(loweredEnumConstructor)
}
return loweredEnumConstructor
@@ -129,7 +126,9 @@ internal class EnumConstructorsLowering(val context: Context) : ClassLoweringPas
).apply {
it.bind(this)
parent = constructor.parent
body = constructor.body!! // Will be transformed later.
val body = constructor.body!!
this.body = body // Will be transformed later.
body.setDeclarationsParent(this)
}
}
@@ -14,10 +14,12 @@ import org.jetbrains.kotlin.descriptors.MemberDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.util.DeepCopyIrTreeWithSymbols
import org.jetbrains.kotlin.ir.util.DeepCopySymbolRemapper
import org.jetbrains.kotlin.ir.util.DeepCopyTypeRemapper
import org.jetbrains.kotlin.ir.util.patchDeclarationParents
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid
@@ -77,9 +79,12 @@ internal class ExpectToActualDefaultValueCopier(private val irModule: IrModuleFr
return
}
function.findActualForExpected().valueParameters[index].defaultValue = defaultValue.also {
it.expression = it.expression.remapExpectValueSymbols()
}
val actualForExpected = function.findActualForExpected()
actualForExpected.valueParameters[index].defaultValue =
IrExpressionBodyImpl(
defaultValue.startOffset, defaultValue.endOffset,
defaultValue.expression.remapExpectValueSymbols().patchDeclarationParents(actualForExpected)
)
}
})
}
@@ -5,12 +5,9 @@
package org.jetbrains.kotlin.backend.konan.lower
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
import org.jetbrains.kotlin.backend.common.ScopeWithIr
import org.jetbrains.kotlin.backend.common.*
import org.jetbrains.kotlin.backend.common.ir.createTemporaryVariableWithWrappedDescriptor
import org.jetbrains.kotlin.backend.common.ir.Symbols
import org.jetbrains.kotlin.backend.common.isBuiltInIntercepted
import org.jetbrains.kotlin.backend.common.isBuiltInSuspendCoroutineUninterceptedOrReturn
import org.jetbrains.kotlin.backend.common.lower.CoroutineIntrinsicLambdaOrigin
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
import org.jetbrains.kotlin.backend.konan.Context
@@ -56,9 +53,8 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
val actualCallee = getFunctionDeclaration(callee.symbol)
actualCallee.transformChildrenVoid(this) // Process recursive inline.
val parent = allScopes.map { it.irElement }.filterIsInstance<IrDeclarationParent>().lastOrNull()
val inliner = Inliner(expression, actualCallee, currentScope!!, parent, context)
return inliner.inline()
}
@@ -107,7 +103,7 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
val substituteMap = mutableMapOf<IrValueParameter, IrElement>()
fun inline() = inlineFunction(callSite, callee)
fun inline() = inlineFunction(callSite, callee, true)
/**
* TODO: JVM inliner crashed on attempt inline this function from transform.kt with:
@@ -120,8 +116,12 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
}
}
private fun inlineFunction(callSite: IrFunctionAccessExpression, callee: IrFunction): IrReturnableBlock {
val copiedCallee = copyIrElement.copy(callee) as IrFunction
private fun inlineFunction(callSite: IrFunctionAccessExpression,
callee: IrFunction,
performRecursiveInline: Boolean): IrReturnableBlock {
val copiedCallee = if (performRecursiveInline)
visitElement(copyIrElement.copy(callee)) as IrFunction
else copyIrElement.copy(callee) as IrFunction
val evaluationStatements = evaluateArguments(callSite, copiedCallee)
val statements = (copiedCallee.body as IrBlockBody).statements
@@ -194,6 +194,7 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
return expression
}
})
patchDeclarationParents(parent) // TODO: Why it is not enough to just run SetDeclarationsParentVisitor?
}
}
@@ -263,7 +264,7 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid
return super.visitCall(expression)
val functionDeclaration = functionArgument.statements[0] as IrFunction
val newExpression = inlineFunction(expression, functionDeclaration) // Inline the lambda. Lambda parameters will be substituted with lambda arguments.
val newExpression = inlineFunction(expression, functionDeclaration, false) // Inline the lambda. Lambda parameters will be substituted with lambda arguments.
return newExpression.transform(this, null) // Substitute lambda arguments with target function arguments.
}
@@ -132,7 +132,7 @@ internal class InitializersLowering(val context: CommonBackendContext) : ClassLo
return expression
}
})
initializer.patchDeclarationParents(initializeFun)
initializer.setDeclarationsParent(initializeFun)
}
return initializeFun.symbol
@@ -166,7 +166,7 @@ internal class InitializersLowering(val context: CommonBackendContext) : ClassLo
if (initializeMethodSymbol == null) {
assert(declaration.isPrimary)
for (initializer in initializers)
initializer.patchDeclarationParents(declaration)
initializer.setDeclarationsParent(declaration)
initializers
} else {
val startOffset = it.startOffset
@@ -75,6 +75,8 @@ internal fun IrFile.addTopLevelInitializer(expression: IrExpression, context: Ko
).apply {
descriptor.bind(this)
expression.setDeclarationsParent(this)
if (threadLocal)
annotations += buildSimpleAnnotation(context.irBuiltIns, startOffset, endOffset, context.ir.symbols.threadLocal.owner)
@@ -315,6 +317,7 @@ fun IrBuilderWithScope.irCatch(type: IrType) =
false
).apply {
descriptor.bind(this)
parent = this@irCatch.parent
}
}
)