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

Commits:

6 changed files:

Changes:

  • compiler/GHC/Tc/Errors/Ppr.hs
    ... ... @@ -5327,7 +5327,7 @@ pprArising :: CtLoc -> SDoc
    5327 5327
     -- Used for the main, top-level error message
    
    5328 5328
     -- We've done special processing for TypeEq, KindEq, givens
    
    5329 5329
     pprArising ct_loc
    
    5330
    -  | in_generated_code = empty  -- See Note ["Arising from" messages in generated code]
    
    5330
    +  | in_generated_code = pprCtOrigin orig -- TODO ANI: maybe should go way
    
    5331 5331
       | suppress_origin   = empty
    
    5332 5332
       | otherwise         = pprCtOrigin orig
    
    5333 5333
       where
    

  • compiler/GHC/Tc/Gen/App.hs
    1
    -
    
    2 1
     {-# LANGUAGE DataKinds           #-}
    
    3 2
     {-# LANGUAGE FlexibleContexts    #-}
    
    4 3
     {-# LANGUAGE GADTs               #-}
    
    ... ... @@ -189,8 +188,8 @@ tcExprSigma inst fun_orig rn_expr
    189 188
       = do { (fun@(rn_fun,fun_ctxt), rn_args) <- splitHsApps rn_expr
    
    190 189
            ; do_ql <- wantQuickLook rn_fun
    
    191 190
            ; (tc_fun, fun_sigma) <- tcInferAppHead fun
    
    192
    -       ; (inst_args, app_res_sigma) <- tcInstFun do_ql inst fun_orig (tc_fun, fun_ctxt) fun_sigma rn_args
    
    193
    -       ; tc_args <- tcValArgs do_ql inst_args
    
    191
    +       ; (inst_args, app_res_sigma) <- tcInstFun do_ql inst fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
    
    192
    +       ; tc_args <- tcValArgs do_ql rn_fun inst_args
    
    194 193
            ; let tc_expr = rebuildHsApps (tc_fun, fun_ctxt) tc_args
    
    195 194
            ; return (tc_expr, app_res_sigma) }
    
    196 195
     
    
    ... ... @@ -422,7 +421,7 @@ tcApp fun_orig rn_expr exp_res_ty
    422 421
                   , text "do_ql:" <+> ppr do_ql]
    
    423 422
     
    
    424 423
            ; (inst_args, app_res_rho)
    
    425
    -              <- tcInstFun do_ql True fun_orig (tc_fun, fun_ctxt) fun_sigma rn_args
    
    424
    +              <- tcInstFun do_ql True fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
    
    426 425
     
    
    427 426
            ; case do_ql of
    
    428 427
                 NoQL -> do { traceTc "tcApp:NoQL" (ppr rn_fun $$ ppr app_res_rho)
    
    ... ... @@ -433,7 +432,7 @@ tcApp fun_orig rn_expr exp_res_ty
    433 432
                                                        app_res_rho exp_res_ty
    
    434 433
     
    
    435 434
                              -- Step 4.2: typecheck the  arguments
    
    436
    -                       ; tc_args <- tcValArgs NoQL inst_args
    
    435
    +                       ; tc_args <- tcValArgs NoQL rn_fun inst_args
    
    437 436
                              -- Step 4.3: wrap up
    
    438 437
                            ; finishApp tc_head tc_args app_res_rho res_wrap }
    
    439 438
     
    
    ... ... @@ -443,7 +442,7 @@ tcApp fun_orig rn_expr exp_res_ty
    443 442
                            ; quickLookResultType app_res_rho exp_res_ty
    
    444 443
                              -- Step 5.2: typecheck the arguments, and monomorphise
    
    445 444
                              --           any un-unified instantiation variables
    
    446
    -                       ; tc_args <- tcValArgs DoQL inst_args
    
    445
    +                       ; tc_args <- tcValArgs DoQL rn_fun inst_args
    
    447 446
                              -- Step 5.3: typecheck the arguments
    
    448 447
                            ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
    
    449 448
                              -- Step 5.4: subsumption check against the expected type
    
    ... ... @@ -529,26 +528,43 @@ checkResultTy rn_expr (tc_fun, fun_ctxt) inst_args app_res_rho (Check res_ty)
    529 528
             thing_inside
    
    530 529
     
    
    531 530
     ----------------
    
    532
    -tcValArgs :: QLFlag -> [HsExprArg 'TcpInst] -> TcM [HsExprArg 'TcpTc]
    
    531
    +tcValArgs :: QLFlag -> HsExpr GhcRn -> [HsExprArg 'TcpInst] -> TcM [HsExprArg 'TcpTc]
    
    533 532
     -- Importantly, tcValArgs works left-to-right, so that by the time we
    
    534 533
     -- encounter an argument, we have monomorphised all the instantiation
    
    535 534
     -- variables that its type contains.  All that is left to do is an ordinary
    
    536 535
     -- zonkTcType.  See Note [Monomorphise instantiation variables].
    
    537
    -tcValArgs do_ql args = mapM (tcValArg do_ql) args
    
    536
    +tcValArgs do_ql fun args = go do_ql 0 args
    
    537
    +  where
    
    538
    +    go _ _ [] = return []
    
    539
    +    go do_ql pos (arg : args) =
    
    540
    +      do { arg' <- tcValArg do_ql pos' fun arg
    
    541
    +         ; args' <- go do_ql pos' args
    
    542
    +         ; return (arg' : args')
    
    543
    +         }
    
    544
    +      where
    
    545
    +    -- increment position if the argument is user written type or value argument
    
    546
    +        pos' | EValArg { ea_ctxt = l } <- arg
    
    547
    +             , not (isGeneratedSrcSpan l) = pos + 1
    
    548
    +             | EValArgQL { eaql_ctxt = l } <- arg
    
    549
    +             , not (isGeneratedSrcSpan l) = pos + 1
    
    550
    +             | ETypeArg{ ea_ctxt = l } <- arg
    
    551
    +             , not (isGeneratedSrcSpan l) = pos + 1
    
    552
    +             | otherwise = pos
    
    538 553
     
    
    539
    -tcValArg :: QLFlag -> HsExprArg 'TcpInst    -- Actual argument
    
    554
    +
    
    555
    +tcValArg :: QLFlag -> Int -> HsExpr GhcRn -> HsExprArg 'TcpInst    -- Actual argument
    
    540 556
              -> TcM (HsExprArg 'TcpTc)          -- Resulting argument
    
    541
    -tcValArg _     (EPrag l p)         = return (EPrag l (tcExprPrag p))
    
    542
    -tcValArg _     (ETypeArg l hty ty) = return (ETypeArg l hty ty)
    
    543
    -tcValArg do_ql (EWrap (EHsWrap w)) = do { whenQL do_ql $ qlMonoHsWrapper w
    
    544
    -                                        ; return (EWrap (EHsWrap w)) }
    
    557
    +tcValArg _     _ _ (EPrag l p)         = return (EPrag l (tcExprPrag p))
    
    558
    +tcValArg _     _ _ (ETypeArg l hty ty) = return (ETypeArg l hty ty)
    
    559
    +tcValArg do_ql _ _ (EWrap (EHsWrap w)) = do { whenQL do_ql $ qlMonoHsWrapper w
    
    560
    +                                            ; return (EWrap (EHsWrap w)) }
    
    545 561
       -- qlMonoHsWrapper: see Note [Monomorphise instantiation variables]
    
    546
    -tcValArg _     (EWrap ew)          = return (EWrap ew)
    
    562
    +tcValArg _     _ _ (EWrap ew)          = return (EWrap ew)
    
    547 563
     
    
    548
    -tcValArg do_ql (EValArg { ea_ctxt   = ctxt
    
    549
    -                        , ea_arg    = larg@(L arg_loc arg)
    
    550
    -                        , ea_arg_ty = sc_arg_ty })
    
    551
    -  = addArgCtxt ctxt larg $
    
    564
    +tcValArg do_ql pos fun (EValArg { ea_ctxt   = ctxt
    
    565
    +                            , ea_arg    = larg@(L arg_loc arg)
    
    566
    +                            , ea_arg_ty = sc_arg_ty })
    
    567
    +  = addArgCtxt pos ctxt fun larg $
    
    552 568
         do { -- Crucial step: expose QL results before checking exp_arg_ty
    
    553 569
              -- So far as the paper is concerned, this step applies
    
    554 570
              -- the poly-substitution Theta, learned by QL, so that we
    
    ... ... @@ -577,7 +593,7 @@ tcValArg do_ql (EValArg { ea_ctxt = ctxt
    577 593
                              , ea_arg = L arg_loc arg'
    
    578 594
                              , ea_arg_ty = noExtField }) }
    
    579 595
     
    
    580
    -tcValArg _ (EValArgQL { eaql_wanted  = wanted
    
    596
    +tcValArg _ pos fun (EValArgQL { eaql_wanted  = wanted
    
    581 597
                           , eaql_ctxt    = ctxt
    
    582 598
                           , eaql_arg_ty  = sc_arg_ty
    
    583 599
                           , eaql_larg    = larg@(L arg_loc rn_expr)
    
    ... ... @@ -586,7 +602,7 @@ tcValArg _ (EValArgQL { eaql_wanted = wanted
    586 602
                           , eaql_args    = inst_args
    
    587 603
                           , eaql_encl    = arg_influences_enclosing_call
    
    588 604
                           , eaql_res_rho = app_res_rho })
    
    589
    -  = addArgCtxt ctxt larg $
    
    605
    +  = addArgCtxt pos ctxt fun larg $
    
    590 606
         do { -- Expose QL results to tcSkolemise, as in EValArg case
    
    591 607
              Scaled mult exp_arg_ty <- liftZonkM $ zonkScaledTcType sc_arg_ty
    
    592 608
     
    
    ... ... @@ -611,7 +627,7 @@ tcValArg _ (EValArgQL { eaql_wanted = wanted
    611 627
                       ; unless arg_influences_enclosing_call $  -- Don't repeat
    
    612 628
                         qlUnify app_res_rho exp_arg_rho         -- the qlUnify
    
    613 629
     
    
    614
    -                  ; tc_args <- tcValArgs DoQL inst_args
    
    630
    +                  ; tc_args <- tcValArgs DoQL fun inst_args
    
    615 631
                       ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
    
    616 632
                       ; res_wrap <- checkResultTy rn_expr tc_head inst_args
    
    617 633
                                                   app_res_rho (mkCheckExpType exp_arg_rho)
    
    ... ... @@ -656,14 +672,14 @@ tcInstFun :: QLFlag
    656 672
                         -- Otherwise we do eager instantiation; in Fig 5 of the paper
    
    657 673
                         --    |-inst returns a rho-type
    
    658 674
               -> CtOrigin
    
    659
    -          -> (HsExpr GhcTc, AppCtxt)
    
    675
    +          -> (HsExpr GhcTc, HsExpr GhcRn, AppCtxt)
    
    660 676
               -> TcSigmaType -> [HsExprArg 'TcpRn]
    
    661 677
               -> TcM ( [HsExprArg 'TcpInst]
    
    662 678
                      , TcSigmaType )
    
    663 679
     -- This crucial function implements the |-inst judgement in Fig 4, plus the
    
    664 680
     -- modification in Fig 5, of the QL paper:
    
    665 681
     -- "A quick look at impredicativity" (ICFP'20).
    
    666
    -tcInstFun do_ql inst_final fun_orig (tc_fun, fun_ctxt) fun_sigma rn_args
    
    682
    +tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
    
    667 683
       = do { traceTc "tcInstFun" (vcat [ text "origin" <+> ppr fun_orig
    
    668 684
                                        , text "tc_fun" <+> ppr tc_fun
    
    669 685
                                        , text "fun_sigma" <+> ppr fun_sigma
    
    ... ... @@ -845,7 +861,7 @@ tcInstFun do_ql inst_final fun_orig (tc_fun, fun_ctxt) fun_sigma rn_args
    845 861
                       (Just $ HsExprTcThing tc_fun)
    
    846 862
                       (n_val_args, fun_sigma) fun_ty
    
    847 863
     
    
    848
    -           ; arg' <- quickLookArg do_ql ctxt arg arg_ty
    
    864
    +           ; arg' <- quickLookArg do_ql pos ctxt rn_fun arg arg_ty
    
    849 865
                ; let acc' = arg' : addArgWrap wrap acc
    
    850 866
                ; go (pos+1) acc' res_ty rest_args }
    
    851 867
     
    
    ... ... @@ -889,7 +905,7 @@ looks_like_type_arg EValArg{ ea_arg = L _ e } =
    889 905
         _           -> False
    
    890 906
     looks_like_type_arg _ = False
    
    891 907
     
    
    892
    -addArgCtxt :: AppCtxt -> LHsExpr GhcRn
    
    908
    +addArgCtxt :: Int -> AppCtxt -> HsExpr GhcRn -> LHsExpr GhcRn
    
    893 909
                -> TcM a -> TcM a
    
    894 910
     -- There are 2 cases:
    
    895 911
     -- 1. In the normal case, we add an informative context
    
    ... ... @@ -901,20 +917,18 @@ addArgCtxt :: AppCtxt -> LHsExpr GhcRn
    901 917
     --   Unless the arg is also a generated thing, in which case do nothing.
    
    902 918
     --  See Note [Rebindable syntax and XXExprGhcRn] in GHC.Hs.Expr
    
    903 919
     --  See Note [Expanding HsDo with XXExprGhcRn] in GHC.Tc.Gen.Do
    
    904
    -addArgCtxt ctxt (L arg_loc arg) thing_inside
    
    920
    +addArgCtxt arg_no ctxt fun (L arg_loc arg) thing_inside
    
    905 921
       = do { in_generated_code <- inGeneratedCode
    
    906 922
            ; traceTc "addArgCtxt" (vcat [ text "generated:" <+> ppr in_generated_code
    
    907 923
                                         , text "arg: " <+> ppr arg
    
    908 924
                                         , text "arg_loc" <+> ppr arg_loc])
    
    909
    -       ; case ctxt of
    
    910
    -           VACall fun arg_no _ | not in_generated_code
    
    911
    -             -> do setSrcSpanA arg_loc                    $
    
    912
    -                     addErrCtxt (FunAppCtxt (FunAppCtxtExpr fun arg) arg_no) $
    
    913
    -                     thing_inside
    
    914
    -
    
    915
    -           _ -> setSrcSpanA arg_loc $
    
    916
    -                  addExprCtxt arg     $  -- Auto-suppressed if arg_loc is generated
    
    917
    -                  thing_inside }
    
    925
    +       ; if in_generated_code
    
    926
    +         then do setSrcSpanA arg_loc $
    
    927
    +                   addExprCtxt arg     $  -- Auto-suppressed if arg_loc is generated
    
    928
    +                   thing_inside
    
    929
    +         else do setSrcSpanA arg_loc                    $
    
    930
    +                   addErrCtxt (FunAppCtxt (FunAppCtxtExpr fun arg) arg_no) $
    
    931
    +                   thing_inside }
    
    918 932
     
    
    919 933
     {- *********************************************************************
    
    920 934
     *                                                                      *
    
    ... ... @@ -1690,19 +1704,19 @@ This turned out to be more subtle than I expected. Wrinkles:
    1690 1704
     
    
    1691 1705
     -}
    
    1692 1706
     
    
    1693
    -quickLookArg :: QLFlag -> AppCtxt
    
    1707
    +quickLookArg :: QLFlag -> Int -> AppCtxt -> HsExpr GhcRn
    
    1694 1708
                  -> LHsExpr GhcRn          -- ^ Argument
    
    1695 1709
                  -> Scaled TcSigmaTypeFRR  -- ^ Type expected by the function
    
    1696 1710
                  -> TcM (HsExprArg 'TcpInst)
    
    1697 1711
     -- See Note [Quick Look at value arguments]
    
    1698
    -quickLookArg NoQL ctxt larg orig_arg_ty
    
    1712
    +quickLookArg NoQL _ ctxt _ larg orig_arg_ty
    
    1699 1713
       = skipQuickLook ctxt larg orig_arg_ty
    
    1700
    -quickLookArg DoQL ctxt larg orig_arg_ty
    
    1714
    +quickLookArg DoQL pos ctxt fun larg orig_arg_ty
    
    1701 1715
       = do { is_rho <- tcIsDeepRho (scaledThing orig_arg_ty)
    
    1702 1716
            ; traceTc "qla" (ppr orig_arg_ty $$ ppr is_rho)
    
    1703 1717
            ; if not is_rho
    
    1704 1718
              then skipQuickLook ctxt larg orig_arg_ty
    
    1705
    -         else quickLookArg1 ctxt larg orig_arg_ty }
    
    1719
    +         else quickLookArg1 pos ctxt fun larg orig_arg_ty }
    
    1706 1720
     
    
    1707 1721
     skipQuickLook :: AppCtxt -> LHsExpr GhcRn -> Scaled TcRhoType
    
    1708 1722
                   -> TcM (HsExprArg 'TcpInst)
    
    ... ... @@ -1745,12 +1759,12 @@ isGuardedTy ty
    1745 1759
       | Just {} <- tcSplitAppTy_maybe ty        = True
    
    1746 1760
       | otherwise                               = False
    
    1747 1761
     
    
    1748
    -quickLookArg1 :: AppCtxt -> LHsExpr GhcRn
    
    1762
    +quickLookArg1 :: Int -> AppCtxt -> HsExpr GhcRn -> LHsExpr GhcRn
    
    1749 1763
                   -> Scaled TcRhoType  -- Deeply skolemised
    
    1750 1764
                   -> TcM (HsExprArg 'TcpInst)
    
    1751 1765
     -- quickLookArg1 implements the "QL Argument" judgement in Fig 5 of the paper
    
    1752
    -quickLookArg1 ctxt larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_rho)
    
    1753
    -  = addArgCtxt ctxt larg $ -- Context needed for constraints
    
    1766
    +quickLookArg1 pos ctxt fun larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_rho)
    
    1767
    +  = addArgCtxt pos ctxt fun larg $ -- Context needed for constraints
    
    1754 1768
                                -- generated by calls in arg
    
    1755 1769
         do { ((rn_fun, fun_ctxt), rn_args) <- splitHsApps arg
    
    1756 1770
     
    
    ... ... @@ -1776,7 +1790,7 @@ quickLookArg1 ctxt larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_rho)
    1776 1790
            ; do_ql <- wantQuickLook rn_fun
    
    1777 1791
            ; ((inst_args, app_res_rho), wanted)
    
    1778 1792
                  <- captureConstraints $
    
    1779
    -                tcInstFun do_ql True (exprCtOrigin arg) (tc_fun, fun_ctxt) fun_sigma rn_args
    
    1793
    +                tcInstFun do_ql True (exprCtOrigin arg) (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
    
    1780 1794
                     -- We must capture type-class and equality constraints here, but
    
    1781 1795
                     -- not equality constraints.  See (QLA6) in Note [Quick Look at
    
    1782 1796
                     -- value arguments]
    

  • compiler/GHC/Tc/Gen/Expr.hs
    1
    -
    
    2 1
     {-# LANGUAGE DataKinds           #-}
    
    3 2
     {-# LANGUAGE FlexibleContexts    #-}
    
    4 3
     {-# LANGUAGE ScopedTypeVariables #-}
    
    ... ... @@ -295,7 +294,7 @@ tcExpr :: HsExpr GhcRn
    295 294
     -- These constructors are the union of
    
    296 295
     --   - ones taken apart by GHC.Tc.Gen.Head.splitHsApps
    
    297 296
     --   - ones understood by GHC.Tc.Gen.Head.tcInferAppHead_maybe
    
    298
    --- See Note [Application chains and heads] in GHC.Tc.Gen.Ap
    
    297
    +-- See Note [Application chains and heads] in GHC.Tc.Gen.App
    
    299 298
     tcExpr e@(HsVar {})              res_ty = tcApp (exprCtOrigin e) e res_ty
    
    300 299
     tcExpr e@(HsApp {})              res_ty = tcApp (exprCtOrigin e) e res_ty
    
    301 300
     tcExpr e@(OpApp {})              res_ty = tcApp (exprCtOrigin e) e res_ty
    
    ... ... @@ -905,7 +904,7 @@ tcSyntaxOpGen :: CtOrigin
    905 904
                   -> ([TcSigmaTypeFRR] -> [Mult] -> TcM a)
    
    906 905
                   -> TcM (a, SyntaxExprTc)
    
    907 906
     tcSyntaxOpGen orig (SyntaxExprRn op) arg_tys res_ty thing_inside
    
    908
    -  = do { (expr, sigma) <- tcInferAppHead (op, VACall op 0 noSrcSpan)
    
    907
    +  = do { (expr, sigma) <- tcInferAppHead (op, noSrcSpan)
    
    909 908
                  -- Ugh!! But all this code is scheduled for demolition anyway
    
    910 909
            ; traceTc "tcSyntaxOpGen" (ppr op $$ ppr expr $$ ppr sigma)
    
    911 910
            ; (result, expr_wrap, arg_wraps, res_wrap)
    

  • compiler/GHC/Tc/Gen/Head.hs
    1
    -
    
    2 1
     {-# LANGUAGE DataKinds           #-}
    
    3 2
     {-# LANGUAGE FlexibleContexts    #-}
    
    4 3
     {-# LANGUAGE GADTs               #-}
    
    ... ... @@ -17,7 +16,7 @@
    17 16
     
    
    18 17
     module GHC.Tc.Gen.Head
    
    19 18
            ( HsExprArg(..), TcPass(..), QLFlag(..), EWrap(..)
    
    20
    -       , AppCtxt(..), appCtxtLoc, insideExpansion, appCtxtExpr
    
    19
    +       , AppCtxt, appCtxtLoc, insideExpansion
    
    21 20
            , splitHsApps, rebuildHsApps
    
    22 21
            , addArgWrap, isHsValArg
    
    23 22
            , leadingValArgs, isVisibleArg
    
    ... ... @@ -209,11 +208,11 @@ data EWrap = EPar AppCtxt
    209 208
                | EExpand (HsExpr GhcRn)
    
    210 209
                | EHsWrap HsWrapper
    
    211 210
     
    
    212
    -data AppCtxt =
    
    213
    -  VACall
    
    214
    -     (HsExpr GhcRn) Int  -- In the third argument of function f
    
    215
    -     SrcSpan             -- The SrcSpan of the application (f e1 e2 e3)
    
    216
    -                         --    noSrcSpan if outermost; see Note [AppCtxt]
    
    211
    +type AppCtxt = SrcSpan
    
    212
    +  -- VACall
    
    213
    +  --    (HsExpr GhcRn) Int  -- In the third argument of function f
    
    214
    +  --    SrcSpan             -- The SrcSpan of the application (f e1 e2 e3)
    
    215
    +  --                        --    noSrcSpan if outermost; see Note [AppCtxt]
    
    217 216
     
    
    218 217
     
    
    219 218
     {- Note [AppCtxt]
    
    ... ... @@ -244,21 +243,15 @@ a second time.
    244 243
     -}
    
    245 244
     
    
    246 245
     appCtxtLoc :: AppCtxt -> SrcSpan
    
    247
    -appCtxtLoc (VACall _ _ l)    = l
    
    246
    +appCtxtLoc l    = l
    
    248 247
     
    
    249 248
     insideExpansion :: AppCtxt -> Bool
    
    250
    -insideExpansion ctxt  = isGeneratedSrcSpan (appCtxtLoc ctxt)
    
    251
    -
    
    252
    -appCtxtExpr :: AppCtxt -> HsExpr GhcRn
    
    253
    -appCtxtExpr (VACall e _ _) = e
    
    249
    +insideExpansion l  = isGeneratedSrcSpan l
    
    254 250
     
    
    255 251
     instance Outputable QLFlag where
    
    256 252
       ppr DoQL = text "DoQL"
    
    257 253
       ppr NoQL = text "NoQL"
    
    258 254
     
    
    259
    -instance Outputable AppCtxt where
    
    260
    -  ppr (VACall f n l)    = text "VACall" <+> int n <+> ppr f  <+> ppr l
    
    261
    -
    
    262 255
     type family XPass (p :: TcPass) where
    
    263 256
       XPass 'TcpRn   = 'Renamed
    
    264 257
       XPass 'TcpInst = 'Renamed
    
    ... ... @@ -288,29 +281,15 @@ splitHsApps :: HsExpr GhcRn
    288 281
     -- This uses the TcM monad solely because we must run modFinalizers when looking
    
    289 282
     -- through HsUntypedSplices
    
    290 283
     -- (see Note [Looking through Template Haskell splices in splitHsApps]).
    
    291
    -splitHsApps e = go e (top_ctxt 0 e) []
    
    284
    +splitHsApps e = go e noSrcSpan []
    
    292 285
       where
    
    293
    -    top_ctxt :: Int -> HsExpr GhcRn -> AppCtxt
    
    294
    -    -- Always returns VACall fun n_val_args noSrcSpan
    
    295
    -    -- to initialise the argument splitting in 'go'
    
    296
    -    -- See Note [AppCtxt]
    
    297
    -    top_ctxt n (HsPar _ fun)        = top_lctxt n fun
    
    298
    -    top_ctxt n (HsPragE _ _ fun)    = top_lctxt n fun
    
    299
    -    top_ctxt n (HsAppType _ fun _)  = top_lctxt (n+1) fun
    
    300
    -    top_ctxt n (HsApp _ fun _)      = top_lctxt (n+1) fun
    
    301
    -    top_ctxt n (XExpr (PopErrCtxt fun)) = top_ctxt n fun
    
    302
    -    top_ctxt n other_fun            = VACall other_fun n noSrcSpan
    
    303
    -
    
    304
    -    top_lctxt :: Int -> LHsExpr GhcRn -> AppCtxt
    
    305
    -    top_lctxt n (L _ fun) = top_ctxt n fun
    
    306
    -
    
    307 286
         go :: HsExpr GhcRn -> AppCtxt -> [HsExprArg 'TcpRn]
    
    308 287
            -> TcM ((HsExpr GhcRn, AppCtxt), [HsExprArg 'TcpRn])
    
    309 288
         -- Modify the AppCtxt as we walk inwards, so it describes the next argument
    
    310
    -    go (HsPar _ (L l fun))           ctxt args = go fun (set l ctxt) (EWrap (EPar ctxt)     : args)
    
    311
    -    go (HsPragE _ p (L l fun))       ctxt args = go fun (set l ctxt) (EPrag      ctxt p     : args)
    
    312
    -    go (HsAppType _ (L l fun) ty)    ctxt args = go fun (dec l ctxt) (mkETypeArg ctxt ty    : args)
    
    313
    -    go (HsApp _ (L l fun) arg)       ctxt args = go fun (dec l ctxt) (mkEValArg  ctxt arg   : args)
    
    289
    +    go (HsPar _ (L l fun))           ctxt args = go fun (locA l) (EWrap (EPar ctxt)     : args)
    
    290
    +    go (HsPragE _ p (L l fun))       ctxt args = go fun (locA l) (EPrag      ctxt p     : args)
    
    291
    +    go (HsAppType _ (L l fun) ty)    ctxt args = go fun ctxt (mkETypeArg ctxt ty    : args)
    
    292
    +    go (HsApp _ (L l fun) arg)       ctxt args = go fun ctxt (mkEValArg  ctxt arg   : args)
    
    314 293
     
    
    315 294
         -- See Note [Looking through Template Haskell splices in splitHsApps]
    
    316 295
         go e@(HsUntypedSplice splice_res splice) ctxt args
    
    ... ... @@ -319,14 +298,14 @@ splitHsApps e = go e (top_ctxt 0 e) []
    319 298
           where
    
    320 299
             ctxt' :: AppCtxt
    
    321 300
             ctxt' = case splice of
    
    322
    -            HsUntypedSpliceExpr _ (L l _) -> set l ctxt -- l :: SrcAnn AnnListItem
    
    323
    -            HsQuasiQuote _ _ (L l _)      -> set l ctxt -- l :: SrcAnn NoEpAnns
    
    301
    +            HsUntypedSpliceExpr _ (L l _) -> locA l -- l :: SrcAnn AnnListItem
    
    302
    +            HsQuasiQuote _ _ (L l _)      -> locA l -- l :: SrcAnn NoEpAnns
    
    324 303
     
    
    325 304
         -- See Note [Desugar OpApp in the typechecker]
    
    326 305
         go e@(OpApp _ arg1 (L l op) arg2) _ args
    
    327
    -      = pure ( (op, VACall op 0 (locA l))
    
    328
    -             ,   mkEValArg (VACall op 1 generatedSrcSpan) arg1
    
    329
    -               : mkEValArg (VACall op 2 generatedSrcSpan) arg2
    
    306
    +      = pure ( (op, locA l)
    
    307
    +             ,   mkEValArg generatedSrcSpan arg1
    
    308
    +               : mkEValArg generatedSrcSpan arg2
    
    330 309
                         -- generatedSrcSpan because this the span of the call,
    
    331 310
                         -- and its hard to say exactly what that is
    
    332 311
                    : EWrap (EExpand e)
    
    ... ... @@ -337,11 +316,6 @@ splitHsApps e = go e (top_ctxt 0 e) []
    337 316
     
    
    338 317
         go e ctxt args = pure ((e,ctxt), args)
    
    339 318
     
    
    340
    -    set :: EpAnn ann -> AppCtxt -> AppCtxt
    
    341
    -    set l (VACall f n _)          = VACall f n (locA l)
    
    342
    -
    
    343
    -    dec :: EpAnn ann -> AppCtxt -> AppCtxt
    
    344
    -    dec l (VACall f n _)          = VACall f (n-1) (locA l)
    
    345 319
     
    
    346 320
     -- | Rebuild an application: takes a type-checked application head
    
    347 321
     -- expression together with arguments in the form of typechecked 'HsExprArg's
    
    ... ... @@ -545,13 +519,12 @@ tcInferAppHead_maybe fun =
    545 519
           HsOverLit _ lit             -> Just <$> tcInferOverLit lit
    
    546 520
           _                           -> return Nothing
    
    547 521
     
    
    548
    -addHeadCtxt :: AppCtxt -> TcM a -> TcM a
    
    549
    -addHeadCtxt fun_ctxt thing_inside
    
    522
    +addHeadCtxt :: AppCtxt -> TcM a -> TcM a --TODO ANI: Why not just setSrcSpan?
    
    523
    +addHeadCtxt fun_loc thing_inside
    
    550 524
       | not (isGoodSrcSpan fun_loc)       -- noSrcSpan => no arguments
    
    551 525
       = thing_inside                      -- => context is already set
    
    552 526
       | otherwise
    
    553 527
       = setSrcSpan fun_loc thing_inside
    
    554
    -  where fun_loc = appCtxtLoc fun_ctxt
    
    555 528
     
    
    556 529
     
    
    557 530
     {- *********************************************************************
    

  • compiler/GHC/Tc/Utils/Monad.hs
    ... ... @@ -1730,6 +1730,7 @@ mkErrCtxt env ctxts
    1730 1730
     --          else go dbg 0 env ctxts
    
    1731 1731
      = go False 0 env ctxts -- regular error ctx
    
    1732 1732
      where
    
    1733
    +   go :: Bool -> Int -> TidyEnv -> [ErrCtxt] -> TcM [ErrCtxtMsg]
    
    1733 1734
        go _ _ _   [] = return []
    
    1734 1735
        go dbg n env ((is_landmark, ctxt) : ctxts)
    
    1735 1736
          | is_landmark || n < mAX_CONTEXTS -- Too verbose || dbg
    

  • testsuite/tests/indexed-types/should_fail/T5439.stderr
    1
    -
    
    2 1
     T5439.hs:83:33: error: [GHC-83865]
    
    3 2
         • Couldn't match expected type: Attempt (HElemOf rs)
    
    4 3
                       with actual type: Attempt (HHead (HDrop n0 l0))
    
    ... ... @@ -6,8 +5,7 @@ T5439.hs:83:33: error: [GHC-83865]
    6 5
         • Probable cause: ‘($)’ is applied to too few arguments
    
    7 6
           In the second argument of ‘($)’, namely
    
    8 7
             ‘inj $ Failure (e :: SomeException)’
    
    9
    -      In a stmt of a 'do' block:
    
    10
    -        c <- complete ev $ inj $ Failure (e :: SomeException)
    
    8
    +      In the expression: complete ev $ inj $ Failure (e :: SomeException)
    
    11 9
           In the expression:
    
    12 10
             do c <- complete ev $ inj $ Failure (e :: SomeException)
    
    13 11
                return $ c || not first
    
    ... ... @@ -28,5 +26,5 @@ T5439.hs:83:39: error: [GHC-83865]
    28 26
             ‘Failure (e :: SomeException)’
    
    29 27
           In the second argument of ‘($)’, namely
    
    30 28
             ‘inj $ Failure (e :: SomeException)’
    
    31
    -      In a stmt of a 'do' block:
    
    32
    -        c <- complete ev $ inj $ Failure (e :: SomeException)
    29
    +      In the expression: complete ev $ inj $ Failure (e :: SomeException)
    
    30
    +