diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2016-11-02 15:06:31 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-11-02 15:42:01 -0400 |
commit | 80076fa68f68e337d74c42311f9c3ebebbdc4680 (patch) | |
tree | a8dc28d1b3f165740e576d11007dd88453f0b640 | |
parent | dc4d59621dff31908dc7646082a2c5a362deb10f (diff) | |
download | haskell-80076fa68f68e337d74c42311f9c3ebebbdc4680.tar.gz |
Add notes describing SRT concepts
Test Plan: Read it
Reviewers: austin, erikd, simonmar
Reviewed By: simonmar
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2663
-rw-r--r-- | compiler/stgSyn/CoreToStg.hs | 28 | ||||
-rw-r--r-- | includes/rts/storage/InfoTables.h | 13 |
2 files changed, 40 insertions, 1 deletions
diff --git a/compiler/stgSyn/CoreToStg.hs b/compiler/stgSyn/CoreToStg.hs index d130b74ea2..0e33918d8a 100644 --- a/compiler/stgSyn/CoreToStg.hs +++ b/compiler/stgSyn/CoreToStg.hs @@ -86,6 +86,34 @@ import Control.Monad (liftM, ap) -- live then so is `q'. Furthermore, if `e' mentions an enclosing -- let-no-escaped variable, then its free variables are also live if `v' is. +-- Note [What are these SRTs all about?] +-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +-- +-- Consider the Core program, +-- +-- fibs = go 1 1 +-- where go a b = let c = a + c +-- in c : go b c +-- add x = map (\y -> x*y) fibs +-- +-- In this case we have a CAF, 'fibs', which is quite large after evaluation and +-- has only one possible user, 'add'. Consequently, we want to ensure that when +-- all references to 'add' die we can garbage collect any bit of 'fibs' that we +-- have evaluated. +-- +-- However, how do we know whether there are any references to 'fibs' still +-- around? Afterall, the only reference to it is buried in the code generated +-- for 'add'. The answer is that we record the CAFs referred to by a definition +-- in its info table, namely a part of it known as the Static Reference Table +-- (SRT). +-- +-- Since SRTs are so common, we use a special compact encoding for them in: we +-- produce one table containing a list of CAFs in a module and then include a +-- bitmap in each info table describing which entries of this table the closure +-- references. +-- +-- See also: Commentary/Rts/Storage/GC/CAFs on the GHC Wiki. + -- Note [Collecting live CAF info] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- diff --git a/includes/rts/storage/InfoTables.h b/includes/rts/storage/InfoTables.h index fb14ac5821..bb1bac0c65 100644 --- a/includes/rts/storage/InfoTables.h +++ b/includes/rts/storage/InfoTables.h @@ -223,10 +223,21 @@ typedef struct StgInfoTable_ { them doesn't affect the layout). - If srt_bitmap (in the std info table part) is zero, then the srt - field may be omitted. This only applies if the slow_apply and + field needn't be set. This only applies if the slow_apply and bitmap fields have also been omitted. -------------------------------------------------------------------------- */ +/* + Note [Encoding static reference tables] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + As static reference tables appear frequently in code, we use a special + compact encoding for the common case of a module defining only a few CAFs: We + produce one table containing a list of CAFs in the module and then include a + bitmap in each info table describing which entries of this table the closure + references. + */ + typedef struct StgFunInfoExtraRev_ { OFFSET_FIELD(slow_apply_offset); /* apply to args on the stack */ union { |