Namespace-specified wildcards in import/export lists (#25901)
This change adds support for top-level namespace-specified wildcards type .. and data .. to import and export lists (part of GHC Proposal #581 "Namespace-specified imports").
Examples:
import M (type ..) -- imports all type and class constructors from M
import M (data ..) -- imports all data constructors and terms from M
module M (type .., f) where
-- exports all type and class constructors defined in M,
-- plus the function 'f'
The primary intended usage of this feature is in combination with module aliases, allowing namespace disambiguation:
import Data.Proxy as T (type ..) -- T.Proxy is unambiguously the type constructor
import Data.Proxy as D (data ..) -- D.Proxy is unambiguously the data constructor
The patch accounts for the interactions of wildcards with:
- Imports with
hidingclauses - Import warnings
-Wunused-imports,-Wdodgy-imports - Export warnings
-Wduplicate-exports,-Wdodgy-exports
Summary of the changes:
-
Move the
NamespaceSpecifiertype fromGHC.Hs.BindstoGHC.Hs.Basic, making it possible to use it in more places in the AST. -
Extend the AST (type:
IE) with a representation of..,type .., anddata ..(constructor:IEWholeNamespace). Per the proposal, the plain..is always rejected with a dedicated error message. -
Extend the grammar in
Parser.ywith productions for..,type .., anddata ..in both import and export lists. -
Implement wildcard imports by updating the
filterImportsfunction inGHC.Rename.Names; the logic forIEWholeNamespaceis roughly modeled after theNothing(no explicit import list) case. -
Implement wildcard exports by updating the
exports_from_availfunction inGHC.Tc.Gen.Export; the logic forIEWholeNamespaceis closely modeled after theIEModuleContentscase. -
Refactor and extend diagnostics to report the new warnings and errors. See
PsErrPlainWildcardImport,DodgyImportsWildcard,PsErrPlainWildcardExport,DodgyExportsWildcard,TcRnDupeWildcardExport.
Note that this patch is specifically about top-level import/export items. Subordinate import/export items are left unchanged.