JVM: simplify choice of wrapped receiver descriptors

This commit is contained in:
Georgy Bronnikov
2019-07-25 15:11:48 +03:00
parent a10e57eaec
commit 3729c4e770
4 changed files with 12 additions and 23 deletions
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.backend.common.descriptors.*
import org.jetbrains.kotlin.backend.common.lower.VariableRemapper
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.ir.IrElement
@@ -152,10 +151,9 @@ fun IrValueParameter.copyTo(
varargElementType: IrType? = this.varargElementType,
defaultValue: IrExpressionBody? = this.defaultValue,
isCrossinline: Boolean = this.isCrossinline,
isNoinline: Boolean = this.isNoinline,
receiverToValue: Boolean = false
isNoinline: Boolean = this.isNoinline
): IrValueParameter {
val descriptor = if (this.descriptor is ReceiverParameterDescriptor && !receiverToValue) {
val descriptor = if (index < 0) {
WrappedReceiverParameterDescriptor(this.descriptor.annotations, this.descriptor.source)
} else {
WrappedValueParameterDescriptor(this.descriptor.annotations, this.descriptor.source)
@@ -262,8 +260,7 @@ fun IrFunction.copyValueParametersToStatic(
origin = originalDispatchReceiver.origin,
index = shift++,
type = type,
name = Name.identifier("\$this"),
receiverToValue = true
name = Name.identifier("\$this")
)
)
}
@@ -273,8 +270,7 @@ fun IrFunction.copyValueParametersToStatic(
target,
origin = originalExtensionReceiver.origin,
index = shift++,
name = Name.identifier("\$receiver"),
receiverToValue = true
name = Name.identifier("\$receiver")
)
)
}
@@ -541,14 +537,12 @@ fun createStaticFunctionWithReceivers(
this,
name = Name.identifier("this"),
index = offset++,
type = dispatchReceiverType!!,
receiverToValue = true
type = dispatchReceiverType!!
)
val extensionReceiver = oldFunction.extensionReceiverParameter?.copyTo(
this,
name = Name.identifier("receiver"),
index = offset++,
receiverToValue = true
index = offset++
)
valueParameters.addAll(listOfNotNull(dispatchReceiver, extensionReceiver) +
oldFunction.valueParameters.map { it.copyTo(this, index = it.index + offset) }
@@ -400,7 +400,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
coroutineConstructors += this
functionParameters.mapIndexedTo(valueParameters) { index, parameter ->
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index, receiverToValue = true)
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
}
val continuationParameter = coroutineBaseClassConstructor.valueParameters[0]
valueParameters += continuationParameter.copyTo(
@@ -445,7 +445,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
coroutineConstructors += this
boundParams.mapIndexedTo(valueParameters) { index, parameter ->
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index, receiverToValue = true)
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
}
val irBuilder = context.createIrBuilder(symbol, startOffset, endOffset)
@@ -497,7 +497,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
(unboundArgs + create1CompletionParameter)
.mapIndexedTo(valueParameters) { index, parameter ->
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index, receiverToValue = true)
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
}
this.createDispatchReceiverParameter()