New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve conflict with JDK15's new isEmpty
method on CharSequence
#9239
Conversation
This way allows only to compile but not use it. Close pull request because it is a wrong and very bad way. |
OK I'm cancelling the 1-800-flowers. It's a very annoying issue, so the swing is appreciated. |
@som-snytt I was very optimised about impact. Right now I doubt that it can be solved. |
@catap Note that it would have been sufficient to PR the change on 2.11.x, unless nontrivially different code was needed on the different branches. We merge everything forward from 2.11.x -> 2.12.x -> 2.13.x. |
@SethTisue I can't just cherry-pick it because it created some conflicts => I solved it. Anyway, after a day of thinking about this bug I see that it should be solved on two levels:
So, I would like to reopen my PRs. Anyway tests are broken and if someone from the team thinks that it shouldn't be used — I'm OK with this. |
isEmpty
method on CharSequence
@SethTisue I made the first attempt to force selection of scala This allows to produce on JDK15 a bytecode that runs on JVM before 15 that is good. Anyway, I'm a bit concern about my naive approach. I've used But I afraid that it costs too much in terms of performance. If you have something better in mind I'd love to ask some help. |
isEmpty
method on CharSequence
isEmpty
method on CharSequence
f407c0f
to
1f68cf8
Compare
So this is the special-case-it-in-the-compiler way. When I heard about this breakage I was thinking we could make the CharSequence extending implicit non-implicit (so binary compatible) and |
@dwijnand but by this "hack" scala produces the same bytecode that it produces on JDK before 15. Other approach is broking a lot of compatible in strange places, and here I just help to make right decision :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any other way out than compiler support for Array[Char].isEmpty
.
I just thought: what if we add a (intrinsified) macro |
I mean sure, but I have a thousand other things to worry about and all I'm asking is for a decision to be reached soon so I can work with that. |
I don't think there's a clean way to get the synthetic method to work. In order for it to be visible it has to be forced. This works fine except when compiling the standard library using Other synthetic symbols are forced when the So to me it seems that the best solution is to add the stub to |
Hmm, that doesn't work so easily either... After adding |
My only idea here is to do it in 2 steps:
This means it won't be fixed for 2.13.4, only for 2.13.5. We could use a mergely as starr to avoid that. I think this is still better than special-casing implicit search. |
@lrytz am I right that this way is broke compatibility with class file that was compiled with a new standard library and that is using on old one? Let image that some library is updated a scala version that is used to build it to 2.13.5 and user of this library is using 2.13.3. If I understand it right the end user will have very wired runtime exception. |
The |
This seems a lot more complicated then special-casing implicit search, all for a temporary solution anyway (since the correct solution is to change Predef.scala whenever we can break BC), we've also discussed adding a special case in implicit search like this in dotty at a recent dotty meeting and there wasn't any opposition to it, why do you think it's a worse solution? |
It's not that temporary, we'd have to keep it forever in 2.13. Adding the method to |
That would need to be tested, I don't know how their typer deals with macro methods but I wouldn't be surprised if something breaks.
Can already prepare a PR with that change so I can test dotty against the updated Array.scala? |
Also what prevents you from using an intermediate starr based on a nightly instead of waiting for ~3-4 months? |
re-STARRing on a mergely seems quite acceptable to me, we've done it a number of times before |
I mentioned that as an option above. We only do that when really necessary, I'd be fine doing it here. I'm not sure if a nightly on our artifactory is OK or if we should publish something to maven central, for reproducability. |
Historically we have done it to Maven Central. I see no downside. |
Testing the follow up after restarr here: #9288 |
Another approach which could be considered would be to simply make ArrayCharSequence not implicit at the cost of breaking source-compat in hopefully rare cases (but not binary compat): diff --git src/library/scala/Predef.scala src/library/scala/Predef.scala
index c9911f9299..de2b8984a8 100644
--- src/library/scala/Predef.scala
+++ src/library/scala/Predef.scala
@@ -388,12 +388,13 @@ object Predef extends LowPriorityImplicits {
}
/** @group implicit-classes-char */
- implicit final class ArrayCharSequence(arrayOfChars: Array[Char]) extends CharSequence {
+ final class ArrayCharSequence(arrayOfChars: Array[Char]) extends CharSequence {
def length: Int = arrayOfChars.length
def charAt(index: Int): Char = arrayOfChars(index)
def subSequence(start: Int, end: Int): CharSequence = new runtime.ArrayCharSequence(arrayOfChars, start, end)
override def toString = arrayOfChars.mkString
}
+ def ArrayCharSequence(arrayOfChars: Array[Char]): ArrayCharSequence = new ArrayCharSequence(arrayOfChars)
/** @group conversions-string */
@inline implicit def augmentString(x: String): StringOps = new StringOps(x) That's one less implicit conversion in the world which would be a good thing, and for people who really want a CharSequence backed by their Array[Char], the Internet tells me that can be easily accomplished using |
Yes! So by giving it the same name it's not forward binary incompatible. Of course... -.- I'm happy with dropping source compatibility for implicitly enriching |
That does seem like a reasonable option, indeed. |
Intriguing idea... Should we then also deprecate I looked a bit through the history
I guess the main question is how much code we'd break. The community build can tell something about that. |
Alt: #9292 |
java.lang.CharSequence
hasisEmpty
method since JDK 15 that makes impossibly to compile scala by JDK15.Fix it on the way that allows to compiled with JDK15 and before JDK15.
Fixes scala/bug#12172