Skip to content

Instantly share code, notes, and snippets.

@marcinzh
Created June 16, 2025 22:09
Show Gist options
  • Save marcinzh/c0c24fac96b3571a0313bac3f7f48a59 to your computer and use it in GitHub Desktop.
Save marcinzh/c0c24fac96b3571a0313bac3f7f48a59 to your computer and use it in GitHub Desktop.
Possible performance regression in 3.7.0 due to `betterFors` not being applied
//> using scala "3.6.4"
//> using dep "io.github.marcinzh::turbolift-core:0.114.0"
//> using options "-language:experimental.betterFors", "-Vprint:typer"
// The code is the same in both files, only scala-cli options differ
import turbolift.!!
import turbolift.effects.{Reader, Writer, State, Error}
case object MyError extends Error[String]
case object MyReader extends Reader[Int]
case object MyWriter extends Writer[Long]
case object MyState extends State[Int]
type MyError = MyError.type
type MyReader = MyReader.type
type MyWriter = MyWriter.type
type MyState = MyState.type
def program: Int !! (MyError & MyReader & MyWriter & MyState) =
MyState.getsEff: s =>
for
_ <- MyState.put(s + 1)
_ <- MyWriter.tell(s)
x <- MyReader.asksEff: r =>
if s < r
then program
else !!.pure(s)
yield x
@main def main =
println:
program
.handleWith(MyState.handler(0))
.handleWith(MyWriter.handler)
.handleWith(MyReader.handler(100))
.handleWith(MyError.handler)
.run
// OUTPUT FRAGMENT: no trailing `.map(x => x)`
/*
def program: turbolift.!![Int, MyError & MyReader & MyWriter & MyState] =
MyState.getsEff[Int,
MyReader.type & MyError.type & (MyWriter.type & MyState.type)]((s: Int)
=>
MyState.put(s.+(1)).flatMap[Int,
MyReader.type & MyError.type & (MyWriter.type & MyState.type)]((
x$1: Unit) =>
x$1:Unit @unchecked match
{
case _ =>
MyWriter.tell(Int.int2long(s)).flatMap[Int,
MyReader.type & MyError.type & (MyWriter.type & MyState.type)]
((x$1: Unit) =>
x$1:Unit @unchecked match
{
case _ =>
MyReader.asksEff[Int,
MyReader.type & MyError.type & (MyWriter.type &
MyState.type)
]((r: Int) =>
if s.<(r) then program else turbolift.!!.pure[Int](s))
}
)
}
)
*/
//> using scala "3.7.1-RC1"
//> using dep "io.github.marcinzh::turbolift-core:0.114.0"
//> using options "-preview", "-Vprint:typer"
// The code is the same in both files, only scala-cli options differ
import turbolift.!!
import turbolift.effects.{Reader, Writer, State, Error}
case object MyError extends Error[String]
case object MyReader extends Reader[Int]
case object MyWriter extends Writer[Long]
case object MyState extends State[Int]
type MyError = MyError.type
type MyReader = MyReader.type
type MyWriter = MyWriter.type
type MyState = MyState.type
def program: Int !! (MyError & MyReader & MyWriter & MyState) =
MyState.getsEff: s =>
for
_ <- MyState.put(s + 1)
_ <- MyWriter.tell(s)
x <- MyReader.asksEff: r =>
if s < r
then program
else !!.pure(s)
yield x
@main def main =
println:
program
.handleWith(MyState.handler(0))
.handleWith(MyWriter.handler)
.handleWith(MyReader.handler(100))
.handleWith(MyError.handler)
.run
// OUTPUT FRAGMENT: trailing `.map(x => x)` attached in the `else` branch
/*
def program: turbolift.!![Int, MyError & MyReader & MyWriter & MyState] =
MyState.getsEff[Int,
MyReader.type & MyError.type & (MyWriter.type & MyState.type)]((s: Int)
=>
MyState.put(s + 1).flatMap[Int,
MyReader.type & MyError.type & (MyWriter.type & MyState.type)]((
x$1: Unit) =>
x$1:Unit @unchecked match
{
case _ =>
MyWriter.tell(Int.int2long(s)).flatMap[Int,
MyWriter.type & MyReader.type & (MyError.type & MyState.type)]
((x$1: Unit) =>
x$1:Unit @unchecked match
{
case _ =>
MyReader.asksEff[Int,
MyReader.type & MyError.type & (MyWriter.type &
MyState.type)
]((r: Int) =>
if s < r then program else turbolift.!!.pure[Int](s)).
map[Int]((x: Int) => x)
}
)
}
)
)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment