[Commonizer] Relax conditions for TA lifting-up

Allow lifting up matching TAs with non-empty list of type parameters
and non-empty list of type arguments in the expanded type.
This commit is contained in:
Dmitriy Dolovov
2020-10-20 21:33:27 +03:00
parent cb2e94df16
commit 2764550bbe
4 changed files with 36 additions and 3 deletions
@@ -45,6 +45,7 @@ class TypeAliasCommonizer(cache: CirClassifiersCache) : AbstractStandardCommoniz
private class TypeAliasShortCircuitingCommonizer(cache: CirClassifiersCache) : AbstractStandardCommonizer<CirTypeAlias, CirTypeAlias>() {
private lateinit var name: Name
private val typeParameters = TypeParameterListCommonizer(cache)
private val expandedType = TypeCommonizer(cache)
private val visibility = VisibilityCommonizer.lowering()
@@ -54,7 +55,7 @@ private class TypeAliasShortCircuitingCommonizer(cache: CirClassifiersCache) : A
return CirTypeAliasFactory.create(
annotations = emptyList(),
name = name,
typeParameters = emptyList(),
typeParameters = typeParameters.result,
visibility = visibility.result,
underlyingType = expandedType, // pass expanded type as underlying type
expandedType = expandedType
@@ -69,8 +70,7 @@ private class TypeAliasShortCircuitingCommonizer(cache: CirClassifiersCache) : A
}
override fun doCommonizeWith(next: CirTypeAlias) =
next.typeParameters.isEmpty() // short-circuiting of TAs with type parameters is too complex case, consider implementing it later
&& next.expandedType.arguments.isEmpty() // short-circuiting of TAs with type arguments in expanded type is too complex case
typeParameters.commonizeWith(next.typeParameters)
&& expandedType.commonizeWith(next.expandedType)
&& visibility.commonizeWith(next)
}
@@ -12,6 +12,17 @@ typealias E = A // different TAs expanded to the same class at the RHS
typealias F = List<String> // parameterized type at the RHS
typealias H<T> = List<T> // TA with own parameters
typealias I2<T> = List<T>
typealias I3<R> = List<R>
typealias I4 = List<String>
typealias I5<V, K> = Map<K, V>
typealias I6<T, R> = Map<R, T>
typealias I7<K, V> = Map<K, V>
typealias I8<T, R> = Map<R, T>
typealias I9<Q, W> = Map<W, Q>
typealias J<T> = Function<T> // function type at the RHS
typealias M = () -> Unit // same return type
typealias O = (String) -> Int // same argument type
@@ -15,6 +15,17 @@ typealias G = List<Int> // different parameterized types at the RHS
typealias H<T> = List<T> // TA with own parameters
typealias I<T> = List<T> // TAs with own parameters with different names
typealias I2<T> = List<T>
typealias I3<R> = I2<R>
typealias I4 = I2<String>
typealias I5<V, K> = Map<K, V>
typealias I6<T, R> = I5<T, R>
typealias I7<K, V> = Map<K, V>
typealias I8<T, R> = I7<R, T>
typealias I9<Q, W> = I8<Q, W>
typealias J<T> = Function<T> // function type at the RHS
typealias K<T> = Function<T> // function types with different type parameter names
typealias L<T> = () -> T // different kinds of function types
@@ -15,6 +15,17 @@ typealias G = List<String> // different parameterized types at the RHS
typealias H<T> = List<T> // TA with own parameters
typealias I<R> = List<R> // TAs with own parameters with different names
typealias I2<T> = List<T>
typealias I3<R> = I2<R>
typealias I4 = I2<String>
typealias I5<V, K> = Map<K, V>
typealias I6<T, R> = I5<T, R>
typealias I7<K, V> = Map<K, V>
typealias I8<T, R> = I7<R, T>
typealias I9<Q, W> = I8<Q, W>
typealias J<T> = Function<T> // function type at the RHS
typealias K<R> = Function<R> // function types with different type parameter names
typealias L<T> = Function<T> // different kinds of function types