Remove handling of default arguments from codegen

This commit is contained in:
Georgy Bronnikov
2019-07-11 20:17:37 +03:00
parent 4d50086d35
commit f9391ec790
3 changed files with 3 additions and 46 deletions
@@ -37,7 +37,6 @@ import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.resolve.jvm.AsmTypes import org.jetbrains.kotlin.resolve.jvm.AsmTypes
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.DEFAULT_CONSTRUCTOR_MARKER
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import org.jetbrains.kotlin.utils.addToStdlib.safeAs import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -356,13 +355,6 @@ class ExpressionCodegen(
} }
callGenerator.beforeValueParametersStart() callGenerator.beforeValueParametersStart()
val extraArgsShift =
when {
callee is IrConstructor && callee.parentAsClass.isEnumClass -> 2
callee is IrConstructor && callee.parentAsClass.isInner -> 1 // skip the `$outer` parameter
else -> 0
}
val defaultMask = DefaultCallArgs(callable.valueParameterTypes.size - extraArgsShift)
val typeParameters = if (callee is IrConstructor) val typeParameters = if (callee is IrConstructor)
callee.parentAsClass.typeParameters + callee.typeParameters callee.parentAsClass.typeParameters + callee.typeParameters
else else
@@ -376,16 +368,6 @@ class ExpressionCodegen(
arg != null -> { arg != null -> {
callGenerator.genValueAndPut(irParameter, arg, parameterType, this@ExpressionCodegen, data) callGenerator.genValueAndPut(irParameter, arg, parameterType, this@ExpressionCodegen, data)
} }
irParameter.hasDefaultValue() -> {
callGenerator.putValueIfNeeded(
parameterType,
StackValue.createDefaultValue(parameterType),
ValueKind.DEFAULT_PARAMETER,
i,
this@ExpressionCodegen
)
defaultMask.mark(i - extraArgsShift/*TODO switch to separate lower*/)
}
else -> { else -> {
assert(irParameter.varargElementType != null) assert(irParameter.varargElementType != null)
val type = typeMapper.mapType( val type = typeMapper.mapType(
@@ -412,7 +394,6 @@ class ExpressionCodegen(
callGenerator.genCall( callGenerator.genCall(
callable, callable,
defaultMask.generateOnStackIfNeeded(callGenerator, callee is IrConstructor, this),
this, this,
expression expression
) )
@@ -1231,25 +1212,6 @@ class ExpressionCodegen(
} }
} }
fun DefaultCallArgs.generateOnStackIfNeeded(callGenerator: IrCallGenerator, isConstructor: Boolean, codegen: ExpressionCodegen): Boolean {
val toInts = toInts()
if (toInts.isNotEmpty()) {
for (mask in toInts) {
callGenerator.putValueIfNeeded(Type.INT_TYPE, StackValue.constant(mask, Type.INT_TYPE), ValueKind.DEFAULT_MASK, -1, codegen)
}
val parameterType = if (isConstructor) DEFAULT_CONSTRUCTOR_MARKER else OBJECT_TYPE
callGenerator.putValueIfNeeded(
parameterType,
StackValue.constant(null, parameterType),
ValueKind.METHOD_HANDLE_IN_DEFAULT,
-1,
codegen
)
}
return toInts.isNotEmpty()
}
val IrType.isReifiedTypeParameter: Boolean val IrType.isReifiedTypeParameter: Boolean
get() = this.classifierOrNull?.safeAs<IrTypeParameterSymbol>()?.owner?.isReified == true get() = this.classifierOrNull?.safeAs<IrTypeParameterSymbol>()?.owner?.isReified == true
@@ -28,12 +28,8 @@ import org.jetbrains.org.objectweb.asm.Type
interface IrCallGenerator { interface IrCallGenerator {
fun genCall(callableMethod: Callable, callDefault: Boolean, codegen: ExpressionCodegen, expression: IrFunctionAccessExpression) { fun genCall(callableMethod: Callable, codegen: ExpressionCodegen, expression: IrFunctionAccessExpression) {
if (!callDefault) { callableMethod.genInvokeInstruction(codegen.mv)
callableMethod.genInvokeInstruction(codegen.mv)
} else {
(callableMethod as CallableMethod).genInvokeDefaultInstruction(codegen.mv)
}
} }
fun beforeValueParametersStart() { fun beforeValueParametersStart() {
@@ -99,7 +99,6 @@ class IrInlineCodegen(
override fun genCall( override fun genCall(
callableMethod: Callable, callableMethod: Callable,
callDefault: Boolean,
codegen: ExpressionCodegen, codegen: ExpressionCodegen,
expression: IrFunctionAccessExpression expression: IrFunctionAccessExpression
) { ) {
@@ -107,7 +106,7 @@ class IrInlineCodegen(
// TODO port inlining cycle detection to IrFunctionAccessExpression & pass it // TODO port inlining cycle detection to IrFunctionAccessExpression & pass it
state.globalInlineContext.enterIntoInlining(null) state.globalInlineContext.enterIntoInlining(null)
try { try {
performInline(typeArguments, callDefault, codegen) performInline(typeArguments, false, codegen)
} finally { } finally {
state.globalInlineContext.exitFromInliningOf(null) state.globalInlineContext.exitFromInliningOf(null)
} }