Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC
Commits:
-
b61531f2
by Apoorv Ingle at 2025-06-23T17:42:30-05:00
5 changed files:
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/App.hs-boot
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Match.hs
- compiler/GHC/Tc/Types/Origin.hs
Changes:
... | ... | @@ -410,7 +410,6 @@ tcApp rn_expr exp_res_ty |
410 | 410 | vcat [ text "rn_expr:" <+> ppr rn_expr
|
411 | 411 | , text "rn_fun:" <+> ppr rn_fun
|
412 | 412 | , text "fun_loc:" <+> ppr fun_loc
|
413 | - , text "orig:" <+> ppr fun_orig
|
|
414 | 413 | , text "rn_args:" <+> ppr rn_args ]
|
415 | 414 | |
416 | 415 | -- Step 2: Infer the type of `fun`, the head of the application
|
... | ... | @@ -418,12 +417,13 @@ tcApp rn_expr exp_res_ty |
418 | 417 | ; let tc_head = (tc_fun, fun_loc)
|
419 | 418 | -- Step 3: Instantiate the function type (taking a quick look at args)
|
420 | 419 | ; do_ql <- wantQuickLook rn_fun
|
420 | + ; code_ctxt <- getSrcCodeCtxt
|
|
421 | + ; let fun_orig = srcCodeCtxtCtOrigin rn_fun code_ctxt
|
|
421 | 422 | ; traceTc "tcApp:inferAppHead" $
|
422 | 423 | vcat [ text "tc_fun:" <+> ppr tc_fun
|
423 | 424 | , text "fun_sigma:" <+> ppr fun_sigma
|
425 | + , text "fun_origin" <+> ppr fun_orig
|
|
424 | 426 | , text "do_ql:" <+> ppr do_ql]
|
425 | - ; code_ctxt <- getSrcCodeCtxt
|
|
426 | - ; let fun_orig = srcCodeCtxtCtOrigin rn_fun code_ctxt
|
|
427 | 427 | ; (inst_args, app_res_rho)
|
428 | 428 | <- tcInstFun do_ql True fun_orig (tc_fun, rn_fun, fun_loc) fun_sigma rn_args
|
429 | 429 | |
... | ... | @@ -857,7 +857,7 @@ tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args |
857 | 857 | -- Rule IARG from Fig 4 of the QL paper:
|
858 | 858 | go1 pos acc fun_ty
|
859 | 859 | (EValArg { ea_arg = arg, ea_ctxt = ctxt } : rest_args)
|
860 | - = do { let herald | DoOrigin <- fun_orig = ExpectedFunTySyntaxOp fun_orig tc_fun -- cf. RepPolyDoBind.hs
|
|
860 | + = do { let herald | DoStmtOrigin <- fun_orig = ExpectedFunTySyntaxOp fun_orig tc_fun -- cf. RepPolyDoBind.hs
|
|
861 | 861 | | otherwise = ExpectedFunTyArg (HsExprTcThing tc_fun) (unLoc arg)
|
862 | 862 | ; (wrap, arg_ty, res_ty) <-
|
863 | 863 | -- NB: matchActualFunTy does the rep-poly check.
|
... | ... | @@ -2,10 +2,9 @@ module GHC.Tc.Gen.App where |
2 | 2 | |
3 | 3 | import GHC.Hs ( HsExpr )
|
4 | 4 | import GHC.Tc.Types ( TcM )
|
5 | -import GHC.Tc.Types.Origin ( CtOrigin )
|
|
6 | 5 | import GHC.Tc.Utils.TcType ( TcSigmaType )
|
7 | 6 | import GHC.Hs.Extension ( GhcRn, GhcTc )
|
8 | 7 | |
9 | 8 | import GHC.Prelude (Bool)
|
10 | 9 | |
11 | -tcExprSigma :: Bool -> CtOrigin -> HsExpr GhcRn -> TcM (HsExpr GhcTc, TcSigmaType) |
|
\ No newline at end of file | ||
10 | +tcExprSigma :: Bool -> HsExpr GhcRn -> TcM (HsExpr GhcTc, TcSigmaType) |
|
\ No newline at end of file |
... | ... | @@ -114,10 +114,9 @@ tcCheckPolyExprNC expr res_ty = tcPolyLExprNC expr (mkCheckExpType res_ty) |
114 | 114 | tcPolyLExpr, tcPolyLExprNC :: LHsExpr GhcRn -> ExpSigmaType
|
115 | 115 | -> TcM (LHsExpr GhcTc)
|
116 | 116 | |
117 | -tcPolyLExpr e@(L loc expr) res_ty
|
|
118 | - = setUserCodeCtxt (ExprThing e) $
|
|
119 | - -- setSrcSpanA loc $ -- Set location /first/; see GHC.Tc.Utils.Monad
|
|
120 | - -- addExprCtxt expr $ -- Note [Error contexts in generated code]
|
|
117 | +tcPolyLExpr (L loc expr) res_ty
|
|
118 | + = setSrcSpanA loc $ -- Set location /first/; see GHC.Tc.Utils.Monad
|
|
119 | + addExprCtxt expr $ -- Note [Error contexts in generated code]
|
|
121 | 120 | do { expr' <- tcPolyExpr expr res_ty
|
122 | 121 | ; return (L loc expr') }
|
123 | 122 | |
... | ... | @@ -747,7 +746,7 @@ tcXExpr (PopErrCtxt e) res_ty |
747 | 746 | addExprCtxt e $
|
748 | 747 | tcExpr e res_ty
|
749 | 748 | |
750 | -tcXExpr xe@(ExpandedThingRn o e) res_ty
|
|
749 | +tcXExpr (ExpandedThingRn o e) res_ty
|
|
751 | 750 | = mkExpandedTc o <$> -- necessary for breakpoints
|
752 | 751 | do setInGeneratedCode o $
|
753 | 752 | tcExpr e res_ty
|
... | ... | @@ -980,7 +980,7 @@ tcDoStmt ctxt (BindStmt xbsrn pat rhs) res_ty thing_inside |
980 | 980 | -- in full generality; see #1537
|
981 | 981 | |
982 | 982 | ((rhs_ty, rhs', pat_mult, pat', new_res_ty, thing), bind_op')
|
983 | - <- tcSyntaxOp DoOrigin (xbsrn_bindOp xbsrn) [SynRho, SynFun SynAny SynRho] res_ty $
|
|
983 | + <- tcSyntaxOp DoStmtOrigin (xbsrn_bindOp xbsrn) [SynRho, SynFun SynAny SynRho] res_ty $
|
|
984 | 984 | \ [rhs_ty, pat_ty, new_res_ty] [rhs_mult,fun_mult,pat_mult] ->
|
985 | 985 | do { rhs' <-tcScalingUsage rhs_mult $ tcCheckMonoExprNC rhs rhs_ty
|
986 | 986 | ; (pat', thing) <- tcScalingUsage fun_mult $ tcCheckPat (StmtCtxt ctxt) pat (Scaled pat_mult pat_ty) $
|
... | ... | @@ -1004,7 +1004,7 @@ tcDoStmt _ (BodyStmt _ rhs then_op _) res_ty thing_inside |
1004 | 1004 | = do { -- Deal with rebindable syntax;
|
1005 | 1005 | -- (>>) :: rhs_ty -> new_res_ty -> res_ty
|
1006 | 1006 | ; ((rhs', rhs_ty, new_res_ty, thing), then_op')
|
1007 | - <- tcSyntaxOp DoOrigin then_op [SynRho, SynRho] res_ty $
|
|
1007 | + <- tcSyntaxOp DoStmtOrigin then_op [SynRho, SynRho] res_ty $
|
|
1008 | 1008 | \ [rhs_ty, new_res_ty] [rhs_mult,fun_mult] ->
|
1009 | 1009 | do { rhs' <- tcScalingUsage rhs_mult $ tcCheckMonoExprNC rhs rhs_ty
|
1010 | 1010 | ; thing <- tcScalingUsage fun_mult $ thing_inside (mkCheckExpType new_res_ty)
|
... | ... | @@ -1031,18 +1031,18 @@ tcDoStmt ctxt (RecStmt { recS_stmts = L l stmts, recS_later_ids = later_names |
1031 | 1031 | -- Unify the types of the "final" Ids (which may
|
1032 | 1032 | -- be polymorphic) with those of "knot-tied" Ids
|
1033 | 1033 | ; (_, ret_op')
|
1034 | - <- tcSyntaxOp DoOrigin ret_op [synKnownType tup_ty]
|
|
1034 | + <- tcSyntaxOp DoStmtOrigin ret_op [synKnownType tup_ty]
|
|
1035 | 1035 | inner_res_ty $ \_ _ -> return ()
|
1036 | 1036 | ; return (ret_op', tup_rets) }
|
1037 | 1037 | |
1038 | 1038 | ; ((_, mfix_op'), mfix_res_ty)
|
1039 | 1039 | <- tcInfer $ \ exp_ty ->
|
1040 | - tcSyntaxOp DoOrigin mfix_op
|
|
1040 | + tcSyntaxOp DoStmtOrigin mfix_op
|
|
1041 | 1041 | [synKnownType (mkVisFunTyMany tup_ty stmts_ty)] exp_ty $
|
1042 | 1042 | \ _ _ -> return ()
|
1043 | 1043 | |
1044 | 1044 | ; ((thing, new_res_ty), bind_op')
|
1045 | - <- tcSyntaxOp DoOrigin bind_op
|
|
1045 | + <- tcSyntaxOp DoStmtOrigin bind_op
|
|
1046 | 1046 | [ synKnownType mfix_res_ty
|
1047 | 1047 | , SynFun (synKnownType tup_ty) SynRho ]
|
1048 | 1048 | res_ty $
|
... | ... | @@ -1071,7 +1071,7 @@ tcDoStmt ctxt (XStmtLR (ApplicativeStmt _ pairs mb_join)) res_ty thing_inside |
1071 | 1071 | Nothing -> (, Nothing) <$> tc_app_stmts res_ty
|
1072 | 1072 | Just join_op ->
|
1073 | 1073 | second Just <$>
|
1074 | - (tcSyntaxOp DoOrigin join_op [SynRho] res_ty $
|
|
1074 | + (tcSyntaxOp DoStmtOrigin join_op [SynRho] res_ty $
|
|
1075 | 1075 | \ [rhs_ty] [rhs_mult] -> tcScalingUsage rhs_mult $ tc_app_stmts (mkCheckExpType rhs_ty))
|
1076 | 1076 | |
1077 | 1077 | ; return (XStmtLR $ ApplicativeStmt body_ty pairs' mb_join', thing) }
|
... | ... | @@ -1188,7 +1188,7 @@ tcApplicativeStmts ctxt pairs rhs_ty thing_inside |
1188 | 1188 | goOps _ [] = return []
|
1189 | 1189 | goOps t_left ((op,t_i,exp_ty) : ops)
|
1190 | 1190 | = do { (_, op')
|
1191 | - <- tcSyntaxOp DoOrigin op
|
|
1191 | + <- tcSyntaxOp DoStmtOrigin op
|
|
1192 | 1192 | [synKnownType t_left, synKnownType exp_ty] t_i $
|
1193 | 1193 | \ _ _ -> return ()
|
1194 | 1194 | ; t_i <- readExpType t_i
|
... | ... | @@ -588,7 +588,7 @@ data CtOrigin |
588 | 588 | -- See Note [Inferring the instance context]
|
589 | 589 | -- in GHC.Tc.Deriv.Infer
|
590 | 590 | | DefaultOrigin -- Typechecking a default decl
|
591 | - | DoOrigin -- Arising from a do expression
|
|
591 | + | DoStmtOrigin -- Arising from a do expression
|
|
592 | 592 | | DoPatOrigin (LPat GhcRn) -- Arising from a failable pattern in
|
593 | 593 | -- a do expression
|
594 | 594 | | MCompOrigin -- Arising from a monad comprehension
|
... | ... | @@ -746,7 +746,7 @@ exprCtOrigin (HsCase _ _ matches) = matchesCtOrigin matches |
746 | 746 | exprCtOrigin (HsIf {}) = IfThenElseOrigin
|
747 | 747 | exprCtOrigin (HsMultiIf _ rhs) = lGRHSCtOrigin rhs
|
748 | 748 | exprCtOrigin (HsLet _ _ e) = lexprCtOrigin e
|
749 | -exprCtOrigin (HsDo {}) = DoOrigin
|
|
749 | +exprCtOrigin (HsDo {}) = DoStmtOrigin
|
|
750 | 750 | exprCtOrigin (RecordCon {}) = Shouldn'tHappenOrigin "record construction"
|
751 | 751 | exprCtOrigin (RecordUpd {}) = RecordUpdOrigin
|
752 | 752 | exprCtOrigin (ExprWithTySig {}) = ExprSigOrigin
|
... | ... | @@ -769,7 +769,7 @@ exprCtOrigin (XExpr (HsRecSelRn f)) = OccurrenceOfRecSel (foExt f) |
769 | 769 | |
770 | 770 | hsThingCtOrigin :: HsThingRn -> CtOrigin
|
771 | 771 | hsThingCtOrigin (OrigExpr e) = exprCtOrigin e
|
772 | -hsThingCtOrigin (OrigStmt{}) = DoOrigin
|
|
772 | +hsThingCtOrigin (OrigStmt{}) = DoStmtOrigin
|
|
773 | 773 | hsThingCtOrigin (OrigPat p) = DoPatOrigin p
|
774 | 774 | |
775 | 775 | srcCodeCtxtCtOrigin :: HsExpr GhcRn -> SrcCodeCtxt -> CtOrigin
|
... | ... | @@ -940,7 +940,7 @@ pprCtO (ScOrigin (IsQC {}) _) = text "the head of a quantified constraint" |
940 | 940 | pprCtO DerivClauseOrigin = text "the 'deriving' clause of a data type declaration"
|
941 | 941 | pprCtO StandAloneDerivOrigin = text "a 'deriving' declaration"
|
942 | 942 | pprCtO DefaultOrigin = text "a 'default' declaration"
|
943 | -pprCtO DoOrigin = text "a do statement"
|
|
943 | +pprCtO DoStmtOrigin = text "a do statement"
|
|
944 | 944 | pprCtO MCompOrigin = text "a statement in a monad comprehension"
|
945 | 945 | pprCtO ProcOrigin = text "a proc expression"
|
946 | 946 | pprCtO ArrowCmdOrigin = text "an arrow command"
|