summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorAlec Theriault <alec.theriault@gmail.com>2019-01-08 10:28:10 -0800
committerBen Gamari <ben@smart-cactus.org>2019-01-16 14:17:11 -0500
commit582a96f422a8437f87da2539afc7d7e6772054df (patch)
tree97cde22e39fe965f2c3a8e6ab5d910b54933a657 /compiler
parent9fb2702dec3e9419e1a229f8cd678324e89fdddf (diff)
downloadhaskell-582a96f422a8437f87da2539afc7d7e6772054df.tar.gz
Support printing `integer-simple` Integers in GHCi
This means that `:p` no longer leaks the implementation details of `Integer` with `integer-simple`. The `print037` test case should exercise all possible code paths for GHCi's code around printing `Integer`s (both in `integer-simple` and `integer-gmp`). `ghc` the package now also has a Cabal `integer-simple` flag (like the `integer-gmp` one).
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ghc.cabal.in14
-rw-r--r--compiler/ghci/RtClosureInspect.hs32
2 files changed, 45 insertions, 1 deletions
diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in
index 5b93d3ceb2..4be4d60cb7 100644
--- a/compiler/ghc.cabal.in
+++ b/compiler/ghc.cabal.in
@@ -45,6 +45,11 @@ Flag terminfo
Default: True
Manual: True
+Flag integer-simple
+ Description: Use integer-simple
+ Manual: True
+ Default: False
+
Flag integer-gmp
Description: Use integer-gmp
Manual: True
@@ -89,11 +94,20 @@ Library
CPP-Options: -DGHCI
Include-Dirs: ../rts/dist/build @FFIIncludeDir@
+ -- sanity-check to ensure not more than one integer flag is set
+ if flag(integer-gmp) && flag(integer-simple)
+ build-depends: invalid-cabal-flag-settings<0
+
-- gmp internals are used by the GHCi debugger if available
if flag(integer-gmp)
CPP-Options: -DINTEGER_GMP
build-depends: integer-gmp >= 1.0.2
+ -- simple internals are used by the GHCi debugger if available
+ if flag(integer-simple)
+ CPP-Options: -DINTEGER_SIMPLE
+ build-depends: integer-simple >= 0.1.1.1
+
Other-Extensions:
BangPatterns
CPP
diff --git a/compiler/ghci/RtClosureInspect.hs b/compiler/ghci/RtClosureInspect.hs
index a61d776576..4a119a991b 100644
--- a/compiler/ghci/RtClosureInspect.hs
+++ b/compiler/ghci/RtClosureInspect.hs
@@ -67,6 +67,9 @@ import Data.List
import GHC.Exts
import Data.Array.Base
import GHC.Integer.GMP.Internals
+#elif defined(INTEGER_SIMPLE)
+import GHC.Exts
+import GHC.Integer.Simple.Internals
#endif
import qualified Data.Sequence as Seq
import Data.Sequence (viewl, ViewL(..))
@@ -410,9 +413,36 @@ cPprTermBase y =
let
!(UArray _ _ _ arr#) = listArray (0,length ws-1) ws
constr
- | "Jp#" <- occNameString (nameOccName (dataConName con)) = Jp#
+ | "Jp#" <- getOccString (dataConName con) = Jp#
| otherwise = Jn#
return (Just (Ppr.integer (constr (BN# arr#))))
+#elif defined(INTEGER_SIMPLE)
+ -- As with the GMP case, this depends deeply on the integer-simple
+ -- representation.
+ --
+ -- @
+ -- data Integer = Positive !Digits | Negative !Digits | Naught
+ --
+ -- data Digits = Some !Word# !Digits
+ -- | None
+ -- @
+ --
+ -- NB: the above has some type synonyms expanded out for the sake of brevity
+ ppr_integer _ Term{subTerms=[]} =
+ return (Just (Ppr.integer Naught))
+ ppr_integer _ Term{dc=Right con, subTerms=[digitTerm]}
+ | Just digits <- get_digits digitTerm
+ = return (Just (Ppr.integer (constr digits)))
+ where
+ get_digits :: Term -> Maybe Digits
+ get_digits Term{subTerms=[]} = Just None
+ get_digits Term{subTerms=[Prim{valRaw=[W# w]},t]}
+ = Some w <$> get_digits t
+ get_digits _ = Nothing
+
+ constr
+ | "Positive" <- getOccString (dataConName con) = Positive
+ | otherwise = Negative
#endif
ppr_integer _ _ = return Nothing