Create wrapped receiver descriptors where needed
This commit is contained in:
+1
-7
@@ -394,13 +394,7 @@ open class WrappedSimpleFunctionDescriptor(
|
||||
(containingDeclaration as ClassDescriptor).thisAsReceiverParameter
|
||||
}
|
||||
|
||||
val extensionReceiver by lazy {
|
||||
owner.extensionReceiverParameter?.let {
|
||||
ReceiverParameterDescriptorImpl(this, ExtensionReceiver(it.descriptor, it.type.toKotlinType(), null), Annotations.EMPTY)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getExtensionReceiverParameter() = extensionReceiver
|
||||
override fun getExtensionReceiverParameter() = owner.extensionReceiverParameter?.descriptor as? ReceiverParameterDescriptor
|
||||
override fun getTypeParameters() = owner.typeParameters.map { it.descriptor }
|
||||
override fun getValueParameters() = owner.valueParameters
|
||||
.asSequence()
|
||||
|
||||
@@ -23,6 +23,7 @@ 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
|
||||
@@ -151,9 +152,14 @@ fun IrValueParameter.copyTo(
|
||||
varargElementType: IrType? = this.varargElementType,
|
||||
defaultValue: IrExpressionBody? = this.defaultValue,
|
||||
isCrossinline: Boolean = this.isCrossinline,
|
||||
isNoinline: Boolean = this.isNoinline
|
||||
isNoinline: Boolean = this.isNoinline,
|
||||
receiverToValue: Boolean = false
|
||||
): IrValueParameter {
|
||||
val descriptor = WrappedValueParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)
|
||||
val descriptor = if (this.descriptor is ReceiverParameterDescriptor && !receiverToValue) {
|
||||
WrappedReceiverParameterDescriptor(this.descriptor.annotations, this.descriptor.source)
|
||||
} else {
|
||||
WrappedValueParameterDescriptor(this.descriptor.annotations, this.descriptor.source)
|
||||
}
|
||||
val symbol = IrValueParameterSymbolImpl(descriptor)
|
||||
val defaultValueCopy = defaultValue?.deepCopyWithVariables()
|
||||
defaultValueCopy?.patchDeclarationParents(irFunction)
|
||||
@@ -256,7 +262,8 @@ fun IrFunction.copyValueParametersToStatic(
|
||||
origin = originalDispatchReceiver.origin,
|
||||
index = shift++,
|
||||
type = type,
|
||||
name = Name.identifier("\$this")
|
||||
name = Name.identifier("\$this"),
|
||||
receiverToValue = true
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -266,7 +273,8 @@ fun IrFunction.copyValueParametersToStatic(
|
||||
target,
|
||||
origin = originalExtensionReceiver.origin,
|
||||
index = shift++,
|
||||
name = Name.identifier("\$receiver")
|
||||
name = Name.identifier("\$receiver"),
|
||||
receiverToValue = true
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -533,12 +541,14 @@ fun createStaticFunctionWithReceivers(
|
||||
this,
|
||||
name = Name.identifier("this"),
|
||||
index = offset++,
|
||||
type = dispatchReceiverType!!
|
||||
type = dispatchReceiverType!!,
|
||||
receiverToValue = true
|
||||
)
|
||||
val extensionReceiver = oldFunction.extensionReceiverParameter?.copyTo(
|
||||
this,
|
||||
name = Name.identifier("receiver"),
|
||||
index = offset++
|
||||
index = offset++,
|
||||
receiverToValue = true
|
||||
)
|
||||
valueParameters.addAll(listOfNotNull(dispatchReceiver, extensionReceiver) +
|
||||
oldFunction.valueParameters.map { it.copyTo(this, index = it.index + offset) }
|
||||
|
||||
+3
-3
@@ -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)
|
||||
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index, receiverToValue = true)
|
||||
}
|
||||
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)
|
||||
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index, receiverToValue = true)
|
||||
}
|
||||
|
||||
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)
|
||||
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index, receiverToValue = true)
|
||||
}
|
||||
|
||||
this.createDispatchReceiverParameter()
|
||||
|
||||
+7
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.backend.common.bridges.FunctionHandle
|
||||
import org.jetbrains.kotlin.backend.common.bridges.findAllReachableDeclarations
|
||||
import org.jetbrains.kotlin.backend.common.bridges.findConcreteSuperDeclaration
|
||||
import org.jetbrains.kotlin.backend.common.bridges.generateBridges
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.WrappedReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.WrappedSimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.WrappedValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.ir.*
|
||||
@@ -23,6 +24,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.eraseTypeParameters
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.hasJvmDefault
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
@@ -320,7 +322,11 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass
|
||||
}
|
||||
|
||||
private fun IrValueParameter.copyWithTypeErasure(target: IrSimpleFunction): IrValueParameter {
|
||||
val descriptor = WrappedValueParameterDescriptor(this.descriptor.annotations)
|
||||
val descriptor = if (this.descriptor is ReceiverParameterDescriptor) {
|
||||
WrappedReceiverParameterDescriptor(this.descriptor.annotations)
|
||||
} else {
|
||||
WrappedValueParameterDescriptor(this.descriptor.annotations)
|
||||
}
|
||||
return IrValueParameterImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
IrDeclarationOrigin.BRIDGE,
|
||||
|
||||
+2
-1
@@ -240,7 +240,8 @@ internal class CallableReferenceLowering(val context: JvmBackendContext) : FileL
|
||||
valueParameters += param.copyTo(
|
||||
this,
|
||||
index = valueParameters.size,
|
||||
type = param.type.substitute(typeArgumentsMap)
|
||||
type = param.type.substitute(typeArgumentsMap),
|
||||
receiverToValue = true
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+7
-4
@@ -123,11 +123,14 @@ class MemoizedInlineClassReplacements {
|
||||
|
||||
for ((index, parameter) in function.explicitParameters.withIndex()) {
|
||||
val name = if (parameter == function.extensionReceiverParameter) Name.identifier("\$receiver") else parameter.name
|
||||
val newParameter = parameter.copyTo(this, index = index - 1, name = name)
|
||||
if (parameter == function.dispatchReceiverParameter)
|
||||
val newParameter: IrValueParameter
|
||||
if (parameter == function.dispatchReceiverParameter) {
|
||||
newParameter = parameter.copyTo(this, index = -1, name = name)
|
||||
dispatchReceiverParameter = newParameter
|
||||
else
|
||||
} else {
|
||||
newParameter = parameter.copyTo(this, index = index - 1, name = name, receiverToValue = true)
|
||||
valueParameters.add(newParameter)
|
||||
}
|
||||
parameterMap[parameter.symbol] = newParameter
|
||||
}
|
||||
}
|
||||
@@ -147,7 +150,7 @@ class MemoizedInlineClassReplacements {
|
||||
else -> parameter.name
|
||||
}
|
||||
|
||||
val newParameter = parameter.copyTo(this, index = index, name = name)
|
||||
val newParameter = parameter.copyTo(this, index = index, name = name, receiverToValue = true)
|
||||
valueParameters.add(newParameter)
|
||||
parameterMap[parameter.symbol] = newParameter
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user