ghc-bignum package
Introduce ghc-bignum
package:
- add a new
ghc-bignum
package providingInteger
andNatural
implementations- support several backends
- remove
integer-simple
package.-
ghc-bignum
provides a new pure Haskell backend ("native") - faster than
integer-simple
- a lot more code sharing with other backends
-
- remove
integer-gmp
package- merged as
ghc-bignum
"gmp" backend
- merged as
Motivations
- make GHC agnostic of the bignum backend used
- faster: Integer/Natural are wired-in and we don't need to load interfaces to get their type
- simpler: numeric literals don't have to carry their type
- stronger: single code path (e.g. to produce final Core expression, to match datacons)
- make it easier to test/add new bignum backends (e.g. bsdnt, libcrypto)
- most of the code is shared between backends
- the backend interface to implement is simple and well-documented (in the FFI backend module)
- backends may fall back to "native" for some operations if necessary
- use an efficient representation
- always support small/big constructors (e.g.
data Natural = NS Word# | NB ByteArray#
) - was only present in
integer-gmp
. Now every backend supports it for free
- always support small/big constructors (e.g.
- make boot packages more consistent
- avoid conditional package dependencies (e.g. in
base
) - backend selection is only a Cabal flag for
ghc-bignum
, not for its dependencies
- avoid conditional package dependencies (e.g. in
- easier to test
- supports testing selected backend results against results of "native" backend
Side-effects
- fix #15286 (closed) by defining
Natural
inghc-bignum
instead ofbase
- remove Hadrian's ugly hack (i.e. passing
-fno-omit-interface-pragmas
)
- remove Hadrian's ugly hack (i.e. passing
- fix #15262 (closed) by representing Integer/Natural in only one way
- we provide a compatibility
integer-gmp
package built on top ofghc-bignum
- it exposes function aliases and pattern synonyms (with deprecation warnings)
- useful for packages directly depending on
integer-gmp
- a few GMP specifics functions are gone (e.g. prime number test). They would be better in another package (hgmp)
How to review
- Commits are better reviewed one by one.
- Reviewing the code of the backends may be difficult (especially numeric code) because it uses low-level unlifted stuff
- I've added a lot of comments but do ask if there is something unclear
- If you have some numeric code to test, please check that "gmp" and "native" backends work for you. Backend selection:
- Hadrian:
hadrian/build.sh --bignum=[gmp|native|check-gmp]
- Make: set
BIGNUM_BACKEND=[gmp|native]
in yourmk/build.mk
file -
check-gmp
computes both with "gmp" and "native" and compare the results before returning them (Hadrian only).
- Hadrian: