diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2021-04-23 19:48:03 -0400 |
---|---|---|
committer | Zubin Duggal <zubin.duggal@gmail.com> | 2021-06-08 01:07:10 +0530 |
commit | 7ea3b7eb37ac87917ab490c835e8405646891be3 (patch) | |
tree | b2720484d7da45cb97ee3efe6a0bcfec412be0d0 /compiler/GHC/Hs/Expr.hs | |
parent | 9e724f6e5bcb31abd270ea44fb01b1edb18f626f (diff) | |
download | haskell-7ea3b7eb37ac87917ab490c835e8405646891be3.tar.gz |
Introduce `hsExprType :: HsExpr GhcTc -> Type` in the new modulewip/hsExprType
`GHC.Hs.Syn.Type`
The existing `hsPatType`, `hsLPatType` and `hsLitType` functions have also been
moved to this module
This is a less ambitious take on the same problem that !2182 and !3866
attempt to solve. Rather than have the `hsExprType` function attempt to
efficiently compute the `Type` of every subexpression in an `HsExpr`, this
simply computes the overall `Type` of a single `HsExpr`.
- Explicitly forbids the `SplicePat` `HsIPVar`, `HsBracket`, `HsRnBracketOut`
and `HsTcBracketOut` constructors during the typechecking phase by using
`Void` as the TTG extension field
- Also introduces `dataConCantHappen` as a domain specific alternative to `absurd`
to handle cases where the TTG extension points forbid a constructor.
- Turns HIE file generation into a pure function that doesn't need access to the
`DsM` monad to compute types, but uses `hsExprType` instead.
- Computes a few more types during HIE file generation
- Makes GHCi's `:set +c` command also use `hsExprType` instead of going through
the desugarer to compute types.
Updates haddock submodule
Co-authored-by: Zubin Duggal <zubin.duggal@gmail.com>
Diffstat (limited to 'compiler/GHC/Hs/Expr.hs')
-rw-r--r-- | compiler/GHC/Hs/Expr.hs | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/compiler/GHC/Hs/Expr.hs b/compiler/GHC/Hs/Expr.hs index 006c8a2e8e..72ac021e45 100644 --- a/compiler/GHC/Hs/Expr.hs +++ b/compiler/GHC/Hs/Expr.hs @@ -196,13 +196,25 @@ type instance PendingTcSplice' (GhcPass _) = PendingTcSplice {- Note [Constructor cannot occur] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Some data constructors can't occur in certain phases; e.g. the output -of the type checker never has OverLabel. We signal this by setting -the extension field to Void. For example: +of the type checker never has OverLabel. We signal this by +* setting the extension field to Void +* using dataConCantHappen in the cases that can't happen + +For example: + type instance XOverLabel GhcTc = Void - dsExpr (HsOverLabel x _) = absurd x + + dsExpr :: HsExpr GhcTc -> blah + dsExpr (HsOverLabel x _) = dataConCantHappen x + +The function dataConCantHappen is defined thus: + dataConCantHappen :: Void -> a + dataConCantHappen x = case x of {} +(i.e. identically to Data.Void.absurd, but more helpfully named). +Remember Void is a type whose only element is bottom. It would be better to omit the pattern match altogether, but we -could only do that if the extension field was strict (#18764) +could only do that if the extension field was strict (#18764). -} -- API Annotations types @@ -246,7 +258,9 @@ type instance XUnboundVar GhcTc = HoleExprRef -- Much, much easier just to define HoleExprRef with a Data instance and -- store the whole structure. -type instance XIPVar (GhcPass _) = EpAnnCO +type instance XIPVar GhcPs = EpAnnCO +type instance XIPVar GhcRn = EpAnnCO +type instance XIPVar GhcTc = Void -- See Note [Constructor cannot occur] type instance XOverLitE (GhcPass _) = EpAnnCO type instance XLitE (GhcPass _) = EpAnnCO @@ -348,10 +362,17 @@ type instance XArithSeq GhcPs = EpAnn [AddEpAnn] type instance XArithSeq GhcRn = NoExtField type instance XArithSeq GhcTc = PostTcExpr -type instance XBracket (GhcPass _) = EpAnn [AddEpAnn] +type instance XBracket GhcPs = EpAnn [AddEpAnn] +type instance XBracket GhcRn = EpAnn [AddEpAnn] +type instance XBracket GhcTc = Void -- See Note [Constructor cannot occur] + +type instance XRnBracketOut GhcPs = Void -- See Note [Constructor cannot occur] +type instance XRnBracketOut GhcRn = NoExtField +type instance XRnBracketOut GhcTc = Void -- See Note [Constructor cannot occur] -type instance XRnBracketOut (GhcPass _) = NoExtField -type instance XTcBracketOut (GhcPass _) = NoExtField +type instance XTcBracketOut GhcPs = Void -- See Note [Constructor cannot occur] +type instance XTcBracketOut GhcRn = Void -- See Note [Constructor cannot occur] +type instance XTcBracketOut GhcTc = Type -- Type of the TcBracketOut type instance XSpliceE (GhcPass _) = EpAnnCO type instance XProc (GhcPass _) = EpAnn [AddEpAnn] |