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 tailRecM being not stack safe #460

Merged
merged 3 commits into from
Nov 26, 2021
Merged

Fix tailRecM being not stack safe #460

merged 3 commits into from
Nov 26, 2021

Conversation

kjh618
Copy link

@kjh618 kjh618 commented Nov 25, 2021

Fixes #458.

Something to note is that the original implementation passes tailRecMStackSafety in cats (https://github.com/typelevel/cats/blob/e0784fc0d95b9c4eed0bb1ddce6c69e3fd9a4a4f/laws/src/main/scala/cats/laws/MonadLaws.scala#L39), which does not give tailRecM a recursive function.
This PR doesn't change the semantics in that case, but for the cases where tailRecM is given a recursive function like in tailRecMConstructionStackSafety, it prevents stack overflow during construction.

It's tested on v2.5.1.0, so some changes may be necessary to apply this to master.

@CLAassistant
Copy link

CLAassistant commented Nov 25, 2021

CLA assistant check
All committers have signed the CLA.

adamgfraser
adamgfraser previously approved these changes Nov 25, 2021
Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

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

Thank you for your work on this! 🙏

Good to go when conflicts are resolved.

@joroKr21
Copy link
Contributor

Looks like there are a lot of unrelated changes - or you based it off some old branch 🤔

@kjh618 kjh618 changed the base branch from master to ce2 November 26, 2021 07:47
@kjh618 kjh618 dismissed adamgfraser’s stale review November 26, 2021 07:47

The base branch was changed.

@kjh618
Copy link
Author

kjh618 commented Nov 26, 2021

Yeah I started my branch from the tag v2.5.1.0.

I rebased my branch to ce2 and changed the PR base branch to ce2 as well.

Copy link
Contributor

@joroKr21 joroKr21 left a comment

Choose a reason for hiding this comment

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

Nice! This will probably need porting across ZIO / CE versions and also to Managed 😄

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.

ZIO tailRecM is not stack safe
4 participants