Skip to content

Commit

Permalink
Ensure that inline body is realized when source information is off
Browse files Browse the repository at this point in the history
aosp/3032485 realized groups inside inline functions only when source information is enabled, which is incorrect.

Test: compiler tests
Fixes: 338179884 ( https://issuetracker.google.com/issues/338179884 )
Change-Id: Idddb882db6bf455032b12cf8a5a0d7d2bac85568 ( https://android-review.googlesource.com/q/Idddb882db6bf455032b12cf8a5a0d7d2bac85568 )

Moved from: androidx/androidx@428fff5
  • Loading branch information
ShikaSD authored and Space Cloud committed May 3, 2024
1 parent 3ee4f2d commit 868d0ac
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1409,4 +1409,27 @@ class FunctionBodySkippingTransformTestsNoSource(
annotation class Type
"""
)

@Test
fun testInlineCallInsideComposableInlineFunction() = verifyGoldenComposeIrTransform(
source = """
import androidx.compose.runtime.*
import androidx.compose.foundation.layout.*
@Composable
fun Test(count: Int) {
Row {
repeat(count) {
Text("A")
}
}
}
""",
extra = """
import androidx.compose.runtime.*
@Composable
fun Text(value: String) {}
"""
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Source
// ------------------------------------------

import androidx.compose.runtime.*
import androidx.compose.foundation.layout.*

@Composable
fun Test(count: Int) {
Row {
repeat(count) {
Text("A")
}
}
}

//
// Transformed IR
// ------------------------------------------

@Composable
@ComposableTarget(applier = "androidx.compose.ui.UiComposable")
fun Test(count: Int, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
val %dirty = %changed
if (%changed and 0b1110 == 0) {
%dirty = %dirty or if (%composer.changed(count)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
Row(null, null, null, { %composer: Composer?, %changed: Int ->
%composer.startReplaceGroup(<>)
repeat(count) { it: Int ->
Text("A", %composer, 0b0110)
}
%composer.endReplaceGroup()
}, %composer, 0, 0b0111)
} else {
%composer.skipToGroupEnd()
}
%composer.endRestartGroup()?.updateScope { %composer: Composer?, %force: Int ->
Test(count, %composer, updateChangedFlags(%changed or 0b0001))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Source
// ------------------------------------------

import androidx.compose.runtime.*
import androidx.compose.foundation.layout.*

@Composable
fun Test(count: Int) {
Row {
repeat(count) {
Text("A")
}
}
}

//
// Transformed IR
// ------------------------------------------

@Composable
@ComposableTarget(applier = "androidx.compose.ui.UiComposable")
fun Test(count: Int, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
val %dirty = %changed
if (%changed and 0b1110 == 0) {
%dirty = %dirty or if (%composer.changed(count)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
Row(null, null, null, { %composer: Composer?, %changed: Int ->
%composer.startReplaceGroup(<>)
repeat(count) { it: Int ->
Text("A", %composer, 0b0110)
}
%composer.endReplaceGroup()
}, %composer, 0, 0b0111)
} else {
%composer.skipToGroupEnd()
}
%composer.endRestartGroup()?.updateScope { %composer: Composer?, %force: Int ->
Test(count, %composer, updateChangedFlags(%changed or 0b0001))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,12 @@ class ComposableFunctionBodyTransformer(
val transformed = nonReturningBody.apply {
transformChildrenVoid()
}.let {
// Ensure that all group children of composable inline lambda are realized, since the inline
// lambda doesn't require a group on its own.
if (scope.isInlinedLambda && scope.isComposable) {
scope.realizeAllDirectChildren()
}

if (isInlineLambda) {
it.asSourceOrEarlyExitGroup(scope)
} else it
Expand Down Expand Up @@ -2501,12 +2507,6 @@ class ComposableFunctionBodyTransformer(
)
}

// Ensure that all group children of composable inline lambda are realized, since the inline
// lambda doesn't require a group on its own.
if (scope.isInlinedLambda && scope.isComposable) {
scope.realizeAllDirectChildren()
}

scope.realizeGroup(makeEnd)
return when {
// if the scope ends with a return call, then it will get properly ended if we
Expand Down

0 comments on commit 868d0ac

Please sign in to comment.