data-elevator 0.2 → 0.3
raw patch · 5 files changed
+34/−14 lines, 5 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- CHANGELOG.md +6/−0
- data-elevator.cabal +4/−4
- src/Data/Elevator/Internal.hs +11/−4
- test/Issue4.hs +5/−6
- test/Main.hs +8/−0
CHANGELOG.md view
@@ -1,6 +1,12 @@ # Revision history for data-elevator +## ?.? -- ????-??-??++* Added support for GHC versions 9.12 and 9.14+ ## 0.2 -- 2024-09-16++No changes to the API, but a significant change to the conversion functions. * Fix issue #4, which makes `toStrict#` and `fromLazy#` NOINLINE. We now have rewrite rules to cancel away, e.g., `fromStrict# . toStrict# = id`.
data-elevator.cabal view
@@ -1,8 +1,8 @@ cabal-version: 2.4 name: data-elevator-version: 0.2+version: 0.3 -tested-with: GHC ==9.2.8 || ==9.4.8 || ==9.6.6 || ==9.8.2 || ==9.10.1+tested-with: GHC ==9.2.8 || ==9.4.8 || ==9.6.6 || ==9.8.2 || ==9.10.1 || ==9.12.1 || ==9.14.1 -- A short (one-line) description of the package. synopsis: Coerce between unlifted boxed and lifted types.@@ -42,7 +42,7 @@ -- LANGUAGE extensions used by modules in this package. -- other-extensions:- build-depends: base >=4.16 && <4.21+ build-depends: base >=4.16 && <4.23 hs-source-dirs: src default-language: Haskell2010 @@ -55,7 +55,7 @@ main-is: Main.hs hs-source-dirs: test other-modules: Issue4- build-depends: base >=4.16 && <4.21+ build-depends: base >=4.16 && <4.23 , data-elevator , primitive , hspec
src/Data/Elevator/Internal.hs view
@@ -1,7 +1,6 @@-{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-}-{-# LANGUAGE KindSignatures #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE RoleAnnotations #-} {-# LANGUAGE MagicHash #-}@@ -11,9 +10,7 @@ {-# LANGUAGE UnliftedNewtypes #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE ExplicitForAll #-} {-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE InstanceSigs #-} -- | This module doesn't respect the PVP! -- Breaking changes may happen at any minor version (^>= *.*.m.*)@@ -50,8 +47,13 @@ toStrict# :: a -> Strict a toStrict# = unsafeCoerce id {-# NOINLINE toStrict# #-} -- See Note [NOINLINE toStrict#/fromLazy#]++-- Before 9.6, the let/app invariant is still in effect and the rewrite rules+-- error+#if __GLASGOW_HASKELL__ >= 906 {-# RULES "fromStrict#.toStrict#" forall x. fromStrict# (toStrict# x) = x #-} {-# RULES "toLazy#.toStrict#" forall x. toLazy# (toStrict# x) = unsafeCoerce id x #-}+#endif fromStrict# :: Strict a -> a fromStrict# = unsafeCoerce id@@ -84,8 +86,13 @@ fromLazy# :: Lazy a -> a fromLazy# = unsafeCoerce id {-# NOINLINE fromLazy# #-} -- See Note [NOINLINE toStrict#/fromLazy#]++-- Before 9.6, the let/app invariant is still in effect and the rewrite rules+-- error+#if __GLASGOW_HASKELL__ >= 906 {-# RULES "toLazy#.fromLazy#" forall x. toLazy# (fromLazy# x) = x #-} {-# RULES "fromStrict#.fromLazy#" forall x. fromStrict# (fromLazy# x) = unsafeCoerce id x #-}+#endif pattern Lazy :: a -> Lazy a pattern Lazy x <- (fromLazy# -> x) where
test/Issue4.hs view
@@ -1,14 +1,10 @@ {-# OPTIONS_GHC -O2 #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE UnboxedTuples #-}-module Issue4 (- StrictArray,- primArrayToStrictArray,- indexStrictArray,- sizeofStrictArray,-) where+module Issue4 where import Data.Elevator (Strict (Strict)) import qualified Data.Primitive as P@@ -16,6 +12,8 @@ import GHC.Exts ((+#)) import GHC.ST (ST(ST), runST) +-- 9.2 does not allow lev poly GHC.Array#+#if __GLASGOW_HASKELL__ >= 904 data StrictArray a = StrictArray !(GHC.Array# (Strict a)) primArrayToStrictArray :: forall a. P.Array a -> StrictArray a@@ -57,3 +55,4 @@ sizeofStrictArray :: StrictArray a -> Int sizeofStrictArray (StrictArray a#) = GHC.I# (GHC.sizeofArray# a#)+#endif
test/Main.hs view
@@ -1,5 +1,6 @@ {-# OPTIONS_GHC -fplugin=Test.Inspection.Plugin #-} +{-# LANGUAGE CPP #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-}@@ -50,12 +51,18 @@ it "rank2 co: (Int -> Int) -> Int ~ (Strict Int -> Int) -> Int" $ do levCoerce @((Strict Int -> Int) -> Int) @((Int -> Strict Int) -> Int) (\f -> f (Strict 42)) (\x -> Strict x) `shouldBe` (42 :: Int) +-- 9.2 does not allow lev poly GHC.Array#+#if __GLASGOW_HASKELL__ >= 904 describe "Issue 4" $ do it "should not crash" $ do let arr = P.createArray 5 (even (sum [0..1000]) :: Bool) (\_arr -> return ()) let sarr = Issue4.primArrayToStrictArray arr Issue4.indexStrictArray sarr 3 `shouldBe` True+#endif +-- Before 9.6, the let/app invariant is still in effect and the rewrite rules+-- error+#if __GLASGOW_HASKELL__ >= 906 from_to_strict :: Bool -> Bool from_to_strict x = fromStrict# (toStrict# x) @@ -72,3 +79,4 @@ inspect $ ('from_to_strict2 `doesNotUse` 'toStrict#) { expectFail = True } -- https://gitlab.haskell.org/ghc/ghc/-/issues/25261 inspect $ 'to_from_lazy `doesNotUse` 'fromLazy# inspect $ ('to_from_lazy2 `doesNotUse` 'fromLazy#) { expectFail = True } -- https://gitlab.haskell.org/ghc/ghc/-/issues/25261+#endif