Lowerings commonization:
- Removed dependency LocalDeclarationsLowering -> CallableReferenceLowering - Used common LocalDelegatedPropertiesLowering - Moved DelegationLowering & CallableReferenceLowering down along the pipeline
This commit is contained in:
+8
-6
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.backend.konan
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
|
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
|
||||||
import org.jetbrains.kotlin.backend.common.lower.*
|
import org.jetbrains.kotlin.backend.common.lower.*
|
||||||
|
import org.jetbrains.kotlin.backend.common.lower.LocalDelegatedPropertiesLowering
|
||||||
import org.jetbrains.kotlin.backend.konan.lower.*
|
import org.jetbrains.kotlin.backend.konan.lower.*
|
||||||
import org.jetbrains.kotlin.backend.konan.lower.ExpectDeclarationsRemoving
|
import org.jetbrains.kotlin.backend.konan.lower.ExpectDeclarationsRemoving
|
||||||
import org.jetbrains.kotlin.backend.konan.lower.FinallyBlocksLowering
|
import org.jetbrains.kotlin.backend.konan.lower.FinallyBlocksLowering
|
||||||
@@ -88,13 +89,8 @@ internal class KonanLower(val context: Context, val parentPhaser: PhaseManager)
|
|||||||
phaser.phase(KonanPhase.LOWER_SHARED_VARIABLES) {
|
phaser.phase(KonanPhase.LOWER_SHARED_VARIABLES) {
|
||||||
SharedVariablesLowering(context).runOnFilePostfix(irFile)
|
SharedVariablesLowering(context).runOnFilePostfix(irFile)
|
||||||
}
|
}
|
||||||
phaser.phase(KonanPhase.LOWER_DELEGATION) {
|
|
||||||
PropertyDelegationLowering(context).lower(irFile)
|
|
||||||
}
|
|
||||||
phaser.phase(KonanPhase.LOWER_CALLABLES) {
|
|
||||||
CallableReferenceLowering(context).lower(irFile)
|
|
||||||
}
|
|
||||||
phaser.phase(KonanPhase.LOWER_LOCAL_FUNCTIONS) {
|
phaser.phase(KonanPhase.LOWER_LOCAL_FUNCTIONS) {
|
||||||
|
LocalDelegatedPropertiesLowering().lower(irFile)
|
||||||
LocalDeclarationsLowering(context).runOnFilePostfix(irFile)
|
LocalDeclarationsLowering(context).runOnFilePostfix(irFile)
|
||||||
}
|
}
|
||||||
phaser.phase(KonanPhase.LOWER_TAILREC) {
|
phaser.phase(KonanPhase.LOWER_TAILREC) {
|
||||||
@@ -119,6 +115,12 @@ internal class KonanLower(val context: Context, val parentPhaser: PhaseManager)
|
|||||||
phaser.phase(KonanPhase.LOWER_ENUMS) {
|
phaser.phase(KonanPhase.LOWER_ENUMS) {
|
||||||
EnumClassLowering(context).run(irFile)
|
EnumClassLowering(context).run(irFile)
|
||||||
}
|
}
|
||||||
|
phaser.phase(KonanPhase.LOWER_DELEGATION) {
|
||||||
|
PropertyDelegationLowering(context).lower(irFile)
|
||||||
|
}
|
||||||
|
phaser.phase(KonanPhase.LOWER_CALLABLES) {
|
||||||
|
CallableReferenceLowering(context).lower(irFile)
|
||||||
|
}
|
||||||
phaser.phase(KonanPhase.LOWER_INTEROP_PART2) {
|
phaser.phase(KonanPhase.LOWER_INTEROP_PART2) {
|
||||||
InteropLoweringPart2(context).lower(irFile)
|
InteropLoweringPart2(context).lower(irFile)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ enum class KonanPhase(val description: String,
|
|||||||
/* ... ... */ LOWER_LATEINIT("Lateinit properties lowering", LOWER_INLINE),
|
/* ... ... */ LOWER_LATEINIT("Lateinit properties lowering", LOWER_INLINE),
|
||||||
/* ... ... */ LOWER_SHARED_VARIABLES("Shared Variable Lowering", LOWER_INITIALIZERS),
|
/* ... ... */ LOWER_SHARED_VARIABLES("Shared Variable Lowering", LOWER_INITIALIZERS),
|
||||||
/* ... ... */ LOWER_CALLABLES("Callable references Lowering", LOWER_DELEGATION/*TODO: make weak dependence on TEST_PROCESSOR*/),
|
/* ... ... */ LOWER_CALLABLES("Callable references Lowering", LOWER_DELEGATION/*TODO: make weak dependence on TEST_PROCESSOR*/),
|
||||||
/* ... ... */ LOWER_LOCAL_FUNCTIONS("Local Function Lowering", LOWER_SHARED_VARIABLES, LOWER_CALLABLES),
|
/* ... ... */ LOWER_LOCAL_FUNCTIONS("Local Function Lowering", LOWER_SHARED_VARIABLES),
|
||||||
/* ... ... */ LOWER_INTEROP_PART2("Interop lowering, part 2", LOWER_LOCAL_FUNCTIONS),
|
/* ... ... */ LOWER_INTEROP_PART2("Interop lowering, part 2", LOWER_LOCAL_FUNCTIONS),
|
||||||
/* ... ... */ LOWER_TAILREC("tailrec lowering", LOWER_LOCAL_FUNCTIONS),
|
/* ... ... */ LOWER_TAILREC("tailrec lowering", LOWER_LOCAL_FUNCTIONS),
|
||||||
/* ... ... */ LOWER_FINALLY("Finally blocks lowering", LOWER_INITIALIZERS, LOWER_LOCAL_FUNCTIONS, LOWER_TAILREC),
|
/* ... ... */ LOWER_FINALLY("Finally blocks lowering", LOWER_INITIALIZERS, LOWER_LOCAL_FUNCTIONS, LOWER_TAILREC),
|
||||||
|
|||||||
+22
-18
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
|||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
||||||
@@ -42,6 +41,7 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
|
|||||||
private object DECLARATION_ORIGIN_FUNCTION_REFERENCE_IMPL : IrDeclarationOriginImpl("FUNCTION_REFERENCE_IMPL")
|
private object DECLARATION_ORIGIN_FUNCTION_REFERENCE_IMPL : IrDeclarationOriginImpl("FUNCTION_REFERENCE_IMPL")
|
||||||
|
|
||||||
override fun lower(irFile: IrFile) {
|
override fun lower(irFile: IrFile) {
|
||||||
|
var generatedClasses = mutableListOf<IrClass>()
|
||||||
irFile.transform(object: IrElementTransformerVoidWithContext() {
|
irFile.transform(object: IrElementTransformerVoidWithContext() {
|
||||||
|
|
||||||
private val stack = mutableListOf<IrElement>()
|
private val stack = mutableListOf<IrElement>()
|
||||||
@@ -61,9 +61,18 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitDeclaration(declaration: IrDeclaration): IrStatement {
|
override fun visitDeclaration(declaration: IrDeclaration): IrStatement {
|
||||||
|
lateinit var tempGeneratedClasses: MutableList<IrClass>
|
||||||
|
if (declaration is IrClass) {
|
||||||
|
tempGeneratedClasses = generatedClasses
|
||||||
|
generatedClasses = mutableListOf()
|
||||||
|
}
|
||||||
stack.push(declaration)
|
stack.push(declaration)
|
||||||
val result = super.visitDeclaration(declaration)
|
val result = super.visitDeclaration(declaration)
|
||||||
stack.pop()
|
stack.pop()
|
||||||
|
if (declaration is IrClass) {
|
||||||
|
declaration.declarations += generatedClasses
|
||||||
|
generatedClasses = tempGeneratedClasses
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,20 +108,19 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
|
|||||||
return expression
|
return expression
|
||||||
}
|
}
|
||||||
|
|
||||||
val parent = allScopes.map { it.irElement }.filterIsInstance<IrDeclarationParent>().last()
|
val parent: IrDeclarationContainer = (currentClass?.irElement as? IrClass) ?: irFile
|
||||||
val loweredFunctionReference = FunctionReferenceBuilder(parent, expression).build()
|
val loweredFunctionReference = FunctionReferenceBuilder(parent, expression).build()
|
||||||
|
generatedClasses.add(loweredFunctionReference.functionReferenceClass)
|
||||||
val irBuilder = context.createIrBuilder(currentScope!!.scope.scopeOwnerSymbol,
|
val irBuilder = context.createIrBuilder(currentScope!!.scope.scopeOwnerSymbol,
|
||||||
expression.startOffset, expression.endOffset)
|
expression.startOffset, expression.endOffset)
|
||||||
return irBuilder.irBlock(expression) {
|
return irBuilder.irCall(loweredFunctionReference.functionReferenceConstructor.symbol).apply {
|
||||||
+loweredFunctionReference.functionReferenceClass
|
expression.getArguments().forEachIndexed { index, argument ->
|
||||||
+irCall(loweredFunctionReference.functionReferenceConstructor.symbol).apply {
|
putValueArgument(index, argument.second)
|
||||||
expression.getArguments().forEachIndexed { index, argument ->
|
|
||||||
putValueArgument(index, argument.second)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, null)
|
}, null)
|
||||||
|
irFile.declarations += generatedClasses
|
||||||
}
|
}
|
||||||
|
|
||||||
private class BuiltFunctionReference(val functionReferenceClass: IrClass,
|
private class BuiltFunctionReference(val functionReferenceClass: IrClass,
|
||||||
@@ -249,16 +257,12 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass
|
|||||||
if (!isKFunction)
|
if (!isKFunction)
|
||||||
+irDelegatingConstructorCall(irBuiltIns.anyClass.owner.constructors.single())
|
+irDelegatingConstructorCall(irBuiltIns.anyClass.owner.constructors.single())
|
||||||
else +irDelegatingConstructorCall(kFunctionImplConstructorSymbol.owner).apply {
|
else +irDelegatingConstructorCall(kFunctionImplConstructorSymbol.owner).apply {
|
||||||
val stringType = irBuiltIns.stringType
|
// TODO: Remove as soon as IR declarations have their originalDescriptor.
|
||||||
val name = IrConstImpl(startOffset, endOffset, stringType,
|
val name = (referencedFunction.descriptor as? WrappedSimpleFunctionDescriptor)?.originalDescriptor?.name
|
||||||
IrConstKind.String, referencedFunction.name.asString())
|
?: referencedFunction.name
|
||||||
putValueArgument(0, name)
|
putValueArgument(0, irString(name.asString()))
|
||||||
val fqName = IrConstImpl(startOffset, endOffset, stringType, IrConstKind.String,
|
putValueArgument(1, irString((functionReference.symbol.owner).fullName))
|
||||||
(functionReference.symbol.owner).fullName)
|
putValueArgument(2, irBoolean(boundFunctionParameters.isNotEmpty()))
|
||||||
putValueArgument(1, fqName)
|
|
||||||
val bound = IrConstImpl.boolean(startOffset, endOffset, context.irBuiltIns.booleanType,
|
|
||||||
boundFunctionParameters.isNotEmpty())
|
|
||||||
putValueArgument(2, bound)
|
|
||||||
val needReceiver = boundFunctionParameters.singleOrNull()?.descriptor is ReceiverParameterDescriptor
|
val needReceiver = boundFunctionParameters.singleOrNull()?.descriptor is ReceiverParameterDescriptor
|
||||||
val receiver = if (needReceiver) irGet(valueParameters.single()) else irNull()
|
val receiver = if (needReceiver) irGet(valueParameters.single()) else irNull()
|
||||||
putValueArgument(3, receiver)
|
putValueArgument(3, receiver)
|
||||||
|
|||||||
+1
-17
@@ -22,9 +22,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.builders.*
|
import org.jetbrains.kotlin.ir.builders.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOriginImpl
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrLocalDelegatedProperty
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrLocalDelegatedPropertyReference
|
import org.jetbrains.kotlin.ir.expressions.IrLocalDelegatedPropertyReference
|
||||||
@@ -117,20 +115,6 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
|
|||||||
|
|
||||||
irFile.transformChildrenVoid(object : IrElementTransformerVoidWithContext() {
|
irFile.transformChildrenVoid(object : IrElementTransformerVoidWithContext() {
|
||||||
|
|
||||||
override fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty): IrStatement {
|
|
||||||
declaration.transformChildrenVoid(this)
|
|
||||||
|
|
||||||
val initializer = declaration.delegate.initializer!!
|
|
||||||
declaration.delegate.initializer = IrBlockImpl(initializer.startOffset, initializer.endOffset, initializer.type, null,
|
|
||||||
listOf(
|
|
||||||
declaration.getter,
|
|
||||||
declaration.setter,
|
|
||||||
initializer
|
|
||||||
).filterNotNull())
|
|
||||||
|
|
||||||
return declaration.delegate
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitPropertyReference(expression: IrPropertyReference): IrExpression {
|
override fun visitPropertyReference(expression: IrPropertyReference): IrExpression {
|
||||||
expression.transformChildrenVoid(this)
|
expression.transformChildrenVoid(this)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user