From 0b959800190d0cf44ac2617e09775bfe665f848e Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Sun, 4 Oct 2026 22:01:03 +0300 Subject: [PATCH 1/2] Regression tests for allocation during indexing --- vector/tests-inspect/Inspect/Alloc.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/vector/tests-inspect/Inspect/Alloc.hs b/vector/tests-inspect/Inspect/Alloc.hs index f3bcb1ee..94104e3d 100644 --- a/vector/tests-inspect/Inspect/Alloc.hs +++ b/vector/tests-inspect/Inspect/Alloc.hs @@ -28,7 +28,9 @@ import System.Mem import Test.Alloc import Test.Ignore -import qualified Data.Vector.Unboxed as VU +import qualified Data.Vector.Unboxed as VU +import qualified Data.Vector.Storable as VS +import qualified Data.Vector.Strict as VV import Inspect.Fusion @@ -160,6 +162,11 @@ tests = testGroup "allocations" [ allocWHNF "test_concat" test_concat listVectorI ] ] + , testGroup "indexing" + [ allocWHNF "== storable" (uncurry (==)) (vectorS,vectorS) + , allocWHNF "== unboxed" (uncurry (==)) (vectorI,vectorI) + , allocWHNF "== boxed" (uncurry (==)) (vectorV,vectorV) + ] ] allocWHNF :: String -> (a -> b) -> a -> TestTree @@ -194,6 +201,14 @@ vectorI :: VU.Vector Int {-# NOINLINE vectorI #-} vectorI = VU.generate size fromIntegral +vectorS :: VS.Vector Int +{-# NOINLINE vectorS #-} +vectorS = VS.generate size fromIntegral + +vectorV :: VV.Vector Int +{-# NOINLINE vectorV #-} +vectorV = VV.generate size fromIntegral + vectorIdx :: VU.Vector (Int,Int) {-# NOINLINE vectorIdx #-} vectorIdx = VU.map (\i -> (i`div`3, i)) vectorI From 9038a5a7f473f4928f8cab827f475d6e175ee4e6 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Tue, 13 Oct 2026 17:41:04 +0300 Subject: [PATCH 2/2] Strict indexing for storable vectors --- vector/src/Data/Vector/Storable/Unsafe.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vector/src/Data/Vector/Storable/Unsafe.hs b/vector/src/Data/Vector/Storable/Unsafe.hs index 2d6f9224..dae9d34e 100644 --- a/vector/src/Data/Vector/Storable/Unsafe.hs +++ b/vector/src/Data/Vector/Storable/Unsafe.hs @@ -39,7 +39,7 @@ import Control.Monad.Primitive import Prelude ( Eq, Ord, Monoid, Read, Show, Ordering(..), Int, IO, Num(..) , compare, mempty, mappend, mconcat, showsPrec, return, seq, undefined, div - , (<), (<=), (>), (>=), (==), (/=), (.), ($) ) + , (<), (<=), (>), (>=), (==), (/=), (.), ($), ($!)) import Data.Data ( Data(..) ) import Text.Read ( Read(..), readListPrecDefault ) @@ -123,7 +123,7 @@ instance Storable a => G.Vector Vector a where {-# INLINE basicUnsafeIndexM #-} basicUnsafeIndexM (UnsafeVector _ fp) i = return - . unsafeInlineIO + $! unsafeInlineIO $ unsafeWithForeignPtr fp $ \p -> peekElemOff p i