[GHC] #10716: Metadata in GHC.Generic should give access to strictness annotation

#10716: Metadata in GHC.Generic should give access to strictness annotation -------------------------------------+------------------------------------- Reporter: StefanWehr | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- Currently, the metadata in the GHC.Generics module do not give access to the strictness annotations attached to a field of a datatype. It would be great if this piece of information could be added. Background: we are using a class FullyStrict for ensuring that a datatype is fully strict (in the sense that all fields have bang patterns and the types of all fields are also fully strict). Currently we are using TemplateHaskell to derive the instances automatically. The TemplateHaskell function also checks that all fields have bang patterns. To improve compilation speed, I would like to derive the instances with DeriveGeneric. But this is not possible because then I cannot implement the check whether all fields have bang patterns. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10716 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10716: Metadata in GHC.Generic should give access to strictness annotation -------------------------------------+------------------------------------- Reporter: StefanWehr | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 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 simonpj): * cc: adamgundry, kosmikus, goldfire (added) Comment: I'm all for it. Would you like to describe the design as seen by a user; and maybe offer a patch? Adding Andres to cc. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10716#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10716: Metadata in GHC.Generic should give access to strictness annotation -------------------------------------+------------------------------------- Reporter: StefanWehr | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by StefanWehr): == Extended API == A new class is added to `GHC.Generics`: {{{#!hs class StrictSelector s }}} This class has no methods; it only serves as a type-level constraint for a selector having a bang pattern. Also, I suggest changing the `NoSelector` type from `GHC.Generics` to accept a new type parameter: {{{#!hs data NoSelector t }}} The new type parameter is either `NoStrict` or `Strict`. These two types are also added to `GHC.Generics`: {{{#!hs data NoStrict data Strict }}} For anonymous selectors, we define an instance for `StrictSelector`: {{{#!hs instance StrictSelector (NoSelector Strict) }}} So far, this encodes strictness of a selector on the type-level. To access this information on the value-level, I suggest adding a new method to the type class `Selector` from `GHC.Generics`: {{{#!hs class Selector s where selName :: t s (f :: * -> *) a -> [Char] selIsStrict :: t s (f :: * -> *) a -> Bool -- NEW }}} My API proposal is not backwards compatible: the change to `NoSelector` will definitely break existing code, the addition of a new type class and two new data types might break existing code if the names are already used for something different. I tried avoiding the change to `NoSelector` but couldn't come up with a solution that brings the strictness (or lazyness) of a selector to the type-level. (For the application I have in mind, it's not enough to have these information on the value-level only.) == Changes to the deriving mechanism == The deriving mechanism for generics is extended in the following way: * replace occurrences of `NoSelector` with `NoSelector Strict` or `NoSelector NoStrict` * for named selectors carrying a bang pattern, generate an instance of `StrictSelector T`, where `T` is the type generated for the selector. I'm happy to provide a patch for this, but first I want to make sure that my design is reasonable. Any comments? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10716#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10716: Metadata in GHC.Generic should give access to strictness annotation -------------------------------------+------------------------------------- Reporter: StefanWehr | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by dreixel): Why can't we just add the `selIsStrict` part? To get the information at the type level we better do it for all meta-data at the same time, and we can get it when we make `GHC.Generics` use `DataKinds`, as described in https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/GenericDeriving#Ki... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10716#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10716: Metadata in GHC.Generic should give access to strictness annotation -------------------------------------+------------------------------------- Reporter: StefanWehr | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:1646 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:1646 Comment: I've submitted Phab:D1646, which implements this idea. I included a sketch of my ideas in this [https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/GenericDeriving#Pr... wiki page]. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10716#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10716: Metadata in GHC.Generic should give access to strictness annotation
-------------------------------------+-------------------------------------
Reporter: StefanWehr | Owner:
Type: feature request | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:1646
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#10716: Metadata in GHC.Generic should give access to strictness annotation -------------------------------------+------------------------------------- Reporter: StefanWehr | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:1646 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10716#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10716: Metadata in GHC.Generic should give access to strictness annotation -------------------------------------+------------------------------------- Reporter: StefanWehr | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:1646 Wiki Page: | -------------------------------------+------------------------------------- Comment (by StefanWehr): This is great news! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10716#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10716: Metadata in GHC.Generic should give access to strictness annotation -------------------------------------+------------------------------------- Reporter: StefanWehr | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: fixed | Keywords: Generics Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:1646 Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * keywords: => Generics -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10716#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC