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,
|
value: IrExpression,
|
||||||
newStatements: MutableList<IrStatement>,
|
newStatements: MutableList<IrStatement>,
|
||||||
declaration: IrDeclarationParent
|
declaration: IrDeclarationParent
|
||||||
): () -> IrExpressionWithCopy {
|
): () -> IrExpression {
|
||||||
return if (value.isPure(anyVariable = true, checkFields = false)) {
|
return if (value.isPure(anyVariable = true, checkFields = false)) {
|
||||||
{ value.deepCopyWithSymbols() as IrExpressionWithCopy }
|
{ value.deepCopyWithSymbols() }
|
||||||
} else {
|
} else {
|
||||||
val varDeclaration = JsIrBuilder.buildVar(value.type, declaration, initializer = value)
|
val varDeclaration = JsIrBuilder.buildVar(value.type, declaration, initializer = value)
|
||||||
newStatements += varDeclaration
|
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 toNotNullable = toType.makeNotNull()
|
||||||
val argumentInstance = argument()
|
val argumentInstance = argument()
|
||||||
val instanceCheck = generateTypeCheckNonNull(argumentInstance, toNotNullable)
|
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())
|
assert(!toType.isMarkedNullable())
|
||||||
return when {
|
return when {
|
||||||
toType is IrDynamicType -> argument
|
toType is IrDynamicType -> argument
|
||||||
@@ -257,7 +257,7 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass {
|
|||||||
putValueArgument(0, argument)
|
putValueArgument(0, argument)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateTypeCheckWithTypeParameter(argument: IrExpressionWithCopy, toType: IrType): IrExpression {
|
private fun generateTypeCheckWithTypeParameter(argument: IrExpression, toType: IrType): IrExpression {
|
||||||
val typeParameterSymbol =
|
val typeParameterSymbol =
|
||||||
(toType.classifierOrNull as? IrTypeParameterSymbol) ?: error("expected type parameter, but $toType")
|
(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" }
|
// assert(!typeParameter.isReified) { "reified parameters have to be lowered before" }
|
||||||
|
|
||||||
return typeParameter.superTypes.fold<IrType, IrExpression?>(null) { r, t ->
|
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())
|
val check = generateTypeCheckNonNull(argument.copy(), t.makeNotNull())
|
||||||
|
|
||||||
if (r == null) {
|
if (r == null) {
|
||||||
@@ -353,7 +354,7 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : BodyLoweringPass {
|
|||||||
val isNullable = expression.argument.type.isNullable()
|
val isNullable = expression.argument.type.isNullable()
|
||||||
val toType = expression.typeOperand
|
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())
|
shr(shl(and(arg, mask), shift), shift.copy())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -113,7 +113,7 @@ fun StatementGenerator.generateReceiver(defaultStartOffset: Int, defaultEndOffse
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (receiverExpression is IrExpressionWithCopy)
|
if (receiverExpression is IrExpressionWithCopy)
|
||||||
RematerializableValue(receiverExpression)
|
RematerializableValue(receiverExpression.type, receiverExpression)
|
||||||
else
|
else
|
||||||
OnceExpressionValue(receiverExpression)
|
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.expressions.IrStatementContainer
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
|
|
||||||
class RematerializableValue(val irExpression: IrExpressionWithCopy) : IntermediateValue {
|
class RematerializableValue(override val type: IrType, val irExpression: IrExpressionWithCopy) : IntermediateValue {
|
||||||
override val type: IrType get() = irExpression.type
|
|
||||||
|
|
||||||
override fun load(): IrExpression = irExpression.copy()
|
override fun load(): IrExpression = irExpression.copy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ interface IrExpression : IrStatement, IrVarargElement, IrAttributeContainer {
|
|||||||
accept(transformer, data) as IrExpression
|
accept(transformer, data) as IrExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IrExpressionWithCopy : IrExpression {
|
interface IrExpressionWithCopy {
|
||||||
fun copy(): IrExpressionWithCopy
|
fun copy(): IrExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user