Skip to content

Add NonEmptyHotswap #4267

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

Merged

Conversation

morgen-peschke
Copy link
Contributor

@morgen-peschke morgen-peschke commented Feb 6, 2025

Also corrects the site docs for Hotswap so it conforms to the Hotswap API

Addresses #4268

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Honestly, I wonder if we should deprecate the old HotSwap.

  1. Hotswap[F, A] is just NonEmptyHotswap[F, Option[A]]. We don't need both.
  2. The current Hotswap API is broken anyway, e.g. see #3480 (comment).

@djspiewak I know you hate it, but there are so many things we could fix if we just embrace the ugly Hotswap2, Queue2, 😅

Oh, also you should retarget to series/3.6.x if you want it to make the next release (@djspiewak are we still merging new APIs into this branch?)

@morgen-peschke morgen-peschke changed the base branch from series/3.x to series/3.6.x February 7, 2025 17:14
@morgen-peschke morgen-peschke force-pushed the add-nonempty-version-of-hotswap branch from 11ca512 to e9965a3 Compare February 7, 2025 17:23
morgen-peschke added a commit to morgen-peschke/cats-effect that referenced this pull request Feb 8, 2025
@kamilkloch
Copy link
Contributor

@djspiewak I know you hate it, but there are so many things we could fix if we just embrace the ugly Hotswap2, Queue2, 😅

sttp has embraced this path a long time ago and it works like a charm :) https://github.com/softwaremill/sttp/tree/master/core/src/main

@morgen-peschke
Copy link
Contributor Author

@armanbilge did you want the Hotswap2 rename?

@armanbilge
Copy link
Member

I do, but I'm not sure if @djspiewak has bought in.

@morgen-peschke
Copy link
Contributor Author

@djspiewak could we get a ping if this is something you'd like to weigh in on?

@morgen-peschke
Copy link
Contributor Author

@armanbilge it's been 6 weeks without a ping from @djspiewak, can we take that as "decline to comment" and proceed?

@morgen-peschke
Copy link
Contributor Author

@armanbilge no shade intended by this question, just want to know if I should close it: is this a dead PR?

@armanbilge
Copy link
Member

@morgen-peschke review and release cycles in Cats Effect are often very slow, sorry about that, and thanks for your patience ☺️

@morgen-peschke
Copy link
Contributor Author

morgen-peschke commented Jun 13, 2025

@armanbilge what's the culturally acceptable frequency of comment-bumping a PR in this state?

I'd really like to offload having to remember to check back on this to a repeating calendar event and I also don't want to be a bother by posting too often just to keep the PR from sliding completely off the radar, if the expectation is that this could be another 3+ months.

ETA: In case the above came across wrong, I want to reiterate that no slight is intended, I'm trying to figure out the best way to manage the time and energy I'm going to spend keeping track of this PR, as well as avoid creating the association in y'all's mind as that annoying dev who won't shut up about that one PR.

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

I spoke to Daniel offline, he is alright with moving ahead with Hotswap2. Thanks for your patience!

I just noticed ... we will need to retarget this PR at series/3.x and I think this will require rewriting the test suite using munit, sorry about that!

Comment on lines 65 to 67
## Hotswap

In cases where the managed `Resource` may be missing, `Hotswap` provides some optimizations for this use case.
Copy link
Member

Choose a reason for hiding this comment

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

Sorry if I'm missing something, what is this sentence referring to exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's referring to some of the stuff that Hotswap does around avoiding blocking swap after a call to get returns a Resource containing a None.

If we're fully deprecating Hotswap, we can probably drop this section entirely.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can fully deprecate Hotswap in favor of Hotswap2.

