... | ... | @@ -15,7 +15,7 @@ However, there is a short-term workable plan for GHC 7.10, that does not require |
|
|
|
|
|
The proposal is therefore to:
|
|
|
|
|
|
- Implement the extension in two phases: the full version with full dynamic type checks on top of a revised `Data.Typeable` in GHC 7.12, but an interim version in GHC 7.10 *with the same API* but with the dynamic type checks enabled by the SPT missing.
|
|
|
- Implement the extension in two phases: the full version with full dynamic type checks on top of a revised `Data.Typeable` in GHC 7.12, but an interim version in GHC 7.10 **with the exact same API** but with the dynamic type checks enabled by the SPT missing.
|
|
|
|
|
|
- In GHC 7.10, *implement only a shim SPT*, that looks just like the real thing, but does not include `tTypeRep`s or `TypeRep`s for any value. The reason we still need an SPT in GHC 7.10 is because there needs to be something that references static expressions throughout the lifetime of the program. The reason is that any such expression may at any time be referenced by a new `StaticPtr` produced from an incoming message. In other words, in a distributed system, other nodes may refer to values that are otherwise not live on the local node. The SPT must itself be protected against garbage collection, e.g. through the use of a `StablePtr`.
|
|
|
|
... | ... | @@ -33,9 +33,12 @@ module GHC.StaticPtr |
|
|
|
|
|
data StaticPtr a
|
|
|
|
|
|
-- | A 'Dynamic' that wraps a 'StaticPtr'
|
|
|
type DynStaticPtr = Dynamic
|
|
|
|
|
|
deRefStaticPtr :: StaticPtr a -> a
|
|
|
fingerprint :: StaticPtr a -> Fingerprint
|
|
|
lookup :: Fingerprint -> Maybe Dynamic -- or DynStaticPtr
|
|
|
lookup :: Fingerprint -> Maybe DynStaticPtr
|
|
|
```
|
|
|
|
|
|
**Remarks:**
|
... | ... | @@ -56,7 +59,7 @@ lookup :: Fingerprint -> Maybe Dynamic -- or DynStaticPtr |
|
|
- Each occurrence of `static e` where `e :: a` incurs a new top-level definition:
|
|
|
|
|
|
```wiki
|
|
|
__static_f :: Dynamic
|
|
|
__static_f :: DynStaticPtr
|
|
|
__static_f = toDynamic (StaticPtr (Fingerprint ...) e)
|
|
|
```
|
|
|
|
... | ... | @@ -66,6 +69,7 @@ where `__static_f` is a fresh name. |
|
|
- In the type checker, we add `Typeable a` to the set of constraints.
|
|
|
- All such `__static_*` definitions are considered SPT entries. All SPT entries are collected into the SPT for each module, constructed by the code produced by `mkModuleInit`.
|
|
|
- A global SPT constructed using the SPT from each module by the RTS just before `main` is invoked.
|
|
|
- The RTS creates a `StablePtr` to the global SPT (and transitively any of its dependencies), to avoid it being garbage collected.
|
|
|
- The SPT is a hash table mapping `Fingerprint`s to `StaticPtr`s.
|
|
|
|
|
|
**Remark:** do we need `__static_f` at all? It looks like we could get `mkModuleInit` to generate the right code with all the entries, without the extra indirection.
|
... | ... | |