• Sebastian Graf's avatar
    Separate `LPat` from `Pat` on the type-level · 182b1199
    Sebastian Graf authored
    Since the Trees That Grow effort started, we had `type LPat = Pat`.
    This is so that `SrcLoc`s would only be annotated in GHC's AST, which is
    the reason why all GHC passes use the extension constructor `XPat` to
    attach source locations. See #15495 for the design discussion behind
    that.
    
    But now suddenly there are `XPat`s everywhere!
    There are several functions which dont't cope with `XPat`s by either
    crashing (`hsPatType`) or simply returning incorrect results
    (`collectEvVarsPat`).
    
    This issue was raised in #17330. I also came up with a rather clean and
    type-safe solution to the problem: We define
    
    ```haskell
    type family XRec p (f :: * -> *) = r | r -> p f
    type instance XRec (GhcPass p) f = Located (f (GhcPass p))
    type instance XRec TH          f =          f p
    type LPat p = XRec p Pat
    ```
    
    This is a rather modular embedding of the old "ping-pong" style, while
    we only pay for the `Located` wrapper within GHC. No ping-ponging in
    a potential Template Haskell AST, for example. Yet, we miss no case
    where we should've handled a `SrcLoc`: `hsPatType` and
    `collectEvVarsPat` are not callable at an `LPat`.
    
    Also, this gets rid of one indirection in `Located` variants:
    Previously, we'd have to go through `XPat` and `Located` to get from
    `LPat` to the wrapped `Pat`. Now it's just `Located` again.
    
    Thus we fix #17330.
    182b1199
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...