Skip to content

Fix/issue 476 stack safety#795

Open
Arolg wants to merge 3 commits into
typelevel:masterfrom
Arolg:fix/issue-476-stack-safety
Open

Fix/issue 476 stack safety#795
Arolg wants to merge 3 commits into
typelevel:masterfrom
Arolg:fix/issue-476-stack-safety

Conversation

@Arolg

@Arolg Arolg commented Jun 16, 2026

Copy link
Copy Markdown

Closes #476.

Fixes the StackOverflowError reported in #476 for derived Functor/Contravariant (and other typeclasses) on recursive ADTs. Default derivation (semiauto.* / Eq.derived / strict) keeps the existing fast direct-recursion path, so existing users see no behavior or performance change. A new opt-in entry point cats.derived.stackSafe.* provides Eval-trampolined variants for the 12 K0/K1 typeclasses; one import on the user side is enough to switch. Bifunctor/Bifoldable/Bitraverse keep fast direct recursion only (the two-given-set design doesn't fit the current K2-coproduct resolver in shapeless3 — happy to discuss a follow-up). All 12 081 existing tests pass; StackSafetySuite now covers all 12 K0/K1 instances via the opt-in entry point.

ismat added 3 commits April 24, 2026 00:54
…-safe variants

Default derivation (semiauto / *.derived / strict) again uses direct
recursion, removing the ~5-9x performance regression introduced when the
derivations were trampolined through Eval.

Stack-safe (Eval-trampolined) derivation is now opt-in via
cats.derived.stackSafe.* for Eq, Hash, Order, PartialOrder, Show, Functor,
Contravariant, Invariant, Foldable, Reducible, Traverse and NonEmptyTraverse.

Bifunctor, Bifoldable and Bitraverse are reverted to fast direct recursion
(no Eval variant).

Stack-safety tests updated to use the opt-in stackSafe entry points.
@mergify mergify Bot added the core label Jun 16, 2026
@joroKr21

Copy link
Copy Markdown
Member

The code needs to be formatted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Scala 3] derived instances are not stack-safe

2 participants