[commit: ghc] wip/T15548: Add a Note and and use integer-wired-in for the unit name (2046835)

git at git.haskell.org git at git.haskell.org
Tue Aug 21 21:11:44 UTC 2018


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

On branch  : wip/T15548
Link       : http://ghc.haskell.org/trac/ghc/changeset/2046835af7d49d4331424a9af1388d212c4d887c/ghc

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

commit 2046835af7d49d4331424a9af1388d212c4d887c
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Tue Aug 21 09:36:18 2018 -0700

    Add a Note and and use integer-wired-in for the unit name
    
    to signpost more clearly that there is something weird going on, and
    that people should not look for a package `integer` somewhere. Also,
    make sure the name is set only once.


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

2046835af7d49d4331424a9af1388d212c4d887c
 compiler/basicTypes/Module.hs                 |  3 ++-
 compiler/coreSyn/CorePrep.hs                  |  1 +
 compiler/main/Packages.hs                     |  4 +++-
 compiler/prelude/PrelNames.hs                 | 30 +++++++++++++++++++++++++++
 libraries/integer-gmp/integer-gmp.cabal       |  5 ++++-
 libraries/integer-simple/integer-simple.cabal |  5 +++--
 6 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/compiler/basicTypes/Module.hs b/compiler/basicTypes/Module.hs
index 44f841d..7307a83 100644
--- a/compiler/basicTypes/Module.hs
+++ b/compiler/basicTypes/Module.hs
@@ -1066,7 +1066,8 @@ integerUnitId, primUnitId,
   baseUnitId, rtsUnitId,
   thUnitId, mainUnitId, thisGhcUnitId, interactiveUnitId  :: UnitId
 primUnitId        = fsToUnitId (fsLit "ghc-prim")
-integerUnitId     = fsToUnitId (fsLit "integer")
+integerUnitId     = fsToUnitId (fsLit "integer-wired-in")
+   -- See Note [The integer library] in PrelNames
 baseUnitId        = fsToUnitId (fsLit "base")
 rtsUnitId         = fsToUnitId (fsLit "rts")
 thUnitId          = fsToUnitId (fsLit "template-haskell")
diff --git a/compiler/coreSyn/CorePrep.hs b/compiler/coreSyn/CorePrep.hs
index 0349c8c..26706b1 100644
--- a/compiler/coreSyn/CorePrep.hs
+++ b/compiler/coreSyn/CorePrep.hs
@@ -1537,6 +1537,7 @@ lookupMkNaturalName dflags hsc_env
     = guardNaturalUse dflags $ liftM tyThingId $
       lookupGlobal hsc_env mkNaturalName
 
+-- See Note [The integer library] in PrelNames
 lookupIntegerSDataConName :: DynFlags -> HscEnv -> IO (Maybe DataCon)
 lookupIntegerSDataConName dflags hsc_env = case integerLibrary dflags of
     IntegerGMP -> guardIntegerUse dflags $ liftM (Just . tyThingDataCon) $
diff --git a/compiler/main/Packages.hs b/compiler/main/Packages.hs
index 20f3700..13bac88 100644
--- a/compiler/main/Packages.hs
+++ b/compiler/main/Packages.hs
@@ -976,7 +976,9 @@ findWiredInPackages dflags prec_map pkgs vis_map = do
   --
   let
         matches :: PackageConfig -> WiredInUnitId -> Bool
-        pc `matches` "integer"
+        pc `matches` pid
+            -- See Note [The integer library] in PrelNames
+            | pid == unitIdString integerUnitId
             = packageNameString pc `elem` ["integer-gmp", "integer-simple"]
         pc `matches` pid = packageNameString pc == pid
 
diff --git a/compiler/prelude/PrelNames.hs b/compiler/prelude/PrelNames.hs
index be468c0..3a5bb00 100644
--- a/compiler/prelude/PrelNames.hs
+++ b/compiler/prelude/PrelNames.hs
@@ -110,6 +110,36 @@ by the user. For those things that *can* appear in source programs,
      original-name cache.
 
      See also Note [Built-in syntax and the OrigNameCache]
+
+
+Note [The integer library]
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Clearly, we need to know the names of various definitions of the integer
+library, e.g. the type itself, `mkInteger` etc. But there are two possible
+implementations of the integer library:
+
+ * integer-gmp (fast, but uses libgmp, which may not be available on all
+   targets and is GPL licensed)
+ * integer-simple (slow, but pure Haskell and BSD-licensed)
+
+We want the compiler to work with eitherone. The way we achieve this is:
+
+ * When compiling the integer-{gmp,simple} library, we pass
+     -this-unit-id  integer-wired-in
+   to GHC (see the cabal file libraries/integer-{gmp,simple}.
+ * This way, GHC can use just his UnitID (see Module.integerUnitId) when
+   generating code, and the linker will succeed.
+
+Unfortuately, the abstraction is not complete: When using integer-gmp, we
+really want to use the S# constructor directly. This is controlled by
+the `integerLibrary` field of `DynFlags`: If it is IntegerGMP, we use
+this constructor directly (see  CorePrep.lookupIntegerSDataConName)
+
+When we read the package data base, we have to rewrite it to use
+`integer-wired-in` instead of the actual UnitId (which includes the version
+number); just like for `base` and other packages. This is done in
+Packages.findWiredInPackages.
 -}
 
 {-# LANGUAGE CPP #-}
diff --git a/libraries/integer-gmp/integer-gmp.cabal b/libraries/integer-gmp/integer-gmp.cabal
index e4ecc7a..52834bb 100644
--- a/libraries/integer-gmp/integer-gmp.cabal
+++ b/libraries/integer-gmp/integer-gmp.cabal
@@ -60,7 +60,10 @@ library
     UnliftedFFITypes
   build-depends:       ghc-prim ^>= 0.5.1.0
   hs-source-dirs:      src/
-  ghc-options: -this-unit-id integer -Wall
+  -- We need to set the unit ID to integer-wired-in
+  -- (without a version number) as it's magic.
+  -- See Note [The integer library] in PrelNames
+  ghc-options: -this-unit-id integer-wired-in -Wall
   cc-options: -std=c99 -Wall
 
   include-dirs: include
diff --git a/libraries/integer-simple/integer-simple.cabal b/libraries/integer-simple/integer-simple.cabal
index e6c83da..96c2e23 100644
--- a/libraries/integer-simple/integer-simple.cabal
+++ b/libraries/integer-simple/integer-simple.cabal
@@ -26,6 +26,7 @@ Library
     other-modules: GHC.Integer.Type
     default-extensions: CPP, MagicHash, BangPatterns, UnboxedTuples,
                 UnliftedFFITypes, NoImplicitPrelude
-    -- We need to set the unit ID to integer
+    -- We need to set the unit ID to integer-wired-in
     -- (without a version number) as it's magic.
-    ghc-options: -this-unit-id integer -Wall
+    -- See Note [The integer library] in PrelNames
+    ghc-options: -this-unit-id integer-wired-in -Wall



More information about the ghc-commits mailing list