From 37fcc4826bfe919cb0008c2221753e9d9f6b5d31 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Tue, 6 Mar 2018 14:17:32 -0500 Subject: [PATCH 1/3] Rename the Linker type/module to ModuleTable. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During my recent pairing with @robrix, we agreed that the name of Linker was inaccurate—it doesn't link anything, it just keeps track of past modules. This renames it and its module. --- semantic.cabal | 2 +- src/Analysis/Abstract/Dead.hs | 6 +++--- src/Analysis/Abstract/Evaluating.hs | 8 ++++---- src/Control/Abstract/Evaluator.hs | 14 +++++++------- src/Data/Abstract/Evaluatable.hs | 2 +- src/Data/Abstract/Linker.hs | 16 ---------------- src/Data/Abstract/ModuleTable.hs | 16 ++++++++++++++++ 7 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 src/Data/Abstract/Linker.hs create mode 100644 src/Data/Abstract/ModuleTable.hs diff --git a/semantic.cabal b/semantic.cabal index 4f63a5871..0f6682c2d 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -48,9 +48,9 @@ library , Data.Abstract.Configuration , Data.Abstract.Environment , Data.Abstract.Evaluatable - , Data.Abstract.Linker , Data.Abstract.FreeVariables , Data.Abstract.Live + , Data.Abstract.ModuleTable , Data.Abstract.Store , Data.Abstract.Type , Data.Abstract.Value diff --git a/src/Analysis/Abstract/Dead.hs b/src/Analysis/Abstract/Dead.hs index c5e8c387f..8efd8c7cc 100644 --- a/src/Analysis/Abstract/Dead.hs +++ b/src/Analysis/Abstract/Dead.hs @@ -9,7 +9,7 @@ import Control.Monad.Effect.Reader import Control.Monad.Effect.State import Data.Abstract.Address import Data.Abstract.Evaluatable -import Data.Abstract.Linker +import Data.Abstract.ModuleTable import Data.Abstract.Store import Data.Abstract.Value import Data.Set (delete) @@ -22,8 +22,8 @@ type DeadCodeEffects t v , State (Store (LocationFor v) v) -- The heap , State (EnvironmentFor v) -- Global (imperative) environment , Reader (EnvironmentFor v) -- Local environment (e.g. binding over a closure) - , Reader (Linker t) -- Cache of unevaluated modules - , State (Linker v) -- Cache of evaluated modules + , Reader (ModuleTable t) -- Cache of unevaluated modules + , State (ModuleTable v) -- Cache of evaluated modules ] diff --git a/src/Analysis/Abstract/Evaluating.hs b/src/Analysis/Abstract/Evaluating.hs index dbb043618..6e61efa34 100644 --- a/src/Analysis/Abstract/Evaluating.hs +++ b/src/Analysis/Abstract/Evaluating.hs @@ -9,7 +9,7 @@ import Control.Monad.Effect.Reader import Control.Monad.Effect.State import Data.Abstract.Address import Data.Abstract.Evaluatable -import Data.Abstract.Linker +import Data.Abstract.ModuleTable import Data.Abstract.Store import Data.Abstract.Value import Data.Blob @@ -23,8 +23,8 @@ type EvaluationEffects t v , State (Store (LocationFor v) v) -- The heap , State (EnvironmentFor v) -- Global (imperative) environment , Reader (EnvironmentFor v) -- Local environment (e.g. binding over a closure) - , Reader (Linker t) -- Cache of unevaluated modules - , State (Linker v) -- Cache of evaluated modules + , Reader (ModuleTable t) -- Cache of unevaluated modules + , State (ModuleTable v) -- Cache of evaluated modules ] @@ -60,7 +60,7 @@ evaluates pairs (_, t) = run @(EvaluationEffects term v) (runEvaluator (runEvalu -- | Run an action with the passed ('Blob', @term@) pairs available for imports. withModules :: (MonadAnalysis term value m, MonadEvaluator term value m) => [(Blob, term)] -> m a -> m a withModules pairs = localModuleTable (const moduleTable) - where moduleTable = Linker (Map.fromList (map (first (dropExtensions . blobPath)) pairs)) + where moduleTable = ModuleTable (Map.fromList (map (first (dropExtensions . blobPath)) pairs)) -- | An analysis performing concrete evaluation of @term@s to @value@s. newtype Evaluation term value a = Evaluation { runEvaluation :: Evaluator (EvaluationEffects term value) term value a } diff --git a/src/Control/Abstract/Evaluator.hs b/src/Control/Abstract/Evaluator.hs index 5ed3ae46f..6d60500fe 100644 --- a/src/Control/Abstract/Evaluator.hs +++ b/src/Control/Abstract/Evaluator.hs @@ -8,7 +8,7 @@ import Control.Monad.Effect.Fresh import Control.Monad.Effect.NonDetEff import Control.Monad.Effect.Reader import Control.Monad.Effect.State -import Data.Abstract.Linker +import Data.Abstract.ModuleTable import Data.Abstract.Value import Prelude hiding (fail) @@ -35,21 +35,21 @@ class MonadFail m => MonadEvaluator term value m | m -> term, m -> value where modifyStore :: (StoreFor value -> StoreFor value) -> m () -- | Retrieve the table of evaluated modules. - getModuleTable :: m (Linker value) + getModuleTable :: m (ModuleTable value) -- | Update the table of evaluated modules. - modifyModuleTable :: (Linker value -> Linker value) -> m () + modifyModuleTable :: (ModuleTable value -> ModuleTable value) -> m () -- | Retrieve the table of unevaluated modules. - askModuleTable :: m (Linker term) + askModuleTable :: m (ModuleTable term) -- | Run an action with a locally-modified table of unevaluated modules. - localModuleTable :: (Linker term -> Linker term) -> m a -> m a + localModuleTable :: (ModuleTable term -> ModuleTable term) -> m a -> m a instance Members '[ Fail , Reader (EnvironmentFor value) , State (EnvironmentFor value) , State (StoreFor value) - , Reader (Linker term) - , State (Linker value) + , Reader (ModuleTable term) + , State (ModuleTable value) ] effects => MonadEvaluator term value (Evaluator effects term value) where getGlobalEnv = Evaluator get diff --git a/src/Data/Abstract/Evaluatable.hs b/src/Data/Abstract/Evaluatable.hs index 8ab2a6103..a5a20dcaa 100644 --- a/src/Data/Abstract/Evaluatable.hs +++ b/src/Data/Abstract/Evaluatable.hs @@ -18,7 +18,7 @@ import Control.Monad.Effect.Fail import Data.Abstract.Address import Data.Abstract.Environment import Data.Abstract.FreeVariables as FreeVariables -import Data.Abstract.Linker +import Data.Abstract.ModuleTable import Data.Abstract.Value import Data.Algebra import qualified Data.ByteString.Char8 as BC diff --git a/src/Data/Abstract/Linker.hs b/src/Data/Abstract/Linker.hs deleted file mode 100644 index 86de72b37..000000000 --- a/src/Data/Abstract/Linker.hs +++ /dev/null @@ -1,16 +0,0 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -module Data.Abstract.Linker where - -import Data.Semigroup -import GHC.Generics -import qualified Data.Map as Map - - -newtype Linker a = Linker { unLinker :: Map.Map FilePath a } - deriving (Eq, Foldable, Functor, Generic1, Monoid, Ord, Semigroup, Show, Traversable) - -linkerLookup :: FilePath -> Linker a -> Maybe a -linkerLookup k = Map.lookup k . unLinker - -linkerInsert :: FilePath -> a -> Linker a -> Linker a -linkerInsert k v Linker{..} = Linker (Map.insert k v unLinker) diff --git a/src/Data/Abstract/ModuleTable.hs b/src/Data/Abstract/ModuleTable.hs new file mode 100644 index 000000000..6f53903bb --- /dev/null +++ b/src/Data/Abstract/ModuleTable.hs @@ -0,0 +1,16 @@ +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +module Data.Abstract.ModuleTable where + +import Data.Semigroup +import GHC.Generics +import qualified Data.Map as Map + + +newtype ModuleTable a = ModuleTable { unModuleTable :: Map.Map FilePath a } + deriving (Eq, Foldable, Functor, Generic1, Monoid, Ord, Semigroup, Show, Traversable) + +linkerLookup :: FilePath -> ModuleTable a -> Maybe a +linkerLookup k = Map.lookup k . unModuleTable + +linkerInsert :: FilePath -> a -> ModuleTable a -> ModuleTable a +linkerInsert k v ModuleTable{..} = ModuleTable (Map.insert k v unModuleTable) From f96136918a8c7ccc76fb78ab99a922e76ef6ac25 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Tue, 6 Mar 2018 17:24:54 -0500 Subject: [PATCH 2/3] Rename the linker* family of functions. --- src/Data/Abstract/Evaluatable.hs | 4 ++-- src/Data/Abstract/ModuleTable.hs | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Data/Abstract/Evaluatable.hs b/src/Data/Abstract/Evaluatable.hs index a5a20dcaa..3d750d963 100644 --- a/src/Data/Abstract/Evaluatable.hs +++ b/src/Data/Abstract/Evaluatable.hs @@ -84,7 +84,7 @@ require :: ( FreeVariables term ) => term -> m v -require term = getModuleTable >>= maybe (load term) pure . linkerLookup name +require term = getModuleTable >>= maybe (load term) pure . moduleTableLookup name where name = moduleName term -- | Load another term/file and return an Effect. @@ -96,7 +96,7 @@ load :: ( FreeVariables term ) => term -> m v -load term = askModuleTable >>= maybe notFound evalAndCache . linkerLookup name +load term = askModuleTable >>= maybe notFound evalAndCache . moduleTableLookup name where name = moduleName term notFound = fail ("cannot find " <> show name) evalAndCache e = do diff --git a/src/Data/Abstract/ModuleTable.hs b/src/Data/Abstract/ModuleTable.hs index 6f53903bb..848273aae 100644 --- a/src/Data/Abstract/ModuleTable.hs +++ b/src/Data/Abstract/ModuleTable.hs @@ -1,16 +1,19 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} -module Data.Abstract.ModuleTable where +module Data.Abstract.ModuleTable + ( ModuleTable (..) + , moduleTableLookup + , moduleTableInsert + )where import Data.Semigroup import GHC.Generics import qualified Data.Map as Map - newtype ModuleTable a = ModuleTable { unModuleTable :: Map.Map FilePath a } deriving (Eq, Foldable, Functor, Generic1, Monoid, Ord, Semigroup, Show, Traversable) -linkerLookup :: FilePath -> ModuleTable a -> Maybe a -linkerLookup k = Map.lookup k . unModuleTable +moduleTableLookup :: FilePath -> ModuleTable a -> Maybe a +moduleTableLookup k = Map.lookup k . unModuleTable -linkerInsert :: FilePath -> a -> ModuleTable a -> ModuleTable a -linkerInsert k v ModuleTable{..} = ModuleTable (Map.insert k v unModuleTable) +moduleTableInsert :: FilePath -> a -> ModuleTable a -> ModuleTable a +moduleTableInsert k v ModuleTable{..} = ModuleTable (Map.insert k v unModuleTable) From 276d66e02f76d1c8a483988271dd4c181a93f8cf Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Wed, 7 Mar 2018 10:17:28 -0500 Subject: [PATCH 3/3] fix stray linkerInsert --- src/Data/Abstract/Evaluatable.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/Abstract/Evaluatable.hs b/src/Data/Abstract/Evaluatable.hs index 3d750d963..be9f98501 100644 --- a/src/Data/Abstract/Evaluatable.hs +++ b/src/Data/Abstract/Evaluatable.hs @@ -101,7 +101,7 @@ load term = askModuleTable >>= maybe notFound evalAndCache . moduleTableLookup n notFound = fail ("cannot find " <> show name) evalAndCache e = do v <- evaluateTerm e - modifyModuleTable (linkerInsert name v) + modifyModuleTable (moduleTableInsert name v) pure v -- | Get a module name from a term (expects single free variables).