JVM: simplify choice of wrapped receiver descriptors
This commit is contained in:
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.backend.common.descriptors.*
|
|||||||
import org.jetbrains.kotlin.backend.common.lower.VariableRemapper
|
import org.jetbrains.kotlin.backend.common.lower.VariableRemapper
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
@@ -152,10 +151,9 @@ fun IrValueParameter.copyTo(
|
|||||||
varargElementType: IrType? = this.varargElementType,
|
varargElementType: IrType? = this.varargElementType,
|
||||||
defaultValue: IrExpressionBody? = this.defaultValue,
|
defaultValue: IrExpressionBody? = this.defaultValue,
|
||||||
isCrossinline: Boolean = this.isCrossinline,
|
isCrossinline: Boolean = this.isCrossinline,
|
||||||
isNoinline: Boolean = this.isNoinline,
|
isNoinline: Boolean = this.isNoinline
|
||||||
receiverToValue: Boolean = false
|
|
||||||
): IrValueParameter {
|
): IrValueParameter {
|
||||||
val descriptor = if (this.descriptor is ReceiverParameterDescriptor && !receiverToValue) {
|
val descriptor = if (index < 0) {
|
||||||
WrappedReceiverParameterDescriptor(this.descriptor.annotations, this.descriptor.source)
|
WrappedReceiverParameterDescriptor(this.descriptor.annotations, this.descriptor.source)
|
||||||
} else {
|
} else {
|
||||||
WrappedValueParameterDescriptor(this.descriptor.annotations, this.descriptor.source)
|
WrappedValueParameterDescriptor(this.descriptor.annotations, this.descriptor.source)
|
||||||
@@ -262,8 +260,7 @@ fun IrFunction.copyValueParametersToStatic(
|
|||||||
origin = originalDispatchReceiver.origin,
|
origin = originalDispatchReceiver.origin,
|
||||||
index = shift++,
|
index = shift++,
|
||||||
type = type,
|
type = type,
|
||||||
name = Name.identifier("\$this"),
|
name = Name.identifier("\$this")
|
||||||
receiverToValue = true
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -273,8 +270,7 @@ fun IrFunction.copyValueParametersToStatic(
|
|||||||
target,
|
target,
|
||||||
origin = originalExtensionReceiver.origin,
|
origin = originalExtensionReceiver.origin,
|
||||||
index = shift++,
|
index = shift++,
|
||||||
name = Name.identifier("\$receiver"),
|
name = Name.identifier("\$receiver")
|
||||||
receiverToValue = true
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -541,14 +537,12 @@ fun createStaticFunctionWithReceivers(
|
|||||||
this,
|
this,
|
||||||
name = Name.identifier("this"),
|
name = Name.identifier("this"),
|
||||||
index = offset++,
|
index = offset++,
|
||||||
type = dispatchReceiverType!!,
|
type = dispatchReceiverType!!
|
||||||
receiverToValue = true
|
|
||||||
)
|
)
|
||||||
val extensionReceiver = oldFunction.extensionReceiverParameter?.copyTo(
|
val extensionReceiver = oldFunction.extensionReceiverParameter?.copyTo(
|
||||||
this,
|
this,
|
||||||
name = Name.identifier("receiver"),
|
name = Name.identifier("receiver"),
|
||||||
index = offset++,
|
index = offset++
|
||||||
receiverToValue = true
|
|
||||||
)
|
)
|
||||||
valueParameters.addAll(listOfNotNull(dispatchReceiver, extensionReceiver) +
|
valueParameters.addAll(listOfNotNull(dispatchReceiver, extensionReceiver) +
|
||||||
oldFunction.valueParameters.map { it.copyTo(this, index = it.index + offset) }
|
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
|
coroutineConstructors += this
|
||||||
|
|
||||||
functionParameters.mapIndexedTo(valueParameters) { index, parameter ->
|
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]
|
val continuationParameter = coroutineBaseClassConstructor.valueParameters[0]
|
||||||
valueParameters += continuationParameter.copyTo(
|
valueParameters += continuationParameter.copyTo(
|
||||||
@@ -445,7 +445,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
coroutineConstructors += this
|
coroutineConstructors += this
|
||||||
|
|
||||||
boundParams.mapIndexedTo(valueParameters) { index, parameter ->
|
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)
|
val irBuilder = context.createIrBuilder(symbol, startOffset, endOffset)
|
||||||
@@ -497,7 +497,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
|
|
||||||
(unboundArgs + create1CompletionParameter)
|
(unboundArgs + create1CompletionParameter)
|
||||||
.mapIndexedTo(valueParameters) { index, parameter ->
|
.mapIndexedTo(valueParameters) { index, parameter ->
|
||||||
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index, receiverToValue = true)
|
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.createDispatchReceiverParameter()
|
this.createDispatchReceiverParameter()
|
||||||
|
|||||||
+1
-2
@@ -240,8 +240,7 @@ internal class CallableReferenceLowering(val context: JvmBackendContext) : FileL
|
|||||||
valueParameters += param.copyTo(
|
valueParameters += param.copyTo(
|
||||||
this,
|
this,
|
||||||
index = valueParameters.size,
|
index = valueParameters.size,
|
||||||
type = param.type.substitute(typeArgumentsMap),
|
type = param.type.substitute(typeArgumentsMap)
|
||||||
receiverToValue = true
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-6
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.backend.common.ir.copyTypeParameters
|
|||||||
import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom
|
import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom
|
||||||
import org.jetbrains.kotlin.backend.common.ir.createDispatchReceiverParameter
|
import org.jetbrains.kotlin.backend.common.ir.createDispatchReceiverParameter
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.backend.jvm.ir.erasedUpperBound
|
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.InlineClassAbi.mangledNameFor
|
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.InlineClassAbi.mangledNameFor
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter
|
import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||||
@@ -19,14 +18,11 @@ import org.jetbrains.kotlin.ir.declarations.*
|
|||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
|
||||||
import org.jetbrains.kotlin.ir.types.getClass
|
import org.jetbrains.kotlin.ir.types.getClass
|
||||||
import org.jetbrains.kotlin.ir.util.constructedClass
|
import org.jetbrains.kotlin.ir.util.constructedClass
|
||||||
import org.jetbrains.kotlin.ir.util.defaultType
|
import org.jetbrains.kotlin.ir.util.defaultType
|
||||||
import org.jetbrains.kotlin.ir.util.explicitParameters
|
import org.jetbrains.kotlin.ir.util.explicitParameters
|
||||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||||
|
|
||||||
class IrReplacementFunction(
|
class IrReplacementFunction(
|
||||||
@@ -128,7 +124,7 @@ class MemoizedInlineClassReplacements {
|
|||||||
newParameter = parameter.copyTo(this, index = -1, name = name)
|
newParameter = parameter.copyTo(this, index = -1, name = name)
|
||||||
dispatchReceiverParameter = newParameter
|
dispatchReceiverParameter = newParameter
|
||||||
} else {
|
} else {
|
||||||
newParameter = parameter.copyTo(this, index = index - 1, name = name, receiverToValue = true)
|
newParameter = parameter.copyTo(this, index = index - 1, name = name)
|
||||||
valueParameters.add(newParameter)
|
valueParameters.add(newParameter)
|
||||||
}
|
}
|
||||||
parameterMap[parameter.symbol] = newParameter
|
parameterMap[parameter.symbol] = newParameter
|
||||||
@@ -150,7 +146,7 @@ class MemoizedInlineClassReplacements {
|
|||||||
else -> parameter.name
|
else -> parameter.name
|
||||||
}
|
}
|
||||||
|
|
||||||
val newParameter = parameter.copyTo(this, index = index, name = name, receiverToValue = true)
|
val newParameter = parameter.copyTo(this, index = index, name = name)
|
||||||
valueParameters.add(newParameter)
|
valueParameters.add(newParameter)
|
||||||
parameterMap[parameter.symbol] = newParameter
|
parameterMap[parameter.symbol] = newParameter
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user