-
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.
Avoid memoizing lambdas with captured delegates
Prevents memoization of internal delegate variables with strong skipping enabled. Fixes: [342557697](https://issuetracker.google.com/342557697) Relnote: Stop memoizing lambdas with captured property delegates.
- Loading branch information
Showing
23 changed files
with
865 additions
and
75 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
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
91 changes: 91 additions & 0 deletions
91
...gins.kotlin.LambdaMemoizationTransformTests/testMemoizingFromDelegate[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,91 @@ | ||
// | ||
// Source | ||
// ------------------------------------------ | ||
|
||
import androidx.compose.runtime.* | ||
|
||
@Composable | ||
fun StrongSkippingIssue( | ||
data: ClassWithData | ||
) { | ||
val state by remember { mutableStateOf("") } | ||
val action by data::action | ||
val action1 by getData()::action | ||
{ | ||
action | ||
} | ||
{ | ||
action1 | ||
} | ||
{ | ||
state | ||
} | ||
} | ||
|
||
// | ||
// Transformed IR | ||
// ------------------------------------------ | ||
|
||
@Composable | ||
fun StrongSkippingIssue(data: ClassWithData, %composer: Composer?, %changed: Int) { | ||
%composer = %composer.startRestartGroup(<>) | ||
sourceInformation(%composer, "C(StrongSkippingIssue)<rememb...>,<{>:Test.kt") | ||
val %dirty = %changed | ||
if (%changed and 0b1110 == 0) { | ||
%dirty = %dirty or if (%composer.changed(data)) 0b0100 else 0b0010 | ||
} | ||
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) { | ||
if (isTraceInProgress()) { | ||
traceEventStart(<>, %dirty, -1, <>) | ||
} | ||
val state by { | ||
val state%delegate = <block>{ | ||
sourceInformationMarkerStart(%composer, <>, "CC(remember):Test.kt#9igjgp") | ||
val tmp0_group = %composer.cache(false) { | ||
mutableStateOf( | ||
value = "" | ||
) | ||
} | ||
sourceInformationMarkerEnd(%composer) | ||
tmp0_group | ||
} | ||
get() { | ||
return state%delegate.getValue(null, ::state%delegate) | ||
} | ||
} | ||
val action by { | ||
val action%delegate = data::action | ||
get() { | ||
return action%delegate.getValue(null, ::action%delegate) | ||
} | ||
} | ||
val action1 by { | ||
val action1%delegate = getData()::action | ||
get() { | ||
return action1%delegate.getValue(null, ::action1%delegate) | ||
} | ||
} | ||
{ | ||
<get-action>() | ||
} | ||
{ | ||
<get-action1>() | ||
} | ||
sourceInformationMarkerStart(%composer, <>, "CC(remember):Test.kt#9igjgp") | ||
val tmp1_group = %composer.cache(false) { | ||
{ | ||
<get-state>() | ||
} | ||
} | ||
sourceInformationMarkerEnd(%composer) | ||
tmp1_group | ||
if (isTraceInProgress()) { | ||
traceEventEnd() | ||
} | ||
} else { | ||
%composer.skipToGroupEnd() | ||
} | ||
%composer.endRestartGroup()?.updateScope { %composer: Composer?, %force: Int -> | ||
StrongSkippingIssue(data, %composer, updateChangedFlags(%changed or 0b0001)) | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...ugins.kotlin.LambdaMemoizationTransformTests/testMemoizingFromDelegate[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,91 @@ | ||
// | ||
// Source | ||
// ------------------------------------------ | ||
|
||
import androidx.compose.runtime.* | ||
|
||
@Composable | ||
fun StrongSkippingIssue( | ||
data: ClassWithData | ||
) { | ||
val state by remember { mutableStateOf("") } | ||
val action by data::action | ||
val action1 by getData()::action | ||
{ | ||
action | ||
} | ||
{ | ||
action1 | ||
} | ||
{ | ||
state | ||
} | ||
} | ||
|
||
// | ||
// Transformed IR | ||
// ------------------------------------------ | ||
|
||
@Composable | ||
fun StrongSkippingIssue(data: ClassWithData, %composer: Composer?, %changed: Int) { | ||
%composer = %composer.startRestartGroup(<>) | ||
sourceInformation(%composer, "C(StrongSkippingIssue)<rememb...>,<{>:Test.kt") | ||
val %dirty = %changed | ||
if (%changed and 0b1110 == 0) { | ||
%dirty = %dirty or if (%composer.changed(data)) 0b0100 else 0b0010 | ||
} | ||
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) { | ||
if (isTraceInProgress()) { | ||
traceEventStart(<>, %dirty, -1, <>) | ||
} | ||
val state by { | ||
val state%delegate = <block>{ | ||
sourceInformationMarkerStart(%composer, <>, "CC(remember):Test.kt#9igjgp") | ||
val tmp0_group = %composer.cache(false) { | ||
mutableStateOf( | ||
value = "" | ||
) | ||
} | ||
sourceInformationMarkerEnd(%composer) | ||
tmp0_group | ||
} | ||
get() { | ||
return state%delegate.getValue(null, ::state%delegate) | ||
} | ||
} | ||
val action by { | ||
val action%delegate = data::action | ||
get() { | ||
return action%delegate.getValue(null, ::action%delegate) | ||
} | ||
} | ||
val action1 by { | ||
val action1%delegate = getData()::action | ||
get() { | ||
return action1%delegate.getValue(null, ::action1%delegate) | ||
} | ||
} | ||
{ | ||
<get-action>() | ||
} | ||
{ | ||
<get-action1>() | ||
} | ||
sourceInformationMarkerStart(%composer, <>, "CC(remember):Test.kt#9igjgp") | ||
val tmp1_group = %composer.cache(false) { | ||
{ | ||
<get-state>() | ||
} | ||
} | ||
sourceInformationMarkerEnd(%composer) | ||
tmp1_group | ||
if (isTraceInProgress()) { | ||
traceEventEnd() | ||
} | ||
} else { | ||
%composer.skipToGroupEnd() | ||
} | ||
%composer.endRestartGroup()?.updateScope { %composer: Composer?, %force: Int -> | ||
StrongSkippingIssue(data, %composer, updateChangedFlags(%changed or 0b0001)) | ||
} | ||
} |
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
Oops, something went wrong.