[GHC] #10970: Built in MIN_VERSION macro support

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 7.11 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: -------------------------------------+------------------------------------- Pursuant to https://mail.haskell.org/pipermail/ghc- devs/2015-September/010015.html Recapped here: when preprocessing Haskell source code, we generate a temporary stub header file which defines a number of MIN_VERSION macros, ala what Cabal generates today. Specifically, for every explicitly specified package dependency (via a `-package` or `-package-id` argument), we generate a `MIN_VERSION_pkgname` macro which tests for the version recorded for the package database. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 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:D1349 Wiki Page: | -------------------------------------+------------------------------------- Changes (by ezyang): * differential: => Phab:D1349 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support
-------------------------------------+-------------------------------------
Reporter: ezyang | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.11
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:D1349
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 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:D1349 Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): I think I may have unwittingly argued for this in the discussion on that mailing list thread, but I don't understand any more why it should be the case that we only create these macros for packages explicitly specified with `-package` or equivalent. Can't we treat the latest version of each package (or more generally, whichever one ghc(i) would pick by default for satisfying an import of one of its modules) as specified, since as I learned ghc's choice is not dependent on the contents of the source files? In its current form this patch doesn't do a lot to address developer- friendliness, since I might have to use a lot of `-package` flags to load a source file into ghci. Granted there might be other flags (like `-i`, or `-package` to pick versions of packages that are different from the ones ghc would pick by default) needed to load a source file from a Cabal package into ghci, but it seems like we could completely remove `MIN_VERSION_*` macros being a source of additional such flags. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 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:D1349 Wiki Page: | -------------------------------------+------------------------------------- Comment (by ezyang): The big problem is that, if you do this, you effectively force GHC to dump the ENTIRE package database into a giant header file, which defines each of the macros. The bigger the database, the bigger the file. I'm not fundamentally opposed, but this was the reason this draft didn't do it that way. I think Duncan also has some ulterior motives for not enabling it by default, mostly to get people to use proper setup dependencies on their Cabal files. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.11 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:D1349 Wiki Page: | -------------------------------------+------------------------------------- Changes (by ezyang): * status: new => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.11 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:D1349 Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * status: closed => new * resolution: fixed => Comment: I didn't understand Duncan's "ulterior motives" before, but since he just mentioned them on IRC, I'm rather sure they are wrong. We should create a `MIN_VERSION_*` macro for every ''visible'' package. Cabal builds with `-hide-all-packages` anyways, so this is no behavior change compared to what's currently implemented when building with Cabal. The performance worry seems suspect, too. Besides the fact that Cabal builds are still unaffected, the amount of work needed to write out the header file can't be large in comparison to the time needed to read the package database in the first place. The only non-linear case would be using `ghc --make` to build a large number of modules while having a large number of packages in the package database, when cpp would have to process the header file once for every package. I think this is still unlikely to be a big issue compared to ghc actually compiling the modules. I'll try to do some timing tests. On general principle, it seems bad to unnecessarily create multiple "tiers" of visible packages: the visible packages but also the ''really'' visible packages, that were specified explicitly. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.11 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:D1349 Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): I made a header file with 100000 copies (with different names) of the two macros generated per package, and ran a file that `#include`s it through cpp. It took 0.27 seconds. So for a more realistic package database size of 1000 packages, that's 2 milliseconds. I think that overhead is negligible relative to the time it takes ghc to compile any module. Not critical to fix this for 8.0 though, since it's just a convenience feature request. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.11 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:D1349 Wiki Page: | -------------------------------------+------------------------------------- Comment (by ezyang): Well, it's literally a two line change. I'm willing to flip the switch. Anyone else? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.11 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:D1349 Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): Sounds good to me. Note that `-hide-all-packages` is mentioned in the documentation for `MIN_VERSION_pkgname` and `VERSION_pkgname` as well. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.11 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:D1349, Wiki Page: | Phab:D1869 -------------------------------------+------------------------------------- Changes (by thomie): * differential: Phab:D1349 => Phab:D1349, Phab:D1869 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.11 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:D1349, Wiki Page: | Phab:D1869 -------------------------------------+------------------------------------- Comment (by hvr): Replying to [comment:3 rwbarton]:
[...] I don't understand any more why it should be the case that we only create these macros for packages explicitly specified with `-package` or equivalent.
Well, if you `-hide-all-packages` and unmask a few packages via `-package`, then exposing macros for all other packages in the package database would be very unsound, as it would destroy modularity. You don't expect package versions outside the set of explicitly requested ones to have any effect on your code, just like you wouldn't expect modules not explicitly imported to bring entities into scope (sadly, instances violate this already, but we shouldn't add to this any more). Also, always defining macros even though the packages are not activated (i.e. enabled via `-package`) would also break code which uses `#ifdef MIN_VERSION_...` to query whether a package has been activated for a given compilation, and thus its modules are allowed to be `import`ed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.11 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:D1349, Wiki Page: | Phab:D1869 -------------------------------------+------------------------------------- Comment (by rwbarton): Replying to [comment:12 hvr]:
Replying to [comment:3 rwbarton]:
[...] I don't understand any more why it should be the case that we only create these macros for packages explicitly specified with `-package` or equivalent.
Well, if you `-hide-all-packages` and unmask a few packages via `-package`, then exposing macros for all other packages in the package database would be very unsound, as it would destroy modularity.
I was unclear in comment:3. I thought I was pretty clear in comment:7, but let me try again. For a given compilation, after processing all package-related flags and environment variables, and reading in all package databases, GHC selects some set of installed packages, called the exposed packages. These are the packages that GHC will use to satisfy import statements. My proposal is simply: define `MIN_VERSION_x` macros for exactly the exposed packages. If you can import it, then you can check its version too. So, if you `-hide-all-packages` and unmask a few packages via `-package`, you'd only get `MIN_VERSION_x` macros for those packages you exposed with `-package`. The modularity concerns that Cabal addresses for imports then extend directly to `MIN_VERSION_x` macros. In Cabal, you need to state your dependency on a module to import it. So, you need to state your dependency on a module to check its version with `MIN_VERSION_x`, too. No need to reason explicitly about `-hide-all-packages` and `-package` flags to arrive at this result. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.11 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:D1349, Wiki Page: | Phab:D1869 -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => patch Comment: This (Phab:D1869) will be merged when #11763 is implemented. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.11 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:D1349, Wiki Page: | Phab:D1869 -------------------------------------+------------------------------------- Comment (by hvr): Replying to [comment:14 bgamari]:
This (Phab:D1869) will be merged when #11763 is implemented.
#11763 has been implemetned already... but we should make sure that the Cabal 1.24 bundled with GHC 8 is updated to use `-fno-version-macros` so that Cabal controls 100% of which macros are made available to programs; it's a bad idea IMHO to have both, `cabal_macros.h` and `-fversion-macros` in effect even if it doesn't cause apparent problems *yet*. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: patch Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.11 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:D1349, Wiki Page: | Phab:D1869 -------------------------------------+------------------------------------- Comment (by hvr): Replying to [comment:7 rwbarton]:
Cabal builds with `-hide-all-packages` anyways, so this is no behavior change compared to what's currently implemented when building with Cabal.
minor nitpick: This claim does not apply to `Setup.hs` unless a `custom- setup` section exists (and is understood by Cabal). However, things are becoming way more "interesting" for `Setup.hs` starting with GHC 8 & Cabal 1.24 & Stack ;-) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10970: Built in MIN_VERSION macro support
-------------------------------------+-------------------------------------
Reporter: ezyang | Owner:
Type: feature request | Status: patch
Priority: normal | Milestone: 8.0.1
Component: Compiler | Version: 7.11
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:D1349,
Wiki Page: | Phab:D1869
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#10970: Built in MIN_VERSION macro support -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 7.11 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:D1349, Wiki Page: | Phab:D1869 -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed Comment: Merged as b6be8a106c6c6fb477832220b606f19a5943f083. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10970#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC