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

Fix hold1 #3112

Merged
merged 7 commits into from
Feb 4, 2023
Merged

Fix hold1 #3112

merged 7 commits into from
Feb 4, 2023

Conversation

armanbilge
Copy link
Member

Fixes #3081.

Copy link
Contributor

@Jasper-M Jasper-M left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a shame that uncons and concurrently don't seem to be composable.

@mpilquist
Copy link
Member

Still a shame that uncons and concurrently don't seem to be composable.

I wouldn't necessarily conclude that. There's some bug hiding here that broke hold1 but I'd be surprised if that bug was something fundamental about uncons and concurrently interactions.

@armanbilge
Copy link
Member Author

I'd be surprised if that bug was something fundamental about uncons and concurrently interactions.

Yes, it needed the zip as well.

I don't really understand how all this scoping works, but it seemed like what was happening was some scope was being opened in the uncons, and because the tail was being run elsewhere concurrently, it was unable to locate this already open scope. If my understanding is right, then we are lacking some mechanism to thread that opened scope through.

@armanbilge
Copy link
Member Author

Wait, maybe there is a way :) let me try something

/** Extends the scope of the currently open resources to the specified stream,
* preventing them from being finalized until after `s` completes execution,
* even if the returned pull is converted to a stream, compiled, and
* evaluated before `s` is compiled and evaluated.
*/
def extendScopeTo[F[_], O](
s: Stream[F, O]
)(implicit F: MonadError[F, Throwable]): Pull[F, Nothing, Stream[F, O]] =

@armanbilge
Copy link
Member Author

No, that didn't work either. be8d3e7

@armanbilge
Copy link
Member Author

Yeah, so extendScopeTo extended the lifetime of the scope, but it still didn't use that scope to compile the concurrent stream.

@armanbilge
Copy link
Member Author

I experimented with the idea that the scope of the background stream in concurrently should be part of the scope tree of the foreground stream, instead of creating its own root scope. I believe that would solve this issue, without requiring to change the implementation of hold1.

I tried two different approaches, either interfacing directly with Pull.compile or adding a new API stream.compileScope(scope).

  • 779a170 fixes hold1, but breaks concurrently
  • 576acc4 didn't fix hold1, but didn't break concurrently

Once I've mustered up new courage I'll probably take another shot at it.

}.streamNoScope

Stream.eval(Deferred[F2, Signal[F2, O2]]).flatMap { signal =>
Stream.eval(signal.get).concurrently(go(signal))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in Stream.never if the signal never gets completed, e.g. if this is empty.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the behavior we want, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. An empty stream is also an option. That's what the original implementation did afaict.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, we are not concerned with the case Stream.never.hold1 (which never emits but never ends) but with the case Stream.empty.hold1. So there should be an onFinalize or something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the fix was even easier than I realized, no need for onFinalize :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scope lookup failure with hold1
3 participants