Rethink constraints incorporation

Namely, remove incorporation “otherInsideMyConstraint” to eliminate
constraint system redundancy and produce a potentially very large number
 of constructs.
Instead, introduce not so “spreadable” incorporation during variable
fixation (equality constraint with result type into other constraints).
^KT-41644 Fixed
^KT-42195 Fixed
^KT-42920 Fixed
^KT-42791 Fixed
^KT-41741 Fixed
This commit is contained in:
Victor Petukhov
2020-11-19 12:39:57 +03:00
parent 616e40f879
commit 0857b9c9e7
24 changed files with 299 additions and 136 deletions
@@ -0,0 +1,44 @@
// FIR_IDENTICAL
//!DIAGNOSTICS: -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS
sealed class DataType<T> {
sealed class NotNull<T> : DataType<T>() {
abstract class Partial<T> : NotNull<T>()
}
}
class Tuple8<A, DA : DataType<A>, B, DB : DataType<B>, C, DC : DataType<C>, D, DD : DataType<D>, E, DE : DataType<E>, F, DF : DataType<F>, G, DG : DataType<G>, H, DH : DataType<H>>(
firstName: String, firstType: DA,
secondName: String, secondType: DB,
thirdName: String, thirdType: DC,
fourthName: String, fourthType: DD,
fifthName: String, fifthType: DE,
sixthName: String, sixthType: DF,
seventhName: String, seventhType: DG,
eighthName: String, eighthType: DH
) : Schema<Tuple8<A, DA, B, DB, C, DC, D, DD, E, DE, F, DF, G, DG, H, DH>>()
class EitherType<SCH : Schema<SCH>>(
schema: SCH
)
open class Schema<T>
fun <A, DA : DataType<A>, B, DB : DataType<B>, C, DC : DataType<C>, D, DD : DataType<D>, E, DE : DataType<E>, F, DF : DataType<F>, G, DG : DataType<G>, H, DH : DataType<H>> either8(
firstName: String, firstType: DA,
secondName: String, secondType: DB,
thirdName: String, thirdType: DC,
fourthName: String, fourthType: DD,
fifthName: String, fifthType: DE,
sixthName: String, sixthType: DF,
seventhName: String, seventhType: DG,
eighthName: String, eighthType: DH
): DataType.NotNull.Partial<Either8<A, B, C, D, E, F, G, H>> =
EitherType(
Tuple8(
firstName, firstType, secondName, secondType, thirdName, thirdType, fourthName, fourthType,
fifthName, fifthType, sixthName, sixthType, seventhName, seventhType, eighthName, eighthType
)
) as DataType.NotNull.Partial<Either8<A, B, C, D, E, F, G, H>>
class Either8<T, U, V, W, X, Y, Z, T1>
@@ -0,0 +1,52 @@
package
public fun </*0*/ A, /*1*/ DA : DataType<A>, /*2*/ B, /*3*/ DB : DataType<B>, /*4*/ C, /*5*/ DC : DataType<C>, /*6*/ D, /*7*/ DD : DataType<D>, /*8*/ E, /*9*/ DE : DataType<E>, /*10*/ F, /*11*/ DF : DataType<F>, /*12*/ G, /*13*/ DG : DataType<G>, /*14*/ H, /*15*/ DH : DataType<H>> either8(/*0*/ firstName: kotlin.String, /*1*/ firstType: DA, /*2*/ secondName: kotlin.String, /*3*/ secondType: DB, /*4*/ thirdName: kotlin.String, /*5*/ thirdType: DC, /*6*/ fourthName: kotlin.String, /*7*/ fourthType: DD, /*8*/ fifthName: kotlin.String, /*9*/ fifthType: DE, /*10*/ sixthName: kotlin.String, /*11*/ sixthType: DF, /*12*/ seventhName: kotlin.String, /*13*/ seventhType: DG, /*14*/ eighthName: kotlin.String, /*15*/ eighthType: DH): DataType.NotNull.Partial<Either8<A, B, C, D, E, F, G, H>>
public sealed class DataType</*0*/ T> {
private constructor DataType</*0*/ T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public sealed class NotNull</*0*/ T> : DataType<T> {
private constructor NotNull</*0*/ T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public abstract class Partial</*0*/ T> : DataType.NotNull<T> {
public constructor Partial</*0*/ T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
}
public final class Either8</*0*/ T, /*1*/ U, /*2*/ V, /*3*/ W, /*4*/ X, /*5*/ Y, /*6*/ Z, /*7*/ T1> {
public constructor Either8</*0*/ T, /*1*/ U, /*2*/ V, /*3*/ W, /*4*/ X, /*5*/ Y, /*6*/ Z, /*7*/ T1>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class EitherType</*0*/ SCH : Schema<SCH>> {
public constructor EitherType</*0*/ SCH : Schema<SCH>>(/*0*/ schema: SCH)
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public open class Schema</*0*/ T> {
public constructor Schema</*0*/ T>()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Tuple8</*0*/ A, /*1*/ DA : DataType<A>, /*2*/ B, /*3*/ DB : DataType<B>, /*4*/ C, /*5*/ DC : DataType<C>, /*6*/ D, /*7*/ DD : DataType<D>, /*8*/ E, /*9*/ DE : DataType<E>, /*10*/ F, /*11*/ DF : DataType<F>, /*12*/ G, /*13*/ DG : DataType<G>, /*14*/ H, /*15*/ DH : DataType<H>> : Schema<Tuple8<A, DA, B, DB, C, DC, D, DD, E, DE, F, DF, G, DG, H, DH>> {
public constructor Tuple8</*0*/ A, /*1*/ DA : DataType<A>, /*2*/ B, /*3*/ DB : DataType<B>, /*4*/ C, /*5*/ DC : DataType<C>, /*6*/ D, /*7*/ DD : DataType<D>, /*8*/ E, /*9*/ DE : DataType<E>, /*10*/ F, /*11*/ DF : DataType<F>, /*12*/ G, /*13*/ DG : DataType<G>, /*14*/ H, /*15*/ DH : DataType<H>>(/*0*/ firstName: kotlin.String, /*1*/ firstType: DA, /*2*/ secondName: kotlin.String, /*3*/ secondType: DB, /*4*/ thirdName: kotlin.String, /*5*/ thirdType: DC, /*6*/ fourthName: kotlin.String, /*7*/ fourthType: DD, /*8*/ fifthName: kotlin.String, /*9*/ fifthType: DE, /*10*/ sixthName: kotlin.String, /*11*/ sixthType: DF, /*12*/ seventhName: kotlin.String, /*13*/ seventhType: DG, /*14*/ eighthName: kotlin.String, /*15*/ eighthType: DH)
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,37 @@
// FIR_IDENTICAL
// FILE: Simple.java
// FULL_JDK
// WITH_RUNTIME
// !DIAGNOSTICS: -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS -UNUSED_VARIABLE
import java.util.*;
import java.util.function.Supplier;
public class Simple<K, V, C extends E, E extends Collection<V>> {
public Simple(Map<K, C> backingMap, Supplier<? extends C> innerCollectionCreator) {
// TODO
}
public final void add(K key, V value) {
//TODO
}
public static class ListSimple<K, V> extends Simple<K, V, List<V>, List<V>> {
public ListSimple(Map<K, List<V>> backingMap, Supplier<? extends List<V>> innerCollectionCreator) {
super(backingMap, innerCollectionCreator);
}
}
}
// FILE: main.kt
import java.util.*
fun <K, V, C : E, E : Collection<V>, B: Simple<K, V, C, E>> Iterable<V>.groupByTo(destination: B, keySelector: (V) -> K) = null as B
enum class Format { Foo, Bar }
class Instance(val format: Format)
fun main(x: List<Instance>) {
val doesntWork = x.groupByTo(
Simple.ListSimple(EnumMap<Format, List<Instance>>(Format::class.java), ::LinkedList)
) { it.format } // Internal Error occurred while analyzing this expression
}
@@ -0,0 +1,49 @@
package
public fun main(/*0*/ x: kotlin.collections.List<Instance>): kotlin.Unit
public fun </*0*/ K, /*1*/ V, /*2*/ C : E, /*3*/ E : kotlin.collections.Collection<V>, /*4*/ B : Simple<K, V, C, E>> kotlin.collections.Iterable<V>.groupByTo(/*0*/ destination: B, /*1*/ keySelector: (V) -> K): B
public final enum class Format : kotlin.Enum<Format> {
enum entry Foo
enum entry Bar
private constructor Format()
public final override /*1*/ /*fake_override*/ val name: kotlin.String
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: Format): kotlin.Int
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit
public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class<Format!>!
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): Format
public final /*synthesized*/ fun values(): kotlin.Array<Format>
}
public final class Instance {
public constructor Instance(/*0*/ format: Format)
public final val format: Format
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public open class Simple</*0*/ K : kotlin.Any!, /*1*/ V : kotlin.Any!, /*2*/ C : E!, /*3*/ E : kotlin.collections.(Mutable)Collection<V!>!> {
public constructor Simple</*0*/ K : kotlin.Any!, /*1*/ V : kotlin.Any!, /*2*/ C : E!, /*3*/ E : kotlin.collections.(Mutable)Collection<V!>!>(/*0*/ backingMap: kotlin.collections.(Mutable)Map<K!, C!>!, /*1*/ innerCollectionCreator: java.util.function.Supplier<out C!>!)
public final fun add(/*0*/ key: K!, /*1*/ value: V!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public open class ListSimple</*0*/ K : kotlin.Any!, /*1*/ V : kotlin.Any!> : Simple<K!, V!, kotlin.collections.(Mutable)List<V!>!, kotlin.collections.(Mutable)List<V!>!> {
public constructor ListSimple</*0*/ K : kotlin.Any!, /*1*/ V : kotlin.Any!>(/*0*/ backingMap: kotlin.collections.(Mutable)Map<K!, kotlin.collections.(Mutable)List<V!>!>!, /*1*/ innerCollectionCreator: java.util.function.Supplier<out kotlin.collections.(Mutable)List<V!>!>!)
public final override /*1*/ /*fake_override*/ fun add(/*0*/ key: K!, /*1*/ value: V!): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
@@ -0,0 +1,40 @@
// FIR_IDENTICAL
sealed class Tree<TIndex, out TCommon, out TInner, out TLeaf> {
abstract val value: TCommon
abstract val children: Map<TIndex, Tree<TIndex, TCommon, TInner, TLeaf>>
data class Inner<TIndex, TCommon, TInner, TLeaf>(
override val value: TCommon,
val innerValue: TInner,
override val children: Map<TIndex, Tree<TIndex, TCommon, TInner, TLeaf>>
) : Tree<TIndex, TCommon, TInner, TLeaf>()
data class Leaf<TIndex, TCommon, TLeaf>(
override val value: TCommon,
val leafValue: TLeaf
) : Tree<TIndex, TCommon, Nothing, TLeaf>() {
override val children: Map<TIndex, Tree<TIndex, TCommon, Nothing, TLeaf>> get() = emptyMap()
}
}
val tree = Tree.Inner(
"root",
Unit,
mapOf(
1 to Tree.Leaf("1", 1),
2 to Tree.Inner(
"2",
Unit,
mapOf(
1 to Tree.Leaf("21", 2),
2 to Tree.Inner(
"22",
Unit,
mapOf(1 to Tree.Leaf("221", 3))
),
3 to Tree.Leaf("23", 4)
)
)
)
)
@@ -0,0 +1,39 @@
package
public val tree: Tree.Inner<kotlin.Int, kotlin.String, kotlin.Unit, kotlin.Int>
public sealed class Tree</*0*/ TIndex, /*1*/ out TCommon, /*2*/ out TInner, /*3*/ out TLeaf> {
private constructor Tree</*0*/ TIndex, /*1*/ out TCommon, /*2*/ out TInner, /*3*/ out TLeaf>()
public abstract val children: kotlin.collections.Map<TIndex, Tree<TIndex, TCommon, TInner, TLeaf>>
public abstract val value: TCommon
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final data class Inner</*0*/ TIndex, /*1*/ TCommon, /*2*/ TInner, /*3*/ TLeaf> : Tree<TIndex, TCommon, TInner, TLeaf> {
public constructor Inner</*0*/ TIndex, /*1*/ TCommon, /*2*/ TInner, /*3*/ TLeaf>(/*0*/ value: TCommon, /*1*/ innerValue: TInner, /*2*/ children: kotlin.collections.Map<TIndex, Tree<TIndex, TCommon, TInner, TLeaf>>)
public open override /*1*/ val children: kotlin.collections.Map<TIndex, Tree<TIndex, TCommon, TInner, TLeaf>>
public final val innerValue: TInner
public open override /*1*/ val value: TCommon
public final operator /*synthesized*/ fun component1(): TCommon
public final operator /*synthesized*/ fun component2(): TInner
public final operator /*synthesized*/ fun component3(): kotlin.collections.Map<TIndex, Tree<TIndex, TCommon, TInner, TLeaf>>
public final /*synthesized*/ fun copy(/*0*/ value: TCommon = ..., /*1*/ innerValue: TInner = ..., /*2*/ children: kotlin.collections.Map<TIndex, Tree<TIndex, TCommon, TInner, TLeaf>> = ...): Tree.Inner<TIndex, TCommon, TInner, TLeaf>
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
public final data class Leaf</*0*/ TIndex, /*1*/ TCommon, /*2*/ TLeaf> : Tree<TIndex, TCommon, kotlin.Nothing, TLeaf> {
public constructor Leaf</*0*/ TIndex, /*1*/ TCommon, /*2*/ TLeaf>(/*0*/ value: TCommon, /*1*/ leafValue: TLeaf)
public open override /*1*/ val children: kotlin.collections.Map<TIndex, Tree<TIndex, TCommon, kotlin.Nothing, TLeaf>>
public final val leafValue: TLeaf
public open override /*1*/ val value: TCommon
public final operator /*synthesized*/ fun component1(): TCommon
public final operator /*synthesized*/ fun component2(): TLeaf
public final /*synthesized*/ fun copy(/*0*/ value: TCommon = ..., /*1*/ leafValue: TLeaf = ...): Tree.Leaf<TIndex, TCommon, TLeaf>
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
}
}