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

[CE3] Kleisli Stack safety #2095

Closed
ronanM opened this issue Jul 3, 2021 · 7 comments · Fixed by #2101 or #2159
Closed

[CE3] Kleisli Stack safety #2095

ronanM opened this issue Jul 3, 2021 · 7 comments · Fixed by #2101 or #2159
Assignees
Labels

Comments

@ronanM
Copy link

ronanM commented Jul 3, 2021

This code is Ok with CE2, but fail with StackOverflowError in CE3.

import cats.effect.{ExitCode, IO, IOApp}
import cats.syntax.all._
import cats.data.Kleisli

object MainKleisli extends IOApp {

  override def run(args: List[String]): IO[ExitCode] = {
    val N = 10000
    var i = 0

    List.fill(N)(0).traverse_(_ => Kleisli.liftF(IO(i += 1))).run("Go...") *>
      IO(println(s"i: ${i}")) *>
      IO(assert(i === N, s"i: $i != $N")).as(ExitCode.Success)
  }
}
@vasilmkd vasilmkd self-assigned this Jul 5, 2021
@vasilmkd
Copy link
Member

vasilmkd commented Jul 5, 2021

@ronanM Thanks for reporting and for the reproduction. I have a fix incoming.

@catostrophe
Copy link
Contributor

@vasilmkd
this still fails:

  "should be stack safe in long parTraverse chains" in ticked { implicit ticker =>
      val N = 10000

      Ref[IO].of(0).flatMap { ref =>
        List
          .fill(N)(0)
          .parTraverse_(_ => Kleisli.liftF(ref.update(_ + 1)))
          .run("Go...") *> ref.get
      } must completeAs(N)
    }

@catostrophe
Copy link
Contributor

Also typelevel/cats#3947

@vasilmkd
Copy link
Member

Even with Cats Effect 3.2.0?

@catostrophe
Copy link
Contributor

Yes. And it never worked on CE2

@vasilmkd
Copy link
Member

Bummer. I'll take a look.

@vasilmkd vasilmkd reopened this Jul 25, 2021
@vasilmkd
Copy link
Member

I have a fix for parTraverse, I'll open a PR later.

@vasilmkd vasilmkd linked a pull request Jul 29, 2021 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants