https://kotlinlang.org logo
#k2-early-adopters
Title
# k2-early-adopters
d

dniHze

11/20/2023, 4:41 PM
👋 We run an experiment trying to determine how K2 performs for us on 2.0.0 Beta1, and we run into a compiler error. We are not sure what's exactly causing it. I've tried reproducing it in a sample project, but I failed to reproduce the issue that way. I'm attaching more details down in 🧵 to keep the feed clean.
This is an android project: Plugins: AGP
8.3.0-alpha14
, KAPT3 enabled, Dagger + Dagger Android Processor
2.48.1
(in kapt classpath), Compose Compiler
1.5.5-dev-k2.0.0-Beta1-06b8ae672a4
. It fails on
kaptGenerateStubsDebugKotlin
step with
KotlinFrontEndException
Copy code
w: Kapt currently doesn't support language version 2.0+. Falling back to 1.9.
e: org.jetbrains.kotlin.util.KotlinFrontEndException: Exception while analyzing expression in (56,15) in /Users/***/EducationFeatureLabsActivity.kt

Attachments:
causeThrowable
java.lang.AssertionError: Not an exact function type: [@kotlin.ExtensionFunctionType] [@androidx.compose.runtime.Composable] Function0<NO_EXPECTED_TYPE>
***
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1611)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

----
expression.kt
<File name: EducationFeatureLabsActivity.kt, Physical: true>
{
            ScrollColumn(
                contentPadding = PaddingValues(Regular),
                verticalArrangement = Arrangement.spacedBy(Regular),
            ) <ELEMENT>{
                Asset(id = IllustrationsR.il_education_step0)
                Asset(id = IllustrationsR.il_carousel_0)
                Asset(id = IllustrationsR.il_carousel_1)
                Asset(id = IllustrationsR.il_carousel_2)
                Asset(id = IllustrationsR.il_carousel_3)
                Asset(id = IllustrationsR.il_carousel_4)
                Asset(id = IllustrationsR.il_carousel_5)
                Asset(id = IllustrationsR.il_education_step1)
                Asset(id = IllustrationsR.il_education_step3)
            }</ELEMENT>
        }
	at org.jetbrains.kotlin.types.expressions.ExpressionTypingVisitorDispatcher.logOrThrowException(ExpressionTypingVisitorDispatcher.java:261)
***
Here is the code block in question. Compiler gives it a pass if
val entries
is converted to
@Composable fun entries()
. It also works as expected using
1.9.20
. I'm not sure who to blame there, but I suspect it's something with how KAPT compat mode implemented.
Copy code
internal class EducationFeatureLabsActivity : BaseDaggerAppCompatActivity() {

    @Inject
    internal lateinit var contentStringLoader: ContentStringLoader

    ***

    private val entries: List<Entry> = listOf(
        Entry.Content("Assets") {
            ScrollColumn(
                contentPadding = PaddingValues(Regular),
                verticalArrangement = Arrangement.spacedBy(Regular),
            ) {
                Asset(id = IllustrationsR.il_education_step0)
                Asset(id = IllustrationsR.il_carousel_0)
                Asset(id = IllustrationsR.il_carousel_1)
                Asset(id = IllustrationsR.il_carousel_2)
                Asset(id = IllustrationsR.il_carousel_3)
                Asset(id = IllustrationsR.il_carousel_4)
                Asset(id = IllustrationsR.il_carousel_5)
                Asset(id = IllustrationsR.il_education_step1)
                Asset(id = IllustrationsR.il_education_step3)
            }
        },
        Entry.Content("Launch Single Page Education") {
            EducationIntroLabsView()
        },
        Entry.Action("FAQs") {
            faqLauncher.start()
        },
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            CuvvaTheme {
                EducationLabsUi(
                    entries = entries,
                    onNavigateUp = ::finish,
                )
            }
        }
    }

    ***
}
Side note: we also measured our performance, and we noticed that app build is taking longer with 2.0.0. Configuration time is up by 2 seconds, and compiler performs roughly the same if not slightly worse in some scenarios. This is what we got using Gradle Profiler with 1.9.20 and 2.0.0. It's probably because we still have just a little of Java as well as KAPT in 50% of our modules.
👀 4
p

Pavel Mikhailovskii

11/22/2023, 1:12 PM
It would be very helpful if you could provide more information regarding your project and the performance-related findings. Could you maybe identify which Gradle tasks cause performance issues?
4 Views