[Commonizer] Only serialize common or LeafCommonizerTargets
This commit is contained in:
@@ -30,7 +30,7 @@ fun runCommonization(parameters: CommonizerParameters) {
|
||||
}
|
||||
|
||||
val storageManager = LockBasedStorageManager("Declarations commonization")
|
||||
serializeCommonDeclarations(commonize(parameters, storageManager, parameters.outputTarget), parameters)
|
||||
commonize(parameters, storageManager, parameters.outputTarget)
|
||||
parameters.resultsConsumer.allConsumed(Status.DONE)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ private fun commonize(
|
||||
mergedTree.accept(CommonizationVisitor(classifiers, mergedTree), Unit)
|
||||
parameters.progressLogger?.invoke("Commonized declarations for $target")
|
||||
|
||||
serializeTargetDeclarations(mergedTree, parameters)
|
||||
serialize(mergedTree, parameters)
|
||||
parameters.progressLogger?.invoke("Commonized target $target")
|
||||
|
||||
return mergedTree
|
||||
@@ -69,35 +69,32 @@ private fun getCirTree(
|
||||
}
|
||||
}
|
||||
|
||||
private fun serializeTargetDeclarations(mergedTree: CirRootNode, parameters: CommonizerParameters) {
|
||||
for (targetIndex in (mergedTree.indices - mergedTree.indexOfCommon)) {
|
||||
private fun serialize(mergedTree: CirRootNode, parameters: CommonizerParameters) {
|
||||
for (targetIndex in mergedTree.indices) {
|
||||
serializeTarget(mergedTree, targetIndex, parameters)
|
||||
}
|
||||
}
|
||||
|
||||
private fun serializeCommonDeclarations(mergedTree: CirRootNode, parameters: CommonizerParameters) {
|
||||
serializeTarget(mergedTree, mergedTree.indexOfCommon, parameters)
|
||||
}
|
||||
|
||||
private fun serializeTarget(mergedTree: CirRootNode, targetIndex: Int, parameters: CommonizerParameters) {
|
||||
val target = mergedTree.getTarget(targetIndex)
|
||||
|
||||
CirTreeSerializer.serializeSingleTarget(mergedTree, targetIndex, parameters.statsCollector) { metadataModule ->
|
||||
val libraryName = metadataModule.name
|
||||
val serializedMetadata = with(metadataModule.write(KLIB_FRAGMENT_WRITE_STRATEGY)) {
|
||||
SerializedMetadata(header, fragments, fragmentNames)
|
||||
}
|
||||
val manifestData = parameters.manifestProvider[target].getManifest(libraryName)
|
||||
parameters.resultsConsumer.consume(target, ModuleResult.Commonized(libraryName, serializedMetadata, manifestData))
|
||||
}
|
||||
|
||||
if (target in parameters.targetProviders.targets) {
|
||||
parameters.targetProviders[target].modulesProvider.loadModuleInfos()
|
||||
.filter { it.name !in parameters.getCommonModuleNames() }
|
||||
.forEach { missingModule -> parameters.resultsConsumer.consume(target, ModuleResult.Missing(missingModule.originalLocation)) }
|
||||
}
|
||||
|
||||
parameters.resultsConsumer.targetConsumed(target)
|
||||
if (targetIndex == mergedTree.indexOfCommon || target is LeafCommonizerTarget) {
|
||||
CirTreeSerializer.serializeSingleTarget(mergedTree, targetIndex, parameters.statsCollector) { metadataModule ->
|
||||
val libraryName = metadataModule.name
|
||||
val serializedMetadata = with(metadataModule.write(KLIB_FRAGMENT_WRITE_STRATEGY)) {
|
||||
SerializedMetadata(header, fragments, fragmentNames)
|
||||
}
|
||||
val manifestData = parameters.manifestProvider[target].getManifest(libraryName)
|
||||
parameters.resultsConsumer.consume(target, ModuleResult.Commonized(libraryName, serializedMetadata, manifestData))
|
||||
}
|
||||
parameters.resultsConsumer.targetConsumed(target)
|
||||
}
|
||||
}
|
||||
|
||||
private val KLIB_FRAGMENT_WRITE_STRATEGY = ChunkedKlibModuleFragmentWriteStrategy()
|
||||
|
||||
+30
-30
@@ -20,15 +20,15 @@ class HierarchicalClassCommonizationTest : AbstractInlineSourcesCommonizationTes
|
||||
simpleSingleSourceTarget("e", "class X")
|
||||
}
|
||||
|
||||
result.assertCommonized("a", "actual class X")
|
||||
result.assertCommonized("b", "actual class X")
|
||||
result.assertCommonized("c", "actual class X")
|
||||
result.assertCommonized("d", "actual class X")
|
||||
result.assertCommonized("e", "actual class X")
|
||||
result.assertCommonized("a", "class X")
|
||||
result.assertCommonized("b", "class X")
|
||||
result.assertCommonized("c", "class X")
|
||||
result.assertCommonized("d", "class X")
|
||||
result.assertCommonized("e", "class X")
|
||||
|
||||
result.assertCommonized("(a,b)", "class X")
|
||||
result.assertCommonized("(c,d)", "class X")
|
||||
result.assertCommonized("(a,b)", "class X")
|
||||
result.assertCommonized("(a,b)", "expect class X expect constructor()")
|
||||
result.assertCommonized("(c,d)", "expect class X expect constructor()")
|
||||
result.assertCommonized("(a,b)", "expect class X expect constructor()")
|
||||
result.assertCommonized("((a,b), (c,d), e)", "expect class X expect constructor()")
|
||||
}
|
||||
|
||||
@@ -78,58 +78,58 @@ class HierarchicalClassCommonizationTest : AbstractInlineSourcesCommonizationTes
|
||||
|
||||
result.assertCommonized(
|
||||
"a", """
|
||||
actual class X {
|
||||
actual val a: Int = 42
|
||||
actual val ab: Int = 42
|
||||
actual val abcd: Int = 42
|
||||
class X {
|
||||
val a: Int = 42
|
||||
val ab: Int = 42
|
||||
val abcd: Int = 42
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"b", """
|
||||
actual class X {
|
||||
actual val b: Int = 42
|
||||
actual val ab: Int = 42
|
||||
actual val abcd: Int = 42
|
||||
class X {
|
||||
val b: Int = 42
|
||||
val ab: Int = 42
|
||||
val abcd: Int = 42
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"c", """
|
||||
actual class X {
|
||||
actual val c: Int = 42
|
||||
actual val cd: Int = 42
|
||||
actual val abcd: Int = 42
|
||||
class X {
|
||||
val c: Int = 42
|
||||
val cd: Int = 42
|
||||
val abcd: Int = 42
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"d", """
|
||||
actual class X {
|
||||
actual val d: Int = 42
|
||||
actual val cd: Int = 42
|
||||
actual val abcd: Int = 42
|
||||
class X {
|
||||
val d: Int = 42
|
||||
val cd: Int = 42
|
||||
val abcd: Int = 42
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(a,b)", """
|
||||
class X {
|
||||
val ab: Int
|
||||
val abcd: Int
|
||||
expect class X expect constructor() {
|
||||
expect val ab: Int
|
||||
expect val abcd: Int
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(c,d)", """
|
||||
class X {
|
||||
val cd: Int
|
||||
val abcd: Int
|
||||
expect class X expect constructor() {
|
||||
expect val cd: Int
|
||||
expect val abcd: Int
|
||||
}
|
||||
"""
|
||||
)
|
||||
|
||||
+34
-34
@@ -20,8 +20,8 @@ class HierarchicalFunctionCommonizationTest : AbstractInlineSourcesCommonization
|
||||
}
|
||||
|
||||
result.assertCommonized("((a,b), (c,d))", "expect fun x(): Int")
|
||||
result.assertCommonized("(a,b)", "actual fun x(): Int = 42")
|
||||
result.assertCommonized("(c,d)", "actual fun x(): Int = 42")
|
||||
result.assertCommonized("(a,b)", "expect fun x(): Int")
|
||||
result.assertCommonized("(c,d)", "expect fun x(): Int")
|
||||
result.assertCommonized("a", "actual fun x(): Int = 42")
|
||||
result.assertCommonized("b", "actual fun x(): Int = 42")
|
||||
result.assertCommonized("c", "actual fun x(): Int = 42")
|
||||
@@ -37,10 +37,10 @@ class HierarchicalFunctionCommonizationTest : AbstractInlineSourcesCommonization
|
||||
}
|
||||
|
||||
result.assertCommonized("((a,b), c)", "expect fun x(): Int")
|
||||
result.assertCommonized("(a,b)", "actual fun x(): Int = 42")
|
||||
result.assertCommonized("a", "actual fun x(): Int = 42")
|
||||
result.assertCommonized("b", "actual fun x(): Int = 42")
|
||||
result.assertCommonized("c", "actual fun x(): Int = 42")
|
||||
result.assertCommonized("(a,b)", "expect fun x(): Int")
|
||||
result.assertCommonized("a", "fun x(): Int = 42")
|
||||
result.assertCommonized("b", "fun x(): Int = 42")
|
||||
result.assertCommonized("c", "fun x(): Int = 42")
|
||||
}
|
||||
|
||||
fun `test function with returnType`() {
|
||||
@@ -75,43 +75,43 @@ class HierarchicalFunctionCommonizationTest : AbstractInlineSourcesCommonization
|
||||
|
||||
result.assertCommonized(
|
||||
"a", """
|
||||
actual interface ABCD
|
||||
actual fun x(): ABCD = TODO()
|
||||
interface ABCD
|
||||
fun x(): ABCD = TODO()
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"b", """
|
||||
actual interface ABCD
|
||||
actual fun x(): ABCD = TODO()
|
||||
interface ABCD
|
||||
fun x(): ABCD = TODO()
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"c", """
|
||||
actual interface ABCD
|
||||
actual fun x(): ABCD = TODO()
|
||||
interface ABCD
|
||||
fun x(): ABCD = TODO()
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"d", """
|
||||
actual interface ABCD
|
||||
actual fun x(): ABCD = TODO()
|
||||
interface ABCD
|
||||
fun x(): ABCD = TODO()
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(a, b)", """
|
||||
actual interface ABCD
|
||||
actual fun x(): ABCD
|
||||
expect interface ABCD
|
||||
expect fun x(): ABCD
|
||||
"""
|
||||
)
|
||||
|
||||
result.assertCommonized(
|
||||
"(c, d)", """
|
||||
actual interface ABCD
|
||||
actual fun x(): ABCD
|
||||
expect interface ABCD
|
||||
expect fun x(): ABCD
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -133,12 +133,12 @@ class HierarchicalFunctionCommonizationTest : AbstractInlineSourcesCommonization
|
||||
simpleSingleSourceTarget("d", "fun x(): ABCD = TODO()")
|
||||
}
|
||||
|
||||
result.assertCommonized("a", "actual fun x(): ABCD")
|
||||
result.assertCommonized("b", "actual fun x(): ABCD")
|
||||
result.assertCommonized("c", "actual fun x(): ABCD")
|
||||
result.assertCommonized("d", "actual fun x(): ABCD")
|
||||
result.assertCommonized("(c, d)", "fun x(): ABCD")
|
||||
result.assertCommonized("(a, b)", "fun x(): ABCD")
|
||||
result.assertCommonized("a", "fun x(): ABCD")
|
||||
result.assertCommonized("b", "fun x(): ABCD")
|
||||
result.assertCommonized("c", "fun x(): ABCD")
|
||||
result.assertCommonized("d", "fun x(): ABCD")
|
||||
result.assertCommonized("(c, d)", "expect fun x(): ABCD")
|
||||
result.assertCommonized("(a, b)", "expect fun x(): ABCD")
|
||||
result.assertCommonized("((a,b), (c,d))", "expect fun x(): ABCD")
|
||||
}
|
||||
|
||||
@@ -153,12 +153,12 @@ class HierarchicalFunctionCommonizationTest : AbstractInlineSourcesCommonization
|
||||
simpleSingleSourceTarget("d", "fun x(): ABCD = TODO()")
|
||||
}
|
||||
|
||||
result.assertCommonized("a", "actual fun x(): ABCD")
|
||||
result.assertCommonized("b", "actual fun x(): ABCD")
|
||||
result.assertCommonized("c", "actual fun x(): ABCD")
|
||||
result.assertCommonized("d", "actual fun x(): ABCD")
|
||||
result.assertCommonized("(c, d)", "fun x(): ABCD")
|
||||
result.assertCommonized("(a, b)", "fun x(): ABCD")
|
||||
result.assertCommonized("a", "fun x(): ABCD")
|
||||
result.assertCommonized("b", "fun x(): ABCD")
|
||||
result.assertCommonized("c", "fun x(): ABCD")
|
||||
result.assertCommonized("d", "fun x(): ABCD")
|
||||
result.assertCommonized("(c, d)", "expect fun x(): ABCD")
|
||||
result.assertCommonized("(a, b)", "expect fun x(): ABCD")
|
||||
result.assertCommonized("((a,b), (c,d))", "")
|
||||
}
|
||||
|
||||
@@ -172,10 +172,10 @@ class HierarchicalFunctionCommonizationTest : AbstractInlineSourcesCommonization
|
||||
simpleSingleSourceTarget("c", "fun x(): ABCD = TODO()")
|
||||
}
|
||||
|
||||
result.assertCommonized("a", "actual fun x(): ABCD")
|
||||
result.assertCommonized("b", "actual fun x(): ABCD")
|
||||
result.assertCommonized("c", "actual fun x(): ABCD")
|
||||
result.assertCommonized("(a, b)", "fun x(): ABCD")
|
||||
result.assertCommonized("a", "fun x(): ABCD")
|
||||
result.assertCommonized("b", "fun x(): ABCD")
|
||||
result.assertCommonized("c", "fun x(): ABCD")
|
||||
result.assertCommonized("(a, b)", "expect fun x(): ABCD")
|
||||
result.assertCommonized("((a,b), c)", "expect fun x(): ABCD")
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -195,13 +195,13 @@ class HierarchicalPackageCommonizationTest : AbstractInlineSourcesCommonizationT
|
||||
source(
|
||||
"""
|
||||
package pkg.abcd
|
||||
val dummy: String
|
||||
expect val dummy: String
|
||||
""", "abcd.kt"
|
||||
)
|
||||
source(
|
||||
"""
|
||||
package pkg.ab
|
||||
val dummy: String
|
||||
expect val dummy: String
|
||||
""", "ab.kt"
|
||||
)
|
||||
}
|
||||
@@ -210,13 +210,13 @@ class HierarchicalPackageCommonizationTest : AbstractInlineSourcesCommonizationT
|
||||
source(
|
||||
"""
|
||||
package pkg.abcd
|
||||
val dummy: String
|
||||
expect val dummy: String
|
||||
""", "abcd.kt"
|
||||
)
|
||||
source(
|
||||
"""
|
||||
package pkg.cd
|
||||
val dummy: String
|
||||
expect val dummy: String
|
||||
""", "cd.kt"
|
||||
)
|
||||
}
|
||||
|
||||
+6
-6
@@ -22,11 +22,11 @@ class HierarchicalPropertyCommonizationTest : AbstractInlineSourcesCommonization
|
||||
}
|
||||
|
||||
result.assertCommonized("((a,b), (c,d))", "expect val x: Int")
|
||||
result.assertCommonized("(a, b)", "actual val x: Int")
|
||||
result.assertCommonized("(c, d)", "actual val x: Int")
|
||||
result.assertCommonized("a", "actual val x: Int = 42")
|
||||
result.assertCommonized("b", "actual val x: Int = 42")
|
||||
result.assertCommonized("c", "actual val x: Int = 42")
|
||||
result.assertCommonized("d", "actual val x: Int = 42")
|
||||
result.assertCommonized("(a, b)", "expect val x: Int")
|
||||
result.assertCommonized("(c, d)", "expect val x: Int")
|
||||
result.assertCommonized("a", "val x: Int = 42")
|
||||
result.assertCommonized("b", "val x: Int = 42")
|
||||
result.assertCommonized("c", "val x: Int = 42")
|
||||
result.assertCommonized("d", "val x: Int = 42")
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -20,8 +20,10 @@ class HierarchicalTypeAliasCommonizationTest : AbstractInlineSourcesCommonizatio
|
||||
}
|
||||
|
||||
result.assertCommonized("((a,b), (c,d))", "typealias X = Int")
|
||||
result.assertCommonized("(a,b)", "")
|
||||
result.assertCommonized("(c, d)", "")
|
||||
result.assertCommonized("(a,b)", "typealias X = Int")
|
||||
result.assertCommonized("(c, d)", "typealias X = Int")
|
||||
|
||||
/* Special case: For now, leaves should depend on commonized platform libraries */
|
||||
result.assertCommonized("a", "")
|
||||
result.assertCommonized("b", "")
|
||||
result.assertCommonized("c", "")
|
||||
|
||||
Reference in New Issue
Block a user