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

Groom comments related to StaticPointers.

Reviewed By: austin

Differential Revision: https://phabricator.haskell.org/D575
parent 22bb78bb
......@@ -24,8 +24,7 @@
-- >
-- > }
--
-- where constants are values of a fingerprint of the string
-- "<package_id>:<module_name>.sptEntry:<N>"
-- where the constants are fingerprints produced from the static forms.
--
module StaticPtrTable (sptInitCode) where
......@@ -38,7 +37,7 @@ import GHC.Fingerprint
-- | @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
-- top-level binding for the entry.
......
......@@ -313,7 +313,7 @@ rnExpr e@(ELazyPat {}) = patSynErr e
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
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
......
......@@ -10470,9 +10470,6 @@ While the following definitions are rejected:
ref6 = let x = 1 in static x
ref7 y = static (let x = 1 in y)
</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>
</sect2>
......@@ -10502,13 +10499,14 @@ That being said, with the appropriate use of wrapper datatypes, the
above limitations induce no loss of generality:
<programlisting>
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DerivingDataTypeable #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE StaticPointers #-}
import Control.Monad.ST
import Data.Typeable
import GHC.StaticPtr
data Dict c = c => Dict
......
......@@ -17,8 +17,7 @@
/** Inserts an entry in the Static Pointer Table.
*
* 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
* (GHC.SptEntry).
* and the spe_closure is a pointer to the closure defining the table entry.
*
* A stable pointer to the closure is made to prevent it from being garbage
* collected while the entry exists on the table.
......
......@@ -206,7 +206,7 @@ lookupHashTable(HashTable *table, StgWord key)
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.
//
// If the table is modified concurrently, the function behavior is undefined.
......
......@@ -21,7 +21,7 @@ void * removeHashTable ( HashTable *table, StgWord key, void *data );
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.
//
// If the table is modified concurrently, the function behavior is undefined.
......
......@@ -14,9 +14,9 @@ import Unsafe.Coerce (unsafeCoerce)
nats :: [Integer]
nats = [0 .. ]
-- Just a StaticPtr to some CAF so that we can deRef it.
nats_fp :: StaticKey
nats_fp = staticKey (static nats :: StaticPtr [Integer])
-- The key of a 'StaticPtr' to some CAF.
nats_key :: StaticKey
nats_key = staticKey (static nats :: StaticPtr [Integer])
main = do
let z = nats !! 400
......@@ -26,8 +26,8 @@ main = do
print z
performGC
threadDelay 1000000
let Just p = unsafeLookupStaticPtr nats_fp
let Just p = unsafeLookupStaticPtr nats_key
print (deRefStaticPtr (unsafeCoerce p) !! 800 :: Integer)
-- Uncommenting the next line keeps primes alive and would prevent a segfault
-- if nats were garbage collected.
-- Uncommenting the next line keeps 'nats' alive and would prevent a segfault
-- if 'nats' were garbage collected.
-- print (nats !! 900)
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StaticPointers #-}
-- | A test to try the static form in splices.
--
-- A static form is defined in a splice and then it is used in the program.
-- | A test to try the static form in splices, which should fail.
--
module Main(main) where
......
TH_StaticPointers02.hs:13:34:
TH_StaticPointers02.hs:11:34:
static forms cannot be used in splices: static 'a'
In the splice:
$(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