packages feed

imp 1.0.2.0 → 1.0.2.1

raw patch · 8 files changed

+50/−95 lines, 8 filesdep ~Cabal-syntaxdep ~basedep ~containersPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: Cabal-syntax, base, containers, ghc, hspec, transformers

API changes (from Hackage documentation)

- Imp.Ghc: newImportDecl :: ModuleName -> ImportDecl GhcPs
- Imp.Ghc: type HsModulePs = HsModule GhcPs
- Imp: imp :: MonadThrow m => [String] -> ModuleName -> Located HsModulePs -> m (Located HsModulePs)
+ Imp: imp :: MonadThrow m => [String] -> ModuleName -> Located (HsModule GhcPs) -> m (Located (HsModule GhcPs))
- Imp.Extra.HsModule: overDecls :: Functor f => ([LHsDecl GhcPs] -> f [LHsDecl GhcPs]) -> HsModulePs -> f HsModulePs
+ Imp.Extra.HsModule: overDecls :: Functor f => ([LHsDecl GhcPs] -> f [LHsDecl GhcPs]) -> HsModule GhcPs -> f (HsModule GhcPs)
- Imp.Extra.HsModule: overImports :: ([LImportDecl GhcPs] -> [LImportDecl GhcPs]) -> HsModulePs -> HsModulePs
+ Imp.Extra.HsModule: overImports :: ([LImportDecl GhcPs] -> [LImportDecl GhcPs]) -> HsModule GhcPs -> HsModule GhcPs
- Imp.Extra.HsParsedModule: overModule :: Functor f => (Located HsModulePs -> f (Located HsModulePs)) -> HsParsedModule -> f HsParsedModule
+ Imp.Extra.HsParsedModule: overModule :: Functor f => (Located (HsModule GhcPs) -> f (Located (HsModule GhcPs))) -> HsParsedModule -> f HsParsedModule

Files

