Apoorv Ingle pushed to branch wip/ani/kill-SrcCodeOrigin at Glasgow Haskell Compiler / GHC

Commits:

18 changed files:

Changes:

  • compiler/GHC/Hs/Expr.hs
    ... ... @@ -34,6 +34,7 @@ import GHC.Parser.Annotation
    34 34
     
    
    35 35
     -- others:
    
    36 36
     import GHC.Tc.Types.Evidence
    
    37
    +import GHC.Tc.Types.ErrCtxt
    
    37 38
     import GHC.Types.Id.Info ( RecSelParent )
    
    38 39
     import GHC.Types.Name
    
    39 40
     import GHC.Types.Name.Reader
    
    ... ... @@ -658,16 +659,8 @@ type instance XXExpr GhcTc = XXExprGhcTc
    658 659
     *                                                                      *
    
    659 660
     ********************************************************************* -}
    
    660 661
     
    
    661
    --- | The different source constructs that we use to instantiate the "original" field
    
    662
    ---   in an `XXExprGhcRn original expansion`
    
    663
    ---   See Note [Handling overloaded and rebindable constructs] in `GHC.Rename.Expr`
    
    664
    -data SrcCodeOrigin
    
    665
    -  = OrigExpr (HsExpr GhcRn)                -- ^ The source, user written, expression
    
    666
    -  | OrigStmt (ExprLStmt GhcRn) HsDoFlavour -- ^ which kind of do-block did this statement come from
    
    667
    -  | OrigPat  (ExprLStmt GhcRn) (Pat GhcRn) -- ^ Used for failable patterns that trigger MonadFail constraints
    
    668
    -
    
    669 662
     data XXExprGhcRn
    
    670
    -  = ExpandedThingRn { xrn_orig     :: SrcCodeOrigin   -- The original source thing to be used for error messages
    
    663
    +  = ExpandedThingRn { xrn_orig     :: ErrCtxtMsg         -- The original source thing context to be used for error messages
    
    671 664
                         , xrn_expanded :: HsExpr GhcRn    -- The compiler generated, expanded thing
    
    672 665
                         }
    
    673 666
     
    
    ... ... @@ -679,21 +672,21 @@ data XXExprGhcRn
    679 672
     --   and the two components of the expansion: original expression and
    
    680 673
     --   expanded expressions.
    
    681 674
     mkExpandedExpr
    
    682
    -  :: HsExpr GhcRn         -- ^ source expression
    
    675
    +  :: HsExpr GhcRn         -- ^ source expression context
    
    683 676
       -> HsExpr GhcRn         -- ^ expanded expression
    
    684 677
       -> HsExpr GhcRn         -- ^ suitably wrapped 'XXExprGhcRn'
    
    685
    -mkExpandedExpr oExpr eExpr = XExpr (ExpandedThingRn { xrn_orig = OrigExpr oExpr
    
    678
    +mkExpandedExpr oExpr eExpr = XExpr (ExpandedThingRn { xrn_orig = ExprCtxt oExpr
    
    686 679
                                                         , xrn_expanded = eExpr })
    
    687 680
     
    
    688 681
     -- | Build an expression using the extension constructor `XExpr`,
    
    689 682
     --   and the two components of the expansion: original do stmt and
    
    690 683
     --   expanded expression
    
    691 684
     mkExpandedStmt
    
    692
    -  :: ExprLStmt GhcRn      -- ^ source statement
    
    693
    -  -> HsDoFlavour          -- ^ source statement do flavour
    
    685
    +  :: ExprLStmt GhcRn      -- ^ source statement context
    
    686
    +  -> HsDoFlavour          -- ^ source statements do flavour
    
    694 687
       -> HsExpr GhcRn         -- ^ expanded expression
    
    695 688
       -> HsExpr GhcRn         -- ^ suitably wrapped 'XXExprGhcRn'
    
    696
    -mkExpandedStmt oStmt flav eExpr = XExpr (ExpandedThingRn { xrn_orig = OrigStmt oStmt flav
    
    689
    +mkExpandedStmt oStmt flav eExpr = XExpr (ExpandedThingRn { xrn_orig = StmtErrCtxt (HsDoStmt flav) oStmt
    
    697 690
                                                              , xrn_expanded = eExpr })
    
    698 691
     
    
    699 692
     data XXExprGhcTc
    
    ... ... @@ -702,7 +695,7 @@ data XXExprGhcTc
    702 695
     
    
    703 696
       | ExpandedThingTc                         -- See Note [Rebindable syntax and XXExprGhcRn]
    
    704 697
                                                 -- See Note [Expanding HsDo with XXExprGhcRn] in `GHC.Tc.Gen.Do`
    
    705
    -         { xtc_orig     :: SrcCodeOrigin        -- The original user written thing
    
    698
    +         { xtc_orig     :: ErrCtxtMsg        -- The original user written thing
    
    706 699
              , xtc_expanded :: HsExpr GhcTc }   -- The expanded typechecked expression
    
    707 700
     
    
    708 701
       | ConLikeTc
    
    ... ... @@ -736,10 +729,10 @@ mkExpandedExprTc
    736 729
       :: HsExpr GhcRn           -- ^ source expression
    
    737 730
       -> HsExpr GhcTc           -- ^ expanded typechecked expression
    
    738 731
       -> HsExpr GhcTc           -- ^ suitably wrapped 'XXExprGhcRn'
    
    739
    -mkExpandedExprTc oExpr eExpr = mkExpandedTc (OrigExpr oExpr) eExpr
    
    732
    +mkExpandedExprTc oExpr eExpr = mkExpandedTc (ExprCtxt oExpr) eExpr
    
    740 733
     
    
    741 734
     mkExpandedTc
    
    742
    -  :: SrcCodeOrigin          -- ^ source, user written do statement/expression
    
    735
    +  :: ErrCtxtMsg          -- ^ source, user written do statement/expression
    
    743 736
       -> HsExpr GhcTc           -- ^ expanded typechecked expression
    
    744 737
       -> HsExpr GhcTc           -- ^ suitably wrapped 'XXExprGhcRn'
    
    745 738
     mkExpandedTc o e = XExpr (ExpandedThingTc o e)
    
    ... ... @@ -1060,24 +1053,32 @@ ppr_expr (XExpr x) = case ghcPass @p of
    1060 1053
       GhcRn -> ppr x
    
    1061 1054
       GhcTc -> ppr x
    
    1062 1055
     
    
    1063
    -instance Outputable SrcCodeOrigin where
    
    1064
    -  ppr thing
    
    1065
    -    = case thing of
    
    1066
    -        OrigExpr x    -> ppr_builder "<OrigExpr>:" x
    
    1067
    -        OrigStmt x _  -> ppr_builder "<OrigStmt>:" x
    
    1068
    -        OrigPat  _ x  -> ppr_builder "<OrigPat>:" x
    
    1069
    -    where ppr_builder prefix x = ifPprDebug (braces (text prefix <+> parens (ppr x))) (ppr x)
    
    1070
    -
    
    1071 1056
     instance Outputable XXExprGhcRn where
    
    1072
    -  ppr (ExpandedThingRn o e) = ifPprDebug (braces $ vcat [ppr o, text ";;" , ppr e]) (ppr o)
    
    1073 1057
       ppr (HsRecSelRn f)        = pprPrefixOcc f
    
    1058
    +  ppr (ExpandedThingRn o e) = ifPprDebug (braces $ vcat [pprCtxt o, text ";;" , ppr e]) (pprCtxt o)
    
    1059
    +    where
    
    1060
    +      ppr_builder prefix x = ifPprDebug (braces (text prefix <+> parens x)) x
    
    1061
    +      pprCtxt :: ErrCtxtMsg -> SDoc
    
    1062
    +      pprCtxt (ExprCtxt e) = ppr_builder "<OrigExpr>:"  (ppr e)
    
    1063
    +      pprCtxt (StmtErrCtxt _ stmt) = ppr_builder "<OrigStmt>:" (ppr stmt)
    
    1064
    +      pprCtxt (StmtErrCtxtPat _ _ pat) = ppr_builder "<OrigPat>:" (ppr pat)
    
    1065
    +      pprCtxt _ = empty
    
    1074 1066
     
    
    1075 1067
     instance Outputable XXExprGhcTc where
    
    1076 1068
       ppr (WrapExpr co_fn e)
    
    1077 1069
         = pprHsWrapper co_fn (\_parens -> pprExpr e)
    
    1078 1070
     
    
    1079 1071
       ppr (ExpandedThingTc o e)
    
    1080
    -    = ifPprDebug (braces $ vcat [ppr o, ppr e]) (ppr o)
    
    1072
    +    = ifPprDebug (braces $ vcat [pprCtxt o, ppr e]) (pprCtxt o)
    
    1073
    +
    
    1074
    +    where
    
    1075
    +      ppr_builder prefix x = ifPprDebug (braces (text prefix <+> parens x)) x
    
    1076
    +      pprCtxt :: ErrCtxtMsg -> SDoc
    
    1077
    +      pprCtxt (ExprCtxt e) = ppr_builder "<OrigExpr>:"  (ppr e)
    
    1078
    +      pprCtxt (StmtErrCtxt _ stmt) = ppr_builder "<OrigStmt>:" (ppr stmt)
    
    1079
    +      pprCtxt (StmtErrCtxtPat _ _ pat) = ppr_builder "<OrigPat>:" (ppr pat)
    
    1080
    +      pprCtxt _ = empty
    
    1081
    +
    
    1081 1082
                 -- e is the expanded expression, we print the original
    
    1082 1083
                 -- expression (HsExpr GhcRn), not the
    
    1083 1084
                 -- expanded typechecked one (HsExpr GhcTc),
    
    ... ... @@ -1125,8 +1126,8 @@ ppr_infix_expr_tc (HsTick {}) = Nothing
    1125 1126
     ppr_infix_expr_tc (HsBinTick {})             = Nothing
    
    1126 1127
     ppr_infix_expr_tc (HsRecSelTc f)            = Just (pprInfixOcc f)
    
    1127 1128
     
    
    1128
    -ppr_infix_hs_expansion :: SrcCodeOrigin -> Maybe SDoc
    
    1129
    -ppr_infix_hs_expansion (OrigExpr e) = ppr_infix_expr e
    
    1129
    +ppr_infix_hs_expansion :: ErrCtxtMsg -> Maybe SDoc
    
    1130
    +ppr_infix_hs_expansion (ExprCtxt e) = ppr_infix_expr e
    
    1130 1131
     ppr_infix_hs_expansion _            = Nothing
    
    1131 1132
     
    
    1132 1133
     pprDebugParendExpr :: (OutputableBndrId p)
    
    ... ... @@ -1216,8 +1217,8 @@ hsExprNeedsParens prec = go
    1216 1217
         go_x_rn (ExpandedThingRn thing _ )   = hsExpandedNeedsParens thing
    
    1217 1218
         go_x_rn (HsRecSelRn{})               = False
    
    1218 1219
     
    
    1219
    -    hsExpandedNeedsParens :: SrcCodeOrigin -> Bool
    
    1220
    -    hsExpandedNeedsParens (OrigExpr e) = hsExprNeedsParens prec e
    
    1220
    +    hsExpandedNeedsParens :: ErrCtxtMsg -> Bool
    
    1221
    +    hsExpandedNeedsParens (ExprCtxt e) = hsExprNeedsParens prec e
    
    1221 1222
         hsExpandedNeedsParens _            = False
    
    1222 1223
     
    
    1223 1224
     -- | Parenthesize an expression without token information
    
    ... ... @@ -1268,8 +1269,8 @@ isAtomicHsExpr (XExpr x)
    1268 1269
         go_x_rn (ExpandedThingRn thing _)   = isAtomicExpandedThingRn thing
    
    1269 1270
         go_x_rn (HsRecSelRn{})              = True
    
    1270 1271
     
    
    1271
    -    isAtomicExpandedThingRn :: SrcCodeOrigin -> Bool
    
    1272
    -    isAtomicExpandedThingRn (OrigExpr e) = isAtomicHsExpr e
    
    1272
    +    isAtomicExpandedThingRn :: ErrCtxtMsg -> Bool
    
    1273
    +    isAtomicExpandedThingRn (ExprCtxt e) = isAtomicHsExpr e
    
    1273 1274
         isAtomicExpandedThingRn _            = False
    
    1274 1275
     
    
    1275 1276
     isAtomicHsExpr _ = False
    

  • compiler/GHC/Hs/Expr.hs-boot
    ... ... @@ -15,8 +15,11 @@ import Language.Haskell.Syntax.Expr
    15 15
       , GRHSs
    
    16 16
       , HsUntypedSplice
    
    17 17
       , HsTypedSplice
    
    18
    +  , HsMatchContext
    
    19
    +  , HsStmtContext
    
    18 20
       )
    
    19
    -import GHC.Hs.Extension ( OutputableBndrId, GhcPass )
    
    21
    +import Language.Haskell.Syntax.Extension (LIdP)
    
    22
    +import GHC.Hs.Extension ( OutputableBndrId, GhcPass, GhcRn)
    
    20 23
     import GHC.Types.Name   ( Name )
    
    21 24
     import Data.Bool  ( Bool )
    
    22 25
     import Data.Maybe ( Maybe )
    
    ... ... @@ -48,3 +51,6 @@ data HsUntypedSpliceResult thing
    48 51
           , utsplice_result            :: thing
    
    49 52
           }
    
    50 53
       | HsUntypedSpliceNested SplicePointName
    
    54
    +
    
    55
    +type HsMatchContextRn = HsMatchContext (LIdP GhcRn)
    
    56
    +type HsStmtContextRn = HsStmtContext (LIdP GhcRn)

  • compiler/GHC/Hs/Instances.hs
    ... ... @@ -36,6 +36,7 @@ import Language.Haskell.Syntax.Decls
    36 36
     import Language.Haskell.Syntax.Decls.Overlap (OverlapMode(..))
    
    37 37
     import Language.Haskell.Syntax.Extension (Anno)
    
    38 38
     import Language.Haskell.Syntax.Binds.InlinePragma (ActivationX(..), InlinePragma(..))
    
    39
    +import GHC.Tc.Types.ErrCtxt
    
    39 40
     
    
    40 41
     -- ---------------------------------------------------------------------
    
    41 42
     -- Data derivations from GHC.Hs-----------------------------------------
    
    ... ... @@ -619,7 +620,7 @@ deriving instance Eq (IE GhcTc)
    619 620
     
    
    620 621
     -- ---------------------------------------------------------------------
    
    621 622
     
    
    622
    -deriving instance Data SrcCodeOrigin
    
    623
    +deriving instance Data ErrCtxtMsg
    
    623 624
     deriving instance Data XXExprGhcRn
    
    624 625
     deriving instance Data a => Data (WithUserRdr a)
    
    625 626
     
    

  • compiler/GHC/Tc/Errors.hs
    ... ... @@ -2778,7 +2778,7 @@ isHasFieldOrigin = \case
    2778 2778
       RecordUpdOrigin {} -> True
    
    2779 2779
       RecordFieldProjectionOrigin {} -> True
    
    2780 2780
       GetFieldOrigin {} -> True
    
    2781
    -  ExpansionOrigin (OrigExpr e)
    
    2781
    +  ExpansionOrigin (ExprCtxt e)
    
    2782 2782
         | HsGetField{} <- e -> True
    
    2783 2783
         | RecordUpd{} <- e -> True
    
    2784 2784
         | HsProjection{} <- e -> True
    

  • compiler/GHC/Tc/Errors/Ppr.hs
    ... ... @@ -68,11 +68,11 @@ import GHC.Core.FVs( orphNamesOfTypes )
    68 68
     import GHC.CoreToIface
    
    69 69
     
    
    70 70
     import GHC.Driver.Flags
    
    71
    -import GHC.Driver.Backend
    
    71
    +-- import GHC.Driver.Backend
    
    72 72
     import GHC.Hs hiding (HoleError)
    
    73 73
     import GHC.Hs.Decls.Overlap
    
    74 74
     
    
    75
    -import GHC.Tc.Errors.Types
    
    75
    +-- import GHC.Tc.Errors.Types
    
    76 76
     import GHC.Tc.Errors.Types.PromotionErr (pprTermLevelUseCtxt)
    
    77 77
     import GHC.Tc.Errors.Hole.FitTypes
    
    78 78
     import GHC.Tc.Types.BasicTypes
    
    ... ... @@ -109,7 +109,7 @@ import GHC.Iface.Errors.Types
    109 109
     import GHC.Iface.Errors.Ppr
    
    110 110
     import GHC.Iface.Syntax
    
    111 111
     
    
    112
    -import GHC.Unit.State
    
    112
    +-- import GHC.Unit.State
    
    113 113
     import GHC.Unit.Module
    
    114 114
     
    
    115 115
     import GHC.Data.Bag
    

  • compiler/GHC/Tc/Gen/App.hs
    ... ... @@ -909,7 +909,7 @@ tcInstFun do_ql inst_final ds_flag (fun_orig, rn_fun, fun_lspan) tc_fun fun_sigm
    909 909
         mk_herald :: HsExpr GhcTc -> HsExpr GhcRn -> CtOrigin
    
    910 910
         mk_herald tc_fun arg
    
    911 911
           = case fun_orig of
    
    912
    -           ExpansionOrigin (OrigStmt{}) -> ExpectedTySyntax DoStmtOrigin arg
    
    912
    +           ExpansionOrigin (StmtErrCtxt{}) -> ExpectedTySyntax DoStmtOrigin arg
    
    913 913
                _ -> ExpectedFunTyArg (HsExprTcThing tc_fun) arg
    
    914 914
     
    
    915 915
     -- Is the argument supposed to instantiate a forall?
    
    ... ... @@ -1258,7 +1258,7 @@ expr_to_type earg =
    1258 1258
           | otherwise = not_in_scope
    
    1259 1259
           where occ = occName rdr
    
    1260 1260
                 not_in_scope = failWith $ TcRnNotInScope NotInScope rdr
    
    1261
    -    go (L l (XExpr (ExpandedThingRn (OrigExpr orig) _))) =
    
    1261
    +    go (L l (XExpr (ExpandedThingRn (ExprCtxt orig) _))) =
    
    1262 1262
           -- Use the original, user-written expression (before expansion).
    
    1263 1263
           -- Example. Say we have   vfun :: forall a -> blah
    
    1264 1264
           --          and the call  vfun (Maybe [1,2,3])
    

  • compiler/GHC/Tc/Gen/Do.hs
    ... ... @@ -482,4 +482,6 @@ It stores the original statement (with location) and the expanded expression
    482 482
     
    
    483 483
     
    
    484 484
     mkExpandedPatRn :: Pat GhcRn -> ExprLStmt GhcRn -> HsExpr GhcRn -> HsExpr GhcRn
    
    485
    -mkExpandedPatRn pat stmt e = XExpr (ExpandedThingRn (OrigPat stmt pat) e)
    485
    +mkExpandedPatRn oflav pat stmt e = XExpr $ ExpandedThingRn
    
    486
    +                                   { xrn_orig = StmtErrCtxtPat (HsDoStmt flav) stmt pat
    
    487
    +                                   , xrn_expand = e}

  • compiler/GHC/Tc/Gen/Expr.hs
    ... ... @@ -676,7 +676,7 @@ tcExpr expr@(RecordUpd { rupd_expr = record_expr
    676 676
     
    
    677 677
             ; (ds_expr, ds_res_ty, err_msg)
    
    678 678
                 <- expandRecordUpd record_expr possible_parents rbnds res_ty
    
    679
    -        ; addExpansionErrCtxt (OrigExpr expr) err_msg $
    
    679
    +        ; addExpansionErrCtxt (ExprCtxt expr) err_msg $
    
    680 680
               do { -- Typecheck the expanded expression.
    
    681 681
                    expr' <- tcExpr ds_expr (Check ds_res_ty)
    
    682 682
                    -- NB: it's important to use ds_res_ty and not res_ty here.
    

  • compiler/GHC/Tc/Instance/Class.hs
    ... ... @@ -1287,7 +1287,7 @@ warnIncompleteRecSel dflags sel_id ct_loc
    1287 1287
     
    
    1288 1288
         -- GHC.Tc.Gen.App.tcInstFun arranges that the CtOrigin of (r.x) is GetFieldOrigin,
    
    1289 1289
         -- despite the expansion to (getField @"x" r)
    
    1290
    -    isGetFieldOrigin (ExpansionOrigin (OrigExpr (HsGetField {}))) = True
    
    1290
    +    isGetFieldOrigin (ExpansionOrigin (ExprCtxt (HsGetField {}))) = True
    
    1291 1291
         isGetFieldOrigin _                   = False
    
    1292 1292
     
    
    1293 1293
     lookupHasFieldLabel
    

  • compiler/GHC/Tc/Types/ErrCtxt.hs
    1 1
     {-# LANGUAGE UndecidableInstances #-}
    
    2 2
     
    
    3 3
     module GHC.Tc.Types.ErrCtxt
    
    4
    -  ( ErrCtxt (..), ErrCtxtMsg(..), ErrCtxtMsgM,  CodeSrcFlag (..), srcCodeOriginErrCtxMsg
    
    4
    +  ( ErrCtxt (..), ErrCtxtMsg(..), CodeSrcFlag (..)
    
    5 5
       , UserSigType(..), FunAppCtxtFunArg(..)
    
    6 6
       , TyConInstFlavour(..)
    
    7 7
       )
    
    8 8
       where
    
    9 9
     
    
    10 10
     import GHC.Prelude
    
    11
    -import GHC.Hs.Expr
    
    11
    +import {-# SOURCE #-} GHC.Hs.Expr (SplicePointName, HsMatchContextRn, HsStmtContextRn)
    
    12
    +import {-# SOURCE #-} GHC.Hs.Expr () -- for outputable instances
    
    13
    +import GHC.Hs.Type () -- for outputable instances
    
    12 14
     import GHC.Hs.Extension
    
    13 15
     
    
    14 16
     import GHC.Parser.Annotation ( LocatedN, SrcSpanAnnA )
    
    15 17
     
    
    16 18
     import GHC.Tc.Errors.Types.PromotionErr ( TermLevelUseCtxt )
    
    17
    -import GHC.Tc.Types.Origin   ( CtOrigin, UserTypeCtxt )
    
    18
    -import GHC.Tc.Utils.TcType   ( TcType, TcTyCon )
    
    19
    -import GHC.Tc.Zonk.Monad     ( ZonkM )
    
    19
    +import {-# SOURCE #-} GHC.Tc.Types.Origin   ( CtOrigin, UserTypeCtxt )
    
    20
    +import {-# SOURCE #-} GHC.Tc.Utils.TcType   ( TcType, TcTyCon )
    
    20 21
     
    
    21 22
     import GHC.Types.Basic       ( TyConFlavour )
    
    22 23
     import GHC.Types.Name        ( Name )
    
    23
    -import GHC.Types.SrcLoc      ( SrcSpan, unLoc )
    
    24
    +import GHC.Types.SrcLoc      ( SrcSpan )
    
    24 25
     import GHC.Types.Var         ( Id, TyCoVar )
    
    25
    -import GHC.Types.Var.Env     ( TidyEnv )
    
    26 26
     
    
    27 27
     import GHC.Unit.Types ( Module, InstantiatedModule )
    
    28 28
     
    
    ... ... @@ -32,7 +32,7 @@ import GHC.Core.PatSyn ( PatSyn )
    32 32
     import GHC.Core.TyCon    ( TyCon )
    
    33 33
     import GHC.Core.TyCo.Rep ( Type, ThetaType, PredType )
    
    34 34
     
    
    35
    -import GHC.Unit.State ( UnitState )
    
    35
    +import {-# SOURCE #-} GHC.Unit.State ( UnitState ) -- Break the module graph cycle for accesing ErrCtxtMsg in GHC.Hs.Expr
    
    36 36
     
    
    37 37
     import GHC.Data.FastString  ( FastString )
    
    38 38
     import GHC.Utils.Outputable ( Outputable(..) )
    
    ... ... @@ -45,7 +45,7 @@ import qualified Data.List.NonEmpty as NE
    45 45
     
    
    46 46
     --------------------------------------------------------------------------------
    
    47 47
     
    
    48
    -type ErrCtxtMsgM = TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg)
    
    48
    +-- type ErrCtxtMsgM = TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg)
    
    49 49
     
    
    50 50
     -- | Additional context to include in an error message, e.g.
    
    51 51
     -- "In the type signature ...", "In the ambiguity check for ...", etc.
    
    ... ... @@ -55,7 +55,7 @@ data ErrCtxt = MkErrCtxt
    55 55
                      -- LandmarkUserSrcCode <=> this is a landmark context; do not
    
    56 56
                      --                         discard it when trimming for display
    
    57 57
     
    
    58
    -                 ErrCtxtMsgM
    
    58
    +                 ErrCtxtMsg
    
    59 59
                      -- Monadic so that we have a chance
    
    60 60
                      -- to deal with bound type variables just before error
    
    61 61
                      -- message construction
    
    ... ... @@ -63,19 +63,20 @@ data ErrCtxt = MkErrCtxt
    63 63
     
    
    64 64
     data CodeSrcFlag = VanillaUserSrcCode
    
    65 65
                      | LandmarkUserSrcCode
    
    66
    -                 | ExpansionCodeCtxt SrcCodeOrigin
    
    66
    +                 | ExpansionCodeCtxt
    
    67 67
     
    
    68 68
     --------------------------------------------------------------------------------
    
    69 69
     -- Error message contexts
    
    70 70
     
    
    71
    -data UserSigType p
    
    72
    -  = UserLHsSigType !(LHsSigType p)
    
    73
    -  | UserLHsType !(LHsType p)
    
    71
    +data UserSigType
    
    72
    +  = UserLHsSigType !(LHsSigType GhcRn)
    
    73
    +  | UserLHsType !(LHsType GhcRn)
    
    74 74
     
    
    75
    -instance OutputableBndrId p => Outputable (UserSigType (GhcPass p)) where
    
    75
    +instance Outputable UserSigType where
    
    76 76
       ppr (UserLHsSigType ty) = ppr ty
    
    77 77
       ppr (UserLHsType ty) = ppr ty
    
    78 78
     
    
    79
    +
    
    79 80
     data FunAppCtxtFunArg
    
    80 81
       = FunAppCtxtExpr !(HsExpr GhcRn) !(HsExpr GhcRn)
    
    81 82
       | FunAppCtxtTy   !(LHsType GhcRn) !(LHsType GhcRn)
    
    ... ... @@ -104,7 +105,7 @@ data ErrCtxtMsg
    104 105
       -- or a type signature, or... (see 'Sig').
    
    105 106
       | SigCtxt !(Sig GhcRn)
    
    106 107
       -- | In a user-written type signature.
    
    107
    -  | UserSigCtxt !UserTypeCtxt !(UserSigType GhcRn)
    
    108
    +  | UserSigCtxt !UserTypeCtxt !UserSigType
    
    108 109
       -- | In a record update.
    
    109 110
       | RecordUpdCtxt !(NE.NonEmpty ConLike) ![Name] ![TyCoVar]
    
    110 111
       -- | In a class method.
    
    ... ... @@ -175,10 +176,10 @@ data ErrCtxtMsg
    175 176
       | VDQWarningCtxt !TcTyCon
    
    176 177
     
    
    177 178
       -- | In a statement.
    
    178
    -  | forall body.
    
    179
    -    ( Anno (StmtLR GhcRn GhcRn body) ~ SrcSpanAnnA
    
    180
    -    , Outputable body
    
    181
    -    ) => StmtErrCtxt !HsStmtContextRn !(StmtLR GhcRn GhcRn body)
    
    179
    +  | StmtErrCtxt !HsStmtContextRn !(ExprLStmt GhcRn)
    
    180
    +
    
    181
    +  -- | In patten of the statement. (c.f. MonadFailErrors)
    
    182
    +  | StmtErrCtxtPat !HsStmtContextRn !(ExprLStmt GhcRn) (Pat GhcRn)
    
    182 183
     
    
    183 184
       -- | In an rebindable syntax expression.
    
    184 185
       | SyntaxNameCtxt !(HsExpr GhcRn) !CtOrigin !TcType !SrcSpan
    
    ... ... @@ -228,9 +229,3 @@ data ErrCtxtMsg
    228 229
       | MergeSignaturesCtxt !UnitState !ModuleName ![InstantiatedModule]
    
    229 230
       -- | While checking that a module implements a Backpack signature.
    
    230 231
       | CheckImplementsCtxt !UnitState !Module !InstantiatedModule
    231
    -
    
    232
    -
    
    233
    -srcCodeOriginErrCtxMsg :: SrcCodeOrigin -> ErrCtxtMsg
    
    234
    -srcCodeOriginErrCtxMsg (OrigExpr e) = ExprCtxt e
    
    235
    -srcCodeOriginErrCtxMsg (OrigStmt s f) = StmtErrCtxt (HsDoStmt f) (unLoc s)
    
    236
    -srcCodeOriginErrCtxMsg (OrigPat s _) = StmtErrCtxt (HsDoStmt (DoExpr Nothing)) (unLoc s)

  • compiler/GHC/Tc/Types/LclEnv.hs
    ... ... @@ -213,7 +213,7 @@ setLclEnvSrcCodeOrigin ec = modifyLclCtxt (setLclCtxtSrcCodeOrigin ec)
    213 213
     setLclCtxtSrcCodeOrigin :: ErrCtxt -> TcLclCtxt -> TcLclCtxt
    
    214 214
     setLclCtxtSrcCodeOrigin ec lclCtxt
    
    215 215
       | ecs@(MkErrCtxt (ExpansionCodeCtxt{}) _ : _) <- tcl_err_ctxt lclCtxt
    
    216
    -  , MkErrCtxt (ExpansionCodeCtxt OrigExpr{}) _ <- ec
    
    216
    +  , MkErrCtxt (ExpansionCodeCtxt ExprCtxt{}) _ <- ec
    
    217 217
       = lclCtxt { tcl_err_ctxt =  ec : ecs }
    
    218 218
       | MkErrCtxt (ExpansionCodeCtxt{}) _ : ecs <- tcl_err_ctxt lclCtxt
    
    219 219
       , MkErrCtxt (ExpansionCodeCtxt{}) _ <- ec
    

  • compiler/GHC/Tc/Types/Origin.hs
    ... ... @@ -654,7 +654,7 @@ data CtOrigin
    654 654
       | AmbiguityCheckOrigin UserTypeCtxt
    
    655 655
       | ImplicitLiftOrigin HsImplicitLiftSplice
    
    656 656
     
    
    657
    -  | ExpansionOrigin SrcCodeOrigin -- This is due to an expansion of the original thing given by SrcCodeOrigin
    
    657
    +  | ExpansionOrigin ErrCtxtMsg -- This is due to an expansion of the original thing given by the ErrCtxtMsg
    
    658 658
     
    
    659 659
       | ExpectedTySyntax !CtOrigin (HsExpr GhcRn)
    
    660 660
     
    
    ... ... @@ -828,11 +828,11 @@ exprCtOrigin (HsHole _) = Shouldn'tHappenOrigin "hole expression"
    828 828
     exprCtOrigin (HsForAll {})       = Shouldn'tHappenOrigin "forall telescope"    -- See Note [Types in terms]
    
    829 829
     exprCtOrigin (HsQual {})         = Shouldn'tHappenOrigin "constraint context"  -- See Note [Types in terms]
    
    830 830
     exprCtOrigin (HsFunArr {})       = Shouldn'tHappenOrigin "function arrow"      -- See Note [Types in terms]
    
    831
    -exprCtOrigin e@(ExplicitList {})  = ExpansionOrigin (OrigExpr e)
    
    832
    -exprCtOrigin e@(HsIf {})          = ExpansionOrigin (OrigExpr e)
    
    833
    -exprCtOrigin e@(HsProjection _ _) = ExpansionOrigin (OrigExpr e)
    
    834
    -exprCtOrigin e@(RecordUpd{})      = ExpansionOrigin (OrigExpr e)
    
    835
    -exprCtOrigin e@(HsGetField{})     = ExpansionOrigin (OrigExpr e)
    
    831
    +exprCtOrigin e@(ExplicitList {})  = ExpansionOrigin (ExprCtxt e)
    
    832
    +exprCtOrigin e@(HsIf {})          = ExpansionOrigin (ExprCtxt e)
    
    833
    +exprCtOrigin e@(HsProjection _ _) = ExpansionOrigin (ExprCtxt e)
    
    834
    +exprCtOrigin e@(RecordUpd{})      = ExpansionOrigin (ExprCtxt e)
    
    835
    +exprCtOrigin e@(HsGetField{})     = ExpansionOrigin (ExprCtxt e)
    
    836 836
     exprCtOrigin (XExpr (ExpandedThingRn o _)) = ExpansionOrigin o
    
    837 837
     exprCtOrigin (XExpr (HsRecSelRn f))  = OccurrenceOfRecSel $ L (getLoc $ foLabel f) (foExt f)
    
    838 838
     
    
    ... ... @@ -872,21 +872,21 @@ pprCtOrigin (ExpansionOrigin o)
    872 872
         where
    
    873 873
           what :: SDoc
    
    874 874
           what = case o of
    
    875
    -        OrigStmt{} ->
    
    875
    +        StmtErrCtxt{} ->
    
    876 876
               text "a do statement"
    
    877
    -        OrigPat _ p ->
    
    877
    +        StmtErrCtxtPat _ p ->
    
    878 878
               text "a do statement" $$
    
    879 879
                  text "with the failable pattern" <+> quotes (ppr p)
    
    880
    -        OrigExpr (HsGetField _ _ (L _ f)) ->
    
    880
    +        ExprCtxt (HsGetField _ _ (L _ f)) ->
    
    881 881
               hsep [text "selecting the field", quotes (ppr f)]
    
    882
    -        OrigExpr (HsOverLabel _ l) ->
    
    882
    +        ExprCtxt (HsOverLabel _ l) ->
    
    883 883
               hsep [text "the overloaded label" , quotes (char '#' <> ppr l)]
    
    884
    -        OrigExpr (RecordUpd{}) -> text "a record update"
    
    885
    -        OrigExpr (ExplicitList{}) -> text "an overloaded list"
    
    886
    -        OrigExpr (HsIf{}) -> text "an if-then-else expression"
    
    887
    -        OrigExpr (HsProjection _ p) -> text "the record selector" <+>
    
    884
    +        ExprCtxt (RecordUpd{}) -> text "a record update"
    
    885
    +        ExprCtxt (ExplicitList{}) -> text "an overloaded list"
    
    886
    +        ExprCtxt (HsIf{}) -> text "an if-then-else expression"
    
    887
    +        ExprCtxt (HsProjection _ p) -> text "the record selector" <+>
    
    888 888
                  quotes (ppr ((FieldLabelStrings $ fmap noLocA p)))
    
    889
    -        OrigExpr e -> text "the expression" <+> (ppr e)
    
    889
    +        ExprCtxt e -> text "the expression" <+> (ppr e)
    
    890 890
     
    
    891 891
     pprCtOrigin (GivenSCOrigin sk d blk)
    
    892 892
       = vcat [ ctoHerald <+> pprSkolInfo sk
    
    ... ... @@ -1105,13 +1105,13 @@ ppr_br (InstanceSigOrigin {}) = text "a type signature in an instance"
    1105 1105
     ppr_br (AmbiguityCheckOrigin {})    = text "a type ambiguity check"
    
    1106 1106
     ppr_br (ImpedanceMatching {})       = text "combining required constraints"
    
    1107 1107
     ppr_br (NonLinearPatternOrigin _ pat) = hsep [text "a non-linear pattern" <+> quotes (ppr pat)]
    
    1108
    -ppr_br (ExpansionOrigin (OrigExpr (HsOverLabel _ l))) = hsep [text "the overloaded label", quotes (char '#' <> ppr l)]
    
    1109
    -ppr_br (ExpansionOrigin (OrigExpr (RecordUpd{}))) = text "a record update"
    
    1110
    -ppr_br (ExpansionOrigin (OrigExpr (ExplicitList{}))) = text "an overloaded list"
    
    1111
    -ppr_br (ExpansionOrigin (OrigExpr (HsIf{}))) = text "an if-then-else expression"
    
    1112
    -ppr_br (ExpansionOrigin (OrigExpr e)) = text "an expression" <+> ppr e
    
    1113
    -ppr_br (ExpansionOrigin (OrigStmt{})) = text "a do statement"
    
    1114
    -ppr_br (ExpansionOrigin (OrigPat{})) = text "a do statement"
    
    1108
    +ppr_br (ExpansionOrigin (ExprCtxt (HsOverLabel _ l))) = hsep [text "the overloaded label", quotes (char '#' <> ppr l)]
    
    1109
    +ppr_br (ExpansionOrigin (ExprCtxt (RecordUpd{}))) = text "a record update"
    
    1110
    +ppr_br (ExpansionOrigin (ExprCtxt (ExplicitList{}))) = text "an overloaded list"
    
    1111
    +ppr_br (ExpansionOrigin (ExprCtxt (HsIf{}))) = text "an if-then-else expression"
    
    1112
    +ppr_br (ExpansionOrigin (ExprCtxt e)) = text "an expression" <+> ppr e
    
    1113
    +ppr_br (ExpansionOrigin (StmtErrCtxt{})) = text "a do statement"
    
    1114
    +ppr_br (ExpansionOrigin (StmtErrCtxtPat{})) = text "a do statement"
    
    1115 1115
     ppr_br (ExpectedTySyntax o _) = ppr_br o
    
    1116 1116
     ppr_br (ExpectedFunTySyntaxOp{}) = text "a rebindable syntax operator"
    
    1117 1117
     ppr_br (ExpectedFunTyViewPat{}) = text "a view pattern"
    

  • compiler/GHC/Tc/Types/Origin.hs-boot
    ... ... @@ -4,6 +4,8 @@ import GHC.Prelude.Basic ( Int, Maybe )
    4 4
     import GHC.Utils.Misc ( HasDebugCallStack )
    
    5 5
     import {-# SOURCE #-} GHC.Core.TyCo.Rep ( Type )
    
    6 6
     
    
    7
    +data CtOrigin
    
    8
    +data UserTypeCtxt
    
    7 9
     data SkolemInfoAnon
    
    8 10
     data SkolemInfo
    
    9 11
     data FixedRuntimeRepContext
    

  • compiler/GHC/Tc/Utils/Monad.hs
    ... ... @@ -1346,12 +1346,12 @@ add_expr_ctxt e thing_inside
    1346 1346
        -- because it is mentioned in the error message itself
    
    1347 1347
     
    
    1348 1348
           ExprWithTySig _ (L _ e') _
    
    1349
    -        | XExpr (ExpandedThingRn o _) <- e' -> addExpansionErrCtxt o (ExprCtxt e) thing_inside
    
    1349
    +        | XExpr (ExpandedThingRn o _) <- e' -> addExpansionErrCtxt o thing_inside
    
    1350 1350
        -- There is a special case for expressions with signatures to avoid having too verbose
    
    1351 1351
        -- error context. So here we flip the ErrCtxt state to expanded if the expression is expanded.
    
    1352 1352
        -- c.f. RecordDotSyntaxFail9
    
    1353 1353
     
    
    1354
    -      XExpr (ExpandedThingRn o _) -> addExpansionErrCtxt o (srcCodeOriginErrCtxMsg o) thing_inside
    
    1354
    +      XExpr (ExpandedThingRn o _) -> addExpansionErrCtxt o thing_inside
    
    1355 1355
        -- Flip error ctxt into expansion mode
    
    1356 1356
     
    
    1357 1357
           _ -> addErrCtxt (ExprCtxt e) thing_inside
    
    ... ... @@ -1372,9 +1372,9 @@ addErrCtxt :: ErrCtxtMsg -> TcM a -> TcM a
    1372 1372
     addErrCtxt msg = addErrCtxtM (\env -> return (env, msg))
    
    1373 1373
     
    
    1374 1374
     -- See Note [ErrCtxtStack Manipulation]
    
    1375
    -addExpansionErrCtxt :: SrcCodeOrigin -> ErrCtxtMsg -> TcM a -> TcM a
    
    1375
    +addExpansionErrCtxt :: ErrCtxtMsg -> TcM a -> TcM a
    
    1376 1376
     {-# INLINE addExpansionErrCtxt #-}   -- Note [Inlining addErrCtxt]
    
    1377
    -addExpansionErrCtxt o msg = addExpansionErrCtxtM o (\env -> return (env, msg))
    
    1377
    +addExpansionErrCtxt msg = addExpansionErrCtxtM (\env -> return (env, msg))
    
    1378 1378
     
    
    1379 1379
     -- | Add a message to the error context. This message may do tidying.
    
    1380 1380
     --   See Note [Rebindable syntax and XXExprGhcRn] in GHC.Hs.Expr
    
    ... ... @@ -1383,9 +1383,9 @@ addErrCtxtM :: (TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg)) -> TcM a -> TcM a
    1383 1383
     addErrCtxtM ctxt = pushCtxt (MkErrCtxt VanillaUserSrcCode ctxt)
    
    1384 1384
     
    
    1385 1385
     -- See Note [ErrCtxtStack Manipulation]
    
    1386
    -addExpansionErrCtxtM :: SrcCodeOrigin -> (TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg)) -> TcM a -> TcM a
    
    1386
    +addExpansionErrCtxtM :: (TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg)) -> TcM a -> TcM a
    
    1387 1387
     {-# INLINE addExpansionErrCtxtM #-}  -- Note [Inlining addErrCtxt]
    
    1388
    -addExpansionErrCtxtM o ctxt = pushCtxt (MkErrCtxt (ExpansionCodeCtxt o) ctxt)
    
    1388
    +addExpansionErrCtxtM ctxt = pushCtxt (MkErrCtxt ExpansionCodeCtxt ctxt)
    
    1389 1389
     
    
    1390 1390
     -- | Add a fixed landmark message to the error context. A landmark
    
    1391 1391
     -- message is always sure to be reported, even if there is a lot of
    

  • compiler/GHC/Tc/Utils/TcType.hs-boot
    ... ... @@ -5,6 +5,8 @@ import GHC.Prelude ( Bool )
    5 5
     import {-# SOURCE #-} GHC.Types.Var ( TcTyVar )
    
    6 6
     import {-# SOURCE #-} GHC.Tc.Types.Origin ( FixedRuntimeRepOrigin )
    
    7 7
     import GHC.Types.Name.Env ( NameEnv )
    
    8
    +import {-# SOURCE #-} GHC.Core.TyCon (TyCon)
    
    9
    +import {-# SOURCE #-} GHC.Core.TyCo.Rep (Type)
    
    8 10
     
    
    9 11
     data MetaDetails
    
    10 12
     
    
    ... ... @@ -20,3 +22,6 @@ data ConcreteTvOrigin
    20 22
     
    
    21 23
     isConcreteTyVar :: TcTyVar -> Bool
    
    22 24
     noConcreteTyVars :: ConcreteTyVars
    
    25
    +
    
    26
    +type TcTyCon = TyCon
    
    27
    +type TcType = Type
    \ No newline at end of file

  • compiler/GHC/Types/Error.hs-boot
    1
    +module GHC.Types.Error where
    
    2
    +
    
    3
    +import GHC.Prelude (Maybe, Bool, IO)
    
    4
    +import GHC.Utils.Outputable (SDoc)
    
    5
    +import GHC.Types.SrcLoc (SrcSpan)
    
    6
    +
    
    7
    +data MessageClass
    
    8
    +  = MCOutput
    
    9
    +  | MCFatal
    
    10
    +  | MCInteractive
    
    11
    +  | MCDump
    
    12
    +  | MCInfo
    
    13
    +  | MCDiagnostic Severity ResolvedDiagnosticReason (Maybe DiagnosticCode)
    
    14
    +
    
    15
    +data Severity
    
    16
    +  = SevIgnore
    
    17
    +  | SevWarning
    
    18
    +  | SevError
    
    19
    +
    
    20
    +data DiagnosticCode
    
    21
    +data ResolvedDiagnosticReason
    
    22
    +
    
    23
    +mkLocMessageWarningGroups  :: Bool -> MessageClass -> SrcSpan -> SDoc -> SDoc
    
    24
    +getCaretDiagnostic :: MessageClass -> SrcSpan -> IO SDoc
    \ No newline at end of file

  • compiler/GHC/Unit/State.hs-boot
    1
    +module GHC.Unit.State where
    
    2
    +
    
    3
    +data UnitState
    
    4
    +data ModuleSuggestion
    
    5
    +data ModuleOrigin
    
    6
    +data UnusableUnit
    
    7
    +data UnitInfo
    \ No newline at end of file

  • compiler/GHC/Utils/Logger.hs
    ... ... @@ -82,7 +82,10 @@ where
    82 82
     
    
    83 83
     import GHC.Prelude
    
    84 84
     import GHC.Driver.Flags
    
    85
    -import GHC.Types.Error
    
    85
    +import {-# SOURCE #-} GHC.Types.Error
    
    86
    +  ( MessageClass (..), Severity (..), ResolvedDiagnosticReason, DiagnosticCode
    
    87
    +  , mkLocMessageWarningGroups,getCaretDiagnostic)
    
    88
    +import GHC.Types.Error ()
    
    86 89
     import GHC.Types.SrcLoc
    
    87 90
     
    
    88 91
     import qualified GHC.Utils.Ppr as Pretty