cats-effect-cps icon indicating copy to clipboard operation
cats-effect-cps copied to clipboard

Updated to Cats Effect 3.7, Scala Native 0.5, and dotty-cps-async 1.0…

Open djspiewak opened this issue 4 months ago • 3 comments

Also changed the name to cats-effect-direct. When we release I'll update the repo and the readme.

djspiewak avatar Aug 05 '25 14:08 djspiewak

Okay this is super fun. I'm observing the following two issues. First, on Java 8 (and only Java 8), the Scala Native ++2.13 test seems to produce the following:

  | => cat StackTrace_PrintStackTrace
  at stackOverflowHandler
  at _sigtramp
  at _SM46cats.effect.cpsinternal.AsyncAwaitStateMachineD6tryGetL17scala.util.EitherL16java.lang.ObjectEO
  at _SM48cats.effect.AsyncAwaitSuite$stateMachine$async$1D5applyL17scala.util.EitheruEO
  at _SM48cats.effect.AsyncAwaitSuite$stateMachine$async$1D5applyL16java.lang.ObjectL16java.lang.ObjectEO
  at _SM46cats.effect.cpsinternal.AsyncAwaitStateMachineD21$anonfun$onComplete$8L16java.lang.ObjectL16java.lang.ObjectuEPT46cats.effect.cpsinternal.AsyncAwaitStateMachine
  at _SM56cats.effect.cpsinternal.AsyncAwaitStateMachine$$Lambda$8D5applyL16java.lang.ObjectEO
  at _SM19cats.effect.IOFiberD7runLoopL14cats.effect.IOiiuEPT19cats.effect.IOFiber
  at _SM19cats.effect.IOFiberD24asyncContinueSuccessfulRuEPT19cats.effect.IOFiber
  at _SM19cats.effect.IOFiberD3runuEO
  at _SM31cats.effect.unsafe.WorkerThreadD3runuEO
  at _SM39scala.scalanative.runtime.NativeThread$D16threadEntryPointL38scala.scalanative.runtime.NativeThreaduEPT39scala.scalanative.runtime.NativeThread$
  at _SM39scala.scalanative.runtime.NativeThread$D24$anonfun$threadRoutine$1L28scala.scalanative.unsafe.PtrL28scala.scalanative.unsafe.PtrEPT39scala.scalanative.runtime.NativeThread$
  at _SM49scala.scalanative.runtime.NativeThread$$$Lambda$1G17$extern$forwarder
  at ProxyThreadStartRoutine
  at _pthread_start

I haven't been able to reproduce this on more recent versions of the JVM, so that's a fun one.

The second issue I'm hitting (also on 2.13) seems to be not JVM specific (thankfully…) and it results in the following test error:

==> X cats.effect.AsyncAwaitSuite.async[OptionT[IO, *]] - work on successes 0.210s scala.MatchError: Ptr@70001135d8 (of class scala.scalanative.unsafe.Ptr)

This appears to be nondeterministic.

It's worth noting that we don't have any SN specific stuff here, so something very odd is going on.

djspiewak avatar Aug 05 '25 15:08 djspiewak

Something is very wrong here: Trying this branch locally (2.13, x86_64 linux, JVM 17) I get a segfault in cats.effect.AsyncAwaitSuite. If I comment out there every test except the first one (async[IO] - work on success), then it fails with a scala.MatchError: class scala.util.Right (of class java.lang.Class), i.e., it gets essentially a classOf[Right[_]] (that is, a java.lang.Class instance, and not a scala.util.Right instance). (It's this match: https://github.com/djspiewak/cats-effect-cps/blob/c79c36fa75d53218a2880be7d16761698fc12fb9/core/shared/src/main/scala-2/cats/effect/cpsinternal/AsyncAwaitStateMachine.scala#L89.) The static type of that argument is Either[F[AnyRef], (F[Unit], AnyRef)], so this should be impossible.

durban avatar Aug 10 '25 21:08 durban

I think it's fair to say this is surfacing a bug in Scala Native.

djspiewak avatar Aug 10 '25 22:08 djspiewak