Refactoring: move getRepresentativeUpperBound method to core
Plus prettify it a bit
This commit is contained in:
@@ -6,11 +6,11 @@
|
||||
package org.jetbrains.kotlin.codegen.state
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.load.kotlin.getRepresentativeUpperBound
|
||||
import org.jetbrains.kotlin.resolve.InlineClassDescriptorResolver
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.jvm.*
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.representativeUpperBound
|
||||
import java.security.MessageDigest
|
||||
import java.util.*
|
||||
|
||||
@@ -44,7 +44,7 @@ private fun getSignatureElementForMangling(type: KotlinType): String = buildStri
|
||||
}
|
||||
|
||||
is TypeParameterDescriptor -> {
|
||||
append(getSignatureElementForMangling(getRepresentativeUpperBound(descriptor)))
|
||||
append(getSignatureElementForMangling(descriptor.representativeUpperBound))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.resolve.unsubstitutedUnderlyingType
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
|
||||
import org.jetbrains.kotlin.types.typeUtil.representativeUpperBound
|
||||
import org.jetbrains.kotlin.utils.DO_NOTHING_3
|
||||
|
||||
interface JvmTypeFactory<T : Any> {
|
||||
@@ -181,7 +182,7 @@ fun <T : Any> mapType(
|
||||
|
||||
descriptor is TypeParameterDescriptor -> {
|
||||
val type = mapType(
|
||||
getRepresentativeUpperBound(descriptor),
|
||||
descriptor.representativeUpperBound,
|
||||
factory,
|
||||
mode,
|
||||
typeMappingConfiguration,
|
||||
@@ -255,7 +256,7 @@ internal fun computeUnderlyingType(inlineClassType: KotlinType): KotlinType? {
|
||||
|
||||
val descriptor = inlineClassType.unsubstitutedUnderlyingType()?.constructor?.declarationDescriptor ?: return null
|
||||
return if (descriptor is TypeParameterDescriptor)
|
||||
getRepresentativeUpperBound(descriptor)
|
||||
descriptor.representativeUpperBound
|
||||
else
|
||||
inlineClassType.substitutedUnderlyingType()
|
||||
}
|
||||
@@ -270,7 +271,7 @@ internal fun computeExpandedTypeInner(kotlinType: KotlinType, visitedClassifiers
|
||||
|
||||
return when {
|
||||
classifier is TypeParameterDescriptor ->
|
||||
computeExpandedTypeInner(getRepresentativeUpperBound(classifier), visitedClassifiers)
|
||||
computeExpandedTypeInner(classifier.representativeUpperBound, visitedClassifiers)
|
||||
?.let { expandedUpperBound ->
|
||||
if (expandedUpperBound.isNullable() || !kotlinType.isMarkedNullable)
|
||||
expandedUpperBound
|
||||
@@ -338,16 +339,6 @@ fun computeInternalName(
|
||||
private fun getContainer(container: DeclarationDescriptor?): DeclarationDescriptor? =
|
||||
container as? ClassDescriptor ?: container as? PackageFragmentDescriptor ?: container?.let { getContainer(it.containingDeclaration) }
|
||||
|
||||
fun getRepresentativeUpperBound(descriptor: TypeParameterDescriptor): KotlinType {
|
||||
val upperBounds = descriptor.upperBounds
|
||||
assert(!upperBounds.isEmpty()) { "Upper bounds should not be empty: $descriptor" }
|
||||
|
||||
return upperBounds.firstOrNull {
|
||||
val classDescriptor = it.constructor.declarationDescriptor as? ClassDescriptor ?: return@firstOrNull false
|
||||
classDescriptor.kind != ClassKind.INTERFACE && classDescriptor.kind != ClassKind.ANNOTATION_CLASS
|
||||
} ?: upperBounds.first()
|
||||
}
|
||||
|
||||
open class JvmDescriptorTypeWriter<T : Any>(private val jvmTypeFactory: JvmTypeFactory<T>) {
|
||||
private var jvmCurrentTypeArrayLevel: Int = 0
|
||||
protected var jvmCurrentType: T? = null
|
||||
|
||||
+2
-6
@@ -6,15 +6,11 @@
|
||||
package org.jetbrains.kotlin.resolve.jvm
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.load.kotlin.getRepresentativeUpperBound
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.isInlineClass
|
||||
import org.jetbrains.kotlin.resolve.isInlineClassType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import java.security.MessageDigest
|
||||
import java.util.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.representativeUpperBound
|
||||
|
||||
fun shouldHideConstructorDueToInlineClassTypeValueParameters(descriptor: CallableMemberDescriptor): Boolean {
|
||||
val constructorDescriptor = descriptor as? ClassConstructorDescriptor ?: return false
|
||||
@@ -45,5 +41,5 @@ private fun isDontMangleClass(classDescriptor: ClassDescriptor) =
|
||||
|
||||
private fun KotlinType.isTypeParameterWithUpperBoundThatRequiresMangling(): Boolean {
|
||||
val descriptor = constructor.declarationDescriptor as? TypeParameterDescriptor ?: return false
|
||||
return getRepresentativeUpperBound(descriptor).requiresFunctionNameMangling()
|
||||
return descriptor.representativeUpperBound.requiresFunctionNameMangling()
|
||||
}
|
||||
|
||||
@@ -228,3 +228,14 @@ fun UnwrappedType.canHaveUndefinedNullability(): Boolean =
|
||||
constructor is NewTypeVariableConstructor ||
|
||||
constructor.declarationDescriptor is TypeParameterDescriptor ||
|
||||
this is NewCapturedType
|
||||
|
||||
val TypeParameterDescriptor.representativeUpperBound: KotlinType
|
||||
get() {
|
||||
assert(upperBounds.isNotEmpty()) { "Upper bounds should not be empty: $this" }
|
||||
|
||||
return upperBounds.firstOrNull {
|
||||
val classDescriptor = it.constructor.declarationDescriptor as? ClassDescriptor ?: return@firstOrNull false
|
||||
classDescriptor.kind != ClassKind.INTERFACE && classDescriptor.kind != ClassKind.ANNOTATION_CLASS
|
||||
} ?: upperBounds.first()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user