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