From 5e6aa649ed3906e44f56ca4f9ad49ec9f313dbed Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Thu, 9 Feb 2023 13:22:05 +0200 Subject: [PATCH] [IR] Extracted implicitCastIfNeeded to common utils --- .../kotlin/backend/common/lower/inline/FunctionInlining.kt | 7 ------- .../ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt index 7d2c6270051..3933d577abc 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt @@ -407,13 +407,6 @@ class FunctionInlining( override fun visitElement(element: IrElement) = element.accept(this, null) } - private fun IrExpression.implicitCastIfNeededTo(type: IrType) = - // No need to cast expressions of type nothing - if (type == this.type || (insertAdditionalImplicitCasts && this.type == context.irBuiltIns.nothingType)) - this - else - IrTypeOperatorCallImpl(startOffset, endOffset, type, IrTypeOperator.IMPLICIT_CAST, type, this) - // With `insertAdditionalImplicitCasts` flag we sometimes insert // casts to inline lambda parameters before calling `invoke` on them. // Unwrapping these casts helps us satisfy inline lambda call detection logic. diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt index 0a6a9e18f0d..33011b622b3 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt @@ -183,6 +183,12 @@ fun IrExpression.coerceToUnitIfNeeded(valueType: IrType, irBuiltIns: IrBuiltIns, ) } +fun IrExpression.implicitCastIfNeededTo(type: IrType) = + if (type == this.type || this.type.isNothing()) + this + else + IrTypeOperatorCallImpl(startOffset, endOffset, type, IrTypeOperator.IMPLICIT_CAST, type, this) + fun IrFunctionAccessExpression.usesDefaultArguments(): Boolean = symbol.owner.valueParameters.any { this.getValueArgument(it.index) == null }