Skip to content

Draft: Add machinery for plugins to write data to extensible interface fields

Josh Meredith requested to merge wip/pluginExtFields into master

Implementation for #18503

Currently extensible interface files are only able to be written to by external users of the GHC API - after the interface file has been created.

These changes add functions for plugins to write data out during the pipeline, and have it be included in the interface file when it is written to disk, via either GHC's Binary typeclass, or by writing directly to the BinHandle, in the case of more complicated fields, such as those requiring headers/footers:

  • registerInterfaceData :: Binary a => FieldName -> HscEnv -> a -> IO ()
  • registerInterfaceDataWith :: FieldName -> HscEnv -> (BinHandle -> IO ()) -> IO ()
  • unregisterInterfaceData :: FieldName -> HscEnv -> IO ()

The registered fields are stored in a serialised form in the HscEnv - hsc_ext_fields :: !(IORef ExtensibleFields), allowing plugins, which have access to the HscEnv, to write fields.

Edited by Andreas Klebinger

Merge request reports