[GHC] #12942: Add infix flag for class and data declarations

#12942: Add infix flag for class and data declarations -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: #3384 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- At the moment, data and type declarations using infix formatting produce the same AST as those using prefix. So {{{#!hs type a ++ b = c }}} and {{{#!hs type (++) a b = c }}} cannot be distinguished in the parsed source, without looking at the `OccName` details of the constructor being defined. Having access to the `OccName` requires an additional constraint which explodes out over the entire AST because of its recursive definitions. In keeping with moving the parsed source to more directly reflect the source code as parsed, add a specific flag to the declaration to indicate the fixity, as used in a `Match` now too. Note: this flag is to capture the fixity used for the lexical definition of the type, primarily for use by `ppr` and `ghc-exactprint`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12942 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12942: Add infix flag for class and data declarations -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3384 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I'm all for capturing the source syntax in the AST, so thumbs-up from me. I don't understand this comment though
Having access to the OccName requires an additional constraint which explodes out over the entire AST because of its recursive definitions.
I'm sure you are right, but what additional constraint? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12942#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12942: Add infix flag for class and data declarations -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3384 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by alanz): The additional `HasOccNameId`constraints were introduced in Phab:D2752, this patch should remove them again. E.g. {{{#!hs pp_vanilla_decl_head :: (OutputableBndrId name, HasOccNameId name) => Located name -> LHsQTyVars name -> HsContext name -> SDoc pp_vanilla_decl_head thing (HsQTvs { hsq_explicit = tyvars }) context = hsep [pprHsContext context, pp_tyvars tyvars] where pp_tyvars (varl:varsr) | isSymOcc $ occName (unLoc thing) = hsep [ppr (unLoc varl), pprInfixOcc (unLoc thing) , hsep (map (ppr.unLoc) varsr)] | otherwise = hsep [ pprPrefixOcc (unLoc thing) , hsep (map (ppr.unLoc) (varl:varsr))] pp_tyvars [] = ppr thing }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12942#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12942: Add infix flag for class and data declarations -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3384 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by alanz): And I just realised the issue statement is wrong, the constraints are on the `Outputable` instances for the AST, not the AST itself. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12942#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12942: Add infix flag for class and data declarations -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3384 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by alanz): And it seems the `HasOccName` constraint is also required for `pprMinimalSig`, via {{{#!hs pprBooleanFormulaNormal :: (Outputable a, HasOccName a) => BooleanFormula a -> SDoc pprBooleanFormulaNormal = go where go (Var x) = pprPrefixVar (isSymOcc (occName x)) (ppr x) ... }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12942#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12942: Add infix flag for class and data declarations -------------------------------------+------------------------------------- Reporter: alanz | Owner: mpickering Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3384 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * owner: alanz => mpickering Comment: I didn't notice this before but there is something wrong with this constraint and we should clean it up before someone forgets. The first thing which is wrong is that it already nearly exists in GHC and is called `NamedThing`, so we should just try to use that rather than this new class. The second thing, in both cases it is used to check whether a variable is an infix operator or not and then either calls `pprInfixOcc` or `pprPrefixOcc`. It would seem better to add a new method to `OutputableBndr` which also does this check rather than do it every time we need to know. Something like `pprInPos :: (SDoc -> SDoc) -> (SDoc -> SDoc) -> SDoc` where the two continuations describe how to deal with the two cases that the indentified is infix or prefix might be better. Another very good question is why `pprBooleanFormulaNormal` isn't parametrised by `OutputableBndr` as well when it very clearly outputs `Bndr`s. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12942#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12942: Add infix flag for class and data declarations -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3384 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * owner: mpickering => alanz -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12942#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12942: Add infix flag for class and data declarations -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3384 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by alanz): `NamedThing` has a method `getName :: a -> Name` which is meaningless in the `RdrName` case for the `ParsedSource`. I see that `OutputableBndr` has class methods `pprPrefixOcc, pprInfixOcc :: a -> SDoc` which will work for the `BooleanFormula` case. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12942#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12942: Add infix flag for class and data declarations -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: task | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3384 | Differential Rev(s): Phab:D2828 Wiki Page: | -------------------------------------+------------------------------------- Changes (by alanz): * differential: => Phab:D2828 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12942#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12942: Add infix flag for class and data declarations -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: task | Status: patch Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3384 | Differential Rev(s): Phab:D2828 Wiki Page: | -------------------------------------+------------------------------------- Changes (by alanz): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12942#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12942: Add infix flag for class and data declarations
-------------------------------------+-------------------------------------
Reporter: alanz | Owner: alanz
Type: task | Status: patch
Priority: normal | Milestone: 8.2.1
Component: Compiler | Version: 8.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #3384 | Differential Rev(s): Phab:D2828
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Alan Zimmerman

#12942: Add infix flag for class and data declarations -------------------------------------+------------------------------------- Reporter: alanz | Owner: alanz Type: task | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #3384 | Differential Rev(s): Phab:D2828 Wiki Page: | -------------------------------------+------------------------------------- Changes (by alanz): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12942#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC