Freeze event-type ABI: internal constructors + consistent copy() (closes #15)#26
Merged
Conversation
After this commit HttpEvent, MqttEvent and BleEvent expose no public way to construct or copy() them — only to read, destructure, and `when`-match. This unfreezes their field list: a future field can be added without a source or binary break for consumers, the whole point of #15. What changed: - Primary constructors are now `internal` (instances are only built inside the loggers/PreviewData, all in-module). `data` is kept, so componentN destructuring and `when`-matching still work for consumers. - Added `@ConsistentCopyVisibility` so the generated `copy()`/`copy$default` inherit the internal constructor's visibility. Without it Kotlin keeps copy() public for back-compat, leaving the copy() ABI frozen against new fields — a half-freeze that defeats the issue's purpose. - Regenerated the BCV dumps (jvm `.api` + native `.klib.api`) for both modules: the `<init>`, `copy` and `copy$default` entries drop out; getters, componentN, equals/hashCode/toString and the computed props stay. Parity: the change is symmetric across :sharingan and :sharingan-noop, so the frozen surface stays identical between them. (The pre-existing `$stable`-field divergence — Compose-only on :sharingan — is untouched here and is for #12 to reconcile.) Verified: :sharingan + :sharingan-noop testDebugUnitTest green; apiDump regenerated; sample (consumer) compiles against the narrowed surface; sample constructs no events directly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8b38f1c to
8a96f9c
Compare
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.
What
HttpEvent,MqttEvent,BleEventwerepublic data classes with all-public constructors, but instances are only ever built inside the loggers — consumers only read them. Public constructors (andcopy()) freeze the field list: adding a field later is a source/binary break. This narrows the surface so a field can be added later without breaking consumers. Closes #15.Changes
internalon all three event types in both:sharinganand:sharingan-noop.datais kept, so consumers can still destructure (componentN) andwhen-match.@ConsistentCopyVisibilityso the generatedcopy()/copy$defaultfollow the now-internalconstructor..api+.klib.api) for both modules.copy()is also frozenThe issue asked for
internalconstructors. Aninternalconstructor alone leavescopy()public (Kotlin keeps it public for back-compat) — soevent.copy()would still be a frozen ABI and adding a field would still break it. That's a half-freeze that doesn't deliver #15's stated goal.I went the full-freeze route with
@ConsistentCopyVisibility, which removes publiccopy()/copy$defaulttoo. Net effect on the public surface:If you'd rather keep
copy()public (constructor-only freeze), drop the three@ConsistentCopyVisibilityannotations and re-run./gradlew apiDump.Parity note (relevant to #12)
The change is symmetric across both modules, so the frozen surface stays identical between
:sharinganand:sharingan-noop. Separately, I noticed a pre-existing divergence the parity check (#12) must handle::sharinganevent classes carry a Compose$stablefield that:sharingan-noopdoesn't (Compose is only on the real module). It predates this PR — flagging it so #12's parity check normalizes/ignores$stablerather than failing on it.Acceptance criteria
internalwhen-match/destructure still compiles (sample builds; sample constructs no events).apidumps regenerated to reflect the narrowed surfaceVerification
:sharingan:testDebugUnitTest+:sharingan-noop:testDebugUnitTestgreen ·./gradlew apiDumpregenerated ·:sample:composeApp:compileDebugKotlinAndroidgreen.🤖 Generated with Claude Code