Hotswap2.create[F, R].map { nes =>
new Hotswap[F, R] {
override def swap(next: Resource[F, R]): F[R] =
nes.swap(next.map(_.some)) *> get.use(_.get.pure[F])
Copy link
Member

Choose a reason for hiding this comment

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

This is the "leaking" implementation, correct? Maybe we should add a comment saying this is intentional, to satisfy the mistakes of the old api.

Comment on lines 60 to 65
* [[swap]] finalizes the previous resource immediately, so users must ensure that the old `R`
* is not used thereafter. Failure to do so may result in an error on the _consumer_ side. In
* any case, no resources will be leaked.
*
* For safer access to the current resource see [[get]], which guarantees that it will not be
* released while it is being used.
Copy link
Member

Choose a reason for hiding this comment

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

These docs can be updated, they are trying to massage around the shortcomings of the old API.

morgen-peschke added a commit to morgen-peschke/cats-effect that referenced this pull request Jul 12, 2025
Squash
- Deprecate Hotswap
- Apply suggestions from code review

  Co-authored-by: Arman Bilge <armanbilge@gmail.com>
- Remove unsafe returned value from swap
- prePR
- Implement Hotswap in terms of NonEmptyHotswap
- Also adds two methods to make `NonEmptyHotswap` a drop-in replacement for `Hotswap`
- Revert "Implement Hotswap in terms of NonEmptyHotswap"
- This reverts commit 8dc9fcf.
- Add a not about the differences between Hotspot and NonEmptyHotspot
- Revert "Add a not about the differences between Hotspot and NonEmptyHotspot"
- This reverts commit bcfb4b0.
- Revert "Revert "Implement Hotswap in terms of NonEmptyHotswap""
- This reverts commit 4b7ebe4.
- Implement lock aquiring shenanigans and restore related test

  Thanks to armanbilge for the [suggestion](typelevel#4267 (comment))
- Switch NonEmptyHotswap to Hotswap2
- Apply suggestions from code review

  Co-authored-by: Arman Bilge <armanbilge@gmail.com>
- Deprecate Hotswap
- Documentation fixes in Hotswap2
- Add Hotswap2.getOpt

  This would allow upgrading from Hotswap without losing the semantics of not acquiring a lock when no resource is present for `Hotswap2[F, Resource[Option[R]]]`
@morgen-peschke morgen-peschke force-pushed the add-nonempty-version-of-hotswap branch from a49624e to bfadf2b Compare July 12, 2025 18:33
morgen-peschke added a commit to morgen-peschke/cats-effect that referenced this pull request Jul 12, 2025
Squash
- Deprecate Hotswap
- Apply suggestions from code review

  Co-authored-by: Arman Bilge <armanbilge@gmail.com>
- Remove unsafe returned value from swap
- prePR
- Implement Hotswap in terms of NonEmptyHotswap
- Also adds two methods to make `NonEmptyHotswap` a drop-in replacement for `Hotswap`
- Revert "Implement Hotswap in terms of NonEmptyHotswap"
- This reverts commit 8dc9fcf.
- Add a not about the differences between Hotspot and NonEmptyHotspot
- Revert "Add a not about the differences between Hotspot and NonEmptyHotspot"
- This reverts commit bcfb4b0.
- Revert "Revert "Implement Hotswap in terms of NonEmptyHotswap""
- This reverts commit 4b7ebe4.
- Implement lock aquiring shenanigans and restore related test

  Thanks to armanbilge for the [suggestion](typelevel#4267 (comment))
- Switch NonEmptyHotswap to Hotswap2
- Apply suggestions from code review

  Co-authored-by: Arman Bilge <armanbilge@gmail.com>
- Deprecate Hotswap
- Documentation fixes in Hotswap2
- Add Hotswap2.getOpt

  This would allow upgrading from Hotswap without losing the semantics of not acquiring a lock when no resource is present for `Hotswap2[F, Resource[Option[R]]]`
@morgen-peschke morgen-peschke force-pushed the add-nonempty-version-of-hotswap branch from bfadf2b to e114c7d Compare July 12, 2025 18:36
@morgen-peschke morgen-peschke changed the base branch from series/3.6.x to series/3.x July 12, 2025 18:37
Squash
- Deprecate Hotswap
- Apply suggestions from code review

  Co-authored-by: Arman Bilge <armanbilge@gmail.com>
- Remove unsafe returned value from swap
- prePR
- Implement Hotswap in terms of NonEmptyHotswap
- Also adds two methods to make `NonEmptyHotswap` a drop-in replacement for `Hotswap`
- Revert "Implement Hotswap in terms of NonEmptyHotswap"
- This reverts commit 8dc9fcf.
- Add a not about the differences between Hotspot and NonEmptyHotspot
- Revert "Add a not about the differences between Hotspot and NonEmptyHotspot"
- This reverts commit bcfb4b0.
- Revert "Revert "Implement Hotswap in terms of NonEmptyHotswap""
- This reverts commit 4b7ebe4.
- Implement lock aquiring shenanigans and restore related test

  Thanks to armanbilge for the [suggestion](typelevel#4267 (comment))
- Switch NonEmptyHotswap to Hotswap2
- Apply suggestions from code review

  Co-authored-by: Arman Bilge <armanbilge@gmail.com>
- Deprecate Hotswap
- Documentation fixes in Hotswap2
- Add Hotswap2.getOpt

  This would allow upgrading from Hotswap without losing the semantics of not acquiring a lock when no resource is present for `Hotswap2[F, Resource[Option[R]]]`
@morgen-peschke morgen-peschke force-pushed the add-nonempty-version-of-hotswap branch from 87b5ce7 to e8f3003 Compare July 12, 2025 18:39
@morgen-peschke
Copy link
Contributor Author

@armanbilge the test failure appears to be unrelated to this change, if everything else looks good, can you retrigger CI? If something needs changed, don't worry about it, since it should clear on the next push 🤞🏻

Copy link
Member

@djspiewak djspiewak left a comment

Choose a reason for hiding this comment

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

Is there a reason we moved away from NonEmptyHotswap as a name? Aesthetically that seems better to me than Hotswap2. We could still deprecate Hotswap even in that world.

@morgen-peschke
Copy link
Contributor Author

Is there a reason we moved away from NonEmptyHotswap as a name? Aesthetically that seems better to me than Hotswap2. We could still deprecate Hotswap even in that world.

This isn't something I have strong opinions about, so you'll have to check in with @armanbilge for the reasons behind it.

Context: originally raised in this comment, I swapped the names because it was requested by the primary reviewer, I couldn't think of a good reason not to do it, and I didn't want to hold up the PR.

@armanbilge
Copy link
Member

@djspiewak

Aesthetically that seems better to me than Hotswap2.

I don't want to hold this up over aesthetic concerns 😁 if NonEmptyHotswap feels better, let's just do that. To be clear, I still feel strongly that the original Hotswap should be deprecated.

The reason I suggested Hotswap2 is because I think this new API should be Hotswap, not just a different flavor of it. The original Hotswap API is broken, and my personal opinion is the "emptiness" of it is also kind of weird. So describing this new API as the non-empty version of this broken, deprecated API did not sit right with me.

@morgen-peschke morgen-peschke requested a review from mzuehlke July 23, 2025 17:38
@djspiewak djspiewak dismissed armanbilge’s stale review July 23, 2025 20:42

I think everything is addressed?

@djspiewak djspiewak merged commit 160c1c6 into typelevel:series/3.x Jul 23, 2025
36 of 38 checks passed
@morgen-peschke morgen-peschke deleted the add-nonempty-version-of-hotswap branch July 23, 2025 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants