Skip to content
  • Hannes Siebenhandl's avatar
    286f1adf
    Fix regression T27202: `:load` and `:add` work in GHCi · 286f1adf
    Hannes Siebenhandl authored and Marge Bot's avatar Marge Bot committed
    To fix the regression there are conceptually two major things that we
    fix:
    
    * We don't remove the `importDirs` from `interactive-session`
    * When `:add`ing a module, we don't try to find them via PackageImports
        * The PackageImport is wrong as we can't know the package-name at
          this stage in ghc/UI.hs
    
    What does it mean to not remove the `importDirs` from
    `interactive-session`?
    It means that, given some initial `DynFlags`, we will use those
    `importDirs` in `interactive-session`.
    
    The initial `DynFlags`, however, depend on how you initialise the GHC
    session.
    For a simple session, initialised by
    
        ghc -isrc -this-unit-id main
    
    It is simple, just use the `DynFlags` given on the cli.
    Thus, `main` and `interactive-session` will have the same `DynFlags`,
    except for the `homeUnitId` and `interactive-session` depends on `main`
    by construction of the GHCi session.
    
    What about a multiple home unit session, though?
    
        ghc -unit @unit1 -unit @unit2
    
    What are the `DynFlags` in this cli invocation? It shouldn't be either
    `@unti1` nor `@unit2`, as the order shouldn't matter or any other
    implicit condition.
    
    For consistency, we decide that the initial `DynFlags` are the top
    `DynFlags` on the cli, ignoring `-unit` flags.
    Thus, in this example, there are no `importsDirs` regardless of what we
    might find in `@unit1` and `@unit2`.
    
    But in this invocation:
    
        ghc -isrc -unit @unit1 -unit @unit2
    
    The `interactive-session` will have the `importsDirs` `src`.
    Note, `-isrc` will be inherited in `@unit1` and `@unit2`, so you need to
    explicitly use `-i` to clear the `importsDirs`, in order to avoid
    accidentally adding `src` as an import directory to all other home
    units.
    
    This fix has been made possible by the improvements introduced in
    !15888, which avoids ambiguity when a home unit shares the `importsDirs`
    with the `interactive-session`, on top of being much faster for multiple
    home units.
    
    Adds regression tests for T27202 for `:load`ing and `:add`ing modules
    that are located in import directories.
    286f1adf
    Fix regression T27202: `:load` and `:add` work in GHCi
    Hannes Siebenhandl authored and Marge Bot's avatar Marge Bot committed
    To fix the regression there are conceptually two major things that we
    fix:
    
    * We don't remove the `importDirs` from `interactive-session`
    * When `:add`ing a module, we don't try to find them via PackageImports
        * The PackageImport is wrong as we can't know the package-name at
          this stage in ghc/UI.hs
    
    What does it mean to not remove the `importDirs` from
    `interactive-session`?
    It means that, given some initial `DynFlags`, we will use those
    `importDirs` in `interactive-session`.
    
    The initial `DynFlags`, however, depend on how you initialise the GHC
    session.
    For a simple session, initialised by
    
        ghc -isrc -this-unit-id main
    
    It is simple, just use the `DynFlags` given on the cli.
    Thus, `main` and `interactive-session` will have the same `DynFlags`,
    except for the `homeUnitId` and `interactive-session` depends on `main`
    by construction of the GHCi session.
    
    What about a multiple home unit session, though?
    
        ghc -unit @unit1 -unit @unit2
    
    What are the `DynFlags` in this cli invocation? It shouldn't be either
    `@unti1` nor `@unit2`, as the order shouldn't matter or any other
    implicit condition.
    
    For consistency, we decide that the initial `DynFlags` are the top
    `DynFlags` on the cli, ignoring `-unit` flags.
    Thus, in this example, there are no `importsDirs` regardless of what we
    might find in `@unit1` and `@unit2`.
    
    But in this invocation:
    
        ghc -isrc -unit @unit1 -unit @unit2
    
    The `interactive-session` will have the `importsDirs` `src`.
    Note, `-isrc` will be inherited in `@unit1` and `@unit2`, so you need to
    explicitly use `-i` to clear the `importsDirs`, in order to avoid
    accidentally adding `src` as an import directory to all other home
    units.
    
    This fix has been made possible by the improvements introduced in
    !15888, which avoids ambiguity when a home unit shares the `importsDirs`
    with the `interactive-session`, on top of being much faster for multiple
    home units.
    
    Adds regression tests for T27202 for `:load`ing and `:add`ing modules
    that are located in import directories.
Loading