[Commonizer] CirKnownClassifiers: Store indices and target dependencies as 'TargetDependent'
^KT-47430
This commit is contained in:
committed by
Space
parent
367db345a8
commit
9fb41b6334
@@ -33,6 +33,16 @@ sealed interface TargetDependent<T> : Iterable<T> {
|
|||||||
fun getOrNull(index: Int): T? {
|
fun getOrNull(index: Int): T? {
|
||||||
return getOrNull(targets.getOrNull(index) ?: return null)
|
return getOrNull(targets.getOrNull(index) ?: return null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
fun <T> empty(): TargetDependent<T> = Empty as TargetDependent<T>
|
||||||
|
}
|
||||||
|
|
||||||
|
object Empty : TargetDependent<Any?> {
|
||||||
|
override val targets: List<CommonizerTarget> = emptyList()
|
||||||
|
override fun get(target: CommonizerTarget) = throwMissingTarget(target)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun <T : Any> TargetDependent<T?>.filterNonNull(): TargetDependent<T> {
|
internal fun <T : Any> TargetDependent<T?>.filterNonNull(): TargetDependent<T> {
|
||||||
@@ -96,7 +106,7 @@ private class FactoryBasedTargetDependent<T>(
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
override fun get(target: CommonizerTarget): T {
|
override fun get(target: CommonizerTarget): T {
|
||||||
val indexOfTarget = indexOf(target)
|
val indexOfTarget = indexOf(target)
|
||||||
if (indexOfTarget < 0) throw NoSuchElementException("Missing target $target")
|
if (indexOfTarget < 0) throwMissingTarget(target)
|
||||||
val storedValue = values[indexOfTarget]
|
val storedValue = values[indexOfTarget]
|
||||||
if (storedValue == Uninitialized) {
|
if (storedValue == Uninitialized) {
|
||||||
val producedValue = factory?.invoke(target)
|
val producedValue = factory?.invoke(target)
|
||||||
@@ -112,3 +122,5 @@ private class FactoryBasedTargetDependent<T>(
|
|||||||
return storedValue as T
|
return storedValue as T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun throwMissingTarget(target: CommonizerTarget): Nothing = throw NoSuchElementException("Missing target $target")
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ internal fun commonizeTarget(
|
|||||||
|
|
||||||
parameters.logger.progress(output, "Commonized declarations from ${inputs.targets}") {
|
parameters.logger.progress(output, "Commonized declarations from ${inputs.targets}") {
|
||||||
val classifiers = CirKnownClassifiers(
|
val classifiers = CirKnownClassifiers(
|
||||||
classifierIndices = availableTrees.toList().map(::CirClassifierIndex),
|
classifierIndices = availableTrees.mapValue(::CirClassifierIndex),
|
||||||
|
targetDependencies = availableTrees.mapValue(CirTreeRoot::dependencies),
|
||||||
commonizedNodes = CirCommonizedClassifierNodes.default(),
|
commonizedNodes = CirCommonizedClassifierNodes.default(),
|
||||||
commonDependencies = parameters.dependencyClassifiers(output)
|
commonDependencies = parameters.dependencyClassifiers(output)
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-1
@@ -6,10 +6,12 @@
|
|||||||
package org.jetbrains.kotlin.commonizer.mergedtree
|
package org.jetbrains.kotlin.commonizer.mergedtree
|
||||||
|
|
||||||
import gnu.trove.THashMap
|
import gnu.trove.THashMap
|
||||||
|
import org.jetbrains.kotlin.commonizer.TargetDependent
|
||||||
import org.jetbrains.kotlin.commonizer.cir.CirEntityId
|
import org.jetbrains.kotlin.commonizer.cir.CirEntityId
|
||||||
|
|
||||||
class CirKnownClassifiers(
|
class CirKnownClassifiers(
|
||||||
val classifierIndices: List<CirClassifierIndex>,
|
val classifierIndices: TargetDependent<CirClassifierIndex>,
|
||||||
|
val targetDependencies: TargetDependent<CirProvidedClassifiers>,
|
||||||
val commonizedNodes: CirCommonizedClassifierNodes,
|
val commonizedNodes: CirCommonizedClassifierNodes,
|
||||||
val commonDependencies: CirProvidedClassifiers
|
val commonDependencies: CirProvidedClassifiers
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-1
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.commonizer.transformer
|
package org.jetbrains.kotlin.commonizer.transformer
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.commonizer.TargetDependent
|
||||||
import org.jetbrains.kotlin.commonizer.cir.*
|
import org.jetbrains.kotlin.commonizer.cir.*
|
||||||
import org.jetbrains.kotlin.commonizer.cir.CirClassType.Companion.copyInterned
|
import org.jetbrains.kotlin.commonizer.cir.CirClassType.Companion.copyInterned
|
||||||
import org.jetbrains.kotlin.commonizer.cir.CirTypeAliasType.Companion.copyInterned
|
import org.jetbrains.kotlin.commonizer.cir.CirTypeAliasType.Companion.copyInterned
|
||||||
@@ -15,7 +16,7 @@ import org.jetbrains.kotlin.commonizer.tree.CirTreeTypeAlias
|
|||||||
|
|
||||||
internal class CirAliasTypeSubstitutor(
|
internal class CirAliasTypeSubstitutor(
|
||||||
private val commonDependencies: CirProvidedClassifiers,
|
private val commonDependencies: CirProvidedClassifiers,
|
||||||
private val classifierIndices: List<CirClassifierIndex>
|
private val classifierIndices: TargetDependent<CirClassifierIndex>
|
||||||
) : CirTypeSubstitutor {
|
) : CirTypeSubstitutor {
|
||||||
|
|
||||||
override fun substitute(targetIndex: Int, type: CirType): CirType {
|
override fun substitute(targetIndex: Int, type: CirType): CirType {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.commonizer.core
|
package org.jetbrains.kotlin.commonizer.core
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.commonizer.TargetDependent
|
||||||
import org.jetbrains.kotlin.commonizer.cir.*
|
import org.jetbrains.kotlin.commonizer.cir.*
|
||||||
import org.jetbrains.kotlin.commonizer.mergedtree.*
|
import org.jetbrains.kotlin.commonizer.mergedtree.*
|
||||||
import org.jetbrains.kotlin.commonizer.utils.isUnderStandardKotlinPackages
|
import org.jetbrains.kotlin.commonizer.utils.isUnderStandardKotlinPackages
|
||||||
@@ -25,7 +26,8 @@ class TypeCommonizerTest : AbstractCommonizerTest<CirType, CirType>() {
|
|||||||
fun initialize() {
|
fun initialize() {
|
||||||
// reset cache
|
// reset cache
|
||||||
classifiers = CirKnownClassifiers(
|
classifiers = CirKnownClassifiers(
|
||||||
classifierIndices = emptyList(), // TODO NOW
|
classifierIndices = TargetDependent.empty(),
|
||||||
|
targetDependencies = TargetDependent.empty(),
|
||||||
commonizedNodes = CirCommonizedClassifierNodes.default(),
|
commonizedNodes = CirCommonizedClassifierNodes.default(),
|
||||||
commonDependencies = object : CirProvidedClassifiers {
|
commonDependencies = object : CirProvidedClassifiers {
|
||||||
override fun hasClassifier(classifierId: CirEntityId) = classifierId.packageName.isUnderStandardKotlinPackages
|
override fun hasClassifier(classifierId: CirEntityId) = classifierId.packageName.isUnderStandardKotlinPackages
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,6 @@
|
|||||||
package org.jetbrains.kotlin.commonizer.transformer
|
package org.jetbrains.kotlin.commonizer.transformer
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.commonizer.TargetDependent
|
||||||
import org.jetbrains.kotlin.commonizer.cir.*
|
import org.jetbrains.kotlin.commonizer.cir.*
|
||||||
import org.jetbrains.kotlin.commonizer.mergedtree.*
|
import org.jetbrains.kotlin.commonizer.mergedtree.*
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
@@ -15,7 +16,8 @@ class InlineTypeAliasCirNodeTransformerTest {
|
|||||||
private val storageManager = LockBasedStorageManager("test")
|
private val storageManager = LockBasedStorageManager("test")
|
||||||
|
|
||||||
private val classifiers = CirKnownClassifiers(
|
private val classifiers = CirKnownClassifiers(
|
||||||
classifierIndices = emptyList(),
|
classifierIndices = TargetDependent.empty(),
|
||||||
|
targetDependencies = TargetDependent.empty(),
|
||||||
commonizedNodes = CirCommonizedClassifierNodes.default(),
|
commonizedNodes = CirCommonizedClassifierNodes.default(),
|
||||||
commonDependencies = CirProvidedClassifiers.EMPTY
|
commonDependencies = CirProvidedClassifiers.EMPTY
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-1
@@ -88,7 +88,8 @@ abstract class AbstractMergeCirTreeTest : KtInlineSourceCommonizerTestCase() {
|
|||||||
|
|
||||||
private fun createDefaultKnownClassifiers(): CirKnownClassifiers {
|
private fun createDefaultKnownClassifiers(): CirKnownClassifiers {
|
||||||
return CirKnownClassifiers(
|
return CirKnownClassifiers(
|
||||||
emptyList(), // TODO NOW
|
TargetDependent.empty(),
|
||||||
|
TargetDependent.empty(),
|
||||||
CirCommonizedClassifierNodes.default(),
|
CirCommonizedClassifierNodes.default(),
|
||||||
CirProvidedClassifiers.of(
|
CirProvidedClassifiers.of(
|
||||||
CirFictitiousFunctionClassifiers,
|
CirFictitiousFunctionClassifiers,
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ private fun createValidClassifierId(classifierId: String): CirEntityId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal val MOCK_CLASSIFIERS = CirKnownClassifiers(
|
internal val MOCK_CLASSIFIERS = CirKnownClassifiers(
|
||||||
classifierIndices = emptyList(),
|
classifierIndices = TargetDependent.empty(),
|
||||||
|
targetDependencies = TargetDependent.empty(),
|
||||||
commonizedNodes = object : CirCommonizedClassifierNodes {
|
commonizedNodes = object : CirCommonizedClassifierNodes {
|
||||||
override fun classNode(classId: CirEntityId) = CirClassNode(
|
override fun classNode(classId: CirEntityId) = CirClassNode(
|
||||||
classId,
|
classId,
|
||||||
|
|||||||
Reference in New Issue
Block a user