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
feature: Implement experimental javalib IntStream & LongStream classes #3729
feature: Implement experimental javalib IntStream & LongStream classes #3729
Conversation
Wonderful! Today I've made experiment with foundations for publishing Scala projects as dynamic libraries, and that was one of found blockers - some methods in Scala 2 stdlib were using IntStream. |
The prospect of this working getting actual use gladdens my heart!
|
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'm a bit concerned with hard dependencies on {Int/Long}StreamImpl
. I don't fully understand the composition of different Impl classes in Streams, but I worry that a custom Stream
implementation might slip into the pipeline leading to runtime class cast exception. If possible we should either ensure that different Stream implementations would not mixed in the pipeline, or only depend on public API.
Otherwise looks good to me
if (n > 0) { | ||
nextInt(n) + origin | ||
} else { // range not representable as int | ||
var r: Integer = 0 |
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.
Why boxed Integer
instead of primitive Int
?
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.
Good catch. That is bad translation from the Java, not something intentional.
Fixed now.
Thank you for reviewing all this code and doing so on a weekend.
} | ||
|
||
val coercedPriorStages = pipeline | ||
.asInstanceOf[ArrayDeque[IntStreamImpl]] |
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.
Is it possible that pipeline
would contain IntStream
element which is not an instance of IntStreamImpl
? For example, if somebody implements a custom IntStream
, can a custom implementation be added to pipeline? It seems to be possible during flatMap
-like operations. In such case it would fail at runtime.
_parallel, | ||
coercedPriorStages | ||
) | ||
.asInstanceOf[LongStream] |
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.
This cast should not be required. It should be automatically widen to LongStream
by compiler
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.
Fixed in several places in java.util.stream
.
The changes do make the code more idiomatic & consistent.
This is exactly the kind of insightful alternate view I was hoping to get from review. thank you. I would have to check what Java allows. It does not use the "providers" concept for the Stream classes, I propose that this PR, once reasonably passing CI, flow through. It is pretty large & complex already. The entire SN pipeline implementation, across all types of *Streams, is I believe the answer & intent is that no custom implementation of *Stream can slip into the SN pipeline. This means that any custom implementation of one *Stream class would need to implement its own private implementation of the pipeline concept and all other *Stream classes & objects intended to be used So, this gives safety but not ease of extensibility. From studying the quoted comment, I need to do some sandbox work. I have the hint of a way to remove |
Three failures are "usual suspects", all others are Green. |
The javalib
IntStream
andLongStream
classes now have an experimental implementation.A number of classes, noticibly the
Random
andCharSequence
classes, were modifiedto provide previously missing methods which
IntStream
andLongStream
.unit-tests are provided for the change of this PR.
Individual morsels of this PR might be backported to SN 4.n, but the overall PR is
probably not a good candidate: too many interconnected pieces.