feat(compose): Support the Kotlin 2.4 compiler plugin#1253
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 041b81b. Configure here.
| * Default is disabled. | ||
| */ | ||
| val debug: Property<Boolean> = objects.property<Boolean?>(Boolean::class.java).convention(false) | ||
| val debug: Property<Boolean> = objects.property(Boolean::class.java).convention(false) |
There was a problem hiding this comment.
small breaking API change
| autoServiceAnnotatons = { group = "com.google.auto.service", name = "auto-service-annotations", version = "1.1.1" } | ||
| kotlinJunit = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit", version.ref = "kotlin" } | ||
| kotlinCompileTesting = { group = "dev.zacsweers.kctfork", name = "core", version = "0.7.1" } | ||
| # Pre-release: first kctfork that supports the Kotlin 2.4 compiler. Pin to a stable release once available. |
There was a problem hiding this comment.
TODO remove this comment
| // regular value parameters, otherwise modifier-receiver chains (e.g. | ||
| // Modifier.fillMaxSize().padding()) would each get their receiver wrapped as well. | ||
| if ( | ||
| valueParameter.kind == IrParameterKind.Regular && |
There was a problem hiding this comment.
Seems like this was an existing bug due to an existing bug in kctfork.
See this PR for this change independently: https://github.com/getsentry/sentry-android-gradle-plugin/pull/1254/changes
| plugins { | ||
| alias(libs.plugins.kotlin) version "2.1.0" | ||
| alias(libs.plugins.kapt) version "2.1.0" | ||
| alias(libs.plugins.kotlin) version "2.3.21" |
There was a problem hiding this comment.
Setting to 2.3.21 let's us keep our language version here at 1.9
| import org.jetbrains.kotlin.name.Name | ||
| import org.jetbrains.kotlin.name.SpecialNames | ||
|
|
||
| // Modified duplicate of JetpackComposeTracingIrExtension22, compiled against 2.4.0 |
There was a problem hiding this comment.
This was generated by claude and I don't have the full context on what to check here, it is mostly a copy.
|
| get() = true | ||
|
|
||
| val pluginId: String = PLUGIN_ID | ||
| override val pluginId: String = PLUGIN_ID |
There was a problem hiding this comment.
oh, I recall doing that #1046 (comment), but I guess now we're compiling against 2.3.x and it should be good?
There was a problem hiding this comment.
seems like that is true (since we now have KGP 2.3)
|
Great work!! |
Replace deprecated toLowerCase/toUpperCase(Locale) with lowercase/ uppercase, and drop the invalid nullable Boolean type argument on the debug property so it matches the declared Property<Boolean> type. These were failing :plugin-build:compileKotlin on the CI matrix. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Kotlin 2.4 replaced ProjectExtensionDescriptor with ExtensionPointDescriptor as the IrGenerationExtension registration descriptor, so the shared registerExtension call (compiled against one compiler version) threw a ClassCastException at runtime on a mismatched compiler. Move the registration into per-version helpers compiled against their own compiler ABI and have SentryKotlinCompilerPlugin only dispatch using version-stable APIs, so a single artifact registers correctly on every supported Kotlin version. Add a kotlin2400 variant built against 2.4.0 and bump the module's Kotlin Gradle Plugin to 2.4.0 (language version 2.0), which is required to read 2.4 compiler metadata. The instrumentation tests are temporarily ignored because no stable kotlin-compile-testing release supports the 2.4 compiler yet; the 2.4 path remains covered by the sample-app builds in the test matrix. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Kotlin 2.4's unified parameter API lists dispatch/extension/context receivers in IrFunction.parameters, so the 2.4 variant tagged the Modifier receivers of chained calls (e.g. Modifier.fillMaxSize().padding()) in addition to the composable's modifier argument, injecting three sentryTag calls instead of one. Restrict wrapping to IrParameterKind.Regular arguments. Bump kotlin-compile-testing (kctfork) to 0.13.0-alpha01, the first release that supports the Kotlin 2.4 compiler, and re-enable the instrumentation tests that exercise this path. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Build the compiler-plugin module with Kotlin Gradle Plugin 2.3.21 instead of 2.4.0 so the language version can stay at 1.9 and the tests can use a stable kotlin-compile-testing (0.12.1); a 2.3 compiler can still read the 2.4.0 metadata needed to build the kotlin2400 variant. Running the instrumentation tests on the 2.3 compiler surfaced that the unified IrFunction.parameters API (Kotlin 2.2+) also lists dispatch, extension and context receivers, so the 2.2.0 variant tagged the Modifier receivers of chained calls (e.g. Modifier.fillMaxSize().padding()) in addition to the composable's modifier argument. Restrict wrapping to IrParameterKind.Regular arguments, matching the 2.4.0 variant. The 1.9.24 and 2.1.20 variants use the older valueParameters API and are unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
d73287f to
cdd7724
Compare

What
ProjectExtensionDescriptorwithExtensionPointDescriptoras theIrGenerationExtensionregistration descriptor, so the single shared registration call threwIrGenerationExtension$Companion cannot be cast to ProjectExtensionDescriptorat runtime on the matrix. Registration is now delegated to per-version helpers (registerComposeTracing19/21/22/24), each compiled against its own compiler ABI, withSentryKotlinCompilerPluginonly dispatching via version-stable APIs. A newkotlin2400variant (built againstkotlin-compiler-embeddable:2.4.0) handles 2.4 IR generation.Modifier.fillMaxSize().padding()) were tagged multiple times. Since Kotlin 2.2 the unifiedIrFunction.parametersAPI also lists dispatch/extension/context receivers, so the receivers of chained calls got wrapped too. Wrapping is now restricted toIrParameterKind.Regulararguments. Affects the 2.2.0 and 2.4.0 variants; the 1.9.24 / 2.1.20 variants use the oldervalueParametersAPI and are unaffected.toLowerCase/toUpperCase(Locale)→lowercase/uppercase, and removes an invalid<Boolean?>type argument on thedebugextension property (it staysProperty<Boolean>).Why
The nightly AGP/Gradle/Kotlin test matrix started exercising Kotlin 2.4 and failed at compiler-plugin registration, on top of the pre-existing deprecation and type-mismatch compile errors.
Closes #1257
Fixes Gradle-105
How
kotlin2400variant, while keepinglanguageVersionat 1.9 and allowing a stablekotlin-compile-testing(0.12.1).Notes
kotlin2400variant is exercised end-to-end by the matrix's sample-app builds; the module's unit tests run on the 2.3 compiler and cover the fixedExtension22path.