[commit: ghc] wip/tdammers/T14375: Remove NOINLINE on allocaBytes... functions (9692dc1)

git at git.haskell.org git at git.haskell.org
Wed Nov 28 10:16:16 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/tdammers/T14375
Link       : http://ghc.haskell.org/trac/ghc/changeset/9692dc1d1c3264b8be321990178ea503a4be7f01/ghc

>---------------------------------------------------------------

commit 9692dc1d1c3264b8be321990178ea503a4be7f01
Author: Tobias Dammers <tdammers at gmail.com>
Date:   Wed Nov 28 11:13:43 2018 +0100

    Remove NOINLINE on allocaBytes... functions
    
    These pragmas were needed as a hack, to prevent dead code elimination
    from snatching away touch#; but now that we have rewritten these
    functions using with#, this is no longer necessary.


>---------------------------------------------------------------

9692dc1d1c3264b8be321990178ea503a4be7f01
 libraries/base/Foreign/Marshal/Alloc.hs | 19 +------------------
 1 file changed, 1 insertion(+), 18 deletions(-)

diff --git a/libraries/base/Foreign/Marshal/Alloc.hs b/libraries/base/Foreign/Marshal/Alloc.hs
index aaf6912..94a5363 100644
--- a/libraries/base/Foreign/Marshal/Alloc.hs
+++ b/libraries/base/Foreign/Marshal/Alloc.hs
@@ -99,7 +99,7 @@ calloc = callocBytes (sizeOf (undefined :: a))
 mallocBytes      :: Int -> IO (Ptr a)
 mallocBytes size  = failWhenNULL "malloc" (_malloc (fromIntegral size))
 
--- |Llike 'mallocBytes' but memory is filled with bytes of value zero.
+-- |Like 'mallocBytes' but memory is filled with bytes of value zero.
 --
 callocBytes :: Int -> IO (Ptr a)
 callocBytes size = failWhenNULL "calloc" $ _calloc 1 (fromIntegral size)
@@ -116,19 +116,6 @@ alloca :: forall a b . Storable a => (Ptr a -> IO b) -> IO b
 alloca  =
   allocaBytesAligned (sizeOf (undefined :: a)) (alignment (undefined :: a))
 
--- Note [NOINLINE for touch#]
--- ~~~~~~~~~~~~~~~~~~~~~~~~~~
--- Both allocaBytes and allocaBytesAligned use the touch#, which is notoriously
--- fragile in the presence of simplification (see #14346). In particular, the
--- simplifier may drop the continuation containing the touch# if it can prove
--- that the action passed to allocaBytes will not return. The hack introduced to
--- fix this for 8.2.2 is to mark allocaBytes as NOINLINE, ensuring that the
--- simplifier can't see the divergence.
---
--- These can be removed once #14375 is fixed, which suggests that we instead do
--- away with touch# in favor of a primitive that will capture the scoping left
--- implicit in the case of touch#.
-
 -- |@'allocaBytes' n f@ executes the computation @f@, passing as argument
 -- a pointer to a temporarily allocated block of memory of @n@ bytes.
 -- The block of memory is sufficiently aligned for any of the basic
@@ -145,8 +132,6 @@ allocaBytes (I# size) action = IO $ \ s0 ->
      case action addr                      of { IO action' ->
      with# barr# action' s2
   }}}
--- See Note [NOINLINE for touch#]
-{-# NOINLINE allocaBytes #-}
 
 allocaBytesAligned :: Int -> Int -> (Ptr a -> IO b) -> IO b
 allocaBytesAligned (I# size) (I# align) action = IO $ \ s0 ->
@@ -156,8 +141,6 @@ allocaBytesAligned (I# size) (I# align) action = IO $ \ s0 ->
      case action addr     of { IO action' ->
      with# barr# action' s2
   }}}
--- See Note [NOINLINE for touch#]
-{-# NOINLINE allocaBytesAligned #-}
 
 -- |Resize a memory area that was allocated with 'malloc' or 'mallocBytes'
 -- to the size needed to store values of type @b at .  The returned pointer



More information about the ghc-commits mailing list