Skip to content

Commit 9fcd247

Browse files
ShikaSDSpace Cloud
authored and
Space Cloud
committed
Move source information of default parameters to the default group
1 parent 4bad11d commit 9fcd247

File tree

12 files changed

+79
-63
lines changed

12 files changed

+79
-63
lines changed

Diff for: plugins/compose/compiler-hosted/integration-tests/src/jvmTest/resources/golden/androidx.compose.compiler.plugins.kotlin.FunctionBodySkippingTransformTests/testComposableParameter[useFir = false].txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fun Example(a: Int = 0, b: Int = makeInt(), c: Int = 0) {
2121
@Composable
2222
fun Example(a: Int, b: Int, c: Int, %composer: Composer?, %changed: Int, %default: Int) {
2323
%composer = %composer.startRestartGroup(<>)
24-
sourceInformation(%composer, "C(Example)<makeIn...>:Test.kt")
24+
sourceInformation(%composer, "C(Example):Test.kt")
2525
val %dirty = %changed
2626
if (%default and 0b0001 != 0) {
2727
%dirty = %dirty or 0b0110
@@ -38,6 +38,7 @@ fun Example(a: Int, b: Int, c: Int, %composer: Composer?, %changed: Int, %defaul
3838
}
3939
if (%dirty and 0b10010011 != 0b10010010 || !%composer.skipping) {
4040
%composer.startDefaults()
41+
sourceInformation(%composer, "<makeIn...>")
4142
if (%changed and 0b0001 == 0 || %composer.defaultsInvalid) {
4243
if (%default and 0b0001 != 0) {
4344
a = 0

Diff for: plugins/compose/compiler-hosted/integration-tests/src/jvmTest/resources/golden/androidx.compose.compiler.plugins.kotlin.FunctionBodySkippingTransformTests/testComposableParameter[useFir = true].txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fun Example(a: Int = 0, b: Int = makeInt(), c: Int = 0) {
2121
@Composable
2222
fun Example(a: Int, b: Int, c: Int, %composer: Composer?, %changed: Int, %default: Int) {
2323
%composer = %composer.startRestartGroup(<>)
24-
sourceInformation(%composer, "C(Example)<makeIn...>:Test.kt")
24+
sourceInformation(%composer, "C(Example):Test.kt")
2525
val %dirty = %changed
2626
if (%default and 0b0001 != 0) {
2727
%dirty = %dirty or 0b0110
@@ -38,6 +38,7 @@ fun Example(a: Int, b: Int, c: Int, %composer: Composer?, %changed: Int, %defaul
3838
}
3939
if (%dirty and 0b10010011 != 0b10010010 || !%composer.skipping) {
4040
%composer.startDefaults()
41+
sourceInformation(%composer, "<makeIn...>")
4142
if (%changed and 0b0001 == 0 || %composer.defaultsInvalid) {
4243
if (%default and 0b0001 != 0) {
4344
a = 0

Diff for: plugins/compose/compiler-hosted/integration-tests/src/jvmTest/resources/golden/androidx.compose.compiler.plugins.kotlin.FunctionBodySkippingTransformTests/testSingleStableParamWithComposableDefault[useFir = false].txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ fun Test(x: Int = I()) {
1919
@Composable
2020
fun Test(x: Int, %composer: Composer?, %changed: Int, %default: Int) {
2121
%composer = %composer.startRestartGroup(<>)
22-
sourceInformation(%composer, "C(Test)<I()>,<A(x)>:Test.kt")
22+
sourceInformation(%composer, "C(Test)<A(x)>:Test.kt")
2323
val %dirty = %changed
2424
if (%changed and 0b0110 == 0) {
2525
%dirty = %dirty or if (%default and 0b0001 == 0 && %composer.changed(x)) 0b0100 else 0b0010
2626
}
2727
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
2828
%composer.startDefaults()
29+
sourceInformation(%composer, "<I()>")
2930
if (%changed and 0b0001 == 0 || %composer.defaultsInvalid) {
3031
if (%default and 0b0001 != 0) {
3132
x = I(%composer, 0)

Diff for: plugins/compose/compiler-hosted/integration-tests/src/jvmTest/resources/golden/androidx.compose.compiler.plugins.kotlin.FunctionBodySkippingTransformTests/testSingleStableParamWithComposableDefault[useFir = true].txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ fun Test(x: Int = I()) {
1919
@Composable
2020
fun Test(x: Int, %composer: Composer?, %changed: Int, %default: Int) {
2121
%composer = %composer.startRestartGroup(<>)
22-
sourceInformation(%composer, "C(Test)<I()>,<A(x)>:Test.kt")
22+
sourceInformation(%composer, "C(Test)<A(x)>:Test.kt")
2323
val %dirty = %changed
2424
if (%changed and 0b0110 == 0) {
2525
%dirty = %dirty or if (%default and 0b0001 == 0 && %composer.changed(x)) 0b0100 else 0b0010
2626
}
2727
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
2828
%composer.startDefaults()
29+
sourceInformation(%composer, "<I()>")
2930
if (%changed and 0b0001 == 0 || %composer.defaultsInvalid) {
3031
if (%default and 0b0001 != 0) {
3132
x = I(%composer, 0)

Diff for: plugins/compose/compiler-hosted/integration-tests/src/jvmTest/resources/golden/androidx.compose.compiler.plugins.kotlin.FunctionBodySkippingTransformTests/testStaticAndNonStaticDefaultValueSkipping[useFir = false].txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fun Example(
2323
@Composable
2424
fun Example(wontChange: Int, mightChange: Int, %composer: Composer?, %changed: Int, %default: Int) {
2525
%composer = %composer.startRestartGroup(<>)
26-
sourceInformation(%composer, "C(Example)P(1)<curren...>,<A(wont...>,<A(migh...>:Test.kt")
26+
sourceInformation(%composer, "C(Example)P(1)<A(wont...>,<A(migh...>:Test.kt")
2727
val %dirty = %changed
2828
if (%default and 0b0001 != 0) {
2929
%dirty = %dirty or 0b0110
@@ -35,6 +35,7 @@ fun Example(wontChange: Int, mightChange: Int, %composer: Composer?, %changed: I
3535
}
3636
if (%dirty and 0b00010011 != 0b00010010 || !%composer.skipping) {
3737
%composer.startDefaults()
38+
sourceInformation(%composer, "<curren...>")
3839
if (%changed and 0b0001 == 0 || %composer.defaultsInvalid) {
3940
if (%default and 0b0001 != 0) {
4041
wontChange = 123

Diff for: plugins/compose/compiler-hosted/integration-tests/src/jvmTest/resources/golden/androidx.compose.compiler.plugins.kotlin.FunctionBodySkippingTransformTests/testStaticAndNonStaticDefaultValueSkipping[useFir = true].txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fun Example(
2323
@Composable
2424
fun Example(wontChange: Int, mightChange: Int, %composer: Composer?, %changed: Int, %default: Int) {
2525
%composer = %composer.startRestartGroup(<>)
26-
sourceInformation(%composer, "C(Example)P(1)<curren...>,<A(wont...>,<A(migh...>:Test.kt")
26+
sourceInformation(%composer, "C(Example)P(1)<A(wont...>,<A(migh...>:Test.kt")
2727
val %dirty = %changed
2828
if (%default and 0b0001 != 0) {
2929
%dirty = %dirty or 0b0110
@@ -35,6 +35,7 @@ fun Example(wontChange: Int, mightChange: Int, %composer: Composer?, %changed: I
3535
}
3636
if (%dirty and 0b00010011 != 0b00010010 || !%composer.skipping) {
3737
%composer.startDefaults()
38+
sourceInformation(%composer, "<curren...>")
3839
if (%changed and 0b0001 == 0 || %composer.defaultsInvalid) {
3940
if (%default and 0b0001 != 0) {
4041
wontChange = 123

Diff for: plugins/compose/compiler-hosted/integration-tests/src/jvmTest/resources/golden/androidx.compose.compiler.plugins.kotlin.RememberIntrinsicTransformTests/testIntrinsicRememberOfDefaultParameters_AfterComposable[useFir = false].txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fun Test(a: Int = remember { 0 }, b: Int = SomeComposable(), c: Int = remember {
2020
@Composable
2121
fun Test(a: Int, b: Int, c: Int, %composer: Composer?, %changed: Int, %default: Int) {
2222
%composer = %composer.startRestartGroup(<>)
23-
sourceInformation(%composer, "C(Test)<rememb...>,<SomeCo...>,<rememb...>:Test.kt")
23+
sourceInformation(%composer, "C(Test):Test.kt")
2424
val %dirty = %changed
2525
if (%default and 0b0001 != 0) {
2626
%dirty = %dirty or 0b0110
@@ -37,6 +37,7 @@ fun Test(a: Int, b: Int, c: Int, %composer: Composer?, %changed: Int, %default:
3737
}
3838
if (%dirty and 0b10010011 != 0b10010010 || !%composer.skipping) {
3939
%composer.startDefaults()
40+
sourceInformation(%composer, "<rememb...>,<SomeCo...>,<rememb...>")
4041
if (%changed and 0b0001 == 0 || %composer.defaultsInvalid) {
4142
if (%default and 0b0001 != 0) {
4243
a = <block>{

Diff for: plugins/compose/compiler-hosted/integration-tests/src/jvmTest/resources/golden/androidx.compose.compiler.plugins.kotlin.RememberIntrinsicTransformTests/testIntrinsicRememberOfDefaultParameters_AfterComposable[useFir = true].txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fun Test(a: Int = remember { 0 }, b: Int = SomeComposable(), c: Int = remember {
2020
@Composable
2121
fun Test(a: Int, b: Int, c: Int, %composer: Composer?, %changed: Int, %default: Int) {
2222
%composer = %composer.startRestartGroup(<>)
23-
sourceInformation(%composer, "C(Test)<rememb...>,<SomeCo...>,<rememb...>:Test.kt")
23+
sourceInformation(%composer, "C(Test):Test.kt")
2424
val %dirty = %changed
2525
if (%default and 0b0001 != 0) {
2626
%dirty = %dirty or 0b0110
@@ -37,6 +37,7 @@ fun Test(a: Int, b: Int, c: Int, %composer: Composer?, %changed: Int, %default:
3737
}
3838
if (%dirty and 0b10010011 != 0b10010010 || !%composer.skipping) {
3939
%composer.startDefaults()
40+
sourceInformation(%composer, "<rememb...>,<SomeCo...>,<rememb...>")
4041
if (%changed and 0b0001 == 0 || %composer.defaultsInvalid) {
4142
if (%default and 0b0001 != 0) {
4243
a = <block>{

Diff for: plugins/compose/compiler-hosted/integration-tests/src/jvmTest/resources/golden/androidx.compose.compiler.plugins.kotlin.RememberIntrinsicTransformTestsStrongSkipping/testRememberWithDefaultParams[useFir = false].txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import androidx.compose.runtime.*
1818
@Composable
1919
fun Icon(param: Int, defaultParam: Int, %composer: Composer?, %changed: Int, %default: Int) {
2020
%composer = %composer.startRestartGroup(<>)
21-
sourceInformation(%composer, "C(Icon)P(1)<curren...>,<rememb...>:Test.kt")
21+
sourceInformation(%composer, "C(Icon)P(1)<rememb...>:Test.kt")
2222
val %dirty = %changed
2323
if (%default and 0b0001 != 0) {
2424
%dirty = %dirty or 0b0110
@@ -30,6 +30,7 @@ fun Icon(param: Int, defaultParam: Int, %composer: Composer?, %changed: Int, %de
3030
}
3131
if (%dirty and 0b00010011 != 0b00010010 || !%composer.skipping) {
3232
%composer.startDefaults()
33+
sourceInformation(%composer, "<curren...>")
3334
if (%changed and 0b0001 == 0 || %composer.defaultsInvalid) {
3435
if (%default and 0b0010 != 0) {
3536
defaultParam = LocalColor.<get-current>(%composer, 0b0110)

Diff for: plugins/compose/compiler-hosted/integration-tests/src/jvmTest/resources/golden/androidx.compose.compiler.plugins.kotlin.RememberIntrinsicTransformTestsStrongSkipping/testRememberWithDefaultParams[useFir = true].txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import androidx.compose.runtime.*
1818
@Composable
1919
fun Icon(param: Int, defaultParam: Int, %composer: Composer?, %changed: Int, %default: Int) {
2020
%composer = %composer.startRestartGroup(<>)
21-
sourceInformation(%composer, "C(Icon)P(1)<curren...>,<rememb...>:Test.kt")
21+
sourceInformation(%composer, "C(Icon)P(1)<rememb...>:Test.kt")
2222
val %dirty = %changed
2323
if (%default and 0b0001 != 0) {
2424
%dirty = %dirty or 0b0110
@@ -30,6 +30,7 @@ fun Icon(param: Int, defaultParam: Int, %composer: Composer?, %changed: Int, %de
3030
}
3131
if (%dirty and 0b00010011 != 0b00010010 || !%composer.skipping) {
3232
%composer.startDefaults()
33+
sourceInformation(%composer, "<curren...>")
3334
if (%changed and 0b0001 == 0 || %composer.defaultsInvalid) {
3435
if (%default and 0b0010 != 0) {
3536
defaultParam = LocalColor.<get-current>(%composer, 0b0110)

Diff for: plugins/compose/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableFunctionBodyTransformer.kt

+52-50
Original file line numberDiff line numberDiff line change
@@ -1299,54 +1299,53 @@ class ComposableFunctionBodyTransformer(
12991299

13001300
val setDefaults = mutableStatementContainer()
13011301
val skipDefaults = mutableStatementContainer()
1302-
// val parametersScope = Scope.ParametersScope()
1303-
parameters.fastForEachIndexed { slotIndex, param ->
1304-
val defaultIndex = scope.defaultIndexForSlotIndex(slotIndex)
1305-
val defaultValue = param.defaultValue?.expression
1306-
if (defaultParam != null && defaultValue != null) {
1307-
// val transformedDefault = inScope(parametersScope) {
1308-
// defaultValue.expression.transform(this, null)
1309-
// }
1310-
1311-
// we want to call this on the transformed version.
1312-
defaultExprIsStatic[slotIndex] = defaultValue.isStatic()
1313-
defaultExpr[slotIndex] = defaultValue
1314-
val hasStaticDefaultExpr = defaultExprIsStatic[slotIndex]
1315-
when {
1316-
isSkippableDeclaration && !hasStaticDefaultExpr &&
1317-
dirty is IrChangedBitMaskVariable -> {
1318-
// If we are setting the parameter to the default expression and
1319-
// running the default expression again, and the expression isn't
1320-
// provably static, we can't be certain that the dirty value of
1321-
// SAME is going to be valid. We must mark it as UNCERTAIN. In order
1322-
// to avoid slot-table misalignment issues, we must mark it as
1323-
// UNCERTAIN even when we skip the defaults, so that any child
1324-
// function receives UNCERTAIN vs SAME/DIFFERENT deterministically.
1325-
setDefaults.statements.add(
1326-
irIf(
1327-
condition = irGetBit(defaultParam, defaultIndex),
1328-
body = irBlock(
1329-
statements = listOf(
1330-
irSet(param, defaultValue),
1331-
dirty.irSetSlotUncertain(slotIndex)
1302+
1303+
withScope(defaultScope) {
1304+
parameters.fastForEachIndexed { slotIndex, param ->
1305+
val defaultIndex = scope.defaultIndexForSlotIndex(slotIndex)
1306+
val defaultValue = param.defaultValue?.expression
1307+
if (defaultParam != null && defaultValue != null) {
1308+
1309+
// we want to call this on the transformed version.
1310+
defaultExprIsStatic[slotIndex] = defaultValue.isStatic()
1311+
defaultExpr[slotIndex] = defaultValue
1312+
val hasStaticDefaultExpr = defaultExprIsStatic[slotIndex]
1313+
when {
1314+
isSkippableDeclaration && !hasStaticDefaultExpr &&
1315+
dirty is IrChangedBitMaskVariable -> {
1316+
// If we are setting the parameter to the default expression and
1317+
// running the default expression again, and the expression isn't
1318+
// provably static, we can't be certain that the dirty value of
1319+
// SAME is going to be valid. We must mark it as UNCERTAIN. In order
1320+
// to avoid slot-table misalignment issues, we must mark it as
1321+
// UNCERTAIN even when we skip the defaults, so that any child
1322+
// function receives UNCERTAIN vs SAME/DIFFERENT deterministically.
1323+
setDefaults.statements.add(
1324+
irIf(
1325+
condition = irGetBit(defaultParam, defaultIndex),
1326+
body = irBlock(
1327+
statements = listOf(
1328+
irSet(param, defaultValue),
1329+
dirty.irSetSlotUncertain(slotIndex)
1330+
)
13321331
)
13331332
)
13341333
)
1335-
)
1336-
skipDefaults.statements.add(
1337-
irIf(
1338-
condition = irGetBit(defaultParam, defaultIndex),
1339-
body = dirty.irSetSlotUncertain(slotIndex)
1334+
skipDefaults.statements.add(
1335+
irIf(
1336+
condition = irGetBit(defaultParam, defaultIndex),
1337+
body = dirty.irSetSlotUncertain(slotIndex)
1338+
)
13401339
)
1341-
)
1342-
}
1343-
else -> {
1344-
setDefaults.statements.add(
1345-
irIf(
1346-
condition = irGetBit(defaultParam, defaultIndex),
1347-
body = irSet(param, defaultValue)
1340+
}
1341+
else -> {
1342+
setDefaults.statements.add(
1343+
irIf(
1344+
condition = irGetBit(defaultParam, defaultIndex),
1345+
body = irSet(param, defaultValue)
1346+
)
13481347
)
1349-
)
1348+
}
13501349
}
13511350
}
13521351
}
@@ -1565,7 +1564,7 @@ class ComposableFunctionBodyTransformer(
15651564
// otherwise, we wrap the whole thing in an if expression with a skip
15661565
scope.hasDefaultsGroup = true
15671566
scope.metrics.recordGroup()
1568-
bodyPreamble.statements.add(irStartDefaults(sourceElement))
1567+
bodyPreamble.statements.add(irStartDefaults(sourceElement, defaultScope))
15691568
bodyPreamble.statements.add(
15701569
irIfThenElse(
15711570
// this prevents us from re-executing the defaults if this function is getting
@@ -2086,12 +2085,15 @@ class ComposableFunctionBodyTransformer(
20862085
irIfTraceInProgress(irCall(it))
20872086
}
20882087

2089-
private fun irStartDefaults(element: IrElement): IrExpression {
2090-
return irMethodCall(
2091-
irCurrentComposer(),
2092-
startDefaultsFunction,
2093-
element.startOffset,
2094-
element.endOffset
2088+
private fun irStartDefaults(element: IrElement, scope: Scope.BlockScope): IrExpression {
2089+
return irWithSourceInformation(
2090+
irMethodCall(
2091+
irCurrentComposer(),
2092+
startDefaultsFunction,
2093+
element.startOffset,
2094+
element.endOffset
2095+
),
2096+
scope
20952097
)
20962098
}
20972099

Diff for: plugins/compose/compiler-hosted/testData/codegen/nestedLambda.ir.txt

+7-3
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ MODULE_FRAGMENT
237237
key: CONST Int type=kotlin.Int value=-435887556
238238
CALL 'public final fun sourceInformation (composer: androidx.compose.runtime.Composer, sourceInformation: kotlin.String): kotlin.Unit declared in androidx.compose.runtime' type=kotlin.Unit origin=null
239239
composer: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.DynamicThemePrimaryColorsFromImage' type=androidx.compose.runtime.Composer? origin=null
240-
sourceInformation: CONST String type=kotlin.String value="C(DynamicThemePrimaryColorsFromImage)P(1)21@595L28:main.kt#1wrmn"
240+
sourceInformation: CONST String type=kotlin.String value="C(DynamicThemePrimaryColorsFromImage)P(1):main.kt#1wrmn"
241241
VAR name:$dirty type:kotlin.Int [val]
242242
GET_VAR '$changed: kotlin.Int declared in home.DynamicThemePrimaryColorsFromImage' type=kotlin.Int origin=null
243243
WHEN type=kotlin.Unit origin=IF
@@ -257,8 +257,12 @@ MODULE_FRAGMENT
257257
$this: CALL 'public abstract fun <get-skipping> (): kotlin.Boolean declared in androidx.compose.runtime.Composer' type=kotlin.Boolean origin=null
258258
$this: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.DynamicThemePrimaryColorsFromImage' type=androidx.compose.runtime.Composer? origin=null
259259
then: BLOCK type=kotlin.Unit origin=null
260-
CALL 'public abstract fun startDefaults (): kotlin.Unit declared in androidx.compose.runtime.Composer' type=kotlin.Unit origin=null
261-
$this: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.DynamicThemePrimaryColorsFromImage' type=androidx.compose.runtime.Composer? origin=null
260+
BLOCK type=kotlin.Unit origin=null
261+
CALL 'public abstract fun startDefaults (): kotlin.Unit declared in androidx.compose.runtime.Composer' type=kotlin.Unit origin=null
262+
$this: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.DynamicThemePrimaryColorsFromImage' type=androidx.compose.runtime.Composer? origin=null
263+
CALL 'public final fun sourceInformation (composer: androidx.compose.runtime.Composer, sourceInformation: kotlin.String): kotlin.Unit declared in androidx.compose.runtime' type=kotlin.Unit origin=null
264+
composer: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.DynamicThemePrimaryColorsFromImage' type=androidx.compose.runtime.Composer? origin=null
265+
sourceInformation: CONST String type=kotlin.String value="21@595L28"
262266
WHEN type=kotlin.Unit origin=IF
263267
BRANCH
264268
if: WHEN type=kotlin.Boolean origin=OROR

0 commit comments

Comments
 (0)