Skip to content
  • Rodrigo Mesquita's avatar
    6b7ea592
    driver: Store the HomePackageTable in a mutable reference · 6b7ea592
    Rodrigo Mesquita authored and Marge Bot's avatar Marge Bot committed
    
    
    This commit refactors the HomePackageTable and HomeUnitGraph:
    
    (1) It fixes a quadratic-in-the-number-of-modules space leak in upsweep (#25511)
    
    (2) And it reworks these structures into their own modules to simplify
        the driver. The refactor is driven by the introduction of IO in the HPT
        interface, but is a bit more aggressive in simplifying the
        interfaces to enforce correct usage (ie to avoid performance
        pitfalls).
    
    Specifically:
    
    - The `HomeUnitGraph` (HUG) is now in `GHC.Unit.Home.Graph`
    - The `HomePackageTable` (HPT) is now in `GHC.Unit.Home.PackageTable`
        - The HPT now stores an `IORef` with the table of loaded home package modules.
        - The interface to the HPT now requires IO
        - The interface now enforces that the HPT is a datastructure that
          only grows
        - This is not enforced in the interface, but, clients of the HPT
          should never care about there being more or less entries in the
          HPT when these additional entries are not relevant to their result.
        - The exception to the invariant that the HPT is monotonically
          increasing is `restrictHpt`, a function which is called at a
          "barrier point" (during which there are no other threads
          inspecting or inserting in the HPT). The invariant can be
          temporarily broken at this point (currently, after upsweep).
          This is safe because a single thread holds control over the
          structure (thus the invariant being broken is never observed).
    
    The hug_var and associated structures in the driver, which aimed to
    improve memory usage in the driver by updating in place a HUG during
    upsweep, are no longer required as the HPT entries in the HUG are now
    themselves mutable by construction. This was previously explained in
    Note [ModuleNameSet, efficiency and space leaks], which is no longer
    relevant and was deleted.
    
    Fixes #25511
    
    Co-authored-by: default avatarMatthew Pickering <matthewtpickering@gmail.com>
    
    -------------------------
    Metric Decrease:
        MultiComponentModulesRecomp
        MultiLayerModulesRecomp
    -------------------------
    6b7ea592
    driver: Store the HomePackageTable in a mutable reference
    Rodrigo Mesquita authored and Marge Bot's avatar Marge Bot committed
    
    
    This commit refactors the HomePackageTable and HomeUnitGraph:
    
    (1) It fixes a quadratic-in-the-number-of-modules space leak in upsweep (#25511)
    
    (2) And it reworks these structures into their own modules to simplify
        the driver. The refactor is driven by the introduction of IO in the HPT
        interface, but is a bit more aggressive in simplifying the
        interfaces to enforce correct usage (ie to avoid performance
        pitfalls).
    
    Specifically:
    
    - The `HomeUnitGraph` (HUG) is now in `GHC.Unit.Home.Graph`
    - The `HomePackageTable` (HPT) is now in `GHC.Unit.Home.PackageTable`
        - The HPT now stores an `IORef` with the table of loaded home package modules.
        - The interface to the HPT now requires IO
        - The interface now enforces that the HPT is a datastructure that
          only grows
        - This is not enforced in the interface, but, clients of the HPT
          should never care about there being more or less entries in the
          HPT when these additional entries are not relevant to their result.
        - The exception to the invariant that the HPT is monotonically
          increasing is `restrictHpt`, a function which is called at a
          "barrier point" (during which there are no other threads
          inspecting or inserting in the HPT). The invariant can be
          temporarily broken at this point (currently, after upsweep).
          This is safe because a single thread holds control over the
          structure (thus the invariant being broken is never observed).
    
    The hug_var and associated structures in the driver, which aimed to
    improve memory usage in the driver by updating in place a HUG during
    upsweep, are no longer required as the HPT entries in the HUG are now
    themselves mutable by construction. This was previously explained in
    Note [ModuleNameSet, efficiency and space leaks], which is no longer
    relevant and was deleted.
    
    Fixes #25511
    
    Co-authored-by: default avatarMatthew Pickering <matthewtpickering@gmail.com>
    
    -------------------------
    Metric Decrease:
        MultiComponentModulesRecomp
        MultiLayerModulesRecomp
    -------------------------
Loading