diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/compilerPhase.kt b/compiler/fir/analysis-tests/testData/resolve/problems/compilerPhase.kt new file mode 100644 index 00000000000..7a1446811da --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/problems/compilerPhase.kt @@ -0,0 +1,44 @@ +interface CommonBackendContext + +interface PhaserState { + var depth: Int +} + +interface PhaseConfig { + val needProfiling: Boolean +} + +inline fun PhaserState.downlevel(nlevels: Int, block: () -> R): R { + depth += nlevels + val result = block() + depth -= nlevels + return result +} + +interface CompilerPhase { + fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState, context: Context, input: Input): Output +} + +class NamedCompilerPhase( + private val lower: CompilerPhase +) : CompilerPhase { + override fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState, 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, context: Context, output: Data) { + + } + + private fun runAndProfile(phaseConfig: PhaseConfig, phaserState: PhaserState, context: Context, source: Data): Data { + + } +} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/compilerPhase.txt b/compiler/fir/analysis-tests/testData/resolve/problems/compilerPhase.txt new file mode 100644 index 00000000000..e574055d543 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/problems/compilerPhase.txt @@ -0,0 +1,55 @@ +FILE: compilerPhase.kt + public abstract interface CommonBackendContext : R|kotlin/Any| { + } + public abstract interface PhaserState : 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|PhaserState|.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|/nlevels|) + lval result: R|R| = R|/block|.R|SubstitutionOverride|() + this@R|/downlevel|.R|/PhaserState.depth| = this@R|/downlevel|.R|/PhaserState.depth|.R|kotlin/Int.minus|(R|/nlevels|) + ^downlevel R|/result| + } + public abstract interface CompilerPhase : R|kotlin/Any| { + public abstract fun invoke(phaseConfig: R|PhaseConfig|, phaserState: R|PhaserState|, context: R|Context|, input: R|Input|): R|Output| + + } + public final class NamedCompilerPhase : R|CompilerPhase| { + public constructor(lower: R|CompilerPhase|): R|NamedCompilerPhase| { + super() + } + + private final val lower: R|CompilerPhase| = R|/lower| + private get(): R|CompilerPhase| + + public final override fun invoke(phaseConfig: R|PhaseConfig|, phaserState: R|PhaserState|, context: R|Context|, input: R|Data|): R|Data| { + lval output: R|Data| = when () { + R|/phaseConfig|.R|/PhaseConfig.needProfiling| -> { + this@R|/NamedCompilerPhase|.R|/NamedCompilerPhase.runAndProfile|(R|/phaseConfig|, R|/phaserState|, R|/context|, R|/input|) + } + else -> { + R|/phaserState|.R|/downlevel|(Int(1), = downlevel@fun (): R|Data| { + ^ this@R|/NamedCompilerPhase|.R|/NamedCompilerPhase.lower|.R|SubstitutionOverride|(R|/phaseConfig|, R|/phaserState|, R|/context|, R|/input|) + } + ) + } + } + + this@R|/NamedCompilerPhase|.R|/NamedCompilerPhase.runAfter|(R|/phaseConfig|, R|/phaserState|, R|/context|, R|/output|) + } + + private final fun runAfter(phaseConfig: R|PhaseConfig|, phaserState: R|PhaserState|, context: R|Context|, output: R|Data|): R|kotlin/Unit| { + } + + private final fun runAndProfile(phaseConfig: R|PhaseConfig|, phaserState: R|PhaserState|, context: R|Context|, source: R|Data|): R|Data| { + } + + } diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 39cc95f6058..9e8a81ab802 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -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"); diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index ccb0b49c2ac..fb36942a569 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -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"); diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java index 71463b1001f..3cb1851cae2 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java @@ -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"); diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt index cb1df83b5c1..ec132d66375 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt @@ -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) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt index fdb35bc8da0..b6905baca37 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt @@ -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) diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/argumentAndReturnExpectedType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/argumentAndReturnExpectedType.fir.kt index fc710a64a4f..c43049f5469 100644 --- a/compiler/testData/diagnostics/tests/callableReference/generic/argumentAndReturnExpectedType.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/generic/argumentAndReturnExpectedType.fir.kt @@ -27,9 +27,9 @@ fun listOf(): List = TODO() fun setOf(): Set = TODO() fun test2(x: T) { - bar(x, x, ::foo).checkType { _>() } + bar(x, x, ::foo).checkType { _>() } bar(x, 1, ::foo).checkType { _>() } - bar(1, x, ::foo).checkType { _>() } + bar(1, x, ::foo).checkType { _>() } bar(listOf(), setOf(), ::foo).checkType { _, Set>> () } bar(listOf(), 1, ::foo).checkType { _, Int>>() } diff --git a/compiler/testData/ir/irText/expressions/kt30796.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt30796.fir.kt.txt index f45cf10a60b..92347743b7d 100644 --- a/compiler/testData/ir/irText/expressions/kt30796.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/kt30796.fir.kt.txt @@ -70,7 +70,7 @@ fun test(value: T, value2: T) { } } val x7: Any = { // BLOCK - val : T? = { // BLOCK + val : T = { // BLOCK val : T? = magic() when { EQEQ(arg0 = , arg1 = null) -> value @@ -79,7 +79,7 @@ fun test(value: T, value2: T) { } when { EQEQ(arg0 = , arg1 = null) -> 42 - else -> /*as T */ + else -> } } } diff --git a/compiler/testData/ir/irText/expressions/kt30796.fir.txt b/compiler/testData/ir/irText/expressions/kt30796.fir.txt index 0b70ed16ffd..344efa7f284 100644 --- a/compiler/testData/ir/irText/expressions/kt30796.fir.txt +++ b/compiler/testData/ir/irText/expressions/kt30796.fir.txt @@ -137,12 +137,12 @@ FILE fqName: fileName:/kt30796.kt then: GET_VAR 'val tmp_8: T of .test [val] declared in .test' type=T of .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 .test? [val] - BLOCK type=T of .test? origin=ELVIS + VAR IR_TEMPORARY_VARIABLE name:tmp_10 type:T of .test [val] + BLOCK type=T of .test origin=ELVIS VAR IR_TEMPORARY_VARIABLE name:tmp_11 type:T of .test? [val] CALL 'public final fun magic (): T of .magic declared in ' type=T of .test? origin=null : T of .test? - WHEN type=T of .test? origin=ELVIS + WHEN type=T of .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 .test? [val] declared in .test' type=T of .test? origin=null @@ -155,10 +155,9 @@ FILE fqName: 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 .test? [val] declared in .test' type=T of .test? origin=null + arg0: GET_VAR 'val tmp_10: T of .test [val] declared in .test' type=T of .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 .test origin=IMPLICIT_CAST typeOperand=T of .test - GET_VAR 'val tmp_10: T of .test? [val] declared in .test' type=T of .test? origin=null + then: GET_VAR 'val tmp_10: T of .test [val] declared in .test' type=T of .test origin=null diff --git a/compiler/testData/ir/irText/regressions/typeParametersInImplicitCast.fir.kt.txt b/compiler/testData/ir/irText/regressions/typeParametersInImplicitCast.fir.kt.txt index df40c6ff4e0..35d4f744505 100644 --- a/compiler/testData/ir/irText/regressions/typeParametersInImplicitCast.fir.kt.txt +++ b/compiler/testData/ir/irText/regressions/typeParametersInImplicitCast.fir.kt.txt @@ -1,5 +1,5 @@ fun problematic(lss: List>): List { - return lss.flatMap, T>(transform = local fun (it: List): Iterable { + return lss.flatMap, T?>(transform = local fun (it: List): Iterable { return id(v = it) /*!! List */ } ) diff --git a/compiler/testData/ir/irText/regressions/typeParametersInImplicitCast.fir.txt b/compiler/testData/ir/irText/regressions/typeParametersInImplicitCast.fir.txt index a21eafe3e68..2b7343b61d9 100644 --- a/compiler/testData/ir/irText/regressions/typeParametersInImplicitCast.fir.txt +++ b/compiler/testData/ir/irText/regressions/typeParametersInImplicitCast.fir.txt @@ -4,15 +4,15 @@ FILE fqName: fileName:/typeParametersInImplicitCast.kt VALUE_PARAMETER name:lss index:0 type:kotlin.collections.List.problematic>> BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun problematic (lss: kotlin.collections.List.problematic>>): kotlin.collections.List.problematic> declared in ' - CALL 'public final fun flatMap (transform: kotlin.Function1>): kotlin.collections.List [inline] declared in kotlin.collections' type=kotlin.collections.List.problematic> origin=null + CALL 'public final fun flatMap (transform: kotlin.Function1>): kotlin.collections.List [inline] declared in kotlin.collections' type=kotlin.collections.List.problematic?> origin=null : kotlin.collections.List.problematic> - : T of .problematic + : T of .problematic? $receiver: GET_VAR 'lss: kotlin.collections.List.problematic>> declared in .problematic' type=kotlin.collections.List.problematic>> origin=null - transform: FUN_EXPR type=kotlin.Function1.problematic>, kotlin.collections.Iterable.problematic>> origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.collections.List.problematic>) returnType:kotlin.collections.Iterable.problematic> + transform: FUN_EXPR type=kotlin.Function1.problematic>, kotlin.collections.Iterable.problematic?>> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.collections.List.problematic>) returnType:kotlin.collections.Iterable.problematic?> VALUE_PARAMETER name:it index:0 type:kotlin.collections.List.problematic> BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (it: kotlin.collections.List.problematic>): kotlin.collections.Iterable.problematic> declared in .problematic' + RETURN type=kotlin.Nothing from='local final fun (it: kotlin.collections.List.problematic>): kotlin.collections.Iterable.problematic?> declared in .problematic' TYPE_OP type=kotlin.collections.List.problematic?> origin=IMPLICIT_NOTNULL typeOperand=kotlin.collections.List.problematic?> CALL 'public/*package*/ open fun id (v: kotlin.collections.List.ListId.id?>?): @[EnhancedNullability] kotlin.collections.List.ListId.id?> declared in .ListId' type=@[EnhancedNullability] kotlin.collections.List.problematic?> origin=null : T of .problematic?