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

Commits:

3 changed files:

Changes:

  • compiler/GHC/Tc/Gen/App.hs
    ... ... @@ -183,7 +183,7 @@ tcExprSigma inst rn_expr
    183 183
            ; (tc_fun, fun_sigma) <- tcInferAppHead fun
    
    184 184
            ; code_orig <- getSrcCodeOrigin
    
    185 185
            ; let fun_orig = srcCodeOriginCtOrigin rn_expr code_orig
    
    186
    -       ; (inst_args, app_res_sigma) <- tcInstFun do_ql inst fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
    
    186
    +       ; (inst_args, app_res_sigma) <- tcInstFun do_ql inst (fun_orig, rn_fun, fun_ctxt) tc_fun fun_sigma rn_args
    
    187 187
            ; tc_args <- tcValArgs do_ql (rn_fun, generatedSrcSpan) inst_args
    
    188 188
            ; let tc_expr = rebuildHsApps (tc_fun, fun_ctxt) tc_args
    
    189 189
            ; return (tc_expr, app_res_sigma) }
    
    ... ... @@ -424,14 +424,17 @@ tcApp rn_expr exp_res_ty
    424 424
     
    
    425 425
            -- Setp 3.2 Set the correct origin to blame for the error message
    
    426 426
            -- What should be the origin for this function call?
    
    427
    -       -- If we are in generated code, blame it on the
    
    427
    +       -- If the head of the function is user written
    
    428
    +       -- then it can be used in the error message
    
    429
    +       -- If it is generated code location span, blame it on the
    
    428 430
            -- source code origin stored in the lclEnv.
    
    429
    -       -- If not, the head of the function is user written
    
    430
    -       -- and can be used in the error message
    
    431 431
            -- See Note [Error contexts in generated code]
    
    432 432
            -- See Note [Error Context Stack]
    
    433 433
            ; code_orig <- getSrcCodeOrigin
    
    434
    -       ; let fun_orig = srcCodeOriginCtOrigin rn_fun code_orig
    
    434
    +       ; let fun_orig | isGoodSrcSpan fun_lspan
    
    435
    +                      = exprCtOrigin rn_fun
    
    436
    +                      | otherwise
    
    437
    +                      = srcCodeOriginCtOrigin rn_fun code_orig
    
    435 438
     
    
    436 439
            ; traceTc "tcApp:inferAppHead" $
    
    437 440
              vcat [ text "tc_fun:" <+> ppr tc_fun
    
    ... ... @@ -439,7 +442,7 @@ tcApp rn_expr exp_res_ty
    439 442
                   , text "fun_origin" <+> ppr fun_orig
    
    440 443
                   , text "do_ql:" <+> ppr do_ql]
    
    441 444
            ; (inst_args, app_res_rho)
    
    442
    -              <- tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_lspan) fun_sigma rn_args
    
    445
    +              <- tcInstFun do_ql inst_final (fun_orig, rn_fun, fun_lspan) tc_fun fun_sigma rn_args
    
    443 446
              -- See (TCAPP1) and (TCAPP2) in
    
    444 447
              -- Note [tcApp: typechecking applications]
    
    445 448
     
    
    ... ... @@ -699,15 +702,15 @@ tcInstFun :: QLFlag
    699 702
                         --           always return a rho-type (but not a deep-rho type)
    
    700 703
                         -- Generally speaking we pass in True; in Fig 5 of the paper
    
    701 704
                         --    |-inst returns a rho-type
    
    702
    -          -> CtOrigin
    
    703
    -          -> (HsExpr GhcTc, HsExpr GhcRn, SrcSpan) -- ANI: TODO, move HsExpr GhcRn, SrcSpan to CtOrigin
    
    705
    +          -> (CtOrigin, HsExpr GhcRn, SrcSpan)
    
    706
    +          -> HsExpr GhcTc -- ANI: TODO, move HsExpr GhcRn, SrcSpan to CtOrigin
    
    704 707
               -> TcSigmaType -> [HsExprArg 'TcpRn]
    
    705 708
               -> TcM ( [HsExprArg 'TcpInst]
    
    706 709
                      , TcSigmaType )   -- Does not instantiate trailing invisible foralls
    
    707 710
     -- This crucial function implements the |-inst judgement in Fig 4, plus the
    
    708 711
     -- modification in Fig 5, of the QL paper:
    
    709 712
     -- "A quick look at impredicativity" (ICFP'20).
    
    710
    -tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_lspan) fun_sigma rn_args
    
    713
    +tcInstFun do_ql inst_final (fun_orig, rn_fun, fun_lspan) tc_fun fun_sigma rn_args
    
    711 714
       = do { traceTc "tcInstFun" (vcat [ text "origin" <+> ppr fun_orig
    
    712 715
                                        , text "tc_fun" <+> ppr tc_fun
    
    713 716
                                        , text "fun_sigma" <+> ppr fun_sigma
    
    ... ... @@ -1819,7 +1822,7 @@ quickLookArg1 pos app_lspan (fun, fun_lspan) larg@(L _ arg) sc_arg_ty@(Scaled _
    1819 1822
            ; do_ql <- wantQuickLook rn_fun
    
    1820 1823
            ; ((inst_args, app_res_rho), wanted)
    
    1821 1824
                  <- captureConstraints $
    
    1822
    -                tcInstFun do_ql True (exprCtOrigin arg) (tc_fun, rn_fun, fun_lspan) fun_sigma rn_args
    
    1825
    +                tcInstFun do_ql True (exprCtOrigin arg, rn_fun, fun_lspan) tc_fun fun_sigma rn_args
    
    1823 1826
                     -- We must capture type-class and equality constraints here, but
    
    1824 1827
                     -- not equality constraints.  See (QLA6) in Note [Quick Look at
    
    1825 1828
                     -- value arguments]
    

  • compiler/GHC/Tc/Gen/Head.hs
    ... ... @@ -457,7 +457,7 @@ tcInferAppHead :: (HsExpr GhcRn, SrcSpan)
    457 457
     --
    
    458 458
     -- See Note [tcApp: typechecking applications] in GHC.Tc.Gen.App
    
    459 459
     tcInferAppHead (fun,fun_lspan)
    
    460
    -  = setSrcSpan fun_lspan $
    
    460
    +  = addLExprCtxt fun_lspan fun $
    
    461 461
         do { mb_tc_fun <- tcInferAppHead_maybe fun
    
    462 462
            ; case mb_tc_fun of
    
    463 463
                 Just (fun', fun_sigma) -> return (fun', fun_sigma)
    
    ... ... @@ -471,9 +471,10 @@ tcInferAppHead_maybe fun =
    471 471
         case fun of
    
    472 472
           HsVar _ nm                  -> Just <$> tcInferId nm
    
    473 473
           XExpr (HsRecSelRn f)        -> Just <$> tcInferRecSelId f
    
    474
    -      XExpr (ExpandedThingRn o e) -> Just <$> (addExpansionErrCtxt o (srcCodeOriginErrCtxMsg o) $
    
    474
    +      XExpr (ExpandedThingRn _ e) -> Just <$> -- (addExpansionErrCtxt o (srcCodeOriginErrCtxMsg o) $
    
    475 475
                                                   -- We do not want to instantiate c.f. T19167
    
    476
    -                                                    tcExprSigma False e)
    
    476
    +                                              tcExprSigma False e
    
    477
    +                                              -- )
    
    477 478
           ExprWithTySig _ e hs_ty     -> Just <$> tcExprWithSig e hs_ty
    
    478 479
           HsOverLit _ lit             -> Just <$> tcInferOverLit lit
    
    479 480
           _                           -> return Nothing
    

  • testsuite/tests/rebindable/rebindable6.stderr
    ... ... @@ -49,7 +49,7 @@ rebindable6.hs:111:17: error: [GHC-39999]
    49 49
                      return b
    
    50 50
     
    
    51 51
     rebindable6.hs:112:17: error: [GHC-39999]
    
    52
    -    • Ambiguous type variable ‘t1’ arising from a do statement
    
    52
    +    • Ambiguous type variable ‘t1’ arising from a use of ‘return’
    
    53 53
           prevents the constraint ‘(HasReturn (b -> t1))’ from being solved.
    
    54 54
           (maybe you haven't applied a function to enough arguments?)
    
    55 55
           Relevant bindings include