Fix/issue 476 stack safety#795
Open
Arolg wants to merge 3 commits into
Open
Conversation
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.
Member
|
The code needs to be formatted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.