[GHC] #7015: Add support for 'static'

GHC ghc-devs at haskell.org
Wed Sep 17 07:26:36 UTC 2014


#7015: Add support for 'static'
-------------------------------------+-------------------------------------
              Reporter:  edsko       |            Owner:
                  Type:  feature     |           Status:  patch
  request                            |        Milestone:  7.10.1
              Priority:  normal      |          Version:  7.4.2
             Component:  Compiler    |         Keywords:
            Resolution:              |     Architecture:  Unknown/Multiple
      Operating System:              |       Difficulty:  Unknown
  Unknown/Multiple                   |       Blocked By:
       Type of failure:              |  Related Tickets:
  None/Unknown                       |
             Test Case:              |
              Blocking:              |
Differential Revisions:  Phab:D119   |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 Here's a comment from Phab that should feed into the design: The current
 implementation does not appear to keep the heap references alive
 correctly:
 {{{
 {-# LANGUAGE StaticValues #-}
 module Main where

 import GHC.Ref

 import Control.Concurrent
 import System.Environment
 import System.Mem
 import System.Mem.Weak

 import Data.Numbers.Primes -- from Numbers

 -- Just a Ref to some CAF from another package so that we can deRef it
 when linked with -dynamic
 primes_ref :: Ref [Integer]
 primes_ref = static primes

 main = do
   as <- getArgs
   let z = primes!!(length as+200)
   print z
   performGC

   -- addFinalizer z (putStrLn "finalizer z")
   print z
   performGC
   threadDelay 1000000
   print . fmap (!!300) =<< deRef primes_ref
   -- uncommenting the next line keeps primes alive and prevents the
 segfault
   -- print (primes!!300)
 }}}
 and

 {{{
 $ ghc -dynamic -o primes primes.hs
 [1 of 1] Compiling Main             ( primes.hs, primes.o )
 Linking primes ...

 $ ./primes
 1229
 1229
 Segmentation fault (core dumped)
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/7015#comment:32>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list