-
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.
Make sure a composable call does not escape composable lambda
Compose compiler ignores inline lambdas when marking coalescable group children. This should not be the case for @composable inline lambdas, as they don't require additional groups to support the control flow. The coalescable group was previously added to both inline lambda block and parent composable block, incorrectly creating an additional endGroup call. Test: compose compiler tests Fixes: 331365999 ( https://issuetracker.google.com/issues/331365999 ) Change-Id: If5ca9550559263126252b923f7a4a9078b165d14 ( https://android-review.googlesource.com/q/If5ca9550559263126252b923f7a4a9078b165d14 ) Moved from: androidx/androidx@d4c18f0
- Loading branch information
Showing
6 changed files
with
356 additions
and
19 deletions.
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
...ins.kotlin.ControlFlowTransformTests/ifInsideInlineComposableFunction[useFir = false].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,55 @@ | ||
// | ||
// Source | ||
// ------------------------------------------ | ||
|
||
import androidx.compose.runtime.* | ||
|
||
@Composable | ||
fun Label(test: Boolean) { | ||
Layout( | ||
content = { | ||
Box() | ||
if (test) { | ||
Box() | ||
} | ||
} | ||
) | ||
} | ||
|
||
// | ||
// Transformed IR | ||
// ------------------------------------------ | ||
|
||
@Composable | ||
fun Label(test: Boolean, %composer: Composer?, %changed: Int) { | ||
%composer = %composer.startRestartGroup(<>) | ||
sourceInformation(%composer, "C(Label)<Layout...>:Test.kt") | ||
val %dirty = %changed | ||
if (%changed and 0b0110 == 0) { | ||
%dirty = %dirty or if (%composer.changed(test)) 0b0100 else 0b0010 | ||
} | ||
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) { | ||
if (isTraceInProgress()) { | ||
traceEventStart(<>, %dirty, -1, <>) | ||
} | ||
Layout({ %composer: Composer?, %changed: Int -> | ||
sourceInformationMarkerStart(%composer, <>, "C<Box()>:Test.kt") | ||
Box(%composer, 0) | ||
%composer.startReplaceGroup(<>) | ||
sourceInformation(%composer, "<Box()>") | ||
if (test) { | ||
Box(%composer, 0) | ||
} | ||
%composer.endReplaceGroup() | ||
sourceInformationMarkerEnd(%composer) | ||
}, %composer, 0) | ||
if (isTraceInProgress()) { | ||
traceEventEnd() | ||
} | ||
} else { | ||
%composer.skipToGroupEnd() | ||
} | ||
%composer.endRestartGroup()?.updateScope { %composer: Composer?, %force: Int -> | ||
Label(test, %composer, updateChangedFlags(%changed or 0b0001)) | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...gins.kotlin.ControlFlowTransformTests/ifInsideInlineComposableFunction[useFir = true].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,55 @@ | ||
// | ||
// Source | ||
// ------------------------------------------ | ||
|
||
import androidx.compose.runtime.* | ||
|
||
@Composable | ||
fun Label(test: Boolean) { | ||
Layout( | ||
content = { | ||
Box() | ||
if (test) { | ||
Box() | ||
} | ||
} | ||
) | ||
} | ||
|
||
// | ||
// Transformed IR | ||
// ------------------------------------------ | ||
|
||
@Composable | ||
fun Label(test: Boolean, %composer: Composer?, %changed: Int) { | ||
%composer = %composer.startRestartGroup(<>) | ||
sourceInformation(%composer, "C(Label)<Layout...>:Test.kt") | ||
val %dirty = %changed | ||
if (%changed and 0b0110 == 0) { | ||
%dirty = %dirty or if (%composer.changed(test)) 0b0100 else 0b0010 | ||
} | ||
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) { | ||
if (isTraceInProgress()) { | ||
traceEventStart(<>, %dirty, -1, <>) | ||
} | ||
Layout({ %composer: Composer?, %changed: Int -> | ||
sourceInformationMarkerStart(%composer, <>, "C<Box()>:Test.kt") | ||
Box(%composer, 0) | ||
%composer.startReplaceGroup(<>) | ||
sourceInformation(%composer, "<Box()>") | ||
if (test) { | ||
Box(%composer, 0) | ||
} | ||
%composer.endReplaceGroup() | ||
sourceInformationMarkerEnd(%composer) | ||
}, %composer, 0) | ||
if (isTraceInProgress()) { | ||
traceEventEnd() | ||
} | ||
} else { | ||
%composer.skipToGroupEnd() | ||
} | ||
%composer.endRestartGroup()?.updateScope { %composer: Composer?, %force: Int -> | ||
Label(test, %composer, updateChangedFlags(%changed or 0b0001)) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...gins.kotlin.ControlFlowTransformTests/testConditionalReturnFromInline[useFir = false].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,76 @@ | ||
// | ||
// Source | ||
// ------------------------------------------ | ||
|
||
import androidx.compose.runtime.* | ||
|
||
@Composable fun Test(test: Boolean) { | ||
Column { | ||
if (!test) { | ||
Text("Say") | ||
return@Column | ||
} | ||
Text("Hello") | ||
} | ||
|
||
NonComposable { | ||
if (!test) { | ||
Text("Say") | ||
return@NonComposable | ||
} | ||
Text("Hello") | ||
} | ||
} | ||
|
||
// | ||
// Transformed IR | ||
// ------------------------------------------ | ||
|
||
@Composable | ||
fun Test(test: Boolean, %composer: Composer?, %changed: Int) { | ||
%composer = %composer.startRestartGroup(<>) | ||
sourceInformation(%composer, "C(Test)<Column>,*<Text("...>:Test.kt") | ||
val %dirty = %changed | ||
if (%changed and 0b0110 == 0) { | ||
%dirty = %dirty or if (%composer.changed(test)) 0b0100 else 0b0010 | ||
} | ||
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) { | ||
if (isTraceInProgress()) { | ||
traceEventStart(<>, %dirty, -1, <>) | ||
} | ||
Column({ %composer: Composer?, %changed: Int -> | ||
%composer.startReplaceGroup(<>) | ||
sourceInformation(%composer, "C<Text("...>:Test.kt") | ||
%composer.startReplaceGroup(<>) | ||
sourceInformation(%composer, "<Text("...>") | ||
if (!test) { | ||
Text("Say", %composer, 0b0110) | ||
%composer.endReplaceGroup() | ||
%composer.endReplaceGroup() | ||
return@Column | ||
} | ||
%composer.endReplaceGroup() | ||
Text("Hello", %composer, 0b0110) | ||
%composer.endReplaceGroup() | ||
}, %composer, 0) | ||
NonComposable { | ||
%composer.startReplaceGroup(<>) | ||
sourceInformation(%composer, "<Text("...>") | ||
if (!test) { | ||
Text("Say", %composer, 0b0110) | ||
%composer.endReplaceGroup() | ||
return@NonComposable | ||
} | ||
%composer.endReplaceGroup() | ||
Text("Hello", %composer, 0b0110) | ||
} | ||
if (isTraceInProgress()) { | ||
traceEventEnd() | ||
} | ||
} else { | ||
%composer.skipToGroupEnd() | ||
} | ||
%composer.endRestartGroup()?.updateScope { %composer: Composer?, %force: Int -> | ||
Test(test, %composer, updateChangedFlags(%changed or 0b0001)) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...ugins.kotlin.ControlFlowTransformTests/testConditionalReturnFromInline[useFir = true].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,76 @@ | ||
// | ||
// Source | ||
// ------------------------------------------ | ||
|
||
import androidx.compose.runtime.* | ||
|
||
@Composable fun Test(test: Boolean) { | ||
Column { | ||
if (!test) { | ||
Text("Say") | ||
return@Column | ||
} | ||
Text("Hello") | ||
} | ||
|
||
NonComposable { | ||
if (!test) { | ||
Text("Say") | ||
return@NonComposable | ||
} | ||
Text("Hello") | ||
} | ||
} | ||
|
||
// | ||
// Transformed IR | ||
// ------------------------------------------ | ||
|
||
@Composable | ||
fun Test(test: Boolean, %composer: Composer?, %changed: Int) { | ||
%composer = %composer.startRestartGroup(<>) | ||
sourceInformation(%composer, "C(Test)<Column>,*<Text("...>:Test.kt") | ||
val %dirty = %changed | ||
if (%changed and 0b0110 == 0) { | ||
%dirty = %dirty or if (%composer.changed(test)) 0b0100 else 0b0010 | ||
} | ||
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) { | ||
if (isTraceInProgress()) { | ||
traceEventStart(<>, %dirty, -1, <>) | ||
} | ||
Column({ %composer: Composer?, %changed: Int -> | ||
%composer.startReplaceGroup(<>) | ||
sourceInformation(%composer, "C<Text("...>:Test.kt") | ||
%composer.startReplaceGroup(<>) | ||
sourceInformation(%composer, "<Text("...>") | ||
if (!test) { | ||
Text("Say", %composer, 0b0110) | ||
%composer.endReplaceGroup() | ||
%composer.endReplaceGroup() | ||
return@Column | ||
} | ||
%composer.endReplaceGroup() | ||
Text("Hello", %composer, 0b0110) | ||
%composer.endReplaceGroup() | ||
}, %composer, 0) | ||
NonComposable { | ||
%composer.startReplaceGroup(<>) | ||
sourceInformation(%composer, "<Text("...>") | ||
if (!test) { | ||
Text("Say", %composer, 0b0110) | ||
%composer.endReplaceGroup() | ||
return@NonComposable | ||
} | ||
%composer.endReplaceGroup() | ||
Text("Hello", %composer, 0b0110) | ||
} | ||
if (isTraceInProgress()) { | ||
traceEventEnd() | ||
} | ||
} else { | ||
%composer.skipToGroupEnd() | ||
} | ||
%composer.endRestartGroup()?.updateScope { %composer: Composer?, %force: Int -> | ||
Test(test, %composer, updateChangedFlags(%changed or 0b0001)) | ||
} | ||
} |
Oops, something went wrong.