From c31b151ba85aa0c2f4967fd1cd34ccec5c816a3b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Oct 2019 17:33:56 -0400 Subject: [PATCH 01/16] :fire: Core.Loc.Path. --- semantic-core/semantic-core.cabal | 1 + semantic-core/src/Analysis/Concrete.hs | 18 +++++++++--------- semantic-core/src/Analysis/Eval.hs | 5 +++-- semantic-core/src/Analysis/ImportGraph.hs | 14 +++++++------- semantic-core/src/Analysis/ScopeGraph.hs | 16 ++++++++-------- semantic-core/src/Analysis/Typecheck.hs | 10 +++++----- .../src/Control/Carrier/Fail/WithLoc.hs | 12 ++++++------ semantic-core/src/Core/File.hs | 3 ++- semantic-core/src/Core/Loc.hs | 17 ++++++----------- 9 files changed, 47 insertions(+), 49 deletions(-) diff --git a/semantic-core/semantic-core.cabal b/semantic-core/semantic-core.cabal index 65b9e7004..8f387f695 100644 --- a/semantic-core/semantic-core.cabal +++ b/semantic-core/semantic-core.cabal @@ -65,6 +65,7 @@ library , fused-syntax , haskeline ^>= 0.7.5 , parsers ^>= 0.12.10 + , pathtype ^>= 0.8.1 , prettyprinter ^>= 1.2.1 , prettyprinter-ansi-terminal ^>= 1.1.1 , semantic-source ^>= 0 diff --git a/semantic-core/src/Analysis/Concrete.hs b/semantic-core/src/Analysis/Concrete.hs index b63c25984..91e5dfdad 100644 --- a/semantic-core/src/Analysis/Concrete.hs +++ b/semantic-core/src/Analysis/Concrete.hs @@ -21,7 +21,6 @@ import Control.Effect.Reader hiding (Local) import Control.Effect.State import Control.Monad ((<=<), guard) import Core.File -import Core.Loc import Core.Name import Data.Function (fix) import qualified Data.IntMap as IntMap @@ -33,6 +32,7 @@ import Data.Text (Text, pack) import Data.Traversable (for) import Prelude hiding (fail) import Source.Span +import qualified System.Path as Path type Precise = Int type Env = Map.Map Name Precise @@ -41,7 +41,7 @@ newtype FrameId = FrameId { unFrameId :: Precise } deriving (Eq, Ord, Show) data Concrete term - = Closure Path Span Name term Env + = Closure Path.AbsRelFile Span Name term Env | Unit | Bool Bool | String Text @@ -67,18 +67,18 @@ data Edge = Lexical | Import -- | Concrete evaluation of a term to a value. -- --- >>> map fileBody (snd (concrete eval [File (Path "bool") (Span (Pos 1 1) (Pos 1 5)) (Core.bool True)])) +-- >>> map fileBody (snd (concrete eval [File (Path.AbsRelFile "bool") (Span (Pos 1 1) (Pos 1 5)) (Core.bool True)])) -- [Right (Bool True)] concrete :: (Foldable term, Show (term Name)) => (forall sig m - . (Carrier sig m, Member (Reader Path) sig, Member (Reader Span) sig, MonadFail m) + . (Carrier sig m, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig, MonadFail m) => Analysis (term Name) Precise (Concrete (term Name)) m -> (term Name -> m (Concrete (term Name))) -> (term Name -> m (Concrete (term Name))) ) -> [File (term Name)] - -> (Heap (term Name), [File (Either (Path, Span, String) (Concrete (term Name)))]) + -> (Heap (term Name), [File (Either (Path.AbsRelFile, Span, String) (Concrete (term Name)))]) concrete eval = run . runFresh @@ -94,13 +94,13 @@ runFile , Show (term Name) ) => (forall sig m - . (Carrier sig m, Member (Reader Path) sig, Member (Reader Span) sig, MonadFail m) + . (Carrier sig m, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig, MonadFail m) => Analysis (term Name) Precise (Concrete (term Name)) m -> (term Name -> m (Concrete (term Name))) -> (term Name -> m (Concrete (term Name))) ) -> File (term Name) - -> m (File (Either (Path, Span, String) (Concrete (term Name)))) + -> m (File (Either (Path.AbsRelFile, Span, String) (Concrete (term Name)))) runFile eval file = traverse run file where run = runReader (filePath file) . runReader (fileSpan file) @@ -112,7 +112,7 @@ concreteAnalysis :: ( Carrier sig m , Foldable term , Member Fresh sig , Member (Reader Env) sig - , Member (Reader Path) sig + , Member (Reader Path.AbsRelFile) sig , Member (Reader Span) sig , Member (State (Heap (term Name))) sig , MonadFail m @@ -209,7 +209,7 @@ addressStyle heap = (G.defaultStyle vertex) { G.edgeAttributes } Unit -> "()" Bool b -> pack $ show b String s -> pack $ show s - Closure p (Span s e) n _ _ -> "\\\\ " <> unName n <> " [" <> getPath p <> ":" <> showPos s <> "-" <> showPos e <> "]" + Closure p (Span s e) n _ _ -> "\\\\ " <> unName n <> " [" <> pack (show p) <> ":" <> showPos s <> "-" <> showPos e <> "]" Record _ -> "{}" showPos (Pos l c) = pack (show l) <> ":" <> pack (show c) diff --git a/semantic-core/src/Analysis/Eval.hs b/semantic-core/src/Analysis/Eval.hs index d8f8d39ff..6f2efa28f 100644 --- a/semantic-core/src/Analysis/Eval.hs +++ b/semantic-core/src/Analysis/Eval.hs @@ -28,6 +28,7 @@ import Prelude hiding (fail) import Source.Span import Syntax.Scope import Syntax.Term +import qualified System.Path as Path eval :: ( Carrier sig m , Member (Reader Span) sig @@ -130,9 +131,9 @@ prog5 = fromBody $ ann (do' prog6 :: (Carrier sig t, Member Core sig) => [File (t Name)] prog6 = - [ File (Path "dep") (snd (fromJust here)) $ Core.record + [ File (Path.absRel "dep") (snd (fromJust here)) $ Core.record [ ("dep", Core.record [ ("var", Core.bool True) ]) ] - , File (Path "main") (snd (fromJust here)) $ do' (map (Nothing :<-) + , File (Path.absRel "main") (snd (fromJust here)) $ do' (map (Nothing :<-) [ load (Core.string "dep") , Core.record [ ("thing", pure "dep" Core.... "var") ] ]) diff --git a/semantic-core/src/Analysis/ImportGraph.hs b/semantic-core/src/Analysis/ImportGraph.hs index 9df957023..74d5cdde2 100644 --- a/semantic-core/src/Analysis/ImportGraph.hs +++ b/semantic-core/src/Analysis/ImportGraph.hs @@ -15,7 +15,6 @@ import Control.Effect.Reader import Control.Effect.State import Control.Monad ((>=>)) import Core.File -import Core.Loc import Core.Name import Data.Foldable (fold, for_) import Data.Function (fix) @@ -26,6 +25,7 @@ import qualified Data.Set as Set import Data.Text (Text) import Prelude hiding (fail) import Source.Span +import qualified System.Path as Path type ImportGraph = Map.Map Text (Set.Set Text) @@ -42,7 +42,7 @@ instance Monoid (Value term) where mempty = Value Abstract mempty data Semi term - = Closure Path Span Name term + = Closure Path.AbsRelFile Span Name term -- FIXME: Bound String values. | String Text | Abstract @@ -52,14 +52,14 @@ data Semi term importGraph :: (Ord term, Show term) => (forall sig m - . (Carrier sig m, Member (Reader Path) sig, Member (Reader Span) sig, MonadFail m) + . (Carrier sig m, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig, MonadFail m) => Analysis term Name (Value term) m -> (term -> m (Value term)) -> (term -> m (Value term)) ) -> [File term] -> ( Heap Name (Value term) - , [File (Either (Path, Span, String) (Value term))] + , [File (Either (Path.AbsRelFile, Span, String) (Value term))] ) importGraph eval = run @@ -76,13 +76,13 @@ runFile , Show term ) => (forall sig m - . (Carrier sig m, Member (Reader Path) sig, Member (Reader Span) sig, MonadFail m) + . (Carrier sig m, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig, MonadFail m) => Analysis term Name (Value term) m -> (term -> m (Value term)) -> (term -> m (Value term)) ) -> File term - -> m (File (Either (Path, Span, String) (Value term))) + -> m (File (Either (Path.AbsRelFile, Span, String) (Value term))) runFile eval file = traverse run file where run = runReader (filePath file) . runReader (fileSpan file) @@ -93,7 +93,7 @@ runFile eval file = traverse run file -- FIXME: decompose into a product domain and two atomic domains importGraphAnalysis :: ( Alternative m , Carrier sig m - , Member (Reader Path) sig + , Member (Reader Path.AbsRelFile) sig , Member (Reader Span) sig , Member (State (Heap Name (Value term))) sig , MonadFail m diff --git a/semantic-core/src/Analysis/ScopeGraph.hs b/semantic-core/src/Analysis/ScopeGraph.hs index 2c540af1a..89b085563 100644 --- a/semantic-core/src/Analysis/ScopeGraph.hs +++ b/semantic-core/src/Analysis/ScopeGraph.hs @@ -17,7 +17,6 @@ import Control.Effect.Reader import Control.Effect.State import Control.Monad ((>=>)) import Core.File -import Core.Loc import Core.Name import Data.Foldable (fold) import Data.Function (fix) @@ -28,16 +27,17 @@ import qualified Data.Set as Set import Data.Traversable (for) import Prelude hiding (fail) import Source.Span +import qualified System.Path as Path data Decl = Decl { declSymbol :: Name - , declPath :: Path + , declPath :: Path.AbsRelFile , declSpan :: Span } deriving (Eq, Ord, Show) data Ref = Ref - { refPath :: Path + { refPath :: Path.AbsRelFile , refSpan :: Span } deriving (Eq, Ord, Show) @@ -54,13 +54,13 @@ instance Monoid ScopeGraph where scopeGraph :: Ord term => (forall sig m - . (Carrier sig m, Member (Reader Path) sig, Member (Reader Span) sig, MonadFail m) + . (Carrier sig m, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig, MonadFail m) => Analysis term Name ScopeGraph m -> (term -> m ScopeGraph) -> (term -> m ScopeGraph) ) -> [File term] - -> (Heap Name ScopeGraph, [File (Either (Path, Span, String) ScopeGraph)]) + -> (Heap Name ScopeGraph, [File (Either (Path.AbsRelFile, Span, String) ScopeGraph)]) scopeGraph eval = run . runFresh @@ -75,13 +75,13 @@ runFile , Ord term ) => (forall sig m - . (Carrier sig m, Member (Reader Path) sig, Member (Reader Span) sig, MonadFail m) + . (Carrier sig m, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig, MonadFail m) => Analysis term Name ScopeGraph m -> (term -> m ScopeGraph) -> (term -> m ScopeGraph) ) -> File term - -> m (File (Either (Path, Span, String) ScopeGraph)) + -> m (File (Either (Path.AbsRelFile, Span, String) ScopeGraph)) runFile eval file = traverse run file where run = runReader (filePath file) . runReader (fileSpan file) @@ -93,7 +93,7 @@ runFile eval file = traverse run file scopeGraphAnalysis :: ( Alternative m , Carrier sig m - , Member (Reader Path) sig + , Member (Reader Path.AbsRelFile) sig , Member (Reader Span) sig , Member (Reader (Map.Map Name Ref)) sig , Member (State (Heap Name ScopeGraph)) sig diff --git a/semantic-core/src/Analysis/Typecheck.hs b/semantic-core/src/Analysis/Typecheck.hs index 594d00eef..e1d1a8af6 100644 --- a/semantic-core/src/Analysis/Typecheck.hs +++ b/semantic-core/src/Analysis/Typecheck.hs @@ -17,7 +17,6 @@ import Control.Effect.Reader hiding (Local) import Control.Effect.State import Control.Monad ((>=>), unless) import Core.File -import Core.Loc import Core.Name as Name import Data.Foldable (for_) import Data.Function (fix) @@ -39,6 +38,7 @@ import Syntax.Module import Syntax.Scope import Syntax.Term import Syntax.Var (closed) +import qualified System.Path as Path data Monotype f a = Bool @@ -96,14 +96,14 @@ generalize ty = fromJust (closed (forAlls (IntSet.toList (mvs ty)) (hoistTerm R typecheckingFlowInsensitive :: Ord term => (forall sig m - . (Carrier sig m, Member (Reader Path) sig, Member (Reader Span) sig, MonadFail m) + . (Carrier sig m, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig, MonadFail m) => Analysis term Name Type m -> (term -> m Type) -> (term -> m Type) ) -> [File term] -> ( Heap Name Type - , [File (Either (Path, Span, String) (Term (Polytype :+: Monotype) Void))] + , [File (Either (Path.AbsRelFile, Span, String) (Term (Polytype :+: Monotype) Void))] ) typecheckingFlowInsensitive eval = run @@ -120,13 +120,13 @@ runFile , Ord term ) => (forall sig m - . (Carrier sig m, Member (Reader Path) sig, Member (Reader Span) sig, MonadFail m) + . (Carrier sig m, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig, MonadFail m) => Analysis term Name Type m -> (term -> m Type) -> (term -> m Type) ) -> File term - -> m (File (Either (Path, Span, String) Type)) + -> m (File (Either (Path.AbsRelFile, Span, String) Type)) runFile eval file = traverse run file where run = (\ m -> do diff --git a/semantic-core/src/Control/Carrier/Fail/WithLoc.hs b/semantic-core/src/Control/Carrier/Fail/WithLoc.hs index f2e8b62ea..90cf3c157 100644 --- a/semantic-core/src/Control/Carrier/Fail/WithLoc.hs +++ b/semantic-core/src/Control/Carrier/Fail/WithLoc.hs @@ -12,22 +12,22 @@ import Control.Effect.Carrier import Control.Effect.Error import Control.Effect.Fail (Fail(..), MonadFail(..)) import Control.Effect.Reader -import Core.Loc import Prelude hiding (fail) import Source.Span +import qualified System.Path as Path -runFail :: FailC m a -> m (Either (Path, Span, String) a) +runFail :: FailC m a -> m (Either (Path.AbsRelFile, Span, String) a) runFail = runError . runFailC -newtype FailC m a = FailC { runFailC :: ErrorC (Path, Span, String) m a } +newtype FailC m a = FailC { runFailC :: ErrorC (Path.AbsRelFile, Span, String) m a } deriving (Alternative, Applicative, Functor, Monad) -instance (Carrier sig m, Effect sig, Member (Reader Path) sig, Member (Reader Span) sig) => MonadFail (FailC m) where +instance (Carrier sig m, Effect sig, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig) => MonadFail (FailC m) where fail s = do path <- ask span <- ask - FailC (throwError (path :: Path, span :: Span, s)) + FailC (throwError (path :: Path.AbsRelFile, span :: Span, s)) -instance (Carrier sig m, Effect sig, Member (Reader Path) sig, Member (Reader Span) sig) => Carrier (Fail :+: sig) (FailC m) where +instance (Carrier sig m, Effect sig, Member (Reader Path.AbsRelFile) sig, Member (Reader Span) sig) => Carrier (Fail :+: sig) (FailC m) where eff (L (Fail s)) = fail s eff (R other) = FailC (eff (R (handleCoercible other))) diff --git a/semantic-core/src/Core/File.hs b/semantic-core/src/Core/File.hs index 69f765162..206e900dc 100644 --- a/semantic-core/src/Core/File.hs +++ b/semantic-core/src/Core/File.hs @@ -8,9 +8,10 @@ import Core.Loc import Data.Maybe (fromJust) import GHC.Stack import Source.Span +import qualified System.Path as Path data File a = File - { filePath :: !Path + { filePath :: !Path.AbsRelFile , fileSpan :: {-# UNPACK #-} !Span , fileBody :: !a } diff --git a/semantic-core/src/Core/Loc.hs b/semantic-core/src/Core/Loc.hs index b6c2016f7..f2d8fe740 100644 --- a/semantic-core/src/Core/Loc.hs +++ b/semantic-core/src/Core/Loc.hs @@ -1,25 +1,20 @@ {-# LANGUAGE RecordWildCards #-} module Core.Loc -( Path(..) -, here +( here , stackLoc ) where -import Data.Text (Text, pack) import GHC.Stack import Source.Span +import qualified System.Path as Path -newtype Path = Path { getPath :: Text } - deriving (Eq, Ord, Show) - - -here :: HasCallStack => Maybe (Path, Span) +here :: HasCallStack => Maybe (Path.AbsRelFile, Span) here = stackLoc callStack -stackLoc :: CallStack -> Maybe (Path, Span) +stackLoc :: CallStack -> Maybe (Path.AbsRelFile, Span) stackLoc cs = case getCallStack cs of (_, srcLoc):_ -> Just (fromGHCSrcLoc srcLoc) _ -> Nothing -fromGHCSrcLoc :: SrcLoc -> (Path, Span) -fromGHCSrcLoc SrcLoc{..} = (Path (pack srcLocFile), Span (Pos srcLocStartLine srcLocStartCol) (Pos srcLocEndLine srcLocEndCol)) +fromGHCSrcLoc :: SrcLoc -> (Path.AbsRelFile, Span) +fromGHCSrcLoc SrcLoc{..} = (Path.absRel srcLocFile, Span (Pos srcLocStartLine srcLocStartCol) (Pos srcLocEndLine srcLocEndCol)) From b2b88f24b54974ce81852a6cdb6ec394b41461d0 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Oct 2019 17:37:46 -0400 Subject: [PATCH 02/16] Stub in a debug module. --- semantic-source/semantic-source.cabal | 1 + semantic-source/src/Source/Debug.hs | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 semantic-source/src/Source/Debug.hs diff --git a/semantic-source/semantic-source.cabal b/semantic-source/semantic-source.cabal index 6e683a3db..b3fc23c63 100644 --- a/semantic-source/semantic-source.cabal +++ b/semantic-source/semantic-source.cabal @@ -42,6 +42,7 @@ common common library import: common exposed-modules: + Source.Debug Source.Loc Source.Range Source.Source diff --git a/semantic-source/src/Source/Debug.hs b/semantic-source/src/Source/Debug.hs new file mode 100644 index 000000000..6a85e1fb1 --- /dev/null +++ b/semantic-source/src/Source/Debug.hs @@ -0,0 +1,2 @@ +module Source.Debug +() where From e177ea7eab66b316845f6aa9f479e14deae83951 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Oct 2019 17:40:42 -0400 Subject: [PATCH 03/16] Rename fromGHCSrcLoc to fromSrcLoc. --- semantic-core/src/Core/Loc.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/semantic-core/src/Core/Loc.hs b/semantic-core/src/Core/Loc.hs index f2d8fe740..47184ad2c 100644 --- a/semantic-core/src/Core/Loc.hs +++ b/semantic-core/src/Core/Loc.hs @@ -13,8 +13,8 @@ here = stackLoc callStack stackLoc :: CallStack -> Maybe (Path.AbsRelFile, Span) stackLoc cs = case getCallStack cs of - (_, srcLoc):_ -> Just (fromGHCSrcLoc srcLoc) + (_, srcLoc):_ -> Just (fromSrcLoc srcLoc) _ -> Nothing -fromGHCSrcLoc :: SrcLoc -> (Path.AbsRelFile, Span) -fromGHCSrcLoc SrcLoc{..} = (Path.absRel srcLocFile, Span (Pos srcLocStartLine srcLocStartCol) (Pos srcLocEndLine srcLocEndCol)) +fromSrcLoc :: SrcLoc -> (Path.AbsRelFile, Span) +fromSrcLoc SrcLoc{..} = (Path.absRel srcLocFile, Span (Pos srcLocStartLine srcLocStartCol) (Pos srcLocEndLine srcLocEndCol)) From edaa56ec7f5fd242dcf45308d0dfa5e8f5ae2d7b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Oct 2019 17:44:50 -0400 Subject: [PATCH 04/16] Revert "Stub in a debug module." This reverts commit b2b88f24b54974ce81852a6cdb6ec394b41461d0. --- semantic-source/semantic-source.cabal | 1 - semantic-source/src/Source/Debug.hs | 2 -- 2 files changed, 3 deletions(-) delete mode 100644 semantic-source/src/Source/Debug.hs diff --git a/semantic-source/semantic-source.cabal b/semantic-source/semantic-source.cabal index b3fc23c63..6e683a3db 100644 --- a/semantic-source/semantic-source.cabal +++ b/semantic-source/semantic-source.cabal @@ -42,7 +42,6 @@ common common library import: common exposed-modules: - Source.Debug Source.Loc Source.Range Source.Source diff --git a/semantic-source/src/Source/Debug.hs b/semantic-source/src/Source/Debug.hs deleted file mode 100644 index 6a85e1fb1..000000000 --- a/semantic-source/src/Source/Debug.hs +++ /dev/null @@ -1,2 +0,0 @@ -module Source.Debug -() where From 26cc613a07cbacfb30b315ad03b698cab45dd96f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Oct 2019 17:46:56 -0400 Subject: [PATCH 05/16] Spacing. --- semantic-source/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/semantic-source/CHANGELOG.md b/semantic-source/CHANGELOG.md index f1859800e..9182facd8 100644 --- a/semantic-source/CHANGELOG.md +++ b/semantic-source/CHANGELOG.md @@ -2,6 +2,7 @@ - Adds an `NFData` instance for `Source`. + # 0.0.0.1 - Loosens the upper bound on `hashable`. From d679f287607e56b0efa364d0a217ba67ed173d55 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Oct 2019 17:50:25 -0400 Subject: [PATCH 06/16] =?UTF-8?q?File.fromBody=20doesn=E2=80=99t=20depend?= =?UTF-8?q?=20on=20Core.Loc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- semantic-core/src/Core/File.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/semantic-core/src/Core/File.hs b/semantic-core/src/Core/File.hs index 206e900dc..9962faa5f 100644 --- a/semantic-core/src/Core/File.hs +++ b/semantic-core/src/Core/File.hs @@ -4,8 +4,7 @@ module Core.File , fromBody ) where -import Core.Loc -import Data.Maybe (fromJust) +import Data.Maybe (fromJust, listToMaybe) import GHC.Stack import Source.Span import qualified System.Path as Path @@ -18,5 +17,5 @@ data File a = File deriving (Eq, Foldable, Functor, Ord, Show, Traversable) fromBody :: HasCallStack => a -> File a -fromBody body = File path span body where - (path, span) = fromJust (stackLoc callStack) +fromBody body = File (Path.absRel (srcLocFile srcLoc)) (spanFromSrcLoc srcLoc) body where + srcLoc = snd (fromJust (listToMaybe (getCallStack callStack))) From 585848658a1008b8f7c5b9870f0759e1e1f40e5d Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Oct 2019 17:57:26 -0400 Subject: [PATCH 07/16] =?UTF-8?q?Core.Core=20doesn=E2=80=99t=20depend=20on?= =?UTF-8?q?=20Core.Loc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- semantic-core/src/Core/Core.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/semantic-core/src/Core/Core.hs b/semantic-core/src/Core/Core.hs index 1647c6c6b..481a11b7b 100644 --- a/semantic-core/src/Core/Core.hs +++ b/semantic-core/src/Core/Core.hs @@ -37,12 +37,11 @@ module Core.Core import Control.Applicative (Alternative (..)) import Control.Effect.Carrier -import Core.Loc import Core.Name import Data.Bifunctor (Bifunctor (..)) import Data.Foldable (foldl') import Data.List.NonEmpty (NonEmpty (..)) -import Data.Maybe (fromMaybe) +import Data.Maybe (fromMaybe, listToMaybe) import Data.Text (Text) import GHC.Generics (Generic1) import GHC.Stack @@ -233,7 +232,7 @@ annAt :: (Carrier sig m, Member (Ann ann) sig) => ann -> m a -> m a annAt ann = send . Ann ann annWith :: (Carrier sig m, Member (Ann Span) sig) => CallStack -> m a -> m a -annWith callStack = maybe id (annAt . snd) (stackLoc callStack) +annWith callStack = maybe id (annAt . spanFromSrcLoc . snd) (listToMaybe (getCallStack callStack)) stripAnnotations :: forall ann a sig . (HFunctor sig, forall g . Functor g => Functor (sig g)) => Term (Ann ann :+: sig) a -> Term sig a From ab1932c264b3e6469a255b57542dd4773f9ce068 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Oct 2019 18:04:20 -0400 Subject: [PATCH 08/16] Use File.fromBody. --- semantic-core/src/Analysis/Eval.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/semantic-core/src/Analysis/Eval.hs b/semantic-core/src/Analysis/Eval.hs index 6f2efa28f..8163b6afe 100644 --- a/semantic-core/src/Analysis/Eval.hs +++ b/semantic-core/src/Analysis/Eval.hs @@ -18,10 +18,9 @@ import Control.Effect.Reader import Control.Monad ((>=>)) import Core.Core as Core import Core.File -import Core.Loc import Core.Name import Data.Functor -import Data.Maybe (fromJust, fromMaybe) +import Data.Maybe (fromMaybe) import Data.Text (Text) import GHC.Stack import Prelude hiding (fail) @@ -131,12 +130,14 @@ prog5 = fromBody $ ann (do' prog6 :: (Carrier sig t, Member Core sig) => [File (t Name)] prog6 = - [ File (Path.absRel "dep") (snd (fromJust here)) $ Core.record - [ ("dep", Core.record [ ("var", Core.bool True) ]) ] - , File (Path.absRel "main") (snd (fromJust here)) $ do' (map (Nothing :<-) + [ (fromBody (Core.record + [ ("dep", Core.record [ ("var", Core.bool True) ]) ])) + { filePath = Path.absRel "dep"} + , (fromBody (do' (map (Nothing :<-) [ load (Core.string "dep") , Core.record [ ("thing", pure "dep" Core.... "var") ] - ]) + ]))) + { filePath = Path.absRel "main" } ] ruby :: (Carrier sig t, Member (Ann Span) sig, Member Core sig) => File (t Name) From c31b6a072f1ea9c343a3d58290dbf42b5cbcb87e Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Oct 2019 18:08:25 -0400 Subject: [PATCH 09/16] Fix the tests. --- semantic-python/test/Instances.hs | 7 ++++--- semantic-python/test/Test.hs | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/semantic-python/test/Instances.hs b/semantic-python/test/Instances.hs index 3db17c44a..76875ea97 100644 --- a/semantic-python/test/Instances.hs +++ b/semantic-python/test/Instances.hs @@ -9,11 +9,11 @@ module Instances () where import Analysis.ScopeGraph import Core.File -import Core.Loc import Core.Name (Name (..)) import Data.Aeson import qualified Data.Map as Map -import Data.Text (Text) +import Data.Text (Text, pack) +import qualified System.Path as Path deriving newtype instance ToJSON Name deriving newtype instance ToJSONKey Name @@ -25,7 +25,8 @@ instance ToJSON a => ToJSON (File a) where , "body" .= fileBody ] -deriving newtype instance ToJSON Path +instance ToJSON Path.AbsRelFile where + toJSON p = toJSON (pack (show p)) instance ToJSON Ref where toJSON (Ref path span) = object diff --git a/semantic-python/test/Test.hs b/semantic-python/test/Test.hs index 739174b9d..11a5ee333 100644 --- a/semantic-python/test/Test.hs +++ b/semantic-python/test/Test.hs @@ -14,7 +14,6 @@ import Control.Monad.Trans.Resource (ResourceT, runResourceT) import Core.Core import Core.Core.Pretty import Core.File -import Core.Loc import Core.Name import qualified Data.Aeson as Aeson import qualified Data.Aeson.Encode.Pretty as Aeson @@ -51,7 +50,7 @@ import Instances () assertJQExpressionSucceeds :: Show a => Directive.Directive -> a -> Term (Ann Span :+: Core) Name -> HUnit.Assertion assertJQExpressionSucceeds directive tree core = do - bod <- case scopeGraph Eval.eval [File (Path "") (Span (Pos 1 1) (Pos 1 1)) core] of + bod <- case scopeGraph Eval.eval [File (Path.absRel "") (Span (Pos 1 1) (Pos 1 1)) core] of (heap, [File _ _ (Right result)]) -> pure $ Aeson.object [ "scope" Aeson..= heap , "heap" Aeson..= result From c2bb05fe25243d2c932519ebe8b77f4891588aed Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 10 Oct 2019 18:09:02 -0400 Subject: [PATCH 10/16] :fire: Core.Loc. --- semantic-core/semantic-core.cabal | 1 - semantic-core/src/Core/Loc.hs | 20 -------------------- 2 files changed, 21 deletions(-) delete mode 100644 semantic-core/src/Core/Loc.hs diff --git a/semantic-core/semantic-core.cabal b/semantic-core/semantic-core.cabal index 9af8a26cc..b391b4c32 100644 --- a/semantic-core/semantic-core.cabal +++ b/semantic-core/semantic-core.cabal @@ -53,7 +53,6 @@ library Core.Core.Parser Core.Core.Pretty Core.File - Core.Loc Core.Name build-depends: algebraic-graphs ^>= 0.3 diff --git a/semantic-core/src/Core/Loc.hs b/semantic-core/src/Core/Loc.hs deleted file mode 100644 index 47184ad2c..000000000 --- a/semantic-core/src/Core/Loc.hs +++ /dev/null @@ -1,20 +0,0 @@ -{-# LANGUAGE RecordWildCards #-} -module Core.Loc -( here -, stackLoc -) where - -import GHC.Stack -import Source.Span -import qualified System.Path as Path - -here :: HasCallStack => Maybe (Path.AbsRelFile, Span) -here = stackLoc callStack - -stackLoc :: CallStack -> Maybe (Path.AbsRelFile, Span) -stackLoc cs = case getCallStack cs of - (_, srcLoc):_ -> Just (fromSrcLoc srcLoc) - _ -> Nothing - -fromSrcLoc :: SrcLoc -> (Path.AbsRelFile, Span) -fromSrcLoc SrcLoc{..} = (Path.absRel srcLocFile, Span (Pos srcLocStartLine srcLocStartCol) (Pos srcLocEndLine srcLocEndCol)) From 9b48331945d63532d43a994e003f8325c1c37f32 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 11 Oct 2019 09:13:20 -0400 Subject: [PATCH 11/16] :fire: a redundant constraint. --- semantic-core/test/Generators.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-core/test/Generators.hs b/semantic-core/test/Generators.hs index 37e8dc0bf..b7443961f 100644 --- a/semantic-core/test/Generators.hs +++ b/semantic-core/test/Generators.hs @@ -31,7 +31,7 @@ name = Gen.prune (named' <$> names) where boolean :: (Carrier sig t, Member Core.Core sig, MonadGen m) => m (t Name) boolean = Core.bool <$> Gen.bool -variable :: (Carrier sig t, Member Core.Core sig, MonadGen m) => m (t Name) +variable :: (Carrier sig t, MonadGen m) => m (t Name) variable = pure . namedValue <$> name ifthenelse :: (Carrier sig t, Member Core.Core sig, MonadGen m) => m (t Name) -> m (t Name) From d16a3c909cf25c0af4ee896aa525502e71eabaa0 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 11 Oct 2019 09:13:30 -0400 Subject: [PATCH 12/16] Weaken a Carrier constraint to Applicative. --- semantic-core/test/Generators.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-core/test/Generators.hs b/semantic-core/test/Generators.hs index b7443961f..5839b2d14 100644 --- a/semantic-core/test/Generators.hs +++ b/semantic-core/test/Generators.hs @@ -31,7 +31,7 @@ name = Gen.prune (named' <$> names) where boolean :: (Carrier sig t, Member Core.Core sig, MonadGen m) => m (t Name) boolean = Core.bool <$> Gen.bool -variable :: (Carrier sig t, MonadGen m) => m (t Name) +variable :: (Applicative t, MonadGen m) => m (t Name) variable = pure . namedValue <$> name ifthenelse :: (Carrier sig t, Member Core.Core sig, MonadGen m) => m (t Name) -> m (t Name) From cce6f74b95e46556d1670b0aaaeb769dc0fe519a Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 11 Oct 2019 09:13:48 -0400 Subject: [PATCH 13/16] :fire: a redundant import. --- semantic-core/test/Generators.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/semantic-core/test/Generators.hs b/semantic-core/test/Generators.hs index 5839b2d14..01cfd6feb 100644 --- a/semantic-core/test/Generators.hs +++ b/semantic-core/test/Generators.hs @@ -19,7 +19,6 @@ import qualified Hedgehog.Range as Range import Control.Effect.Carrier import qualified Core.Core as Core import Core.Name -import Syntax.Term -- The 'prune' call here ensures that we don't spend all our time just generating -- fresh names for variables, since the length of variable names is not an From a05bb26c9f04f00c9c337fd5a525d6445518dc61 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 11 Oct 2019 12:13:57 -0400 Subject: [PATCH 14/16] Use Path.toString instead of show. --- semantic-python/test/Instances.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-python/test/Instances.hs b/semantic-python/test/Instances.hs index 76875ea97..5a7750d11 100644 --- a/semantic-python/test/Instances.hs +++ b/semantic-python/test/Instances.hs @@ -26,7 +26,7 @@ instance ToJSON a => ToJSON (File a) where ] instance ToJSON Path.AbsRelFile where - toJSON p = toJSON (pack (show p)) + toJSON p = toJSON (pack (Path.toString p)) instance ToJSON Ref where toJSON (Ref path span) = object From 7554271e2d8502978bfbc06f2eb5b6e60ec1e285 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 11 Oct 2019 12:14:58 -0400 Subject: [PATCH 15/16] toString. --- semantic-core/src/Analysis/Concrete.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-core/src/Analysis/Concrete.hs b/semantic-core/src/Analysis/Concrete.hs index 9a0a36022..47c6554d5 100644 --- a/semantic-core/src/Analysis/Concrete.hs +++ b/semantic-core/src/Analysis/Concrete.hs @@ -209,7 +209,7 @@ addressStyle heap = (G.defaultStyle vertex) { G.edgeAttributes } Unit -> "()" Bool b -> pack $ show b String s -> pack $ show s - Closure p (Span s e) n _ _ -> "\\\\ " <> unName n <> " [" <> pack (show p) <> ":" <> showPos s <> "-" <> showPos e <> "]" + Closure p (Span s e) n _ _ -> "\\\\ " <> unName n <> " [" <> pack (Path.toString p) <> ":" <> showPos s <> "-" <> showPos e <> "]" Record _ -> "{}" showPos (Pos l c) = pack (show l) <> ":" <> pack (show c) From 7c2ac87ff3d58599b7eb93393cf5770a541e0854 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 11 Oct 2019 12:19:37 -0400 Subject: [PATCH 16/16] Correct the doctest. --- semantic-core/src/Analysis/Concrete.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-core/src/Analysis/Concrete.hs b/semantic-core/src/Analysis/Concrete.hs index 47c6554d5..1cdf51827 100644 --- a/semantic-core/src/Analysis/Concrete.hs +++ b/semantic-core/src/Analysis/Concrete.hs @@ -67,7 +67,7 @@ data Edge = Lexical | Import -- | Concrete evaluation of a term to a value. -- --- >>> map fileBody (snd (concrete eval [File (Path.AbsRelFile "bool") (Span (Pos 1 1) (Pos 1 5)) (Core.bool True)])) +-- >>> map fileBody (snd (concrete eval [File (Path.absRel "bool") (Span (Pos 1 1) (Pos 1 5)) (Core.bool True)])) -- [Right (Bool True)] concrete :: (Foldable term, Show (term Name))