From e0823e20c78dc5e50561c9a8b2d0c5cb887ec5af Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 23 Aug 2019 18:44:23 +0200 Subject: [PATCH] JVM IR: do not use AsmUtil.genToString AsmUtil.genToString requires an instance of KotlinTypeMapper and calls KotlinTypeMapper.mapToCallableMethod inside, which (in subsequent commits) we're getting rid of in the IR backend --- .../backend/jvm/codegen/ExpressionCodegen.kt | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) 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 65e5350ceec..556980ff69a 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 @@ -695,17 +695,17 @@ class ExpressionCodegen( // Convert single arg to string. val arg = expression.arguments[0] val result = arg.accept(this, data).boxInlineClasses(arg.type).materialized - if (!arg.type.isString()) - AsmUtil.genToString(StackValue.onStack(result.type), result.type, result.kotlinType, typeMapper.kotlinTypeMapper) - .put(expression.asmType, mv) + if (!arg.type.isString()) { + result.genToString(mv) + } } arity == 2 && expression.arguments[0].type.isStringClassType() -> { // Call the stringPlus intrinsic - expression.arguments.forEach { - val result = it.accept(this, data).boxInlineClasses(it.type).materialized - val type = result.type - if (type.sort != Type.OBJECT) - AsmUtil.genToString(StackValue.onStack(type), type, result.kotlinType, typeMapper.kotlinTypeMapper).put(expression.asmType, mv) + for (argument in expression.arguments) { + val result = argument.accept(this, data).boxInlineClasses(argument.type).materialized + if (result.type.sort != Type.OBJECT) { + result.genToString(mv) + } } mv.invokestatic( IrIntrinsicMethods.INTRINSICS_CLASS_NAME, @@ -717,8 +717,8 @@ class ExpressionCodegen( else -> { // Use StringBuilder to concatenate. genStringBuilderConstructor(mv) - expression.arguments.forEach { - genInvokeAppendMethod(mv, it.accept(this, data).boxInlineClasses(it.type).materialized.type, null) + for (argument in expression.arguments) { + genInvokeAppendMethod(mv, argument.accept(this, data).boxInlineClasses(argument.type).materialized.type, null) } mv.invokevirtual("java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false) } @@ -726,6 +726,12 @@ class ExpressionCodegen( return expression.onStack } + private fun MaterialValue.genToString(v: InstructionAdapter) { + val asmType = + if (irType.getClass()?.isInline == true) OBJECT_TYPE else stringValueOfType(type) + v.invokestatic("java/lang/String", "valueOf", Type.getMethodDescriptor(AsmTypes.JAVA_STRING_TYPE, asmType), false) + } + override fun visitWhileLoop(loop: IrWhileLoop, data: BlockInfo): PromisedValue { val continueLabel = markNewLabel() val endLabel = Label()