diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index f76b530caf9..586e08d60ba 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.codegen.* import org.jetbrains.kotlin.codegen.AsmUtil.* import org.jetbrains.kotlin.codegen.ExpressionCodegen.putReifiedOperationMarkerIfTypeIsReifiedParameter -import org.jetbrains.kotlin.codegen.StackValue.* import org.jetbrains.kotlin.codegen.inline.* import org.jetbrains.kotlin.codegen.inline.ReifiedTypeInliner.OperationKind.AS import org.jetbrains.kotlin.codegen.inline.ReifiedTypeInliner.OperationKind.SAFE_AS @@ -150,7 +149,7 @@ class ExpressionCodegen( // idempotent and must always be done before generating other values or emitting raw bytecode. internal fun StackValue.materialize(): StackValue { put(type, kotlinType, mv) - return onStack(type, kotlinType) + return StackValue.onStack(type, kotlinType) } // Same as above, but if the type is Unit, do not materialize the actual push of a constant value. @@ -294,7 +293,7 @@ class ExpressionCodegen( } private fun visitStatementContainer(container: IrStatementContainer, data: BlockInfo): StackValue = - container.statements.fold(none()) { prev, exp -> + container.statements.fold(StackValue.none()) { prev, exp -> prev.discard() exp.accept(this, data).also { (exp as? IrExpression)?.markEndOfStatementIfNeeded() } } @@ -428,10 +427,10 @@ class ExpressionCodegen( mv.athrow() return expression.onStack } else if (expression.descriptor is ConstructorDescriptor) { - return none() + return StackValue.none() } - return onStack(callable.returnType, returnType).coerce(expression.type) + return StackValue.onStack(callable.returnType, returnType).coerce(expression.type) } override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall, data: BlockInfo): StackValue { @@ -452,7 +451,7 @@ class ExpressionCodegen( } data.variables.add(VariableInfo(declaration, index, varType, markNewLabel())) - return none() + return StackValue.none() } override fun visitGetValue(expression: IrGetValue, data: BlockInfo): StackValue { @@ -495,7 +494,7 @@ class ExpressionCodegen( expression.markLineNumber(startOffset = true) generateFieldValue(expression, data, true).store(expressionValue.accept(this, data), mv) } - return none().coerce(expression.type) + return StackValue.none().coerce(expression.type) } /** @@ -530,7 +529,7 @@ class ExpressionCodegen( expression.value.markLineNumber(startOffset = true) val value = expression.value.accept(this, data) StackValue.local(findLocalIndex(expression.symbol), expression.descriptor.asmType).store(value, mv) - return none().coerce(expression.type) + return StackValue.none().coerce(expression.type) } override fun visitConst(expression: IrConst, data: BlockInfo): StackValue { @@ -552,7 +551,7 @@ class ExpressionCodegen( // TODO maybe remove? override fun visitClass(declaration: IrClass, data: BlockInfo): StackValue { classCodegen.generateLocalClass(declaration) - return none() + return StackValue.none() } override fun visitVararg(expression: IrVararg, data: BlockInfo): StackValue { @@ -666,7 +665,7 @@ class ExpressionCodegen( mv, "java/lang/UnsupportedOperationException", "Non-local returns are not allowed with inlining disabled" ) - return none() + return StackValue.none() } val returnType = typeMapper.mapReturnType(owner.descriptor) @@ -680,7 +679,7 @@ class ExpressionCodegen( mv.areturn(returnType) mv.mark(afterReturnLabel) mv.nop()/*TODO check RESTORE_STACK_IN_TRY_CATCH processor*/ - return expression.onStack + return StackValue.none() } override fun visitWhen(expression: IrWhen, data: BlockInfo): StackValue { @@ -713,7 +712,7 @@ class ExpressionCodegen( } // Produce the default value for the type. Doesn't really matter right now, as non-exhaustive // conditionals cannot be used as expressions. - val result = none().coerce(expression.type).materializeNonUnit() + val result = StackValue.none().coerce(expression.type).materializeNonUnit() mv.mark(endLabel) return result } @@ -747,7 +746,7 @@ class ExpressionCodegen( state.languageVersionSettings.isReleaseCoroutines() ) } - onStack(boxedType).coerce(expression.type) + StackValue.onStack(boxedType).coerce(expression.type) } IrTypeOperator.INSTANCEOF, IrTypeOperator.NOT_INSTANCEOF -> { @@ -876,7 +875,7 @@ class ExpressionCodegen( ?: throw AssertionError("Target label for break/continue not found") mv.fixStackAndJump(if (jump is IrBreak) stackElement.breakLabel else stackElement.continueLabel) mv.mark(endLabel) - return none() + return StackValue.none() } override fun visitDoWhileLoop(loop: IrDoWhileLoop, data: BlockInfo): StackValue { @@ -911,9 +910,9 @@ class ExpressionCodegen( mv.nop() val tryResult = aTry.tryResult.accept(this, data) val isExpression = true //TODO: more wise check is required - var savedValue: Local? = null + var savedValue: StackValue.Local? = null if (isExpression) { - savedValue = local(frame.enterTemp(aTry.asmType), aTry.asmType) + savedValue = StackValue.local(frame.enterTemp(aTry.asmType), aTry.asmType) savedValue.store(tryResult.coerce(aTry.type), mv) } else { tryResult.discard() @@ -989,9 +988,9 @@ class ExpressionCodegen( if (savedValue != null) { savedValue.put(mv) frame.leaveTemp(aTry.asmType) - return onStack(aTry.asmType) + return StackValue.onStack(aTry.asmType) } - return none() + return StackValue.none() } private fun genTryCatchCover(catchStart: Label, tryStart: Label, tryEnd: Label, tryGaps: List>, type: String?) { @@ -1039,7 +1038,7 @@ class ExpressionCodegen( expression.markLineNumber(startOffset = true) expression.value.accept(this, data).coerce(AsmTypes.JAVA_THROWABLE_TYPE).materialize() mv.athrow() - return none() + return StackValue.none() } override fun visitGetClass(expression: IrGetClass, data: BlockInfo): StackValue {