JVM IR: do not use KotlinTypeMapper indirectly in CallableReferenceLowering
This commit is contained in:
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods
|
|||||||
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.InlineClassAbi
|
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.InlineClassAbi
|
||||||
import org.jetbrains.kotlin.codegen.ClassBuilder
|
import org.jetbrains.kotlin.codegen.ClassBuilder
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
@@ -23,7 +24,10 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
|||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrLocalDelegatedPropertySymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
||||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||||
@@ -95,8 +99,11 @@ class JvmBackendContext(
|
|||||||
internal fun referenceTypeParameter(descriptor: TypeParameterDescriptor): IrTypeParameterSymbol =
|
internal fun referenceTypeParameter(descriptor: TypeParameterDescriptor): IrTypeParameterSymbol =
|
||||||
symbolTable.referenceTypeParameter(descriptor)
|
symbolTable.referenceTypeParameter(descriptor)
|
||||||
|
|
||||||
internal fun referenceSimpleFunction(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol =
|
internal fun referenceFunction(descriptor: FunctionDescriptor): IrFunctionSymbol =
|
||||||
symbolTable.referenceSimpleFunction(descriptor)
|
if (descriptor is ClassConstructorDescriptor)
|
||||||
|
symbolTable.referenceConstructor(descriptor)
|
||||||
|
else
|
||||||
|
symbolTable.referenceSimpleFunction(descriptor)
|
||||||
|
|
||||||
override fun log(message: () -> String) {
|
override fun log(message: () -> String) {
|
||||||
/*TODO*/
|
/*TODO*/
|
||||||
|
|||||||
+8
-1
@@ -204,6 +204,13 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
|
|||||||
writeParameter(sw, JvmMethodParameterKind.RECEIVER, receiverParameter.type, function)
|
writeParameter(sw, JvmMethodParameterKind.RECEIVER, receiverParameter.type, function)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is needed because mapSignature is currently invoked in CallableReferenceLowering before InnerClassesLowering where
|
||||||
|
// this parameter is transformed to a normal value parameter.
|
||||||
|
// TODO: do not call mapSignature in CallableReferenceLowering
|
||||||
|
if (function is IrConstructor && function.dispatchReceiverParameter != null) {
|
||||||
|
writeParameter(sw, JvmMethodParameterKind.VALUE, function.dispatchReceiverParameter!!.type, function)
|
||||||
|
}
|
||||||
|
|
||||||
for (parameter in function.valueParameters) {
|
for (parameter in function.valueParameters) {
|
||||||
val type = if (forceSingleValueParameterBoxing(function.descriptor)) parameter.type.makeNullable() else parameter.type
|
val type = if (forceSingleValueParameterBoxing(function.descriptor)) parameter.type.makeNullable() else parameter.type
|
||||||
writeParameter(sw, JvmMethodParameterKind.VALUE, type, function)
|
writeParameter(sw, JvmMethodParameterKind.VALUE, type, function)
|
||||||
@@ -312,7 +319,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
|
|||||||
private fun mapOverriddenSpecialBuiltinIfNeeded(callee: IrFunction, superCall: Boolean): JvmMethodSignature? {
|
private fun mapOverriddenSpecialBuiltinIfNeeded(callee: IrFunction, superCall: Boolean): JvmMethodSignature? {
|
||||||
val overriddenSpecialBuiltinFunction = callee.descriptor.original.getOverriddenBuiltinReflectingJvmDescriptor()
|
val overriddenSpecialBuiltinFunction = callee.descriptor.original.getOverriddenBuiltinReflectingJvmDescriptor()
|
||||||
if (overriddenSpecialBuiltinFunction != null && !superCall) {
|
if (overriddenSpecialBuiltinFunction != null && !superCall) {
|
||||||
return mapSignatureSkipGeneric(context.referenceSimpleFunction(overriddenSpecialBuiltinFunction.original).owner)
|
return mapSignatureSkipGeneric(context.referenceFunction(overriddenSpecialBuiltinFunction.original).owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|||||||
+7
-4
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.backend.jvm.codegen.isInlineIrExpression
|
|||||||
import org.jetbrains.kotlin.backend.jvm.ir.createJvmIrBuilder
|
import org.jetbrains.kotlin.backend.jvm.ir.createJvmIrBuilder
|
||||||
import org.jetbrains.kotlin.backend.jvm.ir.irArray
|
import org.jetbrains.kotlin.backend.jvm.ir.irArray
|
||||||
import org.jetbrains.kotlin.backend.jvm.ir.isInlineParameter
|
import org.jetbrains.kotlin.backend.jvm.ir.isInlineParameter
|
||||||
import org.jetbrains.kotlin.codegen.PropertyReferenceCodegen
|
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
@@ -35,8 +34,8 @@ import org.jetbrains.kotlin.ir.types.*
|
|||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||||
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
|
|
||||||
internal val callableReferencePhase = makeIrFilePhase(
|
internal val callableReferencePhase = makeIrFilePhase(
|
||||||
@@ -348,10 +347,14 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext)
|
|||||||
get() = (metadata as? MetadataSource.Function)?.descriptor?.name ?: name
|
get() = (metadata as? MetadataSource.Function)?.descriptor?.name ?: name
|
||||||
|
|
||||||
private fun createGetSignatureMethod(superFunction: IrSimpleFunction): IrSimpleFunction = buildOverride(superFunction).apply {
|
private fun createGetSignatureMethod(superFunction: IrSimpleFunction): IrSimpleFunction = buildOverride(superFunction).apply {
|
||||||
val state = context.state
|
val codegenContext = context
|
||||||
body = context.createIrBuilder(symbol, startOffset, endOffset).run {
|
body = context.createIrBuilder(symbol, startOffset, endOffset).run {
|
||||||
// TODO do not use descriptors
|
// TODO do not use descriptors
|
||||||
irExprBody(irString(PropertyReferenceCodegen.getSignatureString(irFunctionReference.symbol.descriptor, state)))
|
val declaration = codegenContext.referenceFunction(
|
||||||
|
DescriptorUtils.unwrapFakeOverride(irFunctionReference.symbol.descriptor).original
|
||||||
|
).owner
|
||||||
|
val method = codegenContext.methodSignatureMapper.mapAsmMethod(declaration)
|
||||||
|
irExprBody(irString(method.name + method.descriptor))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user