Skip to content

printMinimalImports does not close the .imports file into which it writes

Summary

Recent GHCs have a printMinimalImports which dumps a minimal set of imports into a file:

printMinimalImports :: [ImportDeclUsage] -> RnM ()
printMinimalImports imports_w_usage
  = do { imports' <- getMinimalImports imports_w_usage
       ; this_mod <- getModule
       ; dflags   <- getDynFlags
       ; liftIO $
         do { h <- openFile (mkFilename dflags this_mod) WriteMode
            ; printForUser dflags h neverQualify (vcat (map ppr imports')) }       
       }
  where
    mkFilename dflags this_mod
      | Just d <- dumpDir dflags = d </> basefn
      | otherwise                = basefn
      where
        basefn = moduleNameString (moduleName this_mod) ++ ".imports"

That file does not seem to be closed after the imports have been written.

Should it not be something like:

  109     printMinimalImports' dflags filename imports_w_usage =
  110       do
  111         imports' <- getMinimalImports imports_w_usage
  112         liftIO $
  113           withFile
  114             ..filename..
  115             WriteMode
  116             ( \h ->
  117                 printForUser dflags h neverQualify (vcat (map ppr imports'))
  118             )

?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information