[commit: ghc] ghc-8.6: Fix for built-in Natural literals desugaring (31f7d21)

git at git.haskell.org git at git.haskell.org
Thu Jul 12 20:05:31 UTC 2018


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

On branch  : ghc-8.6
Link       : http://ghc.haskell.org/trac/ghc/changeset/31f7d21bae5d75621a4077e2966a80ce30c55d46/ghc

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

commit 31f7d21bae5d75621a4077e2966a80ce30c55d46
Author: Sylvain Henry <hsyl20 at gmail.com>
Date:   Fri Jul 6 11:01:14 2018 -0400

    Fix for built-in Natural literals desugaring
    
    The recent patch "Built-in Natural literals in Core"
    (https://phabricator.haskell.org/rGHCfe770c211631e7b4c9b0b1e88ef9b6046c6
    585ef) introduced a regression when desugaring large numbers.
    
    This patch fixes it and adds a regression test.
    
    Reviewers: hvr, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: rwbarton, thomie, carter
    
    GHC Trac Issues: #15301
    
    Differential Revision: https://phabricator.haskell.org/D4885
    
    (cherry picked from commit 987b5e7fbacd8afd2c8463c16eac28cd68f43155)


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

31f7d21bae5d75621a4077e2966a80ce30c55d46
 libraries/base/GHC/Natural.hs                                      | 2 +-
 testsuite/tests/numeric/should_run/T15301.hs                       | 7 +++++++
 .../tests/numeric/should_run/T15301.stdout                         | 0
 testsuite/tests/numeric/should_run/all.T                           | 1 +
 4 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libraries/base/GHC/Natural.hs b/libraries/base/GHC/Natural.hs
index db8d8b8..a35688d 100644
--- a/libraries/base/GHC/Natural.hs
+++ b/libraries/base/GHC/Natural.hs
@@ -594,7 +594,7 @@ mkNatural :: [Word]  -- ^ value expressed in 32 bit chunks, least
           -> Natural
 mkNatural [] = wordToNaturalBase 0##
 mkNatural (W# i : is') = wordToNaturalBase (i `and#` 0xffffffff##) `orNatural`
-                         shiftLNatural (mkNatural is') 31
+                         shiftLNatural (mkNatural is') 32
 {-# CONSTANT_FOLDED mkNatural #-}
 
 -- | Convert 'Int' to 'Natural'.
diff --git a/testsuite/tests/numeric/should_run/T15301.hs b/testsuite/tests/numeric/should_run/T15301.hs
new file mode 100644
index 0000000..6efbce4
--- /dev/null
+++ b/testsuite/tests/numeric/should_run/T15301.hs
@@ -0,0 +1,7 @@
+import Numeric
+import GHC.Natural
+
+main = do
+   -- test that GHC correctly compiles big Natural literals
+   let x = 0xffffffffffffffffffffffff :: Natural
+   print (showHex x "" == "ffffffffffffffffffffffff")
diff --git a/libraries/base/tests/IO/IOError002.stdout b/testsuite/tests/numeric/should_run/T15301.stdout
similarity index 100%
copy from libraries/base/tests/IO/IOError002.stdout
copy to testsuite/tests/numeric/should_run/T15301.stdout
diff --git a/testsuite/tests/numeric/should_run/all.T b/testsuite/tests/numeric/should_run/all.T
index 691fc26..140fa6c 100644
--- a/testsuite/tests/numeric/should_run/all.T
+++ b/testsuite/tests/numeric/should_run/all.T
@@ -65,3 +65,4 @@ test('T10011', normal, compile_and_run, [''])
 test('T10962', omit_ways(['ghci']), compile_and_run, ['-O2'])
 test('T11702', extra_ways(['optasm']), compile_and_run, [''])
 test('T12136', normal, compile_and_run, [''])
+test('T15301', normal, compile_and_run, ['-O2'])



More information about the ghc-commits mailing list