[GHC] #16240: Core visible conditional compilation/static definition/code selection based upon static key values

#16240: Core visible conditional compilation/static definition/code selection based upon static key values -------------------------------------+------------------------------------- Reporter: carter | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.7 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: -------------------------------------+------------------------------------- currently the way we write haskell code to handle multiple platforms or configurations use the C preprocessor (CPP) in traditional mode. there are several challenges with this 1) tooling dependency 2) not actually designed for haskell code 3) no compiler support for checking the syntax / name / type well- formedness of each alternative code fragment under the associated environment assumptions. Abstractly, CPP uses a mapping from Names to Maybe (Either String Integer) or something to that effect. theres two ways we could then treat a "HPP" design: 1) just like CPP traditional mode, its just splicing tokens together. a) One implication of this design choice would be that to be able to check/ parse the different combinations of compilation, you'd need to be able to enumerate the set of maps of key value pairs of interest, and then you'd roughly want to have each Module be actually a {{{ Map (Map String (Maybe (Either String Integer))) Module) }}} this would have some pretty obvious code blowup issues, at least if you wanted to full on type check each combination in full. 2) only allow "HPP" to work on valid syntactic units, eg expressions, right hand sides, patterns, top level definition, etc, and provide a magic primop or several that would look roughly like NOTE: it could also just be at the Haskell post type inference phase, not necessarily at core level {{{ DefinitionDispatchTermLevel :: [(Map String (Maybe (Either String Integer)) , CoreTerm)] -> --- set of all #if/else/ifdef etc conditionals? Map (String) (Maybe (Either String Integer)) -> -- actual CPP flag combination used CoreTerm -> --- actual term ghc / optimizer works with and manipulates CoreTerm }}} this sketched out constructor representation overlooks a few things, eg the ability to do interval predicates and various boolean algebra operations, which WOULD be expressible in a fully fleshed out approch to this, but i'm elliding to keep simple. i think approach (1) or something like it would have the benefit of mostly working "today" wrt how we use CPP, and checking/coverage could be done via some package level or module level enumeration of cpp value mappings that you wnat to be checked or even generated approach (2) adds a funny looking operation to core/haskell terms/types representation where you could carry around "alternative expressions" plus the "selected expression". and thus you could do some amount of syntax/type checking for those altnerative platforms? either way, this is just me jotting down some thoughts on this because its been discussed on and off for a while now as an eventual nice to have for ghc. Also quite a complicated design space! :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16240 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16240: Core visible conditional compilation/static definition/code selection based upon static key values -------------------------------------+------------------------------------- Reporter: carter | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.7 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 carter): forgot to add: each map assignment would correspond to a different typing environment if we wanted to check types under each combination .. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16240#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16240: Core visible conditional compilation/static definition/code selection based upon static key values -------------------------------------+------------------------------------- Reporter: carter | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.7 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 AndreasK): Replying to [comment:1 carter]:
forgot to add: each map assignment would correspond to a different typing environment if we wanted to check types under each combination ..
There are valid use cases for CPP with code which doesn't compile/type check at all under one of the variants on a specific system. Primarily when libraries/ghc add new features and only the old version is available. Eg I don't see how this would be enough if a base version uses a different class definition for Monoid. You would need both definitions to type check both variants, which in general is not always possible. So ideally we want to support both: * Essentially string replacement * Typechecking of both variants. Unless you want to restrict HPP to certain use cases and fall back to CPP for other ones. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16240#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16240: Core visible conditional compilation/static definition/code selection based upon static key values -------------------------------------+------------------------------------- Reporter: carter | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.7 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 carter): agreed. I think "new style HPP" would probably involve ghc understanding that the predicates around eg GHC version and package version are "externally fixed" and cant be fudged/checked under a single GHC environment. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16240#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16240: Core visible conditional compilation/static definition/code selection based upon static key values -------------------------------------+------------------------------------- Reporter: carter | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.7 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: | -------------------------------------+------------------------------------- Changes (by alanz): * cc: alanz (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16240#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16240: Core visible conditional compilation/static definition/code selection based upon static key values -------------------------------------+------------------------------------- Reporter: carter | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.7 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 alanz): I think we should consider separately the operation of conditionals to enable/disable/switch out blocks of code, and the use of other (CPP) primitives such as `#define` as a shortcut for configuring code. I regard the former as "low-power" and potentially able to be manageable integrated into tooling, if we assume that the inactive block must meet some minimal syntactic requirements, but not necessarily be able to be fully parsed or type checked. The latter should be discouraged, and if needed fall back to CPP as we have now, with the understanding that certain classed of tooling are then not possible. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16240#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16240: Core visible conditional compilation/static definition/code selection based upon static key values -------------------------------------+------------------------------------- Reporter: carter | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.7 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 carter): after speaking with alanz on IRC a smidge, he's meaning "CPP as a support tool for portable code across platforms/configurations ghc versions", vs #define'd names/procedures as a poor mans macrosystem that lighter weight than TH and simpler to use/write this ticket is about the former, though its definitely true we would benefit from thinking about a decent macro systemy thing for syntactic abstraction -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16240#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16240: Core visible conditional compilation/static definition/code selection based upon static key values -------------------------------------+------------------------------------- Reporter: carter | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.7 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 carter): part of the intent / context is to make it easier for a single GHC compiler better able to check/(?compile) multiple platform targets -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16240#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16240: Core visible conditional compilation/static definition/code selection based upon static key values -------------------------------------+------------------------------------- Reporter: carter | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.7 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: | -------------------------------------+------------------------------------- Changes (by angerman): * cc: angerman (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16240#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC