[GHC] #14476: Keep source locations in Core (optionally)

#14476: Keep source locations in Core (optionally) -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The people working on liquid haskell have to maintain their own copy of the desugarer because of one little change they have to do: Add lots and lots of `CC`s to keep source spans around. Their current patch is {{{ diff --git a/src/Language/Haskell/Liquid/Desugar/DsExpr.hs b/src/Language/Haskell/Liquid/Desugar/DsExpr.hs index 396095e9a..9ba60c56f 100644 --- a/src/Language/Haskell/Liquid/Desugar/DsExpr.hs +++ b/src/Language/Haskell/Liquid/Desugar/DsExpr.hs @@ -221,14 +221,13 @@ dsUnliftedBind bind body = pprPanic "dsLet: unlifted" (ppr bind $$ ppr body) dsLExpr :: LHsExpr Id -> DsM CoreExpr dsLExpr (L loc e) - = putSrcSpanDs loc $ - do { core_expr <- dsExpr e - -- uncomment this check to test the hsExprType function in TcHsSyn - -- ; MASSERT2( exprType core_expr `eqType` hsExprType e - -- , ppr e <+> dcolon <+> ppr (hsExprType e) $$ - -- ppr core_expr <+> dcolon <+> ppr (exprType core_expr) ) - ; return core_expr } + = do ce <- putSrcSpanDs loc $ dsExpr e + m <- getModule + return $ Tick (srcSpanTick m loc) ce +srcSpanTick :: Module -> SrcSpan -> Tickish a +srcSpanTick m loc + = ProfNote (AllCafsCC m loc) False True -- | Variant of 'dsLExpr' that ensures that the result is not levity -- polymorphic. This should be used when the resulting expression will -- be an argument to some other function. }}} It would make their live easier if they could just use GHC’s desugarer, and it might open the path to making Liquid Haskell a proper GHC plugin instead of a separate program, which could facilitate adoption. Would it be ok to add a flag to GHC that enables this behaviour? Or is there another way of doing this? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14476 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14476: Keep source locations in Core (optionally) -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Can they not use `SourceNote` ticks instead? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14476#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14476: Keep source locations in Core (optionally) -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nomeata): I admit that I did not scrutinize the patch, nor do I personally know much about the various ticks. So feel free to phrase your input as propositions, not questions :-) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14476#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14476: Keep source locations in Core (optionally) -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Okay: I recommend they use `SourceNote`s instead of cost centers ;) That being said, we don't offer a terribly great way to communicate to GHC that it should add source notes. The only way currently is `-g` (corresponding to the `debugLevel` `DynFlags` field) however it also controls code generation so it may not be appropriate for a plugin. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14476#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14476: Keep source locations in Core (optionally) -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nomeata):
we don't offer a terribly great way to communicate to GHC that it should add source notes.
But a patch that adds a flag to do so would be reasonable, woundn’t it? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14476#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14476: Keep source locations in Core (optionally) -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): What semantics would this flag have? Just enable tick generation in desugar without enabling any of the codegen bits? There are a few questions: Should ticks be preserved in interface files in this case? STG? C--? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14476#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14476: Keep source locations in Core (optionally) -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Niki): So, @bgamari you are saying that if I run ghc with a hight enough `debugLevel` (is it just >2?), than CoreExpr will preserve all source info as `SourceNote` (inside the Ticks). I will try it in LH to see if it work, but for completeness, this is related to https://ghc.haskell.org/trac/ghc/ticket/10506 (that seem to be stale) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14476#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14476: Keep source locations in Core (optionally) -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): Yes, setting `debugLevel` to 2 is exactly what `-g` does. Setting it to 1,2 or 3, it doesn't matter as they all do the same thing. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14476#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC