Separate `LPat` from `Pat` on the type-level
Since the Trees That Grow effort started, we had type LPat = Pat.
This is so that SrcLocs 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 XPats everywhere!
There are several functions which dont't cope with XPats by either
crashing (hsPatType) or simply returning incorrect results
(collectEvVarsPat).
This issue was raised in #17330 (closed). I also came up with a rather clean and mostly type-safe solution to the problem: We define
data Loc p
type LPat p = Pat (Loc p)
And simply only allow XPat to occur when there's a Loc wrapping the
pass. At the same time, we can disallow any other constructors to occur
in an LPat by setting the constructor field extension to NoExtCon
for all but XPat. We do the same for the plain GHC passes and XPat.
ow we have a rather modular embedding of the old "ping-pong" style inside of a TTG-ified AST. TH doesn't pay in performance, while we retain type safety for GHC passes.
Thus we fix #17330 (closed).