Apoorv Ingle pushed to branch wip/ani/kill-popErrCtxt at Glasgow Haskell Compiler / GHC
Commits:
-
106e67d2
by Apoorv Ingle at 2025-09-22T08:14:06-05:00
5 changed files:
- compiler/GHC/Rename/Utils.hs
- compiler/GHC/Tc/Gen/Do.hs
- compiler/GHC/Tc/Gen/Head.hs
- compiler/GHC/Tc/Types/LclEnv.hs
- compiler/GHC/Tc/Utils/Monad.hs
Changes:
| ... | ... | @@ -20,7 +20,7 @@ module GHC.Rename.Utils ( |
| 20 | 20 | DeprecationWarnings(..), warnIfDeprecated,
|
| 21 | 21 | checkUnusedRecordWildcard,
|
| 22 | 22 | badQualBndrErr, typeAppErr, badFieldConErr,
|
| 23 | - wrapGenSpan, genHsVar, genLHsVar, genHsApp, genHsApps, genHsApps', genHsExpApps,
|
|
| 23 | + wrapGenSpan, wrapNoSpan, genHsVar, genLHsVar, genHsApp, genHsApps, genHsApps', genHsExpApps,
|
|
| 24 | 24 | genLHsApp, genAppType,
|
| 25 | 25 | genLHsLit, genHsIntegralLit, genHsTyLit, genSimpleConPat,
|
| 26 | 26 | genVarPat, genWildPat,
|
| ... | ... | @@ -706,6 +706,12 @@ wrapGenSpan :: (HasAnnotation an) => a -> GenLocated an a |
| 706 | 706 | -- See Note [Rebindable syntax and XXExprGhcRn]
|
| 707 | 707 | wrapGenSpan x = L (noAnnSrcSpan generatedSrcSpan) x
|
| 708 | 708 | |
| 709 | +wrapNoSpan :: (HasAnnotation an) => a -> GenLocated an a
|
|
| 710 | +-- Wrap something in a "noSrcSpan"
|
|
| 711 | +-- See Note [Rebindable syntax and XXExprGhcRn]
|
|
| 712 | +wrapNoSpan x = L (noAnnSrcSpan noSrcSpan) x
|
|
| 713 | + |
|
| 714 | + |
|
| 709 | 715 | -- | Make a 'SyntaxExpr' from a 'Name' (the "rn" is because this is used in the
|
| 710 | 716 | -- renamer).
|
| 711 | 717 | mkRnSyntaxExpr :: Name -> SyntaxExprRn
|
| ... | ... | @@ -18,7 +18,7 @@ module GHC.Tc.Gen.Do (expandDoStmts) where |
| 18 | 18 | |
| 19 | 19 | import GHC.Prelude
|
| 20 | 20 | |
| 21 | -import GHC.Rename.Utils ( wrapGenSpan, genHsExpApps, genHsApp, genHsLet,
|
|
| 21 | +import GHC.Rename.Utils ( wrapGenSpan, wrapNoSpan, genHsExpApps, genHsApp, genHsLet,
|
|
| 22 | 22 | genHsLamDoExp, genHsCaseAltDoExp, genWildPat )
|
| 23 | 23 | import GHC.Rename.Env ( irrefutableConLikeRn )
|
| 24 | 24 | |
| ... | ... | @@ -126,7 +126,7 @@ expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ e (SyntaxExprRn then_op) _)) |
| 126 | 126 | -- e ; stmts ~~> (>>) e stmts'
|
| 127 | 127 | do expand_stmts_expr <- expand_do_stmts doFlavour lstmts
|
| 128 | 128 | let expansion = genHsExpApps then_op -- (>>)
|
| 129 | - [ e
|
|
| 129 | + [ e -- Span is set becuase of statement loc
|
|
| 130 | 130 | , expand_stmts_expr ]
|
| 131 | 131 | return $ L loc (mkExpandedStmt stmt doFlavour expansion)
|
| 132 | 132 |
| ... | ... | @@ -1109,5 +1109,4 @@ addExprCtxt e thing_inside |
| 1109 | 1109 | -- f x = _
|
| 1110 | 1110 | -- when we don't want to say "In the expression: _",
|
| 1111 | 1111 | -- because it is mentioned in the error message itself
|
| 1112 | - XExpr (ExpandedThingRn o _) -> setInGeneratedCode o thing_inside
|
|
| 1113 | 1112 | _ -> addErrCtxt (ExprCtxt e) thing_inside -- no op in generated code |
| ... | ... | @@ -25,6 +25,7 @@ module GHC.Tc.Types.LclEnv ( |
| 25 | 25 | , setLclEnvSrcCodeOrigin
|
| 26 | 26 | , setLclCtxtSrcCodeOrigin
|
| 27 | 27 | , lclEnvInGeneratedCode
|
| 28 | + , setLclCtxtInGenCode
|
|
| 28 | 29 | |
| 29 | 30 | , addLclEnvErrCtxt
|
| 30 | 31 | |
| ... | ... | @@ -206,6 +207,9 @@ getLclEnvSrcCodeOrigin = get_src_code_origin . tcl_err_ctxt . tcl_lcl_ctxt |
| 206 | 207 | setLclEnvSrcCodeOrigin :: SrcCodeOrigin -> TcLclEnv -> TcLclEnv
|
| 207 | 208 | setLclEnvSrcCodeOrigin o = modifyLclCtxt (setLclCtxtSrcCodeOrigin o)
|
| 208 | 209 | |
| 210 | +setLclCtxtInGenCode :: TcLclCtxt -> TcLclCtxt
|
|
| 211 | +setLclCtxtInGenCode lclCtxt = lclCtxt { tcl_in_gen_code = True }
|
|
| 212 | + |
|
| 209 | 213 | -- See Note [ErrCtxt Stack Manipulation]
|
| 210 | 214 | setLclCtxtSrcCodeOrigin :: SrcCodeOrigin -> TcLclCtxt -> TcLclCtxt
|
| 211 | 215 | setLclCtxtSrcCodeOrigin o lclCtxt
|
| ... | ... | @@ -985,10 +985,10 @@ inGeneratedCode = lclEnvInGeneratedCode <$> getLclEnv |
| 985 | 985 | setSrcSpan :: SrcSpan -> TcRn a -> TcRn a
|
| 986 | 986 | -- See Note [Error contexts in generated code]
|
| 987 | 987 | setSrcSpan (RealSrcSpan loc _) thing_inside
|
| 988 | - = updLclCtxt (\env -> env { tcl_loc = loc }) thing_inside
|
|
| 988 | + = updLclCtxt (\env -> env { tcl_loc = loc, tcl_in_gen_code = False }) thing_inside
|
|
| 989 | 989 | |
| 990 | 990 | setSrcSpan (UnhelpfulSpan _) thing_inside
|
| 991 | - = thing_inside
|
|
| 991 | + = updLclCtxt setLclCtxtInGenCode thing_inside
|
|
| 992 | 992 | |
| 993 | 993 | getSrcCodeOrigin :: TcRn (Maybe SrcCodeOrigin)
|
| 994 | 994 | getSrcCodeOrigin = getLclEnvSrcCodeOrigin <$> getLclEnv
|
| ... | ... | @@ -999,6 +999,7 @@ getSrcCodeOrigin = getLclEnvSrcCodeOrigin <$> getLclEnv |
| 999 | 999 | -- See Note [Error Context Stack]
|
| 1000 | 1000 | setInGeneratedCode :: SrcCodeOrigin -> TcRn a -> TcRn a
|
| 1001 | 1001 | setInGeneratedCode sco thing_inside =
|
| 1002 | + updLclCtxt setLclCtxtInGenCode $
|
|
| 1002 | 1003 | updLclCtxt (setLclCtxtSrcCodeOrigin sco) thing_inside
|
| 1003 | 1004 | |
| 1004 | 1005 | setSrcSpanA :: EpAnn ann -> TcRn a -> TcRn a
|