[Git][ghc/ghc][wip/spj-apporv-Oct24] 2 commits: accept callstack001 testcase
Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC Commits: 9cce15d0 by Apoorv Ingle at 2026-03-20T12:26:42-05:00 accept callstack001 testcase - - - - - 46d715bf by Apoorv Ingle at 2026-03-20T12:27:15-05:00 update Note to include HsExpansion - - - - - 2 changed files: - compiler/GHC/Tc/Gen/Expr.hs - testsuite/tests/profiling/should_run/callstack001.stdout Changes: ===================================== compiler/GHC/Tc/Gen/Expr.hs ===================================== @@ -572,7 +572,8 @@ tcExpr (HsDo _ do_or_lc stmts) res_ty = do hse <- expandDoStmts do_or_lc stmts tcHsExpansion hse res_ty | otherwise - -- ListComp, MonadComp are handled by tcDoStmts + -- ListComp and MonadComp are handled by legacy tcDoStmts for now, + -- The ultimate goal is to handle them via expandDoStmts. -- GHCiStmts are handled completely separate = tcDoStmts do_or_lc stmts res_ty @@ -786,15 +787,16 @@ directly, it's much easier to * Expand (or desugar) the code to something simpler * Typecheck that simpler expression -Example: record updates. The typechecker looks like this: +Example: Typechecking the do expression. The typechecker looks (somewhat) like this: - tcExpr e@(HsDo{}) rho = do { ee <- expandExpr e - ; tcExpr ee rho } + tcExpr e@(HsDo _ stmts) rho = do { hse <- expandDoStmts stmts + ; tcHsExpansion hse rho } -The `expandExpr` replaces the HsDo { x <- e1; return x } +The `expandDoStmts` replaces the HsDo { x <- e1; return x } with something like - e1 >>= \ x -> x -and we then typecheck the latter. + HSE { hs_ctxt = e + , expanded_expr = e1 >>= \ x -> x } +and we then typecheck the expression `e1 >>= \ x -> x` See also Note [Handling overloaded and rebindable constructs] and Note [Doing XXExprGhcRn in the Renamer vs Typechecker] @@ -806,8 +808,8 @@ The rest of this Note explains how that is done. * The expansion process typically takes a user written thing L lspan ue and returns - L lspan (XExpr (ExpandedThingRn { xrn_orig = ue - , xrn_expanded = ee } )) + L lspan (XExpr (ExpandedThingRn (HSE { hs_ctxt = ue + , expanded_expr = ee } )) where `ee` is the expansion of the user written thing `ue` * The type checker context has 3 key fields that describe the context: @@ -824,30 +826,29 @@ The rest of this Note explains how that is done. The `tcl_in_gen_code` is a boolean that keeps track of whether the current expression being typechecked is compiler generated or user generated. + INVARIANT: `tcl_in_gen_code` is modified only in `setSrcSpan`. - The `tcl_in_gen_code` is a boolean that keeps track of whether - the current expression being typechecked is compiler generated - or user generated. * Now, when tcMonoLExpr :: LHsExpr GhcRn -> ExpRhoType -> TcM (HsExpr GhcTc) gets a located expression, it does 2 things: - * Calls `addLExprCtxt` to perform error context management - * Calls `tcExpr` to typecheck the expression. + (a) Calls `addLExprCtxt` to perform error context management + (b) Calls `tcExpr` to typecheck the expression. -* `addLExprCtxt span expr` +(a) `addLExprCtxt span expr` (1) updates the location of `tcl_loc` with the `span` above, (2) adds an `ErrCtxt` on top of the `tcl_err_ctxt`. * However, if the `span` is generated (see `isGeneratedSrcSpan`), then - `addLExprCtxt` is a no-op. Crucially, when we generate code in `expandExpr`, + `addLExprCtxt` sets `tcl_in_gen_code` to `True` via a call to `setSrcSpan` + and the `tcl_err_ctxt` is left untouched. Crucially, when we generate code in `expandExpr`, all the generated AST notes are tagged with a `GeneratedSrcSpan`. This is how we avoid populating the TcLclCtxt with generated code. -* The type checker error-stack element `GHC.Tc.Types.ErrCtxt.ErrCtxt` - type ErrCtxt = HsCtxt +* The type checker error-stack element `GHC.Tc.Types.ErrCtxt.HsCtxt` + just stores an error message - just stores an error message + type ErrCtxt = HsCtxt When called on an `XExpr`, `addLExprCtxt`, adds the user written thing `ue`, and the error message provided by the caller on the `ErrCtxtStack` See @@ -857,10 +858,9 @@ The rest of this Note explains how that is done. tcHsExpansion :: HsExpansion GhcRn -> ExpRhoType -> TcM (HsExpr GhcTc) tcHsExpansion (HSE o e) res_ty - = mkExpandedTc o <$> -- necessary for hpc ticks - -- Need to call tcExpr and not tcApp - -- as e can be let statement which tcApp cannot gracefully handle - tcMonoLExpr e res_ty + = do e' <- tcMonoLExpr e res_ty + return $ XExpr HSE o e' + {- ************************************************************************ ===================================== testsuite/tests/profiling/should_run/callstack001.stdout ===================================== @@ -1,2 +1,2 @@ -["GHC.Internal.TopHandler.runMainIO1 (<no location info>)","Main.main (callstack001.hs:17:8-21)","Main.mapM (callstack001.hs:10:13-17)","Main.mapM.go (callstack001.hs:(12,21)-(15,25))","Main.mapM.go (callstack001.hs:13:17-19)","Main.f (callstack001.hs:7:7-49)","Main.f (callstack001.hs:7:10-35)","GHC.Internal.Base.>>= (libraries/ghc-internal/src/GHC/Internal/Base.hs:1347:5-55)","GHC.Internal.Base.$fMonadIO1 (<no location info>)","GHC.Internal.Stack.CCS.currentCallStack (libraries/ghc-internal/src/GHC/Internal/Stack/CCS.hsc:129:1-16)","GHC.Internal.Stack.CCS.currentCallStack1 (<no location info>)"] -["GHC.Internal.TopHandler.runMainIO1 (<no location info>)","Main.main (callstack001.hs:17:8-21)","Main.mapM (callstack001.hs:10:13-17)","Main.mapM.go (callstack001.hs:(12,21)-(15,25))","GHC.Internal.Base.>>= (libraries/ghc-internal/src/GHC/Internal/Base.hs:1347:5-55)","GHC.Internal.Base.$fMonadIO1 (<no location info>)","GHC.Internal.Stack.CCS.currentCallStack (libraries/ghc-internal/src/GHC/Internal/Stack/CCS.hsc:129:1-16)","GHC.Internal.Stack.CCS.currentCallStack1 (<no location info>)"] +["GHC.Internal.TopHandler.runMainIO1 (<no location info>)","Main.main (callstack001.hs:17:8-21)","Main.mapM (callstack001.hs:10:13-17)","Main.mapM.go (callstack001.hs:(12,21)-(15,25))","Main.mapM.go (callstack001.hs:13:11-19)","Main.mapM.go (callstack001.hs:13:17-19)","Main.f (callstack001.hs:7:7-49)","Main.f (callstack001.hs:7:10-35)","GHC.Internal.Base.>>= (libraries/ghc-internal/src/GHC/Internal/Base.hs:1347:5-55)","GHC.Internal.Base.$fMonadIO1 (<no location info>)","GHC.Internal.Stack.CCS.currentCallStack (libraries/ghc-internal/src/GHC/Internal/Stack/CCS.hsc:129:1-16)","GHC.Internal.Stack.CCS.currentCallStack1 (<no location info>)"] +["GHC.Internal.TopHandler.runMainIO1 (<no location info>)","Main.main (callstack001.hs:17:8-21)","Main.mapM (callstack001.hs:10:13-17)","Main.mapM.go (callstack001.hs:(12,21)-(15,25))","Main.mapM.go (callstack001.hs:13:11-19)","GHC.Internal.Base.>>= (libraries/ghc-internal/src/GHC/Internal/Base.hs:1347:5-55)","GHC.Internal.Base.$fMonadIO1 (<no location info>)","GHC.Internal.Stack.CCS.currentCallStack (libraries/ghc-internal/src/GHC/Internal/Stack/CCS.hsc:129:1-16)","GHC.Internal.Stack.CCS.currentCallStack1 (<no location info>)"] \ No newline at end of file View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7d2a15c1226cfa12c0df3b011d91d73... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7d2a15c1226cfa12c0df3b011d91d73... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Apoorv Ingle (@ani)