Matthew Pickering pushed to branch wip/gbc-files at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/ByteCode/Serialize.hs
    ... ... @@ -40,18 +40,11 @@ import System.IO.Unsafe (unsafeInterleaveIO)
    40 40
     {- Note [Overview of persistent bytecode]
    
    41 41
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    42 42
     
    
    43
    -GHC can produce a .gbc file, which is a serialised representation of a bytecode object.
    
    43
    +By default, when using the interpreter, a Haskell module is first compiled to bytecode (which lives in memory) and then executed by the RTS interpreter. However, when dealing with many modules compiling to bytecode from scratch every time is expensive. This is especially relevant for interpreter-heavy workflows on large projects where changes are incremental or non-existent (e.g. running the project in the debugger).
    
    44 44
     
    
    45
    -By passing the flag `-fwrite-bytecode`, then when using the bytecode backend,
    
    46
    -a .gbc file will be written to the output directory.
    
    45
    +In light of this, GHC can produce so-called `.gbc` files, which contain a serialized representation of the bytecode objects in a Haskell module. These files are written by enabling the flag `-fwrite-bytecode` when using the interpreter.
    
    47 46
     
    
    48
    -The primary use case for the file is to avoid having to recompile when using
    
    49
    -GHCi. Instead, the driver will look for the interface and .gbc file and load
    
    50
    -those to avoid recompiling.
    
    51
    -
    
    52
    -* This can save a lot of time if you have many modules. Even compared to `-fwrite-if-simplified-core`.
    
    53
    -* The source code might not be available, but you may still want to run the bytecode rather than
    
    54
    -  native object code (for example, for debugging).
    
    47
    +The driver will always look for both the interface and the `.gbc` file and load those to avoid unnecessary recompilation. This can save a lot of time if you have many modules. Even compared to `-fwrite-if-simplified-core`.
    
    55 48
     
    
    56 49
     .gbc files are standalone, in the sense that they can be loaded into the interpreter
    
    57 50
     without having the interface file or source files available. In the future you could
    

  • compiler/GHC/Driver/Main.hs
    ... ... @@ -877,7 +877,7 @@ hscRecompStatus
    877 877
                           , text "BCO core linkable", ppr bc_core_linkable
    
    878 878
                           , text "Object Linkable", ppr obj_linkable])
    
    879 879
     
    
    880
    -               let just_o  = justObjects  <$> obj_linkable
    
    880
    +               let just_o = justObjects <$> obj_linkable
    
    881 881
     
    
    882 882
                        bytecode_or_object_code
    
    883 883
                           | gopt Opt_WriteByteCode lcl_dflags = justBytecode <$> definitely_bc
    
    ... ... @@ -2215,7 +2215,7 @@ generateAndWriteByteCode hsc_env cgguts mod_location = do
    2215 2215
     
    
    2216 2216
     {-
    
    2217 2217
     Note [-fwrite-bytecode is not the default]
    
    2218
    -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    2218
    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    2219 2219
     
    
    2220 2220
     `-fwrite-bytecode` is not enabled by default because previously using `-fbyte-code` would
    
    2221 2221
     not write anything at all to disk. For example, GHCi would not write anything to the directory