[K/N] Refactor default argument lowering to avoid boxing
Current inline classes API is not compatible between different backends. So implementing common function required for this optimization was not possible in Native backend. So, common default arguments lowering was refactored to make bigger piece of code replaceable in backends. ^KT-57860
This commit is contained in:
committed by
Space Team
parent
2aea5822b2
commit
f55fd481e9
@@ -288,10 +288,6 @@ class JsIrBackendContext(
|
||||
}
|
||||
}
|
||||
|
||||
override fun unfoldInlineClassType(irType: IrType): IrType? {
|
||||
return inlineClassesUtils.getInlinedClass(irType)?.typeWith()
|
||||
}
|
||||
|
||||
override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -5,11 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.backend.js.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.lower.DefaultArgumentFunctionFactory
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.makeNullable
|
||||
import org.jetbrains.kotlin.ir.util.copyTypeParametersFrom
|
||||
import org.jetbrains.kotlin.ir.util.defaultType
|
||||
@@ -17,13 +19,16 @@ import org.jetbrains.kotlin.ir.util.isTopLevel
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class JsDefaultArgumentFunctionFactory(override val context: JsIrBackendContext) : DefaultArgumentFunctionFactory(context) {
|
||||
class JsDefaultArgumentFunctionFactory(context: CommonBackendContext) : DefaultArgumentFunctionFactory(context) {
|
||||
|
||||
override fun IrType.hasNullAsUndefinedValue() = false
|
||||
|
||||
override fun IrFunction.generateDefaultArgumentStubFrom(original: IrFunction, useConstructorMarker: Boolean) {
|
||||
copyAttributesFrom(original)
|
||||
copyTypeParametersFrom(original)
|
||||
copyReturnTypeFrom(original)
|
||||
copyReceiversFrom(original)
|
||||
copyValueParametersFrom(original, wrapWithNullable = false)
|
||||
copyValueParametersFrom(original)
|
||||
|
||||
if (!original.isTopLevel) {
|
||||
introduceContextParam()
|
||||
|
||||
+5
-5
@@ -29,12 +29,12 @@ import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
import org.jetbrains.kotlin.utils.memoryOptimizedMap
|
||||
import org.jetbrains.kotlin.utils.memoryOptimizedPlus
|
||||
|
||||
class JsDefaultArgumentStubGenerator(override val context: JsIrBackendContext) :
|
||||
DefaultArgumentStubGenerator(
|
||||
context,
|
||||
class JsDefaultArgumentStubGenerator(context: JsIrBackendContext) :
|
||||
DefaultArgumentStubGenerator<JsIrBackendContext>(
|
||||
context = context,
|
||||
factory = JsDefaultArgumentFunctionFactory(context),
|
||||
skipExternalMethods = true,
|
||||
forceSetOverrideSymbols = false,
|
||||
factory = JsDefaultArgumentFunctionFactory(context)
|
||||
forceSetOverrideSymbols = false
|
||||
) {
|
||||
|
||||
private fun IrBuilderWithScope.createDefaultResolutionExpression(
|
||||
|
||||
+4
-5
@@ -22,16 +22,15 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.util.copyAnnotations
|
||||
import org.jetbrains.kotlin.ir.util.defaultType
|
||||
import org.jetbrains.kotlin.ir.util.isTopLevel
|
||||
import org.jetbrains.kotlin.ir.util.isVararg
|
||||
|
||||
class JsDefaultParameterInjector(override val context: JsIrBackendContext) :
|
||||
DefaultParameterInjector(
|
||||
class JsDefaultParameterInjector(context: JsIrBackendContext) :
|
||||
DefaultParameterInjector<JsIrBackendContext>(
|
||||
context,
|
||||
factory = JsDefaultArgumentFunctionFactory(context),
|
||||
skipExternalMethods = true,
|
||||
forceSetOverrideSymbols = false,
|
||||
factory = JsDefaultArgumentFunctionFactory(context)
|
||||
forceSetOverrideSymbols = false
|
||||
) {
|
||||
override fun nullConst(startOffset: Int, endOffset: Int, irParameter: IrValueParameter): IrExpression? =
|
||||
if (irParameter.isVararg && !irParameter.hasDefaultValue()) {
|
||||
|
||||
Reference in New Issue
Block a user