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.visitors.IrElementVisitor
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.utils.addToStdlib.firstIsInstanceOrNull
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -356,13 +355,6 @@ class ExpressionCodegen(
}
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)
callee.parentAsClass.typeParameters + callee.typeParameters
else
@@ -376,16 +368,6 @@ class ExpressionCodegen(
arg != null -> {
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 -> {
assert(irParameter.varargElementType != null)
val type = typeMapper.mapType(
@@ -412,7 +394,6 @@ class ExpressionCodegen(
callGenerator.genCall(
callable,
defaultMask.generateOnStackIfNeeded(callGenerator, callee is IrConstructor, this),
this,
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
get() = this.classifierOrNull?.safeAs<IrTypeParameterSymbol>()?.owner?.isReified == true
@@ -28,12 +28,8 @@ import org.jetbrains.org.objectweb.asm.Type
interface IrCallGenerator {
fun genCall(callableMethod: Callable, callDefault: Boolean, codegen: ExpressionCodegen, expression: IrFunctionAccessExpression) {
if (!callDefault) {
callableMethod.genInvokeInstruction(codegen.mv)
} else {
(callableMethod as CallableMethod).genInvokeDefaultInstruction(codegen.mv)
}
fun genCall(callableMethod: Callable, codegen: ExpressionCodegen, expression: IrFunctionAccessExpression) {
callableMethod.genInvokeInstruction(codegen.mv)
}
fun beforeValueParametersStart() {
@@ -99,7 +99,6 @@ class IrInlineCodegen(
override fun genCall(
callableMethod: Callable,
callDefault: Boolean,
codegen: ExpressionCodegen,
expression: IrFunctionAccessExpression
) {
@@ -107,7 +106,7 @@ class IrInlineCodegen(
// TODO port inlining cycle detection to IrFunctionAccessExpression & pass it
state.globalInlineContext.enterIntoInlining(null)
try {
performInline(typeArguments, callDefault, codegen)
performInline(typeArguments, false, codegen)
} finally {
state.globalInlineContext.exitFromInliningOf(null)
}