 Keep only hiding imports making them non-hiding. This function
-- needed to collect unused hiding imports because @importTable@ doesn't
-- track information about hiding imports.
switchHidingImports :: Module SrcSpanInfo -> Module SrcSpanInfo
switchHidingImports (Module ml mhead mpragmas mimports mdecls) =
    Module ml
           mhead
           ( LanguagePragma noSrcSpan
                            [ Ident noSrcSpan
                            $ prettyExtension
                            $ DisableExtension ImplicitPrelude
                            ]
           : mpragmas)
           (mapMaybe unhide mimports)
           mdecls
  where
    unhide :: ImportDecl SrcSpanInfo -> Maybe (ImportDecl SrcSpanInfo)
    unhide decl = do
        ImportSpecList l isHiding imports <- importSpecs decl
        guard isHiding
        guard $ not $ isInsideExport mhead (importReferenceName decl)
        pure $ decl { importSpecs = Just $ ImportSpecList l False imports }

sw
switchHidingImports :: Module SrcSpanInfo -> Module SrcSpanInfo
switchHidingImports (Module ml mhead mpragmas mimports mdecls) =
    Module ml
           mhead
           ( LanguagePragma noSrcSpan
                            [ Ident noSrcSpan
                            $ prettyExtension
                            $ DisableExtension ImplicitPrelude
                            ]
           : mpragmas)
           (mapMaybe unhide mimports)
           mdecls
  where
    unhide :: ImportDecl SrcSpanInfo -> Maybe (ImportDecl SrcSpanInfo)
    unhide decl = do
        ImportSpecList l isHiding imports <- importSpecs decl
        guard isHiding
        guard $ not $ isInsideExport mhead (importReferenceName decl)
        pure $ decl { importSpecs = Just $ ImportSpecList l False imports }
switchHidingImports (Module ml mhead mpragmas mimports mdecls) =
    Module ml
           mhead
           ( LanguagePragma noSrcSpan
                            [ Ident noSrcSpan
                            $ prettyExtension
                            $ DisableExtension ImplicitPrelude
                            ]
           : mpragmas)
           (mapMaybe unhide mimports)
           mdecls
  where
    unhide :: ImportDecl SrcSpanInfo -> Maybe (ImportDecl SrcSpanInfo)
    unhide decl = do
        ImportSpecList l isHiding imports <- importSpecs decl
        guard isHiding
        guard $ not $ isInsideExport mhead (importReferenceName decl)
        pure $ decl { importSpecs = Just $ ImportSpecList l False imports }