Skip to content

Commit

Permalink
Replace Enum usage for IoSubSystem with manully written functions
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Oct 17, 2024
1 parent 4c0d82e commit b8fdd1c
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions core/src/Streamly/Internal/Data/Unbox.hs
Original file line number Diff line number Diff line change
Expand Up @@ -461,19 +461,38 @@ instance Unbox () where
sizeOf _ = 1

#if MIN_VERSION_base(4,15,0)

-- We could use Word8 instead of Int here but that would be a silent breaking
-- change.

-- base that ships with GHC 9.12 removes the Enum instance for IoSubSystem. It's
-- easier to remove the use of Enum for every version than to play around with
-- CPP macros.

{-# INLINE fromEnumIoSubSystem #-}
fromEnumIoSubSystem :: IoSubSystem -> Int
fromEnumIoSubSystem IoPOSIX = 0
fromEnumIoSubSystem IoNative = 1

{-# INLINE toEnumIoSubSystem #-}
toEnumIoSubSystem :: Int -> IoSubSystem
toEnumIoSubSystem 0 = IoPOSIX
toEnumIoSubSystem 1 = IoNative
toEnumIoSubSystem val = error $ show val ++ ": Invalid tag for IoSubSystem"

instance Unbox IoSubSystem where

{-# INLINE peekAt #-}
peekAt i arr =
checkBounds
"peek IoSubSystem" (i + sizeOf (Proxy :: Proxy IoSubSystem)) arr
>> toEnum <$> peekAt i arr
>> toEnumIoSubSystem <$> peekAt i arr

{-# INLINE pokeAt #-}
pokeAt i arr a =
checkBounds
"poke IoSubSystem" (i + sizeOf (Proxy :: Proxy IoSubSystem)) arr
>> pokeAt i arr (fromEnum a)
>> pokeAt i arr (fromEnumIoSubSystem a)

{-# INLINE sizeOf #-}
sizeOf _ = sizeOf (Proxy :: Proxy Int)
Expand Down

0 comments on commit b8fdd1c

Please sign in to comment.