Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework exportsMap on top of hiedb #1941

Closed
pepeiborra opened this issue Jun 17, 2021 · 1 comment · Fixed by #1989
Closed

Rework exportsMap on top of hiedb #1941

pepeiborra opened this issue Jun 17, 2021 · 1 comment · Fixed by #1989

Comments

@pepeiborra
Copy link
Collaborator

pepeiborra commented Jun 17, 2021

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.

@pepeiborra
Copy link
Collaborator Author

This will require adding a new table to hiedb that tracks the module exports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants