Additional cleanup of KotlinTypeMapper after J2K
This commit is contained in:
committed by
Mikhael Bogdanov
parent
20da778046
commit
2bec72d46a
@@ -2442,7 +2442,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
return intrinsic.toCallable(fd, superCall, resolvedCall, this);
|
return intrinsic.toCallable(fd, superCall, resolvedCall, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeMapper.mapToCallableMethod(SamCodegenUtil.resolveSamAdapter(fd), resolvedCall, superCall, null);
|
return typeMapper.mapToCallableMethod(SamCodegenUtil.resolveSamAdapter(fd), superCall, null, resolvedCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invokeMethodWithArguments(
|
public void invokeMethodWithArguments(
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ import org.jetbrains.kotlin.util.OperatorNameConventions
|
|||||||
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||||
import java.util.stream.Stream
|
|
||||||
import kotlin.collections.*
|
import kotlin.collections.*
|
||||||
|
|
||||||
class KotlinTypeMapper @JvmOverloads constructor(
|
class KotlinTypeMapper @JvmOverloads constructor(
|
||||||
@@ -97,8 +96,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getPredefinedInternalNameForClass(classDescriptor: ClassDescriptor): String? {
|
override fun getPredefinedInternalNameForClass(classDescriptor: ClassDescriptor): String? {
|
||||||
val type = getPredefinedTypeForClass(classDescriptor)
|
return getPredefinedTypeForClass(classDescriptor)?.internalName
|
||||||
return type?.internalName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processErrorType(kotlinType: KotlinType, descriptor: ClassDescriptor) {
|
override fun processErrorType(kotlinType: KotlinType, descriptor: ClassDescriptor) {
|
||||||
@@ -202,41 +200,32 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
return mapType(returnType, sw, typeMappingModeFromAnnotation)
|
return mapType(returnType, sw, typeMappingModeFromAnnotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
val mappingMode = TypeMappingMode.getOptimalModeForReturnType(
|
val mappingMode = TypeMappingMode.getOptimalModeForReturnType(returnType, isAnnotationMethod)
|
||||||
returnType,
|
|
||||||
/* isAnnotationMethod = */ isAnnotationMethod
|
|
||||||
)
|
|
||||||
|
|
||||||
return mapType(returnType, sw, mappingMode)
|
return mapType(returnType, sw, mappingMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapSupertype(jetType: KotlinType, signatureVisitor: JvmSignatureWriter?): Type {
|
fun mapSupertype(type: KotlinType, signatureVisitor: JvmSignatureWriter?): Type {
|
||||||
return mapType(jetType, signatureVisitor, TypeMappingMode.SUPER_TYPE)
|
return mapType(type, signatureVisitor, TypeMappingMode.SUPER_TYPE)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapTypeParameter(jetType: KotlinType, signatureVisitor: JvmSignatureWriter?): Type {
|
fun mapTypeParameter(type: KotlinType, signatureVisitor: JvmSignatureWriter?): Type {
|
||||||
return mapType(jetType, signatureVisitor, TypeMappingMode.GENERIC_ARGUMENT)
|
return mapType(type, signatureVisitor, TypeMappingMode.GENERIC_ARGUMENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapClass(classifier: ClassifierDescriptor): Type {
|
fun mapClass(classifier: ClassifierDescriptor): Type {
|
||||||
return mapType(classifier.defaultType, null, TypeMappingMode.CLASS_DECLARATION)
|
return mapType(classifier.defaultType, null, TypeMappingMode.CLASS_DECLARATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapType(jetType: KotlinType): Type {
|
|
||||||
return mapType(jetType, null, TypeMappingMode.DEFAULT)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mapTypeAsDeclaration(kotlinType: KotlinType): Type {
|
fun mapTypeAsDeclaration(kotlinType: KotlinType): Type {
|
||||||
return mapType(kotlinType, null, TypeMappingMode.CLASS_DECLARATION)
|
return mapType(kotlinType, null, TypeMappingMode.CLASS_DECLARATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapType(descriptor: CallableDescriptor): Type {
|
fun mapType(descriptor: CallableDescriptor): Type {
|
||||||
|
|
||||||
return mapType(descriptor.returnType!!)
|
return mapType(descriptor.returnType!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapTypeAsDeclaration(descriptor: CallableDescriptor): Type {
|
fun mapTypeAsDeclaration(descriptor: CallableDescriptor): Type {
|
||||||
|
|
||||||
return mapTypeAsDeclaration(descriptor.returnType!!)
|
return mapTypeAsDeclaration(descriptor.returnType!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,20 +246,18 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
return mapType(descriptor.defaultType)
|
return mapType(descriptor.defaultType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmOverloads
|
||||||
fun mapType(
|
fun mapType(
|
||||||
kotlinType: KotlinType,
|
type: KotlinType,
|
||||||
signatureVisitor: JvmSignatureWriter?,
|
signatureVisitor: JvmSignatureWriter? = null,
|
||||||
mode: TypeMappingMode
|
mode: TypeMappingMode = TypeMappingMode.DEFAULT
|
||||||
): Type {
|
): Type = mapType(
|
||||||
return mapType(
|
type, AsmTypeFactory, mode, typeMappingConfiguration, signatureVisitor,
|
||||||
kotlinType, AsmTypeFactory, mode, typeMappingConfiguration, signatureVisitor,
|
{ ktType, asmType, typeMappingMode ->
|
||||||
{ ktType, asmType, typeMappingMode ->
|
writeGenericType(ktType, asmType, signatureVisitor, typeMappingMode)
|
||||||
writeGenericType(ktType, asmType, signatureVisitor, typeMappingMode)
|
},
|
||||||
Unit
|
isIrBackend
|
||||||
},
|
)
|
||||||
isIrBackend
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun mapInlineClassType(kotlinType: KotlinType): Type {
|
private fun mapInlineClassType(kotlinType: KotlinType): Type {
|
||||||
return mapInlineClassType(kotlinType, TypeMappingMode.DEFAULT, typeMappingConfiguration)
|
return mapInlineClassType(kotlinType, TypeMappingMode.DEFAULT, typeMappingConfiguration)
|
||||||
@@ -342,18 +329,13 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
|
|
||||||
if (classDescriptor is FunctionClassDescriptor) {
|
if (classDescriptor is FunctionClassDescriptor) {
|
||||||
if (classDescriptor.hasBigArity ||
|
if (classDescriptor.hasBigArity ||
|
||||||
classDescriptor.functionKind === FunctionClassDescriptor.Kind.KFunction ||
|
classDescriptor.functionKind == FunctionClassDescriptor.Kind.KFunction ||
|
||||||
classDescriptor.functionKind === FunctionClassDescriptor.Kind.KSuspendFunction
|
classDescriptor.functionKind == FunctionClassDescriptor.Kind.KSuspendFunction
|
||||||
) {
|
) {
|
||||||
// kotlin.reflect.KFunction{n}<P1, ..., Pn, R> is mapped to kotlin.reflect.KFunction<R> (for all n), and
|
// kotlin.reflect.KFunction{n}<P1, ..., Pn, R> is mapped to kotlin.reflect.KFunction<R> (for all n), and
|
||||||
// kotlin.Function{n}<P1, ..., Pn, R> is mapped to kotlin.jvm.functions.FunctionN<R> (for n > 22).
|
// kotlin.Function{n}<P1, ..., Pn, R> is mapped to kotlin.jvm.functions.FunctionN<R> (for n > 22).
|
||||||
// So for these classes, we need to skip all type arguments except the very last one
|
// So for these classes, we need to skip all type arguments except the very last one
|
||||||
writeGenericArguments(
|
writeGenericArguments(signatureVisitor, listOf(arguments.last()), listOf(parameters.last()), mode)
|
||||||
signatureVisitor,
|
|
||||||
listOf(arguments.last()),
|
|
||||||
listOf(parameters.last()),
|
|
||||||
mode
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,7 +350,6 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
mode: TypeMappingMode
|
mode: TypeMappingMode
|
||||||
) {
|
) {
|
||||||
for ((parameter, argument) in parameters.zip(arguments)) {
|
for ((parameter, argument) in parameters.zip(arguments)) {
|
||||||
|
|
||||||
if (argument.isStarProjection ||
|
if (argument.isStarProjection ||
|
||||||
// In<Nothing, Foo> == In<*, Foo> -> In<?, Foo>
|
// In<Nothing, Foo> == In<*, Foo> -> In<?, Foo>
|
||||||
KotlinBuiltIns.isNothing(argument.type) && parameter.variance === Variance.IN_VARIANCE
|
KotlinBuiltIns.isNothing(argument.type) && parameter.variance === Variance.IN_VARIANCE
|
||||||
@@ -392,11 +373,12 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmOverloads
|
||||||
fun mapToCallableMethod(
|
fun mapToCallableMethod(
|
||||||
descriptor: FunctionDescriptor,
|
descriptor: FunctionDescriptor,
|
||||||
resolvedCall: ResolvedCall<*>?,
|
|
||||||
superCall: Boolean,
|
superCall: Boolean,
|
||||||
kind: OwnerKind?
|
kind: OwnerKind? = null,
|
||||||
|
resolvedCall: ResolvedCall<*>? = null
|
||||||
): CallableMethod {
|
): CallableMethod {
|
||||||
// we generate constructors of inline classes as usual functions
|
// we generate constructors of inline classes as usual functions
|
||||||
if (descriptor is ConstructorDescriptor && kind !== OwnerKind.ERASED_INLINE_CLASS) {
|
if (descriptor is ConstructorDescriptor && kind !== OwnerKind.ERASED_INLINE_CLASS) {
|
||||||
@@ -404,26 +386,13 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
val owner = mapOwner(descriptor)
|
val owner = mapOwner(descriptor)
|
||||||
val originalDescriptor = descriptor.original
|
val originalDescriptor = descriptor.original
|
||||||
return CallableMethod(
|
return CallableMethod(
|
||||||
owner,
|
owner, owner, { mapDefaultMethod(originalDescriptor, OwnerKind.IMPLEMENTATION).descriptor }, method, INVOKESPECIAL,
|
||||||
owner,
|
null, null, null, null, null, originalDescriptor.returnType, isInterfaceMethod = false, isDefaultMethodInInterface = false
|
||||||
{ mapDefaultMethod(originalDescriptor, OwnerKind.IMPLEMENTATION).descriptor },
|
|
||||||
method,
|
|
||||||
INVOKESPECIAL,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
originalDescriptor.returnType,
|
|
||||||
isInterfaceMethod = false,
|
|
||||||
isDefaultMethodInInterface = false
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor is LocalVariableAccessorDescriptor) {
|
if (descriptor is LocalVariableAccessorDescriptor) {
|
||||||
val delegateAccessorResolvedCall =
|
val delegateAccessorResolvedCall = bindingContext.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, descriptor)
|
||||||
bindingContext.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, descriptor as VariableAccessorDescriptor)
|
|
||||||
|
|
||||||
return mapToCallableMethod(delegateAccessorResolvedCall!!.resultingDescriptor, false)
|
return mapToCallableMethod(delegateAccessorResolvedCall!!.resultingDescriptor, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,7 +429,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
else
|
else
|
||||||
mapClass(ownerForDefault)
|
mapClass(ownerForDefault)
|
||||||
|
|
||||||
if (isInterface && (superCall || descriptor.visibility === Visibilities.PRIVATE || isAccessor(descriptor))) {
|
if (isInterface && (superCall || descriptor.visibility == Visibilities.PRIVATE || isAccessor(descriptor))) {
|
||||||
thisClass = mapClass(functionParent)
|
thisClass = mapClass(functionParent)
|
||||||
dispatchReceiverKotlinType = functionParent.defaultType
|
dispatchReceiverKotlinType = functionParent.defaultType
|
||||||
if (declarationOwner is JavaClassDescriptor || declarationFunctionDescriptor.hasJvmDefaultAnnotation()) {
|
if (declarationOwner is JavaClassDescriptor || declarationFunctionDescriptor.hasJvmDefaultAnnotation()) {
|
||||||
@@ -474,7 +443,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
val originalDescriptor = descriptor.original
|
val originalDescriptor = descriptor.original
|
||||||
signature = mapSignatureSkipGeneric(originalDescriptor, OwnerKind.DEFAULT_IMPLS)
|
signature = mapSignatureSkipGeneric(originalDescriptor, OwnerKind.DEFAULT_IMPLS)
|
||||||
returnKotlinType = originalDescriptor.returnType
|
returnKotlinType = originalDescriptor.returnType
|
||||||
if (descriptor is AccessorForCallableDescriptor<*> && (descriptor as AccessorForCallableDescriptor<*>).calleeDescriptor.hasJvmDefaultAnnotation()) {
|
if (descriptor is AccessorForCallableDescriptor<*> && descriptor.calleeDescriptor.hasJvmDefaultAnnotation()) {
|
||||||
owner = mapClass(functionParent)
|
owner = mapClass(functionParent)
|
||||||
isInterfaceMember = true
|
isInterfaceMember = true
|
||||||
} else {
|
} else {
|
||||||
@@ -555,10 +524,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
invokeOpcode = INVOKEVIRTUAL
|
invokeOpcode = INVOKEVIRTUAL
|
||||||
thisClass = owner
|
thisClass = owner
|
||||||
val ownerDescriptor = functionDescriptor.containingDeclaration
|
val ownerDescriptor = functionDescriptor.containingDeclaration
|
||||||
dispatchReceiverKotlinType = if (ownerDescriptor is ClassDescriptor)
|
dispatchReceiverKotlinType = (ownerDescriptor as? ClassDescriptor)?.defaultType
|
||||||
ownerDescriptor.defaultType
|
|
||||||
else
|
|
||||||
null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -586,11 +552,6 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
|
||||||
fun mapToCallableMethod(descriptor: FunctionDescriptor, superCall: Boolean, kind: OwnerKind? = null): CallableMethod {
|
|
||||||
return mapToCallableMethod(descriptor, null, superCall, kind)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun mapFunctionName(descriptor: FunctionDescriptor, kind: OwnerKind?): String {
|
fun mapFunctionName(descriptor: FunctionDescriptor, kind: OwnerKind?): String {
|
||||||
if (descriptor !is JavaCallableMemberDescriptor) {
|
if (descriptor !is JavaCallableMemberDescriptor) {
|
||||||
val platformName = getJvmName(descriptor)
|
val platformName = getJvmName(descriptor)
|
||||||
@@ -600,7 +561,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
val nameForSpecialFunction = getJvmMethodNameIfSpecial(descriptor)
|
val nameForSpecialFunction = getJvmMethodNameIfSpecial(descriptor)
|
||||||
if (nameForSpecialFunction != null) return nameForSpecialFunction
|
if (nameForSpecialFunction != null) return nameForSpecialFunction
|
||||||
|
|
||||||
when {
|
return when {
|
||||||
descriptor is PropertyAccessorDescriptor -> {
|
descriptor is PropertyAccessorDescriptor -> {
|
||||||
val property = descriptor.correspondingProperty
|
val property = descriptor.correspondingProperty
|
||||||
if (isAnnotationClass(property.containingDeclaration)) {
|
if (isAnnotationClass(property.containingDeclaration)) {
|
||||||
@@ -618,7 +579,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
else
|
else
|
||||||
JvmAbi.setterName(propertyName)
|
JvmAbi.setterName(propertyName)
|
||||||
|
|
||||||
return mangleMemberNameIfRequired(if (isAccessor) "access$$accessorName" else accessorName, descriptor, kind)
|
mangleMemberNameIfRequired(if (isAccessor) "access$$accessorName" else accessorName, descriptor, kind)
|
||||||
}
|
}
|
||||||
isFunctionLiteral(descriptor) -> {
|
isFunctionLiteral(descriptor) -> {
|
||||||
val element = DescriptorToSourceUtils.getSourceFromDescriptor(descriptor)
|
val element = DescriptorToSourceUtils.getSourceFromDescriptor(descriptor)
|
||||||
@@ -632,13 +593,12 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return OperatorNameConventions.INVOKE.asString()
|
|
||||||
}
|
|
||||||
else -> return if (isLocalFunction(descriptor) || isFunctionExpression(descriptor)) {
|
|
||||||
OperatorNameConventions.INVOKE.asString()
|
OperatorNameConventions.INVOKE.asString()
|
||||||
} else {
|
|
||||||
mangleMemberNameIfRequired(descriptor.name.asString(), descriptor, kind)
|
|
||||||
}
|
}
|
||||||
|
isLocalFunction(descriptor) || isFunctionExpression(descriptor) ->
|
||||||
|
OperatorNameConventions.INVOKE.asString()
|
||||||
|
else ->
|
||||||
|
mangleMemberNameIfRequired(descriptor.name.asString(), descriptor, kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,8 +663,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getModuleName(descriptor: CallableMemberDescriptor): String {
|
private fun getModuleName(descriptor: CallableMemberDescriptor): String {
|
||||||
val deserialized = getJvmModuleNameForDeserializedDescriptor(descriptor)
|
return getJvmModuleNameForDeserializedDescriptor(descriptor) ?: moduleName
|
||||||
return deserialized ?: moduleName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapAsmMethod(descriptor: FunctionDescriptor): Method {
|
fun mapAsmMethod(descriptor: FunctionDescriptor): Method {
|
||||||
@@ -740,9 +699,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
return mapSignature(f, kind, false)
|
return mapSignature(f, kind, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapSignatureWithGeneric(
|
fun mapSignatureWithGeneric(f: FunctionDescriptor, kind: OwnerKind, hasSpecialBridge: Boolean): JvmMethodGenericSignature {
|
||||||
f: FunctionDescriptor, kind: OwnerKind, hasSpecialBridge: Boolean
|
|
||||||
): JvmMethodGenericSignature {
|
|
||||||
return mapSignature(f, null, kind, false, hasSpecialBridge)
|
return mapSignature(f, null, kind, false, hasSpecialBridge)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -757,7 +714,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
skipGenericSignature: Boolean,
|
skipGenericSignature: Boolean,
|
||||||
hasSpecialBridge: Boolean
|
hasSpecialBridge: Boolean
|
||||||
): JvmMethodGenericSignature {
|
): JvmMethodGenericSignature {
|
||||||
if (f.initialSignatureDescriptor != null && f !== f.initialSignatureDescriptor) {
|
if (f.initialSignatureDescriptor != null && f != f.initialSignatureDescriptor) {
|
||||||
// Overrides of special builtin in Kotlin classes always have special signature
|
// Overrides of special builtin in Kotlin classes always have special signature
|
||||||
if (f.getOverriddenBuiltinReflectingJvmDescriptor() == null || f.containingDeclaration.original is JavaClassDescriptor) {
|
if (f.getOverriddenBuiltinReflectingJvmDescriptor() == null || f.containingDeclaration.original is JavaClassDescriptor) {
|
||||||
return mapSignature(f.initialSignatureDescriptor!!, kind, skipGenericSignature)
|
return mapSignature(f.initialSignatureDescriptor!!, kind, skipGenericSignature)
|
||||||
@@ -783,13 +740,13 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
val builtIns = f.builtIns
|
val builtIns = f.builtIns
|
||||||
val arrayOfNullableAny = builtIns.getArrayType(Variance.INVARIANT, builtIns.nullableAnyType)
|
val arrayOfNullableAny = builtIns.getArrayType(Variance.INVARIANT, builtIns.nullableAnyType)
|
||||||
return mapSignatureWithCustomParameters(
|
return mapSignatureWithCustomParameters(
|
||||||
f, kind, Stream.of(arrayOfNullableAny), null,
|
f, kind, sequenceOf(arrayOfNullableAny), null,
|
||||||
skipGenericSignature = false,
|
skipGenericSignature = false,
|
||||||
hasSpecialBridge = false
|
hasSpecialBridge = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val parameterTypes: Stream<KotlinType>
|
val parameterTypes: Sequence<KotlinType>
|
||||||
val returnType: KotlinType?
|
val returnType: KotlinType?
|
||||||
|
|
||||||
if (languageVersionSettings.supportsFeature(LanguageFeature.PolymorphicSignature) && isPolymorphicSignature(f)) {
|
if (languageVersionSettings.supportsFeature(LanguageFeature.PolymorphicSignature) && isPolymorphicSignature(f)) {
|
||||||
@@ -799,7 +756,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
parameterTypes = extractPolymorphicParameterTypes(resolvedCall)
|
parameterTypes = extractPolymorphicParameterTypes(resolvedCall)
|
||||||
returnType = extractPolymorphicReturnType(resolvedCall)
|
returnType = extractPolymorphicReturnType(resolvedCall)
|
||||||
} else {
|
} else {
|
||||||
parameterTypes = f.valueParameters.stream().map { it.type }
|
parameterTypes = f.valueParameters.asSequence().map { it.type }
|
||||||
returnType = null
|
returnType = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -812,20 +769,13 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
valueParameters: List<ValueParameterDescriptor>,
|
valueParameters: List<ValueParameterDescriptor>,
|
||||||
skipGenericSignature: Boolean
|
skipGenericSignature: Boolean
|
||||||
): JvmMethodGenericSignature {
|
): JvmMethodGenericSignature {
|
||||||
return mapSignatureWithCustomParameters(
|
return mapSignatureWithCustomParameters(f, kind, valueParameters.asSequence().map { it.type }, null, skipGenericSignature, false)
|
||||||
f,
|
|
||||||
kind,
|
|
||||||
valueParameters.stream().map { it.type },
|
|
||||||
null,
|
|
||||||
skipGenericSignature,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun mapSignatureWithCustomParameters(
|
private fun mapSignatureWithCustomParameters(
|
||||||
f: FunctionDescriptor,
|
f: FunctionDescriptor,
|
||||||
kind: OwnerKind,
|
kind: OwnerKind,
|
||||||
valueParameterTypes: Stream<KotlinType>,
|
valueParameterTypes: Sequence<KotlinType>,
|
||||||
customReturnType: KotlinType?,
|
customReturnType: KotlinType?,
|
||||||
skipGenericSignature: Boolean,
|
skipGenericSignature: Boolean,
|
||||||
hasSpecialBridge: Boolean
|
hasSpecialBridge: Boolean
|
||||||
@@ -841,13 +791,15 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
sw.writeParametersStart()
|
sw.writeParametersStart()
|
||||||
writeAdditionalConstructorParameters(f, sw)
|
writeAdditionalConstructorParameters(f, sw)
|
||||||
|
|
||||||
valueParameterTypes.forEach({ type -> writeParameter(sw, type, f) })
|
for (type in valueParameterTypes) {
|
||||||
|
writeParameter(sw, type, f)
|
||||||
|
}
|
||||||
|
|
||||||
if (f is AccessorForConstructorDescriptor) {
|
if (f is AccessorForConstructorDescriptor) {
|
||||||
writeParameter(sw, JvmMethodParameterKind.CONSTRUCTOR_MARKER, DEFAULT_CONSTRUCTOR_MARKER)
|
writeParameter(sw, JvmMethodParameterKind.CONSTRUCTOR_MARKER, DEFAULT_CONSTRUCTOR_MARKER)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OwnerKind.ERASED_INLINE_CLASS === kind) {
|
if (kind == OwnerKind.ERASED_INLINE_CLASS) {
|
||||||
sw.writeReturnType()
|
sw.writeReturnType()
|
||||||
sw.writeAsmType(mapType(f.containingDeclaration))
|
sw.writeAsmType(mapType(f.containingDeclaration))
|
||||||
sw.writeReturnTypeEnd()
|
sw.writeReturnTypeEnd()
|
||||||
@@ -856,18 +808,20 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val directMember = DescriptorUtils.getDirectMember(f)
|
val directMember = DescriptorUtils.getDirectMember(f)
|
||||||
var thisIfNeeded: KotlinType? = null
|
val thisIfNeeded: KotlinType? = when (kind) {
|
||||||
if (OwnerKind.DEFAULT_IMPLS === kind) {
|
OwnerKind.DEFAULT_IMPLS -> {
|
||||||
val receiverTypeAndTypeParameters = patchTypeParametersForDefaultImplMethod(directMember)
|
val receiverTypeAndTypeParameters = patchTypeParametersForDefaultImplMethod(directMember)
|
||||||
writeFormalTypeParameters(receiverTypeAndTypeParameters.typeParameters.plus(directMember.typeParameters), sw)
|
writeFormalTypeParameters(receiverTypeAndTypeParameters.typeParameters + directMember.typeParameters, sw)
|
||||||
thisIfNeeded = receiverTypeAndTypeParameters.receiverType
|
receiverTypeAndTypeParameters.receiverType
|
||||||
} else if (OwnerKind.ERASED_INLINE_CLASS === kind) {
|
}
|
||||||
val classDescriptor = directMember.containingDeclaration as ClassDescriptor
|
OwnerKind.ERASED_INLINE_CLASS -> {
|
||||||
thisIfNeeded = classDescriptor.defaultType
|
(directMember.containingDeclaration as ClassDescriptor).defaultType
|
||||||
} else {
|
}
|
||||||
writeFormalTypeParameters(directMember.typeParameters, sw)
|
else -> {
|
||||||
if (isAccessor(f) && f.dispatchReceiverParameter != null) {
|
writeFormalTypeParameters(directMember.typeParameters, sw)
|
||||||
thisIfNeeded = (f.containingDeclaration as ClassDescriptor).defaultType
|
if (isAccessor(f) && f.dispatchReceiverParameter != null) {
|
||||||
|
(f.containingDeclaration as ClassDescriptor).defaultType
|
||||||
|
} else null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -881,10 +835,10 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
writeParameter(sw, JvmMethodParameterKind.RECEIVER, receiverParameter.type, f)
|
writeParameter(sw, JvmMethodParameterKind.RECEIVER, receiverParameter.type, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
valueParameterTypes.forEach({ type ->
|
for (type in valueParameterTypes) {
|
||||||
val forceBoxing = forceSingleValueParameterBoxing(f)
|
val forceBoxing = forceSingleValueParameterBoxing(f)
|
||||||
writeParameter(sw, if (forceBoxing) TypeUtils.makeNullable(type) else type, f)
|
writeParameter(sw, if (forceBoxing) TypeUtils.makeNullable(type) else type, f)
|
||||||
})
|
}
|
||||||
|
|
||||||
sw.writeReturnType()
|
sw.writeReturnType()
|
||||||
customReturnType?.let { mapReturnType(f, sw, it) } ?: mapReturnType(f, sw)
|
customReturnType?.let { mapReturnType(f, sw, it) } ?: mapReturnType(f, sw)
|
||||||
@@ -893,7 +847,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
|
|
||||||
val signature = sw.makeJvmMethodSignature(mapFunctionName(f, kind))
|
val signature = sw.makeJvmMethodSignature(mapFunctionName(f, kind))
|
||||||
|
|
||||||
if (kind !== OwnerKind.DEFAULT_IMPLS && kind !== OwnerKind.ERASED_INLINE_CLASS && !hasSpecialBridge) {
|
if (kind != OwnerKind.DEFAULT_IMPLS && kind != OwnerKind.ERASED_INLINE_CLASS && !hasSpecialBridge) {
|
||||||
val specialSignatureInfo = with(BuiltinMethodsWithSpecialGenericSignature) { f.getSpecialSignatureInfo() }
|
val specialSignatureInfo = with(BuiltinMethodsWithSpecialGenericSignature) { f.getSpecialSignatureInfo() }
|
||||||
|
|
||||||
if (specialSignatureInfo != null) {
|
if (specialSignatureInfo != null) {
|
||||||
@@ -905,24 +859,18 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
return signature
|
return signature
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun extractPolymorphicParameterTypes(resolvedCall: ResolvedCall<*>): Stream<KotlinType> {
|
private fun extractPolymorphicParameterTypes(resolvedCall: ResolvedCall<*>): Sequence<KotlinType> {
|
||||||
val valueArgumentsByIndex = resolvedCall.valueArgumentsByIndex
|
val valueArgumentsByIndex = resolvedCall.valueArgumentsByIndex
|
||||||
if (valueArgumentsByIndex == null ||
|
val argument = valueArgumentsByIndex?.singleOrNull() as? VarargValueArgument ?: throw UnsupportedOperationException(
|
||||||
valueArgumentsByIndex.size != 1 ||
|
"Polymorphic signature is only supported for methods with one vararg argument: " + resolvedCall.resultingDescriptor
|
||||||
valueArgumentsByIndex[0] !is VarargValueArgument
|
)
|
||||||
) {
|
|
||||||
throw UnsupportedOperationException(
|
|
||||||
"Polymorphic signature is only supported for methods with one vararg argument: " + resolvedCall.resultingDescriptor
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val argument = valueArgumentsByIndex[0] as VarargValueArgument
|
return argument.arguments.asSequence().map { arg ->
|
||||||
return argument.arguments.stream().map({ arg ->
|
val expression = arg.getArgumentExpression() ?: throw UnsupportedOperationException(
|
||||||
val expression = arg.getArgumentExpression() ?: throw UnsupportedOperationException(
|
"Polymorphic signature argument must be an expression: " + resolvedCall.resultingDescriptor
|
||||||
"Polymorphic signature argument must be an expression: " + resolvedCall.resultingDescriptor
|
)
|
||||||
)
|
bindingContext.getType(expression)!!
|
||||||
bindingContext.getType(expression)
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun extractPolymorphicReturnType(resolvedCall: ResolvedCall<*>): KotlinType? {
|
private fun extractPolymorphicReturnType(resolvedCall: ResolvedCall<*>): KotlinType? {
|
||||||
@@ -930,16 +878,12 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
val originalReturnType = resolvedCall.resultingDescriptor.returnType
|
val originalReturnType = resolvedCall.resultingDescriptor.returnType
|
||||||
if (originalReturnType != null && !KotlinBuiltIns.isAny(originalReturnType)) return null
|
if (originalReturnType != null && !KotlinBuiltIns.isAny(originalReturnType)) return null
|
||||||
|
|
||||||
if (resolvedCall.call.callElement !is KtExpression) {
|
var expression = resolvedCall.call.callElement as? KtExpression ?: throw UnsupportedOperationException(
|
||||||
throw UnsupportedOperationException(
|
"Polymorphic signature method call must be an expression: " + resolvedCall.resultingDescriptor
|
||||||
"Polymorphic signature method call must be an expression: " + resolvedCall.resultingDescriptor
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
var expression = resolvedCall.call.callElement as KtExpression
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
val parent = expression.getQualifiedExpressionForSelector() ?: break
|
expression = expression.getQualifiedExpressionForSelector() ?: break
|
||||||
expression = parent
|
|
||||||
}
|
}
|
||||||
expression = expression.getOutermostParenthesizerOrThis()
|
expression = expression.getOutermostParenthesizerOrThis()
|
||||||
|
|
||||||
@@ -982,24 +926,14 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
private fun forceBoxedReturnType(descriptor: FunctionDescriptor): Boolean {
|
private fun forceBoxedReturnType(descriptor: FunctionDescriptor): Boolean {
|
||||||
if (isBoxMethodForInlineClass(descriptor)) return true
|
if (isBoxMethodForInlineClass(descriptor)) return true
|
||||||
|
|
||||||
|
return isJvmPrimitive(descriptor.returnType!!) &&
|
||||||
if (!isJvmPrimitive(descriptor.returnType!!)) return false
|
getAllOverriddenDescriptors(descriptor).any { !isJvmPrimitive(it.returnType!!) }
|
||||||
|
|
||||||
for (overridden in getAllOverriddenDescriptors(descriptor)) {
|
|
||||||
|
|
||||||
if (!isJvmPrimitive(overridden.returnType!!)) return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isJvmPrimitive(kotlinType: KotlinType): Boolean {
|
private fun isJvmPrimitive(kotlinType: KotlinType): Boolean {
|
||||||
if (KotlinBuiltIns.isPrimitiveType(kotlinType)) return true
|
if (KotlinBuiltIns.isPrimitiveType(kotlinType)) return true
|
||||||
|
|
||||||
return if (kotlinType.isInlineClassType() && !kotlinType.isError) {
|
return kotlinType.isInlineClassType() && !kotlinType.isError && AsmUtil.isPrimitive(mapInlineClassType(kotlinType))
|
||||||
AsmUtil.isPrimitive(mapInlineClassType(kotlinType))
|
|
||||||
} else false
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapFieldSignature(backingFieldType: KotlinType, propertyDescriptor: PropertyDescriptor): String? {
|
fun mapFieldSignature(backingFieldType: KotlinType, propertyDescriptor: PropertyDescriptor): String? {
|
||||||
@@ -1037,15 +971,12 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
|
|
||||||
sw.writeFormalTypeParameter(typeParameterDescriptor.name.asString())
|
sw.writeFormalTypeParameter(typeParameterDescriptor.name.asString())
|
||||||
|
|
||||||
|
|
||||||
sw.writeClassBound()
|
sw.writeClassBound()
|
||||||
|
|
||||||
classBound@ for (jetType in typeParameterDescriptor.upperBounds) {
|
for (type in typeParameterDescriptor.upperBounds) {
|
||||||
if (jetType.constructor.declarationDescriptor is ClassDescriptor) {
|
if (type.constructor.declarationDescriptor is ClassDescriptor && !isJvmInterface(type)) {
|
||||||
if (!isJvmInterface(jetType)) {
|
mapType(type, sw, TypeMappingMode.GENERIC_ARGUMENT)
|
||||||
mapType(jetType, sw, TypeMappingMode.GENERIC_ARGUMENT)
|
break
|
||||||
break@classBound
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1056,29 +987,24 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
|
|
||||||
sw.writeClassBoundEnd()
|
sw.writeClassBoundEnd()
|
||||||
|
|
||||||
for (jetType in typeParameterDescriptor.upperBounds) {
|
for (type in typeParameterDescriptor.upperBounds) {
|
||||||
val classifier = jetType.constructor.declarationDescriptor
|
when (val classifier = type.constructor.declarationDescriptor) {
|
||||||
if (classifier is ClassDescriptor) {
|
is ClassDescriptor -> if (isJvmInterface(type)) {
|
||||||
if (isJvmInterface(jetType)) {
|
|
||||||
sw.writeInterfaceBound()
|
sw.writeInterfaceBound()
|
||||||
mapType(jetType, sw, TypeMappingMode.GENERIC_ARGUMENT)
|
mapType(type, sw, TypeMappingMode.GENERIC_ARGUMENT)
|
||||||
sw.writeInterfaceBoundEnd()
|
sw.writeInterfaceBoundEnd()
|
||||||
}
|
}
|
||||||
} else if (classifier is TypeParameterDescriptor) {
|
is TypeParameterDescriptor -> {
|
||||||
sw.writeInterfaceBound()
|
sw.writeInterfaceBound()
|
||||||
mapType(jetType, sw, TypeMappingMode.GENERIC_ARGUMENT)
|
mapType(type, sw, TypeMappingMode.GENERIC_ARGUMENT)
|
||||||
sw.writeInterfaceBoundEnd()
|
sw.writeInterfaceBoundEnd()
|
||||||
} else {
|
}
|
||||||
throw UnsupportedOperationException("Unknown classifier: " + classifier!!)
|
else -> throw UnsupportedOperationException("Unknown classifier: $classifier")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeParameter(
|
private fun writeParameter(sw: JvmSignatureWriter, type: KotlinType, callableDescriptor: CallableDescriptor?) {
|
||||||
sw: JvmSignatureWriter,
|
|
||||||
type: KotlinType,
|
|
||||||
callableDescriptor: CallableDescriptor?
|
|
||||||
) {
|
|
||||||
writeParameter(sw, JvmMethodParameterKind.VALUE, type, callableDescriptor)
|
writeParameter(sw, JvmMethodParameterKind.VALUE, type, callableDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1095,11 +1021,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
sw.writeParameterTypeEnd()
|
sw.writeParameterTypeEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun writeParameterType(
|
fun writeParameterType(sw: JvmSignatureWriter, type: KotlinType, callableDescriptor: CallableDescriptor?) {
|
||||||
sw: JvmSignatureWriter,
|
|
||||||
type: KotlinType,
|
|
||||||
callableDescriptor: CallableDescriptor?
|
|
||||||
) {
|
|
||||||
if (sw.skipGenericSignature()) {
|
if (sw.skipGenericSignature()) {
|
||||||
mapType(type, sw, TypeMappingMode.DEFAULT)
|
mapType(type, sw, TypeMappingMode.DEFAULT)
|
||||||
return
|
return
|
||||||
@@ -1118,7 +1040,6 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
|
|
||||||
private fun writeAdditionalConstructorParameters(descriptor: ClassConstructorDescriptor, sw: JvmSignatureWriter) {
|
private fun writeAdditionalConstructorParameters(descriptor: ClassConstructorDescriptor, sw: JvmSignatureWriter) {
|
||||||
val isSynthesized = descriptor.kind == CallableMemberDescriptor.Kind.SYNTHESIZED
|
val isSynthesized = descriptor.kind == CallableMemberDescriptor.Kind.SYNTHESIZED
|
||||||
//if (isSynthesized) return;
|
|
||||||
|
|
||||||
val closure = bindingContext.get(CLOSURE, descriptor.containingDeclaration)
|
val closure = bindingContext.get(CLOSURE, descriptor.containingDeclaration)
|
||||||
|
|
||||||
@@ -1136,14 +1057,8 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
|
|
||||||
if (!isSynthesized) {
|
if (!isSynthesized) {
|
||||||
if (containingDeclaration.kind == ClassKind.ENUM_CLASS || containingDeclaration.kind == ClassKind.ENUM_ENTRY) {
|
if (containingDeclaration.kind == ClassKind.ENUM_CLASS || containingDeclaration.kind == ClassKind.ENUM_ENTRY) {
|
||||||
writeParameter(
|
writeParameter(sw, JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL, descriptor.builtIns.stringType, descriptor)
|
||||||
sw, JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL, descriptor.builtIns.stringType,
|
writeParameter(sw, JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL, descriptor.builtIns.intType, descriptor)
|
||||||
descriptor
|
|
||||||
)
|
|
||||||
writeParameter(
|
|
||||||
sw, JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL, descriptor.builtIns.intType,
|
|
||||||
descriptor
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1196,14 +1111,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
val args = valueArguments.size
|
val args = valueArguments.size
|
||||||
|
|
||||||
// Mapped parameters should consist of captured values plus all of valueArguments
|
// Mapped parameters should consist of captured values plus all of valueArguments
|
||||||
assert(params >= args) {
|
assert(params >= args) { "Incorrect number of mapped parameters vs arguments: $params < $args for $descriptor" }
|
||||||
String.format(
|
|
||||||
"Incorrect number of mapped parameters vs arguments: %d < %d for %s",
|
|
||||||
params,
|
|
||||||
args,
|
|
||||||
descriptor
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Include all captured values, i.e. those parameters for which there are no resolved value arguments
|
// Include all captured values, i.e. those parameters for which there are no resolved value arguments
|
||||||
for (i in 0 until params - args) {
|
for (i in 0 until params - args) {
|
||||||
@@ -1218,7 +1126,6 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
if (isAnonymousObject(descriptor.containingDeclaration)) {
|
if (isAnonymousObject(descriptor.containingDeclaration)) {
|
||||||
// For anonymous objects, also add all real non-default value arguments passed to the super constructor
|
// For anonymous objects, also add all real non-default value arguments passed to the super constructor
|
||||||
for ((key, valueArgument) in valueArguments) {
|
for ((key, valueArgument) in valueArguments) {
|
||||||
|
|
||||||
if (valueArgument !is DefaultValueArgument) {
|
if (valueArgument !is DefaultValueArgument) {
|
||||||
val parameter = parameters[params - args + key.index]
|
val parameter = parameters[params - args + key.index]
|
||||||
writeParameter(sw, JvmMethodParameterKind.SUPER_CALL_PARAM, parameter.asmType)
|
writeParameter(sw, JvmMethodParameterKind.SUPER_CALL_PARAM, parameter.asmType)
|
||||||
@@ -1230,13 +1137,13 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
private fun findFirstDelegatingSuperCall(descriptor: ConstructorDescriptor): ResolvedCall<ConstructorDescriptor>? {
|
private fun findFirstDelegatingSuperCall(descriptor: ConstructorDescriptor): ResolvedCall<ConstructorDescriptor>? {
|
||||||
var current = descriptor
|
var current = descriptor
|
||||||
val constructorOwner = current.containingDeclaration
|
val constructorOwner = current.containingDeclaration
|
||||||
val visited = HashSet<ConstructorDescriptor>()
|
val visited = hashSetOf<ConstructorDescriptor>()
|
||||||
visited.add(current)
|
visited.add(current)
|
||||||
while (true) {
|
while (true) {
|
||||||
val next = getDelegationConstructorCall(bindingContext, current) ?: return null
|
val next = getDelegationConstructorCall(bindingContext, current) ?: return null
|
||||||
current = next.resultingDescriptor.original
|
current = next.resultingDescriptor.original
|
||||||
if (!visited.add(current)) return null
|
if (!visited.add(current)) return null
|
||||||
if (current.containingDeclaration !== constructorOwner) return next
|
if (current.containingDeclaration != constructorOwner) return next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1247,10 +1154,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
return Method(name, desc)
|
return Method(name, desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mapScriptSignature(
|
fun mapScriptSignature(script: ScriptDescriptor, importedScripts: List<ScriptDescriptor>): JvmMethodSignature {
|
||||||
script: ScriptDescriptor,
|
|
||||||
importedScripts: List<ScriptDescriptor>
|
|
||||||
): JvmMethodSignature {
|
|
||||||
val sw = BothSignatureWriter(BothSignatureWriter.Mode.METHOD)
|
val sw = BothSignatureWriter(BothSignatureWriter.Mode.METHOD)
|
||||||
|
|
||||||
sw.writeParametersStart()
|
sw.writeParametersStart()
|
||||||
@@ -1279,21 +1183,18 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
return StackValue.sharedTypeForType(mapType(receiverParameter.type))
|
return StackValue.sharedTypeForType(mapType(receiverParameter.type))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor is LocalVariableDescriptor && descriptor.isDelegated) {
|
if (descriptor is LocalVariableDescriptor && @Suppress("DEPRECATION") descriptor.isDelegated) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (descriptor is VariableDescriptor && isBoxedLocalCapturedInClosure(bindingContext, descriptor)) {
|
return if (descriptor is VariableDescriptor && isBoxedLocalCapturedInClosure(bindingContext, descriptor)) {
|
||||||
StackValue.sharedTypeForType(mapType(descriptor.type))
|
StackValue.sharedTypeForType(mapType(descriptor.type))
|
||||||
} else null
|
} else null
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun classInternalName(classDescriptor: ClassDescriptor): String {
|
fun classInternalName(classDescriptor: ClassDescriptor): String {
|
||||||
val recordedType = typeMappingConfiguration.getPredefinedTypeForClass(classDescriptor)
|
return typeMappingConfiguration.getPredefinedTypeForClass(classDescriptor)?.internalName
|
||||||
return if (recordedType != null) {
|
?: computeInternalName(classDescriptor, typeMappingConfiguration, isIrBackend)
|
||||||
recordedType.internalName
|
|
||||||
} else computeInternalName(classDescriptor, typeMappingConfiguration, isIrBackend)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object InternalNameMapper {
|
object InternalNameMapper {
|
||||||
@@ -1302,7 +1203,7 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun canBeMangledInternalName(name: String): Boolean {
|
fun canBeMangledInternalName(name: String): Boolean {
|
||||||
return name.indexOf('$') != -1
|
return '$' in name
|
||||||
}
|
}
|
||||||
|
|
||||||
fun demangleInternalName(name: String): String? {
|
fun demangleInternalName(name: String): String? {
|
||||||
@@ -1354,12 +1255,16 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
*/
|
*/
|
||||||
val LANGUAGE_VERSION_SETTINGS_DEFAULT: LanguageVersionSettings = LanguageVersionSettingsImpl.DEFAULT
|
val LANGUAGE_VERSION_SETTINGS_DEFAULT: LanguageVersionSettings = LanguageVersionSettingsImpl.DEFAULT
|
||||||
|
|
||||||
private fun internalNameForPackageMemberOwner(descriptor: CallableMemberDescriptor, publicFacade: Boolean): String {
|
private fun internalNameForPackageMemberOwner(callableDescriptor: CallableMemberDescriptor, publicFacade: Boolean): String {
|
||||||
var descriptor = descriptor
|
val isAccessor: Boolean
|
||||||
val isAccessor = descriptor is AccessorForCallableDescriptor<*>
|
val descriptor = if (callableDescriptor is AccessorForCallableDescriptor<*>) {
|
||||||
if (isAccessor) {
|
isAccessor = true
|
||||||
descriptor = (descriptor as AccessorForCallableDescriptor<*>).calleeDescriptor
|
callableDescriptor.calleeDescriptor
|
||||||
|
} else {
|
||||||
|
isAccessor = false
|
||||||
|
callableDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
val file = DescriptorToSourceUtils.getContainingFile(descriptor)
|
val file = DescriptorToSourceUtils.getContainingFile(descriptor)
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
val visibility = descriptor.visibility
|
val visibility = descriptor.visibility
|
||||||
@@ -1395,9 +1300,8 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isNonConstProperty(descriptor: CallableMemberDescriptor): Boolean {
|
private fun isNonConstProperty(descriptor: CallableMemberDescriptor): Boolean =
|
||||||
return if (descriptor !is PropertyDescriptor) false else !descriptor.isConst
|
descriptor is PropertyDescriptor && !descriptor.isConst
|
||||||
}
|
|
||||||
|
|
||||||
fun getContainingClassesForDeserializedCallable(
|
fun getContainingClassesForDeserializedCallable(
|
||||||
deserializedDescriptor: DeserializedCallableMemberDescriptor
|
deserializedDescriptor: DeserializedCallableMemberDescriptor
|
||||||
@@ -1417,17 +1321,15 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
private fun getContainerClassIdForClassDescriptor(classDescriptor: ClassDescriptor): ClassId {
|
private fun getContainerClassIdForClassDescriptor(classDescriptor: ClassDescriptor): ClassId {
|
||||||
val classId = classDescriptor.classId ?: error("Deserialized class should have a ClassId: $classDescriptor")
|
val classId = classDescriptor.classId ?: error("Deserialized class should have a ClassId: $classDescriptor")
|
||||||
|
|
||||||
val nestedClass: String?
|
val nestedClass: String? = if (isInterface(classDescriptor)) {
|
||||||
if (isInterface(classDescriptor)) {
|
JvmAbi.DEFAULT_IMPLS_SUFFIX
|
||||||
nestedClass = JvmAbi.DEFAULT_IMPLS_SUFFIX
|
|
||||||
} else {
|
} else {
|
||||||
nestedClass = null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nestedClass != null) {
|
if (nestedClass != null) {
|
||||||
val relativeClassName = classId.relativeClassName
|
|
||||||
//TODO test nested trait fun inlining
|
//TODO test nested trait fun inlining
|
||||||
val defaultImplsClassName = relativeClassName.shortName().asString() + nestedClass
|
val defaultImplsClassName = classId.relativeClassName.shortName().asString() + nestedClass
|
||||||
return ClassId(classId.packageFqName, Name.identifier(defaultImplsClassName))
|
return ClassId(classId.packageFqName, Name.identifier(defaultImplsClassName))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1457,17 +1359,11 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
|
|
||||||
val implClassName = descriptor.getImplClassNameForDeserialized() ?: error("No implClassName for $descriptor")
|
val implClassName = descriptor.getImplClassNameForDeserialized() ?: error("No implClassName for $descriptor")
|
||||||
|
|
||||||
val facadeName: JvmClassName?
|
val facadeName = when (containingDeclaration) {
|
||||||
|
is LazyJavaPackageFragment -> containingDeclaration.getFacadeNameForPartName(implClassName) ?: return null
|
||||||
if (containingDeclaration is LazyJavaPackageFragment) {
|
is IncrementalMultifileClassPackageFragment -> containingDeclaration.facadeName
|
||||||
facadeName = containingDeclaration.getFacadeNameForPartName(implClassName)
|
else -> throw AssertionError(
|
||||||
if (facadeName == null) return null
|
"Unexpected package fragment for $descriptor: $containingDeclaration (${containingDeclaration.javaClass.simpleName})"
|
||||||
} else if (containingDeclaration is IncrementalMultifileClassPackageFragment) {
|
|
||||||
facadeName = containingDeclaration.facadeName
|
|
||||||
} else {
|
|
||||||
throw AssertionError(
|
|
||||||
"Unexpected package fragment for " + descriptor + ": " +
|
|
||||||
containingDeclaration + " (" + containingDeclaration.javaClass.simpleName + ")"
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1494,26 +1390,18 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
kotlinType: KotlinType,
|
kotlinType: KotlinType,
|
||||||
mode: TypeMappingMode,
|
mode: TypeMappingMode,
|
||||||
configuration: TypeMappingConfiguration<Type>
|
configuration: TypeMappingConfiguration<Type>
|
||||||
): Type {
|
): Type =
|
||||||
return mapType(
|
mapType(kotlinType, AsmTypeFactory, mode, configuration, null, isIrBackend = false)
|
||||||
kotlinType, AsmTypeFactory, mode, configuration, null,
|
|
||||||
isIrBackend = false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun generateErrorMessageForErrorType(type: KotlinType, descriptor: DeclarationDescriptor): String {
|
private fun generateErrorMessageForErrorType(type: KotlinType, descriptor: DeclarationDescriptor): String {
|
||||||
val declarationElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) ?: return String.format(
|
val declarationElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor)
|
||||||
"Error type encountered: %s (%s).",
|
?: return "Error type encountered: $type (${type.javaClass.simpleName})."
|
||||||
type,
|
|
||||||
type.javaClass.simpleName
|
|
||||||
)
|
|
||||||
|
|
||||||
val containingDeclaration = descriptor.containingDeclaration
|
val containingDeclaration = descriptor.containingDeclaration
|
||||||
val parentDeclarationElement =
|
val parentDeclarationElement =
|
||||||
if (containingDeclaration != null) DescriptorToSourceUtils.descriptorToDeclaration(containingDeclaration) else null
|
if (containingDeclaration != null) DescriptorToSourceUtils.descriptorToDeclaration(containingDeclaration) else null
|
||||||
|
|
||||||
return String.format(
|
return "Error type encountered: %s (%s). Descriptor: %s. For declaration %s:%s in %s:%s".format(
|
||||||
"Error type encountered: %s (%s). Descriptor: %s. For declaration %s:%s in %s:%s",
|
|
||||||
type,
|
type,
|
||||||
type.javaClass.simpleName,
|
type.javaClass.simpleName,
|
||||||
descriptor,
|
descriptor,
|
||||||
@@ -1525,9 +1413,8 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getJvmShortName(klass: ClassDescriptor): String {
|
private fun getJvmShortName(klass: ClassDescriptor): String {
|
||||||
val classId = JavaToKotlinClassMap.mapKotlinToJava(getFqName(klass))
|
return JavaToKotlinClassMap.mapKotlinToJava(getFqName(klass))?.shortClassName?.asString()
|
||||||
return classId?.shortClassName?.asString() ?: SpecialNames.safeIdentifier(klass.name).identifier
|
?: SpecialNames.safeIdentifier(klass.name).identifier
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hasNothingInNonContravariantPosition(kotlinType: KotlinType): Boolean {
|
private fun hasNothingInNonContravariantPosition(kotlinType: KotlinType): Boolean {
|
||||||
@@ -1548,15 +1435,11 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getVarianceForWildcard(
|
fun getVarianceForWildcard(parameter: TypeParameterDescriptor, projection: TypeProjection, mode: TypeMappingMode): Variance {
|
||||||
parameter: TypeParameterDescriptor,
|
|
||||||
projection: TypeProjection,
|
|
||||||
mode: TypeMappingMode
|
|
||||||
): Variance {
|
|
||||||
val projectionKind = projection.projectionKind
|
val projectionKind = projection.projectionKind
|
||||||
val parameterVariance = parameter.variance
|
val parameterVariance = parameter.variance
|
||||||
|
|
||||||
if (parameterVariance === Variance.INVARIANT) {
|
if (parameterVariance == Variance.INVARIANT) {
|
||||||
return projectionKind
|
return projectionKind
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1564,13 +1447,13 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
return Variance.INVARIANT
|
return Variance.INVARIANT
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projectionKind === Variance.INVARIANT || projectionKind === parameterVariance) {
|
if (projectionKind == Variance.INVARIANT || projectionKind == parameterVariance) {
|
||||||
if (mode.skipDeclarationSiteWildcardsIfPossible && !projection.isStarProjection) {
|
if (mode.skipDeclarationSiteWildcardsIfPossible && !projection.isStarProjection) {
|
||||||
if (parameterVariance === Variance.OUT_VARIANCE && projection.type.isMostPreciseCovariantArgument()) {
|
if (parameterVariance == Variance.OUT_VARIANCE && projection.type.isMostPreciseCovariantArgument()) {
|
||||||
return Variance.INVARIANT
|
return Variance.INVARIANT
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parameterVariance === Variance.IN_VARIANCE && projection.type.isMostPreciseContravariantArgument(parameter)) {
|
if (parameterVariance == Variance.IN_VARIANCE && projection.type.isMostPreciseContravariantArgument(parameter)) {
|
||||||
return Variance.INVARIANT
|
return Variance.INVARIANT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1584,11 +1467,11 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
|
|
||||||
//NB: similar platform agnostic code in DescriptorUtils.unwrapFakeOverride
|
//NB: similar platform agnostic code in DescriptorUtils.unwrapFakeOverride
|
||||||
private fun findSuperDeclaration(descriptor: FunctionDescriptor, isSuperCall: Boolean): FunctionDescriptor {
|
private fun findSuperDeclaration(descriptor: FunctionDescriptor, isSuperCall: Boolean): FunctionDescriptor {
|
||||||
var descriptor = descriptor
|
var current = descriptor
|
||||||
while (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
while (current.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||||
val overridden = descriptor.overriddenDescriptors
|
val overridden = current.overriddenDescriptors
|
||||||
if (overridden.isEmpty()) {
|
if (overridden.isEmpty()) {
|
||||||
throw IllegalStateException("Fake override should have at least one overridden descriptor: $descriptor")
|
throw IllegalStateException("Fake override should have at least one overridden descriptor: $current")
|
||||||
}
|
}
|
||||||
|
|
||||||
var classCallable: FunctionDescriptor? = null
|
var classCallable: FunctionDescriptor? = null
|
||||||
@@ -1601,16 +1484,16 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
|
|
||||||
if (classCallable != null) {
|
if (classCallable != null) {
|
||||||
//prefer class callable cause of else branch
|
//prefer class callable cause of else branch
|
||||||
descriptor = classCallable
|
current = classCallable
|
||||||
continue
|
continue
|
||||||
} else if (isSuperCall && !descriptor.hasJvmDefaultAnnotation() && !isInterface(descriptor.containingDeclaration)) {
|
} else if (isSuperCall && !current.hasJvmDefaultAnnotation() && !isInterface(current.containingDeclaration)) {
|
||||||
//Don't unwrap fake overrides from class to interface cause substituted override would be implicitly generated
|
//Don't unwrap fake overrides from class to interface cause substituted override would be implicitly generated
|
||||||
return descriptor
|
return current
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptor = overridden.iterator().next()
|
current = overridden.iterator().next()
|
||||||
}
|
}
|
||||||
return descriptor
|
return current
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@@ -1665,8 +1548,8 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
@JvmField
|
@JvmField
|
||||||
val UNBOX_JVM_METHOD_NAME = InlineClassDescriptorResolver.UNBOX_METHOD_NAME.toString() + JvmAbi.IMPL_SUFFIX_FOR_INLINE_CLASS_MEMBERS
|
val UNBOX_JVM_METHOD_NAME = InlineClassDescriptorResolver.UNBOX_METHOD_NAME.toString() + JvmAbi.IMPL_SUFFIX_FOR_INLINE_CLASS_MEMBERS
|
||||||
|
|
||||||
private fun getPartSimpleNameForMangling(descriptor: CallableMemberDescriptor): String? {
|
private fun getPartSimpleNameForMangling(callableDescriptor: CallableMemberDescriptor): String? {
|
||||||
var descriptor = descriptor
|
var descriptor = callableDescriptor
|
||||||
val containingFile = DescriptorToSourceUtils.getContainingFile(descriptor)
|
val containingFile = DescriptorToSourceUtils.getContainingFile(descriptor)
|
||||||
if (containingFile != null) {
|
if (containingFile != null) {
|
||||||
val fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(containingFile)
|
val fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(containingFile)
|
||||||
@@ -1676,7 +1559,9 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
descriptor = DescriptorUtils.getDirectMember(descriptor)
|
descriptor = DescriptorUtils.getDirectMember(descriptor)
|
||||||
assert(descriptor is DeserializedCallableMemberDescriptor) { "Descriptor without sources should be instance of DeserializedCallableMemberDescriptor, but: $descriptor" }
|
assert(descriptor is DeserializedCallableMemberDescriptor) {
|
||||||
|
"Descriptor without sources should be instance of DeserializedCallableMemberDescriptor, but: $descriptor"
|
||||||
|
}
|
||||||
val containingClassesInfo = getContainingClassesForDeserializedCallable(descriptor as DeserializedCallableMemberDescriptor)
|
val containingClassesInfo = getContainingClassesForDeserializedCallable(descriptor as DeserializedCallableMemberDescriptor)
|
||||||
val facadeShortName = containingClassesInfo.facadeClassId.shortClassName.asString()
|
val facadeShortName = containingClassesInfo.facadeClassId.shortClassName.asString()
|
||||||
val implShortName = containingClassesInfo.implClassId.shortClassName.asString()
|
val implShortName = containingClassesInfo.implClassId.shortClassName.asString()
|
||||||
@@ -1711,8 +1596,9 @@ class KotlinTypeMapper @JvmOverloads constructor(
|
|||||||
|
|
||||||
private fun isBoxMethodForInlineClass(descriptor: FunctionDescriptor): Boolean {
|
private fun isBoxMethodForInlineClass(descriptor: FunctionDescriptor): Boolean {
|
||||||
val containingDeclaration = descriptor.containingDeclaration
|
val containingDeclaration = descriptor.containingDeclaration
|
||||||
return if (!containingDeclaration.isInlineClass()) false else CallableMemberDescriptor.Kind.SYNTHESIZED == descriptor.kind && InlineClassDescriptorResolver.BOX_METHOD_NAME == descriptor.name
|
return containingDeclaration.isInlineClass() &&
|
||||||
|
descriptor.kind == CallableMemberDescriptor.Kind.SYNTHESIZED &&
|
||||||
|
descriptor.name == InlineClassDescriptorResolver.BOX_METHOD_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeVoidReturn(sw: JvmSignatureWriter) {
|
private fun writeVoidReturn(sw: JvmSignatureWriter) {
|
||||||
|
|||||||
Reference in New Issue
Block a user