JVM_IR drop 'SpecialMethodWithDefaultInfo#needsArgumentBoxing'

This commit is contained in:
Dmitry Petrov
2020-10-09 14:30:03 +03:00
parent a412596d8e
commit 6dd2d8bbdb
2 changed files with 15 additions and 25 deletions
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.name.Name
data class SpecialMethodWithDefaultInfo(
val defaultValueGenerator: (IrSimpleFunction) -> IrExpression,
val argumentsToCheck: Int,
val needsArgumentBoxing: Boolean = false,
val needsGenericSignature: Boolean = false,
)
@@ -67,7 +66,7 @@ class SpecialBridgeMethods(val context: CommonBackendContext) {
makeDescription(StandardNames.FqNames.collection, "contains", 1) to
SpecialMethodWithDefaultInfo(::constFalse, 1),
makeDescription(StandardNames.FqNames.mutableCollection, "remove", 1) to
SpecialMethodWithDefaultInfo(::constFalse, 1, needsArgumentBoxing = false),
SpecialMethodWithDefaultInfo(::constFalse, 1),
makeDescription(StandardNames.FqNames.map, "containsKey", 1) to
SpecialMethodWithDefaultInfo(::constFalse, 1),
makeDescription(StandardNames.FqNames.map, "containsValue", 1) to
@@ -253,7 +253,7 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass
bridgeTarget = when {
irFunction.isJvmAbstract(context.state.jvmDefaultMode) -> {
irClass.declarations.remove(irFunction)
irClass.addAbstractMethodStub(irFunction, specialBridge.methodInfo?.needsArgumentBoxing == true)
irClass.addAbstractMethodStub(irFunction)
}
irFunction.modality != Modality.FINAL -> {
val overriddenFromClass = irFunction.overriddenFromClass()!!
@@ -367,7 +367,7 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass
.map { it.copy(isFinal = false, isSynthetic = true, methodInfo = null) }
}
private fun IrClass.addAbstractMethodStub(irFunction: IrSimpleFunction, needsArgumentBoxing: Boolean) =
private fun IrClass.addAbstractMethodStub(irFunction: IrSimpleFunction) =
addFunction {
updateFrom(irFunction)
modality = Modality.ABSTRACT
@@ -382,7 +382,7 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass
copyCorrespondingPropertyFrom(irFunction)
dispatchReceiverParameter = thisReceiver?.copyTo(this, type = defaultType)
valueParameters = irFunction.valueParameters.map { param ->
param.copyTo(this, type = if (needsArgumentBoxing) param.type.makeNullable() else param.type)
param.copyTo(this, type = param.type)
}
overriddenSymbols = irFunction.overriddenSymbols.toList()
}
@@ -424,12 +424,7 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass
name = Name.identifier(specialBridge.signature.name)
returnType = specialBridge.substitutedReturnType ?: specialBridge.overridden.returnType.eraseTypeParameters()
}.apply {
copyParametersWithErasure(
this@addSpecialBridge,
specialBridge.overridden,
specialBridge.methodInfo?.needsArgumentBoxing == true,
specialBridge.substitutedParameterTypes
)
copyParametersWithErasure(this@addSpecialBridge, specialBridge.overridden, specialBridge.substitutedParameterTypes)
body = context.createIrBuilder(symbol, startOffset, endOffset).irBlockBody {
specialBridge.methodInfo?.let { info ->
@@ -512,32 +507,28 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass
private fun IrSimpleFunction.copyParametersWithErasure(
irClass: IrClass,
from: IrSimpleFunction,
forceArgumentBoxing: Boolean = false,
substitutedParameterTypes: List<IrType>? = null
) {
// This is a workaround for a bug affecting fake overrides. Sometimes we encounter fake overrides
// with dispatch receivers pointing at a superclass instead of the current class.
dispatchReceiverParameter = irClass.thisReceiver?.copyTo(this, type = irClass.defaultType)
extensionReceiverParameter = from.extensionReceiverParameter?.copyWithTypeErasure(this, forceArgumentBoxing)
extensionReceiverParameter = from.extensionReceiverParameter?.copyWithTypeErasure(this)
valueParameters = if (substitutedParameterTypes != null) {
from.valueParameters.zip(substitutedParameterTypes).map { (param, type) ->
param.copyWithTypeErasure(this, forceArgumentBoxing, type)
param.copyWithTypeErasure(this, type)
}
} else {
from.valueParameters.map { it.copyWithTypeErasure(this, forceArgumentBoxing) }
from.valueParameters.map { it.copyWithTypeErasure(this) }
}
}
private fun IrValueParameter.copyWithTypeErasure(
target: IrSimpleFunction,
forceArgumentBoxing: Boolean = false,
substitutedType: IrType? = null
): IrValueParameter = copyTo(
target, IrDeclarationOrigin.BRIDGE,
type = (substitutedType ?: type.eraseTypeParameters()).let { if (forceArgumentBoxing) it.makeNullable() else it },
// Currently there are no special bridge methods with vararg parameters, so we don't track substituted vararg element types.
varargElementType = varargElementType?.eraseTypeParameters()
)
private fun IrValueParameter.copyWithTypeErasure(target: IrSimpleFunction, substitutedType: IrType? = null): IrValueParameter =
copyTo(
target, IrDeclarationOrigin.BRIDGE,
type = (substitutedType ?: type.eraseTypeParameters()),
// Currently there are no special bridge methods with vararg parameters, so we don't track substituted vararg element types.
varargElementType = varargElementType?.eraseTypeParameters()
)
private fun IrBuilderWithScope.delegatingCall(
bridge: IrSimpleFunction,