[GHC] #8488: Annotations should not distinguish type and value

#8488: Annotations should not distinguish type and value ------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- In `HsDecls` we have {{{ data AnnDecl name = HsAnnotation (AnnProvenance name) (Located (HsExpr name)) data AnnProvenance name = ValueAnnProvenance name | TypeAnnProvenance name | ModuleAnnProvenance }}} And there's now a similar 3-way distinction in Template Haskell `Syntax`: {{{ data AnnTarget = ModuleAnnotation | TypeAnnotation Name | ValueAnnotation Name }}} But there's really no need to distinguish between `TypeAnnProvenance` and `ValueAnnProvenance` (and similarly in the TH vesrion) because the namespace on the `Name` makes that distinction. So the current story is redundant, and hence has silly case where you have a `ValueAnnProvenance` on a type constructor. Better to collapse the two. I'm making this a ticket so that people can comment. I hope that Gergely may be able to do it as part of his TH/annotation work. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8488 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8488: Annotations should not distinguish type and value -------------------------------------+------------------------------------ Reporter: simonpj | Owner: errge Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by simonpj): * owner: => errge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8488#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8488: Annotations should not distinguish type and value -------------------------------------+------------------------------------ Reporter: simonpj | Owner: errge Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by errge): Actually the TH data type itself is not very clear in every case on what is a type and what is a value, but `TcSplice -> lookupThName` already handles the complexity, so I just have to call that. Seems straightforward, I will do it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8488#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8488: Annotations should not distinguish type and value -------------------------------------+------------------------------------ Reporter: simonpj | Owner: errge Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by errge): I looked into this today, but I got stuck. The issue is two fold. When doing the `HsDecls` change things almost work out, except for prettyprinting, because the current ppr code looks like this: {{{ pprAnnProvenance (ValueAnnProvenance name) = ptext (sLit "ANN") <+> ppr name pprAnnProvenance (TypeAnnProvenance name) = ptext (sLit "ANN type") <+> ppr name }}} So we use `ValueAnnProvenance` vs `TypeAnnProvenance` to decide if we have to print the type keyword after ANN. I tried to add HasOccName constraint at the pretty printer (because for an OccName we know the namespace), but that gets out of hand very quickly, since everywhere we just assume OutputableBndr now. And I was unsure at that point if it's feasible or not to add everywhere (`HsExpr`, `HsDecls`, etc.) HasOccName besides OutputableBndr. The another issue is on the template haskell side. Template Haskell `OccName` is just a `String`, not a `(String, NameSpace)` (maybe I should fix that, btw?). To compensate this mistake we have some heuristics in `TcSplice` to convert TH names to compiler names. Unfortunately this means that after the proposed change if the user has `data X = X`, it would be very hard for the user to put an annotation on the type and on the constructor both. They would have to resort to `NameG`s which are a bit hard to create and not straightforward at all. How should I go forward with this issues? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8488#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8488: Annotations should not distinguish type and value -------------------------------------+------------------------------------ Reporter: simonpj | Owner: errge Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): I'm not sure it's a mistake for TH to just use `String`. TH is meant to be close to Haskell source. And it might impact a lot of people to change this. I'm more open to adding `hasOccName` to `OutputableBndr`. But it seems like a sledgehammer to crack a nut. Unless there are other uses for it, it might be tidier to change `AnndDecl` thus: {{{ data AnnDecl Name = HsAnnotation Name NameSpace (Located (HsExpr name)) }}} with the invariant that the `NameSpace` should match that of the `Name`. That would remove a tiresome additional type, perhaps clarify the intent. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8488#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8488: Annotations should not distinguish type and value -------------------------------------+------------------------------------- Reporter: simonpj | Owner: errge Type: task | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thomie): * type: bug => task Comment: errge: what is the status of this? Still stuck? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8488#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC