Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC
Commits:
-
45a1bed0
by Apoorv Ingle at 2026-03-18T00:58:42-05:00
17 changed files:
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/Syn/Type.hs
- compiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/HsToCore/Ticks.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Rename/Utils.hs
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Do.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Head.hs
- compiler/GHC/Tc/Gen/Match.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Tc/Utils/Unify.hs
- compiler/GHC/Tc/Zonk/Type.hs
- testsuite/tests/ghci/prog-mhu001/prog-mhu001c.stdout
Changes:
| ... | ... | @@ -661,43 +661,23 @@ type instance XXExpr GhcTc = XXExprGhcTc |
| 661 | 661 | ********************************************************************* -}
|
| 662 | 662 | |
| 663 | 663 | data XXExprGhcRn
|
| 664 | - = ExpandedThingRn { xrn_orig :: HsCtxt -- The original source thing context to be used for error messages
|
|
| 665 | - , xrn_expanded :: HsExpr GhcRn -- The compiler generated, expanded thing
|
|
| 666 | - }
|
|
| 664 | + = ExpandedThingRn { xrn_orig :: HsCtxt -- The original source thing context to be used for error messages
|
|
| 665 | + , xrn_expanded :: LHsExpr GhcRn } -- The compiler generated, expanded thing
|
|
| 666 | + -- This is located because of do statements (TODO ANI : Add Note)
|
|
| 667 | 667 | |
| 668 | 668 | | HsRecSelRn (FieldOcc GhcRn) -- ^ Variable pointing to record selector
|
| 669 | 669 | -- See Note [Non-overloaded record field selectors] and
|
| 670 | 670 | -- Note [Record selectors in the AST]
|
| 671 | 671 | |
| 672 | --- | Build an expression using the extension constructor `XExpr`,
|
|
| 673 | --- and the two components of the expansion: original expression and
|
|
| 674 | --- expanded expressions.
|
|
| 675 | -mkExpandedExpr
|
|
| 676 | - :: HsExpr GhcRn -- ^ source expression context
|
|
| 677 | - -> HsExpr GhcRn -- ^ expanded expression
|
|
| 678 | - -> HsExpr GhcRn -- ^ suitably wrapped 'XXExprGhcRn'
|
|
| 679 | -mkExpandedExpr oExpr eExpr = XExpr (ExpandedThingRn { xrn_orig = ExprCtxt oExpr
|
|
| 680 | - , xrn_expanded = eExpr })
|
|
| 681 | - |
|
| 682 | --- | Build an expression using the extension constructor `XExpr`,
|
|
| 683 | --- and the two components of the expansion: original do stmt and
|
|
| 684 | --- expanded expression
|
|
| 685 | -mkExpandedStmt
|
|
| 686 | - :: ExprLStmt GhcRn -- ^ source statement context
|
|
| 687 | - -> HsDoFlavour -- ^ source statements do flavour
|
|
| 688 | - -> HsExpr GhcRn -- ^ expanded expression
|
|
| 689 | - -> HsExpr GhcRn -- ^ suitably wrapped 'XXExprGhcRn'
|
|
| 690 | -mkExpandedStmt oStmt flav eExpr = XExpr (ExpandedThingRn { xrn_orig = StmtErrCtxt (HsDoStmt flav) oStmt
|
|
| 691 | - , xrn_expanded = eExpr })
|
|
| 692 | - |
|
| 693 | 672 | data XXExprGhcTc
|
| 694 | 673 | = WrapExpr -- Type and evidence application and abstractions
|
| 695 | 674 | HsWrapper (HsExpr GhcTc)
|
| 696 | 675 | |
| 697 | 676 | | ExpandedThingTc -- See Note [Rebindable syntax and XXExprGhcRn]
|
| 698 | 677 | -- See Note [Expanding HsDo with XXExprGhcRn] in `GHC.Tc.Gen.Do`
|
| 699 | - { xtc_orig :: HsCtxt -- The original user written thing
|
|
| 700 | - , xtc_expanded :: HsExpr GhcTc } -- The expanded typechecked expression
|
|
| 678 | + { xtc_orig :: HsCtxt -- The original user written thing
|
|
| 679 | + , xtc_expanded :: LHsExpr GhcTc } -- The expanded typechecked expression
|
|
| 680 | + -- This is located because of do statements (TODO ANI: Add NOTE)
|
|
| 701 | 681 | |
| 702 | 682 | | ConLikeTc
|
| 703 | 683 | -- ^ A 'ConLike', either a data constructor or pattern synonym
|
| ... | ... | @@ -722,22 +702,6 @@ data XXExprGhcTc |
| 722 | 702 | -- See Note [Non-overloaded record field selectors] and
|
| 723 | 703 | -- Note [Record selectors in the AST]
|
| 724 | 704 | |
| 725 | - |
|
| 726 | --- | Build a 'XXExprGhcRn' out of an extension constructor,
|
|
| 727 | --- and the two components of the expansion: original and
|
|
| 728 | --- expanded typechecked expressions.
|
|
| 729 | -mkExpandedExprTc
|
|
| 730 | - :: HsExpr GhcRn -- ^ source expression
|
|
| 731 | - -> HsExpr GhcTc -- ^ expanded typechecked expression
|
|
| 732 | - -> HsExpr GhcTc -- ^ suitably wrapped 'XXExprGhcRn'
|
|
| 733 | -mkExpandedExprTc oExpr eExpr = mkExpandedTc (ExprCtxt oExpr) eExpr
|
|
| 734 | - |
|
| 735 | -mkExpandedTc
|
|
| 736 | - :: HsCtxt -- ^ source, user written do statement/expression
|
|
| 737 | - -> HsExpr GhcTc -- ^ expanded typechecked expression
|
|
| 738 | - -> HsExpr GhcTc -- ^ suitably wrapped 'XXExprGhcRn'
|
|
| 739 | -mkExpandedTc o e = XExpr (ExpandedThingTc o e)
|
|
| 740 | - |
|
| 741 | 705 | {- *********************************************************************
|
| 742 | 706 | * *
|
| 743 | 707 | Pretty-printing expressions
|
| ... | ... | @@ -153,7 +153,7 @@ hsExprType (HsQual x _ _) = dataConCantHappen x |
| 153 | 153 | hsExprType (HsForAll x _ _) = dataConCantHappen x
|
| 154 | 154 | hsExprType (HsFunArr x _ _ _) = dataConCantHappen x
|
| 155 | 155 | hsExprType (XExpr (WrapExpr wrap e)) = hsWrapperType wrap $ hsExprType e
|
| 156 | -hsExprType (XExpr (ExpandedThingTc _ e)) = hsExprType e
|
|
| 156 | +hsExprType (XExpr (ExpandedThingTc _ e)) = lhsExprType e
|
|
| 157 | 157 | hsExprType (XExpr (ConLikeTc con)) = conLikeType con
|
| 158 | 158 | hsExprType (XExpr (HsTick _ e)) = lhsExprType e
|
| 159 | 159 | hsExprType (XExpr (HsBinTick _ _ e)) = lhsExprType e
|
| ... | ... | @@ -41,7 +41,6 @@ import GHC.Hs |
| 41 | 41 | -- needs to see source types
|
| 42 | 42 | import GHC.Tc.Utils.TcType
|
| 43 | 43 | import GHC.Tc.Types.Evidence
|
| 44 | -import GHC.Tc.Types.ErrCtxt
|
|
| 45 | 44 | import GHC.Tc.Utils.Monad
|
| 46 | 45 | import GHC.Tc.Instance.Class (lookupHasFieldLabel)
|
| 47 | 46 | |
| ... | ... | @@ -308,10 +307,7 @@ dsExpr e@(XExpr ext_expr_tc) |
| 308 | 307 | WrapExpr {} -> dsApp e
|
| 309 | 308 | ConLikeTc {} -> dsApp e
|
| 310 | 309 | |
| 311 | - ExpandedThingTc o e
|
|
| 312 | - | StmtErrCtxt _ (L loc _) <- o -- c.f. T14546d. We have lost the location of the first statement in the GhcRn -> GhcTc
|
|
| 313 | - -> putSrcSpanDsA loc $ dsExpr e
|
|
| 314 | - | otherwise -> dsExpr e
|
|
| 310 | + ExpandedThingTc _ e -> dsLExpr e
|
|
| 315 | 311 | |
| 316 | 312 | -- Hpc Support
|
| 317 | 313 | HsTick tickish e -> do
|
| ... | ... | @@ -1167,7 +1167,7 @@ viewLExprEq (e1,_) (e2,_) = lexp e1 e2 |
| 1167 | 1167 | exp (XExpr (WrapExpr h e)) (XExpr (WrapExpr h' e')) =
|
| 1168 | 1168 | wrap h h' && exp e e'
|
| 1169 | 1169 | exp (XExpr (ExpandedThingTc _ x)) (XExpr (ExpandedThingTc _ x'))
|
| 1170 | - = exp x x'
|
|
| 1170 | + = lexp x x'
|
|
| 1171 | 1171 | exp (HsVar _ i) (HsVar _ i') = i == i'
|
| 1172 | 1172 | exp (HsIPVar _ i) (HsIPVar _ i') =
|
| 1173 | 1173 | -- the instance for IPName derives using the id, so follow the HsVar case
|
| ... | ... | @@ -1739,7 +1739,7 @@ repE e@(XExpr (ExpandedThingRn o x)) |
| 1739 | 1739 | | ExprCtxt e <- o
|
| 1740 | 1740 | = do { rebindable_on <- lift $ xoptM LangExt.RebindableSyntax
|
| 1741 | 1741 | ; if rebindable_on -- See Note [Quotation and rebindable syntax]
|
| 1742 | - then repE x
|
|
| 1742 | + then repLE x
|
|
| 1743 | 1743 | else repE e }
|
| 1744 | 1744 | | otherwise
|
| 1745 | 1745 | = notHandled (ThExpressionForm e)
|
| ... | ... | @@ -492,7 +492,7 @@ isCallSite HsApp{} = True |
| 492 | 492 | isCallSite HsAppType{} = True
|
| 493 | 493 | isCallSite HsCase{} = True
|
| 494 | 494 | isCallSite (XExpr (ExpandedThingTc _ e))
|
| 495 | - = isCallSite e
|
|
| 495 | + = isCallSite (unLoc e)
|
|
| 496 | 496 | |
| 497 | 497 | -- NB: OpApp, SectionL, SectionR are all expanded out
|
| 498 | 498 | isCallSite _ = False
|
| ... | ... | @@ -660,14 +660,14 @@ addTickHsExpr (HsDo srcloc cxt (L l stmts)) |
| 660 | 660 | ListComp -> Just $ BinBox QualBinBox
|
| 661 | 661 | _ -> Nothing
|
| 662 | 662 | |
| 663 | -addTickHsExpanded :: HsCtxt -> HsExpr GhcTc -> TM (HsExpr GhcTc)
|
|
| 663 | +addTickHsExpanded :: HsCtxt -> LHsExpr GhcTc -> TM (HsExpr GhcTc)
|
|
| 664 | 664 | addTickHsExpanded o e = liftM (XExpr . ExpandedThingTc o) $ case o of
|
| 665 | 665 | -- We always want statements to get a tick, so we can step over each one.
|
| 666 | 666 | -- To avoid duplicates we blacklist SrcSpans we already inserted here.
|
| 667 | 667 | StmtErrCtxt _ (L pos _) -> do_tick_black pos
|
| 668 | 668 | _ -> skip
|
| 669 | 669 | where
|
| 670 | - skip = addTickHsExpr e
|
|
| 670 | + skip = addTickLHsExpr e
|
|
| 671 | 671 | do_tick_black pos = do
|
| 672 | 672 | d <- getDensity
|
| 673 | 673 | case d of
|
| ... | ... | @@ -675,9 +675,9 @@ addTickHsExpanded o e = liftM (XExpr . ExpandedThingTc o) $ case o of |
| 675 | 675 | TickForBreakPoints -> tick_it_black pos
|
| 676 | 676 | _ -> skip
|
| 677 | 677 | tick_it_black pos =
|
| 678 | - unLoc <$> allocTickBox (ExpBox False) False False (locA pos)
|
|
| 678 | + allocTickBox (ExpBox False) False False (locA pos)
|
|
| 679 | 679 | (withBlackListed (locA pos) $
|
| 680 | - addTickHsExpr e)
|
|
| 680 | + addTickHsExpr (unLoc e))
|
|
| 681 | 681 | |
| 682 | 682 | addTickTupArg :: HsTupArg GhcTc -> TM (HsTupArg GhcTc)
|
| 683 | 683 | addTickTupArg (Present x e) = do { e' <- addTickLHsExpr e
|
| ... | ... | @@ -757,8 +757,8 @@ instance HiePass p => HasType (LocatedA (HsExpr (GhcPass p))) where |
| 757 | 757 | HsPragE _ _ e -> computeLType e
|
| 758 | 758 | XExpr (ExpandedThingTc thing e)
|
| 759 | 759 | | ExprCtxt (HsGetField{}) <- thing -- for record-dot-syntax
|
| 760 | - -> Just (hsExprType e)
|
|
| 761 | - | otherwise -> computeType e
|
|
| 760 | + -> Just (lhsExprType e)
|
|
| 761 | + | otherwise -> computeLType e
|
|
| 762 | 762 | XExpr (HsTick _ e) -> computeLType e
|
| 763 | 763 | XExpr (HsBinTick _ _ e) -> computeLType e
|
| 764 | 764 | e -> Just (hsExprType e)
|
| ... | ... | @@ -1353,7 +1353,7 @@ instance HiePass p => ToHie (LocatedA (HsExpr (GhcPass p))) where |
| 1353 | 1353 | -> [ toHie $ L mspan a
|
| 1354 | 1354 | , toHie (L mspan w) ]
|
| 1355 | 1355 | ExpandedThingTc _ e
|
| 1356 | - -> [ toHie (L mspan e) ]
|
|
| 1356 | + -> [ toHie e ]
|
|
| 1357 | 1357 | ConLikeTc con
|
| 1358 | 1358 | -> [ toHie $ C Use $ L mspan $ conLikeName con ]
|
| 1359 | 1359 | HsTick _ expr
|
| ... | ... | @@ -24,6 +24,8 @@ module GHC.Rename.Utils ( |
| 24 | 24 | genSimpleFunBind, genFunBind,
|
| 25 | 25 | genHsLamDoExp, genHsCaseAltDoExp, genSimpleMatch, genHsLet,
|
| 26 | 26 | |
| 27 | + mkExpandedRn, mkExpandedExpr, mkExpandedStmt, mkExpandedLExpr, mkExpandedTc, mkExpandedExprTc,
|
|
| 28 | + |
|
| 27 | 29 | mkRnSyntaxExpr,
|
| 28 | 30 | |
| 29 | 31 | newLocalBndrRn, newLocalBndrsRn,
|
| ... | ... | @@ -45,7 +47,6 @@ import GHC.Core.Type |
| 45 | 47 | import GHC.Hs
|
| 46 | 48 | import GHC.Types.Name.Reader
|
| 47 | 49 | import GHC.Tc.Errors.Types
|
| 48 | --- import GHC.Tc.Utils.Env
|
|
| 49 | 50 | import GHC.Tc.Utils.Monad
|
| 50 | 51 | import GHC.Types.Name
|
| 51 | 52 | import GHC.Types.Name.Set
|
| ... | ... | @@ -816,3 +817,50 @@ genSimpleMatch ctxt pats rhs |
| 816 | 817 | = wrapGenSpan $
|
| 817 | 818 | Match { m_ext = noExtField, m_ctxt = ctxt, m_pats = noLocA pats
|
| 818 | 819 | , m_grhss = unguardedGRHSs generatedSrcSpan rhs noAnn }
|
| 820 | + |
|
| 821 | + |
|
| 822 | +-- | Build an expression using the extension constructor `XExpr`,
|
|
| 823 | +-- and the two components of the expansion: original expression and
|
|
| 824 | +-- expanded expressions.
|
|
| 825 | +mkExpandedExpr
|
|
| 826 | + :: HsExpr GhcRn -- ^ source expression context
|
|
| 827 | + -> HsExpr GhcRn -- ^ expanded expression
|
|
| 828 | + -> HsExpr GhcRn -- ^ suitably wrapped 'XXExprGhcRn'
|
|
| 829 | +mkExpandedExpr oExpr eExpr = mkExpandedRn (ExprCtxt oExpr) (wrapGenSpan eExpr)
|
|
| 830 | + |
|
| 831 | +mkExpandedLExpr
|
|
| 832 | + :: HsExpr GhcRn -- ^ source expression context
|
|
| 833 | + -> LHsExpr GhcRn -- ^ expanded expression
|
|
| 834 | + -> HsExpr GhcRn -- ^ suitably wrapped 'XXExprGhcRn'
|
|
| 835 | +mkExpandedLExpr oExpr eExpr = mkExpandedRn (ExprCtxt oExpr) eExpr
|
|
| 836 | + |
|
| 837 | +-- | Build an expression using the extension constructor `XExpr`,
|
|
| 838 | +-- and the two components of the expansion: original do stmt and
|
|
| 839 | +-- expanded expression
|
|
| 840 | +mkExpandedStmt
|
|
| 841 | + :: ExprLStmt GhcRn -- ^ source statement context
|
|
| 842 | + -> HsDoFlavour -- ^ source statements do flavour
|
|
| 843 | + -> HsExpr GhcRn -- ^ expanded expression
|
|
| 844 | + -> HsExpr GhcRn -- ^ suitably wrapped 'XXExprGhcRn'
|
|
| 845 | +mkExpandedStmt oStmt flav eExpr = mkExpandedRn (StmtErrCtxt (HsDoStmt flav) oStmt) (wrapGenSpan eExpr)
|
|
| 846 | + |
|
| 847 | +mkExpandedRn
|
|
| 848 | + :: HsCtxt -- ^ source, user written do statement/expression
|
|
| 849 | + -> LHsExpr GhcRn -- ^ expanded typechecked expression
|
|
| 850 | + -> HsExpr GhcRn -- ^ suitably wrapped 'XXExprGhcRn'
|
|
| 851 | +mkExpandedRn orig expr = XExpr (ExpandedThingRn orig expr)
|
|
| 852 | + |
|
| 853 | +-- | Build a 'XXExprGhcRn' out of an extension constructor,
|
|
| 854 | +-- and the two components of the expansion: original and
|
|
| 855 | +-- expanded typechecked expressions.
|
|
| 856 | +mkExpandedExprTc
|
|
| 857 | + :: HsExpr GhcRn -- ^ source expression
|
|
| 858 | + -> HsExpr GhcTc -- ^ expanded typechecked expression
|
|
| 859 | + -> HsExpr GhcTc -- ^ suitably wrapped 'XXExprGhcRn'
|
|
| 860 | +mkExpandedExprTc oExpr eExpr = mkExpandedTc (ExprCtxt oExpr) (wrapGenSpan eExpr)
|
|
| 861 | + |
|
| 862 | +mkExpandedTc
|
|
| 863 | + :: HsCtxt -- ^ source, user written do statement/expression
|
|
| 864 | + -> LHsExpr GhcTc -- ^ expanded typechecked expression
|
|
| 865 | + -> HsExpr GhcTc -- ^ suitably wrapped 'XXExprGhcRn'
|
|
| 866 | +mkExpandedTc o e = XExpr (ExpandedThingTc o e) |
| ... | ... | @@ -957,8 +957,8 @@ addArgCtxt arg_no (app_head, app_head_lspan) (L arg_loc arg) thing_inside |
| 957 | 957 | , ppr arg
|
| 958 | 958 | , ppr arg_no])
|
| 959 | 959 | ; setSrcSpanA arg_loc $
|
| 960 | - addNthFunArgErrCtxt app_head arg arg_no $
|
|
| 961 | - thing_inside
|
|
| 960 | + addErrCtxt (FunAppCtxt (FunAppCtxtExpr app_head arg) arg_no) $
|
|
| 961 | + thing_inside
|
|
| 962 | 962 | }
|
| 963 | 963 | | otherwise
|
| 964 | 964 | = do { traceTc "addArgCtxt" (vcat [text "generated Head"
|
| ... | ... | @@ -969,16 +969,6 @@ addArgCtxt arg_no (app_head, app_head_lspan) (L arg_loc arg) thing_inside |
| 969 | 969 | ; addLExprCtxt (locA arg_loc) arg $
|
| 970 | 970 | thing_inside
|
| 971 | 971 | }
|
| 972 | - where
|
|
| 973 | - addNthFunArgErrCtxt :: HsExpr GhcRn -> HsExpr GhcRn -> Int -> TcM a -> TcM a
|
|
| 974 | - addNthFunArgErrCtxt app_head arg arg_no thing_inside
|
|
| 975 | - | XExpr (ExpandedThingRn _ _) <- arg
|
|
| 976 | - = addExpansionErrCtxt (FunAppCtxt (FunAppCtxtExpr app_head arg) arg_no) $
|
|
| 977 | - thing_inside
|
|
| 978 | - | otherwise
|
|
| 979 | - = addErrCtxt (FunAppCtxt (FunAppCtxtExpr app_head arg) arg_no) $
|
|
| 980 | - thing_inside
|
|
| 981 | - |
|
| 982 | 972 | |
| 983 | 973 | |
| 984 | 974 | {- *********************************************************************
|
| ... | ... | @@ -1950,13 +1940,10 @@ quickLookArg1 :: Int -> SrcSpan -> (HsExpr GhcRn, SrcSpan) -> LHsExpr GhcRn |
| 1950 | 1940 | quickLookArg1 pos app_lspan (fun, fun_lspan) larg@(L arg_loc arg) sc_arg_ty@(Scaled _ orig_arg_rho)
|
| 1951 | 1941 | = addArgCtxt pos (fun, fun_lspan) larg $ -- Context needed for constraints
|
| 1952 | 1942 | -- generated by calls in arg
|
| 1953 | - do { ((rn_fun_arg, fun_lspan_arg'), rn_args) <- splitHsApps arg
|
|
| 1954 | - ; let fun_lspan_arg | null rn_args = locA arg_loc -- arg is an id (or an XExpr) so use the arg_loc in tcInstFun
|
|
| 1955 | - | otherwise = fun_lspan_arg'
|
|
| 1943 | + do { ((rn_fun_arg, fun_lspan_arg), rn_args) <- splitHsApps arg
|
|
| 1956 | 1944 | |
| 1957 | 1945 | -- Step 1: get the type of the head of the argument
|
| 1958 | - ; (fun_ue, mb_fun_ty) <- maybe_update_err_ctxt fun_lspan_arg rn_fun_arg $
|
|
| 1959 | - (tcCollectingUsage $ tcInferAppHead_maybe rn_fun_arg)
|
|
| 1946 | + ; (fun_ue, mb_fun_ty) <- (tcCollectingUsage $ tcInferAppHead_maybe rn_fun_arg)
|
|
| 1960 | 1947 | -- tcCollectingUsage: the use of an Id at the head generates usage-info
|
| 1961 | 1948 | -- See the call to `tcEmitBindingUsage` in `check_local_id`. So we must
|
| 1962 | 1949 | -- capture and save it in the `EValArgQL`. See (QLA6) in
|
| ... | ... | @@ -2025,20 +2012,6 @@ quickLookArg1 pos app_lspan (fun, fun_lspan) larg@(L arg_loc arg) sc_arg_ty@(Sca |
| 2025 | 2012 | , eaql_res_rho = app_res_rho }) }}}
|
| 2026 | 2013 | |
| 2027 | 2014 | |
| 2028 | -maybe_update_err_ctxt :: SrcSpan -> HsExpr GhcRn -> TcM a -> TcM a
|
|
| 2029 | -maybe_update_err_ctxt fun_lspan_arg rn_fun_arg thing_inside
|
|
| 2030 | - | not (isGeneratedSrcSpan fun_lspan_arg)
|
|
| 2031 | - , XExpr (ExpandedThingRn{}) <- rn_fun_arg
|
|
| 2032 | - = do igc <- inGeneratedCode
|
|
| 2033 | - if igc
|
|
| 2034 | - then thing_inside
|
|
| 2035 | - else addLExprCtxt fun_lspan_arg rn_fun_arg $
|
|
| 2036 | - thing_inside
|
|
| 2037 | - | otherwise
|
|
| 2038 | - = thing_inside
|
|
| 2039 | - |
|
| 2040 | - |
|
| 2041 | - |
|
| 2042 | 2015 | mk_origin :: SrcSpan -- SrcSpan of the argument
|
| 2043 | 2016 | -> HsExpr GhcRn -- The head of the expression application chain
|
| 2044 | 2017 | -> TcM CtOrigin
|
| ... | ... | @@ -14,8 +14,7 @@ module GHC.Tc.Gen.Do (expandDoStmts) where |
| 14 | 14 | |
| 15 | 15 | import GHC.Prelude
|
| 16 | 16 | |
| 17 | -import GHC.Rename.Utils ( wrapGenSpan, genHsExpApps, genHsApp, genHsLet,
|
|
| 18 | - genHsLamDoExp, genHsCaseAltDoExp, genWildPat )
|
|
| 17 | +import GHC.Rename.Utils
|
|
| 19 | 18 | import GHC.Rename.Env ( irrefutableConLikeRn )
|
| 20 | 19 | |
| 21 | 20 | import GHC.Tc.Utils.Monad
|
| ... | ... | @@ -114,7 +113,7 @@ expand_do_stmts doFlavour (stmt@(L loc (BindStmt xbsrn pat e)): lstmts) |
| 114 | 113 | | otherwise
|
| 115 | 114 | = pprPanic "expand_do_stmts: The impossible happened, missing bind operator from renamer" (text "stmt" <+> ppr stmt)
|
| 116 | 115 | |
| 117 | -expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ (L e_lspan e) (SyntaxExprRn then_op) _)) : lstmts) =
|
|
| 116 | +expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ (L _ e) (SyntaxExprRn then_op) _)) : lstmts) =
|
|
| 118 | 117 | -- See Note [BodyStmt] in Language.Haskell.Syntax.Expr
|
| 119 | 118 | -- See Note [Expanding HsDo with XXExprGhcRn] Equation (1) below
|
| 120 | 119 | -- stmts ~~> stmts'
|
| ... | ... | @@ -122,7 +121,7 @@ expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ (L e_lspan e) (SyntaxExprRn t |
| 122 | 121 | -- e ; stmts ~~> (>>) e stmts'
|
| 123 | 122 | do expand_stmts_expr <- expand_do_stmts doFlavour lstmts
|
| 124 | 123 | let expansion = genHsExpApps then_op -- (>>)
|
| 125 | - [ L e_lspan (mkExpandedStmt stmt doFlavour e)
|
|
| 124 | + [ wrapGenSpan e
|
|
| 126 | 125 | , expand_stmts_expr ]
|
| 127 | 126 | return $ L loc (mkExpandedStmt stmt doFlavour expansion)
|
| 128 | 127 | |
| ... | ... | @@ -484,4 +483,4 @@ It stores the original statement (with location) and the expanded expression |
| 484 | 483 | mkExpandedPatRn :: LPat GhcRn -> HsExpr GhcRn -> HsExpr GhcRn
|
| 485 | 484 | mkExpandedPatRn pat e = XExpr $ ExpandedThingRn
|
| 486 | 485 | { xrn_orig = StmtErrCtxtPat pat
|
| 487 | - , xrn_expanded = e} |
|
| 486 | + , xrn_expanded = wrapGenSpan e} |
| ... | ... | @@ -36,6 +36,7 @@ import GHC.Rename.Env ( addUsedGRE, getUpdFieldLbls ) |
| 36 | 36 | |
| 37 | 37 | import GHC.Tc.Gen.App
|
| 38 | 38 | import GHC.Tc.Gen.Head
|
| 39 | +import GHC.Tc.Gen.Do
|
|
| 39 | 40 | import GHC.Tc.Gen.Bind ( tcLocalBinds )
|
| 40 | 41 | import GHC.Tc.Gen.HsType
|
| 41 | 42 | import GHC.Tc.Gen.Arrow
|
| ... | ... | @@ -92,6 +93,8 @@ import GHC.Data.Maybe |
| 92 | 93 | import Control.Monad
|
| 93 | 94 | import qualified Data.List.NonEmpty as NE
|
| 94 | 95 | |
| 96 | +import qualified GHC.LanguageExtensions as LangExt
|
|
| 97 | + |
|
| 95 | 98 | {-
|
| 96 | 99 | ************************************************************************
|
| 97 | 100 | * *
|
| ... | ... | @@ -267,13 +270,6 @@ tcCheckMonoExpr, tcCheckMonoExprNC |
| 267 | 270 | tcCheckMonoExpr expr res_ty = tcMonoLExpr expr (mkCheckExpType res_ty)
|
| 268 | 271 | tcCheckMonoExprNC expr res_ty = tcMonoLExprNC expr (mkCheckExpType res_ty)
|
| 269 | 272 | |
| 270 | - |
|
| 271 | --- Expand the HsExpr if it is typechecked after expansions
|
|
| 272 | --- See Note [Handling overloaded and rebindable constructs]
|
|
| 273 | --- See Note [Typechecking by expansion: overview]
|
|
| 274 | -expand_expr :: HsExpr GhcRn -> TcM (HsExpr GhcRn)
|
|
| 275 | -expand_expr x = return x
|
|
| 276 | - |
|
| 277 | 273 | ---------------
|
| 278 | 274 | tcMonoLExpr, tcMonoLExprNC
|
| 279 | 275 | :: LHsExpr GhcRn -- Expression to type check
|
| ... | ... | @@ -282,8 +278,7 @@ tcMonoLExpr, tcMonoLExprNC |
| 282 | 278 | -> TcM (LHsExpr GhcTc)
|
| 283 | 279 | |
| 284 | 280 | tcMonoLExpr (L loc expr) res_ty
|
| 285 | - = do expanded_expr <- expand_expr expr
|
|
| 286 | - addLExprCtxt (locA loc) expanded_expr $ -- Note [Error contexts in generated code]
|
|
| 281 | + = do addLExprCtxt (locA loc) expr $ -- Note [Error contexts in generated code]
|
|
| 287 | 282 | do { expr' <- tcExpr expr res_ty
|
| 288 | 283 | ; return (L loc expr') }
|
| 289 | 284 | |
| ... | ... | @@ -562,7 +557,20 @@ tcExpr (HsMultiIf _ alts) res_ty |
| 562 | 557 | ; res_ty <- readExpType res_ty
|
| 563 | 558 | ; return (HsMultiIf res_ty alts') }
|
| 564 | 559 | |
| 565 | -tcExpr (HsDo _ do_or_lc stmts) res_ty
|
|
| 560 | +tcExpr expr@(HsDo _ do_or_lc stmts) res_ty
|
|
| 561 | + | DoExpr{} <- do_or_lc
|
|
| 562 | + -- ApplicativeDo are typechecked using tcDoStmts
|
|
| 563 | + = do isApplicativeDo <- xoptM LangExt.ApplicativeDo
|
|
| 564 | + if isApplicativeDo
|
|
| 565 | + then tcDoStmts do_or_lc stmts res_ty
|
|
| 566 | + -- Expand expression on the fly otherwise
|
|
| 567 | + -- See Note [Typechecking by expansion: overview]
|
|
| 568 | + else do { expr' <- tcExpandExpr expr
|
|
| 569 | + ; tcExpr expr' res_ty }
|
|
| 570 | + | MDoExpr{} <- do_or_lc
|
|
| 571 | + = do expr' <- tcExpandExpr expr
|
|
| 572 | + tcExpr expr' res_ty
|
|
| 573 | + | otherwise
|
|
| 566 | 574 | = tcDoStmts do_or_lc stmts res_ty
|
| 567 | 575 | |
| 568 | 576 | tcExpr (HsProc x pat cmd) res_ty
|
| ... | ... | @@ -678,7 +686,7 @@ tcExpr expr@(RecordUpd { rupd_expr = record_expr |
| 678 | 686 | |
| 679 | 687 | ; (ds_expr, ds_res_ty, err_msg)
|
| 680 | 688 | <- expandRecordUpd record_expr possible_parents rbnds res_ty
|
| 681 | - ; addExpansionErrCtxt err_msg $
|
|
| 689 | + ; setInGeneratedCode $ addErrCtxt err_msg $
|
|
| 682 | 690 | do { -- Typecheck the expanded expression.
|
| 683 | 691 | expr' <- tcExpr ds_expr (Check ds_res_ty)
|
| 684 | 692 | -- NB: it's important to use ds_res_ty and not res_ty here.
|
| ... | ... | @@ -776,12 +784,12 @@ directly, it's much easier to |
| 776 | 784 | |
| 777 | 785 | Example: record updates. The typechecker looks like this:
|
| 778 | 786 | |
| 779 | - tcExpr e@(RecordUpd{}) rho = do { ee <- expandExpr e
|
|
| 780 | - ; tcExpr ee rho }
|
|
| 787 | + tcExpr e@(HsDo{}) rho = do { ee <- expandExpr e
|
|
| 788 | + ; tcExpr ee rho }
|
|
| 781 | 789 | |
| 782 | -The `expandExpr` replaces the record update (e { x = rhs })
|
|
| 790 | +The `expandExpr` replaces the HsDo { x <- e1; return x }
|
|
| 783 | 791 | with something like
|
| 784 | - case e of { MkT a b _ d -> MkT a b rhs d }
|
|
| 792 | + e1 >>= \ x -> x
|
|
| 785 | 793 | and we then typecheck the latter.
|
| 786 | 794 | |
| 787 | 795 | See also Note [Handling overloaded and rebindable constructs]
|
| ... | ... | @@ -798,8 +806,9 @@ The rest of this Note explains how that is done. |
| 798 | 806 | , xrn_expanded = ee } ))
|
| 799 | 807 | where `ee` is the expansion of the user written thing `ue`
|
| 800 | 808 | |
| 801 | -* The type checker context has 2 key fields that describe the context:
|
|
| 809 | +* The type checker context has 3 key fields that describe the context:
|
|
| 802 | 810 | TcLclCtxt { tcl_loc :: RealSrcSpan
|
| 811 | + , tcl_in_gen_code :: Bool
|
|
| 803 | 812 | , tcl_err_ctxt :: [ErrCtxt]
|
| 804 | 813 | , ... }
|
| 805 | 814 | Note `tcl_loc` always points to a real place in the source code,
|
| ... | ... | @@ -808,8 +817,12 @@ The rest of this Note explains how that is done. |
| 808 | 817 | The `tcl_err_ctxt` is a stack of contexts, each saying something
|
| 809 | 818 | like "In the expression: x+y" or "In the record update: r { x=2 }"
|
| 810 | 819 | |
| 820 | + The `tcl_in_gen_code` is a boolean that keeps track of whether
|
|
| 821 | + the current expression being typechecked is compiler generated
|
|
| 822 | + or user generated.
|
|
| 823 | + |
|
| 811 | 824 | * Now, when
|
| 812 | - tcMonoLHsExpr :: LHsExpr GhcRn -> ExpRhoType -> TcM (HsExpr GhcTc)
|
|
| 825 | + tcMonoLExpr :: LHsExpr GhcRn -> ExpRhoType -> TcM (HsExpr GhcTc)
|
|
| 813 | 826 | gets a located expression, it does 2 things:
|
| 814 | 827 | * Calls `addLExprCtxt` to perform error context management
|
| 815 | 828 | * Calls `tcExpr` to typecheck the expression.
|
| ... | ... | @@ -839,7 +852,7 @@ tcXExpr (ExpandedThingRn o e) res_ty |
| 839 | 852 | = mkExpandedTc o <$> -- necessary for hpc ticks
|
| 840 | 853 | -- Need to call tcExpr and not tcApp
|
| 841 | 854 | -- as e can be let statement which tcApp cannot gracefully handle
|
| 842 | - tcExpr e res_ty
|
|
| 855 | + tcMonoLExpr e res_ty
|
|
| 843 | 856 | |
| 844 | 857 | -- For record selection, same as HsVar case
|
| 845 | 858 | tcXExpr xe res_ty = tcApp (XExpr xe) res_ty
|
| ... | ... | @@ -1846,3 +1859,14 @@ checkMissingFields con_like rbinds arg_tys |
| 1846 | 1859 | field_strs = conLikeImplBangs con_like
|
| 1847 | 1860 | |
| 1848 | 1861 | fl `elemField` flds = any (\ fl' -> flSelector fl == fl') flds
|
| 1862 | + |
|
| 1863 | + |
|
| 1864 | +-- Expands the expression on the fly
|
|
| 1865 | +-- See Note [Handling overloaded and rebindable constructs]
|
|
| 1866 | +-- See Note [Typechecking by expansion: overview]
|
|
| 1867 | +tcExpandExpr :: HsExpr GhcRn -> TcM (HsExpr GhcRn)
|
|
| 1868 | +tcExpandExpr orig_expr@(HsDo _ flav (L _ stmts))
|
|
| 1869 | + = do { expanded_expr <- expandDoStmts flav stmts
|
|
| 1870 | + ; return (mkExpandedLExpr orig_expr expanded_expr) }
|
|
| 1871 | + |
|
| 1872 | +tcExpandExpr e = return e |
| ... | ... | @@ -29,6 +29,8 @@ import GHC.Prelude |
| 29 | 29 | import GHC.Hs
|
| 30 | 30 | import GHC.Hs.Syn.Type
|
| 31 | 31 | |
| 32 | +import GHC.Rename.Utils (mkExpandedTc, mkExpandedExprTc)
|
|
| 33 | + |
|
| 32 | 34 | import GHC.Tc.Gen.HsType
|
| 33 | 35 | import GHC.Tc.Gen.Bind( chooseInferredQuantifiers )
|
| 34 | 36 | import GHC.Tc.Gen.Sig( tcUserTypeSig, tcInstSig )
|
| ... | ... | @@ -460,12 +462,12 @@ tcInferAppHead_maybe fun = case fun of |
| 460 | 462 | ExprWithTySig _ e hs_ty -> Just <$> with_get_ds (tcExprWithSig e hs_ty)
|
| 461 | 463 | HsOverLit _ lit -> Just <$> with_get_ds (tcInferOverLit lit)
|
| 462 | 464 | XExpr (HsRecSelRn f) -> Just <$> with_get_ds (tcInferRecSelId f)
|
| 463 | - XExpr (ExpandedThingRn o e) -> Just <$> (
|
|
| 465 | + XExpr (ExpandedThingRn o (L loc e)) -> setSrcSpan (locA loc) $ Just <$> (
|
|
| 464 | 466 | -- We do not want to instantiate the type of the head as there may be
|
| 465 | 467 | -- visible type applications in the argument.
|
| 466 | 468 | -- c.f. T19167
|
| 467 | - (\ (e, ds_flag, ty) -> (mkExpandedTc o e, ds_flag, ty)) <$>
|
|
| 468 | - tcExprSigma False (errCtxtCtOrigin o) e
|
|
| 469 | + (\ (e, ds_flag, ty) -> (mkExpandedTc o (L loc e), ds_flag, ty)) <$>
|
|
| 470 | + tcExprSigma False (errCtxtCtOrigin o) e
|
|
| 469 | 471 | )
|
| 470 | 472 | _ -> return Nothing
|
| 471 | 473 |
| ... | ... | @@ -35,7 +35,7 @@ where |
| 35 | 35 | import GHC.Prelude
|
| 36 | 36 | |
| 37 | 37 | import {-# SOURCE #-} GHC.Tc.Gen.Expr( tcSyntaxOp, tcInferRho, tcInferRhoFRRNC
|
| 38 | - , tcMonoLExprNC, tcMonoLExpr, tcExpr
|
|
| 38 | + , tcMonoLExprNC, tcExpr
|
|
| 39 | 39 | , tcCheckMonoExpr, tcCheckMonoExprNC
|
| 40 | 40 | , tcCheckPolyExpr, tcPolyLExpr )
|
| 41 | 41 | |
| ... | ... | @@ -44,7 +44,6 @@ import GHC.Tc.Errors.Types |
| 44 | 44 | import GHC.Tc.Utils.Monad
|
| 45 | 45 | import GHC.Tc.Utils.Env
|
| 46 | 46 | import GHC.Tc.Gen.Pat
|
| 47 | -import GHC.Tc.Gen.Do
|
|
| 48 | 47 | import GHC.Tc.Gen.Head( tcCheckId )
|
| 49 | 48 | import GHC.Tc.Utils.TcMType
|
| 50 | 49 | import GHC.Tc.Utils.TcType
|
| ... | ... | @@ -391,32 +390,14 @@ tcDoStmts MonadComp (L l stmts) res_ty |
| 391 | 390 | ; res_ty <- readExpType res_ty
|
| 392 | 391 | ; return (HsDo res_ty MonadComp (L l stmts')) }
|
| 393 | 392 | |
| 394 | -tcDoStmts ctxt@GhciStmtCtxt _ _ = pprPanic "tcDoStmts" (pprHsDoFlavour ctxt)
|
|
| 395 | - |
|
| 396 | -tcDoStmts doExpr@(DoExpr _) ss@(L l stmts) res_ty
|
|
| 397 | - = do { isApplicativeDo <- xoptM LangExt.ApplicativeDo
|
|
| 398 | - ; if isApplicativeDo
|
|
| 399 | - then do { stmts' <- tcStmts (HsDoStmt doExpr) tcDoStmt stmts res_ty
|
|
| 400 | - ; res_ty <- readExpType res_ty
|
|
| 401 | - ; return (HsDo res_ty doExpr (L l stmts')) }
|
|
| 402 | - else do { expanded_expr <- expandDoStmts doExpr stmts -- Do expansion on the fly
|
|
| 403 | - ; traceTc "tcDoStmts" (ppr expanded_expr)
|
|
| 404 | - ; let orig = HsDo noExtField doExpr ss
|
|
| 405 | - ; mkExpandedExprTc orig <$> (
|
|
| 406 | - -- We lose the location on the first statement location in GhcTc, unfortunately.
|
|
| 407 | - -- It is needed for get the pattern match warnings right cf. T14546d
|
|
| 408 | - -- That location is currently recovered from the location stored in OrigStmt
|
|
| 409 | - -- in dsExpr of ExpandedThingTc
|
|
| 410 | - unLoc <$> tcMonoLExpr expanded_expr res_ty)
|
|
| 411 | - }
|
|
| 412 | - }
|
|
| 413 | 393 | |
| 414 | -tcDoStmts mDoExpr ss@(L _ stmts) res_ty
|
|
| 415 | - = do { expanded_expr <- expandDoStmts mDoExpr stmts -- Do expansion on the fly
|
|
| 416 | - ; let orig = HsDo noExtField mDoExpr ss
|
|
| 417 | - ; e' <- tcMonoLExpr expanded_expr res_ty
|
|
| 418 | - ; return (mkExpandedExprTc orig (unLoc e'))
|
|
| 419 | - }
|
|
| 394 | +tcDoStmts doExpr@(DoExpr _) (L l stmts) res_ty
|
|
| 395 | + = do { stmts' <- tcStmts (HsDoStmt doExpr) tcDoStmt stmts res_ty
|
|
| 396 | + ; res_ty <- readExpType res_ty
|
|
| 397 | + ; return (HsDo res_ty doExpr (L l stmts')) }
|
|
| 398 | + |
|
| 399 | +-- NB: ghcistmts should fail, MDoExpr is handled by expansions
|
|
| 400 | +tcDoStmts ctxt _ _ = pprPanic "tcDoStmts" (pprHsDoFlavour ctxt)
|
|
| 420 | 401 | |
| 421 | 402 | tcBody :: LHsExpr GhcRn -> ExpRhoType -> TcM (LHsExpr GhcTc)
|
| 422 | 403 | tcBody body res_ty
|
| ... | ... | @@ -88,7 +88,7 @@ module GHC.Tc.Utils.Monad( |
| 88 | 88 | |
| 89 | 89 | -- * Context management for the type checker
|
| 90 | 90 | getErrCtxt, setErrCtxt, addErrCtxt,
|
| 91 | - addLExprCtxt, addExpansionErrCtxt,
|
|
| 91 | + addLExprCtxt,
|
|
| 92 | 92 | popErrCtxt, getCtLocM, setCtLocM, mkCtLocEnv,
|
| 93 | 93 | |
| 94 | 94 | -- * Diagnostic message generation (type checker)
|
| ... | ... | @@ -1316,11 +1316,16 @@ problem. |
| 1316 | 1316 | |
| 1317 | 1317 | Note [Error contexts in generated code]
|
| 1318 | 1318 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 1319 | -* If the `SrcSpan` is a `RealSrcSpan`, `setSrcSpan` updates the `tcl_loc`,
|
|
| 1320 | - and makes the `ErrCtxStack` a `UserCodeCtxt`
|
|
| 1321 | -* it is a no-op otherwise
|
|
| 1322 | 1319 | |
| 1323 | -So, it's better to do a `setSrcSpan` /before/ `addErrCtxt`.
|
|
| 1320 | +* addLExpr updates updates the ErrCtxt stored in LclEnv with the following logic
|
|
| 1321 | + - If the `SrcSpan` is a `RealSrcSpan`, `setSrcSpan` updates the `tcl_loc` to the given value
|
|
| 1322 | + and sets `tcl_in_gen_code` to `False`. Meaning we are not type checking a compiler generated
|
|
| 1323 | + expression. And thus it can add the expression on to the ErrCtxt Stack
|
|
| 1324 | + - If the `SrcSpan` is a GeneratedSrcSpan then `tcl_in_gen_code` is set to `True`, meaning
|
|
| 1325 | + the expression in hand is compiler generated, and hence it is not added on to the stack.
|
|
| 1326 | + |
|
| 1327 | +This ensures that the error messages do not leak compiler generated expressions which can
|
|
| 1328 | +be confusing to the users.
|
|
| 1324 | 1329 | |
| 1325 | 1330 | - See Note [Rebindable syntax and XXExprGhcRn] in `GHC.Hs.Expr` for
|
| 1326 | 1331 | more discussion of this fancy footwork
|
| ... | ... | @@ -1329,33 +1334,32 @@ relation with pattern-match checks |
| 1329 | 1334 | - See Note [ErrCtxtStack Manipulation] in `GHC.Tc.Types.LclEnv` for info about `ErrCtxtStack`
|
| 1330 | 1335 | -}
|
| 1331 | 1336 | |
| 1337 | +-- See Note [Error contexts in generated code]
|
|
| 1332 | 1338 | addLExprCtxt :: SrcSpan -> HsExpr GhcRn -> TcRn a -> TcRn a
|
| 1333 | 1339 | addLExprCtxt lspan e thing_inside
|
| 1334 | - | not (isGeneratedSrcSpan lspan)
|
|
| 1335 | 1340 | = setSrcSpan lspan $ add_expr_ctxt e thing_inside
|
| 1336 | - | otherwise -- no op in generated code
|
|
| 1337 | - = thing_inside
|
|
| 1338 | 1341 | where
|
| 1339 | - add_expr_ctxt :: HsExpr GhcRn -> TcRn a -> TcRn a
|
|
| 1340 | - add_expr_ctxt e thing_inside
|
|
| 1341 | - = case e of
|
|
| 1342 | - -- The HsHole special case addresses situations like
|
|
| 1343 | - -- f x = _
|
|
| 1344 | - -- when we don't want to say "In the expression: _",
|
|
| 1345 | - -- because it is mentioned in the error message itself
|
|
| 1346 | - HsHole{} -> thing_inside
|
|
| 1347 | - |
|
| 1348 | - -- There is a special case for expressions with signatures to avoid having too verbose
|
|
| 1349 | - -- error context. So here we flip the ErrCtxt state to expanded if the expression is expanded.
|
|
| 1350 | - -- c.f. RecordDotSyntaxFail9
|
|
| 1351 | - ExprWithTySig _ (L _ e') _
|
|
| 1352 | - | XExpr (ExpandedThingRn o _) <- e' -> addExpansionErrCtxt o thing_inside
|
|
| 1353 | - |
|
| 1354 | - -- Flip error ctxt into expansion mode
|
|
| 1355 | - XExpr (ExpandedThingRn o _) -> addExpansionErrCtxt o thing_inside
|
|
| 1356 | - |
|
| 1357 | - _ -> addErrCtxt (ExprCtxt e) thing_inside
|
|
| 1358 | - |
|
| 1342 | + add_expr_ctxt :: HsExpr GhcRn -> TcRn a -> TcRn a
|
|
| 1343 | + add_expr_ctxt e thing_inside
|
|
| 1344 | + = do { igc <- inGeneratedCode
|
|
| 1345 | + ; if igc -- generated
|
|
| 1346 | + then thing_inside
|
|
| 1347 | + else case e of
|
|
| 1348 | + -- The HsHole special case addresses situations like
|
|
| 1349 | + -- f x = _
|
|
| 1350 | + -- when we don't want to say "In the expression: _",
|
|
| 1351 | + -- because it is mentioned in the error message itself
|
|
| 1352 | + HsHole{} -> thing_inside
|
|
| 1353 | + |
|
| 1354 | + -- There is a special case for expressions with signatures to avoid having too verbose
|
|
| 1355 | + -- error context. c.f. RecordDotSyntaxFail9
|
|
| 1356 | + -- Add the original HsCtxt if we are typechecking an expanded expression
|
|
| 1357 | + ExprWithTySig _ (L _ e') _
|
|
| 1358 | + | XExpr (ExpandedThingRn o _) <- e' -> addErrCtxt o thing_inside
|
|
| 1359 | + XExpr (ExpandedThingRn o _) -> addErrCtxt o thing_inside
|
|
| 1360 | + |
|
| 1361 | + _ -> addErrCtxt (ExprCtxt e) thing_inside
|
|
| 1362 | + }
|
|
| 1359 | 1363 | |
| 1360 | 1364 | getErrCtxt :: TcM [ErrCtxt]
|
| 1361 | 1365 | getErrCtxt = do { env <- getLclEnv; return (getLclEnvErrCtxt env) }
|
| ... | ... | @@ -1369,11 +1373,6 @@ addErrCtxt :: HsCtxt -> TcM a -> TcM a |
| 1369 | 1373 | {-# INLINE addErrCtxt #-} -- Note [Inlining addErrCtxt]
|
| 1370 | 1374 | addErrCtxt ctxt = pushCtxt ctxt
|
| 1371 | 1375 | |
| 1372 | --- See Note [ErrCtxtStack Manipulation]
|
|
| 1373 | -addExpansionErrCtxt :: HsCtxt -> TcM a -> TcM a
|
|
| 1374 | -{-# INLINE addExpansionErrCtxt #-} -- Note [Inlining addErrCtxt]
|
|
| 1375 | -addExpansionErrCtxt ctxt thing_inside = setInGeneratedCode $ pushCtxt ctxt thing_inside
|
|
| 1376 | - |
|
| 1377 | 1376 | -- See Note [Rebindable syntax and XXExprGhcRn] in GHC.Hs.Expr
|
| 1378 | 1377 | pushCtxt :: ErrCtxt -> TcM a -> TcM a
|
| 1379 | 1378 | {-# INLINE pushCtxt #-} -- Note [Inlining addErrCtxt]
|
| ... | ... | @@ -105,7 +105,7 @@ import GHC.Types.Var.Set |
| 105 | 105 | import GHC.Types.Var.Env
|
| 106 | 106 | import GHC.Types.Basic
|
| 107 | 107 | import GHC.Types.Unique.Set (nonDetEltsUniqSet)
|
| 108 | -import GHC.Types.SrcLoc (unLoc)
|
|
| 108 | +import GHC.Types.SrcLoc (unLoc, GenLocated (..))
|
|
| 109 | 109 | |
| 110 | 110 | import GHC.Utils.Misc
|
| 111 | 111 | import GHC.Utils.Outputable as Outputable
|
| ... | ... | @@ -2047,7 +2047,7 @@ getDeepSubsumptionFlag_DataConHead app_head = |
| 2047 | 2047 | go app_head
|
| 2048 | 2048 | | XExpr (ConLikeTc (RealDataCon {})) <- app_head
|
| 2049 | 2049 | = Deep TopSub
|
| 2050 | - | XExpr (ExpandedThingTc _ f) <- app_head
|
|
| 2050 | + | XExpr (ExpandedThingTc _ (L _ f)) <- app_head
|
|
| 2051 | 2051 | = go f
|
| 2052 | 2052 | | XExpr (WrapExpr _ f) <- app_head
|
| 2053 | 2053 | = go f
|
| ... | ... | @@ -1096,7 +1096,7 @@ zonkExpr (XExpr (WrapExpr co_fn expr)) |
| 1096 | 1096 | return (XExpr (WrapExpr new_co_fn new_expr))
|
| 1097 | 1097 | |
| 1098 | 1098 | zonkExpr (XExpr (ExpandedThingTc thing e))
|
| 1099 | - = do e' <- zonkExpr e
|
|
| 1099 | + = do e' <- zonkLExpr e
|
|
| 1100 | 1100 | return $ XExpr (ExpandedThingTc thing e')
|
| 1101 | 1101 | |
| 1102 | 1102 | zonkExpr e@(XExpr (ConLikeTc {}))
|
| ... | ... | @@ -9,6 +9,7 @@ e/E.hs:(15,3)-(15,6): GHC.Internal.Types.Int -> GHC.Internal.Base.String |
| 9 | 9 | e/E.hs:(22,3)-(22,6): E.E -> GHC.Internal.Base.String
|
| 10 | 10 | e/E.hs:(25,3)-(25,10): GHC.Internal.Base.String -> GHC.Internal.Types.IO ()
|
| 11 | 11 | e/E.hs:(25,12)-(25,37): GHC.Internal.Base.String
|
| 12 | +e/E.hs:(25,3)-(25,37): GHC.Internal.Types.IO ()
|
|
| 12 | 13 | e/E.hs:(24,16)-(25,37): GHC.Internal.Types.IO ()
|
| 13 | 14 | e/E.hs:(19,9)-(19,9): E.E
|
| 14 | 15 | e/E.hs:(5,7)-(5,8): GHC.Internal.Bignum.Integer.Integer
|