From 13a0ad5e2938218dd97c8db49b3da6c5bdd5a5db Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 3 Dec 2025 20:55:40 +0100 Subject: Inlining magic --- src/Data/Array/Nested/Mixed/Shape/Internal.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Data/Array/Nested/Mixed/Shape') diff --git a/src/Data/Array/Nested/Mixed/Shape/Internal.hs b/src/Data/Array/Nested/Mixed/Shape/Internal.hs index 9997b0f..2a86ac1 100644 --- a/src/Data/Array/Nested/Mixed/Shape/Internal.hs +++ b/src/Data/Array/Nested/Mixed/Shape/Internal.hs @@ -20,9 +20,11 @@ ixFromLinearStub fname' ishty ixty zshC consshC ixz ixcons shtolist = do locals <- [d| -- Unfold first iteration of fromLin to do the range check. - -- Don't inline because if this is inlined, GHC seems to stop sharing - -- 'suffixes' over multiple calls, which breaks performance in sh*Enum. - {-# NOINLINE fromLin0 #-} + -- Don't inline this function at first to allow GHC to inline the outer + -- function and realise that 'suffixes' is shared. But then later inline it + -- anyway, to avoid the function call. Removing the pragma makes GHC + -- somehow unable to recognise that 'suffixes' can be shared in a loop. + {-# NOINLINE [0] fromLin0 #-} fromLin0 :: Num i => $ishty sh -> [Int] -> Int -> $ixty sh i fromLin0 sh suffixes i = if i < 0 then outrange sh i else -- cgit v1.2.3-70-g09d2