Skip to content

Commit 85e418b

Browse files
committed
Add inline for AdhocSyntaxWired.apply
Combine with moving Inner class out of AdhocSyntaxWired, we completely remove AdhocSyntaxWired footprint from generated bytecode (user's site)
1 parent 74dda73 commit 85e418b

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

core/src/main/scala-3/cats/mtl/HandleCrossCompat.scala

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,27 @@ package mtl
2020
private[mtl] trait HandleCrossCompat { this: Handle.type =>
2121
import Handle.Submarine
2222

23-
def allow[E]: AdHocSyntaxWired[E] =
24-
new AdHocSyntaxWired[E]
23+
inline def allow[E]: AdHocSyntaxWired[E] =
24+
new AdHocSyntaxWired[E]()
2525

26-
final class AdHocSyntaxWired[E]:
26+
private[mtl] final class AdHocSyntaxWired[E]:
27+
inline def apply[F[_], A](inline body: Handle[F, E] ?=> F[A]): InnerWired[F, E, A] =
28+
new InnerWired(body)
2729

28-
def apply[F[_], A](body: Handle[F, E] ?=> F[A])(using ApplicativeThrow[F]): Inner[F, A] =
29-
new Inner(body)
30+
private[mtl] final class InnerWired[F[_], E, A](body: Handle[F, E] ?=> F[A]):
31+
def rescue(h: E => F[A]): ApplicativeThrow[F] ?=> F[A] =
32+
val Marker = new AnyRef
3033

31-
final class Inner[F[_], A](body: Handle[F, E] ?=> F[A])(using ApplicativeThrow[F]):
32-
def rescue(h: E => F[A]): F[A] =
33-
val Marker = new AnyRef
34+
def inner[B](fb: F[B])(f: E => F[B]): F[B] =
35+
ApplicativeThrow[F].handleErrorWith(fb):
36+
case Submarine(e, Marker) => f(e.asInstanceOf[E])
37+
case t => ApplicativeThrow[F].raiseError(t)
3438

35-
def inner[B](fb: F[B])(f: E => F[B]): F[B] =
36-
ApplicativeThrow[F].handleErrorWith(fb):
37-
case Submarine(e, Marker) => f(e.asInstanceOf[E])
38-
case t => ApplicativeThrow[F].raiseError(t)
39+
given Handle[F, E] with
40+
def applicative = Applicative[F]
41+
def raise[E2 <: E, B](e: E2): F[B] =
42+
ApplicativeThrow[F].raiseError(Submarine(e, Marker))
43+
def handleWith[B](fb: F[B])(f: E => F[B]): F[B] = inner(fb)(f)
3944

40-
given Handle[F, E] with
41-
def applicative = Applicative[F]
42-
def raise[E2 <: E, B](e: E2): F[B] =
43-
ApplicativeThrow[F].raiseError(Submarine(e, Marker))
44-
def handleWith[B](fb: F[B])(f: E => F[B]): F[B] = inner(fb)(f)
45-
46-
inner(body)(h)
45+
inner(body)(h)
4746
}

0 commit comments

Comments
 (0)