Changes between Version 4 and Version 5 of Plugins/ReinitializeGlobals


Ignore:
Timestamp:
Jul 5, 2013 3:17:32 PM (21 months ago)
Author:
nfrisby
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Plugins/ReinitializeGlobals

    v4 v5  
    133133 
    134134So the rule would be: ''if your plugin might allocate new !FastStrings, be warned that GHCI might not work quite right''. 
     135 
     136=== Option 5: Circuler `IORef`s === 
     137 
     138This is idea is predicated on the fact that there are at most two libHSghc images in memory. 
     139 
     140We could change `FastStringTable` to the following. 
     141 
     142{{{ 
     143data Maybe_FST = Nothing_FST | Just_FST !(IORef FastStringTable) 
     144 
     145data FastStringTable = 
     146  FastStringTable 
     147     {-# UNPACK #-} !Int 
     148     (MutableArray# RealWorld [FastString]) 
     149     {-# UNPACK #-} !Maybe_FST 
     150}}} 
     151 
     152Semantics: The new field points at the other image's `string_table`; `reinitializeGlobals` would setup this circularity. When updating the `Int` field of one, it would also update the `Int` field of the other. We wouldn't need to duplicate any work for the array, since that pointer is easily directly shared. 
     153 
     154Performance: I'm hoping pointer tagging, unpacking (can we unpack small sum types?), and branch prediction will ameliorate the extra instructions, especially when there is no plugin. Moreover, this extra work would only happen when allocating new `FastStrings`, which is relatively infrequent.