IR: do not inherit IrExpressionWithCopy from IrExpression
This commit is contained in:
+7
-6
@@ -197,9 +197,9 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass {
|
||||
value: IrExpression,
|
||||
newStatements: MutableList<IrStatement>,
|
||||
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<IrType, IrExpression?>(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())
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ fun StatementGenerator.generateReceiver(defaultStartOffset: Int, defaultEndOffse
|
||||
}
|
||||
|
||||
if (receiverExpression is IrExpressionWithCopy)
|
||||
RematerializableValue(receiverExpression)
|
||||
RematerializableValue(receiverExpression.type, receiverExpression)
|
||||
else
|
||||
OnceExpressionValue(receiverExpression)
|
||||
}
|
||||
|
||||
+1
-3
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user