[Git][ghc/ghc][wip/T23578] Refactor more

Jaro Reinders (@Noughtmare) gitlab at gitlab.haskell.org
Fri Jul 7 15:40:13 UTC 2023



Jaro Reinders pushed to branch wip/T23578 at Glasgow Haskell Compiler / GHC


Commits:
810f17c1 by Jaro Reinders at 2023-07-07T17:40:05+02:00
Refactor more

- - - - -


1 changed file:

- libraries/base/GHC/Word.hs


Changes:

=====================================
libraries/base/GHC/Word.hs
=====================================
@@ -732,18 +732,18 @@ instance Enum Word64 where
         | otherwise     = fromEnumError "Word64" x
 
     {-# INLINE enumFrom #-}
-    enumFrom (W# x#)      = eftWord x# maxWord#
-        where !(W# maxWord#) = maxBound
+    enumFrom (W64# x#)      = eftWord64 x# maxWord#
+        where !(W64# maxWord#) = maxBound
         -- Blarg: technically I guess enumFrom isn't strict!
 
     {-# INLINE enumFromTo #-}
-    enumFromTo (W# x) (W# y) = eftWord x y
+    enumFromTo (W64# x) (W64# y) = eftWord64 x y
 
     {-# INLINE enumFromThen #-}
-    enumFromThen (W# x1) (W# x2) = efdWord x1 x2
+    enumFromThen (W64# x1) (W64# x2) = efdWord64 x1 x2
 
     {-# INLINE enumFromThenTo #-}
-    enumFromThenTo (W# x1) (W# x2) (W# y) = efdtWord x1 x2 y
+    enumFromThenTo (W64# x1) (W64# x2) (W64# y) = efdtWord64 x1 x2 y
 
 
 -----------------------------------------------------
@@ -765,18 +765,18 @@ eftWord64 :: Word64# -> Word64# -> [Word64]
 eftWord64 x0 y | isTrue# (x0 `gtWord64#` y) = []
              | otherwise                = go x0
                 where
-                  go x = W# x : if isTrue# (x `eqWord64#` y)
+                  go x = W64# x : if isTrue# (x `eqWord64#` y)
                                 then []
-                                else go (x `plusWord64#` 1##)
+                                else go (x `plusWord64#` (wordToWord64# 1##))
 
 {-# INLINE [0] eftWord64FB #-} -- See Note [Inline FB functions] in GHC.List
 eftWord64FB :: (Word64 -> r -> r) -> r -> Word64# -> Word64# -> r
 eftWord64FB c n x0 y | isTrue# (x0 `gtWord64#` y) = n
                    | otherwise                = go x0
                   where
-                    go x = W# x `c` if isTrue# (x `eqWord64#` y)
+                    go x = W64# x `c` if isTrue# (x `eqWord64#` y)
                                     then n
-                                    else go (x `plusWord64#` 1##)
+                                    else go (x `plusWord64#` (wordToWord64# 1##))
                         -- Watch out for y=maxBound; hence ==, not >
         -- Be very careful not to have more than one "c"
         -- so that when eftInfFB is inlined we can inline
@@ -797,8 +797,8 @@ eftWord64FB c n x0 y | isTrue# (x0 `gtWord64#` y) = n
 efdWord64 :: Word64# -> Word64# -> [Word64]
 -- [x1,x2..maxWord64]
 efdWord64 x1 x2
- | isTrue# (x2 `geWord64#` x1) = case maxBound of W# y -> efdtWord64Up x1 x2 y
- | otherwise                 = case minBound of W# y -> efdtWord64Dn x1 x2 y
+ | isTrue# (x2 `geWord64#` x1) = case maxBound of W64# y -> efdtWord64Up x1 x2 y
+ | otherwise                 = case minBound of W64# y -> efdtWord64Dn x1 x2 y
 
 {-# NOINLINE [1] efdtWord64 #-}
 efdtWord64 :: Word64# -> Word64# -> Word64# -> [Word64]
@@ -816,64 +816,64 @@ efdtWord64FB c n x1 x2 y
 -- Requires x2 >= x1
 efdtWord64Up :: Word64# -> Word64# -> Word64# -> [Word64]
 efdtWord64Up x1 x2 y    -- Be careful about overflow!
- | isTrue# (y `ltWord64#` x2) = if isTrue# (y `ltWord64#` x1) then [] else [W# x1]
+ | isTrue# (y `ltWord64#` x2) = if isTrue# (y `ltWord64#` x1) then [] else [W64# x1]
  | otherwise = -- Common case: x1 <= x2 <= y
-               let !delta = x2 `minusWord64#` x1 -- >= 0
-                   !y' = y `minusWord64#` delta  -- x1 <= y' <= y; hence y' is representable
+               let !delta = x2 `subWord64#` x1 -- >= 0
+                   !y' = y `subWord64#` delta  -- x1 <= y' <= y; hence y' is representable
 
                    -- Invariant: x <= y
                    -- Note that: z <= y' => z + delta won't overflow
                    -- so we are guaranteed not to overflow if/when we recurse
-                   go_up x | isTrue# (x `gtWord64#` y') = [W# x]
-                           | otherwise                = W# x : go_up (x `plusWord64#` delta)
-               in W# x1 : go_up x2
+                   go_up x | isTrue# (x `gtWord64#` y') = [W64# x]
+                           | otherwise                = W64# x : go_up (x `plusWord64#` delta)
+               in W64# x1 : go_up x2
 
 -- Requires x2 >= x1
 {-# INLINE [0] efdtWord64UpFB #-} -- See Note [Inline FB functions] in GHC.List
 efdtWord64UpFB :: (Word64 -> r -> r) -> r -> Word64# -> Word64# -> Word64# -> r
 efdtWord64UpFB c n x1 x2 y    -- Be careful about overflow!
- | isTrue# (y `ltWord64#` x2) = if isTrue# (y `ltWord64#` x1) then n else W# x1 `c` n
+ | isTrue# (y `ltWord64#` x2) = if isTrue# (y `ltWord64#` x1) then n else W64# x1 `c` n
  | otherwise = -- Common case: x1 <= x2 <= y
-               let !delta = x2 `minusWord64#` x1 -- >= 0
-                   !y' = y `minusWord64#` delta  -- x1 <= y' <= y; hence y' is representable
+               let !delta = x2 `subWord64#` x1 -- >= 0
+                   !y' = y `subWord64#` delta  -- x1 <= y' <= y; hence y' is representable
 
                    -- Invariant: x <= y
                    -- Note that: z <= y' => z + delta won't overflow
                    -- so we are guaranteed not to overflow if/when we recurse
-                   go_up x | isTrue# (x `gtWord64#` y') = W# x `c` n
-                           | otherwise                = W# x `c` go_up (x `plusWord64#` delta)
-               in W# x1 `c` go_up x2
+                   go_up x | isTrue# (x `gtWord64#` y') = W64# x `c` n
+                           | otherwise                = W64# x `c` go_up (x `plusWord64#` delta)
+               in W64# x1 `c` go_up x2
 
 -- Requires x2 <= x1
 efdtWord64Dn :: Word64# -> Word64# -> Word64# -> [Word64]
 efdtWord64Dn x1 x2 y    -- Be careful about underflow!
- | isTrue# (y `gtWord64#` x2) = if isTrue# (y `gtWord64#` x1) then [] else [W# x1]
+ | isTrue# (y `gtWord64#` x2) = if isTrue# (y `gtWord64#` x1) then [] else [W64# x1]
  | otherwise = -- Common case: x1 >= x2 >= y
-               let !delta = x2 `minusWord64#` x1 -- <= 0
-                   !y' = y `minusWord64#` delta  -- y <= y' <= x1; hence y' is representable
+               let !delta = x2 `subWord64#` x1 -- <= 0
+                   !y' = y `subWord64#` delta  -- y <= y' <= x1; hence y' is representable
 
                    -- Invariant: x >= y
                    -- Note that: z >= y' => z + delta won't underflow
                    -- so we are guaranteed not to underflow if/when we recurse
-                   go_dn x | isTrue# (x `ltWord64#` y') = [W# x]
-                           | otherwise                = W# x : go_dn (x `plusWord64#` delta)
-   in W# x1 : go_dn x2
+                   go_dn x | isTrue# (x `ltWord64#` y') = [W64# x]
+                           | otherwise                = W64# x : go_dn (x `plusWord64#` delta)
+   in W64# x1 : go_dn x2
 
 -- Requires x2 <= x1
 {-# INLINE [0] efdtWord64DnFB #-} -- See Note [Inline FB functions] in GHC.List
 efdtWord64DnFB :: (Word64 -> r -> r) -> r -> Word64# -> Word64# -> Word64# -> r
 efdtWord64DnFB c n x1 x2 y    -- Be careful about underflow!
- | isTrue# (y `gtWord64#` x2) = if isTrue# (y `gtWord64#` x1) then n else W# x1 `c` n
+ | isTrue# (y `gtWord64#` x2) = if isTrue# (y `gtWord64#` x1) then n else W64# x1 `c` n
  | otherwise = -- Common case: x1 >= x2 >= y
-               let !delta = x2 `minusWord64#` x1 -- <= 0
-                   !y' = y `minusWord64#` delta  -- y <= y' <= x1; hence y' is representable
+               let !delta = x2 `subWord64#` x1 -- <= 0
+                   !y' = y `subWord64#` delta  -- y <= y' <= x1; hence y' is representable
 
                    -- Invariant: x >= y
                    -- Note that: z >= y' => z + delta won't underflow
                    -- so we are guaranteed not to underflow if/when we recurse
-                   go_dn x | isTrue# (x `ltWord64#` y') = W# x `c` n
-                           | otherwise                = W# x `c` go_dn (x `plusWord64#` delta)
-               in W# x1 `c` go_dn x2
+                   go_dn x | isTrue# (x `ltWord64#` y') = W64# x `c` n
+                           | otherwise                = W64# x `c` go_dn (x `plusWord64#` delta)
+               in W64# x1 `c` go_dn x2
 
 
 -- | @since 2.01



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/810f17c13760c903a2d15e98059756840040ffed

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/810f17c13760c903a2d15e98059756840040ffed
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230707/f1c9cce0/attachment-0001.html>


More information about the ghc-commits mailing list