Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC
Commits:
-
f85de9bd
by Apoorv Ingle at 2025-11-25T12:13:25-06:00
3 changed files:
Changes:
| ... | ... | @@ -385,7 +385,7 @@ Unify result type /before/ typechecking the args |
| 385 | 385 | Actual: String
|
| 386 | 386 | • In the first argument of ‘Pair’, namely ‘"yes"’
|
| 387 | 387 | |
| 388 | -The latter is much better. That is why we call checkResultType before tcValArgs.
|
|
| 388 | +The latter is much better. That is why we call `checkResultTy` before tcValArgs.
|
|
| 389 | 389 | -}
|
| 390 | 390 | -- CAUTION: Any changes to tcApp should be reflected in tcExprSigma
|
| 391 | 391 | tcApp :: HsExpr GhcRn
|
| ... | ... | @@ -442,12 +442,13 @@ tcApp rn_expr exp_res_ty |
| 442 | 442 | -- See (TCAPP1) and (TCAPP2) in
|
| 443 | 443 | -- Note [tcApp: typechecking applications]
|
| 444 | 444 | |
| 445 | + ; ds_flag <- getDeepSubsumptionFlag_DataConHead tc_fun
|
|
| 445 | 446 | ; case do_ql of
|
| 446 | 447 | NoQL -> do { traceTc "tcApp:NoQL" (ppr rn_fun $$ ppr app_res_rho)
|
| 447 | 448 | |
| 448 | 449 | -- Step 4.1: subsumption check against expected result type
|
| 449 | 450 | -- See Note [Unify with expected type before typechecking arguments]
|
| 450 | - ; res_wrap <- checkResultTy rn_expr tc_head inst_args
|
|
| 451 | + ; res_wrap <- checkResultTy ds_flag rn_expr tc_head inst_args
|
|
| 451 | 452 | app_res_rho exp_res_ty
|
| 452 | 453 | -- Step 4.2: typecheck the arguments
|
| 453 | 454 | ; tc_args <- tcValArgs NoQL (rn_fun, fun_lspan) inst_args
|
| ... | ... | @@ -467,7 +468,7 @@ tcApp rn_expr exp_res_ty |
| 467 | 468 | ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
|
| 468 | 469 | |
| 469 | 470 | -- Step 5.4: subsumption check against the expected type
|
| 470 | - ; res_wrap <- checkResultTy rn_expr tc_head inst_args
|
|
| 471 | + ; res_wrap <- checkResultTy ds_flag rn_expr tc_head inst_args
|
|
| 471 | 472 | app_res_rho exp_res_ty
|
| 472 | 473 | -- Step 5.5: wrap up
|
| 473 | 474 | ; finishApp tc_head tc_args app_res_rho res_wrap } }
|
| ... | ... | @@ -527,27 +528,25 @@ finishApp tc_head@(tc_fun,_) tc_args app_res_rho res_wrap |
| 527 | 528 | |
| 528 | 529 | -- | Connect up the inferred type of an application with the expected type.
|
| 529 | 530 | -- This is usually just a unification, but with deep subsumption there is more to do.
|
| 530 | -checkResultTy :: HsExpr GhcRn
|
|
| 531 | +checkResultTy :: DeepSubsumptionFlag
|
|
| 532 | + -> HsExpr GhcRn
|
|
| 531 | 533 | -> (HsExpr GhcTc, SrcSpan) -- Head
|
| 532 | 534 | -> [HsExprArg p] -- Arguments, just error messages
|
| 533 | 535 | -> TcRhoType -- Inferred type of the application; zonked to
|
| 534 | 536 | -- expose foralls, but maybe not /deeply/ instantiated
|
| 535 | 537 | -> ExpRhoType -- Expected type; this is deeply skolemised
|
| 536 | 538 | -> TcM HsWrapper
|
| 537 | -checkResultTy rn_expr (fun, _) _inst_args app_res_rho (Infer inf_res)
|
|
| 538 | - = do { ds_flag <- getDeepSubsumptionFlag_DataConHead fun
|
|
| 539 | - ; fillInferResult ds_flag (exprCtOrigin rn_expr) app_res_rho inf_res
|
|
| 540 | - }
|
|
| 539 | +checkResultTy ds_flag rn_expr (fun, _) _inst_args app_res_rho (Infer inf_res)
|
|
| 540 | + = fillInferResult ds_flag (exprCtOrigin rn_expr) app_res_rho inf_res
|
|
| 541 | 541 | |
| 542 | -checkResultTy rn_expr (tc_fun, fun_loc) inst_args app_res_rho (Check res_ty)
|
|
| 542 | +checkResultTy ds_flag rn_expr (tc_fun, fun_loc) inst_args app_res_rho (Check res_ty)
|
|
| 543 | 543 | -- Unify with expected type from the context
|
| 544 | 544 | -- See Note [Unify with expected type before typechecking arguments]
|
| 545 | 545 | --
|
| 546 | 546 | -- Match up app_res_rho: the result type of rn_expr
|
| 547 | 547 | -- with res_ty: the expected result type
|
| 548 | 548 | = perhaps_add_res_ty_ctxt $
|
| 549 | - do { ds_flag <- getDeepSubsumptionFlag_DataConHead tc_fun
|
|
| 550 | - ; traceTc "checkResultTy {" $
|
|
| 549 | + do { traceTc "checkResultTy {" $
|
|
| 551 | 550 | vcat [ text "tc_fun:" <+> ppr tc_fun
|
| 552 | 551 | , text "app_res_rho:" <+> ppr app_res_rho
|
| 553 | 552 | , text "res_ty:" <+> ppr res_ty
|
| ... | ... | @@ -695,7 +694,7 @@ tcValArg _ pos (fun, fun_lspan) (EValArgQL { |
| 695 | 694 | |
| 696 | 695 | ; tc_args <- tcValArgs DoQL (rn_fun, snd tc_head) inst_args
|
| 697 | 696 | ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
|
| 698 | - ; res_wrap <- checkResultTy rn_expr tc_head inst_args
|
|
| 697 | + ; res_wrap <- checkResultTy ds_flag rn_expr tc_head inst_args
|
|
| 699 | 698 | app_res_rho (mkCheckExpType exp_arg_rho)
|
| 700 | 699 | ; finishApp tc_head tc_args app_res_rho res_wrap }
|
| 701 | 700 |
| ... | ... | @@ -21,7 +21,8 @@ module GHC.Tc.Gen.Expr |
| 21 | 21 | tcInferRho, tcInferRhoNC,
|
| 22 | 22 | tcMonoLExpr, tcMonoLExprNC,
|
| 23 | 23 | tcInferRhoFRR, tcInferRhoFRRNC,
|
| 24 | - tcPolyLExpr, tcPolyExpr, tcExpr, tcPolyLExprSig,
|
|
| 24 | + tcPolyLExpr, tcPolyLExprSig, tcPolyLExprNC,
|
|
| 25 | + tcPolyExpr, tcExpr,
|
|
| 25 | 26 | tcSyntaxOp, tcSyntaxOpGen, SyntaxOpType(..), synKnownType,
|
| 26 | 27 | tcCheckId,
|
| 27 | 28 | ) where
|
| ... | ... | @@ -120,7 +121,7 @@ tcCheckPolyExprNC expr res_ty = tcPolyLExprNC expr (mkCheckExpType res_ty) |
| 120 | 121 | -----------------
|
| 121 | 122 | -- These versions take an ExpType
|
| 122 | 123 | tcPolyLExpr, tcPolyLExprNC :: LHsExpr GhcRn -> ExpSigmaType
|
| 123 | - -> TcM (LHsExpr GhcTc)
|
|
| 124 | + -> TcM (LHsExpr GhcTc)
|
|
| 124 | 125 | |
| 125 | 126 | tcPolyLExpr (L loc expr) res_ty
|
| 126 | 127 | = addLExprCtxt (locA loc) expr $ -- Note [Error contexts in generated code]
|
| ... | ... | @@ -269,8 +269,6 @@ splitHsApps e = go e noSrcSpan [] |
| 269 | 269 | -- and its hard to say exactly what that is
|
| 270 | 270 | : EWrap (EExpand e)
|
| 271 | 271 | : args )
|
| 272 | - -- look through PopErrCtxt (cf. T17594f) we do not want to lose the opportunity of calling tcEValArgQL
|
|
| 273 | - -- unlike HsPar, it is okay to forget about the PopErrCtxts as it does not persist over in GhcTc land
|
|
| 274 | 272 | |
| 275 | 273 | go e lspan args = pure ((e, lspan), args)
|
| 276 | 274 | |
| ... | ... | @@ -1087,18 +1085,16 @@ mis-match in the number of value arguments. |
| 1087 | 1085 | add_expr_ctxt :: HsExpr GhcRn -> TcRn a -> TcRn a
|
| 1088 | 1086 | add_expr_ctxt e thing_inside
|
| 1089 | 1087 | = case e of
|
| 1090 | - HsHole _ -> thing_inside
|
|
| 1088 | + HsHole{} -> thing_inside
|
|
| 1091 | 1089 | -- The HsHole special case addresses situations like
|
| 1092 | 1090 | -- f x = _
|
| 1093 | 1091 | -- when we don't want to say "In the expression: _",
|
| 1094 | 1092 | -- because it is mentioned in the error message itself
|
| 1095 | 1093 | |
| 1096 | - HsPar _ e -> add_expr_ctxt (unLoc e) thing_inside
|
|
| 1094 | + HsPar{} -> thing_inside
|
|
| 1097 | 1095 | -- We don't want to say 'In the expression (e)',
|
| 1098 | 1096 | -- we just want to say 'In the expression, 'e'
|
| 1099 | 1097 | -- which will be handeled by the recursive call in thing_inside
|
| 1100 | - -- This may be a little inefficient with nested parens exprs, eg. (((e)))
|
|
| 1101 | - -- But it should be okay as I do not expect too many parens to be nested consecutively
|
|
| 1102 | 1098 | |
| 1103 | 1099 | ExprWithTySig _ (L _ e') _
|
| 1104 | 1100 | | XExpr (ExpandedThingRn o _) <- e' -> addExpansionErrCtxt o (ExprCtxt e)
|