While integrating commons's ToExprFactory into alpaca, I hit a hierarchy that the stock scala.deriving.Mirror (and therefore any Mirror-based derivation, made included) refuses to synthesize a sum mirror for:
private[parser] sealed trait ParseAction extends Any
private[parser] object ParseAction:
sealed case class Shift(state: Int) extends AnyVal with ParseAction
sealed case class Reduction(production: Production) extends AnyVal with ParseAction
ParseAction is a "universal trait" (extends Any) so that its case classes can be AnyVals (avoid boxing for what's a hot path in the generated parse table). Trying derives ToExprFactory (which needs Mirror.Of[ParseAction]) fails with:
No given instance of type scala.deriving.Mirror.Of[alpaca.internal.parser.ParseAction] was found
* trait ParseAction is not a generic product because it is not a case class
* trait ParseAction is not a generic sum because its child class Shift is not a generic sum because it is not an abstract class
That second bullet reads like the sealed-sum check is trying to validate each child as if it also needed to be sum-derivable, and an AnyVal case class trips that check somewhere it shouldn't.
Since made's whole point is to go beyond what stock Mirror can express, it'd be great if Made.derived[T] could handle this shape (sealed trait extending Any, AnyVal case class children) even where stock Mirror.SumOf can't. Concretely this would let ParseAction drop its hand-written ToExpr instance once commons's ToExprFactory can build on made instead of stock Mirror.
Reference: alpaca's hand-written instance this would replace — src/alpaca/internal/parser/ParseAction.scala.
While integrating
commons'sToExprFactoryinto alpaca, I hit a hierarchy that the stockscala.deriving.Mirror(and therefore any Mirror-based derivation, made included) refuses to synthesize a sum mirror for:ParseActionis a "universal trait" (extends Any) so that its case classes can beAnyVals (avoid boxing for what's a hot path in the generated parse table). Tryingderives ToExprFactory(which needsMirror.Of[ParseAction]) fails with:That second bullet reads like the sealed-sum check is trying to validate each child as if it also needed to be sum-derivable, and an
AnyValcase class trips that check somewhere it shouldn't.Since made's whole point is to go beyond what stock
Mirrorcan express, it'd be great ifMade.derived[T]could handle this shape (sealed trait extendingAny,AnyValcase class children) even where stockMirror.SumOfcan't. Concretely this would letParseActiondrop its hand-writtenToExprinstance oncecommons'sToExprFactorycan build onmadeinstead of stockMirror.Reference: alpaca's hand-written instance this would replace —
src/alpaca/internal/parser/ParseAction.scala.