summaryrefslogtreecommitdiff
path: root/compiler/GHC/Tc/Utils
diff options
context:
space:
mode:
authorCarrieMY <carrie.xmy@gmail.com>2022-05-25 16:43:03 +0200
committersheaf <sam.derbyshire@gmail.com>2022-05-25 16:43:03 +0200
commite74fc066cb33e5b7ae0d37cedb30230c597ef1ce (patch)
treecc17cbbe235ada53bdac93e06cbfe4ca632ffa4a /compiler/GHC/Tc/Utils
parent2ff18e390b119c611b3dd429b76cfcbf36ef9545 (diff)
downloadhaskell-wip/T18802.tar.gz
Desugar RecordUpd in `tcExpr`wip/T18802
This patch typechecks record updates by desugaring them inside the typechecker using the HsExpansion mechanism, and then typechecking this desugared result. Example: data T p q = T1 { x :: Int, y :: Bool, z :: Char } | T2 { v :: Char } | T3 { x :: Int } | T4 { p :: Float, y :: Bool, x :: Int } | T5 The record update `e { x=e1, y=e2 }` desugars as follows e { x=e1, y=e2 } ===> let { x' = e1; y' = e2 } in case e of T1 _ _ z -> T1 x' y' z T4 p _ _ -> T4 p y' x' The desugared expression is put into an HsExpansion, and we typecheck that. The full details are given in Note [Record Updates] in GHC.Tc.Gen.Expr. Fixes #2595 #3632 #10808 #10856 #16501 #18311 #18802 #21158 #21289 Updates haddock submodule
Diffstat (limited to 'compiler/GHC/Tc/Utils')
-rw-r--r--compiler/GHC/Tc/Utils/Zonk.hs36
1 files changed, 0 insertions, 36 deletions
diff --git a/compiler/GHC/Tc/Utils/Zonk.hs b/compiler/GHC/Tc/Utils/Zonk.hs
index eee43e8ed1..6fa47f8b64 100644
--- a/compiler/GHC/Tc/Utils/Zonk.hs
+++ b/compiler/GHC/Tc/Utils/Zonk.hs
@@ -857,32 +857,6 @@ zonkExpr env expr@(RecordCon { rcon_ext = con_expr, rcon_flds = rbinds })
; return (expr { rcon_ext = new_con_expr
, rcon_flds = new_rbinds }) }
--- Record updates via dot syntax are replaced by desugared expressions
--- in the renamer. See Note [Rebindable syntax and HsExpansion]. This
--- is why we match on 'rupd_flds = Left rbinds' here and panic otherwise.
-zonkExpr env (RecordUpd { rupd_flds = Left rbinds
- , rupd_expr = expr
- , rupd_ext = RecordUpdTc {
- rupd_cons = cons
- , rupd_in_tys = in_tys
- , rupd_out_tys = out_tys
- , rupd_wrap = req_wrap }})
- = do { new_expr <- zonkLExpr env expr
- ; new_in_tys <- mapM (zonkTcTypeToTypeX env) in_tys
- ; new_out_tys <- mapM (zonkTcTypeToTypeX env) out_tys
- ; new_rbinds <- zonkRecUpdFields env rbinds
- ; (_, new_recwrap) <- zonkCoFn env req_wrap
- ; return (
- RecordUpd {
- rupd_expr = new_expr
- , rupd_flds = Left new_rbinds
- , rupd_ext = RecordUpdTc {
- rupd_cons = cons
- , rupd_in_tys = new_in_tys
- , rupd_out_tys = new_out_tys
- , rupd_wrap = new_recwrap }}) }
-zonkExpr _ (RecordUpd {}) = panic "GHC.Tc.Utils.Zonk: zonkExpr: The impossible happened!"
-
zonkExpr env (ExprWithTySig _ e ty)
= do { e' <- zonkLExpr env e
; return (ExprWithTySig noExtField e' ty) }
@@ -1309,16 +1283,6 @@ zonkRecFields env (HsRecFields flds dd)
; return (L l (fld { hfbLHS = new_id
, hfbRHS = new_expr })) }
-zonkRecUpdFields :: ZonkEnv -> [LHsRecUpdField GhcTc]
- -> TcM [LHsRecUpdField GhcTc]
-zonkRecUpdFields env = mapM zonk_rbind
- where
- zonk_rbind (L l fld)
- = do { new_id <- wrapLocMA (zonkFieldOcc env) (hsRecUpdFieldOcc fld)
- ; new_expr <- zonkLExpr env (hfbRHS fld)
- ; return (L l (fld { hfbLHS = fmap ambiguousFieldOcc new_id
- , hfbRHS = new_expr })) }
-
{-
************************************************************************
* *