README.md view
@@ -1,20 +1,21 @@ # Imp -[![Workflow](https://github.com/tfausak/imp/actions/workflows/workflow.yaml/badge.svg)](https://github.com/tfausak/imp/actions/workflows/workflow.yaml)+[![CI](https://github.com/tfausak/imp/actions/workflows/ci.yml/badge.svg)](https://github.com/tfausak/imp/actions/workflows/ci.yml) [![Hackage](https://badgen.net/hackage/v/imp)](https://hackage.haskell.org/package/imp)-[![Stackage](https://www.stackage.org/package/imp/badge/nightly?label=stackage)](https://www.stackage.org/package/imp)  Imp is a GHC plugin for automatically importing modules. This behavior is similar to the [`-fimplicit-import-qualified`][1] flag for GHCi. In short, Imp allows you to use fully-qualified identifiers without explicitly importing any modules. -[1]: https://downloads.haskell.org/ghc/9.8.2/docs/users_guide/ghci.html#qualified-names+[1]: https://downloads.haskell.org/ghc/9.10.1/docs/users_guide/ghci.html#qualified-names  This is similar to [qualified-imports-plugin][2], but it works differently-behind the scenes and supports newer versions of GHC.+behind the scenes and supports newer versions of GHC. It is also similar to the+[implicit import proposal][3], but more limited in scope.  [2]: https://github.com/utdemir/qualified-imports-plugin+[3]: https://github.com/ghc-proposals/ghc-proposals/pull/500  ## Basic Usage @@ -162,11 +163,11 @@ error like this:  ```-B.hs:1:1: error: [GHC-58427]+B.hs:3:10: error: [GHC-58427]     attempting to use module ‘example-0:A’ (A.hs) which is not loaded   |-1 | module B where-  | ^+3 | bThing = A.aThing+  |          ^^^^^^^^ ```  The only workarounds are to either import the module manually or move the
imp.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: imp-version: 1.0.2.0+version: 1.0.2.1 synopsis: A GHC plugin for automatically importing modules. description: Imp is a GHC plugin for automatically importing modules. category: Plugin@@ -20,7 +20,7 @@   manual: True  common library-  build-depends: base ^>=4.17.0.0 || ^>=4.18.0.0 || ^>=4.19.0.0+  build-depends: base ^>=4.18.0.0 || ^>=4.19.0.0 || ^>=4.20.0.0   default-language: Haskell2010   ghc-options:     -Weverything@@ -46,13 +46,13 @@   import: library   autogen-modules: Paths_imp   build-depends:-    Cabal-syntax ^>=3.6.0.0 || ^>=3.8.1.0 || ^>=3.10.1.0,-    containers ^>=0.6.7,+    Cabal-syntax ^>=3.10.1.0 || ^>=3.12.0.0,+    containers ^>=0.6.7 || ^>=0.7,     exceptions ^>=0.10.5,-    ghc ^>=9.4.1 || ^>=9.6.1 || ^>=9.8.1,-    transformers ^>=0.5.6 || ^>=0.6.1,+    ghc ^>=9.6.1 || ^>=9.8.1 || ^>=9.10.1,+    transformers ^>=0.6.1, -  -- cabal-gild: discover source/ghc-9.4 source/ghc-9.6 source/library+  -- cabal-gild: discover source/library   exposed-modules:     Imp     Imp.Exception.InvalidAlias@@ -73,7 +73,6 @@     Imp.Extra.ParsedResult     Imp.Extra.ReadP     Imp.Extra.SrcSpanAnnN-    Imp.Ghc     Imp.Type.Alias     Imp.Type.Config     Imp.Type.Context@@ -86,11 +85,6 @@   hs-source-dirs: source/library   other-modules: Paths_imp -  if impl(ghc >= 9.6)-    hs-source-dirs: source/ghc-9.6-  else-    hs-source-dirs: source/ghc-9.4-   if flag(pedantic)     ghc-options: -Werror @@ -99,7 +93,7 @@   build-depends:     exceptions,     ghc,-    hspec ^>=2.11.7,+    hspec ^>=2.11.8,    hs-source-dirs: source/test-suite   main-is: Main.hs
− source/ghc-9.4/Imp/Ghc.hs
@@ -1,24 +0,0 @@-module Imp.Ghc where--import qualified GHC.Hs as Hs-import qualified GHC.Plugins as Plugin-import qualified GHC.Types.SourceText as SourceText--type HsModulePs = Hs.HsModule--newImportDecl ::-  Plugin.ModuleName ->-  Hs.ImportDecl Hs.GhcPs-newImportDecl moduleName =-  Hs.ImportDecl-    { Hs.ideclExt = Hs.noAnn,-      Hs.ideclSourceSrc = SourceText.NoSourceText,-      Hs.ideclImplicit = True,-      Hs.ideclName = Hs.noLocA moduleName,-      Hs.ideclPkgQual = Plugin.NoRawPkgQual,-      Hs.ideclSource = Plugin.NotBoot,-      Hs.ideclSafe = False,-      Hs.ideclQualified = Hs.QualifiedPre,-      Hs.ideclAs = Nothing,-      Hs.ideclHiding = Nothing-    }
− source/ghc-9.6/Imp/Ghc.hs
@@ -1,27 +0,0 @@-module Imp.Ghc where--import qualified GHC.Hs as Hs-import qualified GHC.Plugins as Plugin-import qualified GHC.Types.SourceText as SourceText--type HsModulePs = Hs.HsModule Hs.GhcPs--newImportDecl ::-  Plugin.ModuleName ->-  Hs.ImportDecl Hs.GhcPs-newImportDecl moduleName =-  Hs.ImportDecl-    { Hs.ideclExt =-        Hs.XImportDeclPass-          { Hs.ideclAnn = Hs.noAnn,-            Hs.ideclSourceText = SourceText.NoSourceText,-            Hs.ideclImplicit = True-          },-      Hs.ideclName = Hs.noLocA moduleName,-      Hs.ideclPkgQual = Plugin.NoRawPkgQual,-      Hs.ideclSource = Hs.NotBoot,-      Hs.ideclSafe = False,-      Hs.ideclQualified = Hs.QualifiedPre,-      Hs.ideclAs = Nothing,-      Hs.ideclImportList = Nothing-    }
source/library/Imp.hs view
@@ -13,6 +13,7 @@ import qualified GHC.Hs as Hs import qualified GHC.Plugins as Plugin import qualified GHC.Types.PkgQual as PkgQual+import qualified GHC.Types.SourceText as SourceText import qualified Imp.Exception.ShowHelp as ShowHelp import qualified Imp.Exception.ShowVersion as ShowVersion import qualified Imp.Extra.Exception as Exception@@ -22,7 +23,6 @@ import qualified Imp.Extra.Located as Located import qualified Imp.Extra.ParsedResult as ParsedResult import qualified Imp.Extra.SrcSpanAnnN as SrcSpanAnnN-import qualified Imp.Ghc as Ghc import qualified Imp.Type.Config as Config import qualified Imp.Type.Context as Context import qualified Imp.Type.Flag as Flag@@ -68,8 +68,8 @@   (Exception.MonadThrow m) =>   [String] ->   Plugin.ModuleName ->-  Plugin.Located Ghc.HsModulePs ->-  m (Plugin.Located Ghc.HsModulePs)+  Plugin.Located (Hs.HsModule Hs.GhcPs) ->+  m (Plugin.Located (Hs.HsModule Hs.GhcPs)) imp arguments this lHsModule = do   flags <- Flag.fromArguments arguments   config <- Config.fromFlags flags@@ -80,11 +80,13 @@         Set.map Target.toModuleName           . Map.keysSet           $ Map.filter Source.isImplicit aliases-      imports =-        Set.fromList-          . fmap (ImportDecl.toModuleName . Plugin.unLoc)-          . Hs.hsmodImports-          $ Plugin.unLoc lHsModule+      -- I would prefer to use `hsmodImports`, but I get a spurious warning+      -- with GHC 9.10.1.+      -- <https://github.com/tfausak/imp/pull/24#issuecomment-2116480980>+      imports = case Plugin.unLoc lHsModule of+        Hs.HsModule _ _ _ lImportDecls _ ->+          Set.fromList $+            fmap (ImportDecl.toModuleName . Plugin.unLoc) lImportDecls       (newLHsModule, moduleNames) =         StateT.runState           (Located.overValue (HsModule.overDecls $ overData $ updateQualifiedIdentifiers this implicits imports) lHsModule)@@ -131,7 +133,7 @@ updateImports this aliases packages want imports =   let have = Set.insert this . Set.fromList $ fmap (ImportDecl.toModuleName . Plugin.unLoc) imports       need = Map.toList $ Map.withoutKeys want have-   in imports <> Maybe.mapMaybe (\(m, l) -> Plugin.L (Hs.na2la l) <$> createImport aliases packages m) need+   in imports <> Maybe.mapMaybe (\(m, l) -> Plugin.L (Hs.l2l l) <$> createImport aliases packages m) need  createImport ::   Map.Map Target.Target Source.Source ->@@ -146,12 +148,23 @@         Source.Implicit -> Nothing         Source.Explicit m -> Just m   Just-    (Ghc.newImportDecl source)-      { Hs.ideclAs =+    Hs.ImportDecl+      { Hs.ideclExt =+          Hs.XImportDeclPass+            { Hs.ideclAnn = Hs.noAnn,+              Hs.ideclSourceText = SourceText.NoSourceText,+              Hs.ideclImplicit = True+            },+        Hs.ideclName = Hs.noLocA source,+        Hs.ideclPkgQual =+          maybe PkgQual.NoRawPkgQual (PkgQual.RawPkgQual . PackageName.toStringLiteral) $+            Map.lookup (Target.fromModuleName target) packages,+        Hs.ideclSource = Hs.NotBoot,+        Hs.ideclSafe = False,+        Hs.ideclQualified = Hs.QualifiedPre,+        Hs.ideclAs =           if source == target             then Nothing             else Just $ Hs.noLocA target,-        Hs.ideclPkgQual =-          maybe PkgQual.NoRawPkgQual (PkgQual.RawPkgQual . PackageName.toStringLiteral) $-            Map.lookup (Target.fromModuleName target) packages+        Hs.ideclImportList = Nothing       }
source/library/Imp/Extra/HsModule.hs view
@@ -1,17 +1,16 @@ module Imp.Extra.HsModule where  import qualified GHC.Hs as Hs-import qualified Imp.Ghc as Ghc  overDecls ::   (Functor f) =>   ([Hs.LHsDecl Hs.GhcPs] -> f [Hs.LHsDecl Hs.GhcPs]) ->-  Ghc.HsModulePs ->-  f Ghc.HsModulePs+  Hs.HsModule Hs.GhcPs ->+  f (Hs.HsModule Hs.GhcPs) overDecls f x = (\y -> x {Hs.hsmodDecls = y}) <$> f (Hs.hsmodDecls x)  overImports ::   ([Hs.LImportDecl Hs.GhcPs] -> [Hs.LImportDecl Hs.GhcPs]) ->-  Ghc.HsModulePs ->-  Ghc.HsModulePs+  Hs.HsModule Hs.GhcPs ->+  Hs.HsModule Hs.GhcPs overImports f x = x {Hs.hsmodImports = f $ Hs.hsmodImports x}
source/library/Imp/Extra/HsParsedModule.hs view
@@ -2,11 +2,10 @@  import qualified GHC.Hs as Hs import qualified GHC.Plugins as Plugin-import qualified Imp.Ghc as Ghc  overModule ::   (Functor f) =>-  (Plugin.Located Ghc.HsModulePs -> f (Plugin.Located Ghc.HsModulePs)) ->+  (Plugin.Located (Hs.HsModule Hs.GhcPs) -> f (Plugin.Located (Hs.HsModule Hs.GhcPs))) ->   Plugin.HsParsedModule ->   f Plugin.HsParsedModule overModule f x = (\y -> x {Hs.hpm_module = y}) <$> f (Hs.hpm_module x)
source/test-suite/Main.hs view
@@ -3,13 +3,13 @@ import qualified Control.Monad.Catch as Exception import qualified GHC.Data.EnumSet as EnumSet import qualified GHC.Data.StringBuffer as StringBuffer+import qualified GHC.Hs as Hs import qualified GHC.Parser as Parser import qualified GHC.Parser.Lexer as Lexer import qualified GHC.Plugins as Plugin import qualified GHC.Stack as Stack import qualified GHC.Utils.Error as Error import qualified Imp-import qualified Imp.Ghc as Ghc import qualified Test.Hspec as Hspec  main :: IO ()@@ -123,7 +123,7 @@   let actual = Plugin.showPprUnsafe after   actual `Hspec.shouldBe` expected -parseModule :: (Exception.MonadThrow m) => String -> m (Plugin.Located Ghc.HsModulePs)+parseModule :: (Exception.MonadThrow m) => String -> m (Plugin.Located (Hs.HsModule Hs.GhcPs)) parseModule input = do   let parserOpts = Lexer.mkParserOpts EnumSet.empty emptyDiagOpts [] False False False False       stringBuffer = StringBuffer.stringToStringBuffer input