[commit: ghc] ghc-8.0: Don't require -hide-all-packages for MIN_VERSION_* macros (b6be8a1)

git at git.haskell.org git at git.haskell.org
Wed Mar 30 21:24:54 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/b6be8a106c6c6fb477832220b606f19a5943f083/ghc

>---------------------------------------------------------------

commit b6be8a106c6c6fb477832220b606f19a5943f083
Author: Thomas Miedema <thomasmiedema at gmail.com>
Date:   Wed Mar 30 21:43:51 2016 +0200

    Don't require -hide-all-packages for MIN_VERSION_* macros
    
    Define MIN_VERSION_pkgname and VERSION_pkgname macros for all exposed
    packages, without requiring -hide-all-packages.
    
    See #10970 comment 7-10 for discussion.
    
    Reviewers: duncan, ezyang, bgamari, austin
    
    Reviewed By: ezyang
    
    Subscribers: hvr, rwbarton
    
    Differential Revision: https://phabricator.haskell.org/D1869
    
    GHC Trac Issues: #10970
    
    (cherry picked from commit e9c2555ac666912f7dff56448ced4bfa06d14e76)


>---------------------------------------------------------------

b6be8a106c6c6fb477832220b606f19a5943f083
 compiler/main/DriverPipeline.hs       | 15 ++++++++-------
 docs/users_guide/phases.rst           |  6 ++----
 testsuite/tests/driver/T10970a.hs     |  8 --------
 testsuite/tests/driver/T10970a.stdout |  2 --
 testsuite/tests/driver/T3389.hs       |  4 ++--
 testsuite/tests/driver/all.T          |  3 +--
 6 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index c9174f4..5f1e25b 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -2056,13 +2056,14 @@ doCpp dflags raw input_fn output_fn = do
     let uids = explicitPackages (pkgState dflags)
         pkgs = catMaybes (map (lookupPackage dflags) uids)
     mb_macro_include <-
-        -- Only generate if we have (1) we have set -hide-all-packages
-        -- (so we don't generate a HUGE macro file of things we don't
-        -- care about but are exposed) and (2) we actually have packages
-        -- to write macros for!
-        if gopt Opt_HideAllPackages dflags && not (null pkgs)
+        if not (null pkgs)
             then do macro_stub <- newTempName dflags "h"
                     writeFile macro_stub (generatePackageVersionMacros pkgs)
+                    -- Include version macros for every *exposed* package.
+                    -- Without -hide-all-packages and with a package database
+                    -- size of 1000 packages, it takes cpp an estimated 2
+                    -- milliseconds to process this file. See Trac #10970
+                    -- comment 8.
                     return [SysTools.FileOption "-include" macro_stub]
             else return []
 
@@ -2110,8 +2111,8 @@ getBackendDefs _ =
 
 generatePackageVersionMacros :: [PackageConfig] -> String
 generatePackageVersionMacros pkgs = concat
-  [ "/* package " ++ sourcePackageIdString pkg ++ " */\n"
-  ++ generateMacros "" pkgname version
+  -- Do not add any C-style comments. See Trac #3389.
+  [ generateMacros "" pkgname version
   | pkg <- pkgs
   , let version = packageVersion pkg
         pkgname = map fixchar (packageNameString pkg)
diff --git a/docs/users_guide/phases.rst b/docs/users_guide/phases.rst
index ed05add..0c3b59f 100644
--- a/docs/users_guide/phases.rst
+++ b/docs/users_guide/phases.rst
@@ -313,16 +313,14 @@ defined by your local GHC installation, the following trick is useful:
 
 ``VERSION_pkgname``
     This macro is available starting GHC 8.0.  It is defined for every
-    exposed package, but only if the ``-hide-all-packages`` flag
-    is set.  This macro expands to a string recording the
+    exposed package. This macro expands to a string recording the
     version of ``pkgname`` that is exposed for module import.
     It is identical in behavior to the ``VERSION_pkgname`` macros
     that Cabal defines.
 
 ``MIN_VERSION_pkgname(x,y,z)``
     This macro is available starting GHC 8.0.  It is defined for every
-    exposed package, but only if the ``-hide-all-packages`` flag
-    is set. This macro is provided for convenience to write CPP
+    exposed package. This macro is provided for convenience to write CPP
     conditionals testing if a package version is ``x.y.z`` or
     less.  It is identical in behavior to the ``MIN_VERSION_pkgname``
     macros that Cabal defines.
diff --git a/testsuite/tests/driver/T10970a.hs b/testsuite/tests/driver/T10970a.hs
deleted file mode 100644
index 8e7aa60..0000000
--- a/testsuite/tests/driver/T10970a.hs
+++ /dev/null
@@ -1,8 +0,0 @@
-{-# LANGUAGE CPP #-}
-main = do
-#ifndef VERSION_containers
-    putStrLn "OK"
-#endif
-#ifndef MIN_VERSION_base
-    putStrLn "OK"
-#endif
diff --git a/testsuite/tests/driver/T10970a.stdout b/testsuite/tests/driver/T10970a.stdout
deleted file mode 100644
index 2c94e48..0000000
--- a/testsuite/tests/driver/T10970a.stdout
+++ /dev/null
@@ -1,2 +0,0 @@
-OK
-OK
diff --git a/testsuite/tests/driver/T3389.hs b/testsuite/tests/driver/T3389.hs
index c6a5666..e574fc4 100644
--- a/testsuite/tests/driver/T3389.hs
+++ b/testsuite/tests/driver/T3389.hs
@@ -6,7 +6,7 @@
 
 main :: IO ()
 main = putStrLn [A,
--- /*
+-- CPP treats this as the beginning of a multiline C-style comment: /usr/local/*
                  'b',
--- */
+-- And */ close it. By passing `-optP -C` we tell CPP not to delete it.
                  'c']
diff --git a/testsuite/tests/driver/all.T b/testsuite/tests/driver/all.T
index a50476a..077ac66 100644
--- a/testsuite/tests/driver/all.T
+++ b/testsuite/tests/driver/all.T
@@ -462,8 +462,7 @@ test('T365',
 test('T9360a', normal, run_command, ['{compiler} --interactive -e "" -ignore-dot-ghci'])
 test('T9360b', normal, run_command, ['{compiler} -e "" --interactive -ignore-dot-ghci'])
 
-test('T10970', normal, compile_and_run, ['-hide-all-packages -package base -package containers'])
-test('T10970a', normal, compile_and_run, [''])
+test('T10970', normal, compile_and_run, [''])
 test('T4931', normal, compile_and_run, [''])
 test('T11182', normal, compile_and_run, [''])
 test('T11381', normal, compile_fail, [''])



More information about the ghc-commits mailing list