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 foldMap stack safety #702

Merged
merged 3 commits into from
Dec 1, 2015

Conversation

svalaskevicius
Copy link
Contributor

No description provided.

case Free.Gosub(c, g) => c match {
case Free.Pure(a) => g(M.pure(a)).foldMap(f)
case Free.Suspend(s) => g(f(s)).foldMap(f)
case Free.Gosub(c1, g1) => g(M.flatMap(c1.foldMapRecursiveStep(f))(cc => g1(cc).foldMapRecursiveStep(f))).foldMap(f)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

tbh this line should never happen as its resolved by step - should we simple throw an exception and remove foldMapRecursiveStep function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will remove Free. prefixes

also, looks like the only thing thats not handled by step is Suspend..

@codecov-io
Copy link

Current coverage is 84.91%

Merging #702 into master will increase coverage by +0.13% as of 9ef1e43

@@            master    #702   diff @@
======================================
  Files          162     162       
  Stmts         2228    2227     -1
  Branches        74      74       
  Methods          0       0       
======================================
+ Hit           1889    1891     +2
  Partial          0       0       
+ Missed         339     336     -3

Review entire Coverage Diff as of 9ef1e43

Powered by Codecov. Updated on successful CI builds.

@svalaskevicius
Copy link
Contributor Author

how to run @codecov-io again?

case Gosub(c, g) => M.flatMap(c.foldMap(f))(cc => g(cc).foldMap(f))
case Gosub(c, g) => c match {
case Suspend(s) => g(f(s)).foldMap(f)
case _ => throw new Error("Unexpected operation. The case should have been eliminated by `step`.")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to check where else is step used, could it be moved to this function to avoid the exception throwing or does it add value on its own?

@adelbertc
Copy link
Contributor

👍

@ceedubs
Copy link
Contributor

ceedubs commented Dec 1, 2015

Thanks, @svalaskevicius!

This looks good to me. Does anyone else have any concerns? @mandubian?

@mandubian
Copy link
Contributor

👍 good catch... I wonder why we have missed this before ;)

adelbertc added a commit that referenced this pull request Dec 1, 2015
@adelbertc adelbertc merged commit 925db99 into typelevel:master Dec 1, 2015
@svalaskevicius svalaskevicius deleted the fix-foldmap-for-free branch December 1, 2015 09:52
ceedubs added a commit to ceedubs/cats that referenced this pull request Dec 4, 2015
This reverts most of the changes from typelevel#702, because it appears to have
caused a regression in the case of Gosub.

The stack safety test is now failing. I've commented it out for now,
because an incorrectness bug seems to be worse than a stack safety
issue.
ceedubs added a commit to ceedubs/cats that referenced this pull request Dec 4, 2015
This reverts most of the changes from typelevel#702, because it appears to have
caused a regression in the case of Gosub. This commit fixes the
"mapSuspension id" unit test and the issue reported in typelevel#712.

The stack safety test is now failing. I've commented it out for now,
because an incorrectness bug seems to be worse than a stack safety
issue.
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.

5 participants