Skip to content

Rework exportsMap on top of hiedb #1941

Closed
@pepeiborra

Description

@pepeiborra

is a mutable table of names exported by modules in the local project that is used to drive import quick fixes.

The current implementation populates the table by

  1. Typechecking all the project modules at startup:

    -- Typecheck all files in the project on startup
    checkProject <- getCheckProject
    unless (null cs || not checkProject) $ do
    cfps' <- liftIO $ filterM (IO.doesFileExist . fromNormalizedFilePath) (concatMap targetLocations cs)
    void $ shakeEnqueue extras $ mkDelayedAction "InitialLoad" Debug $ void $ do
    mmt <- uses GetModificationTime cfps'
    let cs_exist = catMaybes (zipWith (<$) cfps' mmt)
    modIfaces <- uses GetModIface cs_exist
    -- update exports map
    extras <- getShakeExtras
    let !exportsMap' = createExportsMap $ mapMaybe (fmap hirModIface) modIfaces

  2. Refreshing on every kick:

ifaces <- if checkProject then return Nothing else runMaybeT $ do
deps <- MaybeT $ sequence <$> uses GetDependencies files
hiResults <- lift $ uses GetModIface (nubOrd $ foldMap transitiveModuleDeps deps)
return $ map hirModIface $ catMaybes hiResults
ShakeExtras{exportsMap} <- getShakeExtras
let mguts = catMaybes results
!exportsMap' = createExportsMapMg mguts
!exportsMap'' = maybe mempty createExportsMap ifaces
void $ liftIO $ modifyVar' exportsMap $ (exportsMap'' <>) . (exportsMap' <>)

1 could be replaced by a hiedb query, assuming that the hiedb is fully uptodate. This may not be always the case for a new project, but it will work fine on a project that has previously been loaded and type checked.

2 does a lot of work when checkProject is disabled, by scanning all the transitive dependencies. If we switch 1 to use hiedb we can also make it unconditional and then eliminate the transitive scan from 2.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions