Repository navigation
fix(compiler-plugin): resolve ABI incompatibilities with Kotlin 2.4+ runtimes - #121
Draft
aryapreetam wants to merge 1 commit into
Draft
aryapreetam wants to merge 1 commit into
aryapreetam wants to merge 1 commit into
Conversation
…runtimes - Kotlin 2.4 changed the parameter type of ExtensionStorage.registerExtension from ProjectExtensionDescriptor to ExtensionPointDescriptor, causing ClassCastException. Resolve and invoke registerExtension reflectively to support both 2.3.x and 2.4+ runtimes. - Kotlin 2.4 requires metadata-visible declarations to implement IrAnnotation. Instantiate IrAnnotationImpl reflectively on 2.4+ while falling back to IrConstructorCallImpl on 2.3.x. - Guard HiddenFromObjC lookup so it only runs on Kotlin/Native targets.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Consuming projects targeting Kotlin 2.4+ (such as projects on Compose Multiplatform 1.11+ using Kotlin 2.4.10 or 2.4.20) fail during compilation:
ExtensionStorage.registerExtensionfromProjectExtensionDescriptortoExtensionPointDescriptor. When a compiler daemon running Kotlin 2.4 executes the plugin compiled against Kotlin 2.3, this causes aClassCastException.metadataDeclarationRegistrar.addMetadataVisibleAnnotationsToElementmust implementIrAnnotation(instantiated viaIrAnnotationImpl). PassingIrConstructorCallImplresults in aClassCastException.HiddenFromObjCwas being resolved on all compilation targets, rather than being restricted to Kotlin/Native targets.Solution
1. Dynamic Extension Point Registration
In
StorytaleComponentRegistrar.kt, resolve and invokeExtensionStorage.registerExtensionreflectively. This allows the same compiled plugin binary to execute on both Kotlin 2.3.x and Kotlin 2.4+ compiler environments without ABI conflicts.2. Cross-Version IrAnnotation Instantiation
In
StorytaleLoweringExtension.kt, reflectively instantiateIrAnnotationImplviaBuildersKt.fromSymbolOwneron Kotlin 2.4+ runtimes, while falling back toIrConstructorCallImplon Kotlin 2.3.x runtimes.3. Platform-Scoped Native Annotation
Added an
isNativeTargetcheck to ensure theHiddenFromObjCconstructor lookup and annotation application are only executed for Kotlin/Native compilations.Design Decisions
Verification
1. Automated Checks
./gradlew spotlessCheck(passes)./gradlew -p modules/compiler-plugin test(passes)2. Multi-Environment & Multi-Target Execution
Verified live execution across internal and external projects running different Kotlin and AGP environments:
:examples./gradlew :examples:desktopStoriesRun:examples./gradlew :examples:wasmJsBrowserStoriesDevelopmentRunstorytale-sample./gradlew :shared:jvmStoriesRun -PcmpProfile=1.12storytale-sample./gradlew :shared:wasmJsBrowserStoriesDevelopmentRun -PcmpProfile=1.12storytale-sample./gradlew :shared:jvmStoriesRun -PcmpProfile=1.10storytale-sample./gradlew :shared:wasmJsBrowserStoriesDevelopmentRun -PcmpProfile=1.10Reproduction Steps (storytale-sample)
git clone https://github.com/aryapreetam/storytale-sample.git cd storytale-sampleshared/build.gradle.kts, apply the local snapshot:plugins { ... - id("io.github.aryapreetam.storytale") version "0.0.6" + id("org.jetbrains.compose.storytale") version "0.0.4-SNAPSHOT" }