Skip to content
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

Implement Java Streams #4926

Open
gzm0 opened this issue Jan 5, 2024 · 5 comments
Open

Implement Java Streams #4926

gzm0 opened this issue Jan 5, 2024 · 5 comments
Labels
missing javalib Report of something from the JDK that is missing (does not link)

Comments

@gzm0
Copy link
Contributor

gzm0 commented Jan 5, 2024

Following up from
#4925 (comment)_

IMHO Java streams are sufficiently important that if we cannot support them, we should at the very least formally document that (and why).

@gzm0
Copy link
Contributor Author

gzm0 commented Jan 6, 2024

I've had a look at the java.util.stream package and I really do not see any major reason why we cannot support it.

Of course, we will not be able to offer parallel streams. This means, we should probably not even define all the parallel methods.

There is the (unfortunate) nuisance that the methods on StreamSupport take parallel as an argument. So we'd have to resort to throwing UnsupportedOperationException in this case (which given how low-level the class is, seems acceptable to me).

@sjrd, what am I missing? :)

@gzm0
Copy link
Contributor Author

gzm0 commented Jan 7, 2024

Note on Collection#parallelStream.

Returns a possibly parallel Stream with this collection as its source. It is allowable for this method to return a sequential stream.

So just ignoring request for parallelism might be just fine.

@sjrd
Copy link
Member

sjrd commented Jan 7, 2024

I had another look and I cannot find anything that is a total deal-breaker. The StreamSupport issue is annoying, but perhaps we can simply not provide StreamSupport at all. It is a static-only helper class, which is not interleaved in the rest of the API.

The fact that parallel() is abstract in BaseStream and its public subinterfaces means that third-party code will have trouble implementing their own stream subclasses: if they don't declare an implementation of parallel(), the compiler will complain that it is left abstract; but if they do, they inevitably break its contract. Some IR post-processing may fix that issue, but that's harsh to ask of third-party implementers.

Note on Collection#parallelStream.

Returns a possibly parallel Stream with this collection as its source. It is allowable for this method to return a sequential stream.

So just ignoring request for parallelism might be just fine.

It does have an Implementation Requirements section that says that the default implementation returns a parallel stream, so I think it is still off-limits.

@gzm0
Copy link
Contributor Author

gzm0 commented Jan 7, 2024

The StreamSupport issue is annoying, but perhaps we can simply not provide StreamSupport at all. It is a static-only helper class, which is not interleaved in the rest of the API.

Fair enough. Feels to me like we definitely want something like this to implement streams, but at least for starters, it can be private to the javalib without the parallel parameter.

Some IR post-processing may fix that issue, but that's harsh to ask of third-party implementers.

True. But I guess we agree that providing streams simply for usage is worth it in its own right at least as a first step?

It does have an Implementation Requirements section that says that the default implementation returns a parallel stream, so I think it is still off-limits.

True :-/

In any case, do you agree that based on this, we should re-open #4925?

@sjrd sjrd added the missing javalib Report of something from the JDK that is missing (does not link) label Jan 7, 2024
@sjrd
Copy link
Member

sjrd commented Jan 7, 2024

Some IR post-processing may fix that issue, but that's harsh to ask of third-party implementers.

True. But I guess we agree that providing streams simply for usage is worth it in its own right at least as a first step?

Yes, it's probably viable for usage-only at first.

In any case, do you agree that based on this, we should re-open #4925?

Reopened.

@gzm0 gzm0 changed the title Figure out if we can support java streams (and if not, why not) Implement Java Streams Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing javalib Report of something from the JDK that is missing (does not link)
Projects
None yet
Development

No branches or pull requests

2 participants