• Simon Marlow's avatar
    GHCi: add :seti, for options that apply only at the prompt (#3217) · 2e55760b
    Simon Marlow authored
    GHCi now maintains two DynFlags: one that applies to whole modules
    loaded with :load, and one that applies to things typed at the prompt
    (expressions, statements, declarations, commands).
      The :set command modifies both DynFlags.  This is for backwards
      compatibility: users won't notice any difference.
      The :seti command applies only to the interactive DynFlags.
    Additionally, I made a few changes to ":set" (with no arguments):
      * Now it only prints out options that differ from the defaults,
        rather than the whole list.
      * There is a new variant, ":set -a" to print out all options (the
        old behaviour).
      * It also prints out language options.
    Prelude> :set
    options currently set: none.
    base language is: Haskell2010
    with the following modifiers:
    GHCi-specific dynamic flag settings:
    other dynamic, non-language, flag settings:
    warning settings:
    ":seti" (with no arguments) does the same as ":set", but for the
    interactive options.  It also has the "-a" option.
    The interactive DynFlags are kept in the InteractiveContext, and
    copied into the HscEnv at the appropriate points (all in HscMain).
    There are some new GHC API operations:
    -- | Set the 'DynFlags' used to evaluate interactive expressions.
    setInteractiveDynFlags :: GhcMonad m => DynFlags -> m ()
    -- | Get the 'DynFlags' used to evaluate interactive expressions.
    getInteractiveDynFlags :: GhcMonad m => m DynFlags
    -- | Sets the program 'DynFlags'.
    setProgramDynFlags :: GhcMonad m => DynFlags -> m [PackageId]
    -- | Returns the program 'DynFlags'.
    getProgramDynFlags :: GhcMonad m => m DynFlags
    Note I have not completed the whole of the plan outlined in #3217 yet:
    when in the context of a loaded module we don't take the interactive
    DynFlags from that module.  That needs some more refactoring and
    thinking about, because we'll need to save and restore the original
    interactive DynFlags.
    This solves the immediate problem that people are having with the new
    flag checking in 7.4.1, because now it is possible to set language
    options in ~/.ghci that do not affect loaded modules and thereby cause