-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
K2 AA CodeGen: Set annotation for declarations out of CodeGen targets
The Fir2Ir has two steps in terms of the annotation setup: Step #1. Creating `IrMutableAnnotationContainer` Step #2. Filling `IrMutableAnnotationContainer` with annotations When the `IrMutableAnnotationContainer` is out of the source module, `Fir2IrCallableDeclarationsGenerator` sets annotations for a `IrMutableAnnotationContainer` when creating its IR object. For example, when `foo()` defined in `B.kt` is called in file `A.kt`, and `A.kt` is a part of the source module while `B.kt` is a part of library, `Fir2IrCallableDeclarationsGenerator` sets annotations of `IrFunction` for `foo()`. On the other hand, if `foo()` is a part of the source module, `Fir2IrCallableDeclarationsGenerator` does not set annotations for it when creating `IrMutableAnnotationContainer` (Step #1). Later, when it fills contents of `IrMutableAnnotationContainer`, it conducts Step #2. However, if `foo()` is a part of the source module, but it is not in a compile target file, filling contents of `foo()` does not happen (because it is not a compile target). As a result, set up annotations for `foo()` is not done by Fir2Ir. This missing annotation setup causes a serious bug for Android Compose app. This commit updates code to decide whether we have to set up the annotations of `IrMutableAnnotationContainer` in Step #1 or not. We have to check not only if it is a part of the source code but also if it is a part of compile targets or not. ^KT-66532 Fixed
- Loading branch information
Showing
15 changed files
with
218 additions
and
8 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...NormalAnalysisSourceModuleFirPluginPrototypeMultiModuleCompilerFacilityTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...lity/firPluginPrototypeMultiModule/annotationForFunctionOutOfCodeGenTarget.composable.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
BookmarkButton |
12 changes: 12 additions & 0 deletions
12
...ilerFacility/firPluginPrototypeMultiModule/annotationForFunctionOutOfCodeGenTarget.ir.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
MODULE_FRAGMENT | ||
FILE fqName:<root> fileName:main.kt | ||
FUN name:PostCardSimple visibility:public modality:FINAL <> (navigateToArticle:kotlin.Function1<kotlin.String, kotlin.Unit>, isFavorite:kotlin.Boolean, onToggleFavorite:kotlin.Function0<kotlin.Unit>) returnType:kotlin.Unit | ||
annotations: | ||
MyComposable | ||
VALUE_PARAMETER name:navigateToArticle index:0 type:kotlin.Function1<kotlin.String, kotlin.Unit> | ||
VALUE_PARAMETER name:isFavorite index:1 type:kotlin.Boolean | ||
VALUE_PARAMETER name:onToggleFavorite index:2 type:kotlin.Function0<kotlin.Unit> | ||
BLOCK_BODY | ||
CALL 'public final fun BookmarkButton (isBookmarked: kotlin.Boolean, onClick: kotlin.Function0<kotlin.Unit>): kotlin.Unit declared in p3.JetnewsIconsKt' type=kotlin.Unit origin=null | ||
isBookmarked: GET_VAR 'isFavorite: kotlin.Boolean declared in <root>.PostCardSimple' type=kotlin.Boolean origin=null | ||
onClick: GET_VAR 'onToggleFavorite: kotlin.Function0<kotlin.Unit> declared in <root>.PostCardSimple' type=kotlin.Function0<kotlin.Unit> origin=null |
31 changes: 31 additions & 0 deletions
31
...compilerFacility/firPluginPrototypeMultiModule/annotationForFunctionOutOfCodeGenTarget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// WITH_FIR_TEST_COMPILER_PLUGIN | ||
// DUMP_IR | ||
// CHECK_COMPOSABLE_CALL | ||
|
||
// MODULE: main | ||
// FILE: main.kt | ||
import org.jetbrains.kotlin.fir.plugin.MyComposable | ||
import p3.BookmarkButton | ||
|
||
@MyComposable | ||
fun PostCardSimple( | ||
navigateToArticle: (String) -> Unit, | ||
isFavorite: Boolean, | ||
onToggleFavorite: () -> Unit | ||
) { | ||
BookmarkButton( | ||
isBookmarked = isFavorite, | ||
onClick = onToggleFavorite, | ||
) | ||
} | ||
// FILE: utils/JetnewsIcons.kt | ||
package p3 | ||
|
||
import org.jetbrains.kotlin.fir.plugin.MyComposable | ||
|
||
@MyComposable | ||
fun BookmarkButton( | ||
isBookmarked: Boolean, | ||
onClick: () -> Unit, | ||
) { | ||
} |
4 changes: 4 additions & 0 deletions
4
...ompilerFacility/firPluginPrototypeMultiModule/annotationForFunctionOutOfCodeGenTarget.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public final class MainKt { | ||
// source: 'main.kt' | ||
public final static method PostCardSimple(p0: kotlin.jvm.functions.Function1, p1: boolean, p2: kotlin.jvm.functions.Function0): void | ||
} |
1 change: 1 addition & 0 deletions
1
...ity/firPluginPrototypeMultiModule/annotationForFunctionOutOfCodeGenTarget2.composable.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<get-foo> |
11 changes: 11 additions & 0 deletions
11
...lerFacility/firPluginPrototypeMultiModule/annotationForFunctionOutOfCodeGenTarget2.ir.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
MODULE_FRAGMENT | ||
FILE fqName:<root> fileName:main.kt | ||
FUN name:Greeting visibility:public modality:FINAL <> () returnType:kotlin.String | ||
annotations: | ||
MyComposable | ||
BLOCK_BODY | ||
RETURN type=kotlin.Nothing from='public final fun Greeting (): kotlin.String declared in <root>' | ||
STRING_CONCATENATION type=kotlin.String | ||
CONST String type=kotlin.String value="Hi " | ||
CALL 'public final fun <get-foo> (): kotlin.Int declared in p3.FooKt' type=kotlin.Int origin=GET_PROPERTY | ||
CONST String type=kotlin.String value="!" |
27 changes: 27 additions & 0 deletions
27
...ompilerFacility/firPluginPrototypeMultiModule/annotationForFunctionOutOfCodeGenTarget2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// WITH_FIR_TEST_COMPILER_PLUGIN | ||
// DUMP_IR | ||
// CHECK_COMPOSABLE_CALL | ||
|
||
// MODULE: main | ||
// FILE: main.kt | ||
import org.jetbrains.kotlin.fir.plugin.MyComposable | ||
import p3.foo | ||
|
||
@MyComposable | ||
fun Greeting(): String { | ||
return "Hi $foo!" | ||
} | ||
|
||
// FILE: p3/foo.kt | ||
package p3 | ||
|
||
import org.jetbrains.kotlin.fir.plugin.MyComposable | ||
|
||
private var foo_ = 0 | ||
|
||
fun setFoo(newFoo: Int) { | ||
foo_ = newFoo | ||
} | ||
|
||
val foo: Int | ||
@MyComposable get() = foo_ + 1 |
4 changes: 4 additions & 0 deletions
4
...mpilerFacility/firPluginPrototypeMultiModule/annotationForFunctionOutOfCodeGenTarget2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public final class MainKt { | ||
// source: 'main.kt' | ||
public final static method Greeting(): java.lang.String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters