• Ryan Scott's avatar
    Refactor TcDeriv to validity-check less in anyclass/via deriving (#13154) · cd9b9459
    Ryan Scott authored
    Due to the way `DerivEnv` is currently structured, there is an
    invariant that every derived instance must consist of a class applied
    to a non-empty list of argument types, where the last argument *must*
    be an application of a type constructor to some arguments. This works
    for many cases, but there are also some design patterns in standalone
    `anyclass`/`via` deriving that are made impossible due to enforcing
    this invariant, as documented in #13154.
    
    This fixes #13154 by refactoring `TcDeriv` and friends to perform
    fewer validity checks when using the `anyclass` or `via` strategies.
    The highlights are as followed:
    
    * Five fields of `DerivEnv` have been factored out into a new
      `DerivInstTys` data type. These fields only make sense for
      instances that satisfy the invariant mentioned above, so
      `DerivInstTys` is now only used in `stock` and `newtype` deriving,
      but not in other deriving strategies.
    * There is now a `Note [DerivEnv and DerivSpecMechanism]` describing
      the bullet point above in more detail, as well as explaining the
      exact requirements that each deriving strategy imposes.
    * I've refactored `mkEqnHelp`'s call graph to be slightly less
      complicated. Instead of the previous `mkDataTypeEqn`/`mkNewTypeEqn`
      dichotomy, there is now a single entrypoint `mk_eqn`.
    * Various bits of code were tweaked so as not to use fields that are
      specific to `DerivInstTys` so that they may be used by all deriving
      strategies, since not all deriving strategies use `DerivInstTys`.
    cd9b9459
Name
Last commit
Last update
..
ClsInst.hs Loading commit data...
Constraint.hs Loading commit data...
FamInst.hs Loading commit data...
Flattening-notes Loading commit data...
FunDeps.hs Loading commit data...
Inst.hs Loading commit data...
TcAnnotations.hs Loading commit data...
TcArrows.hs Loading commit data...
TcBackpack.hs Loading commit data...
TcBinds.hs Loading commit data...
TcCanonical.hs Loading commit data...
TcClassDcl.hs Loading commit data...
TcDefaults.hs Loading commit data...
TcDeriv.hs Loading commit data...
TcDerivInfer.hs Loading commit data...
TcDerivUtils.hs Loading commit data...
TcEnv.hs Loading commit data...
TcEnv.hs-boot Loading commit data...
TcErrors.hs Loading commit data...
TcEvTerm.hs Loading commit data...
TcEvidence.hs Loading commit data...
TcExpr.hs Loading commit data...
TcExpr.hs-boot Loading commit data...
TcFlatten.hs Loading commit data...
TcForeign.hs Loading commit data...
TcGenDeriv.hs Loading commit data...
TcGenFunctor.hs Loading commit data...
TcGenGenerics.hs Loading commit data...
TcHoleErrors.hs Loading commit data...
TcHoleErrors.hs-boot Loading commit data...
TcHoleFitTypes.hs Loading commit data...
TcHoleFitTypes.hs-boot Loading commit data...
TcHsSyn.hs Loading commit data...
TcHsType.hs Loading commit data...
TcInstDcls.hs Loading commit data...
TcInstDcls.hs-boot Loading commit data...
TcInteract.hs Loading commit data...
TcMType.hs Loading commit data...
TcMatches.hs Loading commit data...
TcMatches.hs-boot Loading commit data...
TcOrigin.hs Loading commit data...
TcPat.hs Loading commit data...
TcPatSyn.hs Loading commit data...
TcPatSyn.hs-boot Loading commit data...
TcPluginM.hs Loading commit data...
TcRnDriver.hs Loading commit data...
TcRnDriver.hs-boot Loading commit data...
TcRnExports.hs Loading commit data...
TcRnMonad.hs Loading commit data...
TcRnTypes.hs Loading commit data...
TcRnTypes.hs-boot Loading commit data...
TcRules.hs Loading commit data...
TcSMonad.hs Loading commit data...
TcSigs.hs Loading commit data...
TcSimplify.hs Loading commit data...
TcSplice.hs Loading commit data...
TcSplice.hs-boot Loading commit data...
TcTyClsDecls.hs Loading commit data...
TcTyDecls.hs Loading commit data...
TcType.hs Loading commit data...
TcType.hs-boot Loading commit data...
TcTypeNats.hs Loading commit data...
TcTypeable.hs Loading commit data...
TcUnify.hs Loading commit data...
TcUnify.hs-boot Loading commit data...
TcValidity.hs Loading commit data...