[Commonizer] Rename: TypeParameterResolver -> CirTypeParameterResolver

This commit is contained in:
Dmitriy Dolovov
2021-03-05 02:21:19 +03:00
parent d07ede7305
commit 6b0f080ed8
4 changed files with 10 additions and 10 deletions
@@ -10,7 +10,7 @@ import kotlinx.metadata.klib.annotations
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeSignature import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeSignature
import org.jetbrains.kotlin.descriptors.commonizer.core.Commonizer import org.jetbrains.kotlin.descriptors.commonizer.core.Commonizer
import org.jetbrains.kotlin.descriptors.commonizer.metadata.TypeParameterResolver import org.jetbrains.kotlin.descriptors.commonizer.metadata.CirTypeParameterResolver
import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode import org.jetbrains.kotlin.descriptors.commonizer.utils.appendHashCode
import org.jetbrains.kotlin.descriptors.commonizer.utils.computeSignature import org.jetbrains.kotlin.descriptors.commonizer.utils.computeSignature
import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode import org.jetbrains.kotlin.descriptors.commonizer.utils.hashCode
@@ -21,7 +21,7 @@ data class PropertyApproximationKey(
val name: CirName, val name: CirName,
val extensionReceiverParameterType: CirTypeSignature? val extensionReceiverParameterType: CirTypeSignature?
) { ) {
constructor(property: KmProperty, typeParameterResolver: TypeParameterResolver) : this( constructor(property: KmProperty, typeParameterResolver: CirTypeParameterResolver) : this(
CirName.create(property.name), CirName.create(property.name),
property.receiverParameterType?.computeSignature(typeParameterResolver) property.receiverParameterType?.computeSignature(typeParameterResolver)
) )
@@ -34,7 +34,7 @@ data class FunctionApproximationKey(
private val additionalValueParametersNamesHash: Int, private val additionalValueParametersNamesHash: Int,
val extensionReceiverParameterType: CirTypeSignature? val extensionReceiverParameterType: CirTypeSignature?
) { ) {
constructor(function: KmFunction, typeParameterResolver: TypeParameterResolver) : this( constructor(function: KmFunction, typeParameterResolver: CirTypeParameterResolver) : this(
CirName.create(function.name), CirName.create(function.name),
function.valueParameters.computeSignatures(typeParameterResolver), function.valueParameters.computeSignatures(typeParameterResolver),
additionalValueParameterNamesHash(function.annotations, function.valueParameters), additionalValueParameterNamesHash(function.annotations, function.valueParameters),
@@ -62,7 +62,7 @@ data class ConstructorApproximationKey(
val valueParametersTypes: Array<CirTypeSignature>, val valueParametersTypes: Array<CirTypeSignature>,
private val additionalValueParametersNamesHash: Int private val additionalValueParametersNamesHash: Int
) { ) {
constructor(constructor: KmConstructor, typeParameterResolver: TypeParameterResolver) : this( constructor(constructor: KmConstructor, typeParameterResolver: CirTypeParameterResolver) : this(
constructor.valueParameters.computeSignatures(typeParameterResolver), constructor.valueParameters.computeSignatures(typeParameterResolver),
additionalValueParameterNamesHash(constructor.annotations, constructor.valueParameters) additionalValueParameterNamesHash(constructor.annotations, constructor.valueParameters)
) )
@@ -80,7 +80,7 @@ data class ConstructorApproximationKey(
} }
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
private inline fun List<KmValueParameter>.computeSignatures(typeParameterResolver: TypeParameterResolver): Array<CirTypeSignature> = private inline fun List<KmValueParameter>.computeSignatures(typeParameterResolver: CirTypeParameterResolver): Array<CirTypeSignature> =
if (isEmpty()) emptyArray() else Array(size) { index -> this[index].type?.computeSignature(typeParameterResolver).orEmpty() } if (isEmpty()) emptyArray() else Array(size) { index -> this[index].type?.computeSignature(typeParameterResolver).orEmpty() }
private fun additionalValueParameterNamesHash(annotations: List<KmAnnotation>, valueParameters: List<KmValueParameter>): Int { private fun additionalValueParameterNamesHash(annotations: List<KmAnnotation>, valueParameters: List<KmValueParameter>): Int {
@@ -7,6 +7,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.metadata
import kotlinx.metadata.KmTypeParameter import kotlinx.metadata.KmTypeParameter
interface TypeParameterResolver { interface CirTypeParameterResolver {
fun resolveTypeParameter(id: Int): KmTypeParameter? fun resolveTypeParameter(id: Int): KmTypeParameter?
} }
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirProvidedClassif
typealias TypeParameterId = Int typealias TypeParameterId = Int
typealias TypeParameterIndex = Int typealias TypeParameterIndex = Int
abstract class CirTypeResolver : TypeParameterResolver { abstract class CirTypeResolver : CirTypeParameterResolver {
abstract val providedClassifiers: CirProvidedClassifiers abstract val providedClassifiers: CirProvidedClassifiers
protected abstract val typeParameterIndexOffset: Int protected abstract val typeParameterIndexOffset: Int
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.utils
import gnu.trove.TIntHashSet import gnu.trove.TIntHashSet
import kotlinx.metadata.* import kotlinx.metadata.*
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeSignature import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeSignature
import org.jetbrains.kotlin.descriptors.commonizer.metadata.TypeParameterResolver import org.jetbrains.kotlin.descriptors.commonizer.metadata.CirTypeParameterResolver
internal inline val KmTypeParameter.filteredUpperBounds: List<KmType> internal inline val KmTypeParameter.filteredUpperBounds: List<KmType>
get() = upperBounds.takeUnless { it.singleOrNull()?.isNullableAny == true } ?: emptyList() get() = upperBounds.takeUnless { it.singleOrNull()?.isNullableAny == true } ?: emptyList()
@@ -23,7 +23,7 @@ private inline val KmType.isAny: Boolean
get() = (classifier as? KmClassifier.Class)?.name == ANY_CLASS_FULL_NAME && !Flag.Type.IS_NULLABLE(flags) get() = (classifier as? KmClassifier.Class)?.name == ANY_CLASS_FULL_NAME && !Flag.Type.IS_NULLABLE(flags)
internal fun KmType.computeSignature(typeParameterResolver: TypeParameterResolver): CirTypeSignature { internal fun KmType.computeSignature(typeParameterResolver: CirTypeParameterResolver): CirTypeSignature {
// use of interner saves up to 95% of duplicates // use of interner saves up to 95% of duplicates
return typeSignatureInterner.intern( return typeSignatureInterner.intern(
buildString { buildString {
@@ -38,7 +38,7 @@ internal fun KmType.computeSignature(typeParameterResolver: TypeParameterResolve
private fun StringBuilder.buildTypeSignature( private fun StringBuilder.buildTypeSignature(
type: KmType, type: KmType,
typeParameterResolver: TypeParameterResolver, typeParameterResolver: CirTypeParameterResolver,
exploredTypeParameters: TIntHashSet exploredTypeParameters: TIntHashSet
) { ) {
when (val classifier = type.classifier) { when (val classifier = type.classifier) {