Version overloading #431
Replies: 7 comments 10 replies
-
Why? It seems beneficial to have deprecated-hidden |
Beta Was this translation helpful? Give feedback.
-
Mainly because of the implementation clashes due to the different use cases. The current implementation of @JvmOverloads
fun xyz(a: Int = b, b: Int = 1) { ... } The generated overload is For version overloading though we need to copy the default values since the use case is compatibility with older (mostly Kotlin) binaries. In this case, the compiler can copy the default value as long as fun xyz(@IntroducedAt("2") a: Int = b, b: Int = 1) { ... } // deprecated overload: fun xyz(b: B = 1)
fun xyz(a: Int = b, @IntroducedAt("2") b: Int = 1) { ... } // error! 'a' depends on a "future" parameter 'b' There are also problems with the overload deprecation. JvmOverloads does not deprecate-hide the generated overloads to allow discoverability from Java source code, while version overloading deprecates to prevent users from using older signatures. The implementations will also have to be tightly coupled in order to prevent overload signatures clash, but this might be a lesser concern. |
Beta Was this translation helpful? Give feedback.
-
So,
Maybe I'm not seeing something, but this should be solved by lowering |
Beta Was this translation helpful? Give feedback.
-
I just realized the example
This could work, although I'm not sure how we should handle cases like this: @JvmOverloads
fun xyz(
a: Int = 1,
@IntroducedAt("3") a1: Int = 2,
@IntroducedAt("2") b : Int = 3,
) { }
/* Which ones to choose?
IntroducedAt overloads:
1. @Deprecated fun xyz(a: Int = 1)
2. @Deprecated fun xyz(a: Int = 1, b: Int = 3)
JvmOverloads overloads:
3. fun xyz()
4. fun xyz(a: Int) // clash with 1
5. fun xyz(a: Int, a1: Int) // clash with 2
*/ If we choose the overloads 1, 2, and 3, it preserves binary compatibility but breaks the expected behavior of JvmOverloads. Let's say we call This is very similar with the source compatibility problem mentioned in the text which can be solved by providing arguments by name, but we can't do that in Java. This might still be a reasonable trade-off, but I don't know how acceptable it is to most users. What do you think? |
Beta Was this translation helpful? Give feedback.
-
I'm somewhat puzzled by the format requirements, which somehow suggest using the exact release name ("1.1.0.1") of the change. But I'd say that is often unknown during the development time. So I'm thinking that practically, I should rather resort to simple "incremental" single-digit versioning. How do you think the workflow should look? Do you expect actual release version usage, or is it generally open to whatever suits the author? Do you have any feedback e.g. from Google that Compose will use it somehow? |
Beta Was this translation helpful? Give feedback.
-
The current proposal doesn't allow adding new optional parameters in the middle, only to the end. What if we sorted the parameters in the binary signature in the following way? This way, we could allow to add parameters in the middle. Downsides? (1) This approach kinda assumes that Java is a second class citizen. Java can only understand parameters by their order, and the order of parameters in the binary signature is no longer optimal from the programmers point of view but it's optimal from the binary signature point of view. For example: fun poorJava(
textFont: Int = 1,
@IntroducedAt("2") textSize: Int = 1,
@IntroducedAt("1") background: Int = 1,
) {} // binary signature: poorJava(textFont, background, textSize) Although, it's more optimal and logical to put textFont and textSize together, they are separate, and Java will see them separately. |
Beta Was this translation helpful? Give feedback.
-
Thank you for this proposal, I believe it would be helpful in reducing some of the maintenance pain we experience with Compose. Version StringMy biggest bit of feedback is around the constraints on the version string. The proposed format requirements would likely work just fine for Compose, however it seems like an unnecessary constraint to put on the parameter, and some libraries which might want to specify more specific versions which may have alpha characters shouldn't be prevented from using this feature unnecessarily in that case. I believe having all strings be valid seems desirable. Related, however, is how the version strings are ordered if you open them up to be unconstrained. I think the main requirement here would be to preserve the "expected" behavior for version strings like "1.9.0" being earlier in the sequence than something like "1.10.0", (so not a standard alphanumeric sort). The linked Maven sort order would work fine, but I think the main requirement here is that it is well specified / well known and resolves cases like the one above "correctly". Source vs Binary CompatibilityAs a broader point, in Compose, we have a strict binary compatibility requirement, but no such source compatibility requirement. Of course we strive for source compatibility, however it is often impractical or impossible. A big reason for this is due to call sites being able to take the form of named/unnamed arguments, with the last parameter being able to be specified with trailing lambda syntax for lambdas or fun interfaces. We have also done this as a result of the overloads being otherwise ambiguous due to the types of two semantically different parameters being the same. It is our hope that the required named parameters proposal will help dramatically in being able to ensure source compatibility more often. For this reason, I suspect Validation (5) and (6) would have a few instances in the Compose code base where they would need to be suppressed if we were to refactor manually written deprecated overloads in favor of a single API with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is an issue for discussion of version overloading proposal. The full text of the proposal is here.
Please use this issue for the discussion on the substance of the proposal. For minor corrections to the text, please open comment directly in the PR #423.
Beta Was this translation helpful? Give feedback.
All reactions