Commit c72f61c6 authored by Facundo Domínguez's avatar Facundo Domínguez
Browse files

Groom comments related to StaticPointers.

Reviewed By: austin

Differential Revision: https://phabricator.haskell.org/D575
parent 22bb78bb
...@@ -24,8 +24,7 @@ ...@@ -24,8 +24,7 @@
-- > -- >
-- > } -- > }
-- --
-- where constants are values of a fingerprint of the string -- where the constants are fingerprints produced from the static forms.
-- "<package_id>:<module_name>.sptEntry:<N>"
-- --
module StaticPtrTable (sptInitCode) where module StaticPtrTable (sptInitCode) where
...@@ -38,7 +37,7 @@ import GHC.Fingerprint ...@@ -38,7 +37,7 @@ import GHC.Fingerprint
-- | @sptInitCode module statics@ is a C stub to insert the static entries -- | @sptInitCode module statics@ is a C stub to insert the static entries
-- @statics@ of @module@ into the static pointer table -- @statics@ of @module@ into the static pointer table.
-- --
-- Each entry contains the fingerprint used to locate the entry and the -- Each entry contains the fingerprint used to locate the entry and the
-- top-level binding for the entry. -- top-level binding for the entry.
......
...@@ -313,7 +313,7 @@ rnExpr e@(ELazyPat {}) = patSynErr e ...@@ -313,7 +313,7 @@ rnExpr e@(ELazyPat {}) = patSynErr e
For the static form we check that the free variables are all top-level For the static form we check that the free variables are all top-level
value bindings. This is done by checking that the name is external or value bindings. This is done by checking that the name is external or
wired-in. See the Note about the NameSorts in Name.lhs. wired-in. See the Notes about the NameSorts in Name.hs.
-} -}
rnExpr e@(HsStatic expr) = do rnExpr e@(HsStatic expr) = do
......
...@@ -10470,9 +10470,6 @@ While the following definitions are rejected: ...@@ -10470,9 +10470,6 @@ While the following definitions are rejected:
ref6 = let x = 1 in static x ref6 = let x = 1 in static x
ref7 y = static (let x = 1 in y) ref7 y = static (let x = 1 in y)
</programlisting> </programlisting>
Note that currently, the body <literal>e</literal> in <literal>static
e</literal> is restricted to a single identifier when at the GHCi
prompt.
</para> </para>
</sect2> </sect2>
...@@ -10502,13 +10499,14 @@ That being said, with the appropriate use of wrapper datatypes, the ...@@ -10502,13 +10499,14 @@ That being said, with the appropriate use of wrapper datatypes, the
above limitations induce no loss of generality: above limitations induce no loss of generality:
<programlisting> <programlisting>
{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DerivingDataTypeable #-} {-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE Rank2Types #-} {-# LANGUAGE Rank2Types #-}
{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StaticPointers #-} {-# LANGUAGE StaticPointers #-}
import Control.Monad.ST import Control.Monad.ST
import Data.Typeable
import GHC.StaticPtr import GHC.StaticPtr
data Dict c = c => Dict data Dict c = c => Dict
......
...@@ -17,8 +17,7 @@ ...@@ -17,8 +17,7 @@
/** Inserts an entry in the Static Pointer Table. /** Inserts an entry in the Static Pointer Table.
* *
* The key is a fingerprint computed from the StaticName of a static pointer * The key is a fingerprint computed from the StaticName of a static pointer
* and the spe_closure is a pointer to the closure defining the table entry * and the spe_closure is a pointer to the closure defining the table entry.
* (GHC.SptEntry).
* *
* A stable pointer to the closure is made to prevent it from being garbage * A stable pointer to the closure is made to prevent it from being garbage
* collected while the entry exists on the table. * collected while the entry exists on the table.
......
...@@ -206,7 +206,7 @@ lookupHashTable(HashTable *table, StgWord key) ...@@ -206,7 +206,7 @@ lookupHashTable(HashTable *table, StgWord key)
return NULL; return NULL;
} }
// Puts up to keys_sz keys of the hash table into the given array. Returns the // Puts up to szKeys keys of the hash table into the given array. Returns the
// actual amount of keys that have been retrieved. // actual amount of keys that have been retrieved.
// //
// If the table is modified concurrently, the function behavior is undefined. // If the table is modified concurrently, the function behavior is undefined.
......
...@@ -21,7 +21,7 @@ void * removeHashTable ( HashTable *table, StgWord key, void *data ); ...@@ -21,7 +21,7 @@ void * removeHashTable ( HashTable *table, StgWord key, void *data );
int keyCountHashTable (HashTable *table); int keyCountHashTable (HashTable *table);
// Puts up to keys_sz keys of the hash table into the given array. Returns the // Puts up to szKeys keys of the hash table into the given array. Returns the
// actual amount of keys that have been retrieved. // actual amount of keys that have been retrieved.
// //
// If the table is modified concurrently, the function behavior is undefined. // If the table is modified concurrently, the function behavior is undefined.
......
...@@ -14,9 +14,9 @@ import Unsafe.Coerce (unsafeCoerce) ...@@ -14,9 +14,9 @@ import Unsafe.Coerce (unsafeCoerce)
nats :: [Integer] nats :: [Integer]
nats = [0 .. ] nats = [0 .. ]
-- Just a StaticPtr to some CAF so that we can deRef it. -- The key of a 'StaticPtr' to some CAF.
nats_fp :: StaticKey nats_key :: StaticKey
nats_fp = staticKey (static nats :: StaticPtr [Integer]) nats_key = staticKey (static nats :: StaticPtr [Integer])
main = do main = do
let z = nats !! 400 let z = nats !! 400
...@@ -26,8 +26,8 @@ main = do ...@@ -26,8 +26,8 @@ main = do
print z print z
performGC performGC
threadDelay 1000000 threadDelay 1000000
let Just p = unsafeLookupStaticPtr nats_fp let Just p = unsafeLookupStaticPtr nats_key
print (deRefStaticPtr (unsafeCoerce p) !! 800 :: Integer) print (deRefStaticPtr (unsafeCoerce p) !! 800 :: Integer)
-- Uncommenting the next line keeps primes alive and would prevent a segfault -- Uncommenting the next line keeps 'nats' alive and would prevent a segfault
-- if nats were garbage collected. -- if 'nats' were garbage collected.
-- print (nats !! 900) -- print (nats !! 900)
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StaticPointers #-} {-# LANGUAGE StaticPointers #-}
-- | A test to try the static form in splices. -- | A test to try the static form in splices, which should fail.
--
-- A static form is defined in a splice and then it is used in the program.
-- --
module Main(main) where module Main(main) where
......
TH_StaticPointers02.hs:13:34: TH_StaticPointers02.hs:11:34:
static forms cannot be used in splices: static 'a' static forms cannot be used in splices: static 'a'
In the splice: In the splice:
$(case staticKey (static 'a') of { $(case staticKey (static 'a') of {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment