Formatting for ktlint 0.39.0
Mostly automated, partially manual
Bug: 166292916
Test: ./busytown/androidx.sh
This change includes files under ./compose
Change-Id: I55cab72a1029e37fe95c8f031d6abe6ca9925108
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCodegenSignatureTest.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCodegenSignatureTest.kt
index 978d58d1..aacd68b 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCodegenSignatureTest.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCodegenSignatureTest.kt
@@ -79,11 +79,14 @@
val className = "Test_REPLACEME_${uniqueNumber++}"
val fileName = "$className.kt"
- val loader = classLoader("""
+ val loader = classLoader(
+ """
import androidx.compose.runtime.*
$src
- """, fileName, dumpClasses)
+ """,
+ fileName, dumpClasses
+ )
val apiString = loader
.allGeneratedFiles
@@ -190,7 +193,9 @@
$text
- """, dumpClasses)
+ """,
+ dumpClasses
+ )
}
fun codegenNoImports(text: String, dumpClasses: Boolean = false): Unit = ensureSetup {
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCodegenTest.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCodegenTest.kt
index 8509df2..6493d952 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCodegenTest.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCodegenTest.kt
@@ -56,9 +56,11 @@
protected open fun helperFiles(): List<KtFile> = emptyList()
protected fun dumpClasses(loader: GeneratedClassLoader) {
- for (file in loader.allGeneratedFiles.filter {
- it.relativePath.endsWith(".class")
- }) {
+ for (
+ file in loader.allGeneratedFiles.filter {
+ it.relativePath.endsWith(".class")
+ }
+ ) {
println("------\nFILE: ${file.relativePath}\n------")
println(file.asText())
}
@@ -72,7 +74,8 @@
val className = "Test_REPLACEME_${uniqueNumber++}"
val fileName = "$className.kt"
- val loader = classLoader("""
+ val loader = classLoader(
+ """
@file:OptIn(
ExperimentalComposeApi::class,
InternalComposeApi::class,
@@ -83,7 +86,9 @@
import androidx.compose.runtime.*
$src
- """, fileName, dumpClasses)
+ """,
+ fileName, dumpClasses
+ )
val apiString = loader
.allGeneratedFiles
@@ -211,15 +216,15 @@
protected fun testCompileWithViewStubs(source: String, dumpClasses: Boolean = false) =
testCompile(
- """
+ """
$COMPOSE_VIEW_STUBS_IMPORTS
$source
$COMPOSE_VIEW_STUBS
""",
- dumpClasses
- )
+ dumpClasses
+ )
protected fun sourceFile(name: String, source: String): KtFile {
val result =
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCompilerTest.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCompilerTest.kt
index 2b7c8f5..206afdd 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCompilerTest.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractCompilerTest.kt
@@ -55,7 +55,8 @@
override fun setUp() {
// Setup the environment for the analysis
- System.setProperty("user.dir",
+ System.setProperty(
+ "user.dir",
homeDir
)
myEnvironment = createEnvironment()
@@ -112,9 +113,12 @@
}
protected fun createClassLoader(): GeneratedClassLoader {
- val classLoader = URLClassLoader(defaultClassPath.map {
- it.toURI().toURL()
- }.toTypedArray(), null)
+ val classLoader = URLClassLoader(
+ defaultClassPath.map {
+ it.toURI().toURL()
+ }.toTypedArray(),
+ null
+ )
return GeneratedClassLoader(
generateClassesInFile(),
classLoader,
@@ -138,17 +142,19 @@
e.printStackTrace()
System.err.println("Generating instructions as text...")
try {
- System.err.println(classFileFactory?.createText()
- ?: "Cannot generate text: exception was thrown during generation")
+ System.err.println(
+ classFileFactory?.createText()
+ ?: "Cannot generate text: exception was thrown during generation"
+ )
} catch (e1: Throwable) {
System.err.println(
"Exception thrown while trying to generate text, " +
- "the actual exception follows:"
+ "the actual exception follows:"
)
e1.printStackTrace()
System.err.println(
"------------------------------------------------------------------" +
- "-----------"
+ "-----------"
)
}
@@ -215,7 +221,7 @@
override fun toString(): String {
val testName = this@AbstractCompilerTest.getTestName(false)
return this@AbstractCompilerTest.javaClass.name +
- if (StringUtil.isEmpty(testName)) "" else ".test$testName"
+ if (StringUtil.isEmpty(testName)) "" else ".test$testName"
}
}
@@ -233,10 +239,12 @@
}
fun kotlinRuntimeJar(module: String) = File(
- kotlinHome, "$module/$KOTLIN_RUNTIME_VERSION/$module-$KOTLIN_RUNTIME_VERSION.jar")
+ kotlinHome, "$module/$KOTLIN_RUNTIME_VERSION/$module-$KOTLIN_RUNTIME_VERSION.jar"
+ )
init {
- System.setProperty("idea.home",
+ System.setProperty(
+ "idea.home",
homeDir
)
}
@@ -266,31 +274,35 @@
fun newConfiguration(): CompilerConfiguration {
val configuration = CompilerConfiguration()
- configuration.put(CommonConfigurationKeys.MODULE_NAME,
+ configuration.put(
+ CommonConfigurationKeys.MODULE_NAME,
TEST_MODULE_NAME
)
- configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, object : MessageCollector {
- override fun clear() {}
+ configuration.put(
+ CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
+ object : MessageCollector {
+ override fun clear() {}
- override fun report(
- severity: CompilerMessageSeverity,
- message: String,
- location: CompilerMessageSourceLocation?
- ) {
- if (severity === CompilerMessageSeverity.ERROR) {
- val prefix = if (location == null)
- ""
- else
- "(" + location.path + ":" + location.line + ":" + location.column + ") "
- throw AssertionError(prefix + message)
+ override fun report(
+ severity: CompilerMessageSeverity,
+ message: String,
+ location: CompilerMessageSourceLocation?
+ ) {
+ if (severity === CompilerMessageSeverity.ERROR) {
+ val prefix = if (location == null)
+ ""
+ else
+ "(" + location.path + ":" + location.line + ":" + location.column + ") "
+ throw AssertionError(prefix + message)
+ }
+ }
+
+ override fun hasErrors(): Boolean {
+ return false
}
}
-
- override fun hasErrors(): Boolean {
- return false
- }
- })
+ )
return configuration
}
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractComposeDiagnosticsTest.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractComposeDiagnosticsTest.kt
index a6fdb62..510db0d 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractComposeDiagnosticsTest.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractComposeDiagnosticsTest.kt
@@ -72,9 +72,11 @@
}
if (reportedDiagnostic == null) {
val firstRange = reportedDiagnostics.first().textRanges.first()
- message.append(" Error ${diagnostic.name} reported at ${
+ message.append(
+ " Error ${diagnostic.name} reported at ${
firstRange.startOffset
- }-${firstRange.endOffset} but expected at ${range.start}-${range.end}\n")
+ }-${firstRange.endOffset} but expected at ${range.start}-${range.end}\n"
+ )
message.append(
sourceInfo(
clearText,
@@ -87,9 +89,11 @@
found.add(reportedDiagnostic)
}
} else {
- message.append(" Diagnostic ${diagnostic.name} not reported, expected at ${
+ message.append(
+ " Diagnostic ${diagnostic.name} not reported, expected at ${
range.start
- }\n")
+ }\n"
+ )
message.append(
sourceInfo(
clearText,
@@ -108,7 +112,7 @@
val range = diagnostic.textRanges.first()
message.append(
" Unexpected diagnostic ${diagnostic.factoryName} reported at ${
- range.startOffset
+ range.startOffset
}\n"
)
message.append(
@@ -139,11 +143,15 @@
val Diagnostic.factoryName: String
inline get() {
if (factory.name == "PLUGIN_ERROR")
- return (this as
- DiagnosticWithParameters1<*, RenderedDiagnostic<*>>).a.diagnostic.factory.name
+ return (
+ this as
+ DiagnosticWithParameters1<*, RenderedDiagnostic<*>>
+ ).a.diagnostic.factory.name
if (factory.name == "PLUGIN_WARNING")
- return (this as
- DiagnosticWithParameters1<*, RenderedDiagnostic<*>>).a.diagnostic.factory.name
+ return (
+ this as
+ DiagnosticWithParameters1<*, RenderedDiagnostic<*>>
+ ).a.diagnostic.factory.name
return factory.name
}
@@ -162,5 +170,5 @@
val lineEnd = clearText.lineEnd(start)
val displayEnd = if (end > lineEnd) lineEnd else end
return prefix + clearText.substring(lineStart, lineEnd) + "\n" +
- prefix + " ".repeat(start - lineStart) + "~".repeat(displayEnd - start) + "\n"
+ prefix + " ".repeat(start - lineStart) + "~".repeat(displayEnd - start) + "\n"
}
\ No newline at end of file
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractIrTransformTest.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractIrTransformTest.kt
index fe9ccdb..6ed2ca3 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractIrTransformTest.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractIrTransformTest.kt
@@ -132,16 +132,20 @@
}
// replace source information with source it references
.replace(
- Regex("(%composer\\.start(Restart|Movable|Replaceable)Group\\" +
- "([^\"\\n]*)\"(.*)\"\\)")
+ Regex(
+ "(%composer\\.start(Restart|Movable|Replaceable)Group\\" +
+ "([^\"\\n]*)\"(.*)\"\\)"
+ )
) {
"${it.groupValues[1]}\"${
- generateSourceInfo(it.groupValues[3], source)
+ generateSourceInfo(it.groupValues[3], source)
}\")"
}
.replace(
- Regex("(composableLambda[N]?\\" +
- "([^\"\\n]*)\"(.*)\"\\)")
+ Regex(
+ "(composableLambda[N]?\\" +
+ "([^\"\\n]*)\"(.*)\"\\)"
+ )
) {
"${it.groupValues[1]}\"${
generateSourceInfo(it.groupValues[2], source)
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractLoweringTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractLoweringTests.kt
index 0662acb..3ee77fa 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractLoweringTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractLoweringTests.kt
@@ -35,7 +35,9 @@
$COMPOSE_VIEW_STUBS
- """, dumpClasses)
+ """,
+ dumpClasses
+ )
}
@Suppress("UNCHECKED_CAST")
@@ -95,7 +97,8 @@
}
$COMPOSE_VIEW_STUBS
- """, fileName, dumpClasses
+ """,
+ fileName, dumpClasses
)
val allClassFiles = compiledClasses.allGeneratedFiles.filter {
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractMultiPlatformIntegrationTest.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractMultiPlatformIntegrationTest.kt
index 3bd320c..b41dd7d 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractMultiPlatformIntegrationTest.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/AbstractMultiPlatformIntegrationTest.kt
@@ -73,7 +73,8 @@
// jetTestUtils
fun String.trimTrailingWhitespacesAndAddNewlineAtEOF(): String =
this.trimTrailingWhitespaces().let {
- result -> if (result.endsWith("\n")) result else result + "\n"
+ result ->
+ if (result.endsWith("\n")) result else result + "\n"
}
abstract class AbstractMultiPlatformIntegrationTest : AbstractCompilerTest() {
@@ -153,10 +154,12 @@
): String = buildString {
val (output, exitCode) = executeCompilerGrabOutput(
this@compile,
- listOfNotNull(sources.absolutePath,
+ listOfNotNull(
+ sources.absolutePath,
commonSources?.absolutePath,
- commonSources?.absolutePath?.let("-Xcommon-sources="::plus)) +
- "-Xmulti-platform" + mainArguments
+ commonSources?.absolutePath?.let("-Xcommon-sources="::plus)
+ ) +
+ "-Xmulti-platform" + mainArguments
)
appendLine("Exit code: $exitCode")
appendLine("Output:")
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeCallLoweringTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeCallLoweringTests.kt
index c29d29b..7494df7 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeCallLoweringTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeCallLoweringTests.kt
@@ -36,7 +36,8 @@
@Test
fun testInlineGroups(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
@Composable
fun App() {
@@ -58,7 +59,8 @@
@Test
fun testMoveFromIssue(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
""",
"Button(id=1, onClick=invalidate)"
).then { activity ->
@@ -69,7 +71,8 @@
@Test
fun testSimpleInlining(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
@Composable
inline fun foo(block: @Composable () -> Unit) {
block()
@@ -86,7 +89,8 @@
@Test
fun testVarargCall(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
@Composable
fun <T : Any> foo(
vararg inputs: Any?,
@@ -232,7 +236,8 @@
@Test
fun testPropertyValues(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
@Composable val foo get() = "123"
class A {
@@ -636,7 +641,8 @@
@Test
fun testObservableGenericFunction(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
@Composable
fun <T> SimpleComposable(state: MutableState<Int>, value: T) {
Button(
@@ -660,7 +666,8 @@
@Test
fun testObservableExtension(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
@Composable
fun MutableState<Int>.Composable() {
Button(
@@ -686,7 +693,8 @@
@Test
fun testObserverableExpressionBody(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
@Composable
fun SimpleComposable(counter: MutableState<Int>) =
Button(
@@ -714,7 +722,8 @@
@Test
fun testObservableInlineWrapper(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
var inWrapper = false
val counter = mutableStateOf(0)
@@ -752,7 +761,8 @@
@Test
fun testObservableDefaultParameter(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
val counter = mutableStateOf(0)
@Composable
@@ -778,7 +788,8 @@
@Test
fun testObservableEarlyReturn(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
val counter = mutableStateOf(0)
@Composable
@@ -1010,7 +1021,8 @@
@Test
fun testInline_NonComposable_Identity(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
@Composable inline fun InlineWrapper(base: Int, children: @Composable ()->Unit) {
children()
}
@@ -1019,25 +1031,29 @@
InlineWrapper(200) {
TextView(text = "Test", id=101)
}
- """).then { activity ->
+ """
+ ).then { activity ->
assertEquals("Test", activity.findViewById<TextView>(101).text)
}
}
@Test
fun testInline_Composable_Identity(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
""",
"""
TextView(text="Test", id=101)
- """).then { activity ->
+ """
+ ).then { activity ->
assertEquals("Test", activity.findViewById<TextView>(101).text)
}
}
@Test
fun testInline_Composable_EmitChildren(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
@Composable
inline fun InlineWrapper(base: Int, crossinline children: @Composable ()->Unit) {
LinearLayout(id = base + 0) {
@@ -1049,7 +1065,8 @@
InlineWrapper(200) {
TextView(text = "Test", id=101)
}
- """).then { activity ->
+ """
+ ).then { activity ->
val tv = activity.findViewById<TextView>(101)
// Assert the TextView was created with the correct text
assertEquals("Test", tv.text)
@@ -1109,7 +1126,8 @@
@Test
fun testReturnValue(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
var a = 0
var b = 0
@@ -1195,7 +1213,8 @@
@Test
fun testTrivialReturnValue(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
@Composable
fun <T> identity(value: T): T = value
@@ -1364,7 +1383,8 @@
fun testAmbientConsumedFromDefaultParameter(): Unit = ensureSetup {
val initialText = "no text"
val helloWorld = "Hello World!"
- compose("""
+ compose(
+ """
val TextAmbient = ambientOf { "$initialText" }
@Composable
@@ -1480,7 +1500,8 @@
).then { activity ->
val textView = activity.findViewById(tvId) as TextView
val composedSet = textView.getComposedSet(tagId) ?: error(
- "expected a compose set to exist")
+ "expected a compose set to exist"
+ )
fun assertContains(contains: Boolean, key: String) {
assertEquals("composedSet contains key '$key'", contains, composedSet.contains(key))
@@ -1570,8 +1591,11 @@
assert(composedSet.contains("ComposedInlineInt(InlineInt(value=0))"))
assert(composedSet.contains("ComposedInlineInt(InlineInt(value=1))"))
assert(composedSet.contains("ComposedInlineInt(InlineInt(value=2))"))
- assert(composedSet.contains(
- "ComposedInlineInlineInt(InlineInlineInt(value=InlineInt(value=2)))"))
+ assert(
+ composedSet.contains(
+ "ComposedInlineInlineInt(InlineInlineInt(value=InlineInt(value=2)))"
+ )
+ )
assert(composedSet.contains("ComposedInlineMutableSet(InlineMutableSet(value=[a]))"))
}.then { activity ->
val textView = activity.findViewById(tvId) as TextView
@@ -1582,8 +1606,11 @@
// not run for values equal to previous compositions.
assert(!composedSet.contains("ComposedInlineInt(InlineInt(value=0))"))
assert(!composedSet.contains("ComposedInlineInt(InlineInt(value=1))"))
- assert(!composedSet.contains(
- "ComposedInlineInlineInt(InlineInlineInt(value=InlineInt(value=2)))"))
+ assert(
+ !composedSet.contains(
+ "ComposedInlineInlineInt(InlineInlineInt(value=InlineInt(value=2)))"
+ )
+ )
// But if a stable composable is passed a new value, it should re-run.
assert(composedSet.contains("ComposedInlineInt(InlineInt(value=3))"))
@@ -1712,7 +1739,7 @@
TextView(text=value, id=$tvId)
}
""",
- """
+ """
Phone(value=phone)
""",
{ mapOf("phone" to phone) }
@@ -1743,7 +1770,8 @@
TextView(text="${'$'}left + ${'$'}right = ${'$'}{left + right}", id=$tvId)
TextView(text="${'$'}addCalled", id=$rsId)
}
- """, """
+ """,
+ """
AddView(left=left, right=right)
""",
{ mapOf("left" to left, "right" to right) }
@@ -2146,7 +2174,8 @@
""",
"""
Reordering()
- """, noParameters
+ """,
+ noParameters
).then { activity ->
// Click 5 add
val button = activity.findViewById(btnIdAdd + 5) as Button
@@ -2200,7 +2229,8 @@
""",
"""
SimpleComposable()
- """, noParameters
+ """,
+ noParameters
).then { activity ->
val button = activity.findViewById(41) as Button
button.performClick()
@@ -2245,7 +2275,8 @@
""",
"""
Reordering()
- """, noParameters
+ """,
+ noParameters
).then { activity ->
val layout = activity.findViewById(100) as LinearLayout
layout.getChildAt(0).performClick()
@@ -2285,7 +2316,8 @@
@Test
fun testStableParameters_Various(): Unit = ensureSetup {
val output = ArrayList<String>()
- compose("""
+ compose(
+ """
val m = mutableStateOf(0)
@Immutable
@@ -2401,20 +2433,23 @@
i=stateType
)
}
- """, """
+ """,
+ """
output = outerOutput
val v = ValueHolder(0)
Main(v, NotStable())
- """, {
- mapOf(
- "outerOutput: ArrayList<String>" to output
- )
- }).then {
+ """,
+ {
+ mapOf(
+ "outerOutput: ArrayList<String>" to output
+ )
+ }
+ ).then {
// Expect that all the methods are called in order
assertEquals(
"TestSkipping a=1 am=1, MemoInt a=1, MemoFloat, " +
- "MemoDouble, MemoNotStable, MemoModelHolder, MemoEnum, MemoStable, " +
- "MemoMutableState, MemoState",
+ "MemoDouble, MemoNotStable, MemoModelHolder, MemoEnum, MemoStable, " +
+ "MemoMutableState, MemoState",
output.joinToString()
)
output.clear()
@@ -2431,7 +2466,7 @@
// called then expect a second compose which should only MemoNotStable
assertEquals(
"TestSkipping a=1 am=2, MemoInt a=2, MemoNotStable, " +
- "TestSkipping a=1 am=2, MemoNotStable",
+ "TestSkipping a=1 am=2, MemoNotStable",
output.joinToString()
)
}
@@ -2440,7 +2475,8 @@
@Test
fun testStableParameters_Lambdas(): Unit = ensureSetup {
val output = ArrayList<String>()
- compose("""
+ compose(
+ """
val m = mutableStateOf(0)
var output = ArrayList<String>()
@@ -2481,18 +2517,21 @@
Button(id=101, text="model ${'$'}{m.value}", onClick={ m.value++ })
TestSkipping(unchanged = unchanged, changed = forceNewLambda())
}
- """, """
+ """,
+ """
output = outerOutput
Main(unchanged = unchanged)
- """, {
- mapOf(
- "outerOutput: ArrayList<String>" to output
- )
- }).then {
+ """,
+ {
+ mapOf(
+ "outerOutput: ArrayList<String>" to output
+ )
+ }
+ ).then {
// Expect that all the methods are called in order
assertEquals(
"TestSkipping, Container, NormalLambda(1), " +
- "NormalLambda(2), NormalLambda(3), NormalLambda(4)",
+ "NormalLambda(2), NormalLambda(3), NormalLambda(4)",
output.joinToString()
)
output.clear()
@@ -2515,7 +2554,8 @@
@Test
fun testRecomposeScope(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
val m = mutableStateOf(0)
@Composable
@@ -2566,7 +2606,8 @@
@Test
fun testRecomposeScope_ReceiverScope(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
val m = mutableStateOf(0)
class Receiver { var r: Int = 0 }
@@ -2599,7 +2640,8 @@
@Test
fun testCompose_InlineReceiver(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
object Context {
fun t() {}
}
@@ -2619,7 +2661,8 @@
@Test
fun testRecomposeScope_Method(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
val m = mutableStateOf(0)
@Composable
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeCallResolverTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeCallResolverTests.kt
index 742af57..de6a1e2 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeCallResolverTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeCallResolverTests.kt
@@ -228,8 +228,10 @@
carets.forEachIndexed { index, (offset, calltype) ->
val resolvedCall = resolvedCallAtOffset(bindingContext, ktFile, offset)
- ?: error("No resolved call found at index: $index, offset: $offset. Expected " +
- "$calltype.")
+ ?: error(
+ "No resolved call found at index: $index, offset: $offset. Expected " +
+ "$calltype."
+ )
when (calltype) {
"<normal>" -> assert(!resolvedCall.isComposableInvocation())
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeMultiPlatformTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeMultiPlatformTests.kt
index 18875e8..ff3f107 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeMultiPlatformTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposeMultiPlatformTests.kt
@@ -41,17 +41,17 @@
@Test
fun testBasicComposable() = ensureSetup {
multiplatform(
- """
+ """
import androidx.compose.runtime.Composable
expect @Composable fun Test()
""",
- """
+ """
import androidx.compose.runtime.Composable
actual @Composable fun Test() {}
""",
- """
+ """
final class JvmKt%Test%1 extends kotlin/jvm/internal/Lambda implements kotlin/jvm/functions/Function2 {
OUTERCLASS JvmKt Test (Landroidx/compose/runtime/Composer;I)V
final static INNERCLASS JvmKt%Test%1 null null
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposerParamSignatureTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposerParamSignatureTests.kt
index 9083526..59d8296 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposerParamSignatureTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ComposerParamSignatureTests.kt
@@ -155,15 +155,21 @@
"""
) {
val testClass = it.split("public final class ").single { it.startsWith("test/TestKt") }
- assert(!testClass.contains(
- "INVOKEVIRTUAL Bar.unbox-impl ()I"
- ))
- assert(!testClass.contains(
- "INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;"
- ))
- assert(testClass.contains(
- "INVOKEVIRTUAL androidx/compose/runtime/Composer.changed (Ljava/lang/Object;)Z"
- ))
+ assert(
+ !testClass.contains(
+ "INVOKEVIRTUAL Bar.unbox-impl ()I"
+ )
+ )
+ assert(
+ !testClass.contains(
+ "INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;"
+ )
+ )
+ assert(
+ testClass.contains(
+ "INVOKEVIRTUAL androidx/compose/runtime/Composer.changed (Ljava/lang/Object;)Z"
+ )
+ )
}
@Test
@@ -200,9 +206,11 @@
}
"""
) {
- assert(!it.contains(
- "INVOKEINTERFACE kotlin/jvm/functions/Function0.invoke ()Ljava/lang/Object; (itf)"
- ))
+ assert(
+ !it.contains(
+ "INVOKEINTERFACE kotlin/jvm/functions/Function0.invoke ()Ljava/lang/Object; (itf)"
+ )
+ )
}
@Test
@@ -345,7 +353,8 @@
data class Foo(
val bar: @Composable () -> Unit
)
- """) {
+ """
+ ) {
assert(!it.contains("CHECKCAST kotlin/jvm/functions/Function0"))
}
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ControlFlowTransformTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ControlFlowTransformTests.kt
index 85a8188..fcabff3 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ControlFlowTransformTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/ControlFlowTransformTests.kt
@@ -1091,7 +1091,7 @@
@Test
fun testBreakWithCallsAfter(): Unit = controlFlow(
- """
+ """
@ComposableContract(restartable = false) @Composable
fun Example(items: Iterator<Int>) {
while (items.hasNext()) {
@@ -1118,7 +1118,7 @@
%composer.endReplaceableGroup()
}
"""
- )
+ )
@Test
fun testBreakWithCallsBefore(): Unit = controlFlow(
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/FunctionBodySkippingTransformTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/FunctionBodySkippingTransformTests.kt
index 82c9b31..01fe454 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/FunctionBodySkippingTransformTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/FunctionBodySkippingTransformTests.kt
@@ -714,7 +714,7 @@
)
@Test
-fun testStableVarargParams(): Unit = comparisonPropagation(
+ fun testStableVarargParams(): Unit = comparisonPropagation(
"""
import androidx.compose.runtime.Immutable
@Immutable class Foo
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/KtxCrossModuleTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/KtxCrossModuleTests.kt
index 931a988..ecd7e7e 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/KtxCrossModuleTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/KtxCrossModuleTests.kt
@@ -42,8 +42,9 @@
@Ignore("b/165674304")
fun testInlineFunctionDefaultArgument(): Unit = ensureSetup {
compile(
- mapOf("library module" to mapOf (
- "x/library.kt" to """
+ mapOf(
+ "library module" to mapOf (
+ "x/library.kt" to """
package x
import androidx.compose.runtime.Composable
@@ -52,10 +53,10 @@
inline fun f(x: () -> Unit = { println("default") }) {
x()
}
- """.trimIndent()
- ),
- "Main" to mapOf(
- "y/User.kt" to """
+ """.trimIndent()
+ ),
+ "Main" to mapOf(
+ "y/User.kt" to """
package y
import x.f
@@ -67,8 +68,9 @@
println("non-default")
}
}
- """.trimIndent()
- ))
+ """.trimIndent()
+ )
+ )
)
}
@@ -76,8 +78,9 @@
@Ignore("b/165674304")
fun testInlineFunctionDefaultArgument2(): Unit = ensureSetup {
compile(
- mapOf("library module" to mapOf (
- "x/library.kt" to """
+ mapOf(
+ "library module" to mapOf (
+ "x/library.kt" to """
package x
import androidx.compose.runtime.Composable
@@ -86,10 +89,10 @@
inline fun f(x: () -> Unit = { println("default") }) {
x()
}
- """.trimIndent()
- ),
- "Main" to mapOf(
- "y/User.kt" to """
+ """.trimIndent()
+ ),
+ "Main" to mapOf(
+ "y/User.kt" to """
package y
import x.f
@@ -99,15 +102,17 @@
fun g() {
f()
}
- """.trimIndent()
- ))
+ """.trimIndent()
+ )
+ )
)
}
@Test
fun testAccessibilityBridgeGeneration(): Unit = ensureSetup {
compile(
- mapOf("library module" to mapOf(
+ mapOf(
+ "library module" to mapOf(
"x/I.kt" to """
package x
@@ -116,7 +121,7 @@
@Composable fun bar(arg: @Composable () -> Unit) {
arg()
}
- """.trimIndent()
+ """.trimIndent()
),
"Main" to mapOf(
"y/User.kt" to """
@@ -131,7 +136,7 @@
}
}
@Composable private fun foo() { }
- """.trimIndent()
+ """.trimIndent()
)
)
) {
@@ -161,7 +166,7 @@
val prop
get() = i + 1
}
- """.trimIndent()
+ """.trimIndent()
),
"Main" to mapOf(
"y/User.kt" to """
@@ -169,7 +174,7 @@
import x.I
inline class J(val j: Int)
fun foo(): Int = I(42).i + J(23).j + I(1).prop
- """.trimIndent()
+ """.trimIndent()
)
)
) {
@@ -766,7 +771,8 @@
val tvId = 29
compose(
- "TestF", mapOf(
+ "TestF",
+ mapOf(
"library module" to mapOf(
"my/test/lib/InternalComp.kt" to """
package my.test.lib
@@ -829,18 +835,20 @@
dumpClasses: Boolean = false,
validate: ((String) -> Unit)? = null
): List<OutputFile> {
- val libraryClasses = (modules.filter { it.key != "Main" }.map {
- // Setup for compile
- this.classFileFactory = null
- this.myEnvironment = null
- setUp(it.key.contains("--ktx=false"))
+ val libraryClasses = (
+ modules.filter { it.key != "Main" }.map {
+ // Setup for compile
+ this.classFileFactory = null
+ this.myEnvironment = null
+ setUp(it.key.contains("--ktx=false"))
- classLoader(it.value, dumpClasses).allGeneratedFiles.also {
- // Write the files to the class directory so they can be used by the next module
- // and the application
- it.writeToDir(classesDirectory)
- }
- } + emptyList()).reduce { acc, mutableList -> acc + mutableList }
+ classLoader(it.value, dumpClasses).allGeneratedFiles.also {
+ // Write the files to the class directory so they can be used by the next module
+ // and the application
+ it.writeToDir(classesDirectory)
+ }
+ } + emptyList()
+ ).reduce { acc, mutableList -> acc + mutableList }
// Setup for compile
this.classFileFactory = null
@@ -848,8 +856,11 @@
setUp()
// compile the next one
- val appClasses = classLoader(modules["Main"]
- ?: error("No Main module specified"), dumpClasses).allGeneratedFiles
+ val appClasses = classLoader(
+ modules["Main"]
+ ?: error("No Main module specified"),
+ dumpClasses
+ ).allGeneratedFiles
// Load the files looking for mainClassName
val outputFiles = (libraryClasses + appClasses).filter {
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/KtxTransformationTest.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/KtxTransformationTest.kt
index 4acff47..0c169ff 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/KtxTransformationTest.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/KtxTransformationTest.kt
@@ -18,8 +18,9 @@
class KtxTransformationTest : AbstractCodegenTest() {
- fun testObserveLowering() = ensureSetup { testCompileWithViewStubs(
- """
+ fun testObserveLowering() = ensureSetup {
+ testCompileWithViewStubs(
+ """
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
@@ -37,10 +38,12 @@
)
}
"""
- ) }
+ )
+ }
- fun testEmptyComposeFunction() = ensureSetup { testCompile(
- """
+ fun testEmptyComposeFunction() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
class Foo {
@@ -48,10 +51,12 @@
operator fun invoke() {}
}
"""
- ) }
+ )
+ }
- fun testSingleViewCompose() = ensureSetup { testCompileWithViewStubs(
- """
+ fun testSingleViewCompose() = ensureSetup {
+ testCompileWithViewStubs(
+ """
class Foo {
@Composable
operator fun invoke() {
@@ -59,10 +64,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testMultipleRootViewCompose() = ensureSetup { testCompileWithViewStubs(
- """
+ fun testMultipleRootViewCompose() = ensureSetup {
+ testCompileWithViewStubs(
+ """
class Foo {
@Composable
operator fun invoke() {
@@ -72,10 +79,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testNestedViewCompose() = ensureSetup { testCompileWithViewStubs(
- """
+ fun testNestedViewCompose() = ensureSetup {
+ testCompileWithViewStubs(
+ """
class Foo {
@Composable
operator fun invoke() {
@@ -89,10 +98,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testSingleComposite() = ensureSetup { testCompile(
- """
+ fun testSingleComposite() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
@Composable
@@ -105,10 +116,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testMultipleRootComposite() = ensureSetup { testCompile(
- """
+ fun testMultipleRootComposite() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
@Composable
@@ -123,10 +136,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testViewAndComposites() = ensureSetup { testCompileWithViewStubs(
- """
+ fun testViewAndComposites() = ensureSetup {
+ testCompileWithViewStubs(
+ """
@Composable
fun Bar() {}
@@ -139,10 +154,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testForEach() = ensureSetup { testCompile(
- """
+ fun testForEach() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
@Composable
@@ -157,10 +174,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testForLoop() = ensureSetup { testCompile(
- """
+ fun testForLoop() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
@Composable
@@ -175,10 +194,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testEarlyReturns() = ensureSetup { testCompile(
- """
+ fun testEarlyReturns() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
@Composable
@@ -194,10 +215,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testConditionalRendering() = ensureSetup { testCompile(
- """
+ fun testConditionalRendering() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
@Composable
@@ -218,10 +241,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testChildrenWithTypedParameters() = ensureSetup { testCompileWithViewStubs(
- """
+ fun testChildrenWithTypedParameters() = ensureSetup {
+ testCompileWithViewStubs(
+ """
@Composable fun HelperComponent(
children: @Composable (title: String, rating: Int) -> Unit
) {
@@ -240,10 +265,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testChildrenCaptureVariables() = ensureSetup { testCompileWithViewStubs(
- """
+ fun testChildrenCaptureVariables() = ensureSetup {
+ testCompileWithViewStubs(
+ """
@Composable fun HelperComponent(children: @Composable () -> Unit) {
}
@@ -258,10 +285,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testChildrenDeepCaptureVariables() = ensureSetup { testCompile(
- """
+ fun testChildrenDeepCaptureVariables() = ensureSetup {
+ testCompile(
+ """
import android.widget.*
import androidx.compose.runtime.*
@@ -286,11 +315,12 @@
}
}
"""
- ) }
+ )
+ }
fun testChildrenDeepCaptureVariablesWithParameters() = ensureSetup {
testCompile(
- """
+ """
import android.widget.*
import androidx.compose.runtime.*
@@ -318,8 +348,9 @@
)
}
- fun testChildrenOfNativeView() = ensureSetup { testCompileWithViewStubs(
- """
+ fun testChildrenOfNativeView() = ensureSetup {
+ testCompileWithViewStubs(
+ """
class MainComponent {
@Composable
operator fun invoke() {
@@ -330,10 +361,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testIrSpecial() = ensureSetup { testCompileWithViewStubs(
- """
+ fun testIrSpecial() = ensureSetup {
+ testCompileWithViewStubs(
+ """
@Composable fun HelperComponent(children: @Composable () -> Unit) {}
class MainComponent {
@@ -349,10 +382,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testGenericsInnerClass() = ensureSetup { testCompile(
- """
+ fun testGenericsInnerClass() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
class A<T>(val value: T) {
@@ -368,10 +403,12 @@
a.Getter(x=456)
}
"""
- ) }
+ )
+ }
- fun testXGenericConstructorParams() = ensureSetup { testCompile(
- """
+ fun testXGenericConstructorParams() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
@Composable fun <T> A(
@@ -395,10 +432,12 @@
)
}
"""
- ) }
+ )
+ }
- fun testSimpleNoArgsComponent() = ensureSetup { testCompile(
- """
+ fun testSimpleNoArgsComponent() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
@Composable
@@ -409,10 +448,12 @@
Simple()
}
"""
- ) }
+ )
+ }
- fun testDotQualifiedObjectToClass() = ensureSetup { testCompile(
- """
+ fun testDotQualifiedObjectToClass() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
object Obj {
@@ -425,10 +466,12 @@
Obj.B()
}
"""
- ) }
+ )
+ }
- fun testLocalLambda() = ensureSetup { testCompile(
- """
+ fun testLocalLambda() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
@Composable
@@ -440,10 +483,12 @@
foo()
}
"""
- ) }
+ )
+ }
- fun testPropertyLambda() = ensureSetup { testCompile(
- """
+ fun testPropertyLambda() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
class Test(var children: @Composable () () -> Unit) {
@@ -453,10 +498,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testLambdaWithArgs() = ensureSetup { testCompile(
- """
+ fun testLambdaWithArgs() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
class Test(var children: @Composable (x: Int) -> Unit) {
@@ -466,10 +513,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testLocalMethod() = ensureSetup { testCompile(
- """
+ fun testLocalMethod() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
class Test {
@@ -481,10 +530,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testSimpleLambdaChildren() = ensureSetup { testCompile(
- """
+ fun testSimpleLambdaChildren() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
import android.widget.*
import android.content.*
@@ -500,10 +551,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testFunctionComponentsWithChildrenSimple() = ensureSetup { testCompile(
- """
+ fun testFunctionComponentsWithChildrenSimple() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
@Composable
@@ -516,10 +569,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testFunctionComponentWithChildrenOneArg() = ensureSetup { testCompile(
- """
+ fun testFunctionComponentWithChildrenOneArg() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
@Composable
@@ -532,10 +587,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testKtxLambdaInForLoop() = ensureSetup { testCompile(
- """
+ fun testKtxLambdaInForLoop() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
import android.widget.TextView
@@ -548,10 +605,12 @@
}
}
"""
- ) }
+ )
+ }
- fun testKtxLambdaInIfElse() = ensureSetup { testCompileWithViewStubs(
- """
+ fun testKtxLambdaInIfElse() = ensureSetup {
+ testCompileWithViewStubs(
+ """
@Composable
fun foo(x: Boolean) {
val lambda = @Composable { TextView(text="Hello World") }
@@ -564,11 +623,12 @@
}
}
"""
- ) }
+ )
+ }
fun testKtxVariableTagsProperlyCapturedAcrossKtxLambdas() = ensureSetup {
testCompile(
- """
+ """
import androidx.compose.androidview.adapters.*
import androidx.compose.runtime.*
@@ -594,8 +654,9 @@
)
}
- fun testInvocableObject() = ensureSetup { testCompile(
- """
+ fun testInvocableObject() = ensureSetup {
+ testCompile(
+ """
import androidx.compose.runtime.*
class Foo { }
@@ -608,5 +669,6 @@
foo()
}
"""
- ) }
+ )
+ }
}
\ No newline at end of file
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/LambdaMemoizationTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/LambdaMemoizationTests.kt
index 66df232..fd63f002 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/LambdaMemoizationTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/LambdaMemoizationTests.kt
@@ -32,7 +32,8 @@
class LambdaMemoizationTests : AbstractLoweringTests() {
@Test
- fun nonCapturingEventLambda() = skipping("""
+ fun nonCapturingEventLambda() = skipping(
+ """
fun eventFired() { }
@Composable
@@ -48,10 +49,12 @@
ValidateModel(text = model)
}
}
- """)
+ """
+ )
@Test
- fun lambdaInClassInitializer() = skipping("""
+ fun lambdaInClassInitializer() = skipping(
+ """
@Composable
fun EventHolder(event: () -> Unit) {
workToBeRepeated()
@@ -71,10 +74,12 @@
ValidateModel(model)
EventHolder(event = n.lambda)
}
- """)
+ """
+ )
@Test
- fun methodReferenceEvent() = skipping("""
+ fun methodReferenceEvent() = skipping(
+ """
fun eventFired() { }
@Composable
@@ -91,10 +96,12 @@
ValidateModel(text = model)
}
}
- """)
+ """
+ )
@Test
- fun methodReferenceOnValue() = skipping("""
+ fun methodReferenceOnValue() = skipping(
+ """
fun eventFired(value: String) { }
@Composable
@@ -115,10 +122,12 @@
fun Example(model: String) {
Test(model, "unchanged")
}
- """)
+ """
+ )
@Test
- fun extensionMethodReferenceOnValue() = skipping("""
+ fun extensionMethodReferenceOnValue() = skipping(
+ """
fun eventFired(value: String) { }
fun String.self() = this
@@ -141,10 +150,12 @@
fun Example(model: String) {
Test(model, "unchanged")
}
- """)
+ """
+ )
@Test
- fun doNotMemoizeCallsToInlines() = skipping("""
+ fun doNotMemoizeCallsToInlines() = skipping(
+ """
fun eventFired(data: String) { }
@Composable
@@ -169,10 +180,12 @@
ValidateModel(model)
}
}
- """)
+ """
+ )
@Test
- fun captureParameterDirectEventLambda() = skipping("""
+ fun captureParameterDirectEventLambda() = skipping(
+ """
fun eventFired(data: String) { }
@Composable
@@ -188,10 +201,12 @@
ValidateModel(text = model)
}
}
- """)
+ """
+ )
@Test
- fun shouldNotRememberDirectLambdaParameter() = skipping("""
+ fun shouldNotRememberDirectLambdaParameter() = skipping(
+ """
fun eventFired(data: String) {
// println("Validating ${'$'}data")
validateModel(data)
@@ -212,10 +227,12 @@
fun Example(model: String) {
EventWrapper(event = { eventFired(model) })
}
- """)
+ """
+ )
@Test
- fun narrowCaptureValidation() = skipping("""
+ fun narrowCaptureValidation() = skipping(
+ """
fun eventFired(data: String) { }
@Composable
@@ -238,10 +255,12 @@
ExpectModified(event = { eventFired(modified) })
ExpectModified(event = { eventFired(model) })
}
- """)
+ """
+ )
@Test
- fun captureInANestedScope() = skipping("""
+ fun captureInANestedScope() = skipping(
+ """
fun eventFired(data: String) { }
@Composable
@@ -277,10 +296,12 @@
}
}
}
- """)
+ """
+ )
@Test
- fun twoCaptures() = skipping("""
+ fun twoCaptures() = skipping(
+ """
fun eventFired(data: String) { }
@Composable
@@ -310,10 +331,12 @@
ExpectModified(event = { eventFired(unmodified2 + modified2) })
ExpectModified(event = { eventFired(modified1 + modified2) })
}
- """)
+ """
+ )
@Test
- fun threeCaptures() = skipping("""
+ fun threeCaptures() = skipping(
+ """
fun eventFired(data: String) { }
@Composable
@@ -344,10 +367,12 @@
ExpectModified(event = { eventFired(modified1 + modified2 + unmodified3) })
ExpectModified(event = { eventFired(modified1 + modified2 + modified3) })
}
- """)
+ """
+ )
@Test
- fun fiveCaptures() = skipping("""
+ fun fiveCaptures() = skipping(
+ """
fun eventFired(data: String) { }
@Composable
@@ -377,10 +402,12 @@
unmodified1 + unmodified2 + unmodified3 + unmodified4 + unmodified1 + modified
) })
}
- """)
+ """
+ )
@Test
- fun doNotMemoizeNonStableCaptures() = skipping("""
+ fun doNotMemoizeNonStableCaptures() = skipping(
+ """
val unmodifiedUnstable = Any()
val unmodifiedString = "unmodified"
@@ -408,10 +435,12 @@
fun Example(model: String) {
NonStable(model, unmodifiedUnstable, unmodifiedString)
}
- """)
+ """
+ )
@Test
- fun doNotMemoizeVarCapures() = skipping("""
+ fun doNotMemoizeVarCapures() = skipping(
+ """
fun eventFired(data: Int) { }
@Composable
@@ -451,10 +480,12 @@
fun Example(model: String) {
Test(model, 1)
}
- """)
+ """
+ )
@Test
- fun considerNonComposableCaptures() = skipping("""
+ fun considerNonComposableCaptures() = skipping(
+ """
fun eventFired(data: Int) {}
@Composable
@@ -478,10 +509,12 @@
ExpectUnmodified(event = { eventFired(5) })
}
}
- """)
+ """
+ )
@Test
- fun wrapLambaExpressions() = skipping("""
+ fun wrapLambaExpressions() = skipping(
+ """
@Composable
fun Wrapper(block: @Composable () -> Unit) {
workToBeAvoided()
@@ -497,10 +530,12 @@
ValidateModel(model)
}
}
- """)
+ """
+ )
@Test
- fun nonCapturingComposableLambda() = skipping("""
+ fun nonCapturingComposableLambda() = skipping(
+ """
@Composable
fun Wrapper1(block: @Composable () -> Unit) {
workToBeAvoided("Wrapper1.1")
@@ -535,10 +570,12 @@
}
}
}
- """)
+ """
+ )
@Test
- fun wrappingOneParameter() = skipping("""
+ fun wrappingOneParameter() = skipping(
+ """
@Composable
fun Wrap(block: @Composable (p1: String) -> Unit) {
workToBeAvoided()
@@ -556,10 +593,12 @@
ValidateModel(model)
}
}
- """)
+ """
+ )
@Test // Selecting 23 as 22 is the maximum number handled by RestartingFunction
- fun wrapping23Parameters() = skipping("""
+ fun wrapping23Parameters() = skipping(
+ """
@Composable
fun Wrap(block: @Composable (
p1: String,
@@ -632,10 +671,12 @@
ValidateModel(model)
}
}
- """)
+ """
+ )
@Test
- fun wrappingReceiverParameter() = skipping("""
+ fun wrappingReceiverParameter() = skipping(
+ """
class Receiver() { }
@Composable
@@ -654,10 +695,12 @@
ValidateModel(model)
}
}
- """)
+ """
+ )
@Test
- fun untrackedLambdasShouldNotForceEvaluation() = skipping("""
+ fun untrackedLambdasShouldNotForceEvaluation() = skipping(
+ """
@Composable
fun Wrapper(block: @Composable () -> Unit) {
workToBeAvoided()
@@ -678,10 +721,12 @@
}
workToBeRepeated()
}
- """)
+ """
+ )
@Test
- fun lambdasWithReturnResultsShouldBeUntracked() = skipping("""
+ fun lambdasWithReturnResultsShouldBeUntracked() = skipping(
+ """
@Composable
fun Test1(param: @Composable () -> String) {
@@ -703,11 +748,13 @@
s.value = model
Test1({ s.value })
}
- """)
+ """
+ )
private fun skipping(text: String, dumpClasses: Boolean = false) =
ensureSetup {
- compose("""
+ compose(
+ """
var avoidedWorkCount = 0
var repeatedWorkCount = 0
var expectedAvoidedWorkCount = 0
@@ -770,9 +817,12 @@
}
}
- """, """
+ """,
+ """
TestHost()
- """, dumpClasses = dumpClasses).then { activity ->
+ """,
+ dumpClasses = dumpClasses
+ ).then { activity ->
val button = activity.findViewById(42) as Button
button.performClick()
}.then { activity ->
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/LiveLiteralCodegenTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/LiveLiteralCodegenTests.kt
index 60526ec..800bd34 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/LiveLiteralCodegenTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/LiveLiteralCodegenTests.kt
@@ -41,7 +41,8 @@
@Ignore
@Test
fun testBasicFunctionality(): Unit = ensureSetup {
- compose("""
+ compose(
+ """
@Composable
fun App() {
TextView(id=1, text="abc")
@@ -62,7 +63,8 @@
@Ignore
@Test
fun testObjectFieldsLoweredToStaticFields(): Unit = ensureSetup {
- validateBytecode("""
+ validateBytecode(
+ """
fun Test(): Int {
return 123
}
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/ComposableCheckerTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/ComposableCheckerTests.kt
index a14e897..e00e1b3 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/ComposableCheckerTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/ComposableCheckerTests.kt
@@ -11,7 +11,8 @@
override fun setUp() {
// intentionally don't call super.setUp() here since we are recreating an environment
// every test
- System.setProperty("user.dir",
+ System.setProperty(
+ "user.dir",
homeDir
)
}
@@ -56,28 +57,35 @@
doTest(expectedText, false)
}
- fun testCfromNC() = check("""
+ fun testCfromNC() = check(
+ """
import androidx.compose.runtime.*
@Composable fun C() {}
fun <!COMPOSABLE_EXPECTED!>NC<!>() { <!COMPOSABLE_INVOCATION!>C<!>() }
- """)
+ """
+ )
- fun testNCfromC() = check("""
+ fun testNCfromC() = check(
+ """
import androidx.compose.runtime.*
fun NC() {}
@Composable fun C() { NC() }
- """)
+ """
+ )
- fun testCfromC() = check("""
+ fun testCfromC() = check(
+ """
import androidx.compose.runtime.*
@Composable fun C() {}
@Composable fun C2() { C() }
- """)
+ """
+ )
- fun testCinCLambdaArg() = check("""
+ fun testCinCLambdaArg() = check(
+ """
import androidx.compose.runtime.*
@Composable fun C() { }
@Composable fun C2(lambda: @Composable () -> Unit) { lambda() }
@@ -86,9 +94,11 @@
C()
}
}
- """)
+ """
+ )
- fun testCinInlinedNCLambdaArg() = check("""
+ fun testCinInlinedNCLambdaArg() = check(
+ """
import androidx.compose.runtime.*
@Composable fun C() { }
inline fun InlineNC(lambda: () -> Unit) { lambda() }
@@ -97,9 +107,11 @@
C()
}
}
- """)
+ """
+ )
- fun testCinLambdaArgOfNC() = check("""
+ fun testCinLambdaArgOfNC() = check(
+ """
import androidx.compose.runtime.*
@Composable fun C() { }
fun NC(lambda: () -> Unit) { lambda() }
@@ -108,9 +120,11 @@
<!COMPOSABLE_INVOCATION!>C<!>()
}
}
- """)
+ """
+ )
- fun testCinLambdaArgOfC() = check("""
+ fun testCinLambdaArgOfC() = check(
+ """
import androidx.compose.runtime.*
@Composable fun C() { }
@Composable fun C2(lambda: () -> Unit) { lambda() }
@@ -119,28 +133,36 @@
<!COMPOSABLE_INVOCATION!>C<!>()
}
}
- """)
+ """
+ )
- fun testCinCPropGetter() = check("""
+ fun testCinCPropGetter() = check(
+ """
import androidx.compose.runtime.*
@Composable fun C(): Int { return 123 }
@Composable val cProp: Int get() = C()
- """)
+ """
+ )
- fun testCinNCPropGetter() = check("""
+ fun testCinNCPropGetter() = check(
+ """
import androidx.compose.runtime.*
@Composable fun C(): Int { return 123 }
val <!COMPOSABLE_EXPECTED!>ncProp<!>: Int get() = <!COMPOSABLE_INVOCATION!>C<!>()
- """)
+ """
+ )
- fun testCinTopLevelInitializer() = check("""
+ fun testCinTopLevelInitializer() = check(
+ """
import androidx.compose.runtime.*
@Composable fun C(): Int { return 123 }
val ncProp: Int = <!COMPOSABLE_INVOCATION!>C<!>()
@Composable val <!COMPOSABLE_PROPERTY_BACKING_FIELD!>cProp<!>: Int = <!COMPOSABLE_INVOCATION!>C<!>()
- """)
+ """
+ )
- fun testCTypeAlias() = check("""
+ fun testCTypeAlias() = check(
+ """
import androidx.compose.runtime.*
typealias Content = @Composable () -> Unit
@Composable fun C() {}
@@ -150,9 +172,11 @@
C2 { C() }
C2 { inner() }
}
- """)
+ """
+ )
- fun testPreventedCaptureOnInlineLambda() = check("""
+ fun testPreventedCaptureOnInlineLambda() = check(
+ """
import androidx.compose.runtime.*
@Composable inline fun A(
@@ -163,10 +187,12 @@
@Composable fun C() {
A { <!CAPTURED_COMPOSABLE_INVOCATION!>B<!>() }
}
- """)
+ """
+ )
fun testComposableReporting001() {
- checkFail("""
+ checkFail(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -175,8 +201,10 @@
fun myStatelessFunctionalComponent() {
Leaf()
}
- """)
- check("""
+ """
+ )
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -191,11 +219,13 @@
fun foo() {
myStatelessFunctionalComponent()
}
- """)
+ """
+ )
}
fun testComposableReporting002() {
- checkFail("""
+ checkFail(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -203,8 +233,10 @@
val myLambda1 = { Leaf() }
val myLambda2: () -> Unit = { Leaf() }
- """)
- check("""
+ """
+ )
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -212,11 +244,13 @@
val myLambda1 = @Composable { Leaf() }
val myLambda2: @Composable ()->Unit = { Leaf() }
- """)
+ """
+ )
}
fun testComposableReporting006() {
- checkFail("""
+ checkFail(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -229,8 +263,10 @@
bar()
System.out.println(bar)
}
- """)
- check("""
+ """
+ )
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -244,21 +280,25 @@
bar()
System.out.println(bar)
}
- """)
+ """
+ )
}
fun testComposableReporting007() {
- checkFail("""
+ checkFail(
+ """
import androidx.compose.runtime.*;
fun foo(children: @Composable ()->Unit) {
<!SVC_INVOCATION!>children<!>()
}
- """)
+ """
+ )
}
fun testComposableReporting008() {
- checkFail("""
+ checkFail(
+ """
import androidx.compose.runtime.*;
@Composable fun Leaf() {}
@@ -270,11 +310,13 @@
<!COMPOSABLE_INVOCATION!>bar<!>()
System.out.println(bar)
}
- """)
+ """
+ )
}
fun testComposableReporting009() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable fun Leaf() {}
@@ -287,11 +329,13 @@
fun <!COMPOSABLE_EXPECTED!>noise<!>() {
<!COMPOSABLE_INVOCATION!>myStatelessFunctionalComponent<!>()
}
- """)
+ """
+ )
}
fun testComposableReporting017() {
- checkFail("""
+ checkFail(
+ """
import androidx.compose.runtime.*;
@Composable fun Leaf() {}
@@ -305,8 +349,10 @@
fun main() {
Foo { Leaf() }
}
- """)
- check("""
+ """
+ )
+ check(
+ """
import androidx.compose.runtime.*;
@Composable fun Leaf() {}
@@ -320,11 +366,13 @@
fun main() {
Foo { <!COMPOSABLE_INVOCATION!>Leaf<!>() }
}
- """)
+ """
+ )
}
fun testComposableReporting018() {
- checkFail("""
+ checkFail(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -334,8 +382,10 @@
val myVariable: ()->Unit = @Composable { Leaf() }
System.out.println(myVariable)
}
- """)
- check("""
+ """
+ )
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -345,11 +395,13 @@
val myVariable: ()->Unit = <!TYPE_MISMATCH!>@Composable { Leaf() }<!>
System.out.println(myVariable)
}
- """)
+ """
+ )
}
fun testComposableReporting021() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -363,11 +415,13 @@
System.out.println(value)
}
}
- """)
+ """
+ )
}
fun testComposableReporting022() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -380,11 +434,13 @@
println(value)
}
}
- """)
+ """
+ )
}
fun testComposableReporting023() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -398,11 +454,13 @@
println(value)
}
}
- """)
+ """
+ )
}
fun testComposableReporting024() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*
var x: (@Composable () -> Unit)? = null
@@ -418,11 +476,13 @@
fun Example(foo: Foo) {
foo.setContent { Leaf() }
}
- """)
+ """
+ )
}
fun testComposableReporting024x() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*
var x: (@Composable () -> Unit)? = null
@@ -431,11 +491,13 @@
x = content
<!COMPOSABLE_INVOCATION!>content<!>()
}
- """)
+ """
+ )
}
fun testComposableReporting025() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -445,11 +507,13 @@
fun foo() {
listOf(1,2,3,4,5).forEach { Leaf() }
}
- """)
+ """
+ )
}
fun testComposableReporting026() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -464,11 +528,13 @@
Leaf()
}
}
- """)
+ """
+ )
}
fun testComposableReporting027() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -485,30 +551,36 @@
}
}
}
- """)
+ """
+ )
}
fun testComposableReporting028() {
- checkFail("""
+ checkFail(
+ """
import androidx.compose.runtime.*;
fun foo(v: @Composable ()->Unit) {
val myVariable: ()->Unit = v
myVariable()
}
- """)
- check("""
+ """
+ )
+ check(
+ """
import androidx.compose.runtime.*;
fun foo(v: @Composable ()->Unit) {
val myVariable: ()->Unit = <!TYPE_MISMATCH!>v<!>
myVariable()
}
- """)
+ """
+ )
}
fun testComposableReporting030() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -516,11 +588,13 @@
val myVariable: @Composable ()->Unit = {};
myVariable()
}
- """)
+ """
+ )
}
fun testComposableReporting032() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -533,11 +607,13 @@
fun foo() {
MyComposable { Leaf() }
}
- """)
+ """
+ )
}
fun testComposableReporting033() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -550,11 +626,13 @@
fun foo() {
MyComposable(children={ Leaf() })
}
- """)
+ """
+ )
}
fun testComposableReporting034() {
- checkFail("""
+ checkFail(
+ """
import androidx.compose.runtime.*;
fun identity(f: ()->Unit): ()->Unit { return f; }
@@ -564,8 +642,10 @@
val f2: @Composable ()->Unit = identity(f);
f2()
}
- """)
- check("""
+ """
+ )
+ check(
+ """
import androidx.compose.runtime.*;
fun identity(f: ()->Unit): ()->Unit { return f; }
@@ -575,11 +655,13 @@
val f2: @Composable ()->Unit = <!TYPE_MISMATCH!>identity (<!TYPE_MISMATCH!>f<!>)<!>;
f2()
}
- """)
+ """
+ )
}
fun testComposableReporting035() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*
@Composable
@@ -587,7 +669,8 @@
@Composable operator fun String.invoke() {}
x()
}
- """)
+ """
+ )
}
fun testComposableReporting039() {
@@ -612,7 +695,8 @@
}
fun testComposableReporting041() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*
typealias COMPOSABLE_UNIT_LAMBDA = @Composable () -> Unit
@@ -627,11 +711,13 @@
@Composable fun MyComposeWrapper(children: COMPOSABLE_UNIT_LAMBDA) {
print(children.hashCode())
}
- """)
+ """
+ )
}
fun testComposableReporting043() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*
@Composable
@@ -640,11 +726,13 @@
fun <!COMPOSABLE_EXPECTED!>Noise<!>() {
<!COMPOSABLE_INVOCATION!>FancyButton<!>()
}
- """)
+ """
+ )
}
fun testComposableReporting044() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*
typealias UNIT_LAMBDA = () -> Unit
@@ -656,11 +744,13 @@
fun Noise() {
FancyButton()
}
- """)
+ """
+ )
}
fun testComposableReporting045() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable
@@ -669,12 +759,14 @@
bar()
System.out.println(bar)
}
- """)
+ """
+ )
}
fun testComposableReporting048() {
// Type inference for non-null @Composable lambdas
- checkFail("""
+ checkFail(
+ """
import androidx.compose.runtime.*
val lambda: @Composable (() -> Unit)? = null
@@ -691,10 +783,12 @@
fun Bar(child: @Composable () -> Unit) {
child()
}
- """)
+ """
+ )
// Type inference for nullable @Composable lambdas, with no default value
- check("""
+ check(
+ """
import androidx.compose.runtime.*
val lambda: @Composable (() -> Unit)? = null
@@ -710,10 +804,12 @@
fun Bar(child: @Composable (() -> Unit)?) {
child?.invoke()
}
- """)
+ """
+ )
// Type inference for nullable @Composable lambdas, with a nullable default value
- check("""
+ check(
+ """
import androidx.compose.runtime.*
val lambda: @Composable (() -> Unit)? = null
@@ -730,10 +826,12 @@
fun Bar(child: @Composable (() -> Unit)? = null) {
child?.invoke()
}
- """)
+ """
+ )
// Type inference for nullable @Composable lambdas, with a non-null default value
- check("""
+ check(
+ """
import androidx.compose.runtime.*
val lambda: @Composable (() -> Unit)? = null
@@ -750,20 +848,24 @@
fun Bar(child: @Composable (() -> Unit)? = {}) {
child?.invoke()
}
- """)
+ """
+ )
}
fun testComposableReporting049() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*
fun foo(<!WRONG_ANNOTATION_TARGET!>@Composable<!> bar: ()->Unit) {
println(bar)
}
- """)
+ """
+ )
}
fun testComposableReporting050() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable val foo: Int get() = 123
@@ -771,8 +873,10 @@
fun <!COMPOSABLE_EXPECTED!>App<!>() {
<!COMPOSABLE_INVOCATION!>foo<!>
}
- """)
- check("""
+ """
+ )
+ check(
+ """
import androidx.compose.runtime.*;
@Composable val foo: Int get() = 123
@@ -781,11 +885,13 @@
fun App() {
println(foo)
}
- """)
+ """
+ )
}
fun testComposableReporting051() {
- checkFail("""
+ checkFail(
+ """
import androidx.compose.runtime.*;
class A {
@@ -798,8 +904,10 @@
val a = A()
a.bar
}
- """)
- checkFail("""
+ """
+ )
+ checkFail(
+ """
import androidx.compose.runtime.*;
class A {
@@ -812,8 +920,10 @@
val a = A()
a.bam
}
- """)
- check("""
+ """
+ )
+ check(
+ """
import androidx.compose.runtime.*;
class A {
@@ -832,11 +942,13 @@
bam
}
}
- """)
+ """
+ )
}
fun testComposableReporting052() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable fun Foo() {}
@@ -845,9 +957,11 @@
<!COMPOSABLE_INVOCATION!>Foo<!>()
return 123
}
- """)
+ """
+ )
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable fun Foo() {}
@@ -856,11 +970,13 @@
Foo()
return 123
}
- """)
+ """
+ )
}
fun testComposableReporting053() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable fun foo(): Int = 123
@@ -869,11 +985,13 @@
val x = <!COMPOSABLE_INVOCATION!>foo<!>()
print(x)
}
- """)
+ """
+ )
}
fun testComposableReporting054() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable fun Foo() {}
@@ -904,11 +1022,13 @@
}
print(x)
}
- """)
+ """
+ )
}
fun testComposableReporting055() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable fun Foo() {}
@@ -934,11 +1054,13 @@
}
print(x)
}
- """)
+ """
+ )
}
fun testComposableReporting057() {
- check("""
+ check(
+ """
import androidx.compose.runtime.*;
@Composable fun App() {
@@ -950,6 +1072,7 @@
}
print(x)
}
- """)
+ """
+ )
}
}
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/ComposableDeclarationCheckerTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/ComposableDeclarationCheckerTests.kt
index cd1d414..51cb746 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/ComposableDeclarationCheckerTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/ComposableDeclarationCheckerTests.kt
@@ -30,7 +30,8 @@
@Composable
val <!COMPOSABLE_PROPERTY_BACKING_FIELD!>foo<!>: Int = 123
- """)
+ """
+ )
}
fun testPropertyWithJustGetter() {
@@ -40,7 +41,8 @@
@Composable
val bar: Int get() = 123
- """)
+ """
+ )
}
fun testPropertyWithGetterAndSetter() {
@@ -52,7 +54,8 @@
var <!COMPOSABLE_VAR!>bam<!>: Int
get() { return 123 }
set(value) { print(value) }
- """)
+ """
+ )
}
fun testSuspendComposable() {
@@ -74,6 +77,7 @@
acceptComposableSuspend(<!UNSUPPORTED_FEATURE!>composableLambda<!>)
acceptSuspend(<!COMPOSABLE_SUSPEND_FUN, TYPE_MISMATCH!>@Composable suspend fun() { }<!>)
}
- """)
+ """
+ )
}
}
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/TryCatchComposableCheckerTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/TryCatchComposableCheckerTests.kt
index 460e024..e89a6db 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/TryCatchComposableCheckerTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/TryCatchComposableCheckerTests.kt
@@ -37,7 +37,8 @@
} catch(e: Exception) {
}
}
- """)
+ """
+ )
}
fun testTryCatchReporting002() {
@@ -53,7 +54,8 @@
} catch(e: Exception) {
}
}
- """)
+ """
+ )
}
fun testTryCatchReporting003() {
@@ -71,7 +73,8 @@
foo()
}
}
- """)
+ """
+ )
}
fun testTryCatchReporting004() {
@@ -87,6 +90,7 @@
} catch(e: Exception) {
}
}
- """)
+ """
+ )
}
}
diff --git a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/UnionCheckerTests.kt b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/UnionCheckerTests.kt
index de10fa8..3e4c32b 100644
--- a/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/UnionCheckerTests.kt
+++ b/compose/compiler/compiler-hosted/integration-tests/src/test/java/androidx/compose/compiler/plugins/kotlin/analysis/UnionCheckerTests.kt
@@ -37,7 +37,8 @@
foo(value="1")
foo(value=<!ILLEGAL_ASSIGN_TO_UNIONTYPE!>1f<!>)
}
- """)
+ """
+ )
}
fun testUnionTypeReporting002() {
@@ -57,7 +58,8 @@
fun bar(value: @UnionType(Int::class, String::class) Any) {
foo(value)
}
- """)
+ """
+ )
}
fun testUnionTypeReporting003() {
@@ -77,7 +79,8 @@
fun bar(value: @UnionType(Int::class, String::class) Any) {
foo(value)
}
- """)
+ """
+ )
}
fun testUnionTypeReporting004() {
@@ -97,6 +100,7 @@
fun bar(value: @UnionType(Int::class, String::class, Float::class) Any) {
foo(<!ILLEGAL_ASSIGN_TO_UNIONTYPE!>value<!>)
}
- """)
+ """
+ )
}
}
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposableCallChecker.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposableCallChecker.kt
index 624f26a..ad1f2c1 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposableCallChecker.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposableCallChecker.kt
@@ -65,7 +65,9 @@
import org.jetbrains.kotlin.types.upperIfFlexible
import org.jetbrains.kotlin.util.OperatorNameConventions
-open class ComposableCallChecker : CallChecker, AdditionalTypeChecker,
+open class ComposableCallChecker :
+ CallChecker,
+ AdditionalTypeChecker,
StorageComponentContainerContributor {
override fun registerModuleComponents(
container: StorageComponentContainer,
@@ -116,9 +118,9 @@
}
// TODO(lmr): in future, we should check for CALLS_IN_PLACE contract
val inlined = arg != null &&
- canBeInlineArgument(node.functionLiteral) &&
- isInline(arg.containingDeclaration) &&
- isInlineParameter(arg)
+ canBeInlineArgument(node.functionLiteral) &&
+ isInline(arg.containingDeclaration) &&
+ isInlineParameter(arg)
if (!inlined) {
illegalCall(context, reportOn)
return
@@ -232,13 +234,15 @@
val anyType = expectedType.builtIns.anyType
if (anyType == expectedType.lowerIfFlexible() &&
- nullableAnyType == expectedType.upperIfFlexible()) return
+ nullableAnyType == expectedType.upperIfFlexible()
+ ) return
val nullableNothingType = expectedType.builtIns.nullableNothingType
// Handle assigning null to a nullable composable type
if (expectedType.isMarkedNullable &&
- expressionTypeWithSmartCast == nullableNothingType) return
+ expressionTypeWithSmartCast == nullableNothingType
+ ) return
val isComposable = expressionType.hasComposableAnnotation()
if (expectedComposable != isComposable) {
@@ -269,7 +273,8 @@
val candidateDescriptor = candidateDescriptor
if (candidateDescriptor is FunctionDescriptor) {
if (candidateDescriptor.isOperator &&
- candidateDescriptor.name == OperatorNameConventions.INVOKE) {
+ candidateDescriptor.name == OperatorNameConventions.INVOKE
+ ) {
if (dispatchReceiver?.type?.hasComposableAnnotation() == true) {
return true
}
@@ -339,8 +344,8 @@
// otherwise, this is only true if it is a lambda which can be capable of composer
// capture
return bindingContext[
- ComposeWritableSlices.LAMBDA_CAPABLE_OF_COMPOSER_CAPTURE,
- this
+ ComposeWritableSlices.LAMBDA_CAPABLE_OF_COMPOSER_CAPTURE,
+ this
] == true
}
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeDiagnosticSuppressor.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeDiagnosticSuppressor.kt
index e3966bd..cc26fef 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeDiagnosticSuppressor.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeDiagnosticSuppressor.kt
@@ -46,9 +46,11 @@
override fun isSuppressed(diagnostic: Diagnostic, bindingContext: BindingContext?): Boolean {
if (diagnostic.factory == Errors.NON_SOURCE_ANNOTATION_ON_INLINED_LAMBDA_EXPRESSION) {
- for (entry in (
+ for (
+ entry in (
diagnostic.psiElement.parent as KtAnnotatedExpression
- ).annotationEntries) {
+ ).annotationEntries
+ ) {
if (bindingContext != null) {
val annotation = bindingContext.get(BindingContext.ANNOTATION, entry)
if (annotation != null && annotation.isComposableAnnotation) return true
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeErrorMessages.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeErrorMessages.kt
index fed4706..7e39845 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeErrorMessages.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeErrorMessages.kt
@@ -36,7 +36,7 @@
MAP.put(
ComposeErrors.COMPOSABLE_EXPECTED,
"Functions which invoke @Composable functions must be marked with the @Composable " +
- "annotation"
+ "annotation"
)
MAP.put(
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeFqNames.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeFqNames.kt
index 8f7ec38..dde9624 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeFqNames.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeFqNames.kt
@@ -73,8 +73,9 @@
!isSpecialType && annotations.findAnnotation(ComposeFqNames.Composable) != null
fun KotlinType.isMarkedStable(): Boolean =
!isSpecialType && (
- annotations.hasStableMarker() ||
- (constructor.declarationDescriptor?.annotations?.hasStableMarker() ?: false))
+ annotations.hasStableMarker() ||
+ (constructor.declarationDescriptor?.annotations?.hasStableMarker() ?: false)
+ )
fun Annotated.hasComposableAnnotation(): Boolean =
annotations.findAnnotation(ComposeFqNames.Composable) != null
fun Annotated.composableRestartableContract(): Boolean? {
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeIrGenerationExtension.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeIrGenerationExtension.kt
index 1e8c217..6e7109e 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeIrGenerationExtension.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposeIrGenerationExtension.kt
@@ -43,8 +43,11 @@
// TODO: refactor transformers to work with just BackendContext
@Suppress("DEPRECATION")
- val bindingTrace = DelegatingBindingTrace(pluginContext.bindingContext, "trace in " +
- "ComposeIrGenerationExtension")
+ val bindingTrace = DelegatingBindingTrace(
+ pluginContext.bindingContext,
+ "trace in " +
+ "ComposeIrGenerationExtension"
+ )
// create a symbol remapper to be used across all transforms
val symbolRemapper = DeepCopySymbolRemapper()
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposePlugin.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposePlugin.kt
index 67f23f1..9675dbc 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposePlugin.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/ComposePlugin.kt
@@ -47,18 +47,18 @@
allowMultipleOccurrences = false
)
val SOURCE_INFORMATION_ENABLED_OPTION = CliOption(
- "sourceInformation",
- "<true|false>",
- "Include source information in generated code",
- required = false,
- allowMultipleOccurrences = false
+ "sourceInformation",
+ "<true|false>",
+ "Include source information in generated code",
+ required = false,
+ allowMultipleOccurrences = false
)
}
override val pluginId = PLUGIN_ID
override val pluginOptions = listOf(
- LIVE_LITERALS_ENABLED_OPTION,
- SOURCE_INFORMATION_ENABLED_OPTION
+ LIVE_LITERALS_ENABLED_OPTION,
+ SOURCE_INFORMATION_ENABLED_OPTION
)
override fun processOption(
@@ -128,7 +128,8 @@
project,
ComposeTypeResolutionInterceptorExtension()
)
- IrGenerationExtension.registerExtension(project,
+ IrGenerationExtension.registerExtension(
+ project,
ComposeIrGenerationExtension(
liveLiteralsEnabled = liveLiteralsEnabled,
sourceInformationEnabled = sourceInformationEnabled
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/UnionAnnotationChecker.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/UnionAnnotationChecker.kt
index 6ddbfce..9341b22 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/UnionAnnotationChecker.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/UnionAnnotationChecker.kt
@@ -62,7 +62,8 @@
if (TypeUtils.noExpectedType(expectedType)) return
if (!expectedType.annotations.hasAnnotation(UNIONTYPE_ANNOTATION_NAME) &&
- !expressionTypeWithSmartCast.annotations.hasAnnotation(UNIONTYPE_ANNOTATION_NAME)) {
+ !expressionTypeWithSmartCast.annotations.hasAnnotation(UNIONTYPE_ANNOTATION_NAME)
+ ) {
return
}
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/AbstractComposeLowering.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/AbstractComposeLowering.kt
index 7166395..1456aa8 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/AbstractComposeLowering.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/AbstractComposeLowering.kt
@@ -166,8 +166,9 @@
protected val builtIns = context.irBuiltIns
protected val composerTypeDescriptor = context.moduleDescriptor
- .findClassAcrossModuleDependencies(ClassId.topLevel(ComposeFqNames.Composer)
- ) ?: error("Cannot find the Composer class")
+ .findClassAcrossModuleDependencies(
+ ClassId.topLevel(ComposeFqNames.Composer)
+ ) ?: error("Cannot find the Composer class")
private val symbolTable get() = context.symbolTable
@@ -335,23 +336,23 @@
val calculated = trace.get(ComposeWritableSlices.STABLE_TYPE, this)
return if (calculated == null) {
val isStable = !isError &&
- !isTypeParameter() &&
- !isSpecialType &&
- (
- KotlinBuiltIns.isPrimitiveType(this) ||
- isFunctionOrKFunctionType ||
- isEnum ||
- KotlinBuiltIns.isString(this) ||
- isMarkedStable() ||
- (
- isNullable() &&
- makeNotNullable().isStable()
- ) ||
- (
- isInlineClassType() &&
- unsubstitutedUnderlyingType().isStable()
- )
+ !isTypeParameter() &&
+ !isSpecialType &&
+ (
+ KotlinBuiltIns.isPrimitiveType(this) ||
+ isFunctionOrKFunctionType ||
+ isEnum ||
+ KotlinBuiltIns.isString(this) ||
+ isMarkedStable() ||
+ (
+ isNullable() &&
+ makeNotNullable().isStable()
+ ) ||
+ (
+ isInlineClassType() &&
+ unsubstitutedUnderlyingType().isStable()
)
+ )
trace.record(ComposeWritableSlices.STABLE_TYPE, this, isStable)
isStable
} else calculated
@@ -984,6 +985,6 @@
fun ValueParameterDescriptor.isComposerParam(): Boolean =
name == KtxNameConventions.COMPOSER_PARAMETER &&
- type.constructor.declarationDescriptor?.fqNameSafe == ComposeFqNames.Composer
+ type.constructor.declarationDescriptor?.fqNameSafe == ComposeFqNames.Composer
object COMPOSE_STATEMENT_ORIGIN : IrStatementOriginImpl("COMPOSE_STATEMENT_ORIGIN")
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableFunctionBodyTransformer.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableFunctionBodyTransformer.kt
index cf81dab..fef7a82 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableFunctionBodyTransformer.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableFunctionBodyTransformer.kt
@@ -208,9 +208,9 @@
val IrFunction.thisParamCount
get() = (
if (dispatchReceiverParameter != null) 1 else 0
- ) + (
+ ) + (
if (extensionReceiverParameter != null) 1 else 0
- )
+ )
fun changedParamCount(realValueParams: Int, thisParams: Int): Int {
if (realValueParams == 0) return 1
@@ -244,8 +244,8 @@
hasDefaults: Boolean = false
): Int {
return 1 + // composer param
- changedParamCount(realValueParams, thisParams) +
- if (hasDefaults) defaultParamCount(realValueParams) else 0
+ changedParamCount(realValueParams, thisParams) +
+ if (hasDefaults) defaultParamCount(realValueParams) else 0
}
interface IrChangedBitMaskValue {
@@ -620,7 +620,7 @@
// we use != false because a null value is treated as "tracked"
val isTracked = declaration.descriptor.composableTrackedContract() != false &&
- declaration.returnType.isUnit()
+ declaration.returnType.isUnit()
if (declaration.body == null) return declaration
@@ -695,7 +695,8 @@
// Lambdas should be ignored. All composable lambdas are wrapped by a restartable
// function wrapper by ComposerLambdaMemoization which supplies the startRestartGroup/
// endRestartGroup pair on behalf of the lambda.
- origin != IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA) {
+ origin != IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
+ ) {
return true
}
@@ -826,10 +827,10 @@
// don't need to have the dirty parameter locally since it will never be different from
// the passed in `changed` parameter.
val dirty = if (canSkipExecution && realParamsIncludingThis.isNotEmpty())
- // NOTE(lmr): Technically, dirty is a mutable variable, but we don't want to mark it
- // as one since that will cause a `Ref<Int>` to get created if it is captured. Since
- // we know we will never be mutating this variable _after_ it gets captured, we can
- // safely mark this as `isVar = false`.
+ // NOTE(lmr): Technically, dirty is a mutable variable, but we don't want to mark it
+ // as one since that will cause a `Ref<Int>` to get created if it is captured. Since
+ // we know we will never be mutating this variable _after_ it gets captured, we can
+ // safely mark this as `isVar = false`.
changedParam.irCopyToTemporary(
isVar = false,
nameHint = "\$dirty",
@@ -968,10 +969,10 @@
// don't need to have the dirty parameter locally since it will never be different from
// the passed in `changed` parameter.
val dirty = if (canSkipExecution && realParamsIncludingThis.isNotEmpty())
- // NOTE(lmr): Technically, dirty is a mutable variable, but we don't want to mark it
- // as one since that will cause a `Ref<Int>` to get created if it is captured. Since
- // we know we will never be mutating this variable _after_ it gets captured, we can
- // safely mark this as `isVar = false`.
+ // NOTE(lmr): Technically, dirty is a mutable variable, but we don't want to mark it
+ // as one since that will cause a `Ref<Int>` to get created if it is captured. Since
+ // we know we will never be mutating this variable _after_ it gets captured, we can
+ // safely mark this as `isVar = false`.
changedParam.irCopyToTemporary(
isVar = false,
nameHint = "\$dirty",
@@ -1149,26 +1150,28 @@
return when {
!isStable && isUsed -> false
isStable && isUsed && canSkipExecution && dirty is IrChangedBitMaskVariable -> {
- preamble.statements.add(irIf(
- // we only call `$composer.changed(...)` on a parameter if the value came in
- // with an "Uncertain" state AND the value was provided. This is safe to do
- // because this will remain true or false for *every* execution of the
- // function, so we will never get a slot table misalignment as a result.
- condition = irIsUncertain(changedParam, index),
- body = dirty.irOrSetBitsAtSlot(
- index,
- irIfThenElse(
- context.irBuiltIns.intType,
- irChanged(irGet(thisParam)),
- // if the value has changed, update the bits in the slot to be
- // "Different"
- thenPart = irConst(ParamState.Different.bitsForSlot(index)),
- // if the value has not changed, update the bits in the slot to
- // be "Same"
- elsePart = irConst(ParamState.Same.bitsForSlot(index))
+ preamble.statements.add(
+ irIf(
+ // we only call `$composer.changed(...)` on a parameter if the value came in
+ // with an "Uncertain" state AND the value was provided. This is safe to do
+ // because this will remain true or false for *every* execution of the
+ // function, so we will never get a slot table misalignment as a result.
+ condition = irIsUncertain(changedParam, index),
+ body = dirty.irOrSetBitsAtSlot(
+ index,
+ irIfThenElse(
+ context.irBuiltIns.intType,
+ irChanged(irGet(thisParam)),
+ // if the value has changed, update the bits in the slot to be
+ // "Different"
+ thenPart = irConst(ParamState.Different.bitsForSlot(index)),
+ // if the value has not changed, update the bits in the slot to
+ // be "Same"
+ elsePart = irConst(ParamState.Same.bitsForSlot(index))
+ )
)
)
- ))
+ )
true
}
!isUsed && canSkipExecution && dirty is IrChangedBitMaskVariable -> {
@@ -1176,10 +1179,12 @@
// execution of the function, then we need to make sure that we are only
// considering the not-ignored parameters. to do this, we set the changed slot bits
// to Static
- preamble.statements.add(dirty.irOrSetBitsAtSlot(
- index,
- irConst(ParamState.Static.bitsForSlot(index))
- ))
+ preamble.statements.add(
+ dirty.irOrSetBitsAtSlot(
+ index,
+ irConst(ParamState.Static.bitsForSlot(index))
+ )
+ )
}
// nothing changes
else -> canSkipExecution
@@ -1414,25 +1419,27 @@
// for (value in values) {
// dirty = dirty or if (composer.changed(value)) 0b0100 else 0b0000
// }
- skipPreamble.statements.add(irForLoop(
- scope.function.symbol.descriptor,
- varargElementType,
- irGet(param)
- ) { loopVar ->
- dirty.irOrSetBitsAtSlot(
- index,
- irIfThenElse(
- context.irBuiltIns.intType,
- irChanged(irGet(loopVar)),
- // if the value has changed, update the bits in the slot to be
- // "Different".
- thenPart = irConst(ParamState.Different.bitsForSlot(index)),
- // if the value has not changed, we are still uncertain if the entire
- // list of values has gone unchanged or not, so we use Uncertain
- elsePart = irConst(ParamState.Uncertain.bitsForSlot(index))
+ skipPreamble.statements.add(
+ irForLoop(
+ scope.function.symbol.descriptor,
+ varargElementType,
+ irGet(param)
+ ) { loopVar ->
+ dirty.irOrSetBitsAtSlot(
+ index,
+ irIfThenElse(
+ context.irBuiltIns.intType,
+ irChanged(irGet(loopVar)),
+ // if the value has changed, update the bits in the slot to be
+ // "Different".
+ thenPart = irConst(ParamState.Different.bitsForSlot(index)),
+ // if the value has not changed, we are still uncertain if the entire
+ // list of values has gone unchanged or not, so we use Uncertain
+ elsePart = irConst(ParamState.Uncertain.bitsForSlot(index))
+ )
)
- )
- })
+ }
+ )
// composer.endReplaceableGroup()
skipPreamble.statements.add(irEndReplaceableGroup())
@@ -1440,13 +1447,15 @@
// if (dirty and 0b0110 === 0) {
// dirty = dirty or 0b0010
// }
- skipPreamble.statements.add(irIf(
- condition = irIsUncertain(dirty, index),
- body = dirty.irOrSetBitsAtSlot(
- index,
- irConst(ParamState.Same.bitsForSlot(index))
+ skipPreamble.statements.add(
+ irIf(
+ condition = irIsUncertain(dirty, index),
+ body = dirty.irOrSetBitsAtSlot(
+ index,
+ irConst(ParamState.Same.bitsForSlot(index))
+ )
)
- ))
+ )
}
}
// after all of this, we need to potentially wrap the default setters in a group and if
@@ -1604,56 +1613,58 @@
}
// Call the function again with the same parameters
- +irReturn(irCall(function.symbol).apply {
- symbol.owner
- .valueParameters
- .forEachIndexed { index, param ->
- if (param.isVararg) {
- putValueArgument(
- index,
- IrVarargImpl(
- UNDEFINED_OFFSET,
- UNDEFINED_OFFSET,
- param.type,
- param.varargElementType!!,
- elements = listOf(
- IrSpreadElementImpl(
- UNDEFINED_OFFSET,
- UNDEFINED_OFFSET,
- irGet(remappedParam(index))
+ +irReturn(
+ irCall(function.symbol).apply {
+ symbol.owner
+ .valueParameters
+ .forEachIndexed { index, param ->
+ if (param.isVararg) {
+ putValueArgument(
+ index,
+ IrVarargImpl(
+ UNDEFINED_OFFSET,
+ UNDEFINED_OFFSET,
+ param.type,
+ param.varargElementType!!,
+ elements = listOf(
+ IrSpreadElementImpl(
+ UNDEFINED_OFFSET,
+ UNDEFINED_OFFSET,
+ irGet(remappedParam(index))
+ )
)
)
)
- )
- } else {
- // NOTE(lmr): should we be using the parameter here, or the temporary
- // with the default value?
- putValueArgument(index, irGet(remappedParam(index)))
+ } else {
+ // NOTE(lmr): should we be using the parameter here, or the temporary
+ // with the default value?
+ putValueArgument(index, irGet(remappedParam(index)))
+ }
}
+
+ // new composer
+ putValueArgument(
+ numRealValueParameters,
+ irGet(fn.valueParameters[0])
+ )
+
+ // the call in updateScope needs to *always* have the low bit set to 1.
+ // This ensures that the body of the function is actually executed.
+ changedParam.putAsValueArgumentInWithLowBit(
+ this,
+ changedIndex,
+ lowBit = true
+ )
+
+ defaultParam?.putAsValueArgumentIn(this, defaultIndex)
+
+ extensionReceiver = function.extensionReceiverParameter?.let { irGet(it) }
+ dispatchReceiver = outerReceiver?.let { irGet(it) }
+ function.typeParameters.forEachIndexed { index, parameter ->
+ putTypeArgument(index, parameter.defaultType)
}
-
- // new composer
- putValueArgument(
- numRealValueParameters,
- irGet(fn.valueParameters[0])
- )
-
- // the call in updateScope needs to *always* have the low bit set to 1.
- // This ensures that the body of the function is actually executed.
- changedParam.putAsValueArgumentInWithLowBit(
- this,
- changedIndex,
- lowBit = true
- )
-
- defaultParam?.putAsValueArgumentIn(this, defaultIndex)
-
- extensionReceiver = function.extensionReceiverParameter?.let { irGet(it) }
- dispatchReceiver = outerReceiver?.let { irGet(it) }
- function.typeParameters.forEachIndexed { index, parameter ->
- putTypeArgument(index, parameter.defaultType)
}
- })
+ )
}
}
@@ -1769,7 +1780,7 @@
private fun nearestComposer(): IrValueParameter =
currentScope.nearestComposer
- ?: error("Not in a composable function \n${printScopeStack()}")
+ ?: error("Not in a composable function \n${printScopeStack()}")
private fun irCurrentComposer(): IrExpression {
return IrGetValueImpl(
@@ -2383,18 +2394,20 @@
val after = newLoop.statements[2] as IrContainerExpressionBase
val result = mutableStatementContainer()
- result.statements.addAll(listOf(
- before,
- irBlock(
- type = expression.type,
- origin = IrStatementOrigin.FOR_LOOP,
- statements = listOf(
- newVar,
- loop
- )
- ),
- after
- ))
+ result.statements.addAll(
+ listOf(
+ before,
+ irBlock(
+ type = expression.type,
+ origin = IrStatementOrigin.FOR_LOOP,
+ statements = listOf(
+ newVar,
+ loop
+ )
+ ),
+ after
+ )
+ )
result
} else {
error("Expected transformed loop to be an IrBlock")
@@ -2425,7 +2438,7 @@
}
}
collectSourceInformation &&
- expression.symbol.descriptor.fqNameSafe == ComposeFqNames.composableLambda -> {
+ expression.symbol.descriptor.fqNameSafe == ComposeFqNames.composableLambda -> {
// For calls to `composableLambda` we introduce a scope to collect the source
// locations on the top level of the lambda as the startRestartGroup is in the
// composable lambda wrapper.
@@ -2470,8 +2483,8 @@
numDefaults = 0
numChanged = changedParamCountFromTotal(numValueParams + ownerFn.thisParamCount)
numRealValueParams = numValueParams -
- 1 - // composer param
- numChanged
+ 1 - // composer param
+ numChanged
} else {
val hasDefaults = ownerFn.valueParameters.any {
it.name == KtxNameConventions.DEFAULT_PARAMETER
@@ -2485,9 +2498,10 @@
require(
numRealValueParams +
- 1 + // composer param
- numChanged +
- numDefaults == numValueParams)
+ 1 + // composer param
+ numChanged +
+ numDefaults == numValueParams
+ )
val composerIndex = numRealValueParams
val changedArgIndex = composerIndex + 1
@@ -2589,10 +2603,12 @@
calculationArg = arg
}
arg is IrVararg -> {
- inputArgs.addAll(arg.elements.mapNotNull {
- if (it is IrSpreadElement) hasSpreadArgs = true
- it as? IrExpression
- })
+ inputArgs.addAll(
+ arg.elements.mapNotNull {
+ if (it is IrSpreadElement) hasSpreadArgs = true
+ it as? IrExpression
+ }
+ )
}
else -> {
inputArgs.add(arg)
@@ -2686,8 +2702,8 @@
val arg = expression.getValueArgument(i)
?: error("Unexpected null argument found on key call")
if (param.name.asString().startsWith('$'))
- // we are done. synthetic args go at
- // the end
+ // we are done. synthetic args go at
+ // the end
break
when {
@@ -2772,7 +2788,7 @@
// stable return type , then reading the property can also be considered
// static if this is a top level property or the subject is also static.
if (!prop.isVar &&
- prop.getter?.origin == IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR &&
+ prop.getter?.origin == IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR &&
typeIsStable &&
dispatchReceiverIsStatic && extensionReceiverIsStatic
) {
@@ -2780,7 +2796,7 @@
}
val getterIsStable = prop.hasStableAnnotation() ||
- symbol.owner.hasStableAnnotation()
+ symbol.owner.hasStableAnnotation()
if (
getterIsStable &&
@@ -2813,7 +2829,7 @@
.descriptor
.fqNameSafe
.topLevelName() == "kotlin" ||
- symbol.owner.hasStableAnnotation()
+ symbol.owner.hasStableAnnotation()
val typeIsStable = type.toKotlinType().isStable()
if (!typeIsStable) return false
@@ -2829,7 +2845,7 @@
// if it is a call to remember with 0 input arguments, then we can
// consider the value static if the result type of the lambda is stable
val syntheticRememberParams = 1 + // composer param
- 1 // changed param
+ 1 // changed param
val expectedArgumentsCount = 1 + syntheticRememberParams // 1 for lambda
if (
valueArgumentsCount == expectedArgumentsCount &&
@@ -3000,8 +3016,9 @@
val endBlock = mutableStatementContainer()
encounteredReturn(expression.returnTargetSymbol) { endBlock.statements.add(it) }
return if (expression.value.type
- .also { if (it is IrSimpleType) it.classifier.bindIfNecessary() }
- .isUnitOrNullableUnit()) {
+ .also { if (it is IrSimpleType) it.classifier.bindIfNecessary() }
+ .isUnitOrNullableUnit()
+ ) {
expression.wrap(listOf(endBlock))
} else {
val tempVar = irTemporary(expression.value, nameHint = "return")
@@ -3279,12 +3296,13 @@
val parameters = function.valueParameters.filter {
!it.name.asString().startsWith("$")
}
- val sortIndex = mapOf(*parameters.mapIndexed { index, parameter ->
+ val sortIndex = mapOf(
+ *parameters.mapIndexed { index, parameter ->
Pair(index, parameter)
}.sortedBy { it.second.name.asString() }
- .mapIndexed { sortIndex, originalIndex ->
- Pair(originalIndex.first, sortIndex)
- }.toTypedArray()
+ .mapIndexed { sortIndex, originalIndex ->
+ Pair(originalIndex.first, sortIndex)
+ }.toTypedArray()
)
val expectedIndexes = Array(parameters.size) { it }.toMutableList()
@@ -3306,7 +3324,8 @@
parameter.type.classifierOrNull?.bindIfNecessary()
}
if (expectedIndexes.first() == sortIndex[originalIndex] &&
- !parameter.type.isInlined()) {
+ !parameter.type.isInlined()
+ ) {
run++
expectedIndexes.removeAt(0)
} else {
@@ -3319,9 +3338,10 @@
if (parameter.type.isInlined()) {
parameter.type.getClass()?.fqNameWhenAvailable?.let {
builder.append(':')
- builder.append(it.asString()
- .replacePrefix("androidx.compose.", "c#")
- .replacePrefix("androidx.ui.", "u#")
+ builder.append(
+ it.asString()
+ .replacePrefix("androidx.compose.", "c#")
+ .replacePrefix("androidx.ui.", "u#")
)
}
}
@@ -3359,7 +3379,7 @@
super.calculateSourceInfo(sourceInformationEnabled)
} else {
"${callInformation()}${parameterInformation()}${
- super.calculateSourceInfo(sourceInformationEnabled) ?: ""
+ super.calculateSourceInfo(sourceInformationEnabled) ?: ""
}:${sourceFileInformation()}"
}
} else {
@@ -3515,7 +3535,7 @@
val lineNumber = fileEntry?.getLineNumber(it.element.startOffset) ?: ""
val offset = if (it.element.startOffset < it.element.endOffset) {
"@${it.element.startOffset}L${
- it.element.endOffset - it.element.startOffset
+ it.element.endOffset - it.element.startOffset
}"
} else "@${it.element.startOffset}"
if (it.repeatable && !markedRepeatable) {
@@ -3596,7 +3616,7 @@
override fun calculateSourceInfo(sourceInformationEnabled: Boolean): String? =
if (sourceInformationEnabled) {
"C${
- super.calculateSourceInfo(sourceInformationEnabled) ?: ""
+ super.calculateSourceInfo(sourceInformationEnabled) ?: ""
}:${functionScope?.sourceFileInformation() ?: ""}"
} else {
null
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableTypeRemapper.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableTypeRemapper.kt
index abbe496..d89d427 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableTypeRemapper.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposableTypeRemapper.kt
@@ -169,8 +169,10 @@
) {
val typeArguments = containingClass.defaultType.arguments
@Suppress("DEPRECATION")
- val newFnClass = context.symbolTable.referenceClass(context.builtIns
- .getFunction(typeArguments.size))
+ val newFnClass = context.symbolTable.referenceClass(
+ context.builtIns
+ .getFunction(typeArguments.size)
+ )
@Suppress("DEPRECATION")
val newDescriptor = newFnClass
.descriptor
@@ -360,17 +362,17 @@
}
val newIrArguments =
oldIrArguments.subList(0, oldIrArguments.size - 1) +
- extraArgs +
- oldIrArguments.last()
+ extraArgs +
+ oldIrArguments.last()
return IrSimpleTypeImpl(
null,
symbolRemapper.getReferencedClassifier(
context.symbolTable.referenceClass(
context
- .irBuiltIns
- .builtIns
- .getFunction(oldIrArguments.size - 1 + extraArgs.size)
+ .irBuiltIns
+ .builtIns
+ .getFunction(oldIrArguments.size - 1 + extraArgs.size)
)
),
type.hasQuestionMark,
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerIntrinsicTransformer.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerIntrinsicTransformer.kt
index fd374d3..d5bc2b8 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerIntrinsicTransformer.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerIntrinsicTransformer.kt
@@ -48,7 +48,7 @@
// to this call is the composer itself. We just replace this expression with the
// argument expression and we are good.
val expectedArgumentsCount = 1 + // composer parameter
- 1 // changed parameter
+ 1 // changed parameter
assert(expression.valueArgumentsCount == expectedArgumentsCount) {
expression.dump()
}
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerLambdaMemoization.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerLambdaMemoization.kt
index c8660eb..f849792 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerLambdaMemoization.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerLambdaMemoization.kt
@@ -207,11 +207,11 @@
val descriptor = declaration.descriptor
val composable = descriptor.allowsComposableCalls()
val canRemember = composable &&
- // Don't use remember in an inline function
- !descriptor.isInline &&
- // Don't use remember if in a composable that returns a value
- // TODO(b/150390108): Consider allowing remember in effects
- descriptor.returnType.let { it != null && it.isUnit() }
+ // Don't use remember in an inline function
+ !descriptor.isInline &&
+ // Don't use remember if in a composable that returns a value
+ // TODO(b/150390108): Consider allowing remember in effects
+ descriptor.returnType.let { it != null && it.isUnit() }
declarationContextStack.push(FunctionContext(declaration, composable, canRemember))
val result = super.visitFunction(declaration)
@@ -248,8 +248,9 @@
val dispatchReceiver = expression.dispatchReceiver
val extensionReceiver = expression.extensionReceiver
if ((dispatchReceiver != null || extensionReceiver != null) &&
- dispatchReceiver.isNullOrStable() &&
- extensionReceiver.isNullOrStable()) {
+ dispatchReceiver.isNullOrStable() &&
+ extensionReceiver.isNullOrStable()
+ ) {
// Save the receivers into a temporaries and memoize the function reference using
// the resulting temporaries
val builder = DeclarationIrBuilder(
@@ -282,7 +283,8 @@
expression.type,
expression.symbol,
expression.typeArgumentsCount,
- expression.reflectionTarget).copyAttributes(expression).apply {
+ expression.reflectionTarget
+ ).copyAttributes(expression).apply {
this.dispatchReceiver = tempDispatchReceiver?.let { irGet(it) }
this.extensionReceiver = tempExtensionReceiver?.let { irGet(it) }
},
@@ -308,7 +310,8 @@
// Don't memoize inlined lambdas
expression.isInlineArgument() ||
// Don't memoize untracked function
- !expression.isTracked()) {
+ !expression.isTracked()
+ ) {
return super.visitFunctionExpression(expression)
}
@@ -384,10 +387,11 @@
else COMPOSABLE_LAMBDA
else if (useComposableLambdaN)
COMPOSABLE_LAMBDA_N_INSTANCE
- else COMPOSABLE_LAMBDA_INSTANCE
+ else COMPOSABLE_LAMBDA_INSTANCE
val restartFactorySymbol =
getTopLevelFunction(ComposeFqNames.internalFqNameFor(restartFunctionFactory))
- val irBuilder = DeclarationIrBuilder(context,
+ val irBuilder = DeclarationIrBuilder(
+ context,
symbol = declarationContext.symbol,
startOffset = expression.startOffset,
endOffset = expression.endOffset
@@ -407,7 +411,8 @@
// key parameter
putValueArgument(
- index++, irBuilder.irInt(
+ index++,
+ irBuilder.irInt(
@Suppress("DEPRECATION")
symbol.descriptor.fqNameSafe.hashCode() xor expression.startOffset
)
@@ -427,9 +432,11 @@
putValueArgument(index++, irBuilder.irInt(argumentCount))
}
if (index >= valueArgumentsCount) {
- error("function = ${
+ error(
+ "function = ${
function.name.asString()
- }, count = $valueArgumentsCount, index = $index")
+ }, count = $valueArgumentsCount, index = $index"
+ )
}
// block parameter
@@ -444,7 +451,8 @@
): IrExpression {
if (captures.any {
!((it as? IrVariable)?.isVar != true && it.type.toKotlinType().isStable())
- }) return expression
+ }
+ ) return expression
val rememberParameterCount = captures.size + 1 // One additional parameter for the lambda
val declaration = functionContext.declaration
val descriptor = declaration.descriptor
@@ -459,8 +467,8 @@
val directRememberFunction = // Exclude the varargs version
rememberFunctions.singleOrNull {
it.valueParameters.size == rememberParameterCount &&
- // Exclude the varargs version
- it.valueParameters.firstOrNull()?.varargElementType == null
+ // Exclude the varargs version
+ it.valueParameters.firstOrNull()?.varargElementType == null
}
val rememberFunctionDescriptor = directRememberFunction
?: rememberFunctions.single {
@@ -499,7 +507,8 @@
} else {
val parameterType = rememberFunctionDescriptor.valueParameters[0].type.toIrType()
// Call to the vararg version
- putValueArgument(0,
+ putValueArgument(
+ 0,
IrVarargImpl(
startOffset = UNDEFINED_OFFSET,
endOffset = UNDEFINED_OFFSET,
@@ -513,15 +522,18 @@
1
}
- putValueArgument(lambdaArgumentIndex, irBuilder.irLambdaExpression(
- descriptor = irBuilder.createFunctionDescriptor(
- rememberFunctionDescriptor.valueParameters.last().type
- ),
- type = rememberFunctionDescriptor.valueParameters.last().type.toIrType(),
- body = {
- +irReturn(expression)
- }
- ))
+ putValueArgument(
+ lambdaArgumentIndex,
+ irBuilder.irLambdaExpression(
+ descriptor = irBuilder.createFunctionDescriptor(
+ rememberFunctionDescriptor.valueParameters.last().type
+ ),
+ type = rememberFunctionDescriptor.valueParameters.last().type.toIrType(),
+ body = {
+ +irReturn(expression)
+ }
+ )
+ )
}.patchDeclarationParents(declaration).markAsSynthetic(mark = true)
}
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerParamTransformer.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerParamTransformer.kt
index 2a9f532..b7831b4 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerParamTransformer.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ComposerParamTransformer.kt
@@ -447,12 +447,15 @@
ctor,
0, 0, 1
).also {
- it.putValueArgument(0, IrConstImpl.string(
- UNDEFINED_OFFSET,
- UNDEFINED_OFFSET,
- builtIns.stringType,
- name
- ))
+ it.putValueArgument(
+ 0,
+ IrConstImpl.string(
+ UNDEFINED_OFFSET,
+ UNDEFINED_OFFSET,
+ builtIns.stringType,
+ name
+ )
+ )
}
}
@@ -460,9 +463,11 @@
// we only add a default mask parameter if one of the parameters has a default
// expression. Note that if this is a "fake override" method, then only the overridden
// symbols will have the default value expressions
- return this is IrSimpleFunction && (valueParameters.any {
- it.defaultValue != null
- } || overriddenSymbols.any { it.owner.requiresDefaultParameter() })
+ return this is IrSimpleFunction && (
+ valueParameters.any {
+ it.defaultValue != null
+ } || overriddenSymbols.any { it.owner.requiresDefaultParameter() }
+ )
}
private fun IrFunction.copyWithComposerParam(): IrFunction {
@@ -584,13 +589,15 @@
if (expression.returnTargetSymbol == oldFn.symbol) {
// update the return statement to point to the new function, or else
// it will be interpreted as a non-local return
- return super.visitReturn(IrReturnImpl(
- expression.startOffset,
- expression.endOffset,
- expression.type,
- fn.symbol,
- expression.value
- ))
+ return super.visitReturn(
+ IrReturnImpl(
+ expression.startOffset,
+ expression.endOffset,
+ expression.type,
+ fn.symbol,
+ expression.value
+ )
+ )
}
generateSymbols(context)
return super.visitReturn(expression)
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/IrSourcePrinter.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/IrSourcePrinter.kt
index a55c97d..5f430ac 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/IrSourcePrinter.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/IrSourcePrinter.kt
@@ -116,16 +116,16 @@
accept(IrSourcePrinterVisitor(sb), null)
return sb
.toString()
- // replace tabs at beginning of line with white space
+ // replace tabs at beginning of line with white space
.replace(Regex("\\n(%tab%)+", RegexOption.MULTILINE)) {
val size = it.range.last - it.range.first - 1
"\n" + (0..(size / 5)).joinToString("") { " " }
}
- // tabs that are inserted in the middle of lines should be replaced with empty strings
+ // tabs that are inserted in the middle of lines should be replaced with empty strings
.replace(Regex("%tab%", RegexOption.MULTILINE), "")
- // remove empty lines
+ // remove empty lines
.replace(Regex("\\n(\\s)*$", RegexOption.MULTILINE), "")
- // brackets with comma on new line
+ // brackets with comma on new line
.replace(Regex("}\\n(\\s)*,", RegexOption.MULTILINE), "},")
}
@@ -326,7 +326,7 @@
expression.dispatchReceiver?.type?.isInt() == true -> true
expression.extensionReceiver?.type?.isInt() == true -> true
expression.valueArgumentsCount > 0 &&
- expression.getValueArgument(0)?.type?.isInt() == true -> true
+ expression.getValueArgument(0)?.type?.isInt() == true -> true
else -> false
}
else -> false
@@ -460,8 +460,8 @@
if (arg != null) {
val param = symbol.owner.valueParameters[i]
val isTrailingLambda = i == symbol.owner.valueParameters.size - 1 &&
- (
- arg is IrFunctionExpression ||
+ (
+ arg is IrFunctionExpression ||
(arg is IrBlock && arg.origin == IrStatementOrigin.LAMBDA)
)
if (isTrailingLambda) {
@@ -659,7 +659,7 @@
}
expression.branches.forEachIndexed { index, branch ->
val isElse = index == expression.branches.size - 1 &&
- (branch.condition as? IrConst<*>)?.value == true
+ (branch.condition as? IrConst<*>)?.value == true
when {
index == 0 -> {
print("if (")
@@ -1087,7 +1087,7 @@
override fun visitTypeParameter(declaration: IrTypeParameter) {
print(declaration.name)
val isNonEmpty = declaration.superTypes.isNotEmpty() &&
- !declaration.superTypes[0].isNullableAny()
+ !declaration.superTypes[0].isNullableAny()
if (isNonEmpty) {
print(": ")
print(declaration.superTypes.joinToString(", ") { it.renderSrc() })
diff --git a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/LiveLiteralTransformer.kt b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/LiveLiteralTransformer.kt
index d4da8ec..523eaa9 100644
--- a/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/LiveLiteralTransformer.kt
+++ b/compose/compiler/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/LiveLiteralTransformer.kt
@@ -323,11 +323,13 @@
// return b.value
+irIf(
condition = irNot(irCall(isLiveLiteralsEnabled)),
- body = irReturn(irGet(
- literalType,
- irGet(thisParam),
- defaultProp.getter!!.symbol
- ))
+ body = irReturn(
+ irGet(
+ literalType,
+ irGet(thisParam),
+ defaultProp.getter!!.symbol
+ )
+ )
)
val a = irTemporary(irGet(stateType, irGet(thisParam), stateProp.getter!!.symbol))
val b = irIfNull(
@@ -336,11 +338,14 @@
thenPart = irBlock(resultType = stateType) {
val liveLiteralCall = irCall(liveLiteral).apply {
putValueArgument(0, irString(key))
- putValueArgument(1, irGet(
- literalType,
- irGet(thisParam),
- defaultProp.getter!!.symbol
- ))
+ putValueArgument(
+ 1,
+ irGet(
+ literalType,
+ irGet(thisParam),
+ defaultProp.getter!!.symbol
+ )
+ )
putTypeArgument(0, literalType)
}
val c = irTemporary(liveLiteralCall)
@@ -394,12 +399,12 @@
error(
"Duplicate live literal key found: $key\n" +
- "Caused by element at: " +
- "${src.filePath}:${src.startLineNumber}:${src.startColumnNumber}\n" +
- "If you encounter this error, please file a bug at " +
- "https://issuetracker.google.com/issues?q=componentid:610764\n" +
- "Try adding the `@NoLiveLiterals` annotation around the surrounding code to " +
- "avoid this exception."
+ "Caused by element at: " +
+ "${src.filePath}:${src.startLineNumber}:${src.startColumnNumber}\n" +
+ "If you encounter this error, please file a bug at " +
+ "https://issuetracker.google.com/issues?q=componentid:610764\n" +
+ "Try adding the `@NoLiveLiterals` annotation around the surrounding code to " +
+ "avoid this exception."
)
}
// If live literals are enabled, don't do anything
diff --git a/compose/internal-lint-checks/src/main/java/androidx/compose/lint/PackageNameMigrationDetector.kt b/compose/internal-lint-checks/src/main/java/androidx/compose/lint/PackageNameMigrationDetector.kt
index d70f29e..769c3ca 100644
--- a/compose/internal-lint-checks/src/main/java/androidx/compose/lint/PackageNameMigrationDetector.kt
+++ b/compose/internal-lint-checks/src/main/java/androidx/compose/lint/PackageNameMigrationDetector.kt
@@ -49,7 +49,7 @@
node,
context.getLocation(node),
"The package name '$packageName' has been migrated to '$newPackageName', " +
- "please update the package name of this file accordingly."
+ "please update the package name of this file accordingly."
)
}
}
@@ -91,9 +91,9 @@
"PackageNameMigration",
"Using an old package name that has recently been migrated to androidx.compose",
"As part of a large migration from androidx.ui to androidx.compose, package names " +
- "across all libraries are being refactored. If you are seeing this Lint " +
- "error, you are adding new files to the old package name, once the rest of " +
- "the library has migrated to the new package name.",
+ "across all libraries are being refactored. If you are seeing this Lint " +
+ "error, you are adding new files to the old package name, once the rest of " +
+ "the library has migrated to the new package name.",
Category.PERFORMANCE, 5, Severity.ERROR,
Implementation(
PackageNameMigrationDetector::class.java,
diff --git a/compose/internal-lint-checks/src/main/java/androidx/compose/lint/UnnecessaryLambdaCreationDetector.kt b/compose/internal-lint-checks/src/main/java/androidx/compose/lint/UnnecessaryLambdaCreationDetector.kt
index 754107d..ca0f454 100644
--- a/compose/internal-lint-checks/src/main/java/androidx/compose/lint/UnnecessaryLambdaCreationDetector.kt
+++ b/compose/internal-lint-checks/src/main/java/androidx/compose/lint/UnnecessaryLambdaCreationDetector.kt
@@ -167,9 +167,9 @@
private const val explanation =
"Creating this extra lambda instead of just passing the already captured lambda means" +
- " that during code generation the Compose compiler will insert code around " +
- "this lambda to track invalidations. This adds some extra runtime cost so you" +
- " should instead just directly pass the lambda as a parameter to the function."
+ " that during code generation the Compose compiler will insert code around " +
+ "this lambda to track invalidations. This adds some extra runtime cost so you" +
+ " should instead just directly pass the lambda as a parameter to the function."
val ISSUE = Issue.create(
"UnnecessaryLambdaCreation",
diff --git a/compose/internal-lint-checks/src/test/java/androidx/compose/lint/UnnecessaryLambdaCreationDetectorTest.kt b/compose/internal-lint-checks/src/test/java/androidx/compose/lint/UnnecessaryLambdaCreationDetectorTest.kt
index 013cf34..20b95ca 100644
--- a/compose/internal-lint-checks/src/test/java/androidx/compose/lint/UnnecessaryLambdaCreationDetectorTest.kt
+++ b/compose/internal-lint-checks/src/test/java/androidx/compose/lint/UnnecessaryLambdaCreationDetectorTest.kt
@@ -29,7 +29,8 @@
@RunWith(JUnit4::class)
class UnnecessaryLambdaCreationDetectorTest {
- private val stub = kt("""
+ private val stub = kt(
+ """
package test
annotation class Composable
@@ -44,7 +45,8 @@
fun ComposableFunction(children: @Composable () -> Unit) {
children()
}
- """).indented().within("src")
+ """
+ ).indented().within("src")
private fun check(@Language("kotlin") code: String): TestLintResult {
return TestLintTask.lint()
@@ -56,7 +58,8 @@
@Test
fun warnsForSingleExpressions() {
- check("""
+ check(
+ """
package test
@Composable
@@ -81,7 +84,9 @@
function()
}
}
- """).expect("""
+ """
+ ).expect(
+ """
src/test/test.kt:6: Error: Creating an unnecessary lambda to emit a captured lambda [UnnecessaryLambdaCreation]
lambda()
~~~~~~
@@ -89,12 +94,14 @@
anonymousFunction()
~~~~~~~~~~~~~~~~~
2 errors, 0 warnings
- """)
+ """
+ )
}
@Test
fun warnsForMultipleLambdas() {
- check("""
+ check(
+ """
package test
@Composable
@@ -109,7 +116,9 @@
lambda()
}
}
- """).expect("""
+ """
+ ).expect(
+ """
src/test/test.kt:11: Error: Creating an unnecessary lambda to emit a captured lambda [UnnecessaryLambdaCreation]
MultipleChildComposableFunction( { lambda() }) {
~~~~~~
@@ -117,12 +126,14 @@
lambda()
~~~~~~
2 errors, 0 warnings
- """)
+ """
+ )
}
@Test
fun ignoresMultipleExpressions() {
- check("""
+ check(
+ """
package test
@Composable
@@ -132,23 +143,27 @@
lambda()
}
}
- """).expectClean()
+ """
+ ).expectClean()
}
@Test
fun ignoresPropertyAssignment() {
- check("""
+ check(
+ """
package test
val property: @Composable () -> Unit = {
lambda()
}
- """).expectClean()
+ """
+ ).expectClean()
}
@Test
fun ignoresLayoutNodes() {
- check("""
+ check(
+ """
package test
class FooNode(val foo: String)
@@ -159,12 +174,14 @@
lambda()
}
}
- """).expectClean()
+ """
+ ).expectClean()
}
@Test
fun ignoresDifferentFunctionalTypes_parameters() {
- check("""
+ check(
+ """
package test
@Composable
@@ -195,17 +212,21 @@
differentlyParameterizedLambda(5)
}
}
- """).expect("""
+ """
+ ).expect(
+ """
src/test/test.kt:21: Error: Creating an unnecessary lambda to emit a captured lambda [UnnecessaryLambdaCreation]
parameterizedLambda(child)
~~~~~~~~~~~~~~~~~~~
1 errors, 0 warnings
- """)
+ """
+ )
}
@Test
fun ignoresDifferentFunctionalTypes_receiverScopes() {
- check("""
+ check(
+ """
package test
class SomeScope
@@ -234,17 +255,21 @@
differentlyScopedLambda()
}
}
- """).expect("""
+ """
+ ).expect(
+ """
src/test/SomeScope.kt:22: Error: Creating an unnecessary lambda to emit a captured lambda [UnnecessaryLambdaCreation]
scopedLambda()
~~~~~~~~~~~~
1 errors, 0 warnings
- """)
+ """
+ )
}
@Test
fun ignoresMismatchedComposability() {
- check("""
+ check(
+ """
package test
fun uncomposableLambdaFunction(child: () -> Unit) {}
@@ -261,7 +286,8 @@
uncomposableLambda()
}
}
- """).expectClean()
+ """
+ ).expectClean()
}
}
/* ktlint-enable max-line-length */
diff --git a/compose/material/material-icons-extended/src/androidAndroidTest/kotlin/androidx/compose/material/icons/IconComparisonTest.kt b/compose/material/material-icons-extended/src/androidAndroidTest/kotlin/androidx/compose/material/icons/IconComparisonTest.kt
index 46bbb17..e74026a 100644
--- a/compose/material/material-icons-extended/src/androidAndroidTest/kotlin/androidx/compose/material/icons/IconComparisonTest.kt
+++ b/compose/material/material-icons-extended/src/androidAndroidTest/kotlin/androidx/compose/material/icons/IconComparisonTest.kt
@@ -182,12 +182,16 @@
pixels
}
- val result = this.compareBitmaps(xmlPixelArray, programmaticPixelArray,
- programmaticBitmap.width, programmaticBitmap.height)
+ val result = this.compareBitmaps(
+ xmlPixelArray, programmaticPixelArray,
+ programmaticBitmap.width, programmaticBitmap.height
+ )
if (!result.matches) {
- throw AssertionError("Bitmap comparison failed for $iconName, stats: " +
- "${result.comparisonStatistics}\n")
+ throw AssertionError(
+ "Bitmap comparison failed for $iconName, stats: " +
+ "${result.comparisonStatistics}\n"
+ )
}
}
diff --git a/compose/runtime/runtime/compose-runtime-benchmark/src/androidTest/java/androidx/compose/runtime/HotReloadIntegrationTests.kt b/compose/runtime/runtime/compose-runtime-benchmark/src/androidTest/java/androidx/compose/runtime/HotReloadIntegrationTests.kt
index 696327a..af696f9 100644
--- a/compose/runtime/runtime/compose-runtime-benchmark/src/androidTest/java/androidx/compose/runtime/HotReloadIntegrationTests.kt
+++ b/compose/runtime/runtime/compose-runtime-benchmark/src/androidTest/java/androidx/compose/runtime/HotReloadIntegrationTests.kt
@@ -92,6 +92,6 @@
override fun doFrame(frameTimeNanos: Long) {
block()
}
- })
+ })
}
}
\ No newline at end of file
diff --git a/compose/runtime/runtime/compose-runtime-benchmark/src/androidTest/java/androidx/compose/runtime/benchmark/ComposeBenchmark.kt b/compose/runtime/runtime/compose-runtime-benchmark/src/androidTest/java/androidx/compose/runtime/benchmark/ComposeBenchmark.kt
index 28c7654..efe5bee 100644
--- a/compose/runtime/runtime/compose-runtime-benchmark/src/androidTest/java/androidx/compose/runtime/benchmark/ComposeBenchmark.kt
+++ b/compose/runtime/runtime/compose-runtime-benchmark/src/androidTest/java/androidx/compose/runtime/benchmark/ComposeBenchmark.kt
@@ -217,8 +217,7 @@
}
} else {
Rect(model.color)
- }
- else
+ } else
Rect()
}
}
diff --git a/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt b/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt
index c0999de..49c2735 100644
--- a/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt
+++ b/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/BaseComposeTest.kt
@@ -36,9 +36,11 @@
class TestActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(LinearLayout(this).apply {
- id = ROOT_ID
- })
+ setContentView(
+ LinearLayout(this).apply {
+ id = ROOT_ID
+ }
+ )
}
}
@Suppress("DEPRECATION")
diff --git a/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/ComposeModelTests.kt b/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/ComposeModelTests.kt
index 480bf9c..4d1b423 100644
--- a/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/ComposeModelTests.kt
+++ b/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/ComposeModelTests.kt
@@ -206,9 +206,9 @@
@Test
fun testModelUpdatesNextFrameVisibility() {
val president = Person(
- PRESIDENT_NAME_1,
- PRESIDENT_AGE_1
- )
+ PRESIDENT_NAME_1,
+ PRESIDENT_AGE_1
+ )
val tvName = 204
@Composable fun display(person: Person) {
diff --git a/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/RecomposerTests.kt b/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/RecomposerTests.kt
index 51c43c1..cd1eb88 100644
--- a/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/RecomposerTests.kt
+++ b/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/RecomposerTests.kt
@@ -104,8 +104,10 @@
val tv1 = activity.findViewById(456) as TextView
val tv2 = activity.findViewById(567) as TextView
- assertEquals("The linear layout should be the only child of root", 1,
- activity.root.childCount)
+ assertEquals(
+ "The linear layout should be the only child of root", 1,
+ activity.root.childCount
+ )
assertEquals("Both children should have been added", 2, ll.childCount)
assertTrue(
"Should be the expected TextView (1)",
@@ -130,8 +132,10 @@
}.then { activity ->
val ll = activity.findViewById(345) as LinearLayout
- assertEquals("The linear layout should be the only child of root", 1,
- activity.root.childCount)
+ assertEquals(
+ "The linear layout should be the only child of root", 1,
+ activity.root.childCount
+ )
assertEquals("Each item in the for loop should be a child", items.size, ll.childCount)
items.forEachIndexed { index, i ->
assertEquals(
@@ -247,35 +251,41 @@
val recompose = invalidate
- TextView(id = id, onClickListener = View.OnClickListener {
- @Suppress("DEPRECATION")
- when (listener) {
- is ClickAction.Recompose -> recompose()
- is ClickAction.PerformOnView -> listener.action.invoke(it)
- }
- })
- }
-
- @Composable fun RecomposeTestComponentsA(counter: Counter, listener: ClickAction) {
- counter.inc("A")
- val recompose = invalidate
- LinearLayout(id = 99, onClickListener = View.OnClickListener {
+ TextView(
+ id = id,
+ onClickListener = View.OnClickListener {
@Suppress("DEPRECATION")
when (listener) {
is ClickAction.Recompose -> recompose()
is ClickAction.PerformOnView -> listener.action.invoke(it)
}
- }) {
- for (id in 100..102) {
- key(id) {
- RecomposeTestComponentsB(
- counter,
- listener,
- id
- )
- }
+ }
+ )
+ }
+
+ @Composable fun RecomposeTestComponentsA(counter: Counter, listener: ClickAction) {
+ counter.inc("A")
+ val recompose = invalidate
+ LinearLayout(
+ id = 99,
+ onClickListener = View.OnClickListener {
+ @Suppress("DEPRECATION")
+ when (listener) {
+ is ClickAction.Recompose -> recompose()
+ is ClickAction.PerformOnView -> listener.action.invoke(it)
}
}
+ ) {
+ for (id in 100..102) {
+ key(id) {
+ RecomposeTestComponentsB(
+ counter,
+ listener,
+ id
+ )
+ }
+ }
+ }
}
@Test
diff --git a/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/SuspendingEffectsTests.kt b/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/SuspendingEffectsTests.kt
index c56009e..b9d900e 100644
--- a/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/SuspendingEffectsTests.kt
+++ b/compose/runtime/runtime/src/androidAndroidTest/kotlin/androidx/compose/runtime/SuspendingEffectsTests.kt
@@ -91,8 +91,10 @@
}.then {
assertNotEquals(choreographerTime, Long.MIN_VALUE, "Choreographer callback never ran")
assertNotEquals(awaitFrameTime, Long.MAX_VALUE, "awaitFrameNanos callback never ran")
- assertEquals(choreographerTime, awaitFrameTime,
- "expected same values from choreographer post and awaitFrameNanos")
+ assertEquals(
+ choreographerTime, awaitFrameTime,
+ "expected same values from choreographer post and awaitFrameNanos"
+ )
}
}
@@ -115,8 +117,10 @@
}.then {
assertNotEquals(choreographerTime, Long.MIN_VALUE, "Choreographer callback never ran")
assertNotEquals(awaitFrameTime, Long.MAX_VALUE, "awaitFrameNanos callback never ran")
- assertEquals(choreographerTime, awaitFrameTime,
- "expected same values from choreographer post and awaitFrameNanos")
+ assertEquals(
+ choreographerTime, awaitFrameTime,
+ "expected same values from choreographer post and awaitFrameNanos"
+ )
}
}
@@ -144,13 +148,17 @@
coroutineScope = rememberCoroutineScope()
}
}.then {
- assertTrue(coroutineScope?.isActive == true,
- "coroutine scope should be active after initial composition")
+ assertTrue(
+ coroutineScope?.isActive == true,
+ "coroutine scope should be active after initial composition"
+ )
}.then {
toggle = false
}.then {
- assertTrue(coroutineScope?.isActive == false,
- "coroutine scope should be cancelled after leaving composition")
+ assertTrue(
+ coroutineScope?.isActive == false,
+ "coroutine scope should be cancelled after leaving composition"
+ )
}
}
@@ -174,8 +182,10 @@
}.then {
assertNotNull(recomposerClock, "Recomposer frameClock")
assertSame(recomposerClock, launchInCompositionClock, "launchInComposition clock")
- assertSame(recomposerClock, rememberCoroutineScopeFrameClock,
- "rememberCoroutineScope clock")
+ assertSame(
+ recomposerClock, rememberCoroutineScopeFrameClock,
+ "rememberCoroutineScope clock"
+ )
}
}
diff --git a/compose/runtime/runtime/src/androidMain/kotlin/androidx/compose/runtime/KeySourceInfo.kt b/compose/runtime/runtime/src/androidMain/kotlin/androidx/compose/runtime/KeySourceInfo.kt
index bc40929..d2b2dc1 100644
--- a/compose/runtime/runtime/src/androidMain/kotlin/androidx/compose/runtime/KeySourceInfo.kt
+++ b/compose/runtime/runtime/src/androidMain/kotlin/androidx/compose/runtime/KeySourceInfo.kt
@@ -30,32 +30,35 @@
internal actual fun recordSourceKeyInfo(key: Any) {
val sk = findSourceKey(key)
sk?.let {
- keyInfo.getOrPut(sk, {
- val stack = Thread.currentThread().stackTrace
- // On Android the frames looks like:
- // 0: getThreadStackTrace() (native method)
- // 1: getStackTrace()
- // 2: recordSourceKeyInfo()
- // 3: start()
- // 4: start()
- // 5: startRestartGroup() or startReplaceableGroup() or startNode() or startDefaults()
- // 6: <calling method>
- // On a desktop VM this looks like:
- // 0: getStackTrace()
- // 1: recordSourceKey()
- // 2: start()
- // 3: startRestartGroup() or startReplaceableGroup() or startNode() or startDefaults()
- // 4: non-inline call/emit?
- // 4 or 5: <calling method>
- val frame = stack
- .drop(3) // The first 3 elements are never interesting to us
- .dropWhile { it.className.startsWith("androidx.compose.runtime.Composer") } // Drop all
- // start*
- .drop(1) // Drop non-inline call/emit
- .dropWhile { it.lineNumber == -1 } // Drop if we do not have source info
- .first()
- "${frame.className}.${frame.methodName} (${frame.fileName}:${frame.lineNumber})"
- })
+ keyInfo.getOrPut(
+ sk,
+ {
+ val stack = Thread.currentThread().stackTrace
+ // On Android the frames looks like:
+ // 0: getThreadStackTrace() (native method)
+ // 1: getStackTrace()
+ // 2: recordSourceKeyInfo()
+ // 3: start()
+ // 4: start()
+ // 5: startRestartGroup() or startReplaceableGroup() or startNode() or startDefaults()
+ // 6: <calling method>
+ // On a desktop VM this looks like:
+ // 0: getStackTrace()
+ // 1: recordSourceKey()
+ // 2: start()
+ // 3: startRestartGroup() or startReplaceableGroup() or startNode() or startDefaults()
+ // 4: non-inline call/emit?
+ // 4 or 5: <calling method>
+ val frame = stack
+ .drop(3) // The first 3 elements are never interesting to us
+ .dropWhile { it.className.startsWith("androidx.compose.runtime.Composer") } // Drop all
+ // start*
+ .drop(1) // Drop non-inline call/emit
+ .dropWhile { it.lineNumber == -1 } // Drop if we do not have source info
+ .first()
+ "${frame.className}.${frame.methodName} (${frame.fileName}:${frame.lineNumber})"
+ }
+ )
}
}
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/ComposeCompilerApi.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/ComposeCompilerApi.kt
index f08fcbb..e328296 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/ComposeCompilerApi.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/ComposeCompilerApi.kt
@@ -19,7 +19,7 @@
@RequiresOptIn(
level = RequiresOptIn.Level.WARNING,
message = "This API is intended to be targeted by the Compose Compiler Plugin and not called " +
- "directly."
+ "directly."
)
@Target(
AnnotationTarget.CLASS,
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt
index 9a6f506..7a7234e 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composer.kt
@@ -327,7 +327,7 @@
private val lifecycleObservers = HashMap<
CompositionLifecycleObserverHolder,
CompositionLifecycleObserverHolder
- >()
+ >()
private val pendingStack = Stack<Pending?>()
private var pending: Pending? = null
private var nodeIndex: Int = 0
@@ -558,8 +558,8 @@
@ComposeCompilerApi
val skipping: Boolean get() {
return !inserting &&
- !providersInvalid &&
- currentRecomposeScope?.requiresRecompose == false
+ !providersInvalid &&
+ currentRecomposeScope?.requiresRecompose == false
}
/**
@@ -626,9 +626,13 @@
if (!observationsProcessed.removeValueScope(value, scope) &&
scope.invalidate() != InvalidationResult.IGNORED
) {
- (invalidated ?: (HashSet<RecomposeScope>().also {
- invalidated = it
- })).add(scope)
+ (
+ invalidated ?: (
+ HashSet<RecomposeScope>().also {
+ invalidated = it
+ }
+ )
+ ).add(scope)
}
}
}
@@ -646,7 +650,7 @@
*/
private class LifecycleEventDispatcher(
private val lifecycleObservers: MutableMap<CompositionLifecycleObserverHolder,
- CompositionLifecycleObserverHolder>
+ CompositionLifecycleObserverHolder>
) : LifecycleManager {
private val enters = mutableSetOf<CompositionLifecycleObserverHolder>()
private val leaves = mutableSetOf<CompositionLifecycleObserverHolder>()
@@ -1652,8 +1656,10 @@
// Walk down from the anchor group counting nodes of siblings in front of this group
var current = anchorLocation
- val nodeIndexLimit = index + ((nodeCountOverrides[anchorGroup] ?: anchorGroup.nodes) -
- group.nodes)
+ val nodeIndexLimit = index + (
+ (nodeCountOverrides[anchorGroup] ?: anchorGroup.nodes) -
+ group.nodes
+ )
loop@ while (index < nodeIndexLimit) {
if (current == groupLocation) break
current++
@@ -1707,11 +1713,13 @@
* early.
*/
private fun compoundKeyOf(group: Group?, recomposeGroup: Group, recomposeKey: Int): Int {
- return if (group == recomposeGroup) recomposeKey else (compoundKeyOf(
- (group ?: error("Detached group")).parent,
- recomposeGroup,
- recomposeKey
- ) rol 3) xor (if (group.dataKey != null) group.dataKey.hashCode() else group.key)
+ return if (group == recomposeGroup) recomposeKey else (
+ compoundKeyOf(
+ (group ?: error("Detached group")).parent,
+ recomposeGroup,
+ recomposeKey
+ ) rol 3
+ ) xor (if (group.dataKey != null) group.dataKey.hashCode() else group.key)
}
internal fun invalidate(scope: RecomposeScope): InvalidationResult {
@@ -1819,7 +1827,7 @@
// This allows for the invalidate stack to be out of sync since this might be called during exception stack
// unwinding that might have not called the doneJoin/endRestartGroup in the wrong order.
val scope = if (invalidateStack.isNotEmpty()) invalidateStack.pop()
- else null
+ else null
scope?.requiresRecompose = false
val result = if (scope != null && (scope.used || collectKeySources)) {
if (scope.anchor == null) {
@@ -2303,9 +2311,11 @@
}
override fun recordInspectionTable(table: MutableSet<SlotTable>) {
- (inspectionTables ?: HashSet<MutableSet<SlotTable>>().also {
- inspectionTables = it
- }).add(table)
+ (
+ inspectionTables ?: HashSet<MutableSet<SlotTable>>().also {
+ inspectionTables = it
+ }
+ ).add(table)
}
override fun startComposing() {
@@ -2593,10 +2603,11 @@
index++
if (index >= size ||
identityHashCode(get(index)) != valueHash ||
- identityHashCode(get(index + 1)) != scopeHash) {
- index--
- break
- }
+ identityHashCode(get(index + 1)) != scopeHash
+ ) {
+ index--
+ break
+ }
}
return -(index + 1)
}
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Expect.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Expect.kt
index a90b834..4e0d678 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Expect.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Expect.kt
@@ -115,9 +115,11 @@
)
expect annotation class TestOnly()
-@Target(AnnotationTarget.FUNCTION,
+@Target(
+ AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
- AnnotationTarget.PROPERTY_SETTER)
+ AnnotationTarget.PROPERTY_SETTER
+)
@Retention(AnnotationRetention.BINARY)
@MustBeDocumented
expect annotation class CheckResult(
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/ExperimentalComposeApi.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/ExperimentalComposeApi.kt
index bdf8437..aaaa566 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/ExperimentalComposeApi.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/ExperimentalComposeApi.kt
@@ -19,7 +19,7 @@
@RequiresOptIn(
level = RequiresOptIn.Level.ERROR,
message = "This is an experimental API for Compose and is likely to change before becoming " +
- "stable."
+ "stable."
)
@Target(
AnnotationTarget.CLASS,
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/FrameManager.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/FrameManager.kt
index d0c2404..18b19f0 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/FrameManager.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/FrameManager.kt
@@ -43,8 +43,10 @@
/**
* TODO: This will be merged later with the scopes used by [Recomposer]
*/
- private val scheduleScope = CoroutineScope(Recomposer.current().embeddingContext
- .mainThreadCompositionContext() + SupervisorJob())
+ private val scheduleScope = CoroutineScope(
+ Recomposer.current().embeddingContext
+ .mainThreadCompositionContext() + SupervisorJob()
+ )
fun ensureStarted() {
if (!started) {
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Recomposer.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Recomposer.kt
index 1b415ba..7b24ec8 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Recomposer.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Recomposer.kt
@@ -285,7 +285,8 @@
private inline fun <T> composing(composer: Composer<*>, block: () -> T): T {
val snapshot = takeMutableSnapshot(
- readObserverOf(composer), writeObserverOf(composer))
+ readObserverOf(composer), writeObserverOf(composer)
+ )
try {
return snapshot.enter(block)
} finally {
@@ -296,8 +297,10 @@
private fun applyAndCheck(snapshot: MutableSnapshot) {
val applyResult = snapshot.apply()
if (applyResult is SnapshotApplyResult.Failure) {
- error("Unsupported concurrent change during composition. A state object was " +
- "modified by composition as well as being modified outside composition.")
+ error(
+ "Unsupported concurrent change during composition. A state object was " +
+ "modified by composition as well as being modified outside composition."
+ )
// TODO(chuckj): Consider lifting this restriction by forcing a recompose
}
}
@@ -334,8 +337,10 @@
@TestOnly
fun current(): Recomposer {
return mainRecomposer ?: run {
- val mainScope = CoroutineScope(NonCancellable +
- embeddingContext.mainThreadCompositionContext())
+ val mainScope = CoroutineScope(
+ NonCancellable +
+ embeddingContext.mainThreadCompositionContext()
+ )
Recomposer(embeddingContext).also {
mainRecomposer = it
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Remember.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Remember.kt
index d3c8d58..b4cbe97 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Remember.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Remember.kt
@@ -69,8 +69,8 @@
): T {
return currentComposer.cache(
currentComposer.changed(v1) or
- currentComposer.changed(v2) or
- currentComposer.changed(v3),
+ currentComposer.changed(v2) or
+ currentComposer.changed(v3),
calculation
)
}
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SlotTable.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SlotTable.kt
index 522ddce..965f614 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SlotTable.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SlotTable.kt
@@ -265,14 +265,16 @@
while (current < currentEnd) {
val location = current
val group = slots[location].asGroup
- result.add(KeyInfo(
- group.key,
- group.dataKey,
- location,
- skipGroup(),
- index++,
- group
- ))
+ result.add(
+ KeyInfo(
+ group.key,
+ group.dataKey,
+ location,
+ skipGroup(),
+ index++,
+ group
+ )
+ )
}
current = oldCurrent
this.nodeIndex = oldNodeIndex
@@ -664,8 +666,10 @@
current = oldCurrent
nodeCount = oldNodeCount
- slots.copyInto(slots, effectiveIndex(current),
- effectiveIndex(newMoveLocation), effectiveIndex(newMoveLocation) + moveLen)
+ slots.copyInto(
+ slots, effectiveIndex(current),
+ effectiveIndex(newMoveLocation), effectiveIndex(newMoveLocation) + moveLen
+ )
// Before we remove the old location, move any anchors
table.moveAnchors(newMoveLocation, current, moveLen)
@@ -877,12 +881,16 @@
pendingClear = false
if (table.anchors.isNotEmpty()) table.updateAnchors(index)
if (index < table.gapStart) {
- slots.copyInto(slots, index + table.gapLen,
- index, table.gapStart)
+ slots.copyInto(
+ slots, index + table.gapLen,
+ index, table.gapStart
+ )
} else {
- slots.copyInto(slots, table.gapStart,
+ slots.copyInto(
+ slots, table.gapStart,
table.gapStart + table.gapLen,
- index + table.gapLen)
+ index + table.gapLen
+ )
}
table.gapStart = index
pendingClear = true
@@ -966,9 +974,9 @@
else
"none"
return "SlotWriter" +
- "(current=$current, " +
- "size=${slots.size - table.gapLen}, " +
- "gap=${gap}${if (insertCount > 0) ", inserting" else ""})"
+ "(current=$current, " +
+ "size=${slots.size - table.gapLen}, " +
+ "gap=${gap}${if (insertCount > 0) ", inserting" else ""})"
}
}
@@ -1212,7 +1220,7 @@
}
require(group.nodes == nodeCount) {
"Incorrect node count for group at $location, expected ${
- group.nodes
+ group.nodes
}, received $nodeCount"
}
return if (group.isNode) 1 else nodeCount
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SuspendingEffects.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SuspendingEffects.kt
index 7e36e2c..af88263 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SuspendingEffects.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/SuspendingEffects.kt
@@ -198,17 +198,29 @@
coroutineContext: CoroutineContext,
composer: Composer<*>
) = if (coroutineContext[Job] != null) {
- CoroutineScope(Job().apply {
- completeExceptionally(IllegalArgumentException("CoroutineContext supplied to " +
- "rememberCoroutineScope may not include a parent job"))
- })
+ CoroutineScope(
+ Job().apply {
+ completeExceptionally(
+ IllegalArgumentException(
+ "CoroutineContext supplied to " +
+ "rememberCoroutineScope may not include a parent job"
+ )
+ )
+ }
+ )
} else {
val applyContext = composer.recomposer.applyingCoroutineContext
if (applyContext == null) {
- CoroutineScope(Job().apply {
- completeExceptionally(IllegalStateException("cannot create a new composition " +
- "coroutine scope - Composition is not active"))
- })
+ CoroutineScope(
+ Job().apply {
+ completeExceptionally(
+ IllegalStateException(
+ "cannot create a new composition " +
+ "coroutine scope - Composition is not active"
+ )
+ )
+ }
+ )
} else CoroutineScope(applyContext + Job(applyContext[Job]) + coroutineContext)
}
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/collection/ExperimentalCollectionApi.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/collection/ExperimentalCollectionApi.kt
index 30cdf0f..2063c12 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/collection/ExperimentalCollectionApi.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/collection/ExperimentalCollectionApi.kt
@@ -19,7 +19,7 @@
@RequiresOptIn(
level = RequiresOptIn.Level.ERROR,
message = "This is an experimental API for fast access collections and is likely to change " +
- "before becoming stable."
+ "before becoming stable."
)
@Target(
AnnotationTarget.CLASS,
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/frames/FrameContainers.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/frames/FrameContainers.kt
index c8c6bc7..97776b1 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/frames/FrameContainers.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/frames/FrameContainers.kt
@@ -28,14 +28,14 @@
)
)
class ModelList<T>
- @Deprecated(
- "Frames have been replaced by snapshots",
- ReplaceWith(
- "mutableStateListOf()",
- "androidx.compose.runtime.mutableStateListOf"
- )
- )
- constructor() : MutableList<T>, Framed {
+@Deprecated(
+ "Frames have been replaced by snapshots",
+ ReplaceWith(
+ "mutableStateListOf()",
+ "androidx.compose.runtime.mutableStateListOf"
+ )
+)
+constructor() : MutableList<T>, Framed {
private var myFirst: Record =
ArrayContainer<T>()
override val firstFrameRecord: Record get() = myFirst
@@ -148,14 +148,14 @@
)
)
class ModelMap<K, V>
- @Deprecated(
- "Frames have been replaced by snapshots",
- ReplaceWith(
- "mutableStateMapOf()",
- "androidx.compose.runtime.StableMutableMap"
- )
+@Deprecated(
+ "Frames have been replaced by snapshots",
+ ReplaceWith(
+ "mutableStateMapOf()",
+ "androidx.compose.runtime.StableMutableMap"
)
- constructor() : MutableMap<K, V>, Framed {
+)
+constructor() : MutableMap<K, V>, Framed {
private var myFirst: Record =
MapContainer<K, V>()
override val firstFrameRecord: Record get() = myFirst
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/frames/Frames.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/frames/Frames.kt
index 92a1f53..9d1a51f 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/frames/Frames.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/frames/Frames.kt
@@ -18,7 +18,8 @@
package androidx.compose.runtime.frames
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith(
"SnapshotApplyConflictException",
"androidx.compose.runtime.snapshots.SnapshotApplyConflictException"
@@ -30,7 +31,8 @@
/**
* Base implementation of a frame record
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith(
"StateRecord",
"androidx.compose.runtime.snapshots.StateRecord"
@@ -44,7 +46,8 @@
/**
* Frame local values of a framed object.
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith(
"StateRecord",
"androidx.compose.runtime.snapshots.StateRecord"
@@ -76,7 +79,8 @@
* Interface implemented by all model objects. Used by this module to maintain the state records
* of a model object.
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith(
"StateObject",
"androidx.compose.runtime.snapshots.StateObject"
@@ -147,7 +151,8 @@
* [FrameReadObserver] will be called for every frame read happened on the current
* thread during execution of the [block].
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith(
"Snapshot.observe(readObserver, null, block)",
"androidx.compose.runtime.snapshots.Snapshot"
@@ -158,7 +163,8 @@
/**
* Return the thread's active frame. This will throw if no frame is active for the thread.
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith(
"Snapshot.current",
"androidx.compose.runtime.snapshots.Snapshot"
@@ -167,7 +173,8 @@
)
fun currentFrame(): Frame = deprecated()
-@Deprecated("Frames has been replaced by snapshots. There is no equivalent with snapshots, it is" +
+@Deprecated(
+ "Frames has been replaced by snapshots. There is no equivalent with snapshots, it is" +
" always valid to read and write to a state object.",
level = DeprecationLevel.ERROR
)
@@ -179,7 +186,8 @@
* @param readOnly true if the frame can only be read from
* @return the newly created frame's data
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith(
"takeMutableSnapshot()",
"androidx.compose.runtime.snapshots.takeMutableSnapshot"
@@ -191,7 +199,8 @@
/**
* Open a frame with observers
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith(
"takeMutableSnapshot(readObserver, writeObserver)",
"androidx.compose.runtime.snapshots.takeMutableSnapshot"
@@ -205,7 +214,8 @@
/*
* Commits the pending frame if there one is open. Intended to be used in a `finally` clause
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith("snapshot.apply()"),
DeprecationLevel.ERROR
)
@@ -216,7 +226,8 @@
* current committed frame. Throws IllegalStateException no frame is open (use `commitHandler()` to
* commit a frame if one is open).
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith("snapshot.apply()"),
DeprecationLevel.ERROR
)
@@ -225,12 +236,14 @@
/**
* Returns true if the given object framed object mutated in the the frame
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
level = DeprecationLevel.ERROR
)
fun wasModified(value: Any): Boolean = error("deprecated")
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith(
"Snapshot.registerApplyObserver",
"androidx.compose.runtime.snapshots.Snapshot"
@@ -243,7 +256,8 @@
* Commit the given frame. Throws FrameAborted if changes in the frame collides with the current
* committed frame.
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith("frame.apply().check()"),
DeprecationLevel.ERROR
)
@@ -254,7 +268,8 @@
* no frame is open (use `abortHandler` to abort a frame without throwing an exception or to abort a
* frame if one is open).
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith("snapshot.dispose()"),
DeprecationLevel.ERROR
)
@@ -263,7 +278,8 @@
/**
* Abort the given frame and throw a FrameAborted exception.
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith("frame.dispose()"),
DeprecationLevel.ERROR
)
@@ -273,7 +289,8 @@
* Abort the current frame if one is open. This is intended to be used in a catch handler to abort
* the frame and then rethrow the exception.
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith("snapshot.dispose()"),
DeprecationLevel.ERROR
)
@@ -282,7 +299,8 @@
/**
* Abort the given frame.
*/
-@Deprecated("Frames has been replaced by snapshots",
+@Deprecated(
+ "Frames has been replaced by snapshots",
ReplaceWith("frame.dispose()"),
DeprecationLevel.ERROR
)
@@ -328,12 +346,14 @@
)
fun _readable(r: Record, framed: Framed): Record = error("deprecated")
-@Deprecated("Frames has been replaced by snapshots.",
+@Deprecated(
+ "Frames has been replaced by snapshots.",
level = DeprecationLevel.ERROR
)
fun _writable(r: Record, framed: Framed): Record = error("deprecated")
-@Deprecated("Frames has been replaced by snapshots.",
+@Deprecated(
+ "Frames has been replaced by snapshots.",
level = DeprecationLevel.ERROR
)
fun _created(framed: Framed): Unit = error("deprecated")
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/internal/ComposableLambda.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/internal/ComposableLambda.kt
index 554a624..b23c780 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/internal/ComposableLambda.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/internal/ComposableLambda.kt
@@ -44,12 +44,14 @@
*/
@Stable
@ComposeCompilerApi
-class ComposableLambda<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16,
- P17, P18, R>(
- val key: Int,
- private val tracked: Boolean,
- private val sourceInformation: String?
- ) :
+/* ktlint-disable parameter-list-wrapping */ // TODO(https://github.com/pinterest/ktlint/issues/921): reenable
+class ComposableLambda<
+ P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16,
+ P17, P18, R>(
+ val key: Int,
+ private val tracked: Boolean,
+ private val sourceInformation: String?
+) :
Function2<Composer<*>, Int, R>,
Function3<P1, Composer<*>, Int, R>,
Function4<P1, P2, Composer<*>, Int, R>,
@@ -66,13 +68,13 @@
Function15<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, Composer<*>, Int, R>,
Function16<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, Composer<*>, Int, R>,
Function17<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, Composer<*>, Int,
- R>,
+ R>,
Function19<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16,
- Composer<*>, Int, Int, R>,
+ Composer<*>, Int, Int, R>,
Function20<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17,
- Composer<*>, Int, Int, R>,
+ Composer<*>, Int, Int, R>,
Function21<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18,
- Composer<*>, Int, Int, R> {
+ Composer<*>, Int, Int, R> {
private var _block: Any? = null
private var scope: RecomposeScope? = null
private var scopes: MutableList<RecomposeScope>? = null
@@ -148,11 +150,13 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(1) else sameBits(1)
- val result = (_block as (
- p1: P1,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
c,
dirty
@@ -179,13 +183,15 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(3) else sameBits(3)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -207,14 +213,16 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(4) else sameBits(4)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -240,15 +248,17 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(5) else sameBits(5)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -276,16 +286,18 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(6) else sameBits(6)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -315,17 +327,19 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(7) else sameBits(7)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -357,18 +371,20 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(8) else sameBits(8)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- p8: P8,
- c: Composer<*>,
- changed: Int
- ) -> R) (
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ p8: P8,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ ) (
p1,
p2,
p3,
@@ -402,19 +418,21 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(9) else sameBits(9)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- p8: P8,
- p9: P9,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ p8: P8,
+ p9: P9,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -450,20 +468,22 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(10) else sameBits(10)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- p8: P8,
- p9: P9,
- p10: P10,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ p8: P8,
+ p9: P9,
+ p10: P10,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -501,21 +521,23 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(11) else sameBits(11)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- p8: P8,
- p9: P9,
- p10: P10,
- p11: P11,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ p8: P8,
+ p9: P9,
+ p10: P10,
+ p11: P11,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -555,22 +577,24 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(12) else sameBits(12)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- p8: P8,
- p9: P9,
- p10: P10,
- p11: P11,
- p12: P12,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ p8: P8,
+ p9: P9,
+ p10: P10,
+ p11: P11,
+ p12: P12,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -612,23 +636,25 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(13) else sameBits(13)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- p8: P8,
- p9: P9,
- p10: P10,
- p11: P11,
- p12: P12,
- p13: P13,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ p8: P8,
+ p9: P9,
+ p10: P10,
+ p11: P11,
+ p12: P12,
+ p13: P13,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -672,24 +698,26 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(14) else sameBits(14)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- p8: P8,
- p9: P9,
- p10: P10,
- p11: P11,
- p12: P12,
- p13: P13,
- p14: P14,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ p8: P8,
+ p9: P9,
+ p10: P10,
+ p11: P11,
+ p12: P12,
+ p13: P13,
+ p14: P14,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -735,25 +763,27 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed or if (c.changed(this)) differentBits(15) else sameBits(15)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- p8: P8,
- p9: P9,
- p10: P10,
- p11: P11,
- p12: P12,
- p13: P13,
- p14: P14,
- p15: P15,
- c: Composer<*>,
- changed: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ p8: P8,
+ p9: P9,
+ p10: P10,
+ p11: P11,
+ p12: P12,
+ p13: P13,
+ p14: P14,
+ p15: P15,
+ c: Composer<*>,
+ changed: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -820,27 +850,29 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed1 or if (c.changed(this)) differentBits(16) else sameBits(16)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- p8: P8,
- p9: P9,
- p10: P10,
- p11: P11,
- p12: P12,
- p13: P13,
- p14: P14,
- p15: P15,
- p16: P16,
- c: Composer<*>,
- changed: Int,
- changed1: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ p8: P8,
+ p9: P9,
+ p10: P10,
+ p11: P11,
+ p12: P12,
+ p13: P13,
+ p14: P14,
+ p15: P15,
+ p16: P16,
+ c: Composer<*>,
+ changed: Int,
+ changed1: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -912,28 +944,30 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed1 or if (c.changed(this)) differentBits(17) else sameBits(17)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- p8: P8,
- p9: P9,
- p10: P10,
- p11: P11,
- p12: P12,
- p13: P13,
- p14: P14,
- p15: P15,
- p16: P16,
- p17: P17,
- c: Composer<*>,
- changed: Int,
- changed1: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ p8: P8,
+ p9: P9,
+ p10: P10,
+ p11: P11,
+ p12: P12,
+ p13: P13,
+ p14: P14,
+ p15: P15,
+ p16: P16,
+ p17: P17,
+ c: Composer<*>,
+ changed: Int,
+ changed1: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -976,7 +1010,8 @@
p17,
nc,
changed or 0b1,
- changed1)
+ changed1
+ )
}
return result
}
@@ -1007,29 +1042,31 @@
c.startRestartGroup(key, sourceInformation)
trackRead(c)
val dirty = changed1 or if (c.changed(this)) differentBits(18) else sameBits(18)
- val result = (_block as (
- p1: P1,
- p2: P2,
- p3: P3,
- p4: P4,
- p5: P5,
- p6: P6,
- p7: P7,
- p8: P8,
- p9: P9,
- p10: P10,
- p11: P11,
- p12: P12,
- p13: P13,
- p14: P14,
- p15: P15,
- p16: P16,
- p17: P17,
- p18: P18,
- c: Composer<*>,
- changed: Int,
- changed1: Int
- ) -> R)(
+ val result = (
+ _block as (
+ p1: P1,
+ p2: P2,
+ p3: P3,
+ p4: P4,
+ p5: P5,
+ p6: P6,
+ p7: P7,
+ p8: P8,
+ p9: P9,
+ p10: P10,
+ p11: P11,
+ p12: P12,
+ p13: P13,
+ p14: P14,
+ p15: P15,
+ p16: P16,
+ p17: P17,
+ p18: P18,
+ c: Composer<*>,
+ changed: Int,
+ changed1: Int
+ ) -> R
+ )(
p1,
p2,
p3,
@@ -1086,7 +1123,7 @@
@ComposeCompilerApi
private typealias CLambda = ComposableLambda<Any, Any, Any, Any, Any, Any, Any, Any, Any, Any,
- Any, Any, Any, Any, Any, Any, Any, Any, Any>
+ Any, Any, Any, Any, Any, Any, Any, Any, Any>
@Suppress("unused")
@ComposeCompilerApi
diff --git a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/snapshots/Snapshot.kt b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/snapshots/Snapshot.kt
index 0655c7a..00b1514 100644
--- a/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/snapshots/Snapshot.kt
+++ b/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/snapshots/Snapshot.kt
@@ -731,19 +731,25 @@
// obscure the current value so ignore the conflict
}
current -> {
- (mergedRecords ?: mutableListOf<Pair<StateObject, StateRecord>>().also {
- mergedRecords = it
- }).add(state to current.create())
+ (
+ mergedRecords ?: mutableListOf<Pair<StateObject, StateRecord>>().also {
+ mergedRecords = it
+ }
+ ).add(state to current.create())
// If we revert to current then the state is no longer modified.
- (statesToRemove ?: mutableListOf<StateObject>().also {
- statesToRemove = it
- }).add(state)
+ (
+ statesToRemove ?: mutableListOf<StateObject>().also {
+ statesToRemove = it
+ }
+ ).add(state)
}
else -> {
- (mergedRecords ?: mutableListOf<Pair<StateObject, StateRecord>>().also {
- mergedRecords = it
- }).add(
+ (
+ mergedRecords ?: mutableListOf<Pair<StateObject, StateRecord>>().also {
+ mergedRecords = it
+ }
+ ).add(
if (merged != previous) state to merged
else state to previous.create()
)
@@ -1102,19 +1108,24 @@
* A snapshot object that simplifies the code by treating the global state as a mutable snapshot.
*/
internal class GlobalSnapshot(id: Int, invalid: SnapshotIdSet) :
- MutableSnapshot(id, invalid, null, sync {
- // Take a defensive copy of the globalWriteObservers list. This then avoids having to
- // synchronized access to writerObserver in places it is called and allows the list to
- // change while notifications are being dispatched. Changes to globalWriteObservers force
- // a new global snapshot to be created.
- (if (globalWriteObservers.isNotEmpty()) {
- globalWriteObservers.toMutableList()
- } else null)?.let {
- it.firstOrNull() ?: { state: Any ->
- it.forEach { it(state) }
+ MutableSnapshot(
+ id, invalid, null,
+ sync {
+ // Take a defensive copy of the globalWriteObservers list. This then avoids having to
+ // synchronized access to writerObserver in places it is called and allows the list to
+ // change while notifications are being dispatched. Changes to globalWriteObservers force
+ // a new global snapshot to be created.
+ (
+ if (globalWriteObservers.isNotEmpty()) {
+ globalWriteObservers.toMutableList()
+ } else null
+ )?.let {
+ it.firstOrNull() ?: { state: Any ->
+ it.forEach { it(state) }
+ }
}
}
- }) {
+ ) {
override fun takeNestedSnapshot(readObserver: SnapshotReadObserver?): Snapshot =
takeNewSnapshot { invalid ->
@@ -1206,9 +1217,11 @@
if (result != SnapshotApplyResult.Success) return result
// Add all modified objects in this set to the parent
- (parent.modified ?: HashSet<StateObject>().also {
- parent.modified = it
- }).addAll(modified)
+ (
+ parent.modified ?: HashSet<StateObject>().also {
+ parent.modified = it
+ }
+ ).addAll(modified)
}
// Make the snapshot visible in the parent snapshot
@@ -1420,11 +1433,13 @@
// Update the transparent snapshot if necessary
// This doesn't need to take the sync because it is updating thread local state.
(threadSnapshot.get() as? TransparentObserverMutableSnapshot)?.let {
- threadSnapshot.set(TransparentObserverMutableSnapshot(
- currentGlobalSnapshot,
- it.specifiedReadObserver,
- it.specifiedWriteObserver
- ))
+ threadSnapshot.set(
+ TransparentObserverMutableSnapshot(
+ currentGlobalSnapshot,
+ it.specifiedReadObserver,
+ it.specifiedWriteObserver
+ )
+ )
it.dispose()
}
return result
@@ -1457,7 +1472,7 @@
//
// INVALID_SNAPSHOT is reserved as an invalid snapshot id.
return candidateSnapshot != INVALID_SNAPSHOT && candidateSnapshot <= currentSnapshot &&
- !invalid.get(candidateSnapshot)
+ !invalid.get(candidateSnapshot)
}
// Determine if the given data is valid for the snapshot.
@@ -1501,8 +1516,10 @@
}
private fun readError(): Nothing {
- error("Reading a state that was created after the snapshot was taken or in a snapshot that " +
- "has not yet been applied")
+ error(
+ "Reading a state that was created after the snapshot was taken or in a snapshot that " +
+ "has not yet been applied"
+ )
}
/**
@@ -1646,9 +1663,11 @@
?: readError()
val merged = state.mergeRecords(previous, current, applied)
if (merged != null) {
- (result ?: hashMapOf<StateRecord, StateRecord>().also {
- result = it
- })[current] = merged
+ (
+ result ?: hashMapOf<StateRecord, StateRecord>().also {
+ result = it
+ }
+ )[current] = merged
} else {
// If one fails don't bother calculating the others as they are likely not going
// to be used. There is an unlikely case that a optimistic merge cannot be
diff --git a/compose/runtime/runtime/src/desktopMain/kotlin/androidx/compose/runtime/ActualDesktop.kt b/compose/runtime/runtime/src/desktopMain/kotlin/androidx/compose/runtime/ActualDesktop.kt
index ad155f8..d076421 100644
--- a/compose/runtime/runtime/src/desktopMain/kotlin/androidx/compose/runtime/ActualDesktop.kt
+++ b/compose/runtime/runtime/src/desktopMain/kotlin/androidx/compose/runtime/ActualDesktop.kt
@@ -64,35 +64,38 @@
internal actual fun recordSourceKeyInfo(key: Any) {
val sk = findSourceKey(key)
sk?.let {
- keyInfo.getOrPut(sk, {
- val stack = Thread.currentThread().stackTrace
- // On Android the frames looks like:
- // 0: getThreadStackTrace() (native method)
- // 1: getStackTrace()
- // 2: recordSourceKey()
- // 3: start()
- // 4: startGroup() or startNode()
- // 5: non-inline call/emit?
- // 5 or 6: <calling method>
- // On a desktop VM this looks like:
- // 0: getStackTrace()
- // 1: recordSourceKey()
- // 2: start()
- // 3: startGroup() or startNode()
- // 4: non-inline call/emit?
- // 4 or 5: <calling method>
- // If the stack method at 4 is startGroup assume we want 5 instead.
- val frameNumber = stack[4].let {
- if (it.methodName == "startGroup" || it.methodName == "startNode") 5 else 4
+ keyInfo.getOrPut(
+ sk,
+ {
+ val stack = Thread.currentThread().stackTrace
+ // On Android the frames looks like:
+ // 0: getThreadStackTrace() (native method)
+ // 1: getStackTrace()
+ // 2: recordSourceKey()
+ // 3: start()
+ // 4: startGroup() or startNode()
+ // 5: non-inline call/emit?
+ // 5 or 6: <calling method>
+ // On a desktop VM this looks like:
+ // 0: getStackTrace()
+ // 1: recordSourceKey()
+ // 2: start()
+ // 3: startGroup() or startNode()
+ // 4: non-inline call/emit?
+ // 4 or 5: <calling method>
+ // If the stack method at 4 is startGroup assume we want 5 instead.
+ val frameNumber = stack[4].let {
+ if (it.methodName == "startGroup" || it.methodName == "startNode") 5 else 4
+ }
+ val frame = stack[frameNumber].let {
+ if (it.methodName == "call" || it.methodName == "emit")
+ stack[frameNumber + 1]
+ else
+ stack[frameNumber]
+ }
+ "${frame.className}.${frame.methodName} (${frame.fileName}:${frame.lineNumber})"
}
- val frame = stack[frameNumber].let {
- if (it.methodName == "call" || it.methodName == "emit")
- stack[frameNumber + 1]
- else
- stack[frameNumber]
- }
- "${frame.className}.${frame.methodName} (${frame.fileName}:${frame.lineNumber})"
- })
+ )
}
}
diff --git a/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/CompositionTests.kt b/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/CompositionTests.kt
index cbd29ee..16065b1 100644
--- a/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/CompositionTests.kt
+++ b/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/CompositionTests.kt
@@ -660,7 +660,8 @@
val reports = listOf(
jim_reports_to_sally,
rob_reports_to_alice,
- clark_reports_to_lois, r)
+ clark_reports_to_lois, r
+ )
val result = compose {
reportsReport(reports)
}
@@ -725,7 +726,8 @@
val reports = listOf(
jim_reports_to_sally,
rob_reports_to_alice,
- clark_reports_to_lois, r)
+ clark_reports_to_lois, r
+ )
val result = compose {
reportsReport(reports)
}
@@ -1507,25 +1509,31 @@
@Composable fun MockComposeScope.composition(a: Boolean, b: Boolean, c: Boolean) {
linear {
if (a) {
- key(1) { linear {
- val l = remember { lifecycleObject }
- assertEquals(lifecycleObject, l, "Lifecycle object should be returned")
- text("a")
- } }
+ key(1) {
+ linear {
+ val l = remember { lifecycleObject }
+ assertEquals(lifecycleObject, l, "Lifecycle object should be returned")
+ text("a")
+ }
+ }
}
if (b) {
- key(2) { linear {
- val l = remember { lifecycleObject }
- assertEquals(lifecycleObject, l, "Lifecycle object should be returned")
- text("b")
- } }
+ key(2) {
+ linear {
+ val l = remember { lifecycleObject }
+ assertEquals(lifecycleObject, l, "Lifecycle object should be returned")
+ text("b")
+ }
+ }
}
if (c) {
- key(3) { linear {
- val l = remember { lifecycleObject }
- assertEquals(lifecycleObject, l, "Lifecycle object should be returned")
- text("c")
- } }
+ key(3) {
+ linear {
+ val l = remember { lifecycleObject }
+ assertEquals(lifecycleObject, l, "Lifecycle object should be returned")
+ text("c")
+ }
+ }
}
}
}
@@ -1686,10 +1694,12 @@
@Composable fun MockComposeScope.composition(obj: Any) {
linear {
- key(1) { linear {
- remember(obj) { obj }
- text("Some value")
- } }
+ key(1) {
+ linear {
+ remember(obj) { obj }
+ text("Some value")
+ }
+ }
}
}
@@ -1729,8 +1739,11 @@
var order = 0
val objects = mutableListOf<Any>()
val newLifecycleObject = { name: String ->
- object : CompositionLifecycleObserver, Counted,
- Ordered, Named {
+ object :
+ CompositionLifecycleObserver,
+ Counted,
+ Ordered,
+ Named {
override var name = name
override var count = 0
override var enterOrder = -1
@@ -1921,9 +1934,11 @@
fun testInsertOnMultipleLevels() {
val items = mutableListOf(
1 to mutableListOf(
- 0, 1, 2, 3, 4),
+ 0, 1, 2, 3, 4
+ ),
3 to mutableListOf(
- 0, 1, 2, 3, 4)
+ 0, 1, 2, 3, 4
+ )
)
val invalidates = mutableListOf<() -> Unit>()
@@ -2375,13 +2390,17 @@
private fun <T> assertArrayEquals(message: String, expected: Array<T>, received: Array<T>) {
fun Array<T>.getString() = this.joinToString(", ") { it.toString() }
- fun err(msg: String): Nothing = error("$message: $msg, expected: [${
- expected.getString()}], received: [${received.getString()}]")
+ fun err(msg: String): Nothing = error(
+ "$message: $msg, expected: [${
+ expected.getString()}], received: [${received.getString()}]"
+ )
if (expected.size != received.size) err("sizes are different")
expected.indices.forEach { index ->
if (expected[index] != received[index])
- err("item at index $index was different (expected [${
- expected[index]}], received: [${received[index]}]")
+ err(
+ "item at index $index was different (expected [${
+ expected[index]}], received: [${received[index]}]"
+ )
}
}
@@ -2423,11 +2442,14 @@
@OptIn(InternalComposeApi::class, ExperimentalComposeApi::class)
private fun <T> doCompose(composer: Composer<*>, block: () -> T): T {
- val snapshot = takeMutableSnapshot({
- composer.recordReadOf(it)
- }, {
- composer.recordWriteOf(it)
- })
+ val snapshot = takeMutableSnapshot(
+ {
+ composer.recordReadOf(it)
+ },
+ {
+ composer.recordWriteOf(it)
+ }
+ )
return try {
snapshot.enter { block() }.also {
snapshot.apply().check()
diff --git a/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/SlotTableTests.kt b/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/SlotTableTests.kt
index aa920b2..63130b4 100644
--- a/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/SlotTableTests.kt
+++ b/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/SlotTableTests.kt
@@ -1277,8 +1277,7 @@
if (width > 0)
for (childKey in 1..width) {
tree(childKey, width - 1, depth + 1)
- }
- else if (depth > 0) {
+ } else if (depth > 0) {
tree(1001, width, depth - 1)
} else {
repeat(depth + 2) {
diff --git a/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/collection/MutableVectorTest.kt b/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/collection/MutableVectorTest.kt
index 30034eb..8c3c92fb 100644
--- a/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/collection/MutableVectorTest.kt
+++ b/compose/runtime/runtime/src/test/kotlin/androidx/compose/runtime/collection/MutableVectorTest.kt
@@ -303,9 +303,12 @@
@Test
fun foldIndexed() {
- assertEquals("01-12-23-34-45-", list.foldIndexed("") { index, acc, i ->
- "$acc$index$i-"
- })
+ assertEquals(
+ "01-12-23-34-45-",
+ list.foldIndexed("") { index, acc, i ->
+ "$acc$index$i-"
+ }
+ )
}
@Test
@@ -315,9 +318,12 @@
@Test
fun foldRightIndexed() {
- assertEquals("45-34-23-12-01-", list.foldRightIndexed("") { index, i, acc ->
- "$acc$index$i-"
- })
+ assertEquals(
+ "45-34-23-12-01-",
+ list.foldRightIndexed("") { index, i, acc ->
+ "$acc$index$i-"
+ }
+ )
}
@Test