Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC

Commits:

7 changed files:

Changes:

  • compiler/GHC/Tc/Gen/App.hs
    ... ... @@ -1943,7 +1943,7 @@ quickLookArg1 pos app_lspan (fun, fun_lspan) larg@(L _ arg) sc_arg_ty@(Scaled _
    1943 1943
         do { ((rn_fun_arg, fun_lspan_arg), rn_args) <- splitHsApps arg
    
    1944 1944
     
    
    1945 1945
            -- Step 1: get the type of the head of the argument
    
    1946
    -       ; (fun_ue, mb_fun_ty) <- (tcCollectingUsage $ tcInferAppHead_maybe rn_fun_arg)
    
    1946
    +       ; (fun_ue, mb_fun_ty) <- tcCollectingUsage $ tcInferAppHead_maybe rn_fun_arg
    
    1947 1947
              -- tcCollectingUsage: the use of an Id at the head generates usage-info
    
    1948 1948
              -- See the call to `tcEmitBindingUsage` in `check_local_id`.  So we must
    
    1949 1949
              -- capture and save it in the `EValArgQL`.  See (QLA6) in
    
    ... ... @@ -2020,9 +2020,9 @@ mk_origin fun_lspan rn_fun
    2020 2020
       = return $ exprCtOrigin rn_fun
    
    2021 2021
       | otherwise -- if the location is generated,
    
    2022 2022
                   -- the best we can do is to approximate by looking on top of the error message stack
    
    2023
    -  = do { code_orig <- getSrcCodeOrigin
    
    2023
    +  = do { code_orig <- getHsCtxt
    
    2024 2024
            ; traceTc "mk_origin" (pprHsCtxt code_orig)
    
    2025
    -       ; return $ srcCodeOriginCtOrigin code_orig
    
    2025
    +       ; return $ hsCtxtCtOrigin code_orig
    
    2026 2026
            }
    
    2027 2027
     
    
    2028 2028
     
    

  • compiler/GHC/Tc/Gen/Do.hs
    ... ... @@ -448,7 +448,7 @@ It stores the original statement (with location) and the expanded expression
    448 448
         of the error context stack which contains the error message for
    
    449 449
         the previous statement: eg. "In the stmt of a do block: e1".
    
    450 450
         This popping is implicitly done when we push the error context message for the next statment.
    
    451
    -    See Note [ErrCtxtStack Manipulation] and `LclEnv.setLclCtxtSrcCodeOrigin`
    
    451
    +    See Note [ErrCtxtStack Manipulation] and `LclEnv.setLclCtxtHsCtxt`
    
    452 452
     
    
    453 453
         Sans the popping business for error context stack,
    
    454 454
         if there were to be a type error in `e2`, we would get a spurious and confusing error message
    

  • compiler/GHC/Tc/Gen/Expr.hs
    ... ... @@ -677,6 +677,7 @@ tcExpr expr@(RecordCon { rcon_con = L loc qcon@(WithUserRdr _ con_name)
    677 677
     -- in the renamer. See Note [Overview of record dot syntax] in
    
    678 678
     -- GHC.Hs.Expr. This is why we match on 'rupd_flds = Left rbnds' here
    
    679 679
     -- and panic otherwise.
    
    680
    +-- WIP: To be fixed soon expandRecordUpd needs to return HsExpansion and not a separate ds_res_ty
    
    680 681
     tcExpr expr@(RecordUpd { rupd_expr = record_expr
    
    681 682
                            , rupd_flds =
    
    682 683
                                RegularRecUpdFields
    
    ... ... @@ -1862,14 +1863,3 @@ checkMissingFields con_like rbinds arg_tys
    1862 1863
         field_strs = conLikeImplBangs con_like
    
    1863 1864
     
    
    1864 1865
         fl `elemField` flds = any (\ fl' -> flSelector fl == fl') flds
    1865
    -
    
    1866
    -
    
    1867
    --- Expands the expression on the fly
    
    1868
    --- See Note [Handling overloaded and rebindable constructs]
    
    1869
    --- See Note [Typechecking by expansion: overview]
    
    1870
    -tcExpandExpr :: HsExpr GhcRn -> TcM (HsExpr GhcRn)
    
    1871
    -tcExpandExpr orig_expr@(HsDo _ flav (L _ stmts))
    
    1872
    -  = do { expanded_expr <- expandDoStmts flav stmts
    
    1873
    -       ; return (mkExpandedLExpr orig_expr expanded_expr) }
    
    1874
    -
    
    1875
    -tcExpandExpr e = return e

  • compiler/GHC/Tc/Gen/Head.hs
    ... ... @@ -467,7 +467,7 @@ tcInferAppHead_maybe fun = case fun of
    467 467
                                                   -- visible type applications in the argument.
    
    468 468
                                                   -- c.f. T19167
    
    469 469
                                                   (\ (e, ds_flag, ty) -> (mkExpandedTc o (L loc e), ds_flag, ty)) <$>
    
    470
    -                                                  tcExprSigma False (errCtxtCtOrigin o) e
    
    470
    +                                                  tcExprSigma False (hsCtxtCtOrigin o) e
    
    471 471
                                                   )
    
    472 472
           _                           -> return Nothing
    
    473 473
     
    

  • compiler/GHC/Tc/Types/LclEnv.hs
    ... ... @@ -21,9 +21,9 @@ module GHC.Tc.Types.LclEnv (
    21 21
       , setLclEnvTypeEnv
    
    22 22
       , modifyLclEnvTcLevel
    
    23 23
     
    
    24
    -  , getLclEnvSrcCodeOrigin
    
    25
    -  , setLclEnvSrcCodeOrigin
    
    26
    -  , setLclCtxtSrcCodeOrigin
    
    24
    +  , getLclEnvHsCtxt
    
    25
    +  , setLclEnvHsCtxt
    
    26
    +  , setLclCtxtHsCtxt
    
    27 27
       , lclEnvInGeneratedCode
    
    28 28
     
    
    29 29
       , addLclEnvErrCtxt
    
    ... ... @@ -110,7 +110,7 @@ This data structure keeps track of two things:
    110 110
     In the current design, if the top of the ErrCtxtStack is an ExpansionCodeCtxt
    
    111 111
     i.e. we are currently typechecking a compiler generated expression, and we encounter
    
    112 112
     an XExpr, then we _replace_ the top of the stack with the new XExpr. Otherwise, we
    
    113
    -push the new expression error message on top of the stack. cf. `LclEnv.setLclCtxtSrcCodeOrigin`
    
    113
    +push the new expression error message on top of the stack. cf. `LclEnv.setLclCtxtHsCtxt`
    
    114 114
     
    
    115 115
     -}
    
    116 116
     
    
    ... ... @@ -119,9 +119,9 @@ push the new expression error message on top of the stack. cf. `LclEnv.setLclCtx
    119 119
     type ErrCtxtStack = [ErrCtxt]
    
    120 120
     
    
    121 121
     -- | Get the top of the error message stack
    
    122
    -get_src_code_origin :: ErrCtxtStack -> HsCtxt
    
    123
    -get_src_code_origin (e : _) = e
    
    124
    -get_src_code_origin _ = error "get_src_code_origin: oops! Empty error message stack"
    
    122
    +get_err_ctxt_stack_head :: ErrCtxtStack -> HsCtxt
    
    123
    +get_err_ctxt_stack_head (e : _) = e
    
    124
    +get_err_ctxt_stack_head _ = error "get_err_ctxt_stack_head: oops! Empty error message stack"
    
    125 125
     
    
    126 126
     data TcLclCtxt
    
    127 127
       = TcLclCtxt {
    
    ... ... @@ -199,17 +199,17 @@ setLclEnvErrCtxt ctxt = modifyLclCtxt (\env -> env { tcl_err_ctxt = ctxt })
    199 199
     
    
    200 200
     -- See Note [ErrCtxtStack Manipulation]
    
    201 201
     addLclEnvErrCtxt :: ErrCtxt -> TcLclEnv -> TcLclEnv
    
    202
    -addLclEnvErrCtxt ec = setLclEnvSrcCodeOrigin ec
    
    202
    +addLclEnvErrCtxt ec = setLclEnvHsCtxt ec
    
    203 203
     
    
    204
    -getLclEnvSrcCodeOrigin :: TcLclEnv -> HsCtxt
    
    205
    -getLclEnvSrcCodeOrigin = get_src_code_origin . tcl_err_ctxt . tcl_lcl_ctxt
    
    204
    +getLclEnvHsCtxt :: TcLclEnv -> HsCtxt
    
    205
    +getLclEnvHsCtxt = get_err_ctxt_stack_head . tcl_err_ctxt . tcl_lcl_ctxt
    
    206 206
     
    
    207
    -setLclEnvSrcCodeOrigin :: ErrCtxt -> TcLclEnv -> TcLclEnv
    
    208
    -setLclEnvSrcCodeOrigin ec = modifyLclCtxt (setLclCtxtSrcCodeOrigin ec)
    
    207
    +setLclEnvHsCtxt :: ErrCtxt -> TcLclEnv -> TcLclEnv
    
    208
    +setLclEnvHsCtxt ec = modifyLclCtxt (setLclCtxtHsCtxt ec)
    
    209 209
     
    
    210 210
     -- See Note [ErrCtxtStack Manipulation]
    
    211
    -setLclCtxtSrcCodeOrigin :: ErrCtxt -> TcLclCtxt -> TcLclCtxt
    
    212
    -setLclCtxtSrcCodeOrigin ec lclCtxt
    
    211
    +setLclCtxtHsCtxt :: ErrCtxt -> TcLclCtxt -> TcLclCtxt
    
    212
    +setLclCtxtHsCtxt ec lclCtxt
    
    213 213
       -- never stack 2 statement error contexts on top of each other
    
    214 214
       | StmtErrCtxt{} : ecs <- tcl_err_ctxt lclCtxt
    
    215 215
       , StmtErrCtxt{} <- ec
    

  • compiler/GHC/Tc/Types/Origin.hs
    ... ... @@ -9,7 +9,7 @@ module GHC.Tc.Types.Origin (
    9 9
     
    
    10 10
       -- * CtOrigin
    
    11 11
       CtOrigin(..), exprCtOrigin, lexprCtOrigin, matchesCtOrigin, grhssCtOrigin,
    
    12
    -  srcCodeOriginCtOrigin, errCtxtCtOrigin,
    
    12
    +  hsCtxtCtOrigin,
    
    13 13
       invisibleOrigin_maybe, isVisibleOrigin, toInvisibleOrigin,
    
    14 14
       pprCtOrigin, pprCtOriginBriefly, isGivenOrigin,
    
    15 15
       defaultReprEqOrigins, isWantedSuperclassOrigin,
    
    ... ... @@ -625,20 +625,16 @@ exprCtOrigin (HsIf {}) = IfThenElseOrigin
    625 625
     exprCtOrigin (HsProjection _ p)   = RecordFieldProjectionOrigin (FieldLabelStrings $ fmap noLocA p)
    
    626 626
     exprCtOrigin (RecordUpd{})        = RecordUpdOrigin
    
    627 627
     exprCtOrigin (HsGetField _ _ f)   = GetFieldOrigin (fmap field_label $ dfoLabel (unLoc f))
    
    628
    -exprCtOrigin (XExpr (ExpandedThingRn (HSE o _))) = errCtxtCtOrigin o
    
    628
    +exprCtOrigin (XExpr (ExpandedThingRn (HSE o _))) = hsCtxtCtOrigin o
    
    629 629
     exprCtOrigin (XExpr (HsRecSelRn f))  = OccurrenceOfRecSel $ L (getLoc $ foLabel f) (foExt f)
    
    630 630
     
    
    631
    -srcCodeOriginCtOrigin :: HsCtxt -> CtOrigin
    
    632
    -srcCodeOriginCtOrigin = errCtxtCtOrigin
    
    633
    -
    
    634
    -errCtxtCtOrigin :: HsCtxt -> CtOrigin
    
    635
    -errCtxtCtOrigin (ExprCtxt e) = exprCtOrigin e
    
    636
    -errCtxtCtOrigin (FunAppCtxt (FunAppCtxtExpr _ e) _) = exprCtOrigin e
    
    637
    -errCtxtCtOrigin (StmtErrCtxt{}) = DoStmtOrigin
    
    638
    -errCtxtCtOrigin (StmtErrCtxtPat p) = DoPatOrigin p
    
    639
    -errCtxtCtOrigin (RecordUpdCtxt{}) = RecordUpdOrigin
    
    640
    -errCtxtCtOrigin _ = Shouldn'tHappenOrigin "errCtxtCtOrigin"
    
    641
    -
    
    631
    +hsCtxtCtOrigin :: HsCtxt -> CtOrigin
    
    632
    +hsCtxtCtOrigin (ExprCtxt e) = exprCtOrigin e
    
    633
    +hsCtxtCtOrigin (FunAppCtxt (FunAppCtxtExpr _ e) _) = exprCtOrigin e
    
    634
    +hsCtxtCtOrigin (StmtErrCtxt{}) = DoStmtOrigin
    
    635
    +hsCtxtCtOrigin (StmtErrCtxtPat p) = DoPatOrigin p
    
    636
    +hsCtxtCtOrigin (RecordUpdCtxt{}) = RecordUpdOrigin
    
    637
    +hsCtxtCtOrigin _ = Shouldn'tHappenOrigin "hsCtxtCtOrigin"
    
    642 638
     
    
    643 639
     -- | Extract a suitable CtOrigin from a MatchGroup
    
    644 640
     matchesCtOrigin :: MatchGroup GhcRn (LHsExpr GhcRn) -> CtOrigin
    

  • compiler/GHC/Tc/Utils/Monad.hs
    ... ... @@ -61,7 +61,7 @@ module GHC.Tc.Utils.Monad(
    61 61
       addDependentFiles, addDependentDirectories,
    
    62 62
     
    
    63 63
       -- * Error management
    
    64
    -  getSrcCodeOrigin,
    
    64
    +  getHsCtxt,
    
    65 65
       getSrcSpanM, getRealSrcSpanM, setSrcSpan, setSrcSpanA, addLocM,
    
    66 66
       inGeneratedCode,
    
    67 67
       wrapLocM, wrapLocFstM, wrapLocFstMA, wrapLocSndM, wrapLocSndMA, wrapLocM_,
    
    ... ... @@ -1094,8 +1094,8 @@ setSrcSpan (GeneratedSrcSpan{}) thing_inside
    1094 1094
     setSrcSpan _ thing_inside
    
    1095 1095
       = thing_inside
    
    1096 1096
     
    
    1097
    -getSrcCodeOrigin :: TcRn HsCtxt
    
    1098
    -getSrcCodeOrigin = getLclEnvSrcCodeOrigin <$> getLclEnv
    
    1097
    +getHsCtxt :: TcRn HsCtxt
    
    1098
    +getHsCtxt = getLclEnvHsCtxt <$> getLclEnv
    
    1099 1099
     
    
    1100 1100
     setSrcSpanA :: EpAnn ann -> TcRn a -> TcRn a
    
    1101 1101
     setSrcSpanA l = setSrcSpan (locA l)