Skip to content

Commit

Permalink
fix: rewrite the summonAll method to avoid reaching the inline limit
Browse files Browse the repository at this point in the history
when getting a Diffable instance for a large case class
  • Loading branch information
etorreborre committed Nov 28, 2023
1 parent fbcfdb9 commit f8735e6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ trait DiffableLowImplicits2 extends DiffableLowImplicits3:
inline def summonAll[T <: Tuple]: List[Diffable[?]] =
inline erasedValue[T] match
case _: EmptyTuple => Nil
case _: (t *: ts) => summonInline[Diffable[t]] :: summonAll[ts]
// in the case of a large number of fields we summon the diffables 5 by 5 in order
// to avoid hitting the max inlining limit of 32 by default
case _: (t1 *: t2 *: t3 *: t4 *: t5 *: ts) =>
summonInline[Diffable[t1]] :: summonInline[Diffable[t2]] :: summonInline[Diffable[t3]] :: summonInline[Diffable[
t4
]] :: summonInline[Diffable[t5]] :: summonAll[ts]
case _: (t *: ts) => summonInline[Diffable[t]] :: summonAll[ts]

trait DiffableLowImplicits3:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ Compare result
Failure[String](ex2)
) must ===(TryTypeDifferent(isActualSuccess = true))}

Inlining limit
==============

Taking the diff of a large case class must not reach the inlining limit ${
val largeCase =
LargeClass("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", Nested("", "", "", "", "", ""))

largeCase must beEqualTo(largeCase)
}

"""

Expand Down Expand Up @@ -297,3 +306,37 @@ Compare result
sealed trait Animal
case class Cat() extends Animal
case class Dog() extends Animal

case class LargeClass(
a1: String,
a2: String,
a3: String,
a4: String,
a5: String,
a6: String,
a7: String,
a8: String,
a9: String,
a10: String,
a11: String,
a12: String,
a13: String,
a14: String,
a15: String,
a16: String,
a17: String,
a18: String,
a19: String,
a20: String,
a21: String,
a22: Nested
)

case class Nested(
a23: String,
a24: String,
a25: String,
a26: String,
a27: String,
a28: String
)

0 comments on commit f8735e6

Please sign in to comment.