Skip to content

Commit

Permalink
Resolve Fir2IrLazyProperty before creating backing field
Browse files Browse the repository at this point in the history
The Compose compiler plugin IR lowering transformers (a part of
IrGenerationExtension) access IrProperty. When the IrProperty is
Fir2IrLazyProperty, the access to Fir2IrLazyProperty creates its
backing field. Without the lazy resolution of the property, it has
an exception. This commit conducts the lazy resolution to avoid
the exception.

^KT-67972
  • Loading branch information
jaebaek authored and Space Cloud committed Jun 19, 2024
1 parent f01f61c commit 5d59755
Show file tree
Hide file tree
Showing 13 changed files with 878 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class Fir2IrLazyProperty(
}
}
fir.delegate != null -> {
fir.lazyResolveToPhase(FirResolvePhase.BODY_RESOLVE)
callablesGenerator.createBackingField(
this@Fir2IrLazyProperty,
fir,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
MODULE_FRAGMENT
FILE fqName:home fileName:main.kt
FUN name:Home visibility:public modality:FINAL <> ($composer:androidx.compose.runtime.Composer?, $changed:kotlin.Int) returnType:kotlin.Unit
annotations:
Composable
VALUE_PARAMETER name:$composer index:0 type:androidx.compose.runtime.Composer? [assignable]
VALUE_PARAMETER name:$changed index:1 type:kotlin.Int
BLOCK_BODY
BLOCK type=kotlin.Unit origin=null
SET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home' type=kotlin.Unit origin=null
CALL 'public abstract fun startRestartGroup (key: kotlin.Int): androidx.compose.runtime.Composer declared in androidx.compose.runtime.Composer' type=androidx.compose.runtime.Composer origin=null
$this: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home' type=androidx.compose.runtime.Composer? origin=null
key: CONST Int type=kotlin.Int value=289538687
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
composer: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home' type=androidx.compose.runtime.Composer? origin=null
sourceInformation: CONST String type=kotlin.String value="C(Home)57@262L139:main.kt#1wrmn"
WHEN type=kotlin.Unit origin=IF
BRANCH
if: WHEN type=kotlin.Boolean origin=OROR
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=null
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=null
arg0: GET_VAR '$changed: kotlin.Int declared in home.Home' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=0
then: CONST Boolean type=kotlin.Boolean value=true
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=null
$this: CALL 'public abstract fun <get-skipping> (): kotlin.Boolean declared in androidx.compose.runtime.Composer' type=kotlin.Boolean origin=null
$this: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home' type=androidx.compose.runtime.Composer? origin=null
then: BLOCK type=kotlin.Unit origin=null
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun isTraceInProgress (): kotlin.Boolean declared in androidx.compose.runtime' type=kotlin.Boolean origin=null
then: CALL 'public final fun traceEventStart (key: kotlin.Int, dirty1: kotlin.Int, dirty2: kotlin.Int, info: kotlin.String): kotlin.Unit declared in androidx.compose.runtime' type=kotlin.Unit origin=null
key: CONST Int type=kotlin.Int value=289538687
dirty1: GET_VAR '$changed: kotlin.Int declared in home.Home' type=kotlin.Int origin=null
dirty2: CONST Int type=kotlin.Int value=-1
info: CONST String type=kotlin.String value="home.Home (main.kt:56)"
CALL 'public final fun Column (content: @[ExtensionFunctionType] kotlin.Function3<compose.ui.ColumnScope, androidx.compose.runtime.Composer, kotlin.Int, kotlin.Unit>, $composer: androidx.compose.runtime.Composer?, $changed: kotlin.Int): kotlin.Unit [inline] declared in compose.ui' type=kotlin.Unit origin=null
content: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function3<compose.ui.ColumnScope, androidx.compose.runtime.Composer, kotlin.Int, kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> ($receiver:compose.ui.ColumnScope, $composer:androidx.compose.runtime.Composer?, $changed:kotlin.Int) returnType:kotlin.Unit
annotations:
Composable
$receiver: VALUE_PARAMETER name:$this$Column type:compose.ui.ColumnScope
VALUE_PARAMETER name:$composer index:0 type:androidx.compose.runtime.Composer? [assignable]
VALUE_PARAMETER name:$changed index:1 type:kotlin.Int
BLOCK_BODY
BLOCK type=kotlin.Unit origin=null
CALL 'public final fun sourceInformationMarkerStart (composer: androidx.compose.runtime.Composer, key: kotlin.Int, sourceInformation: kotlin.String): kotlin.Unit declared in androidx.compose.runtime' type=kotlin.Unit origin=null
composer: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home.<anonymous>' type=androidx.compose.runtime.Composer? origin=null
key: CONST Int type=kotlin.Int value=735130274
sourceInformation: CONST String type=kotlin.String value="C58@304L28,59@341L54:main.kt#1wrmn"
COMPOSITE type=kotlin.Unit origin=null
VAR name:dominantColorState type:util.DominantColorState [val]
CALL 'public final fun rememberDominantColorState (defaultColor: compose.ui.Color?, $composer: androidx.compose.runtime.Composer?, $changed: kotlin.Int, $default: kotlin.Int): util.DominantColorState declared in util.DominantColorStateKt' type=util.DominantColorState origin=null
defaultColor: COMPOSITE type=kotlin.Nothing? origin=DEFAULT_VALUE
CONST Null type=kotlin.Nothing? value=null
$composer: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home.<anonymous>' type=androidx.compose.runtime.Composer? origin=null
$changed: CONST Int type=kotlin.Int value=0
$default: CONST Int type=kotlin.Int value=1
CALL 'public final fun DynamicThemePrimaryColorsFromImage (dominantColorState: util.DominantColorState?, $composer: androidx.compose.runtime.Composer?, $changed: kotlin.Int, $default: kotlin.Int): kotlin.Unit declared in util.DominantColorStateKt' type=kotlin.Unit origin=null
dominantColorState: GET_VAR 'val dominantColorState: util.DominantColorState [val] declared in home.Home.<anonymous>' type=util.DominantColorState origin=null
$composer: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home.<anonymous>' type=androidx.compose.runtime.Composer? origin=null
$changed: CONST Int type=kotlin.Int value=0
$default: CONST Int type=kotlin.Int value=0
CALL 'public final fun sourceInformationMarkerEnd (composer: androidx.compose.runtime.Composer): kotlin.Unit declared in androidx.compose.runtime' type=kotlin.Unit origin=null
composer: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home.<anonymous>' type=androidx.compose.runtime.Composer? origin=null
$composer: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home' type=androidx.compose.runtime.Composer? origin=null
$changed: CONST Int type=kotlin.Int value=0
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun isTraceInProgress (): kotlin.Boolean declared in androidx.compose.runtime' type=kotlin.Boolean origin=null
then: CALL 'public final fun traceEventEnd (): kotlin.Unit declared in androidx.compose.runtime' type=kotlin.Unit origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public abstract fun skipToGroupEnd (): kotlin.Unit declared in androidx.compose.runtime.Composer' type=kotlin.Unit origin=null
$this: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home' type=androidx.compose.runtime.Composer? origin=null
BLOCK type=kotlin.Unit origin=null
BLOCK type=kotlin.Unit origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:androidx.compose.runtime.ScopeUpdateScope? [val]
CALL 'public abstract fun endRestartGroup (): androidx.compose.runtime.ScopeUpdateScope? declared in androidx.compose.runtime.Composer' type=androidx.compose.runtime.ScopeUpdateScope? origin=null
$this: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home' type=androidx.compose.runtime.Composer? origin=null
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=null
arg0: GET_VAR 'val tmp_0: androidx.compose.runtime.ScopeUpdateScope? [val] declared in home.Home' type=androidx.compose.runtime.ScopeUpdateScope? origin=null
arg1: CONST Null type=kotlin.Any? value=null
then: CONST Null type=kotlin.Any? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public abstract fun updateScope (block: kotlin.Function2<androidx.compose.runtime.Composer, kotlin.Int, kotlin.Unit>): kotlin.Unit declared in androidx.compose.runtime.ScopeUpdateScope' type=kotlin.Unit origin=null
$this: GET_VAR 'val tmp_0: androidx.compose.runtime.ScopeUpdateScope? [val] declared in home.Home' type=androidx.compose.runtime.ScopeUpdateScope? origin=null
block: FUN_EXPR type=kotlin.Function2<androidx.compose.runtime.Composer?, kotlin.Int, kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> ($composer:androidx.compose.runtime.Composer?, $force:kotlin.Int) returnType:kotlin.Unit
VALUE_PARAMETER name:$composer index:0 type:androidx.compose.runtime.Composer?
VALUE_PARAMETER name:$force index:1 type:kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> ($composer: androidx.compose.runtime.Composer?, $force: kotlin.Int): kotlin.Unit declared in home.Home'
CALL 'public final fun Home ($composer: androidx.compose.runtime.Composer?, $changed: kotlin.Int): kotlin.Unit declared in home' type=kotlin.Unit origin=null
$composer: GET_VAR '$composer: androidx.compose.runtime.Composer? declared in home.Home.<anonymous>' type=androidx.compose.runtime.Composer? origin=null
$changed: CALL 'internal final fun updateChangedFlags (flags: kotlin.Int): kotlin.Int declared in androidx.compose.runtime' type=kotlin.Int origin=null
flags: CALL 'public final fun or (other: kotlin.Int): kotlin.Int [infix] declared in kotlin.Int' type=kotlin.Int origin=null
$this: GET_VAR '$changed: kotlin.Int declared in home.Home' type=kotlin.Int origin=null
other: CONST Int type=kotlin.Int value=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// DUMP_IR

// MODULE: lib
// MODULE_KIND: LibraryBinary
// FILE: compose/ui/foo.kt
package compose.ui

import androidx.compose.runtime.Composable

class Color(val r: Int, val g: Int, val b:Int)

interface ColumnScope {
}

@Composable
inline fun Column(content: @Composable ColumnScope.() -> Unit) {
}

// MODULE: main(lib)
// FILE: util/DominantColorState.kt
package util

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import compose.ui.Color

@Composable
fun rememberDominantColorState(defaultColor: Color = Color(0, 0, 0)): DominantColorState = remember {
DominantColorState(defaultColor)
}

@Composable
fun DynamicThemePrimaryColorsFromImage(
dominantColorState: DominantColorState = rememberDominantColorState()
) {
}

@Stable
class DominantColorState(private val defaultColor: Color) {
var color by mutableStateOf(defaultColor)
private set
}

// FILE: main.kt
package home

import androidx.compose.runtime.Composable
import compose.ui.Column
import util.DynamicThemePrimaryColorsFromImage
import util.rememberDominantColorState

@Composable
fun Home() {
Column {
val dominantColorState = rememberDominantColorState()
DynamicThemePrimaryColorsFromImage(dominantColorState)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public final class home/MainKt {
// source: 'main.kt'
private final static method Home$lambda$1(p0: int, p1: androidx.compose.runtime.Composer, p2: int): kotlin.Unit
public final static method Home(p0: androidx.compose.runtime.Composer, p1: int): void
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ MODULE_FRAGMENT
key: CONST Int type=kotlin.Int value=-1263890955
dirty1: GET_VAR '$changed: kotlin.Int declared in home.ComposableSingletons$MainKt.lambda-1.<anonymous>' type=kotlin.Int origin=null
dirty2: CONST Int type=kotlin.Int value=-1
info: CONST String type=kotlin.String value="home.ComposableSingletons$MainKt.lambda-1.<anonymous> (main.kt:57)"
info: CONST String type=kotlin.String value="home.ComposableSingletons$MainKt.lambda-1.<anonymous> (main.kt:60)"
GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit
WHEN type=kotlin.Unit origin=IF
BRANCH
Expand Down Expand Up @@ -76,7 +76,7 @@ MODULE_FRAGMENT
key: CONST Int type=kotlin.Int value=289538687
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
composer: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home' type=androidx.compose.runtime.Composer? origin=null
sourceInformation: CONST String type=kotlin.String value="C(Home)54@259L151:main.kt#1wrmn"
sourceInformation: CONST String type=kotlin.String value="C(Home)57@262L151:main.kt#1wrmn"
WHEN type=kotlin.Unit origin=IF
BRANCH
if: WHEN type=kotlin.Boolean origin=OROR
Expand All @@ -99,7 +99,7 @@ MODULE_FRAGMENT
key: CONST Int type=kotlin.Int value=289538687
dirty1: GET_VAR '$changed: kotlin.Int declared in home.Home' type=kotlin.Int origin=null
dirty2: CONST Int type=kotlin.Int value=-1
info: CONST String type=kotlin.String value="home.Home (main.kt:53)"
info: CONST String type=kotlin.String value="home.Home (main.kt:56)"
CALL 'public final fun Column (content: @[ExtensionFunctionType] kotlin.Function3<compose.ui.ColumnScope, androidx.compose.runtime.Composer, kotlin.Int, kotlin.Unit>, $composer: androidx.compose.runtime.Composer?, $changed: kotlin.Int): kotlin.Unit [inline] declared in compose.ui' type=kotlin.Unit origin=null
content: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function3<compose.ui.ColumnScope, androidx.compose.runtime.Composer, kotlin.Int, kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> ($receiver:compose.ui.ColumnScope, $composer:androidx.compose.runtime.Composer?, $changed:kotlin.Int) returnType:kotlin.Unit
Expand All @@ -112,8 +112,8 @@ MODULE_FRAGMENT
BLOCK type=kotlin.Unit origin=null
CALL 'public final fun sourceInformationMarkerStart (composer: androidx.compose.runtime.Composer, key: kotlin.Int, sourceInformation: kotlin.String): kotlin.Unit declared in androidx.compose.runtime' type=kotlin.Unit origin=null
composer: GET_VAR '$composer: androidx.compose.runtime.Composer? [assignable] declared in home.Home.<anonymous>' type=androidx.compose.runtime.Composer? origin=null
key: CONST Int type=kotlin.Int value=735127670
sourceInformation: CONST String type=kotlin.String value="C55@301L28,56@338L66:main.kt#1wrmn"
key: CONST Int type=kotlin.Int value=735130646
sourceInformation: CONST String type=kotlin.String value="C58@304L28,59@341L66:main.kt#1wrmn"
COMPOSITE type=kotlin.Unit origin=null
VAR name:dominantColorState type:util.DominantColorState [val]
CALL 'public final fun rememberDominantColorState (defaultOnColor: compose.ui.Color?, $composer: androidx.compose.runtime.Composer?, $changed: kotlin.Int, $default: kotlin.Int): util.DominantColorState declared in util.DominantColorStateKt' type=util.DominantColorState origin=null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ package util
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import compose.ui.Color

@Composable
fun rememberDominantColorState(defaultOnColor: Color = Color(0, 0, 0)): DominantColorState = remember {
DominantColorState(defaultColor)
DominantColorState(defaultOnColor)
}

@Composable
Expand All @@ -39,7 +42,7 @@ fun DynamicThemePrimaryColorsFromImage(

@Stable
class DominantColorState(private val defaultOnColor: Color) {
var color = mutableStateOf(defaultColor)
var color = mutableStateOf(defaultOnColor)
}

// FILE: main.kt
Expand Down
Loading

0 comments on commit 5d59755

Please sign in to comment.