[FIR] Set isStubTypeEqualsToAnything = true for inference as in FE 1.0
#KT-43616 Fixed
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
interface CommonBackendContext
|
||||
|
||||
interface PhaserState<Data> {
|
||||
var depth: Int
|
||||
}
|
||||
|
||||
interface PhaseConfig {
|
||||
val needProfiling: Boolean
|
||||
}
|
||||
|
||||
inline fun <R, D> PhaserState<D>.downlevel(nlevels: Int, block: () -> R): R {
|
||||
depth += nlevels
|
||||
val result = block()
|
||||
depth -= nlevels
|
||||
return result
|
||||
}
|
||||
|
||||
interface CompilerPhase<in Context : CommonBackendContext, Input, Output> {
|
||||
fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState<Input>, context: Context, input: Input): Output
|
||||
}
|
||||
|
||||
class NamedCompilerPhase<in Context : CommonBackendContext, Data>(
|
||||
private val lower: CompilerPhase<Context, Data, Data>
|
||||
) : CompilerPhase<Context, Data, Data> {
|
||||
override fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState<Data>, context: Context, input: Data): Data {
|
||||
// Expected: output: Data, Actual: output: Data?
|
||||
val output = if (phaseConfig.needProfiling) {
|
||||
runAndProfile(phaseConfig, phaserState, context, input)
|
||||
} else {
|
||||
phaserState.downlevel(1) {
|
||||
lower.invoke(phaseConfig, phaserState, context, input)
|
||||
}
|
||||
}
|
||||
runAfter(phaseConfig, phaserState, context, output)
|
||||
}
|
||||
|
||||
private fun runAfter(phaseConfig: PhaseConfig, phaserState: PhaserState<Data>, context: Context, output: Data) {
|
||||
|
||||
}
|
||||
|
||||
private fun runAndProfile(phaseConfig: PhaseConfig, phaserState: PhaserState<Data>, context: Context, source: Data): Data {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
FILE: compilerPhase.kt
|
||||
public abstract interface CommonBackendContext : R|kotlin/Any| {
|
||||
}
|
||||
public abstract interface PhaserState<Data> : R|kotlin/Any| {
|
||||
public abstract var depth: R|kotlin/Int|
|
||||
public get(): R|kotlin/Int|
|
||||
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
public abstract interface PhaseConfig : R|kotlin/Any| {
|
||||
public abstract val needProfiling: R|kotlin/Boolean|
|
||||
public get(): R|kotlin/Boolean|
|
||||
|
||||
}
|
||||
public final inline fun <R, D> R|PhaserState<D>|.downlevel(nlevels: R|kotlin/Int|, block: R|() -> R|): R|R| {
|
||||
this@R|/downlevel|.R|/PhaserState.depth| = this@R|/downlevel|.R|/PhaserState.depth|.R|kotlin/Int.plus|(R|<local>/nlevels|)
|
||||
lval result: R|R| = R|<local>/block|.R|SubstitutionOverride<kotlin/Function0.invoke: R|R|>|()
|
||||
this@R|/downlevel|.R|/PhaserState.depth| = this@R|/downlevel|.R|/PhaserState.depth|.R|kotlin/Int.minus|(R|<local>/nlevels|)
|
||||
^downlevel R|<local>/result|
|
||||
}
|
||||
public abstract interface CompilerPhase<in Context : R|CommonBackendContext|, Input, Output> : R|kotlin/Any| {
|
||||
public abstract fun invoke(phaseConfig: R|PhaseConfig|, phaserState: R|PhaserState<Input>|, context: R|Context|, input: R|Input|): R|Output|
|
||||
|
||||
}
|
||||
public final class NamedCompilerPhase<in Context : R|CommonBackendContext|, Data> : R|CompilerPhase<Context, Data, Data>| {
|
||||
public constructor<in Context : R|CommonBackendContext|, Data>(lower: R|CompilerPhase<Context, Data, Data>|): R|NamedCompilerPhase<Context, Data>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
private final val lower: R|CompilerPhase<Context, Data, Data>| = R|<local>/lower|
|
||||
private get(): R|CompilerPhase<Context, Data, Data>|
|
||||
|
||||
public final override fun invoke(phaseConfig: R|PhaseConfig|, phaserState: R|PhaserState<Data>|, context: R|Context|, input: R|Data|): R|Data| {
|
||||
lval output: R|Data| = when () {
|
||||
R|<local>/phaseConfig|.R|/PhaseConfig.needProfiling| -> {
|
||||
this@R|/NamedCompilerPhase|.R|/NamedCompilerPhase.runAndProfile|(R|<local>/phaseConfig|, R|<local>/phaserState|, R|<local>/context|, R|<local>/input|)
|
||||
}
|
||||
else -> {
|
||||
R|<local>/phaserState|.R|/downlevel|<R|Data|, R|Data|>(Int(1), <L> = downlevel@fun <anonymous>(): R|Data| <kind=UNKNOWN> {
|
||||
^ this@R|/NamedCompilerPhase|.R|/NamedCompilerPhase.lower|.R|SubstitutionOverride</CompilerPhase.invoke: R|Data|>|(R|<local>/phaseConfig|, R|<local>/phaserState|, R|<local>/context|, R|<local>/input|)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
this@R|/NamedCompilerPhase|.R|/NamedCompilerPhase.runAfter|(R|<local>/phaseConfig|, R|<local>/phaserState|, R|<local>/context|, R|<local>/output|)
|
||||
}
|
||||
|
||||
private final fun runAfter(phaseConfig: R|PhaseConfig|, phaserState: R|PhaserState<Data>|, context: R|Context|, output: R|Data|): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
private final fun runAndProfile(phaseConfig: R|PhaseConfig|, phaserState: R|PhaserState<Data>|, context: R|Context|, source: R|Data|): R|Data| {
|
||||
}
|
||||
|
||||
}
|
||||
Generated
+5
@@ -2024,6 +2024,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compilerPhase.kt")
|
||||
public void testCompilerPhase() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/compilerPhase.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("complexLambdaWithTypeVariableAsExpectedType.kt")
|
||||
public void testComplexLambdaWithTypeVariableAsExpectedType() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/complexLambdaWithTypeVariableAsExpectedType.kt");
|
||||
|
||||
+5
@@ -2024,6 +2024,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compilerPhase.kt")
|
||||
public void testCompilerPhase() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/compilerPhase.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("complexLambdaWithTypeVariableAsExpectedType.kt")
|
||||
public void testComplexLambdaWithTypeVariableAsExpectedType() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/complexLambdaWithTypeVariableAsExpectedType.kt");
|
||||
|
||||
+5
@@ -2024,6 +2024,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compilerPhase.kt")
|
||||
public void testCompilerPhase() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/compilerPhase.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("complexLambdaWithTypeVariableAsExpectedType.kt")
|
||||
public void testComplexLambdaWithTypeVariableAsExpectedType() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/complexLambdaWithTypeVariableAsExpectedType.kt");
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||
|
||||
@NoMutableState
|
||||
class InferenceComponents(val session: FirSession) : FirSessionComponent {
|
||||
val ctx: ConeTypeCheckerContext = ConeTypeCheckerContext(isErrorTypeEqualsToAnything = false, isStubTypeEqualsToAnything = false, session)
|
||||
val ctx: ConeTypeCheckerContext = ConeTypeCheckerContext(isErrorTypeEqualsToAnything = false, isStubTypeEqualsToAnything = true, session)
|
||||
|
||||
val approximator: AbstractTypeApproximator = object : AbstractTypeApproximator(ctx) {}
|
||||
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx)
|
||||
|
||||
@@ -584,7 +584,7 @@ class ConeTypeCheckerContext(
|
||||
errorTypesEqualToAnything: Boolean,
|
||||
stubTypesEqualToAnything: Boolean
|
||||
): AbstractTypeCheckerContext =
|
||||
if (this.isErrorTypeEqualsToAnything == errorTypesEqualToAnything)
|
||||
if (this.isErrorTypeEqualsToAnything == errorTypesEqualToAnything && this.isStubTypeEqualsToAnything == stubTypesEqualToAnything)
|
||||
this
|
||||
else
|
||||
ConeTypeCheckerContext(errorTypesEqualToAnything, stubTypesEqualToAnything, session)
|
||||
|
||||
Vendored
+2
-2
@@ -27,9 +27,9 @@ fun <T> listOf(): List<T> = TODO()
|
||||
fun <T> setOf(): Set<T> = TODO()
|
||||
|
||||
fun <T> test2(x: T) {
|
||||
bar(x, x, ::foo).checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Pair<T, T>>() }
|
||||
bar(x, x, ::foo).checkType { _<Pair<T, T>>() }
|
||||
bar(x, 1, ::foo).checkType { _<Pair<T, Int>>() }
|
||||
bar(1, x, ::foo).checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Pair<Int, T>>() }
|
||||
bar(1, x, ::foo).checkType { _<Pair<Int, T>>() }
|
||||
|
||||
bar(listOf<T>(), setOf<T>(), ::foo).checkType { _<Pair<List<T>, Set<T>>> () }
|
||||
bar(listOf<T>(), 1, ::foo).checkType { _<Pair<List<T>, Int>>() }
|
||||
|
||||
@@ -70,7 +70,7 @@ fun <T : Any?> test(value: T, value2: T) {
|
||||
}
|
||||
}
|
||||
val x7: Any = { // BLOCK
|
||||
val <elvis>: T? = { // BLOCK
|
||||
val <elvis>: T = { // BLOCK
|
||||
val <elvis>: T? = magic<T?>()
|
||||
when {
|
||||
EQEQ(arg0 = <elvis>, arg1 = null) -> value
|
||||
@@ -79,7 +79,7 @@ fun <T : Any?> test(value: T, value2: T) {
|
||||
}
|
||||
when {
|
||||
EQEQ(arg0 = <elvis>, arg1 = null) -> 42
|
||||
else -> <elvis> /*as T */
|
||||
else -> <elvis>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-6
@@ -137,12 +137,12 @@ FILE fqName:<root> fileName:/kt30796.kt
|
||||
then: GET_VAR 'val tmp_8: T of <root>.test [val] declared in <root>.test' type=T of <root>.test origin=null
|
||||
VAR name:x7 type:kotlin.Any [val]
|
||||
BLOCK type=kotlin.Any origin=ELVIS
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_10 type:T of <root>.test? [val]
|
||||
BLOCK type=T of <root>.test? origin=ELVIS
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_10 type:T of <root>.test [val]
|
||||
BLOCK type=T of <root>.test origin=ELVIS
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_11 type:T of <root>.test? [val]
|
||||
CALL 'public final fun magic <T> (): T of <root>.magic declared in <root>' type=T of <root>.test? origin=null
|
||||
<T>: T of <root>.test?
|
||||
WHEN type=T of <root>.test? origin=ELVIS
|
||||
WHEN type=T of <root>.test origin=ELVIS
|
||||
BRANCH
|
||||
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
arg0: GET_VAR 'val tmp_11: T of <root>.test? [val] declared in <root>.test' type=T of <root>.test? origin=null
|
||||
@@ -155,10 +155,9 @@ FILE fqName:<root> fileName:/kt30796.kt
|
||||
WHEN type=kotlin.Any origin=ELVIS
|
||||
BRANCH
|
||||
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
arg0: GET_VAR 'val tmp_10: T of <root>.test? [val] declared in <root>.test' type=T of <root>.test? origin=null
|
||||
arg0: GET_VAR 'val tmp_10: T of <root>.test [val] declared in <root>.test' type=T of <root>.test origin=null
|
||||
arg1: CONST Null type=kotlin.Nothing? value=null
|
||||
then: CONST Int type=kotlin.Int value=42
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: TYPE_OP type=T of <root>.test origin=IMPLICIT_CAST typeOperand=T of <root>.test
|
||||
GET_VAR 'val tmp_10: T of <root>.test? [val] declared in <root>.test' type=T of <root>.test? origin=null
|
||||
then: GET_VAR 'val tmp_10: T of <root>.test [val] declared in <root>.test' type=T of <root>.test origin=null
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun <T : Any?> problematic(lss: List<List<T>>): List<T> {
|
||||
return lss.flatMap<List<T>, T>(transform = local fun <anonymous>(it: List<T>): Iterable<T> {
|
||||
return lss.flatMap<List<T>, T?>(transform = local fun <anonymous>(it: List<T>): Iterable<T?> {
|
||||
return id<T?>(v = it) /*!! List<T?> */
|
||||
}
|
||||
)
|
||||
|
||||
+5
-5
@@ -4,15 +4,15 @@ FILE fqName:<root> fileName:/typeParametersInImplicitCast.kt
|
||||
VALUE_PARAMETER name:lss index:0 type:kotlin.collections.List<kotlin.collections.List<T of <root>.problematic>>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun problematic <T> (lss: kotlin.collections.List<kotlin.collections.List<T of <root>.problematic>>): kotlin.collections.List<T of <root>.problematic> declared in <root>'
|
||||
CALL 'public final fun flatMap <T, R> (transform: kotlin.Function1<T of kotlin.collections.flatMap, kotlin.collections.Iterable<R of kotlin.collections.flatMap>>): kotlin.collections.List<R of kotlin.collections.flatMap> [inline] declared in kotlin.collections' type=kotlin.collections.List<T of <root>.problematic> origin=null
|
||||
CALL 'public final fun flatMap <T, R> (transform: kotlin.Function1<T of kotlin.collections.flatMap, kotlin.collections.Iterable<R of kotlin.collections.flatMap>>): kotlin.collections.List<R of kotlin.collections.flatMap> [inline] declared in kotlin.collections' type=kotlin.collections.List<T of <root>.problematic?> origin=null
|
||||
<T>: kotlin.collections.List<T of <root>.problematic>
|
||||
<R>: T of <root>.problematic
|
||||
<R>: T of <root>.problematic?
|
||||
$receiver: GET_VAR 'lss: kotlin.collections.List<kotlin.collections.List<T of <root>.problematic>> declared in <root>.problematic' type=kotlin.collections.List<kotlin.collections.List<T of <root>.problematic>> origin=null
|
||||
transform: FUN_EXPR type=kotlin.Function1<kotlin.collections.List<T of <root>.problematic>, kotlin.collections.Iterable<T of <root>.problematic>> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (it:kotlin.collections.List<T of <root>.problematic>) returnType:kotlin.collections.Iterable<T of <root>.problematic>
|
||||
transform: FUN_EXPR type=kotlin.Function1<kotlin.collections.List<T of <root>.problematic>, kotlin.collections.Iterable<T of <root>.problematic?>> origin=LAMBDA
|
||||
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (it:kotlin.collections.List<T of <root>.problematic>) returnType:kotlin.collections.Iterable<T of <root>.problematic?>
|
||||
VALUE_PARAMETER name:it index:0 type:kotlin.collections.List<T of <root>.problematic>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='local final fun <anonymous> (it: kotlin.collections.List<T of <root>.problematic>): kotlin.collections.Iterable<T of <root>.problematic> declared in <root>.problematic'
|
||||
RETURN type=kotlin.Nothing from='local final fun <anonymous> (it: kotlin.collections.List<T of <root>.problematic>): kotlin.collections.Iterable<T of <root>.problematic?> declared in <root>.problematic'
|
||||
TYPE_OP type=kotlin.collections.List<T of <root>.problematic?> origin=IMPLICIT_NOTNULL typeOperand=kotlin.collections.List<T of <root>.problematic?>
|
||||
CALL 'public/*package*/ open fun id <T> (v: kotlin.collections.List<T of <root>.ListId.id?>?): @[EnhancedNullability] kotlin.collections.List<T of <root>.ListId.id?> declared in <root>.ListId' type=@[EnhancedNullability] kotlin.collections.List<T of <root>.problematic?> origin=null
|
||||
<T>: T of <root>.problematic?
|
||||
|
||||
Reference in New Issue
Block a user