Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,356
    • Issues 5,356
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 569
    • Merge requests 569
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #15513
Closed
Open
Issue created Aug 13, 2018 by lspitzner@trac-lspitzner

How to pass "-hide-all-packages" to the GHC API?

In brittany, we have make use of the GHC API e.g. in the following fashion:

parseModuleFromString
  :: [String]
  -> System.IO.FilePath
  -> (GHC.DynFlags -> IO (Either String a))
  -> String
  -> IO (Either String (ExactPrint.Anns, GHC.ParsedSource, a))
parseModuleFromString args fp dynCheck str =
  mask_ $ ExactPrint.ghcWrapper $ ExceptT.runExceptT $ do
    dflags0                       <- lift $ ExactPrint.initDynFlagsPure fp str
    (dflags1, leftover, warnings) <- lift
      $ GHC.parseDynamicFlagsCmdLine dflags0 (GHC.noLoc <$> args)
    when (not $ null leftover)
      $  ExceptT.throwE
      $  "when parsing ghc flags: leftover flags: "
      ++ show (leftover <&> \(L _ s) -> s)
    when (not $ null warnings)
      $  ExceptT.throwE
      $  "when parsing ghc flags: encountered warnings: "
      ++ show (warnings <&> warnExtractorCompat)
    dynCheckRes <- ExceptT.ExceptT $ liftIO $ dynCheck dflags1
    let res = ExactPrint.parseModuleFromStringInternal dflags1 fp str
    case res of
      Left  (span, err) -> ExceptT.throwE $ show span ++ ": " ++ err
      Right (a   , m  ) -> pure (a, m, dynCheckRes)

This code unfortunately picks up "package environment files", which I take it is not at all necessary for this use-case: Brittany only requires parsing functionality, so external packages should be irrelevant. "Unfortunately", because the package environment files can easily become stale, which in turn breaks the API.

The users' guide mentions the "-hide-all-packages" flag, but my attempts to pass this to the API so far have failed. What I have tried is calling parseDynamicFlagsCmdLine with "-hide-all-packages" as an argument, and using the resulting dynflags afterwards. This appears to be without effect, ~~I think even when it is the first thing executed inside of runGhc~~ (not entirely correct, see below).

Edited Mar 10, 2019 by lspitzner
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking