summaryrefslogtreecommitdiff
path: root/compiler/GHC/Iface/Ext/Ast.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2021-05-04 08:45:08 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2021-05-06 23:22:19 +0100
commit2aeee2886818fc66cc23a92de2339fc56f5904c3 (patch)
tree3b5dae15c959efc50507b6169b715574862bbbb8 /compiler/GHC/Iface/Ext/Ast.hs
parent30f6923a834ccaca30c3622a0a82421fabcab119 (diff)
downloadhaskell-2aeee2886818fc66cc23a92de2339fc56f5904c3.tar.gz
Allow visible type application for levity-poly data conswip/T18481
This patch was driven by #18481, to allow visible type application for levity-polymorphic newtypes. As so often, it started simple but grew: * Significant refactor: I removed HsConLikeOut from the client-independent Language.Haskell.Syntax.Expr, and put it where it belongs, as a new constructor `ConLikeTc` in the GHC-specific extension data type for expressions, `GHC.Hs.Expr.XXExprGhcTc`. That changed touched a lot of files in a very superficial way. * Note [Typechecking data constructors] explains the main payload. The eta-expansion part is no longer done by the typechecker, but instead deferred to the desugarer, via `ConLikeTc` * A little side benefit is that I was able to restore VTA for data types with a "stupid theta": #19775. Not very important, but the code in GHC.Tc.Gen.Head.tcInferDataCon is is much, much more elegant now. * I had to refactor the levity-polymorphism checking code in GHC.HsToCore.Expr, see Note [Checking for levity-polymorphic functions] Note [Checking levity-polymorphic data constructors]
Diffstat (limited to 'compiler/GHC/Iface/Ext/Ast.hs')
-rw-r--r--compiler/GHC/Iface/Ext/Ast.hs25
1 files changed, 9 insertions, 16 deletions
diff --git a/compiler/GHC/Iface/Ext/Ast.hs b/compiler/GHC/Iface/Ext/Ast.hs
index 5a787f5b94..692e4a2213 100644
--- a/compiler/GHC/Iface/Ext/Ast.hs
+++ b/compiler/GHC/Iface/Ext/Ast.hs
@@ -175,9 +175,6 @@ Here is an extract from the `ToHie` instance for (LHsExpr (GhcPass p)):
[ toHie $ C Use (L mspan var)
-- Patch up var location since typechecker removes it
]
- HsConLikeOut _ con ->
- [ toHie $ C Use $ L mspan $ conLikeName con
- ]
...
HsApp _ a b ->
[ toHie a
@@ -738,7 +735,7 @@ instance HiePass p => HasType (LocatedA (HsExpr (GhcPass p))) where
HsLit _ l -> Just (hsLitType l)
HsOverLit _ o -> Just (overLitType o)
- HsConLikeOut _ (RealDataCon con) -> Just (dataConNonlinearType con)
+ XExpr (ConLikeTc (RealDataCon con) _ _) -> Just (dataConNonlinearType con)
HsLam _ (MG { mg_ext = groupTy }) -> Just (matchGroupType groupTy)
HsLamCase _ (MG { mg_ext = groupTy }) -> Just (matchGroupType groupTy)
@@ -775,7 +772,6 @@ instance HiePass p => HasType (LocatedA (HsExpr (GhcPass p))) where
skipDesugaring :: HsExpr GhcTc -> Bool
skipDesugaring e = case e of
HsVar{} -> False
- HsConLikeOut{} -> False
HsRecFld{} -> False
HsOverLabel{} -> False
HsIPVar{} -> False
@@ -1087,9 +1083,6 @@ instance HiePass p => ToHie (LocatedA (HsExpr (GhcPass p))) where
-- Patch up var location since typechecker removes it
]
HsUnboundVar _ _ -> [] -- there is an unbound name here, but that causes trouble
- HsConLikeOut _ con ->
- [ toHie $ C Use $ L mspan $ conLikeName con
- ]
HsRecFld _ fld ->
[ toHie $ RFC RecFieldOcc Nothing (L (locA mspan) fld)
]
@@ -1216,14 +1209,14 @@ instance HiePass p => ToHie (LocatedA (HsExpr (GhcPass p))) where
HsProjection {} -> []
XExpr x
| GhcTc <- ghcPass @p
- , WrapExpr (HsWrap w a) <- x
- -> [ toHie $ L mspan a
- , toHie (L mspan w)
- ]
- | GhcTc <- ghcPass @p
- , ExpansionExpr (HsExpanded _ b) <- x
- -> [ toHie (L mspan b)
- ]
+ -> case x of
+ WrapExpr (HsWrap w a)
+ -> [ toHie $ L mspan a
+ , toHie (L mspan w) ]
+ ExpansionExpr (HsExpanded _ b)
+ -> [ toHie (L mspan b) ]
+ ConLikeTc con _ _
+ -> [ toHie $ C Use $ L mspan $ conLikeName con ]
| otherwise -> []
-- NOTE: no longer have the location