packages feed

haskell-tools-ast 1.0.1.1 → 1.1.0.0

raw patch · 13 files changed

+117/−47 lines, 13 filesdep ~basedep ~ghcdep ~template-haskell

Dependency ranges changed: base, ghc, template-haskell

Files

Language/Haskell/Tools/AST/Ann.hs view
@@ -1,4 +1,15 @@-{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, DeriveDataTypeable, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TypeApplications, TypeFamilies, UndecidableInstances #-}
+{-# LANGUAGE AllowAmbiguousTypes #-}
+{-# LANGUAGE ConstraintKinds #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE StandaloneDeriving #-}
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE TypeApplications #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE UndecidableInstances #-}
 
 -- | Parts of AST representation for keeping extra data
 module Language.Haskell.Tools.AST.Ann where
@@ -11,6 +22,7 @@ import Language.Haskell.Tools.AST.Utils.GHCInstances ()
 import qualified Name as GHC
 import SrcLoc as GHC
+import HsExtension
 
 import {-# SOURCE #-} Language.Haskell.Tools.AST.Representation.Exprs as AST
 import {-# SOURCE #-} Language.Haskell.Tools.AST.Representation.Modules as AST
@@ -83,15 +95,15 @@ type instance SemanticInfo' (Dom n) SemaInfoLitCls = PreLiteralInfo
 type instance SemanticInfo' (Dom n) SemaInfoExprCls = ScopeInfo
 type instance SemanticInfo' (Dom n) SemaInfoImportCls = ImportInfo n
-type instance SemanticInfo' (Dom n) SemaInfoModuleCls = ModuleInfo GHC.Name
+type instance SemanticInfo' (Dom n) SemaInfoModuleCls = ModuleInfo GhcRn
 type instance SemanticInfo' (Dom n) SemaInfoWildcardCls = ImplicitFieldInfo
 type instance SemanticInfo' (Dom n) SemaInfoDefaultCls = NoSemanticInfo
 
 type instance SemanticInfo' IdDom SemaInfoNameCls = CNameInfo
 type instance SemanticInfo' IdDom SemaInfoExprCls = ScopeInfo
 type instance SemanticInfo' IdDom SemaInfoLitCls = LiteralInfo
-type instance SemanticInfo' IdDom SemaInfoImportCls = ImportInfo GHC.Id
-type instance SemanticInfo' IdDom SemaInfoModuleCls = ModuleInfo GHC.Id
+type instance SemanticInfo' IdDom SemaInfoImportCls = ImportInfo GhcTc
+type instance SemanticInfo' IdDom SemaInfoModuleCls = ModuleInfo GhcTc
 type instance SemanticInfo' IdDom SemaInfoWildcardCls = ImplicitFieldInfo
 type instance SemanticInfo' IdDom SemaInfoDefaultCls = NoSemanticInfo
 
Language/Haskell/Tools/AST/Helpers.hs view
@@ -1,4 +1,8 @@-{-# LANGUAGE FlexibleContexts, MonoLocalBinds, PatternSynonyms, RankNTypes, ScopedTypeVariables, UndecidableInstances #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE MonoLocalBinds #-}
+{-# LANGUAGE PatternSynonyms #-}
+{-# LANGUAGE RankNTypes #-}
+{-# LANGUAGE ScopedTypeVariables #-}
 
 
 -- | Helper functions for using the AST.
Language/Haskell/Tools/AST/Instances/ClassyPlate.hs view
@@ -1,16 +1,24 @@ -- don't show warnings, Template Haskell generated code contains unused variables
-{-# LANGUAGE TypeApplications, TemplateHaskell, DataKinds, FlexibleInstances, MultiParamTypeClasses, FlexibleContexts, UndecidableInstances, TypeFamilies, AllowAmbiguousTypes, ScopedTypeVariables #-}
+{-# LANGUAGE TypeApplications #-}
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE UndecidableInstances #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE AllowAmbiguousTypes #-}
+{-# LANGUAGE ScopedTypeVariables #-}
 {-# OPTIONS_GHC -fno-warn-unused-matches #-}
 
 -- | Generating instances for traversing the semantic information of the Haskell Representation
 module Language.Haskell.Tools.AST.Instances.ClassyPlate where
 
-import Data.Generics.ClassyPlate
 import Data.Generics.ClassyPlate.TH
 
 import Language.Haskell.Tools.AST.Ann
-import Language.Haskell.Tools.AST.Instances.Data
-import Language.Haskell.Tools.AST.Instances.Generic
+import Language.Haskell.Tools.AST.Instances.Data ()
+import Language.Haskell.Tools.AST.Instances.Generic ()
 
 import Language.Haskell.Tools.AST.Representation.Binds
 import Language.Haskell.Tools.AST.Representation.Decls
Language/Haskell/Tools/AST/Instances/Data.hs view
@@ -1,5 +1,9 @@ -- | Data instances for Haskell AST (used for generics)
-{-# LANGUAGE DeriveDataTypeable, FlexibleContexts, GADTs, StandaloneDeriving, UndecidableInstances #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE StandaloneDeriving #-}
+{-# LANGUAGE UndecidableInstances #-}
 
 module Language.Haskell.Tools.AST.Instances.Data () where
 
Language/Haskell/Tools/AST/Instances/Generic.hs view
@@ -1,5 +1,9 @@ -- | Generic instance for Haskell AST representation
-{-# LANGUAGE DeriveGeneric, FlexibleContexts, GADTs, StandaloneDeriving, UndecidableInstances #-}
+{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE StandaloneDeriving #-}
+{-# LANGUAGE UndecidableInstances #-}
 
 module Language.Haskell.Tools.AST.Instances.Generic () where
 
Language/Haskell/Tools/AST/MakeASTReferences.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE LambdaCase, TemplateHaskellQuotes #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE TemplateHaskellQuotes #-} 
 -- | Contains a transformation to alter the references generated by the template haskell 
 -- function @makeReferences@.
Language/Haskell/Tools/AST/References.hs view
@@ -1,5 +1,6 @@ -- don't show warnings, Template Haskell generated code contains unused variables
-{-# LANGUAGE FlexibleContexts, TemplateHaskell #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE TemplateHaskell #-}
 {-# OPTIONS_GHC -fno-warn-unused-matches #-}
 
 -- | Generated references for AST elements.
Language/Haskell/Tools/AST/SemaInfoClasses.hs view
@@ -1,6 +1,11 @@-{-# LANGUAGE ConstraintKinds, FlexibleContexts, FlexibleInstances, GADTs, UndecidableInstances #-}+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE UndecidableInstances #-} 
-module Language.Haskell.Tools.AST.SemaInfoClasses (module Language.Haskell.Tools.AST.SemaInfoClasses, getInstances, UsageSpec(..)) where
+module Language.Haskell.Tools.AST.SemaInfoClasses
+  (module Language.Haskell.Tools.AST.SemaInfoClasses, getInstances, UsageSpec(..)) where
 
 import GHC
 import Id as GHC (Id, idName)
@@ -26,7 +31,7 @@ class HasNameInfo' si where
   semanticsName :: si -> Maybe GHC.Name
 
-instance HasNameInfo' (NameInfo GHC.Name) where
+instance HasNameInfo' (NameInfo GhcRn) where
   semanticsName = (^? nameInfo)
 
 instance HasNameInfo' CNameInfo where
@@ -141,14 +146,14 @@   semanticsImplicitImports :: si -> [GHC.Name]
   semanticsPrelTransMods :: si -> [Module]
 
-instance HasModuleInfo' (AST.ModuleInfo GHC.Name) where
+instance HasModuleInfo' (AST.ModuleInfo GhcRn) where
   semanticsModule = (^. defModuleName)
   semanticsDynFlags = (^. defDynFlags)
   isBootModule = (^. defIsBootModule)
   semanticsImplicitImports = (^? implicitNames&traversal&pName)
   semanticsPrelTransMods = (^. prelTransMods)
 
-instance HasModuleInfo' (AST.ModuleInfo GHC.Id) where
+instance HasModuleInfo' (AST.ModuleInfo GhcTc) where
   semanticsModule = (^. defModuleName)
   semanticsDynFlags = (^. defDynFlags)
   isBootModule = (^. defIsBootModule)
@@ -172,13 +177,13 @@   semanticsImported :: si -> [GHC.Name]
   semanticsTransMods :: si -> [Module]
 
-instance HasImportInfo' (AST.ImportInfo GHC.Name) where
+instance HasImportInfo' (AST.ImportInfo GhcRn) where
   semanticsImportedModule = (^. importedModule)
   semanticsAvailable = (^. availableNames)
   semanticsImported = (^? importedNames&traversal&pName)
   semanticsTransMods = (^. importTransMods)
 
-instance HasImportInfo' (AST.ImportInfo GHC.Id) where
+instance HasImportInfo' (AST.ImportInfo GhcTc) where
   semanticsImportedModule = (^. importedModule)
   semanticsAvailable = map idName . (^. availableNames)
   semanticsImported = map idName . (^? importedNames&traversal&pName)
Language/Haskell/Tools/AST/SemaInfoTypes.hs view
@@ -1,4 +1,11 @@-{-# LANGUAGE BangPatterns, DeriveDataTypeable, FlexibleContexts, StandaloneDeriving, TemplateHaskell, TypeSynonymInstances, UndecidableInstances, DeriveTraversable #-}
+{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE StandaloneDeriving #-}
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE TypeSynonymInstances #-}
+{-# LANGUAGE UndecidableInstances #-}
+{-# LANGUAGE DeriveTraversable #-}
 
 module Language.Haskell.Tools.AST.SemaInfoTypes
   ( -- types
@@ -13,7 +20,7 @@   , mkNoSemanticInfo, mkScopeInfo, mkNameInfo, mkAmbiguousNameInfo, mkImplicitNameInfo, mkCNameInfo
   , mkModuleInfo, mkImportInfo, mkImplicitFieldInfo
   -- utils
-  , PName(..), pName, pNameParent
+  , PName(..), pName, pNameParent, trfPNames, trfPNamesM, trfImportInfo, trfImportInfoM, trfModuleInfoM
   , getInstances
   ) where
 
@@ -31,15 +38,12 @@ import Type as GHC
 import HscTypes as GHC
 import CoAxiom as GHC
+import HsExtension (IdP)
 
-import Data.Maybe
 import Data.Data as Data
 import Control.Reference
-import Control.Monad
 import Control.Monad.IO.Class
 
-import Outputable
-
 type Scope = [[(Name, Maybe [UsageSpec], Maybe Name)]]
 
 data UsageSpec = UsageSpec { usageQualified :: Bool
@@ -78,7 +82,7 @@ -- | Info corresponding to a name
 data NameInfo n = NameInfo { _nameScopedLocals :: Scope
                            , _nameIsDefined :: Bool
-                           , _nameInfo :: n
+                           , _nameInfo :: IdP n
                            }
                 | AmbiguousNameInfo { _nameScopedLocals :: Scope
                                     , _nameIsDefined :: Bool
@@ -91,10 +95,13 @@                                    , _nameLocation :: SrcSpan
                                    }
 
-  deriving (Data, Functor, Foldable, Traversable)
+deriving instance (Data n, Typeable n, Data (IdP n)) => Data (NameInfo n)
+-- deriving instance Functor NameInfo
+-- deriving instance Foldable NameInfo
+-- deriving instance Traversable NameInfo
 
 -- | Creates semantic information for an unambiguous name
-mkNameInfo :: Scope -> Bool -> n -> NameInfo n
+mkNameInfo :: Scope -> Bool -> IdP n -> NameInfo n
 mkNameInfo = NameInfo
 
 -- | Creates semantic information for a name that is ambiguous because the lack of type info
@@ -118,11 +125,19 @@ mkCNameInfo = CNameInfo
 
 data PName n
-  = PName { _pName :: n
-          , _pNameParent :: Maybe n
+  = PName { _pName :: IdP n
+          , _pNameParent :: Maybe (IdP n)
           }
-  deriving (Data, Functor, Foldable, Traversable)
 
+deriving instance (Data n, Typeable n, Data (IdP n)) => Data (PName n)
+
+trfPNames :: (IdP n -> IdP n') -> PName n -> PName n'
+trfPNames f (PName name parent) = PName (f name) (fmap f parent)
+
+trfPNamesM :: Monad m => (IdP n -> m (IdP n')) -> PName n -> m (PName n')
+trfPNamesM f (PName name (Just parent)) = PName <$> f name <*> (Just <$> f parent)
+trfPNamesM f (PName name Nothing) = PName <$> f name <*> return Nothing
+
 -- | Info for the module element
 data ModuleInfo n = ModuleInfo { _defModuleName :: GHC.Module
                                , _defDynFlags :: DynFlags -- ^ The compilation flags that are set up when the module was compiled
@@ -130,8 +145,13 @@                                , _implicitNames :: [PName n] -- ^ implicitly imported names
                                , _prelTransMods :: [GHC.Module] -- ^ Modules imported transitively.
                                }
-  deriving (Data, Functor, Foldable, Traversable)
 
+trfModuleInfoM :: Monad m => (IdP n -> m (IdP n')) -> ModuleInfo n -> m (ModuleInfo n')
+trfModuleInfoM f (ModuleInfo mn df bm impl tm)
+  = ModuleInfo mn df bm <$> mapM (trfPNamesM f) impl <*> return tm
+
+deriving instance (Data n, Typeable n, Data (IdP n)) => Data (ModuleInfo n)
+
 instance Data DynFlags where
   gunfold _ _ _ = error "Cannot construct dyn flags"
   toConstr _ = dynFlagsCon
@@ -149,36 +169,44 @@ 
 -- | Info corresponding to an import declaration
 data ImportInfo n = ImportInfo { _importedModule :: GHC.Module -- ^ The name and package of the imported module
-                               , _availableNames :: [n] -- ^ Names available from the imported module
+                               , _availableNames :: [IdP n] -- ^ Names available from the imported module
                                , _importedNames :: [PName n] -- ^ Names actually imported from the module.
                                , _importTransMods :: [GHC.Module] -- ^ Modules imported transitively.
                                }
-  deriving (Data, Functor, Foldable, Traversable)
 
+trfImportInfo :: (IdP n -> IdP n') -> ImportInfo n -> ImportInfo n'
+trfImportInfo f (ImportInfo mod avail imp trm)
+  = ImportInfo mod (map f avail) (map (trfPNames f) imp) trm
+
+trfImportInfoM :: Monad m => (IdP n -> m (IdP n')) -> ImportInfo n -> m (ImportInfo n')
+trfImportInfoM f (ImportInfo mod avail imp trm)
+  = ImportInfo mod <$> (mapM f avail) <*> (mapM (trfPNamesM f) imp) <*> return trm
+
+deriving instance (Data n, Typeable n, Data (IdP n)) => Data (ImportInfo n)
+
 deriving instance Data FamInst
 deriving instance Data FamFlavor
 
 -- | Creates semantic information for an import declaration
 -- Strict in the list of the used and imported declarations, orphan and family instances.
-mkImportInfo :: GHC.Module -> [n] -> [PName n] -> [GHC.Module] -> ImportInfo n
+mkImportInfo :: GHC.Module -> [IdP n] -> [PName n] -> [GHC.Module] -> ImportInfo n
 -- the calculate of these fields involves a big parts of the GHC state and it causes a space leak
 -- if not evaluated strictly
 mkImportInfo mod !names !imported deps = ImportInfo mod names imported deps
 
 -- | Gets the class and family instances from a module.
-getInstances :: [Module] -> GHC.Ghc ([ClsInst], [FamInst])
+getInstances :: GHC.GhcMonad m => [GHC.Module] -> m ([ClsInst], [FamInst])
 getInstances mods = do
   env <- GHC.getSession
   eps <- liftIO $ hscEPS env
-  let homePkgs = catMaybes $ map (lookupHpt (hsc_HPT env) . GHC.moduleName) mods
-      (hptInsts, hptFamInsts) = hptInstances env (`elem` map GHC.moduleName mods)
+  let (hptInsts, hptFamInsts) = hptInstances env (`elem` map GHC.moduleName mods)
       isFromMods inst = maybe False (`elem` mods) $ nameModule_maybe $ Var.varName $ is_dfun inst
       famIsFromMods inst = maybe False (`elem` mods) $ nameModule_maybe $ co_ax_name $ fi_axiom inst
       epsInsts = filter isFromMods $ instEnvElts $ eps_inst_env eps
       epsFamInsts = filter famIsFromMods $ famInstEnvElts $ eps_fam_inst_env eps
   return (hptInsts ++ epsInsts, hptFamInsts ++ epsFamInsts)
 
--- | Info corresponding to an record-wildcard
+-- | Info corresponding to a record-wildcard
 data ImplicitFieldInfo = ImplicitFieldInfo { _implicitFieldBindings :: [(Name, Name)] -- ^ The implicitly bounded names
                                            }
   deriving Data
Language/Haskell/Tools/AST/TH/SemanticTraversal.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE LambdaCase, TemplateHaskellQuotes #-}
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE TemplateHaskellQuotes #-}
 
 -- | Generating instances for traversal on semantic information
 module Language.Haskell.Tools.AST.TH.SemanticTraversal where
Language/Haskell/Tools/AST/TH/SourceInfoTraversal.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE LambdaCase, TemplateHaskellQuotes #-}
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE TemplateHaskellQuotes #-}
 
 -- | Generating instances for traversal on semantic information
 module Language.Haskell.Tools.AST.TH.SourceInfoTraversal where
Language/Haskell/Tools/AST/Utils/GHCInstances.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE StandaloneDeriving #-}
 
 
 module Language.Haskell.Tools.AST.Utils.GHCInstances where
haskell-tools-ast.cabal view
@@ -1,5 +1,5 @@ name:                haskell-tools-ast
-version:             1.0.1.1
+version:             1.1.0.0
 synopsis:            Haskell AST for efficient tooling
 description:         A representation of a Haskell Syntax tree that contain source-related and semantic annotations. These annotations help developer tools to work with the defined program. The source information enables refactoring and program transformation tools to change the source code without losing the original format (layout, comments) of the source. Semantic information helps analyzing the program. The representation is different from the GHC's syntax tree. It contains information from all representations in GHC (different version of syntax trees, lexical and module-level information). The module is split up to put the representation of different language elements into different modules. Additionally, it contains the representation of semantic and source annotations, helper functions and generated instances for the representation of language elements. Because langauge elements may refer each other (there can be a pattern inside an expression in case of a pattern match and an expression inside a pattern if view patterns are enabled), we use hs-boot files to break up dependency cycles.
 
@@ -45,12 +45,12 @@                      , Language.Haskell.Tools.AST.TH.SemanticTraversal
                      , Language.Haskell.Tools.AST.TH.SourceInfoTraversal
 
-  build-depends:       base             >= 4.10  && < 4.11
-                     , ghc              >= 8.2  && < 8.3
+  build-depends:       base             >= 4.11  && < 4.12
+                     , ghc              >= 8.4  && < 8.5
                      , references       >= 0.3  && < 0.4
                      , uniplate         >= 1.6  && < 1.7
                      , mtl              >= 2.2  && < 2.3
-                     , template-haskell >= 2.12 && < 2.13
+                     , template-haskell >= 2.13 && < 2.14
                      , classyplate      >= 0.3 && < 0.4
                      , pretty      >= 1.1 && < 1.2
   default-language:    Haskell2010