[Commonizer] typeAliasUtils: computeSuitableUnderlyingType: Consider commonized type-aliases
This commit is contained in:
committed by
Space
parent
5ca81b01f0
commit
9794068f22
+35
@@ -65,6 +65,41 @@ class CommonizeNativeDistributionTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `commonize - apple platforms`() {
|
||||||
|
val iosTarget = CommonizerTarget(IOS_ARM64, IOS_X64, IOS_SIMULATOR_ARM64)
|
||||||
|
val watchosTarget = CommonizerTarget(WATCHOS_ARM64, WATCHOS_X64, WATCHOS_SIMULATOR_ARM64)
|
||||||
|
val macosTarget = CommonizerTarget(MACOS_X64, MACOS_ARM64)
|
||||||
|
val appleTarget = SharedCommonizerTarget(iosTarget.konanTargets + watchosTarget.konanTargets + macosTarget.konanTargets)
|
||||||
|
|
||||||
|
CliCommonizer(this::class.java.classLoader).commonizeNativeDistribution(
|
||||||
|
konanHome = konanHome,
|
||||||
|
outputTargets = setOf(iosTarget, watchosTarget, macosTarget, appleTarget),
|
||||||
|
outputDirectory = temporaryOutputDirectory.root,
|
||||||
|
logLevel = CommonizerLogLevel.Info
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
resolveCommonizedDirectory(temporaryOutputDirectory.root, iosTarget).isDirectory,
|
||||||
|
"Expected directory for $iosTarget"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
resolveCommonizedDirectory(temporaryOutputDirectory.root, watchosTarget).isDirectory,
|
||||||
|
"Expected directory for $watchosTarget"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
resolveCommonizedDirectory(temporaryOutputDirectory.root, macosTarget).isDirectory,
|
||||||
|
"Expected directory for $macosTarget"
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
resolveCommonizedDirectory(temporaryOutputDirectory.root, appleTarget).isDirectory,
|
||||||
|
"Expected directory for $appleTarget"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `commonize - no outputTargets specified`() {
|
fun `commonize - no outputTargets specified`() {
|
||||||
CliCommonizer(this::class.java.classLoader).commonizeNativeDistribution(
|
CliCommonizer(this::class.java.classLoader).commonizeNativeDistribution(
|
||||||
|
|||||||
@@ -17,9 +17,11 @@ internal tailrec fun computeSuitableUnderlyingType(
|
|||||||
): CirClassOrTypeAliasType? {
|
): CirClassOrTypeAliasType? {
|
||||||
return when (underlyingType) {
|
return when (underlyingType) {
|
||||||
is CirClassType -> underlyingType.withCommonizedArguments(classifiers)
|
is CirClassType -> underlyingType.withCommonizedArguments(classifiers)
|
||||||
is CirTypeAliasType -> if (classifiers.commonDependencies.hasClassifier(underlyingType.classifierId))
|
is CirTypeAliasType ->
|
||||||
underlyingType.withCommonizedArguments(classifiers) else
|
if (classifiers.commonDependencies.hasClassifier(underlyingType.classifierId) ||
|
||||||
computeSuitableUnderlyingType(classifiers, underlyingType.underlyingType)
|
classifiers.commonizedNodes.typeAliasNode(underlyingType.classifierId)?.commonDeclaration?.invoke() != null
|
||||||
|
) underlyingType.withCommonizedArguments(classifiers)
|
||||||
|
else computeSuitableUnderlyingType(classifiers, underlyingType.underlyingType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+11
-11
@@ -1,26 +1,26 @@
|
|||||||
expect class A()
|
expect class A()
|
||||||
// Lifted up type aliases:
|
// Lifted up type aliases:
|
||||||
typealias B = A // class at the RHS
|
typealias B = A // class at the RHS
|
||||||
typealias C = A // TA at the RHS, expanded to the same class
|
typealias C = B // TA lifted up as is
|
||||||
typealias C2 = A // 2x TA at the RHS, expanded to the same class
|
typealias C2 = C // TA lifted up as is
|
||||||
typealias C3 = A // 3x TA at the RHS, expanded to the same class
|
typealias C3 = C2 // TA lifted up as is
|
||||||
|
|
||||||
typealias D = A // class/TA expanded to the same class at the RHS
|
typealias D = A // class/TA expanded to the same class at the RHS
|
||||||
typealias E = A // different TAs expanded to the same class at the RHS
|
typealias E = B // different TAs use common type from TA-chain
|
||||||
|
|
||||||
typealias F = List<String> // parameterized type at the RHS
|
typealias F = List<String> // parameterized type at the RHS
|
||||||
typealias H<T> = List<T> // TA with own parameters
|
typealias H<T> = List<T> // TA with own parameters
|
||||||
|
|
||||||
typealias I2<T> = List<T>
|
typealias I2<T> = List<T>
|
||||||
typealias I3<R> = List<R>
|
typealias I3<R> = I2<R>
|
||||||
typealias I4 = List<String>
|
typealias I4 = I2<String>
|
||||||
|
|
||||||
typealias I5<V, K> = Map<K, V>
|
typealias I5<V, K> = Map<K, V>
|
||||||
typealias I6<T, R> = Map<R, T>
|
typealias I6<T, R> = I5<T, R>
|
||||||
|
|
||||||
typealias I7<K, V> = Map<K, V>
|
typealias I7<K, V> = Map<K, V>
|
||||||
typealias I8<T, R> = Map<R, T>
|
typealias I8<T, R> = I7<R, T>
|
||||||
typealias I9<Q, W> = Map<W, Q>
|
typealias I9<Q, W> = I8<Q, W>
|
||||||
|
|
||||||
typealias J<T> = Function<T> // function type at the RHS
|
typealias J<T> = Function<T> // function type at the RHS
|
||||||
typealias M = () -> Unit // same return type
|
typealias M = () -> Unit // same return type
|
||||||
@@ -38,14 +38,14 @@ expect class T
|
|||||||
typealias U = A // same nullability of the RHS class
|
typealias U = A // same nullability of the RHS class
|
||||||
|
|
||||||
expect class V // different nullability of the RHS class
|
expect class V // different nullability of the RHS class
|
||||||
typealias W = A // same nullability of the RHS TA
|
typealias W = U // same nullability of the RHS TA
|
||||||
expect class X // different nullability of the RHS TA
|
expect class X // different nullability of the RHS TA
|
||||||
expect class Y // TA at the RHS with the different nullability of own RHS
|
expect class Y // TA at the RHS with the different nullability of own RHS
|
||||||
|
|
||||||
// Supertypes:
|
// Supertypes:
|
||||||
expect class FILE expect constructor(): kotlinx.cinterop.CStructVar
|
expect class FILE expect constructor(): kotlinx.cinterop.CStructVar
|
||||||
|
|
||||||
typealias uuid_t = kotlinx.cinterop.CArrayPointer<kotlinx.cinterop.UByteVar>
|
typealias uuid_t = __darwin_uuid_t
|
||||||
typealias __darwin_uuid_t = kotlinx.cinterop.CArrayPointer<kotlinx.cinterop.UByteVar>
|
typealias __darwin_uuid_t = kotlinx.cinterop.CArrayPointer<kotlinx.cinterop.UByteVar>
|
||||||
|
|
||||||
expect val uuid: uuid_t
|
expect val uuid: uuid_t
|
||||||
|
|||||||
Vendored
+4
-4
@@ -2,12 +2,12 @@ class A
|
|||||||
|
|
||||||
// Lifted up type aliases:
|
// Lifted up type aliases:
|
||||||
typealias B = A // class at the RHS
|
typealias B = A // class at the RHS
|
||||||
typealias C = B // TA at the RHS, expanded to the same class
|
typealias C = B // TA lifted up as is
|
||||||
typealias C2 = C // 2x TA at the RHS, expanded to the same class
|
typealias C2 = C // TA lifted up as is
|
||||||
typealias C3 = C2 // 3x TA at the RHS, expanded to the same class
|
typealias C3 = C2 // TA lifted up as is
|
||||||
|
|
||||||
typealias D = B // class/TA expanded to the same class at the RHS
|
typealias D = B // class/TA expanded to the same class at the RHS
|
||||||
typealias E = C // different TAs expanded to the same class at the RHS
|
typealias E = C // different TAs use common type from TA-chain
|
||||||
|
|
||||||
typealias F = List<String> // parameterized type at the RHS
|
typealias F = List<String> // parameterized type at the RHS
|
||||||
typealias G = List<Int> // different parameterized types at the RHS
|
typealias G = List<Int> // different parameterized types at the RHS
|
||||||
|
|||||||
Vendored
+4
-4
@@ -2,12 +2,12 @@ class A
|
|||||||
|
|
||||||
// Lifted up type aliases:
|
// Lifted up type aliases:
|
||||||
typealias B = A // class at the RHS
|
typealias B = A // class at the RHS
|
||||||
typealias C = B // TA at the RHS, expanded to the same class
|
typealias C = B // TA lifted up as is
|
||||||
typealias C2 = C // 2x TA at the RHS, expanded to the same class
|
typealias C2 = C // TA lifted up as is
|
||||||
typealias C3 = C2 // 3x TA at the RHS, expanded to the same class
|
typealias C3 = C2 // TA lifted up as is
|
||||||
|
|
||||||
typealias D = A // class/TA expanded to the same class at the RHS
|
typealias D = A // class/TA expanded to the same class at the RHS
|
||||||
typealias E = B // different TAs expanded to the same class at the RHS
|
typealias E = B // different TAs use common type from TA-chain
|
||||||
|
|
||||||
typealias F = List<String> // parameterized type at the RHS
|
typealias F = List<String> // parameterized type at the RHS
|
||||||
typealias G = List<String> // different parameterized types at the RHS
|
typealias G = List<String> // different parameterized types at the RHS
|
||||||
|
|||||||
+63
@@ -548,6 +548,69 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test typealias to numbers`() {
|
||||||
|
val result = commonize {
|
||||||
|
outputTarget("(a, b)", "(c, d)", "(a, b, c, d)")
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"a", """
|
||||||
|
typealias Proxy = Long
|
||||||
|
typealias X = Proxy
|
||||||
|
val x: X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"b", """
|
||||||
|
typealias Proxy = Long
|
||||||
|
typealias X = Proxy
|
||||||
|
val x: X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"c", """
|
||||||
|
typealias Proxy = Int
|
||||||
|
typealias X = Proxy
|
||||||
|
val x: X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
simpleSingleSourceTarget(
|
||||||
|
"d", """
|
||||||
|
typealias Proxy = Short
|
||||||
|
typealias X = Proxy
|
||||||
|
val x: X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
result.assertCommonized(
|
||||||
|
"(a, b)", """
|
||||||
|
typealias Proxy = Long
|
||||||
|
typealias X = Proxy
|
||||||
|
expect val x: X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
result.assertCommonized(
|
||||||
|
"(c, d)", """
|
||||||
|
expect class Proxy
|
||||||
|
typealias X = Proxy
|
||||||
|
expect val x: X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
result.assertCommonized(
|
||||||
|
"(a, b, c, d)", """
|
||||||
|
expect class Proxy
|
||||||
|
typealias X = Proxy
|
||||||
|
expect val x: X
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun `todo - test boxed function using TA and expanded type`() {
|
fun `todo - test boxed function using TA and expanded type`() {
|
||||||
val result = commonize {
|
val result = commonize {
|
||||||
outputTarget("(a, b)")
|
outputTarget("(a, b)")
|
||||||
|
|||||||
Reference in New Issue
Block a user