From fde7314aaf994267a415c57e688b52fcc5518168 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 22 Jul 2020 21:16:57 +0200 Subject: [PATCH] IR: do not inherit IrExpressionWithCopy from IrExpression --- .../ir/backend/js/lower/TypeOperatorLowering.kt | 13 +++++++------ .../psi2ir/generators/ArgumentsGenerationUtils.kt | 2 +- .../psi2ir/intermediate/RematerializableValue.kt | 4 +--- .../jetbrains/kotlin/ir/expressions/IrExpression.kt | 5 ++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/TypeOperatorLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/TypeOperatorLowering.kt index 65d620beca0..27dc438b52d 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/TypeOperatorLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/TypeOperatorLowering.kt @@ -197,9 +197,9 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass { value: IrExpression, newStatements: MutableList, declaration: IrDeclarationParent - ): () -> IrExpressionWithCopy { + ): () -> IrExpression { return if (value.isPure(anyVariable = true, checkFields = false)) { - { value.deepCopyWithSymbols() as IrExpressionWithCopy } + { value.deepCopyWithSymbols() } } else { val varDeclaration = JsIrBuilder.buildVar(value.type, declaration, initializer = value) newStatements += varDeclaration @@ -207,7 +207,7 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass { } } - private fun generateTypeCheck(argument: () -> IrExpressionWithCopy, toType: IrType): IrExpression { + private fun generateTypeCheck(argument: () -> IrExpression, toType: IrType): IrExpression { val toNotNullable = toType.makeNotNull() val argumentInstance = argument() val instanceCheck = generateTypeCheckNonNull(argumentInstance, toNotNullable) @@ -227,7 +227,7 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass { } } - private fun generateTypeCheckNonNull(argument: IrExpressionWithCopy, toType: IrType): IrExpression { + private fun generateTypeCheckNonNull(argument: IrExpression, toType: IrType): IrExpression { assert(!toType.isMarkedNullable()) return when { toType is IrDynamicType -> argument @@ -257,7 +257,7 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass { putValueArgument(0, argument) } - private fun generateTypeCheckWithTypeParameter(argument: IrExpressionWithCopy, toType: IrType): IrExpression { + private fun generateTypeCheckWithTypeParameter(argument: IrExpression, toType: IrType): IrExpression { val typeParameterSymbol = (toType.classifierOrNull as? IrTypeParameterSymbol) ?: error("expected type parameter, but $toType") @@ -267,6 +267,7 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass { // assert(!typeParameter.isReified) { "reified parameters have to be lowered before" } return typeParameter.superTypes.fold(null) { r, t -> + require(argument is IrExpressionWithCopy) { "Not a copyable expression: ${argument.render()}" } val check = generateTypeCheckNonNull(argument.copy(), t.makeNotNull()) if (r == null) { @@ -353,7 +354,7 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass { val isNullable = expression.argument.type.isNullable() val toType = expression.typeOperand - fun maskOp(arg: IrExpression, mask: IrExpression, shift: IrExpressionWithCopy) = calculator.run { + fun maskOp(arg: IrExpression, mask: IrExpression, shift: IrConst<*>) = calculator.run { shr(shl(and(arg, mask), shift), shift.copy()) } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt index 974fdf71dd3..2fd8dae8aff 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt @@ -113,7 +113,7 @@ fun StatementGenerator.generateReceiver(defaultStartOffset: Int, defaultEndOffse } if (receiverExpression is IrExpressionWithCopy) - RematerializableValue(receiverExpression) + RematerializableValue(receiverExpression.type, receiverExpression) else OnceExpressionValue(receiverExpression) } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/RematerializableValue.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/RematerializableValue.kt index dd1f5fd9b54..17c805aaa2f 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/RematerializableValue.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/RematerializableValue.kt @@ -23,9 +23,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpressionWithCopy import org.jetbrains.kotlin.ir.expressions.IrStatementContainer import org.jetbrains.kotlin.ir.types.IrType -class RematerializableValue(val irExpression: IrExpressionWithCopy) : IntermediateValue { - override val type: IrType get() = irExpression.type - +class RematerializableValue(override val type: IrType, val irExpression: IrExpressionWithCopy) : IntermediateValue { override fun load(): IrExpression = irExpression.copy() } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrExpression.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrExpression.kt index b64df400fbc..0eb33e206ee 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrExpression.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrExpression.kt @@ -28,7 +28,6 @@ interface IrExpression : IrStatement, IrVarargElement, IrAttributeContainer { accept(transformer, data) as IrExpression } -interface IrExpressionWithCopy : IrExpression { - fun copy(): IrExpressionWithCopy +interface IrExpressionWithCopy { + fun copy(): IrExpression } -