[Commonizer] Adapt TypeCommonizerTest
^KT-48288
This commit is contained in:
committed by
Space
parent
36a5b53398
commit
9d2553bd18
+1
-1
@@ -28,7 +28,7 @@ internal class ClassOrTypeAliasTypeCommonizer(
|
||||
val arguments = TypeArgumentListCommonizer(typeCommonizer).commonize(values.map { it.arguments }) ?: return null
|
||||
val classifierId = selectClassifierId(values)
|
||||
?: typeCommonizer.options.enableOptimisticNumberTypeCommonization.ifTrue {
|
||||
return OptimisticNumbersTypeCommonizer.commonize(values.map { it.expandedType() })
|
||||
return OptimisticNumbersTypeCommonizer.commonize(expansions)
|
||||
} ?: return null
|
||||
|
||||
val outerTypes = values.safeCastValues<CirClassOrTypeAliasType, CirClassType>()?.map { it.outerType }
|
||||
|
||||
+18
-8
@@ -15,9 +15,10 @@ import org.jetbrains.kotlin.commonizer.cir.CirTypeAlias
|
||||
|
||||
internal fun CirCommonClassifierIdResolver(
|
||||
classifierIndices: TargetDependent<CirClassifierIndex>,
|
||||
dependencies: CirProvidedClassifiers = CirProvidedClassifiers.EMPTY
|
||||
targetDependencies: TargetDependent<CirProvidedClassifiers>,
|
||||
commonDependencies: CirProvidedClassifiers = CirProvidedClassifiers.EMPTY
|
||||
): CirCommonClassifierIdResolver {
|
||||
return CirCommonClassifierIdResolverImpl(classifierIndices, dependencies)
|
||||
return CirCommonClassifierIdResolverImpl(classifierIndices, targetDependencies, commonDependencies)
|
||||
}
|
||||
|
||||
interface CirCommonClassifierIdResolver {
|
||||
@@ -26,7 +27,8 @@ interface CirCommonClassifierIdResolver {
|
||||
|
||||
private class CirCommonClassifierIdResolverImpl(
|
||||
private val classifierIndices: TargetDependent<CirClassifierIndex>,
|
||||
private val dependencies: CirProvidedClassifiers
|
||||
private val targetDependencies: TargetDependent<CirProvidedClassifiers>,
|
||||
private val commonDependencies: CirProvidedClassifiers
|
||||
) : CirCommonClassifierIdResolver {
|
||||
|
||||
private val cachedResults = THashMap<CirEntityId, CirCommonClassifierId>()
|
||||
@@ -54,8 +56,10 @@ private class CirCommonClassifierIdResolverImpl(
|
||||
val nextClassifierId = queue.removeFirst()
|
||||
|
||||
/* Either CirClassifier or CirProvided.Classifier or null */
|
||||
val foundClassifiers = classifierIndices.associateWith { index ->
|
||||
index.findClassifier(nextClassifierId) ?: dependencies.classifier(nextClassifierId)
|
||||
val foundClassifiers = classifierIndices.targets.associateWith { index ->
|
||||
classifierIndices[index].findClassifier(nextClassifierId)
|
||||
?: targetDependencies[index].classifier(nextClassifierId)
|
||||
?: commonDependencies.classifier(nextClassifierId)
|
||||
}
|
||||
|
||||
/* Classifier is available for all targets */
|
||||
@@ -63,17 +67,23 @@ private class CirCommonClassifierIdResolverImpl(
|
||||
results.add(nextClassifierId)
|
||||
}
|
||||
|
||||
foundClassifiers.forEach { (index, classifier) ->
|
||||
foundClassifiers.forEach { (target, classifier) ->
|
||||
if (classifier == null) return@forEach
|
||||
|
||||
// Propagate to the left (towards typealias)
|
||||
index.findTypeAliasesWithUnderlyingType(nextClassifierId).forEach { alias ->
|
||||
classifierIndices[target].findTypeAliasesWithUnderlyingType(nextClassifierId).forEach { alias ->
|
||||
if (visited.add(alias.id)) {
|
||||
queue.add(alias.id)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies.findTypeAliasesWithUnderlyingType(nextClassifierId).forEach { aliasId ->
|
||||
targetDependencies[target].findTypeAliasesWithUnderlyingType(nextClassifierId).forEach { aliasId ->
|
||||
if (visited.add(aliasId)) {
|
||||
queue.add(aliasId)
|
||||
}
|
||||
}
|
||||
|
||||
commonDependencies.findTypeAliasesWithUnderlyingType(nextClassifierId).forEach { aliasId ->
|
||||
if (visited.add(aliasId)) {
|
||||
queue.add(aliasId)
|
||||
}
|
||||
|
||||
+2
-1
@@ -14,7 +14,8 @@ class CirKnownClassifiers(
|
||||
val targetDependencies: TargetDependent<CirProvidedClassifiers>,
|
||||
val commonizedNodes: CirCommonizedClassifierNodes,
|
||||
val commonDependencies: CirProvidedClassifiers,
|
||||
val commonClassifierIdResolver: CirCommonClassifierIdResolver = CirCommonClassifierIdResolver(classifierIndices, commonDependencies),
|
||||
val commonClassifierIdResolver: CirCommonClassifierIdResolver =
|
||||
CirCommonClassifierIdResolver(classifierIndices, targetDependencies, commonDependencies),
|
||||
)
|
||||
|
||||
/** A set of all CIR nodes built for commonized classes and type aliases. */
|
||||
|
||||
+3
-1
@@ -277,7 +277,9 @@ private fun createCommonClassifierIdResolver(
|
||||
return CirCommonClassifierIdResolver(
|
||||
TargetDependent(root.withIndex().associate { (index, root) -> LeafCommonizerTarget(index.toString()) to root })
|
||||
.mapValue(::CirClassifierIndex),
|
||||
dependencies = dependencies
|
||||
targetDependencies = root.withIndex()
|
||||
.associate { (index, _) -> LeafCommonizerTarget(index.toString()) to CirProvidedClassifiers.EMPTY }.toTargetDependent(),
|
||||
commonDependencies = dependencies
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+577
-449
File diff suppressed because it is too large
Load Diff
@@ -114,3 +114,12 @@ fun InlineSourceBuilder.createCirProvidedClassifiers(module: InlineSourceBuilder
|
||||
return CirProvidedClassifiersByModules.load(modulesProvider)
|
||||
}
|
||||
|
||||
@InlineSourceBuilder.ModuleBuilderDsl
|
||||
fun InlineSourceBuilder.createCirProvidedClassifiers(builder: InlineSourceBuilder.ModuleBuilder.() -> Unit): CirProvidedClassifiers {
|
||||
return createCirProvidedClassifiers(createModule { builder() })
|
||||
}
|
||||
|
||||
@InlineSourceBuilder.ModuleBuilderDsl
|
||||
fun InlineSourceBuilder.createCirProvidedClassifiersFromSourceCode(@Language("kotlin") sourceCode: String): CirProvidedClassifiers {
|
||||
return createCirProvidedClassifiers(createModule { source(sourceCode) })
|
||||
}
|
||||
Reference in New Issue
Block a user