From 7834284bece00ffa8fe2b9d2211b963ff2448cb8 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Thu, 25 Jun 2020 18:26:01 +0300 Subject: [PATCH] [FIR] Support deserialization of value parameter annotations There are still some problems, see KT-39837 --- ...enConstructorWithInlineClassParameters.txt | 8 +- .../annotations/parameters/Constructor.txt | 2 +- .../parameters/ExtensionFunction.txt | 2 +- .../parameters/ExtensionFunctionInClass.txt | 2 +- .../parameters/FunctionInClass.txt | 2 +- .../parameters/FunctionInTrait.txt | 2 +- .../parameters/ManyAnnotations.txt | 4 +- .../parameters/TopLevelFunction.txt | 2 +- .../withUseSiteTarget/ReceiverTarget.txt | 2 +- .../resolveWithStdlib/complexPostponedCfg.dot | 125 +++++++++--------- .../resolveWithStdlib/complexPostponedCfg.txt | 4 +- .../inference/builderInferenceFromStdlib.kt | 19 +++ .../inference/builderInferenceFromStdlib.txt | 20 +++ ...FirDiagnosticsWithStdlibTestGenerated.java | 5 + .../JvmBinaryAnnotationDeserializer.kt | 38 +++++- .../AbstractAnnotationDeserializer.kt | 18 ++- .../deserialization/FirMemberDeserializer.kt | 26 +++- ...utableLocalVariableInsideCoroutineBlock.kt | 1 - .../box/coroutines/controlFlow/kt22694_1_3.kt | 1 - .../codegen/box/coroutines/kt35967.kt | 1 - .../ifExpressionInsideCoroutine_1_3.kt | 1 - .../testsWithStdLib/coroutines/kt36947.fir.kt | 2 +- 22 files changed, 191 insertions(+), 96 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInferenceFromStdlib.kt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInferenceFromStdlib.txt diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/HiddenConstructorWithInlineClassParameters.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/HiddenConstructorWithInlineClassParameters.txt index 4e1ea6759d2..c4cacc04208 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/HiddenConstructorWithInlineClassParameters.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/HiddenConstructorWithInlineClassParameters.txt @@ -7,7 +7,7 @@ public sealed class Sealed : R|kotlin/Any| { public final val z: R|test/Z| public get(): R|test/Z| - @R|test/Ann|() private constructor(z: R|test/Z|): R|test/Sealed| + @R|test/Ann|() private constructor(@R|test/Ann|() z: R|test/Z|): R|test/Sealed| public final class Derived : R|test/Sealed| { public constructor(z: R|test/Z|): R|test/Sealed.Derived| @@ -20,11 +20,11 @@ public final class Test : R|kotlin/Any| { public final val z: R|test/Z| public get(): R|test/Z| - @R|test/Ann|() public constructor(z: R|test/Z|, a: R|kotlin/Int|): R|test/Test| + @R|test/Ann|() public constructor(z: R|test/Z|, @R|test/Ann|() a: R|kotlin/Int|): R|test/Test| - @R|test/Ann|() private constructor(z: R|test/Z|, s: R|kotlin/String|): R|test/Test| + @R|test/Ann|() private constructor(z: R|test/Z|, @R|test/Ann|() s: R|kotlin/String|): R|test/Test| - @R|test/Ann|() public constructor(z: R|test/Z|): R|test/Test| + @R|test/Ann|() public constructor(@R|test/Ann|() z: R|test/Z|): R|test/Test| } diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/Constructor.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/Constructor.txt index d15303da7cd..5c134762c17 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/Constructor.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/Constructor.txt @@ -12,6 +12,6 @@ public final class Class : R|kotlin/Any| { public final val x: R|kotlin/Int| public get(): R|kotlin/Int| - public constructor(x: R|kotlin/Int|, y: R|kotlin/String|): R|test/Class| + public constructor(@R|test/A|() x: R|kotlin/Int|, @R|test/B|() y: R|kotlin/String|): R|test/Class| } diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ExtensionFunction.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ExtensionFunction.txt index 23bdbbb48e5..16a2b2a1aa6 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ExtensionFunction.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ExtensionFunction.txt @@ -1,4 +1,4 @@ -public final fun R|kotlin/Int|.foo(x: R|kotlin/Int|): R|kotlin/Unit| +public final fun R|kotlin/Int|.foo(@R|test/A|() x: R|kotlin/Int|): R|kotlin/Unit| public final annotation class A : R|kotlin/Annotation| { public constructor(): R|test/A| diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ExtensionFunctionInClass.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ExtensionFunctionInClass.txt index 831de82c1b0..7e650f8c483 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ExtensionFunctionInClass.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ExtensionFunctionInClass.txt @@ -4,7 +4,7 @@ public final annotation class Anno : R|kotlin/Annotation| { } public final class Class : R|kotlin/Any| { - public final fun R|kotlin/String|.foo(x: R|kotlin/Int|): R|kotlin/Int| + public final fun R|kotlin/String|.foo(@R|test/Anno|() x: R|kotlin/Int|): R|kotlin/Int| public constructor(): R|test/Class| diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/FunctionInClass.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/FunctionInClass.txt index 96490a2cd0a..2993fc9ce93 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/FunctionInClass.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/FunctionInClass.txt @@ -4,7 +4,7 @@ public final annotation class Anno : R|kotlin/Annotation| { } public final class Class : R|kotlin/Any| { - public final fun foo(x: R|kotlin/String|): R|kotlin/Unit| + public final fun foo(@R|test/Anno|() x: R|kotlin/String|): R|kotlin/Unit| public constructor(): R|test/Class| diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/FunctionInTrait.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/FunctionInTrait.txt index 1707f1a2337..737baaa357d 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/FunctionInTrait.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/FunctionInTrait.txt @@ -4,6 +4,6 @@ public final annotation class Anno : R|kotlin/Annotation| { } public abstract interface Trait : R|kotlin/Any| { - public open fun foo(x: R|kotlin/String|): R|kotlin/Int| + public open fun foo(@R|test/Anno|() x: R|kotlin/String|): R|kotlin/Int| } diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ManyAnnotations.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ManyAnnotations.txt index 4a802e7346e..8ed7d27fcf5 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ManyAnnotations.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/ManyAnnotations.txt @@ -1,6 +1,6 @@ -public final fun bar(x: R|kotlin/Int|): R|kotlin/Unit| +public final fun bar(@R|test/A|() @R|test/B|() @R|test/C|() @R|test/D|() x: R|kotlin/Int|): R|kotlin/Unit| -public final fun foo(x: R|kotlin/Int|, y: R|kotlin/Double|, z: R|kotlin/String|): R|kotlin/Unit| +public final fun foo(@R|test/A|() @R|test/B|() x: R|kotlin/Int|, @R|test/A|() @R|test/C|() y: R|kotlin/Double|, @R|test/B|() @R|test/C|() @R|test/D|() z: R|kotlin/String|): R|kotlin/Unit| public final annotation class A : R|kotlin/Annotation| { public constructor(): R|test/A| diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/TopLevelFunction.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/TopLevelFunction.txt index 4dfdddc0f39..e8343abd09f 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/TopLevelFunction.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/parameters/TopLevelFunction.txt @@ -1,4 +1,4 @@ -public final fun foo(x: R|kotlin/Int|): R|kotlin/Unit| +public final fun foo(@R|test/Anno|() x: R|kotlin/Int|): R|kotlin/Unit| public final annotation class Anno : R|kotlin/Annotation| { public constructor(): R|test/Anno| diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/withUseSiteTarget/ReceiverTarget.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/withUseSiteTarget/ReceiverTarget.txt index 370baf4c7cd..c2c9d357dfb 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/withUseSiteTarget/ReceiverTarget.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/withUseSiteTarget/ReceiverTarget.txt @@ -1,5 +1,5 @@ public final class A : R|kotlin/Any| { - public final fun R|kotlin/String|.myLength(q: R|kotlin/String|): R|kotlin/Int| + public final fun R|kotlin/String|.myLength(@R|test/Ann|() q: R|kotlin/String|): R|kotlin/Int| public final val R|kotlin/String|.myLength2: R|kotlin/Int| public get(): R|kotlin/Int| diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/complexPostponedCfg.dot b/compiler/fir/analysis-tests/testData/resolveWithStdlib/complexPostponedCfg.dot index b3ba0551b24..2f2df4159f7 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/complexPostponedCfg.dot +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/complexPostponedCfg.dot @@ -29,115 +29,110 @@ digraph complexPostponedCfg_kt { 9 [label="Postponed enter to lambda"]; subgraph cluster_4 { color=blue - 21 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; + 19 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; subgraph cluster_5 { color=blue - 22 [label="Enter block"]; - 23 [label="Postponed enter to lambda"]; + 20 [label="Enter block"]; + 21 [label="Postponed enter to lambda"]; subgraph cluster_6 { color=blue - 28 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; + 26 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; subgraph cluster_7 { color=blue - 29 [label="Enter block"]; - 30 [label="Access variable this@R|special/anonymous|"]; - 31 [label="Function call: this@R|special/anonymous|.R|FakeOverride|(...)"]; - 32 [label="Access variable R|/arguments|"]; - 33 [label="Function call: R|/arguments|.R|kotlin/collections/last|()"]; - 34 [label="Type operator: (R|/arguments|.R|kotlin/collections/last|() as R|FirFunctionCall|)"]; - 35 [label="Postponed enter to lambda"]; + 27 [label="Enter block"]; + 28 [label="Access variable this@R|special/anonymous|"]; + 29 [label="Function call: this@R|special/anonymous|.R|FakeOverride|(...)"]; + 30 [label="Access variable R|/arguments|"]; + 31 [label="Function call: R|/arguments|.R|kotlin/collections/last|()"]; + 32 [label="Type operator: (R|/arguments|.R|kotlin/collections/last|() as R|FirFunctionCall|)"]; + 33 [label="Postponed enter to lambda"]; subgraph cluster_8 { color=blue - 41 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; + 39 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; subgraph cluster_9 { color=blue - 42 [label="Enter block"]; - 43 [label="Access variable this@R|special/anonymous|"]; - 44 [label="Function call: this@R|special/anonymous|.R|FakeOverride|(...)"]; - 45 [label="Access variable R|/explicitReceiver|"]; - 46 [label="Type operator: (R|/explicitReceiver| as R|FirFunctionCall|)"]; - 47 [label="Function call: this@R|special/anonymous|.R|FakeOverride|(...)"]; - 48 [label="Exit block"]; + 40 [label="Enter block"]; + 41 [label="Access variable this@R|special/anonymous|"]; + 42 [label="Function call: this@R|special/anonymous|.R|FakeOverride|(...)"]; + 43 [label="Access variable R|/explicitReceiver|"]; + 44 [label="Type operator: (R|/explicitReceiver| as R|FirFunctionCall|)"]; + 45 [label="Function call: this@R|special/anonymous|.R|FakeOverride|(...)"]; + 46 [label="Exit block"]; } - 49 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; + 47 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; } - 36 [label="Call arguments union" style="filled" fillcolor=yellow]; - 37 [label="Postponed exit from lambda"]; - 38 [label="Function call: R|kotlin/with|(...)"]; - 39 [label="Exit block"]; + 34 [label="Call arguments union" style="filled" fillcolor=yellow]; + 35 [label="Postponed exit from lambda"]; + 36 [label="Function call: R|kotlin/with|(...)"]; + 37 [label="Exit block"]; } - 40 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; + 38 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; } - 24 [label="Postponed exit from lambda"]; - 25 [label="Function call: R|kotlin/collections/buildList|(...)"]; - 26 [label="Exit block"]; + 22 [label="Postponed exit from lambda"]; + 23 [label="Function call: R|kotlin/collections/buildList|(...)"]; + 24 [label="Exit block"]; } - 27 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; + 25 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; } 10 [label="Call arguments union" style="filled" fillcolor=yellow]; 11 [label="Postponed exit from lambda"]; - 12 [label="Function call: R|kotlin/with|(...)"]; - 13 [label="Stub" style="filled" fillcolor=gray]; - 14 [label="Variable declaration: lval firstCalls: R|kotlin/Nothing|" style="filled" fillcolor=gray]; - 15 [label="Access variable R|/firstCalls|" style="filled" fillcolor=gray]; + 12 [label="Function call: R|kotlin/with||>(...)"]; + 13 [label="Variable declaration: lval firstCalls: R|kotlin/collections/List|"]; + 14 [label="Access variable R|/firstCalls|"]; + 15 [label="Jump: ^foo R|/firstCalls|"]; 16 [label="Stub" style="filled" fillcolor=gray]; - 17 [label="Jump: ^foo R|/firstCalls|" style="filled" fillcolor=gray]; - 18 [label="Stub" style="filled" fillcolor=gray]; - 19 [label="Exit block" style="filled" fillcolor=gray]; + 17 [label="Exit block" style="filled" fillcolor=gray]; } - 20 [label="Exit function foo" style="filled" fillcolor=red]; + 18 [label="Exit function foo" style="filled" fillcolor=red]; } 4 -> {5}; 5 -> {6}; 6 -> {7}; 7 -> {8}; 8 -> {9}; - 9 -> {21}; + 9 -> {19}; 9 -> {11} [color=red]; 10 -> {12} [color=red]; 11 -> {12} [color=green]; - 12 -> {20}; - 12 -> {13} [style=dotted]; - 13 -> {14} [style=dotted]; - 14 -> {15} [style=dotted]; - 15 -> {20 16} [style=dotted]; + 12 -> {13}; + 13 -> {14}; + 14 -> {15}; + 15 -> {18}; + 15 -> {16} [style=dotted]; 16 -> {17} [style=dotted]; - 17 -> {20 18} [style=dotted]; - 18 -> {19} [style=dotted]; - 19 -> {20} [style=dotted]; - 21 -> {22}; + 17 -> {18} [style=dotted]; + 19 -> {20}; + 20 -> {21}; + 21 -> {26}; + 21 -> {22} [color=red]; 22 -> {23}; - 23 -> {28}; - 23 -> {24} [color=red]; + 23 -> {24}; 24 -> {25}; - 25 -> {26}; + 25 -> {10} [color=red]; + 25 -> {11} [color=green]; 26 -> {27}; - 27 -> {10} [color=red]; - 27 -> {11} [color=green]; + 27 -> {28}; 28 -> {29}; 29 -> {30}; 30 -> {31}; 31 -> {32}; 32 -> {33}; - 33 -> {34}; - 34 -> {35}; - 35 -> {41}; - 35 -> {37} [color=red]; - 36 -> {38} [color=red]; - 37 -> {38} [color=green]; - 38 -> {39}; + 33 -> {39}; + 33 -> {35} [color=red]; + 34 -> {36} [color=red]; + 35 -> {36} [color=green]; + 36 -> {37}; + 37 -> {38}; + 38 -> {22} [color=green]; 39 -> {40}; - 40 -> {10} [color=red]; - 40 -> {24} [color=green]; + 40 -> {41}; 41 -> {42}; 42 -> {43}; 43 -> {44}; 44 -> {45}; 45 -> {46}; 46 -> {47}; - 47 -> {48}; - 48 -> {49}; - 49 -> {36} [color=red]; - 49 -> {37} [color=green]; + 47 -> {34} [color=red]; + 47 -> {35} [color=green]; } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/complexPostponedCfg.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/complexPostponedCfg.txt index 00a042f9925..009c72006b7 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/complexPostponedCfg.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/complexPostponedCfg.txt @@ -4,8 +4,8 @@ FILE: complexPostponedCfg.kt public abstract interface FirFunctionCall : R|FirBase| { } public final fun foo(statements: R|kotlin/collections/List|, arguments: R|kotlin/collections/List|, explicitReceiver: R|FirBase|): R|kotlin/collections/List| { - lval firstCalls: R|kotlin/Nothing| = R|kotlin/with|((R|/statements|.R|kotlin/collections/last|() as R|FirFunctionCall|), = setCall@fun R|FirFunctionCall|.(): R|kotlin/Nothing| { - ^ R|kotlin/collections/buildList|( = buildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { + lval firstCalls: R|kotlin/collections/List| = R|kotlin/with||>((R|/statements|.R|kotlin/collections/last|() as R|FirFunctionCall|), = setCall@fun R|FirFunctionCall|.(): R|kotlin/collections/List| { + ^ R|kotlin/collections/buildList|( = buildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|FakeOverride|(this@R|special/anonymous|) ^ R|kotlin/with|((R|/arguments|.R|kotlin/collections/last|() as R|FirFunctionCall|), = plusCall@fun R|FirFunctionCall|.(): R|kotlin/Boolean| { this@R|special/anonymous|.R|FakeOverride|(this@R|special/anonymous|) diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInferenceFromStdlib.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInferenceFromStdlib.kt new file mode 100644 index 00000000000..98426bfb87c --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInferenceFromStdlib.kt @@ -0,0 +1,19 @@ +fun test_1() { + val list = buildList { + add("") + } + takeList(list) +} + +fun test_2() { + val list = myBuildList { + add("") + } + takeList(list) +} + +fun myBuildList(@BuilderInference builderAction: MutableList.() -> Unit): List { + return ArrayList().apply(builderAction) +} + +fun takeList(list: List) {} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInferenceFromStdlib.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInferenceFromStdlib.txt new file mode 100644 index 00000000000..bc77332b341 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInferenceFromStdlib.txt @@ -0,0 +1,20 @@ +FILE: builderInferenceFromStdlib.kt + public final fun test_1(): R|kotlin/Unit| { + lval list: R|kotlin/collections/List| = R|kotlin/collections/buildList|( = buildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { + ^ this@R|special/anonymous|.R|FakeOverride|(String()) + } + ) + R|/takeList|(R|/list|) + } + public final fun test_2(): R|kotlin/Unit| { + lval list: R|kotlin/collections/List| = R|/myBuildList|( = myBuildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { + ^ this@R|special/anonymous|.R|FakeOverride|(String()) + } + ) + R|/takeList|(R|/list|) + } + public final fun myBuildList(@R|kotlin/BuilderInference|() builderAction: R|kotlin/collections/MutableList.() -> kotlin/Unit|): R|kotlin/collections/List| { + ^myBuildList R|java/util/ArrayList.ArrayList|().R|kotlin/apply||>(R|/builderAction|) + } + public final fun takeList(list: R|kotlin/collections/List|): R|kotlin/Unit| { + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java index 1c2b18f18e6..859b75f654a 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java @@ -692,6 +692,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInference.kt"); } + @TestMetadata("builderInferenceFromStdlib.kt") + public void testBuilderInferenceFromStdlib() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInferenceFromStdlib.kt"); + } + @TestMetadata("complexConstraintSystem.kt") public void testComplexConstraintSystem() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/complexConstraintSystem.kt"); diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt index a194fb981bd..2ecf2a057d7 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt @@ -17,11 +17,13 @@ import org.jetbrains.kotlin.metadata.ProtoBuf import org.jetbrains.kotlin.metadata.deserialization.NameResolver import org.jetbrains.kotlin.metadata.deserialization.TypeTable import org.jetbrains.kotlin.metadata.deserialization.getExtensionOrNull +import org.jetbrains.kotlin.metadata.deserialization.hasReceiver import org.jetbrains.kotlin.metadata.jvm.JvmProtoBuf import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.protobuf.MessageLite +import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource class JvmBinaryAnnotationDeserializer( @@ -33,12 +35,6 @@ class JvmBinaryAnnotationDeserializer( session.loadMemberAnnotations(kotlinBinaryClass, byteContent) } - private enum class CallableKind { - PROPERTY_GETTER, - PROPERTY_SETTER, - OTHERS - } - override fun loadTypeAnnotations(typeProto: ProtoBuf.Type, nameResolver: NameResolver): List { val annotations = typeProto.getExtension(JvmProtoBuf.typeAnnotation).orEmpty() return annotations.map { deserializeAnnotation(it, nameResolver) } @@ -86,6 +82,36 @@ class JvmBinaryAnnotationDeserializer( return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, signature) } + override fun loadValueParameterAnnotations( + containerSource: DeserializedContainerSource?, + callableProto: MessageLite, + valueParameterProto: ProtoBuf.ValueParameter, + nameResolver: NameResolver, + typeTable: TypeTable, + kind: CallableKind, + parameterIndex: Int, + ): List { + val methodSignature = getCallableSignature(callableProto, nameResolver, typeTable, kind) ?: return emptyList() + val index = parameterIndex + computeJvmParameterIndexShift(callableProto) + val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, index) + return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, paramSignature) + } + + /* + * TODO: Support container proto and fix index shift for + * constructors of inner classes and enums + * + * See [AbstractBinaryClassAnnotationAndConstantLoader] + */ + private fun computeJvmParameterIndexShift(message: MessageLite): Int { + return when (message) { + is ProtoBuf.Function -> if (message.hasReceiver()) 1 else 0 + is ProtoBuf.Property -> if (message.hasReceiver()) 1 else 0 + is ProtoBuf.Constructor -> 0 + else -> throw UnsupportedOperationException("Unsupported message: ${message::class.java}") + } + } + private fun getCallableSignature( proto: MessageLite, nameResolver: NameResolver, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt index b0dcf1eac18..e2383162280 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt @@ -30,6 +30,8 @@ import org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.Argument.Value.Type.* import org.jetbrains.kotlin.metadata.deserialization.Flags import org.jetbrains.kotlin.metadata.deserialization.NameResolver import org.jetbrains.kotlin.metadata.deserialization.TypeTable +import org.jetbrains.kotlin.protobuf.MessageLite +import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource import org.jetbrains.kotlin.serialization.deserialization.getClassId @@ -40,6 +42,12 @@ abstract class AbstractAnnotationDeserializer( ) { protected val protocol = BuiltInSerializerProtocol + enum class CallableKind { + PROPERTY_GETTER, + PROPERTY_SETTER, + OTHERS + } + fun loadClassAnnotations(classProto: ProtoBuf.Class, nameResolver: NameResolver): List { if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) return emptyList() val annotations = classProto.getExtension(protocol.classAnnotation).orEmpty() @@ -98,7 +106,15 @@ abstract class AbstractAnnotationDeserializer( return annotations.map { deserializeAnnotation(it, nameResolver) } } - fun loadValueParameterAnnotations(valueParameterProto: ProtoBuf.ValueParameter, nameResolver: NameResolver): List { + open fun loadValueParameterAnnotations( + containerSource: DeserializedContainerSource?, + callableProto: MessageLite, + valueParameterProto: ProtoBuf.ValueParameter, + nameResolver: NameResolver, + typeTable: TypeTable, + kind: CallableKind, + parameterIndex: Int + ): List { if (!Flags.HAS_ANNOTATIONS.get(valueParameterProto.flags)) return emptyList() val annotations = valueParameterProto.getExtension(protocol.parameterAnnotation).orEmpty() return annotations.map { deserializeAnnotation(it, nameResolver) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt index 6fa891da347..3b816f294c6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.metadata.deserialization.* import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.protobuf.MessageLite import org.jetbrains.kotlin.serialization.deserialization.ProtoEnumFlags import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource @@ -323,7 +324,11 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) { this.symbol = symbol resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES typeParameters += local.typeDeserializer.ownTypeParameters.map { it.fir } - valueParameters += local.memberDeserializer.valueParameters(proto.valueParameterList) + valueParameters += local.memberDeserializer.valueParameters( + proto.valueParameterList, + proto, + AbstractAnnotationDeserializer.CallableKind.OTHERS + ) annotations += c.annotationDeserializer.loadFunctionAnnotations(c.containerSource, proto, local.nameResolver, local.typeTable) this.containerSource = c.containerSource @@ -373,7 +378,10 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) { typeParameters.filterIsInstance() .map { buildConstructedClassTypeParameterRef { this.symbol = it.symbol } } valueParameters += local.memberDeserializer.valueParameters( - proto.valueParameterList, addDefaultValue = classBuilder.symbol.classId == StandardClassIds.Enum + proto.valueParameterList, + proto, + AbstractAnnotationDeserializer.CallableKind.OTHERS, + addDefaultValue = classBuilder.symbol.classId == StandardClassIds.Enum ) annotations += c.annotationDeserializer.loadConstructorAnnotations(c.containerSource, proto, local.nameResolver, local.typeTable) @@ -389,9 +397,11 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) { private fun valueParameters( valueParameters: List, + callableProto: MessageLite, + callableKind: AbstractAnnotationDeserializer.CallableKind, addDefaultValue: Boolean = false ): List { - return valueParameters.map { proto -> + return valueParameters.mapIndexed { index, proto -> val flags = if (proto.hasFlags()) proto.flags else 0 val name = c.nameResolver.getName(proto.name) buildValueParameter { @@ -407,7 +417,15 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) { isCrossinline = Flags.IS_CROSSINLINE.get(flags) isNoinline = Flags.IS_NOINLINE.get(flags) isVararg = proto.varargElementType(c.typeTable) != null - annotations += c.annotationDeserializer.loadValueParameterAnnotations(proto, c.nameResolver) + annotations += c.annotationDeserializer.loadValueParameterAnnotations( + c.containerSource, + callableProto, + proto, + c.nameResolver, + c.typeTable, + callableKind, + index, + ) } }.toList() } diff --git a/compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt b/compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt index e52f477c39c..9bf0bbf4933 100644 --- a/compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt +++ b/compiler/testData/codegen/box/coroutines/captureMutableLocalVariableInsideCoroutineBlock.kt @@ -1,7 +1,6 @@ // WITH_RUNTIME // KJS_WITH_FULL_RUNTIME // WITH_COROUTINES -// IGNORE_BACKEND_FIR: JVM_IR import helpers.* import kotlin.coroutines.* diff --git a/compiler/testData/codegen/box/coroutines/controlFlow/kt22694_1_3.kt b/compiler/testData/codegen/box/coroutines/controlFlow/kt22694_1_3.kt index 2c1a58b824d..e62274da501 100644 --- a/compiler/testData/codegen/box/coroutines/controlFlow/kt22694_1_3.kt +++ b/compiler/testData/codegen/box/coroutines/controlFlow/kt22694_1_3.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // KJS_WITH_FULL_RUNTIME // WITH_RUNTIME // WITH_COROUTINES diff --git a/compiler/testData/codegen/box/coroutines/kt35967.kt b/compiler/testData/codegen/box/coroutines/kt35967.kt index 53746e350ab..9ff8b1d8f1a 100644 --- a/compiler/testData/codegen/box/coroutines/kt35967.kt +++ b/compiler/testData/codegen/box/coroutines/kt35967.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +NewInference -// IGNORE_BACKEND_FIR: JVM_IR // WITH_RUNTIME // KJS_WITH_FULL_RUNTIME // FULL_JDK diff --git a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/ifExpressionInsideCoroutine_1_3.kt b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/ifExpressionInsideCoroutine_1_3.kt index c3cd44506fb..05e655dd531 100644 --- a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/ifExpressionInsideCoroutine_1_3.kt +++ b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/ifExpressionInsideCoroutine_1_3.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // KJS_WITH_FULL_RUNTIME // WITH_RUNTIME // WITH_COROUTINES diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt36947.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt36947.fir.kt index 2e8706b4919..120c8563911 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt36947.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/kt36947.fir.kt @@ -1,5 +1,5 @@ val foo = iterator { - yield(0) + yield(0) val nullable: String? = null nullable.length nullable.get(2)