Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC Commits: 21a0194e by Apoorv Ingle at 2025-11-10T00:51:08-06:00 kill PopErrCtxt - - - - - 5 changed files: - compiler/GHC/Hs/Expr.hs - compiler/GHC/Tc/Gen/App.hs - compiler/GHC/Tc/Types/ErrCtxt.hs - compiler/GHC/Tc/Types/LclEnv.hs - compiler/GHC/Tc/Types/Origin.hs Changes: ===================================== compiler/GHC/Hs/Expr.hs ===================================== @@ -676,12 +676,6 @@ data SrcCodeOrigin = OrigExpr (HsExpr GhcRn) -- ^ The source, user written, expression | OrigStmt (ExprLStmt GhcRn) HsDoFlavour -- ^ which kind of do-block did this statement come from | OrigPat (Pat GhcRn) -- ^ Used for failable patterns that trigger MonadFail constraints - | PopErrCtxt -- A hint for typechecker to pop - -- the top of the error context stack - -- Does not presist post renaming phase - -- See Part 3. of Note [Expanding HsDo with XXExprGhcRn] - -- in `GHC.Tc.Gen.Do` - -- INVARIANT: SHOULD NEVER APPEAR IN A ExpansionCodeCtxt in CodeSrcFlag ErrCtxt on stack data XXExprGhcRn = ExpandedThingRn { xrn_orig :: SrcCodeOrigin -- The original source thing to be used for error messages @@ -713,12 +707,6 @@ mkExpandedStmt mkExpandedStmt oStmt flav eExpr = XExpr (ExpandedThingRn { xrn_orig = OrigStmt oStmt flav , xrn_expanded = eExpr }) -mkExpandedLastStmt - :: HsExpr GhcRn -- ^ expanded expression - -> HsExpr GhcRn -- ^ suitably wrapped 'XXExprGhcRn' -mkExpandedLastStmt eExpr = XExpr (ExpandedThingRn { xrn_orig = PopErrCtxt - , xrn_expanded = eExpr }) - data XXExprGhcTc = WrapExpr -- Type and evidence application and abstractions HsWrapper (HsExpr GhcTc) @@ -1089,7 +1077,6 @@ instance Outputable SrcCodeOrigin where OrigExpr x -> ppr_builder "<OrigExpr>:" x OrigStmt x _ -> ppr_builder "<OrigStmt>:" x OrigPat x -> ppr_builder "<OrigPat>:" x - PopErrCtxt -> text "<PopErrCtxt>" where ppr_builder prefix x = ifPprDebug (braces (text prefix <+> parens (ppr x))) (ppr x) instance Outputable XXExprGhcRn where ===================================== compiler/GHC/Tc/Gen/App.hs ===================================== @@ -174,11 +174,12 @@ Note [Instantiation variables are short lived] -- cf. T19167. the head is an expanded expression applied to a type -- TODO: Use runInfer for tcExprSigma? -- Caution: Currently we assume that the expression is compiler generated/expanded --- Becuase that is that T19167 testcase generates. This function can possibly +-- Because that is that T19167 testcase generates. This function can possibly -- take in the rn_expr and its location to pass into tcValArgs tcExprSigma :: Bool -> HsExpr GhcRn -> TcM (HsExpr GhcTc, TcSigmaType) tcExprSigma inst rn_expr - = do { (fun@(rn_fun,fun_lspan), rn_args) <- splitHsApps rn_expr + = do { traceTc "tcExprSigma" (ppr rn_expr) + ; (fun@(rn_fun,fun_lspan), rn_args) <- splitHsApps rn_expr ; do_ql <- wantQuickLook rn_fun ; (tc_fun, fun_sigma) <- tcInferAppHead fun ; code_orig <- getSrcCodeOrigin @@ -611,6 +612,7 @@ tcValArg do_ql pos (fun, fun_lspan) (EValArg { ea_loc_span = lspan , text "fun_lspan" <+> ppr fun_lspan , text "sigma_type" <+> ppr (mkCheckExpType exp_arg_ty) , text "arg:" <+> ppr larg + , text "arg_loc:" <+> ppr arg_loc ] @@ -954,12 +956,16 @@ addArgCtxt :: Int -> (HsExpr GhcRn, SrcSpan) -> LHsExpr GhcRn -- See Note [Expanding HsDo with XXExprGhcRn] in GHC.Tc.Gen.Do addArgCtxt arg_no (app_head, app_head_lspan) (L arg_loc arg) thing_inside | isGoodSrcSpan app_head_lspan - = setSrcSpanA arg_loc $ - addErrCtxt (FunAppCtxt (FunAppCtxtExpr app_head arg) arg_no) $ - thing_inside + = do { traceTc "addArgCtxt" (vcat [text "goodSrcSpan", ppr app_head, ppr app_head_lspan, ppr arg_loc, ppr arg, ppr arg_no]) + ; setSrcSpanA arg_loc $ + addErrCtxt (FunAppCtxt (FunAppCtxtExpr app_head arg) arg_no) $ + thing_inside + } | otherwise - = addLExprCtxt (locA arg_loc) arg $ - thing_inside + = do { traceTc "addArgCtxt" (vcat [text "generatedHead", ppr app_head, ppr app_head_lspan, ppr arg_loc, ppr arg]) + ; addLExprCtxt (locA arg_loc) arg $ + thing_inside + } @@ -1823,9 +1829,14 @@ quickLookArg1 pos app_lspan (fun, fun_lspan) larg@(L _ arg) sc_arg_ty@(Scaled _ -- step 2: use |-inst to instantiate the head applied to the arguments do { let tc_head = (tc_fun, fun_lspan) ; do_ql <- wantQuickLook rn_fun + ; code_orig <- getSrcCodeOrigin + ; let arg_orig | isGoodSrcSpan fun_lspan + = exprCtOrigin fun + | otherwise + = srcCodeOriginCtOrigin fun code_orig ; ((inst_args, app_res_rho), wanted) <- captureConstraints $ - tcInstFun do_ql True (exprCtOrigin arg, rn_fun, fun_lspan) tc_fun fun_sigma rn_args + tcInstFun do_ql True (arg_orig, rn_fun, fun_lspan) tc_fun fun_sigma rn_args -- We must capture type-class and equality constraints here, but -- not equality constraints. See (QLA6) in Note [Quick Look at -- value arguments] ===================================== compiler/GHC/Tc/Types/ErrCtxt.hs ===================================== @@ -234,4 +234,3 @@ srcCodeOriginErrCtxMsg :: SrcCodeOrigin -> ErrCtxtMsg srcCodeOriginErrCtxMsg (OrigExpr e) = ExprCtxt e srcCodeOriginErrCtxMsg (OrigStmt s f) = StmtErrCtxt (HsDoStmt f) (unLoc s) srcCodeOriginErrCtxMsg (OrigPat p) = PatCtxt p -srcCodeOriginErrCtxMsg (PopErrCtxt) = error "Shouldn't happen srcCodeOriginErr" ===================================== compiler/GHC/Tc/Types/LclEnv.hs ===================================== @@ -207,8 +207,6 @@ setLclEnvSrcCodeOrigin ec = modifyLclCtxt (setLclCtxtSrcCodeOrigin ec) -- See Note [ErrCtxt Stack Manipulation] setLclCtxtSrcCodeOrigin :: ErrCtxt -> TcLclCtxt -> TcLclCtxt setLclCtxtSrcCodeOrigin ec lclCtxt - | MkErrCtxt (ExpansionCodeCtxt PopErrCtxt) _ <- ec - = lclCtxt { tcl_err_ctxt = tail (tcl_err_ctxt lclCtxt) } | MkErrCtxt (ExpansionCodeCtxt _) _ : ecs <- tcl_err_ctxt lclCtxt , MkErrCtxt (ExpansionCodeCtxt _) _ <- ec = lclCtxt { tcl_err_ctxt = ec : ecs } ===================================== compiler/GHC/Tc/Types/Origin.hs ===================================== @@ -888,7 +888,6 @@ pprCtOrigin (ExpansionOrigin o) OrigExpr (ExplicitList{}) -> text "an overloaded list" OrigExpr (HsIf{}) -> text "an if-then-else expression" OrigExpr e -> text "the expression" <+> (ppr e) - PopErrCtxt -> text "Shouldn't Happen PopErrCtxt" pprCtOrigin (GivenSCOrigin sk d blk) = vcat [ ctoHerald <+> pprSkolInfo sk @@ -1121,7 +1120,6 @@ ppr_br (ExpansionOrigin (OrigExpr (HsIf{}))) = text "an if-then-else expression" ppr_br (ExpansionOrigin (OrigExpr e)) = text "an expression" <+> ppr e ppr_br (ExpansionOrigin (OrigStmt{})) = text "a do statement" ppr_br (ExpansionOrigin (OrigPat{})) = text "a do statement" -ppr_br (ExpansionOrigin PopErrCtxt) = text "SHOULDN'T HAPPEN POPERRORCTXT" ppr_br (ExpectedTySyntax o _) = ppr_br o ppr_br (ExpectedFunTySyntaxOp{}) = text "a rebindable syntax operator" ppr_br (ExpectedFunTyViewPat{}) = text "a view pattern" View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/21a0194e3967fc25698367d67d477789... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/21a0194e3967fc25698367d67d477789... You're receiving this email because of your account on gitlab.haskell.org.