arkivanov / Decompose

Kotlin Multiplatform lifecycle-aware business logic components (aka BLoCs) with routing (navigation) and pluggable UI (Jetpack Compose, SwiftUI, JS React, etc.)
https://arkivanov.github.io/Decompose
Apache License 2.0
2.25k stars 85 forks source link

iOS: Error when updating to 3.1.0 (PageScrollAnimation) #727

Closed oblakr24 closed 4 months ago

oblakr24 commented 5 months ago

I have a KMP project (Kotlin 2.0.0) with an iOS target. Updating from 3.0.0 to 3.1.0 (Essenty at 2.0.0) works fine on Android and Desktop, but on iOS I get the following build failure:

error: org.jetbrains.kotlin.backend.konan.llvm.NativeCodeGeneratorException: Exception during generating code for following declaration:
Inside: FILE fqName:feature.main fileName:/Users/rokoblak/Projects/PersonaLLM/composeApp/src/commonMain/kotlin/feature/main/MainScreen.kt

This is a composable in my app which is a page in a pager.

Pages(
            pages = component.pages,
            onPageSelected = component::selectPage,
            modifier = Modifier.padding(padding).fillMaxSize(),
           scrollAnimation = PagesScrollAnimation.Default,

and is specifically related to this line: scrollAnimation = PagesScrollAnimation.Default, commenting out this line solves the issue.

The root stacktrace below:

Caused by: java.lang.IllegalStateException: FIELD name:com_arkivanov_decompose_extensions_compose_pages_PagesScrollAnimation_Default$stable type:kotlin.Int visibility:public [final,static]
    at org.jetbrains.kotlin.backend.konan.llvm.LlvmDeclarations.forStaticField(LlvmDeclarations.kt:53)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.staticFieldPtr(IrToBitcode.kt:1871)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateGetField(IrToBitcode.kt:1767)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:983)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression$default(IrToBitcode.kt:971)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExplicitArgs(IrToBitcode.kt:2366)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateCall(IrToBitcode.kt:2237)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:975)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression$default(IrToBitcode.kt:971)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExplicitArgs(IrToBitcode.kt:2366)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateCall(IrToBitcode.kt:2237)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:975)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression$default(IrToBitcode.kt:971)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExplicitArgs(IrToBitcode.kt:2366)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateCall(IrToBitcode.kt:2237)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:975)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateContainerExpression(IrToBitcode.kt:2215)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:991)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.generateWhenCase(IrToBitcode.kt:1346)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateWhen(IrToBitcode.kt:1314)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression(IrToBitcode.kt:987)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateExpression$default(IrToBitcode.kt:971)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.generateStatement(IrToBitcode.kt:1012)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.generateStatement$default(IrToBitcode.kt:1010)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitFunction(IrToBitcode.kt:888)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitSimpleFunction(IrElementVisitorVoid.kt:144)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitSimpleFunction(IrToBitcode.kt:244)
    at org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid$DefaultImpls.visitSimpleFunction(IrElementVisitorVoid.kt:140)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitSimpleFunction(IrToBitcode.kt:244)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitSimpleFunction(IrToBitcode.kt:244)
    at org.jetbrains.kotlin.ir.declarations.IrSimpleFunction.accept(IrSimpleFunction.kt:36)
    at org.jetbrains.kotlin.ir.declarations.IrFile.acceptChildren(IrFile.kt:34)
    at org.jetbrains.kotlin.ir.visitors.IrVisitorsKt.acceptChildrenVoid(IrVisitors.kt:15)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitFile$lambda$41$lambda$40(IrToBitcode.kt:606)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.runAndProcessInitializers(IrToBitcode.kt:455)
    at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.visitFile(IrToBitcode.kt:605)
    ... 188 more

error: Compilation finished with errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':composeApp:linkDebugFrameworkIosSimulatorArm64'.
> Compilation finished with errors

Please let me know if I can provide any further info.

arkivanov commented 5 months ago

What compose version are you using? Could you please try using Essenty 2.1.0 and Compose 1.6.10?

oblakr24 commented 5 months ago

@arkivanov yep I used Essenty 2.1.0 (just tried with 2.0.0 to ensure which version bump was related to the issue).

I am using 1.6.11:

compose-plugin = "1.6.11"
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
arkivanov commented 5 months ago

Would it be possible to provide a reproducer?

arkivanov commented 5 months ago

This looks like a compiler bug.

oblakr24 commented 5 months ago

I have the app here: https://github.com/oblakr24/personallm

I am assuming the minimal reproducible scenario would be a Pager with this animation, but haven't set that up to validate.

But yes, it does seem like a compiler bug. Perhaps related (but closed?): https://github.com/JetBrains/compose-multiplatform/issues/4809

arkivanov commented 5 months ago

That issue looks related, thanks! I would check a reproducer and report a bug to Compose, if you could provide a link to a runnable project with the failing changes.

oblakr24 commented 5 months ago

I pushed the bump here: https://github.com/oblakr24/personallm/tree/feature/decompose-to-3.1.0 the project should be runnable (no other setup needed). I can try setting up a smaller project later (not today) with min repro scenario.

arkivanov commented 5 months ago

Thanks! I managed to create a minimal reproducer. Reported here: https://github.com/JetBrains/compose-multiplatform/issues/4809#issuecomment-2169302897

Let's keep this bug open for visibility purposes.

arkivanov commented 5 months ago

The suggested workaround works. Add the following lines to gradle.properties.

kotlin.native.cacheKind=none
compose.kotlin.native.manageCacheKind=false
oblakr24 commented 5 months ago

Great, thank you, the workaround works for me too. But yes let's keep it open until the related CMP issue is resolved.

arkivanov commented 4 months ago

Looks like this issue should be fixed in Kotlin 2.0.10, the fix is already available in Kotlin 2.0.10-RC2. See https://github.com/JetBrains/compose-multiplatform/issues/4809#issuecomment-2245621488. Closing this for now.