ghc-9.2.8: The GHC API
Safe HaskellSafe-Inferred
LanguageHaskell2010

GHC.Iface.Tidy.StaticPtrTable

Description

Code generation for the Static Pointer Table

(c) 2014 I/O Tweag

Each module that uses static keyword declares an initialization function of the form hs_spt_init_<module>() which is emitted into the _stub.c file and annotated with attribute((constructor)) so that it gets executed at startup time.

The function's purpose is to call hs_spt_insert to insert the static pointers of this module in the hashtable of the RTS, and it looks something like this:

static void hs_hpc_init_Main(void) __attribute__((constructor));
static void hs_hpc_init_Main(void) {

  static StgWord64 k0[2] = {16252233372134256ULL,7370534374096082ULL};
  extern StgPtr Main_r2wb_closure;
  hs_spt_insert(k0, &Main_r2wb_closure);

  static StgWord64 k1[2] = {12545634534567898ULL,5409674567544151ULL};
  extern StgPtr Main_r2wc_closure;
  hs_spt_insert(k1, &Main_r2wc_closure);

}

where the constants are fingerprints produced from the static forms.

The linker must find the definitions matching the extern StgPtr name declarations. For this to work, the identifiers of static pointers need to be exported. This is done in newLvlVar.

There is also a finalization function for the time when the module is unloaded.

static void hs_hpc_fini_Main(void) __attribute__((destructor));
static void hs_hpc_fini_Main(void) {

  static StgWord64 k0[2] = {16252233372134256ULL,7370534374096082ULL};
  hs_spt_remove(k0);

  static StgWord64 k1[2] = {12545634534567898ULL,5409674567544151ULL};
  hs_spt_remove(k1);

}
Synopsis

Documentation

sptCreateStaticBinds :: HscEnv -> Module -> CoreProgram -> IO ([SptEntry], CoreProgram) Source #

Replaces all bindings of the form

b = /\ ... -> makeStatic location value

with

b = /\ ... ->
  StaticPtr key (StaticPtrInfo "pkg key" "module" location) value

where a distinct key is generated for each binding.

It also yields the C stub that inserts these bindings into the static pointer table.

sptModuleInitCode :: Platform -> Module -> [SptEntry] -> CStub Source #

sptModuleInitCode module fps is a C stub to insert the static entries of module into the static pointer table.

fps is a list associating each binding corresponding to a static entry with its fingerprint.