From c0ecbb12b656c9cc363cbb736ea6d2134b0c7a7f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 11:31:16 -0400 Subject: [PATCH 01/84] :fire: SomeParser. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s unused. --- src/Control/Carrier/Parse/Measured.hs | 1 - src/Control/Carrier/Parse/Simple.hs | 1 - src/Parsing/Parser.hs | 3 +-- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Control/Carrier/Parse/Measured.hs b/src/Control/Carrier/Parse/Measured.hs index fddbd3d30..2116ea22a 100644 --- a/src/Control/Carrier/Parse/Measured.hs +++ b/src/Control/Carrier/Parse/Measured.hs @@ -75,7 +75,6 @@ runParser blob@Blob{..} parser = case parser of time "parse.cmark_parse" languageTag $ let term = cmarkParser blobSource in length term `seq` pure term - SomeParser parser -> SomeTerm <$> runParser blob parser where languageTag = [("language" :: String, show (blobLanguage blob))] data ParserCancelled = ParserTimedOut | AssignmentTimedOut diff --git a/src/Control/Carrier/Parse/Simple.hs b/src/Control/Carrier/Parse/Simple.hs index d7bf004dc..9339f041b 100644 --- a/src/Control/Carrier/Parse/Simple.hs +++ b/src/Control/Carrier/Parse/Simple.hs @@ -65,7 +65,6 @@ runParser timeout blob@Blob{..} parser = case parser of MarkdownParser -> let term = cmarkParser blobSource in length term `seq` pure term - SomeParser parser -> SomeTerm <$> runParser timeout blob parser data ParseFailure = ParseFailure String deriving (Show, Typeable) diff --git a/src/Parsing/Parser.hs b/src/Parsing/Parser.hs index c287bdb78..ae65e4dbb 100644 --- a/src/Parsing/Parser.hs +++ b/src/Parsing/Parser.hs @@ -112,8 +112,7 @@ data Parser term where -> Parser (Term (Sum syntaxes) Loc) -- | A parser for 'Markdown' using cmark. MarkdownParser :: Parser (Term (TermF [] CMarkGFM.NodeType) (Node Markdown.Grammar)) - -- | An abstraction over parsers when we don’t know the details of the term type. - SomeParser :: ApplyAll typeclasses syntax => Parser (Term syntax ann) -> Parser (SomeTerm typeclasses ann) + -- | Apply all of a list of typeclasses to all of a list of functors using 'Apply'. Used by 'someParser' to constrain all of the language-specific syntax types to the typeclasses in question. type family ApplyAll (typeclasses :: [(* -> *) -> Constraint]) (syntax :: * -> *) :: Constraint where From e9fc6122c43fce57a90a45721d66c9deb035f3b7 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 11:50:30 -0400 Subject: [PATCH 02/84] =?UTF-8?q?Don=E2=80=99t=20pass=20the=20blob=20into?= =?UTF-8?q?=20tagging.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tags/Taggable.hs | 5 ++--- src/Tags/Tagging.hs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Tags/Taggable.hs b/src/Tags/Taggable.hs index 8010186ce..5b265d772 100644 --- a/src/Tags/Taggable.hs +++ b/src/Tags/Taggable.hs @@ -29,7 +29,6 @@ import Analysis.ConstructorName import Analysis.HasTextElement import Data.Abstract.Declarations import Data.Abstract.Name -import Data.Blob import Data.Language import Data.Term import Data.Text hiding (empty) @@ -99,10 +98,10 @@ type IsTaggable syntax = ) tagging :: (Monad m, IsTaggable syntax) - => Blob + => Language -> Term syntax Loc -> Stream (Of Token) m () -tagging b = foldSubterms (descend (blobLanguage b)) +tagging = foldSubterms . descend descend :: ( ConstructorName (TermF syntax Loc) diff --git a/src/Tags/Tagging.hs b/src/Tags/Tagging.hs index 71127736a..52cb856b0 100644 --- a/src/Tags/Tagging.hs +++ b/src/Tags/Tagging.hs @@ -31,7 +31,7 @@ runTagging blob symbolsToSummarize . evalState @[ContextToken] [] . Streaming.toList_ . contextualizing blob toKind - . tagging blob + . tagging (blobLanguage blob) where toKind x = do guard (x `elem` symbolsToSummarize) From de5de5f9367b4a3317f039b24e919cf077c60486 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 11:51:28 -0400 Subject: [PATCH 03/84] =?UTF-8?q?Don=E2=80=99t=20pass=20the=20blob=20into?= =?UTF-8?q?=20contextualizing.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tags/Tagging.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Tags/Tagging.hs b/src/Tags/Tagging.hs index 52cb856b0..17a9d8046 100644 --- a/src/Tags/Tagging.hs +++ b/src/Tags/Tagging.hs @@ -30,7 +30,7 @@ runTagging blob symbolsToSummarize = Eff.run . evalState @[ContextToken] [] . Streaming.toList_ - . contextualizing blob toKind + . contextualizing (blobSource blob) toKind . tagging (blobLanguage blob) where toKind x = do @@ -49,11 +49,11 @@ type ContextToken = (Text, Range) contextualizing :: ( Member (State [ContextToken]) sig , Carrier sig m ) - => Blob + => Source.Source -> (Text -> Maybe Kind) -> Stream (Of Token) m a -> Stream (Of Tag) m a -contextualizing Blob{..} toKind = Streaming.mapMaybeM $ \case +contextualizing source toKind = Streaming.mapMaybeM $ \case Enter x r -> Nothing <$ enterScope (x, r) Exit x r -> Nothing <$ exitScope (x, r) Iden iden span docsLiteralRange -> get @[ContextToken] >>= pure . \case @@ -63,7 +63,7 @@ contextualizing Blob{..} toKind = Streaming.mapMaybeM $ \case -> Just $ Tag iden kind span (firstLine (slice r)) (slice <$> docsLiteralRange) _ -> Nothing where - slice = stripEnd . Source.toText . Source.slice blobSource + slice = stripEnd . Source.toText . Source.slice source firstLine = T.take 180 . fst . breakOn "\n" enterScope, exitScope :: ( Member (State [ContextToken]) sig From 937df795a1a8179f02b619135029357e9f0c1a5d Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 11:54:38 -0400 Subject: [PATCH 04/84] =?UTF-8?q?Don=E2=80=99t=20pass=20the=20blob=20into?= =?UTF-8?q?=20runTagging.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Semantic/Api/Symbols.hs | 4 ++-- src/Tags/Tagging.hs | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 31b3f6c3e..ef63c7f3e 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -44,7 +44,7 @@ legacyParseSymbols blobs = Legacy.ParseTreeSymbolResponse <$> distributeFoldMap symbolsToSummarize = ["Function", "Method", "Class", "Module"] renderToSymbols :: (IsTaggable f, Applicative m) => Term f Loc -> m [Legacy.File] - renderToSymbols = pure . pure . tagsToFile . runTagging blob symbolsToSummarize + renderToSymbols = pure . pure . tagsToFile . runTagging (blobLanguage blob) blobSource symbolsToSummarize tagsToFile :: [Tag] -> Legacy.File tagsToFile tags = Legacy.File (pack (blobPath blob)) (pack (show (blobLanguage blob))) (fmap tagToSymbol tags) @@ -79,7 +79,7 @@ parseSymbols blobs = do errorFile e = File blobPath' (bridging # blobLanguage') mempty (V.fromList [ParseError (T.pack e)]) blobOid renderToSymbols :: IsTaggable f => Term f Loc -> File - renderToSymbols term = tagsToFile (runTagging blob symbolsToSummarize term) + renderToSymbols term = tagsToFile (runTagging (blobLanguage blob) blobSource symbolsToSummarize term) renderPreciseToSymbols :: Py.Term Loc -> File renderPreciseToSymbols term = tagsToFile (Precise.tags blobSource term) diff --git a/src/Tags/Tagging.hs b/src/Tags/Tagging.hs index 17a9d8046..46a5de3ef 100644 --- a/src/Tags/Tagging.hs +++ b/src/Tags/Tagging.hs @@ -14,7 +14,7 @@ import Data.Text as T hiding (empty) import Streaming import qualified Streaming.Prelude as Streaming -import Data.Blob +import Data.Language import Data.Term import Source.Loc import qualified Source.Source as Source @@ -22,16 +22,17 @@ import Tags.Tag import Tags.Taggable runTagging :: (IsTaggable syntax) - => Blob + => Language + -> Source.Source -> [Text] -> Term syntax Loc -> [Tag] -runTagging blob symbolsToSummarize +runTagging lang source symbolsToSummarize = Eff.run . evalState @[ContextToken] [] . Streaming.toList_ - . contextualizing (blobSource blob) toKind - . tagging (blobLanguage blob) + . contextualizing source toKind + . tagging lang where toKind x = do guard (x `elem` symbolsToSummarize) From 1bc251183ed789e40da4611ae70bb80379cef68b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 11:57:00 -0400 Subject: [PATCH 05/84] Generalize renderPreciseToSymbols to any term with a ToTags instance. --- src/Semantic/Api/Symbols.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index ef63c7f3e..4f40863b8 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -17,7 +17,6 @@ import Data.Term import qualified Data.Text as T import qualified Data.Vector as V import Data.Text (pack) -import qualified Language.Python as Py import Parsing.Parser import Prologue import Semantic.Api.Bridge @@ -81,7 +80,7 @@ parseSymbols blobs = do renderToSymbols :: IsTaggable f => Term f Loc -> File renderToSymbols term = tagsToFile (runTagging (blobLanguage blob) blobSource symbolsToSummarize term) - renderPreciseToSymbols :: Py.Term Loc -> File + renderPreciseToSymbols :: Precise.ToTags t => t Loc -> File renderPreciseToSymbols term = tagsToFile (Precise.tags blobSource term) tagsToFile :: [Tag] -> File From 09f95d6cecb85b1d9c41dbdfb521fdb7f8049e63 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 11:58:04 -0400 Subject: [PATCH 06/84] =?UTF-8?q?Define=20a=20helper=20to=20provide=20a=20?= =?UTF-8?q?ToTags=20instance=20for=20=C3=A0=20la=20carte=20terms.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Semantic/Api/Symbols.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 4f40863b8..774526447 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -97,3 +97,9 @@ tagToSymbol Tag{..} = Symbol , span = converting #? span , docs = fmap Docstring docs } + + +data ALaCarteTerm syntax ann = ALaCarteTerm Language (Term syntax ann) + +instance IsTaggable syntax => Precise.ToTags (ALaCarteTerm syntax) where + tags source (ALaCarteTerm lang term) = runTagging lang source symbolsToSummarize term From a43e947104a9fa555c014a11386aa6e332c63f2f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 11:58:40 -0400 Subject: [PATCH 07/84] =?UTF-8?q?Render=20=C3=A0=20la=20carte=20terms=20to?= =?UTF-8?q?=20symbols=20via=20ToTags.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Semantic/Api/Symbols.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 774526447..0dbc25f89 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -78,7 +78,7 @@ parseSymbols blobs = do errorFile e = File blobPath' (bridging # blobLanguage') mempty (V.fromList [ParseError (T.pack e)]) blobOid renderToSymbols :: IsTaggable f => Term f Loc -> File - renderToSymbols term = tagsToFile (runTagging (blobLanguage blob) blobSource symbolsToSummarize term) + renderToSymbols term = tagsToFile (Precise.tags blobSource (ALaCarteTerm (blobLanguage blob) term)) renderPreciseToSymbols :: Precise.ToTags t => t Loc -> File renderPreciseToSymbols term = tagsToFile (Precise.tags blobSource term) From 44b0614c7d1ed313cd21a83f9edffdf0cc760f7f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 11:59:26 -0400 Subject: [PATCH 08/84] Define renderToSymbols using renderPreciseToSymbols. --- src/Semantic/Api/Symbols.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 0dbc25f89..3f9663614 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -78,7 +78,7 @@ parseSymbols blobs = do errorFile e = File blobPath' (bridging # blobLanguage') mempty (V.fromList [ParseError (T.pack e)]) blobOid renderToSymbols :: IsTaggable f => Term f Loc -> File - renderToSymbols term = tagsToFile (Precise.tags blobSource (ALaCarteTerm (blobLanguage blob) term)) + renderToSymbols term = renderPreciseToSymbols (ALaCarteTerm (blobLanguage blob) term) renderPreciseToSymbols :: Precise.ToTags t => t Loc -> File renderPreciseToSymbols term = tagsToFile (Precise.tags blobSource term) From 7259059b51f0428a02b98f87aeedf17a9f82a6bf Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:01:04 -0400 Subject: [PATCH 09/84] Combine the code paths. --- src/Semantic/Api/Symbols.hs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 3f9663614..e00f85ecd 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -69,19 +69,16 @@ parseSymbols blobs = do go modes blob@Blob{..} | Precise <- pythonMode modes , Python <- blobLanguage' - = catching $ renderPreciseToSymbols <$> parse precisePythonParser blob - | otherwise = catching $ withSomeTerm renderToSymbols <$> doParse blob + = catching $ renderToSymbols <$> parse precisePythonParser blob + | otherwise = catching $ withSomeTerm (renderToSymbols . ALaCarteTerm (blobLanguage blob)) <$> doParse blob where catching m = m `catchError` (\(SomeException e) -> pure $ errorFile (show e)) blobLanguage' = blobLanguage blob blobPath' = pack $ blobPath blob errorFile e = File blobPath' (bridging # blobLanguage') mempty (V.fromList [ParseError (T.pack e)]) blobOid - renderToSymbols :: IsTaggable f => Term f Loc -> File - renderToSymbols term = renderPreciseToSymbols (ALaCarteTerm (blobLanguage blob) term) - - renderPreciseToSymbols :: Precise.ToTags t => t Loc -> File - renderPreciseToSymbols term = tagsToFile (Precise.tags blobSource term) + renderToSymbols :: Precise.ToTags t => t Loc -> File + renderToSymbols term = tagsToFile (Precise.tags blobSource term) tagsToFile :: [Tag] -> File tagsToFile tags = File blobPath' (bridging # blobLanguage') (V.fromList (fmap tagToSymbol tags)) mempty blobOid From f092a3017cb21c36e829fd63ad5efd69135e3954 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:10:38 -0400 Subject: [PATCH 10/84] Parameterize ALaCarteTerm by the symbols to summarize. --- src/Semantic/Api/Symbols.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index e00f85ecd..7898a13fd 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -70,7 +70,7 @@ parseSymbols blobs = do | Precise <- pythonMode modes , Python <- blobLanguage' = catching $ renderToSymbols <$> parse precisePythonParser blob - | otherwise = catching $ withSomeTerm (renderToSymbols . ALaCarteTerm (blobLanguage blob)) <$> doParse blob + | otherwise = catching $ withSomeTerm (renderToSymbols . ALaCarteTerm (blobLanguage blob) symbolsToSummarize) <$> doParse blob where catching m = m `catchError` (\(SomeException e) -> pure $ errorFile (show e)) blobLanguage' = blobLanguage blob @@ -96,7 +96,7 @@ tagToSymbol Tag{..} = Symbol } -data ALaCarteTerm syntax ann = ALaCarteTerm Language (Term syntax ann) +data ALaCarteTerm syntax ann = ALaCarteTerm Language [Text] (Term syntax ann) instance IsTaggable syntax => Precise.ToTags (ALaCarteTerm syntax) where - tags source (ALaCarteTerm lang term) = runTagging lang source symbolsToSummarize term + tags source (ALaCarteTerm lang symbolsToSummarize term) = runTagging lang source symbolsToSummarize term From f9c20bc46207e9519f9549cae2210eecf36429bf Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:10:51 -0400 Subject: [PATCH 11/84] Use ToTags for the legacy tagging API as well. --- src/Semantic/Api/Symbols.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 7898a13fd..3817145fe 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -43,7 +43,7 @@ legacyParseSymbols blobs = Legacy.ParseTreeSymbolResponse <$> distributeFoldMap symbolsToSummarize = ["Function", "Method", "Class", "Module"] renderToSymbols :: (IsTaggable f, Applicative m) => Term f Loc -> m [Legacy.File] - renderToSymbols = pure . pure . tagsToFile . runTagging (blobLanguage blob) blobSource symbolsToSummarize + renderToSymbols = pure . pure . tagsToFile . Precise.tags blobSource . ALaCarteTerm (blobLanguage blob) symbolsToSummarize tagsToFile :: [Tag] -> Legacy.File tagsToFile tags = Legacy.File (pack (blobPath blob)) (pack (show (blobLanguage blob))) (fmap tagToSymbol tags) From 371e0c094529c5df35515b963df42d02f09c8965 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:11:52 -0400 Subject: [PATCH 12/84] renderToSymbols is pure. --- src/Semantic/Api/Symbols.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 3817145fe..439ff9d80 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -34,7 +34,7 @@ legacyParseSymbols :: (Member Distribute sig, ParseEffects sig m, Traversable t) legacyParseSymbols blobs = Legacy.ParseTreeSymbolResponse <$> distributeFoldMap go blobs where go :: ParseEffects sig m => Blob -> m [Legacy.File] - go blob@Blob{..} = (doParse blob >>= withSomeTerm renderToSymbols) `catchError` (\(SomeException _) -> pure (pure emptyFile)) + go blob@Blob{..} = (withSomeTerm renderToSymbols <$> doParse blob) `catchError` (\(SomeException _) -> pure (pure emptyFile)) where emptyFile = tagsToFile [] @@ -42,8 +42,8 @@ legacyParseSymbols blobs = Legacy.ParseTreeSymbolResponse <$> distributeFoldMap symbolsToSummarize :: [Text] symbolsToSummarize = ["Function", "Method", "Class", "Module"] - renderToSymbols :: (IsTaggable f, Applicative m) => Term f Loc -> m [Legacy.File] - renderToSymbols = pure . pure . tagsToFile . Precise.tags blobSource . ALaCarteTerm (blobLanguage blob) symbolsToSummarize + renderToSymbols :: IsTaggable f => Term f Loc -> [Legacy.File] + renderToSymbols = pure . tagsToFile . Precise.tags blobSource . ALaCarteTerm (blobLanguage blob) symbolsToSummarize tagsToFile :: [Tag] -> Legacy.File tagsToFile tags = Legacy.File (pack (blobPath blob)) (pack (show (blobLanguage blob))) (fmap tagToSymbol tags) From 11091cf2494a2fa5937b74022e092866dc90a7b7 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:14:40 -0400 Subject: [PATCH 13/84] Generalize renderToSymbols for legacy tagging. --- src/Semantic/Api/Symbols.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 439ff9d80..df11d86b3 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -34,7 +34,7 @@ legacyParseSymbols :: (Member Distribute sig, ParseEffects sig m, Traversable t) legacyParseSymbols blobs = Legacy.ParseTreeSymbolResponse <$> distributeFoldMap go blobs where go :: ParseEffects sig m => Blob -> m [Legacy.File] - go blob@Blob{..} = (withSomeTerm renderToSymbols <$> doParse blob) `catchError` (\(SomeException _) -> pure (pure emptyFile)) + go blob@Blob{..} = (withSomeTerm (renderToSymbols . ALaCarteTerm (blobLanguage blob) symbolsToSummarize) <$> doParse blob) `catchError` (\(SomeException _) -> pure (pure emptyFile)) where emptyFile = tagsToFile [] @@ -42,8 +42,8 @@ legacyParseSymbols blobs = Legacy.ParseTreeSymbolResponse <$> distributeFoldMap symbolsToSummarize :: [Text] symbolsToSummarize = ["Function", "Method", "Class", "Module"] - renderToSymbols :: IsTaggable f => Term f Loc -> [Legacy.File] - renderToSymbols = pure . tagsToFile . Precise.tags blobSource . ALaCarteTerm (blobLanguage blob) symbolsToSummarize + renderToSymbols :: Precise.ToTags t => t Loc -> [Legacy.File] + renderToSymbols = pure . tagsToFile . Precise.tags blobSource tagsToFile :: [Tag] -> Legacy.File tagsToFile tags = Legacy.File (pack (blobPath blob)) (pack (show (blobLanguage blob))) (fmap tagToSymbol tags) From 785d52314a16a95ffff9a95d475b2e4d85556a57 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:29:56 -0400 Subject: [PATCH 14/84] Copy in our own version of doParse & SomeTerm. --- src/Semantic/Api/Symbols.hs | 38 ++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index df11d86b3..73a47e67f 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE GADTs, TypeOperators, DerivingStrategies #-} +{-# LANGUAGE ConstraintKinds, GADTs, RankNTypes, TypeOperators #-} module Semantic.Api.Symbols ( legacyParseSymbols , parseSymbols @@ -17,14 +17,14 @@ import Data.Term import qualified Data.Text as T import qualified Data.Vector as V import Data.Text (pack) -import Parsing.Parser +import qualified Parsing.Parser as Parser import Prologue import Semantic.Api.Bridge import qualified Semantic.Api.LegacyTypes as Legacy -import Semantic.Api.Terms (ParseEffects, doParse) import Semantic.Proto.SemanticPB hiding (Blob) +import Semantic.Config import Semantic.Task -import Serializing.Format +import Serializing.Format (Format) import Source.Loc import Tags.Taggable import Tags.Tagging @@ -34,7 +34,7 @@ legacyParseSymbols :: (Member Distribute sig, ParseEffects sig m, Traversable t) legacyParseSymbols blobs = Legacy.ParseTreeSymbolResponse <$> distributeFoldMap go blobs where go :: ParseEffects sig m => Blob -> m [Legacy.File] - go blob@Blob{..} = (withSomeTerm (renderToSymbols . ALaCarteTerm (blobLanguage blob) symbolsToSummarize) <$> doParse blob) `catchError` (\(SomeException _) -> pure (pure emptyFile)) + go blob@Blob{..} = (withSomeTerm renderToSymbols <$> doParse symbolsToSummarize blob) `catchError` (\(SomeException _) -> pure (pure emptyFile)) where emptyFile = tagsToFile [] @@ -69,8 +69,8 @@ parseSymbols blobs = do go modes blob@Blob{..} | Precise <- pythonMode modes , Python <- blobLanguage' - = catching $ renderToSymbols <$> parse precisePythonParser blob - | otherwise = catching $ withSomeTerm (renderToSymbols . ALaCarteTerm (blobLanguage blob) symbolsToSummarize) <$> doParse blob + = catching $ renderToSymbols <$> parse Parser.precisePythonParser blob + | otherwise = catching $ withSomeTerm renderToSymbols <$> doParse symbolsToSummarize blob where catching m = m `catchError` (\(SomeException e) -> pure $ errorFile (show e)) blobLanguage' = blobLanguage blob @@ -100,3 +100,27 @@ data ALaCarteTerm syntax ann = ALaCarteTerm Language [Text] (Term syntax ann) instance IsTaggable syntax => Precise.ToTags (ALaCarteTerm syntax) where tags source (ALaCarteTerm lang symbolsToSummarize term) = runTagging lang source symbolsToSummarize term + + +data SomeTerm c ann where + SomeTerm :: c t => t ann -> SomeTerm c ann + +withSomeTerm :: (forall t . c t => t ann -> a) -> SomeTerm c ann -> a +withSomeTerm with (SomeTerm term) = with term + +doParse :: ParseEffects sig m => [Text] -> Blob -> m (SomeTerm Precise.ToTags Loc) +doParse symbolsToSummarize blob = case blobLanguage blob of + Go -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.goParser blob + Haskell -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.haskellParser blob + JavaScript -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob + JSON -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.jsonParser blob + JSX -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob + Markdown -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.markdownParser blob + Python -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.pythonParser blob + Ruby -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.rubyParser blob + TypeScript -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.typescriptParser blob + TSX -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob + PHP -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.phpParser blob + _ -> noLanguageForBlob (blobPath blob) + +type ParseEffects sig m = (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Member (Reader Config) sig, Carrier sig m) From 152e94a844e687fdb48daf0d2ba6961ab2e07cf5 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:32:13 -0400 Subject: [PATCH 15/84] doParse handles the PerLanguageModes. --- src/Semantic/Api/Symbols.hs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 73a47e67f..52b029f02 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -109,18 +109,22 @@ withSomeTerm :: (forall t . c t => t ann -> a) -> SomeTerm c ann -> a withSomeTerm with (SomeTerm term) = with term doParse :: ParseEffects sig m => [Text] -> Blob -> m (SomeTerm Precise.ToTags Loc) -doParse symbolsToSummarize blob = case blobLanguage blob of - Go -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.goParser blob - Haskell -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.haskellParser blob - JavaScript -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob - JSON -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.jsonParser blob - JSX -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob - Markdown -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.markdownParser blob - Python -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.pythonParser blob - Ruby -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.rubyParser blob - TypeScript -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.typescriptParser blob - TSX -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob - PHP -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.phpParser blob - _ -> noLanguageForBlob (blobPath blob) +doParse symbolsToSummarize blob = do + modes <- ask @PerLanguageModes + case blobLanguage blob of + Go -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.goParser blob + Haskell -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.haskellParser blob + JavaScript -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob + JSON -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.jsonParser blob + JSX -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob + Markdown -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.markdownParser blob + Python + | Precise <- pythonMode modes -> SomeTerm <$> parse Parser.precisePythonParser blob + | otherwise -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.pythonParser blob + Ruby -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.rubyParser blob + TypeScript -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.typescriptParser blob + TSX -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob + PHP -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.phpParser blob + _ -> noLanguageForBlob (blobPath blob) type ParseEffects sig m = (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Member (Reader Config) sig, Carrier sig m) From 0f8da488b05c00cbe1cb36d02369db9d1c99d821 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:33:26 -0400 Subject: [PATCH 16/84] =?UTF-8?q?Don=E2=80=99t=20specialize=20parseSymbols?= =?UTF-8?q?=20for=20the=20PerLanguageModes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Semantic/Api/Symbols.hs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 52b029f02..ea5e5b9ee 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -61,16 +61,10 @@ parseSymbolsBuilder :: (Member Distribute sig, ParseEffects sig m, Traversable t parseSymbolsBuilder format blobs = parseSymbols blobs >>= serialize format parseSymbols :: (Member Distribute sig, ParseEffects sig m, Traversable t) => t Blob -> m ParseTreeSymbolResponse -parseSymbols blobs = do - modes <- ask - ParseTreeSymbolResponse . V.fromList . toList <$> distributeFor blobs (go modes) +parseSymbols blobs = ParseTreeSymbolResponse . V.fromList . toList <$> distributeFor blobs go where - go :: ParseEffects sig m => PerLanguageModes -> Blob -> m File - go modes blob@Blob{..} - | Precise <- pythonMode modes - , Python <- blobLanguage' - = catching $ renderToSymbols <$> parse Parser.precisePythonParser blob - | otherwise = catching $ withSomeTerm renderToSymbols <$> doParse symbolsToSummarize blob + go :: ParseEffects sig m => Blob -> m File + go blob@Blob{..} = catching $ withSomeTerm renderToSymbols <$> doParse symbolsToSummarize blob where catching m = m `catchError` (\(SomeException e) -> pure $ errorFile (show e)) blobLanguage' = blobLanguage blob From 598dce7fc80923419b2b98119c9ba44594c55709 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:35:06 -0400 Subject: [PATCH 17/84] :fire: ParseEffects. --- src/Semantic/Api/Symbols.hs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index ea5e5b9ee..697f461ea 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -30,10 +30,10 @@ import Tags.Taggable import Tags.Tagging import qualified Tags.Tagging.Precise as Precise -legacyParseSymbols :: (Member Distribute sig, ParseEffects sig m, Traversable t) => t Blob -> m Legacy.ParseTreeSymbolResponse +legacyParseSymbols :: (Member Distribute sig, Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Carrier sig m, Traversable t) => t Blob -> m Legacy.ParseTreeSymbolResponse legacyParseSymbols blobs = Legacy.ParseTreeSymbolResponse <$> distributeFoldMap go blobs where - go :: ParseEffects sig m => Blob -> m [Legacy.File] + go :: (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Carrier sig m) => Blob -> m [Legacy.File] go blob@Blob{..} = (withSomeTerm renderToSymbols <$> doParse symbolsToSummarize blob) `catchError` (\(SomeException _) -> pure (pure emptyFile)) where emptyFile = tagsToFile [] @@ -57,13 +57,13 @@ legacyParseSymbols blobs = Legacy.ParseTreeSymbolResponse <$> distributeFoldMap , symbolSpan = converting #? span } -parseSymbolsBuilder :: (Member Distribute sig, ParseEffects sig m, Traversable t) => Format ParseTreeSymbolResponse -> t Blob -> m Builder +parseSymbolsBuilder :: (Member Distribute sig, Member (Error SomeException) sig, Member Parse sig, Member (Reader Config) sig, Member (Reader PerLanguageModes) sig, Carrier sig m, Traversable t) => Format ParseTreeSymbolResponse -> t Blob -> m Builder parseSymbolsBuilder format blobs = parseSymbols blobs >>= serialize format -parseSymbols :: (Member Distribute sig, ParseEffects sig m, Traversable t) => t Blob -> m ParseTreeSymbolResponse +parseSymbols :: (Member Distribute sig, Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Carrier sig m, Traversable t) => t Blob -> m ParseTreeSymbolResponse parseSymbols blobs = ParseTreeSymbolResponse . V.fromList . toList <$> distributeFor blobs go where - go :: ParseEffects sig m => Blob -> m File + go :: (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Carrier sig m) => Blob -> m File go blob@Blob{..} = catching $ withSomeTerm renderToSymbols <$> doParse symbolsToSummarize blob where catching m = m `catchError` (\(SomeException e) -> pure $ errorFile (show e)) @@ -102,7 +102,7 @@ data SomeTerm c ann where withSomeTerm :: (forall t . c t => t ann -> a) -> SomeTerm c ann -> a withSomeTerm with (SomeTerm term) = with term -doParse :: ParseEffects sig m => [Text] -> Blob -> m (SomeTerm Precise.ToTags Loc) +doParse :: (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Carrier sig m) => [Text] -> Blob -> m (SomeTerm Precise.ToTags Loc) doParse symbolsToSummarize blob = do modes <- ask @PerLanguageModes case blobLanguage blob of @@ -120,5 +120,3 @@ doParse symbolsToSummarize blob = do TSX -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob PHP -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.phpParser blob _ -> noLanguageForBlob (blobPath blob) - -type ParseEffects sig m = (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Member (Reader Config) sig, Carrier sig m) From 05e0086c82cb1b7fe74ed752e80ed9fd32e2c3a4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:38:59 -0400 Subject: [PATCH 18/84] Factor out the term construction. --- src/Semantic/Api/Symbols.hs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 697f461ea..e061dd964 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -106,17 +106,19 @@ doParse :: (Member (Error SomeException) sig, Member (Reader PerLanguageModes) s doParse symbolsToSummarize blob = do modes <- ask @PerLanguageModes case blobLanguage blob of - Go -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.goParser blob - Haskell -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.haskellParser blob - JavaScript -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob - JSON -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.jsonParser blob - JSX -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob - Markdown -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.markdownParser blob + Go -> mkTerm <$> parse Parser.goParser blob + Haskell -> mkTerm <$> parse Parser.haskellParser blob + JavaScript -> mkTerm <$> parse Parser.tsxParser blob + JSON -> mkTerm <$> parse Parser.jsonParser blob + JSX -> mkTerm <$> parse Parser.tsxParser blob + Markdown -> mkTerm <$> parse Parser.markdownParser blob Python | Precise <- pythonMode modes -> SomeTerm <$> parse Parser.precisePythonParser blob - | otherwise -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.pythonParser blob - Ruby -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.rubyParser blob - TypeScript -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.typescriptParser blob - TSX -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.tsxParser blob - PHP -> SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize <$> parse Parser.phpParser blob + | otherwise -> mkTerm <$> parse Parser.pythonParser blob + Ruby -> mkTerm <$> parse Parser.rubyParser blob + TypeScript -> mkTerm <$> parse Parser.typescriptParser blob + TSX -> mkTerm <$> parse Parser.tsxParser blob + PHP -> mkTerm <$> parse Parser.phpParser blob _ -> noLanguageForBlob (blobPath blob) + where mkTerm :: IsTaggable syntax => Term syntax Loc -> SomeTerm Precise.ToTags Loc + mkTerm = SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize From 5de3d14bcc07b4d54a1c333ca5d890da55e4e376 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:39:55 -0400 Subject: [PATCH 19/84] :fire: the HasTextElement & Taggable obligations from TermConstraints. --- src/Semantic/Api/Terms.hs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 30cfa3fae..456d30e03 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -44,7 +44,6 @@ import Semantic.Task import Serializing.Format hiding (JSON) import qualified Serializing.Format as Format import Source.Loc -import Tags.Taggable termGraph :: (Traversable t, Member Distribute sig, ParseEffects sig m) => t Blob -> m ParseTreeGraphResponse termGraph blobs = ParseTreeGraphResponse . V.fromList . toList <$> distributeFor blobs go @@ -107,10 +106,8 @@ quietTerm blob = showTiming blob <$> time' ( (doParse blob >>= withSomeTerm (fma type ParseEffects sig m = (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Member (Reader Config) sig, Carrier sig m) type TermConstraints = - '[ Taggable - , Declarations1 + '[ Declarations1 , ConstructorName - , HasTextElement , Show1 , ToJSONFields1 , Traversable From a97e42a19e8e77f924def35679ac6f7b4219da48 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:42:56 -0400 Subject: [PATCH 20/84] Simplify the Traversable obligation down to just Foldable/Functor. --- src/Semantic/Api/Terms.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 456d30e03..24ab0cb0f 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -108,9 +108,10 @@ type ParseEffects sig m = (Member (Error SomeException) sig, Member (Reader PerL type TermConstraints = '[ Declarations1 , ConstructorName + , Foldable + , Functor , Show1 , ToJSONFields1 - , Traversable ] doParse :: (ParseEffects sig m) => Blob -> m (SomeTerm TermConstraints Loc) From 5c6df1678243ef4480de5c6d40b4c2107eb86c97 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:45:01 -0400 Subject: [PATCH 21/84] Move SomeTerm/withSomeTerm into Semantic.Api.Terms. --- src/Parsing/Parser.hs | 8 -------- src/Semantic/Api/Terms.hs | 9 ++++++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Parsing/Parser.hs b/src/Parsing/Parser.hs index ae65e4dbb..3443805fd 100644 --- a/src/Parsing/Parser.hs +++ b/src/Parsing/Parser.hs @@ -1,8 +1,6 @@ {-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, GADTs, RankNTypes, ScopedTypeVariables, TypeFamilies, TypeOperators #-} module Parsing.Parser ( Parser(..) -, SomeTerm(..) -, withSomeTerm , SomeAnalysisParser(..) , SomeASTParser(..) , someASTParser @@ -167,12 +165,6 @@ precisePythonParser :: Parser (Py.Term Loc) precisePythonParser = UnmarshalParser tree_sitter_python -data SomeTerm typeclasses ann where - SomeTerm :: ApplyAll typeclasses syntax => Term syntax ann -> SomeTerm typeclasses ann - -withSomeTerm :: (forall syntax . ApplyAll typeclasses syntax => Term syntax ann -> a) -> SomeTerm typeclasses ann -> a -withSomeTerm with (SomeTerm term) = with term - -- | A parser for producing specialized (tree-sitter) ASTs. data SomeASTParser where SomeASTParser :: (Bounded grammar, Enum grammar, Show grammar) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 24ab0cb0f..f904ecd8a 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE ConstraintKinds, GADTs, TypeOperators, DerivingStrategies #-} +{-# LANGUAGE ConstraintKinds, GADTs, RankNTypes, TypeOperators #-} module Semantic.Api.Terms ( termGraph @@ -128,3 +128,10 @@ doParse blob = case blobLanguage blob of TSX -> SomeTerm <$> parse tsxParser blob PHP -> SomeTerm <$> parse phpParser blob _ -> noLanguageForBlob (blobPath blob) + + +data SomeTerm typeclasses ann where + SomeTerm :: ApplyAll typeclasses syntax => Term syntax ann -> SomeTerm typeclasses ann + +withSomeTerm :: (forall syntax . ApplyAll typeclasses syntax => Term syntax ann -> a) -> SomeTerm typeclasses ann -> a +withSomeTerm with (SomeTerm term) = with term From cca474b0e9ae441f22a8a733e526814dbc9606a5 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:46:43 -0400 Subject: [PATCH 22/84] :fire: the Declarations1 obligation. --- src/Semantic/Api/Terms.hs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index f904ecd8a..a28f90b57 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -21,7 +21,6 @@ import Control.Effect.Reader import Control.Lens import Control.Monad import Control.Monad.IO.Class -import Data.Abstract.Declarations import Data.Blob import Data.ByteString.Builder import Data.Either @@ -106,8 +105,7 @@ quietTerm blob = showTiming blob <$> time' ( (doParse blob >>= withSomeTerm (fma type ParseEffects sig m = (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Member (Reader Config) sig, Carrier sig m) type TermConstraints = - '[ Declarations1 - , ConstructorName + '[ ConstructorName , Foldable , Functor , Show1 From 7aaaa6433c80f11ce3b5d2d56a484730f0aef5ee Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:47:40 -0400 Subject: [PATCH 23/84] :fire: redundant parens. --- src/Semantic/Api/Terms.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index a28f90b57..6d6089b38 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -78,19 +78,19 @@ parseTermBuilder TermDotGraph = distributeFoldMap dotGraphTerm parseTermBuilder TermShow = distributeFoldMap showTerm parseTermBuilder TermQuiet = distributeFoldMap quietTerm -jsonTerm :: (ParseEffects sig m) => Blob -> m (Rendering.JSON.JSON "trees" SomeJSON) +jsonTerm :: ParseEffects sig m => Blob -> m (Rendering.JSON.JSON "trees" SomeJSON) jsonTerm blob = (doParse blob >>= withSomeTerm (pure . renderJSONTerm blob)) `catchError` jsonError blob jsonError :: Applicative m => Blob -> SomeException -> m (Rendering.JSON.JSON "trees" SomeJSON) jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) -sexpTerm :: (ParseEffects sig m) => Blob -> m Builder +sexpTerm :: ParseEffects sig m => Blob -> m Builder sexpTerm = doParse >=> withSomeTerm (serialize (SExpression ByConstructorName)) -dotGraphTerm :: (ParseEffects sig m) => Blob -> m Builder +dotGraphTerm :: ParseEffects sig m => Blob -> m Builder dotGraphTerm = doParse >=> withSomeTerm (serialize (DOT (termStyle "terms")) . renderTreeGraph) -showTerm :: (ParseEffects sig m) => Blob -> m Builder +showTerm :: ParseEffects sig m => Blob -> m Builder showTerm = doParse >=> withSomeTerm (serialize Show . quieterm) quietTerm :: (ParseEffects sig m, MonadIO m) => Blob -> m Builder @@ -112,7 +112,7 @@ type TermConstraints = , ToJSONFields1 ] -doParse :: (ParseEffects sig m) => Blob -> m (SomeTerm TermConstraints Loc) +doParse :: ParseEffects sig m => Blob -> m (SomeTerm TermConstraints Loc) doParse blob = case blobLanguage blob of Go -> SomeTerm <$> parse goParser blob Haskell -> SomeTerm <$> parse haskellParser blob From 02f46c650dbffd3bd093a861f9deabd9ed72add8 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:52:42 -0400 Subject: [PATCH 24/84] Define TermConstraints as a class. --- src/Semantic/Api/Terms.hs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 6d6089b38..0537481b0 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE ConstraintKinds, GADTs, RankNTypes, TypeOperators #-} +{-# LANGUAGE ConstraintKinds, GADTs, RankNTypes, TypeOperators, UndecidableInstances #-} module Semantic.Api.Terms ( termGraph @@ -104,13 +104,21 @@ quietTerm blob = showTiming blob <$> time' ( (doParse blob >>= withSomeTerm (fma type ParseEffects sig m = (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Member (Reader Config) sig, Carrier sig m) -type TermConstraints = - '[ ConstructorName - , Foldable - , Functor - , Show1 - , ToJSONFields1 - ] +class ( ConstructorName t + , Foldable t + , Functor t + , Show1 t + , ToJSONFields1 t + ) + => TermConstraints t + +instance ( ConstructorName t + , Foldable t + , Functor t + , Show1 t + , ToJSONFields1 t + ) + => TermConstraints t doParse :: ParseEffects sig m => Blob -> m (SomeTerm TermConstraints Loc) doParse blob = case blobLanguage blob of @@ -129,7 +137,7 @@ doParse blob = case blobLanguage blob of data SomeTerm typeclasses ann where - SomeTerm :: ApplyAll typeclasses syntax => Term syntax ann -> SomeTerm typeclasses ann + SomeTerm :: typeclasses syntax => Term syntax ann -> SomeTerm typeclasses ann -withSomeTerm :: (forall syntax . ApplyAll typeclasses syntax => Term syntax ann -> a) -> SomeTerm typeclasses ann -> a +withSomeTerm :: (forall syntax . typeclasses syntax => Term syntax ann -> a) -> SomeTerm typeclasses ann -> a withSomeTerm with (SomeTerm term) = with term From 13e3788422030b1a7226c28f00075230e75dfda2 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 12:53:47 -0400 Subject: [PATCH 25/84] Reformat the signature for doParse. --- src/Semantic/Api/Terms.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 0537481b0..cd7c72e1b 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -120,7 +120,13 @@ instance ( ConstructorName t ) => TermConstraints t -doParse :: ParseEffects sig m => Blob -> m (SomeTerm TermConstraints Loc) +doParse + :: ( Carrier sig m + , Member (Error SomeException) sig + , Member Parse sig + ) + => Blob + -> m (SomeTerm TermConstraints Loc) doParse blob = case blobLanguage blob of Go -> SomeTerm <$> parse goParser blob Haskell -> SomeTerm <$> parse haskellParser blob From 5e1b21c7736f1e6b0aa2d33bffc9b0a379fd9f5a Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 13:00:38 -0400 Subject: [PATCH 26/84] Export ToSExpression. --- src/Serializing/SExpression/Precise.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Serializing/SExpression/Precise.hs b/src/Serializing/SExpression/Precise.hs index f1807042d..a0b0ef098 100644 --- a/src/Serializing/SExpression/Precise.hs +++ b/src/Serializing/SExpression/Precise.hs @@ -1,6 +1,7 @@ {-# LANGUAGE DataKinds, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, OverloadedStrings, ScopedTypeVariables, TypeApplications, TypeFamilies, TypeOperators, UndecidableInstances #-} module Serializing.SExpression.Precise ( serializeSExpression +, ToSExpression(..) ) where import Data.ByteString.Builder From 710173303e5174e9a19eeff2cd956a656365196a Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 14:54:49 -0400 Subject: [PATCH 27/84] Reformat the doParse signature. --- src/Semantic/Api/Symbols.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index e061dd964..eabe5c6ed 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -102,7 +102,15 @@ data SomeTerm c ann where withSomeTerm :: (forall t . c t => t ann -> a) -> SomeTerm c ann -> a withSomeTerm with (SomeTerm term) = with term -doParse :: (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Carrier sig m) => [Text] -> Blob -> m (SomeTerm Precise.ToTags Loc) +doParse + :: ( Carrier sig m + , Member (Error SomeException) sig + , Member Parse sig + , Member (Reader PerLanguageModes) sig + ) + => [Text] + -> Blob + -> m (SomeTerm Precise.ToTags Loc) doParse symbolsToSummarize blob = do modes <- ask @PerLanguageModes case blobLanguage blob of From a060a15d4314a831e3544ea30fc632a3cc2fc8f8 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 14:56:36 -0400 Subject: [PATCH 28/84] Align all the blobs. --- src/Semantic/Api/Symbols.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index eabe5c6ed..7f17f4c4b 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -114,19 +114,19 @@ doParse doParse symbolsToSummarize blob = do modes <- ask @PerLanguageModes case blobLanguage blob of - Go -> mkTerm <$> parse Parser.goParser blob - Haskell -> mkTerm <$> parse Parser.haskellParser blob - JavaScript -> mkTerm <$> parse Parser.tsxParser blob - JSON -> mkTerm <$> parse Parser.jsonParser blob - JSX -> mkTerm <$> parse Parser.tsxParser blob - Markdown -> mkTerm <$> parse Parser.markdownParser blob + Go -> mkTerm <$> parse Parser.goParser blob + Haskell -> mkTerm <$> parse Parser.haskellParser blob + JavaScript -> mkTerm <$> parse Parser.tsxParser blob + JSON -> mkTerm <$> parse Parser.jsonParser blob + JSX -> mkTerm <$> parse Parser.tsxParser blob + Markdown -> mkTerm <$> parse Parser.markdownParser blob Python | Precise <- pythonMode modes -> SomeTerm <$> parse Parser.precisePythonParser blob | otherwise -> mkTerm <$> parse Parser.pythonParser blob - Ruby -> mkTerm <$> parse Parser.rubyParser blob + Ruby -> mkTerm <$> parse Parser.rubyParser blob TypeScript -> mkTerm <$> parse Parser.typescriptParser blob - TSX -> mkTerm <$> parse Parser.tsxParser blob - PHP -> mkTerm <$> parse Parser.phpParser blob + TSX -> mkTerm <$> parse Parser.tsxParser blob + PHP -> mkTerm <$> parse Parser.phpParser blob _ -> noLanguageForBlob (blobPath blob) where mkTerm :: IsTaggable syntax => Term syntax Loc -> SomeTerm Precise.ToTags Loc mkTerm = SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize From 6f5e2ff8e4313972c31955356f6aa703fa5e9231 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:00:33 -0400 Subject: [PATCH 29/84] Eliminate the term directly in doParse. --- src/Semantic/Api/Symbols.hs | 47 +++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 7f17f4c4b..921d8fcd2 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE ConstraintKinds, GADTs, RankNTypes, TypeOperators #-} +{-# LANGUAGE ConstraintKinds, MonoLocalBinds, RankNTypes, TypeOperators #-} module Semantic.Api.Symbols ( legacyParseSymbols , parseSymbols @@ -34,7 +34,7 @@ legacyParseSymbols :: (Member Distribute sig, Member (Error SomeException) sig, legacyParseSymbols blobs = Legacy.ParseTreeSymbolResponse <$> distributeFoldMap go blobs where go :: (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Carrier sig m) => Blob -> m [Legacy.File] - go blob@Blob{..} = (withSomeTerm renderToSymbols <$> doParse symbolsToSummarize blob) `catchError` (\(SomeException _) -> pure (pure emptyFile)) + go blob@Blob{..} = doParse (pure . renderToSymbols) symbolsToSummarize blob `catchError` (\(SomeException _) -> pure (pure emptyFile)) where emptyFile = tagsToFile [] @@ -64,7 +64,7 @@ parseSymbols :: (Member Distribute sig, Member (Error SomeException) sig, Member parseSymbols blobs = ParseTreeSymbolResponse . V.fromList . toList <$> distributeFor blobs go where go :: (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Carrier sig m) => Blob -> m File - go blob@Blob{..} = catching $ withSomeTerm renderToSymbols <$> doParse symbolsToSummarize blob + go blob@Blob{..} = catching $ doParse (pure . renderToSymbols) symbolsToSummarize blob where catching m = m `catchError` (\(SomeException e) -> pure $ errorFile (show e)) blobLanguage' = blobLanguage blob @@ -96,37 +96,32 @@ instance IsTaggable syntax => Precise.ToTags (ALaCarteTerm syntax) where tags source (ALaCarteTerm lang symbolsToSummarize term) = runTagging lang source symbolsToSummarize term -data SomeTerm c ann where - SomeTerm :: c t => t ann -> SomeTerm c ann - -withSomeTerm :: (forall t . c t => t ann -> a) -> SomeTerm c ann -> a -withSomeTerm with (SomeTerm term) = with term - doParse :: ( Carrier sig m , Member (Error SomeException) sig , Member Parse sig , Member (Reader PerLanguageModes) sig ) - => [Text] + => (forall t . Precise.ToTags t => t Loc -> m a) + -> [Text] -> Blob - -> m (SomeTerm Precise.ToTags Loc) -doParse symbolsToSummarize blob = do + -> m a +doParse with symbolsToSummarize blob = do modes <- ask @PerLanguageModes case blobLanguage blob of - Go -> mkTerm <$> parse Parser.goParser blob - Haskell -> mkTerm <$> parse Parser.haskellParser blob - JavaScript -> mkTerm <$> parse Parser.tsxParser blob - JSON -> mkTerm <$> parse Parser.jsonParser blob - JSX -> mkTerm <$> parse Parser.tsxParser blob - Markdown -> mkTerm <$> parse Parser.markdownParser blob + Go -> parse Parser.goParser blob >>= with . mkTerm + Haskell -> parse Parser.haskellParser blob >>= with . mkTerm + JavaScript -> parse Parser.tsxParser blob >>= with . mkTerm + JSON -> parse Parser.jsonParser blob >>= with . mkTerm + JSX -> parse Parser.tsxParser blob >>= with . mkTerm + Markdown -> parse Parser.markdownParser blob >>= with . mkTerm Python - | Precise <- pythonMode modes -> SomeTerm <$> parse Parser.precisePythonParser blob - | otherwise -> mkTerm <$> parse Parser.pythonParser blob - Ruby -> mkTerm <$> parse Parser.rubyParser blob - TypeScript -> mkTerm <$> parse Parser.typescriptParser blob - TSX -> mkTerm <$> parse Parser.tsxParser blob - PHP -> mkTerm <$> parse Parser.phpParser blob + | Precise <- pythonMode modes -> parse Parser.precisePythonParser blob >>= with + | otherwise -> parse Parser.pythonParser blob >>= with . mkTerm + Ruby -> parse Parser.rubyParser blob >>= with . mkTerm + TypeScript -> parse Parser.typescriptParser blob >>= with . mkTerm + TSX -> parse Parser.tsxParser blob >>= with . mkTerm + PHP -> parse Parser.phpParser blob >>= with . mkTerm _ -> noLanguageForBlob (blobPath blob) - where mkTerm :: IsTaggable syntax => Term syntax Loc -> SomeTerm Precise.ToTags Loc - mkTerm = SomeTerm . ALaCarteTerm (blobLanguage blob) symbolsToSummarize + where mkTerm :: Term syntax Loc -> ALaCarteTerm syntax Loc + mkTerm = ALaCarteTerm (blobLanguage blob) symbolsToSummarize From 19ac4d2c9ac403c1fffeba67cb55feb12e1ecbee Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:02:09 -0400 Subject: [PATCH 30/84] Align the blobs. --- src/Semantic/Api/Terms.hs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index cd7c72e1b..b812817d7 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -128,17 +128,17 @@ doParse => Blob -> m (SomeTerm TermConstraints Loc) doParse blob = case blobLanguage blob of - Go -> SomeTerm <$> parse goParser blob - Haskell -> SomeTerm <$> parse haskellParser blob - JavaScript -> SomeTerm <$> parse tsxParser blob - JSON -> SomeTerm <$> parse jsonParser blob - JSX -> SomeTerm <$> parse tsxParser blob - Markdown -> SomeTerm <$> parse markdownParser blob - Python -> SomeTerm <$> parse pythonParser blob - Ruby -> SomeTerm <$> parse rubyParser blob + Go -> SomeTerm <$> parse goParser blob + Haskell -> SomeTerm <$> parse haskellParser blob + JavaScript -> SomeTerm <$> parse tsxParser blob + JSON -> SomeTerm <$> parse jsonParser blob + JSX -> SomeTerm <$> parse tsxParser blob + Markdown -> SomeTerm <$> parse markdownParser blob + Python -> SomeTerm <$> parse pythonParser blob + Ruby -> SomeTerm <$> parse rubyParser blob TypeScript -> SomeTerm <$> parse typescriptParser blob - TSX -> SomeTerm <$> parse tsxParser blob - PHP -> SomeTerm <$> parse phpParser blob + TSX -> SomeTerm <$> parse tsxParser blob + PHP -> SomeTerm <$> parse phpParser blob _ -> noLanguageForBlob (blobPath blob) From e727b3c81be1d36450dac871986ac567602ffdaf Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:05:19 -0400 Subject: [PATCH 31/84] Eliminate the terms directly in doParse. --- src/Semantic/Api/Terms.hs | 52 +++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index b812817d7..9f1323dcf 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE ConstraintKinds, GADTs, RankNTypes, TypeOperators, UndecidableInstances #-} +{-# LANGUAGE ConstraintKinds, MonoLocalBinds, RankNTypes, TypeOperators, UndecidableInstances #-} module Semantic.Api.Terms ( termGraph @@ -9,8 +9,6 @@ module Semantic.Api.Terms , ParseEffects , TermConstraints - , SomeTerm(..) - , withSomeTerm ) where @@ -48,7 +46,7 @@ termGraph :: (Traversable t, Member Distribute sig, ParseEffects sig m) => t Blo termGraph blobs = ParseTreeGraphResponse . V.fromList . toList <$> distributeFor blobs go where go :: ParseEffects sig m => Blob -> m ParseTreeFileGraph - go blob = (doParse blob >>= withSomeTerm (pure . render)) + go blob = doParse (pure . render) blob `catchError` \(SomeException e) -> pure (ParseTreeFileGraph path lang mempty mempty (V.fromList [ParseError (T.pack (show e))])) where @@ -79,22 +77,22 @@ parseTermBuilder TermShow = distributeFoldMap showTerm parseTermBuilder TermQuiet = distributeFoldMap quietTerm jsonTerm :: ParseEffects sig m => Blob -> m (Rendering.JSON.JSON "trees" SomeJSON) -jsonTerm blob = (doParse blob >>= withSomeTerm (pure . renderJSONTerm blob)) `catchError` jsonError blob +jsonTerm blob = doParse (pure . renderJSONTerm blob) blob `catchError` jsonError blob jsonError :: Applicative m => Blob -> SomeException -> m (Rendering.JSON.JSON "trees" SomeJSON) jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) sexpTerm :: ParseEffects sig m => Blob -> m Builder -sexpTerm = doParse >=> withSomeTerm (serialize (SExpression ByConstructorName)) +sexpTerm = doParse (serialize (SExpression ByConstructorName)) dotGraphTerm :: ParseEffects sig m => Blob -> m Builder -dotGraphTerm = doParse >=> withSomeTerm (serialize (DOT (termStyle "terms")) . renderTreeGraph) +dotGraphTerm = doParse (serialize (DOT (termStyle "terms")) . renderTreeGraph) showTerm :: ParseEffects sig m => Blob -> m Builder -showTerm = doParse >=> withSomeTerm (serialize Show . quieterm) +showTerm = doParse (serialize Show . quieterm) quietTerm :: (ParseEffects sig m, MonadIO m) => Blob -> m Builder -quietTerm blob = showTiming blob <$> time' ( (doParse blob >>= withSomeTerm (fmap (const (Right ())) . serialize Show . quieterm)) `catchError` timingError ) +quietTerm blob = showTiming blob <$> time' ( doParse (fmap (const (Right ())) . serialize Show . quieterm) blob `catchError` timingError ) where timingError (SomeException e) = pure (Left (show e)) showTiming Blob{..} (res, duration) = @@ -125,25 +123,19 @@ doParse , Member (Error SomeException) sig , Member Parse sig ) - => Blob - -> m (SomeTerm TermConstraints Loc) -doParse blob = case blobLanguage blob of - Go -> SomeTerm <$> parse goParser blob - Haskell -> SomeTerm <$> parse haskellParser blob - JavaScript -> SomeTerm <$> parse tsxParser blob - JSON -> SomeTerm <$> parse jsonParser blob - JSX -> SomeTerm <$> parse tsxParser blob - Markdown -> SomeTerm <$> parse markdownParser blob - Python -> SomeTerm <$> parse pythonParser blob - Ruby -> SomeTerm <$> parse rubyParser blob - TypeScript -> SomeTerm <$> parse typescriptParser blob - TSX -> SomeTerm <$> parse tsxParser blob - PHP -> SomeTerm <$> parse phpParser blob + => (forall syntax . TermConstraints syntax => Term syntax Loc -> m a) + -> Blob + -> m a +doParse with blob = case blobLanguage blob of + Go -> parse goParser blob >>= with + Haskell -> parse haskellParser blob >>= with + JavaScript -> parse tsxParser blob >>= with + JSON -> parse jsonParser blob >>= with + JSX -> parse tsxParser blob >>= with + Markdown -> parse markdownParser blob >>= with + Python -> parse pythonParser blob >>= with + Ruby -> parse rubyParser blob >>= with + TypeScript -> parse typescriptParser blob >>= with + TSX -> parse tsxParser blob >>= with + PHP -> parse phpParser blob >>= with _ -> noLanguageForBlob (blobPath blob) - - -data SomeTerm typeclasses ann where - SomeTerm :: typeclasses syntax => Term syntax ann -> SomeTerm typeclasses ann - -withSomeTerm :: (forall syntax . typeclasses syntax => Term syntax ann -> a) -> SomeTerm typeclasses ann -> a -withSomeTerm with (SomeTerm term) = with term From 197ffdd40489989d995dcd1e9424305e4a9c8834 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:09:22 -0400 Subject: [PATCH 32/84] Refactor sexpTerm to eliminate the parse. --- src/Semantic/Api/Terms.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 9f1323dcf..6244f8b5c 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -40,6 +40,7 @@ import Semantic.Proto.SemanticPB hiding (Blob) import Semantic.Task import Serializing.Format hiding (JSON) import qualified Serializing.Format as Format +import Serializing.SExpression (ToSExpression) import Source.Loc termGraph :: (Traversable t, Member Distribute sig, ParseEffects sig m) => t Blob -> m ParseTreeGraphResponse @@ -71,7 +72,7 @@ parseTermBuilder :: (Traversable t, Member Distribute sig, ParseEffects sig m, M => TermOutputFormat -> t Blob -> m Builder parseTermBuilder TermJSONTree = distributeFoldMap jsonTerm >=> serialize Format.JSON -- NB: Serialize happens at the top level for these two JSON formats to collect results of multiple blobs. parseTermBuilder TermJSONGraph = termGraph >=> serialize Format.JSON -parseTermBuilder TermSExpression = distributeFoldMap sexpTerm +parseTermBuilder TermSExpression = distributeFoldMap (doParse sexpTerm) parseTermBuilder TermDotGraph = distributeFoldMap dotGraphTerm parseTermBuilder TermShow = distributeFoldMap showTerm parseTermBuilder TermQuiet = distributeFoldMap quietTerm @@ -82,8 +83,8 @@ jsonTerm blob = doParse (pure . renderJSONTerm blob) blob `catchError` jsonError jsonError :: Applicative m => Blob -> SomeException -> m (Rendering.JSON.JSON "trees" SomeJSON) jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) -sexpTerm :: ParseEffects sig m => Blob -> m Builder -sexpTerm = doParse (serialize (SExpression ByConstructorName)) +sexpTerm :: (Carrier sig m, Member (Reader Config) sig, Recursive t, ToSExpression (Base t)) => t -> m Builder +sexpTerm = serialize (SExpression ByConstructorName) dotGraphTerm :: ParseEffects sig m => Blob -> m Builder dotGraphTerm = doParse (serialize (DOT (termStyle "terms")) . renderTreeGraph) From 41a61e37ada66529e5fd08b8ea7f7126f6ea8327 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:11:49 -0400 Subject: [PATCH 33/84] Specialize sexpTerm to Term. --- src/Semantic/Api/Terms.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 6244f8b5c..f13b83d78 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -40,7 +40,6 @@ import Semantic.Proto.SemanticPB hiding (Blob) import Semantic.Task import Serializing.Format hiding (JSON) import qualified Serializing.Format as Format -import Serializing.SExpression (ToSExpression) import Source.Loc termGraph :: (Traversable t, Member Distribute sig, ParseEffects sig m) => t Blob -> m ParseTreeGraphResponse @@ -83,7 +82,7 @@ jsonTerm blob = doParse (pure . renderJSONTerm blob) blob `catchError` jsonError jsonError :: Applicative m => Blob -> SomeException -> m (Rendering.JSON.JSON "trees" SomeJSON) jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) -sexpTerm :: (Carrier sig m, Member (Reader Config) sig, Recursive t, ToSExpression (Base t)) => t -> m Builder +sexpTerm :: (Carrier sig m, ConstructorName syntax, Foldable syntax, Functor syntax, Member (Reader Config) sig) => Term syntax Loc -> m Builder sexpTerm = serialize (SExpression ByConstructorName) dotGraphTerm :: ParseEffects sig m => Blob -> m Builder From 8c6bf14d8fee960afa896437046d564f0cb1cf95 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:13:34 -0400 Subject: [PATCH 34/84] Factor the parse out of showTerm. --- src/Semantic/Api/Terms.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index f13b83d78..0fd210c78 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -73,7 +73,7 @@ parseTermBuilder TermJSONTree = distributeFoldMap jsonTerm >=> serialize Form parseTermBuilder TermJSONGraph = termGraph >=> serialize Format.JSON parseTermBuilder TermSExpression = distributeFoldMap (doParse sexpTerm) parseTermBuilder TermDotGraph = distributeFoldMap dotGraphTerm -parseTermBuilder TermShow = distributeFoldMap showTerm +parseTermBuilder TermShow = distributeFoldMap (doParse showTerm) parseTermBuilder TermQuiet = distributeFoldMap quietTerm jsonTerm :: ParseEffects sig m => Blob -> m (Rendering.JSON.JSON "trees" SomeJSON) @@ -88,8 +88,8 @@ sexpTerm = serialize (SExpression ByConstructorName) dotGraphTerm :: ParseEffects sig m => Blob -> m Builder dotGraphTerm = doParse (serialize (DOT (termStyle "terms")) . renderTreeGraph) -showTerm :: ParseEffects sig m => Blob -> m Builder -showTerm = doParse (serialize Show . quieterm) +showTerm :: (Carrier sig m, Functor syntax, Member (Reader Config) sig, Show1 syntax) => Term syntax Loc -> m Builder +showTerm = serialize Show . quieterm quietTerm :: (ParseEffects sig m, MonadIO m) => Blob -> m Builder quietTerm blob = showTiming blob <$> time' ( doParse (fmap (const (Right ())) . serialize Show . quieterm) blob `catchError` timingError ) From 12a07c252b4a910ebc2da93fb76501d74626b359 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:15:53 -0400 Subject: [PATCH 35/84] Factor the parse out of dotGraphTerm. --- src/Semantic/Api/Terms.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 0fd210c78..806e776fb 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -72,7 +72,7 @@ parseTermBuilder :: (Traversable t, Member Distribute sig, ParseEffects sig m, M parseTermBuilder TermJSONTree = distributeFoldMap jsonTerm >=> serialize Format.JSON -- NB: Serialize happens at the top level for these two JSON formats to collect results of multiple blobs. parseTermBuilder TermJSONGraph = termGraph >=> serialize Format.JSON parseTermBuilder TermSExpression = distributeFoldMap (doParse sexpTerm) -parseTermBuilder TermDotGraph = distributeFoldMap dotGraphTerm +parseTermBuilder TermDotGraph = distributeFoldMap (doParse dotGraphTerm) parseTermBuilder TermShow = distributeFoldMap (doParse showTerm) parseTermBuilder TermQuiet = distributeFoldMap quietTerm @@ -85,8 +85,8 @@ jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) sexpTerm :: (Carrier sig m, ConstructorName syntax, Foldable syntax, Functor syntax, Member (Reader Config) sig) => Term syntax Loc -> m Builder sexpTerm = serialize (SExpression ByConstructorName) -dotGraphTerm :: ParseEffects sig m => Blob -> m Builder -dotGraphTerm = doParse (serialize (DOT (termStyle "terms")) . renderTreeGraph) +dotGraphTerm :: (Carrier sig m, ConstructorName syntax, Foldable syntax, Functor syntax, Member (Reader Config) sig) => Term syntax Loc -> m Builder +dotGraphTerm = serialize (DOT (termStyle "terms")) . renderTreeGraph showTerm :: (Carrier sig m, Functor syntax, Member (Reader Config) sig, Show1 syntax) => Term syntax Loc -> m Builder showTerm = serialize Show . quieterm From 2f77374b9b1c752ea883ade39642d6b402467a9f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:21:58 -0400 Subject: [PATCH 36/84] Define a class abstracting term showing. --- src/Semantic/Api/Terms.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 806e776fb..e9bb7abee 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -118,6 +118,13 @@ instance ( ConstructorName t ) => TermConstraints t +class ShowTerm term where + showTerm' :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder + +instance (Functor syntax, Show1 syntax) => ShowTerm (Term syntax) where + showTerm' = serialize Show . quieterm + + doParse :: ( Carrier sig m , Member (Error SomeException) sig From 0cc79bb86665174273623c84ffd336ee5c4abcbc Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:23:13 -0400 Subject: [PATCH 37/84] Define a class abstract s-expression serialization. --- src/Semantic/Api/Terms.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index e9bb7abee..272893bc8 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -125,6 +125,13 @@ instance (Functor syntax, Show1 syntax) => ShowTerm (Term syntax) where showTerm' = serialize Show . quieterm +class SExprTerm term where + sexprTerm' :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder + +instance (ConstructorName syntax, Foldable syntax, Functor syntax) => SExprTerm (Term syntax) where + sexprTerm' = serialize (SExpression ByConstructorName) + + doParse :: ( Carrier sig m , Member (Error SomeException) sig From 97400fba94f9fd768e79592d07c53a8f1993205f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:24:21 -0400 Subject: [PATCH 38/84] Define a class abstracting DOT graphing. --- src/Semantic/Api/Terms.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 272893bc8..e4d697cfa 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -131,6 +131,12 @@ class SExprTerm term where instance (ConstructorName syntax, Foldable syntax, Functor syntax) => SExprTerm (Term syntax) where sexprTerm' = serialize (SExpression ByConstructorName) +class DOTGraphTerm term where + dotGraphTerm' :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder + +instance (ConstructorName syntax, Foldable syntax, Functor syntax) => DOTGraphTerm (Term syntax) where + dotGraphTerm' = serialize (DOT (termStyle "terms")) . renderTreeGraph + doParse :: ( Carrier sig m From c6cfa944d47cd5fe088f723ef47a4f9239770887 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:25:01 -0400 Subject: [PATCH 39/84] Use the abstracted definitions. --- src/Semantic/Api/Terms.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index e4d697cfa..fe48d45b0 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -83,13 +83,13 @@ jsonError :: Applicative m => Blob -> SomeException -> m (Rendering.JSON.JSON "t jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) sexpTerm :: (Carrier sig m, ConstructorName syntax, Foldable syntax, Functor syntax, Member (Reader Config) sig) => Term syntax Loc -> m Builder -sexpTerm = serialize (SExpression ByConstructorName) +sexpTerm = sexprTerm' dotGraphTerm :: (Carrier sig m, ConstructorName syntax, Foldable syntax, Functor syntax, Member (Reader Config) sig) => Term syntax Loc -> m Builder -dotGraphTerm = serialize (DOT (termStyle "terms")) . renderTreeGraph +dotGraphTerm = dotGraphTerm' showTerm :: (Carrier sig m, Functor syntax, Member (Reader Config) sig, Show1 syntax) => Term syntax Loc -> m Builder -showTerm = serialize Show . quieterm +showTerm = showTerm' quietTerm :: (ParseEffects sig m, MonadIO m) => Blob -> m Builder quietTerm blob = showTiming blob <$> time' ( doParse (fmap (const (Right ())) . serialize Show . quieterm) blob `catchError` timingError ) From 897304ce03dfd11209c0110880ade815d78fea15 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:27:45 -0400 Subject: [PATCH 40/84] Use the abstract definitions directly. --- src/Semantic/Api/Terms.hs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index fe48d45b0..e2fd73b43 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -71,7 +71,7 @@ parseTermBuilder :: (Traversable t, Member Distribute sig, ParseEffects sig m, M => TermOutputFormat -> t Blob -> m Builder parseTermBuilder TermJSONTree = distributeFoldMap jsonTerm >=> serialize Format.JSON -- NB: Serialize happens at the top level for these two JSON formats to collect results of multiple blobs. parseTermBuilder TermJSONGraph = termGraph >=> serialize Format.JSON -parseTermBuilder TermSExpression = distributeFoldMap (doParse sexpTerm) +parseTermBuilder TermSExpression = distributeFoldMap (doParse sexprTerm) parseTermBuilder TermDotGraph = distributeFoldMap (doParse dotGraphTerm) parseTermBuilder TermShow = distributeFoldMap (doParse showTerm) parseTermBuilder TermQuiet = distributeFoldMap quietTerm @@ -82,15 +82,6 @@ jsonTerm blob = doParse (pure . renderJSONTerm blob) blob `catchError` jsonError jsonError :: Applicative m => Blob -> SomeException -> m (Rendering.JSON.JSON "trees" SomeJSON) jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) -sexpTerm :: (Carrier sig m, ConstructorName syntax, Foldable syntax, Functor syntax, Member (Reader Config) sig) => Term syntax Loc -> m Builder -sexpTerm = sexprTerm' - -dotGraphTerm :: (Carrier sig m, ConstructorName syntax, Foldable syntax, Functor syntax, Member (Reader Config) sig) => Term syntax Loc -> m Builder -dotGraphTerm = dotGraphTerm' - -showTerm :: (Carrier sig m, Functor syntax, Member (Reader Config) sig, Show1 syntax) => Term syntax Loc -> m Builder -showTerm = showTerm' - quietTerm :: (ParseEffects sig m, MonadIO m) => Blob -> m Builder quietTerm blob = showTiming blob <$> time' ( doParse (fmap (const (Right ())) . serialize Show . quieterm) blob `catchError` timingError ) where @@ -119,23 +110,23 @@ instance ( ConstructorName t => TermConstraints t class ShowTerm term where - showTerm' :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder + showTerm :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder instance (Functor syntax, Show1 syntax) => ShowTerm (Term syntax) where - showTerm' = serialize Show . quieterm + showTerm = serialize Show . quieterm class SExprTerm term where - sexprTerm' :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder + sexprTerm :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder instance (ConstructorName syntax, Foldable syntax, Functor syntax) => SExprTerm (Term syntax) where - sexprTerm' = serialize (SExpression ByConstructorName) + sexprTerm = serialize (SExpression ByConstructorName) class DOTGraphTerm term where - dotGraphTerm' :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder + dotGraphTerm :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder instance (ConstructorName syntax, Foldable syntax, Functor syntax) => DOTGraphTerm (Term syntax) where - dotGraphTerm' = serialize (DOT (termStyle "terms")) . renderTreeGraph + dotGraphTerm = serialize (DOT (termStyle "terms")) . renderTreeGraph doParse From bf26428ac0a176229a99bb2ea14782271a8f237b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:33:15 -0400 Subject: [PATCH 41/84] Abstract JSON term serialization. --- src/Semantic/Api/Terms.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index e2fd73b43..945a26304 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -77,7 +77,7 @@ parseTermBuilder TermShow = distributeFoldMap (doParse showTerm) parseTermBuilder TermQuiet = distributeFoldMap quietTerm jsonTerm :: ParseEffects sig m => Blob -> m (Rendering.JSON.JSON "trees" SomeJSON) -jsonTerm blob = doParse (pure . renderJSONTerm blob) blob `catchError` jsonError blob +jsonTerm blob = doParse (pure . jsonTerm' blob) blob `catchError` jsonError blob jsonError :: Applicative m => Blob -> SomeException -> m (Rendering.JSON.JSON "trees" SomeJSON) jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) @@ -128,6 +128,12 @@ class DOTGraphTerm term where instance (ConstructorName syntax, Foldable syntax, Functor syntax) => DOTGraphTerm (Term syntax) where dotGraphTerm = serialize (DOT (termStyle "terms")) . renderTreeGraph +class JSONTerm term where + jsonTerm' :: Blob -> term Loc -> (Rendering.JSON.JSON "trees" SomeJSON) + +instance ToJSONFields1 syntax => JSONTerm (Term syntax) where + jsonTerm' = renderJSONTerm + doParse :: ( Carrier sig m From 9d4b7cec29d001d9b6a23548c30e949e387b76e7 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:33:58 -0400 Subject: [PATCH 42/84] Use the abstract interface for timing. --- src/Semantic/Api/Terms.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 945a26304..5cfc134a7 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -83,7 +83,7 @@ jsonError :: Applicative m => Blob -> SomeException -> m (Rendering.JSON.JSON "t jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) quietTerm :: (ParseEffects sig m, MonadIO m) => Blob -> m Builder -quietTerm blob = showTiming blob <$> time' ( doParse (fmap (const (Right ())) . serialize Show . quieterm) blob `catchError` timingError ) +quietTerm blob = showTiming blob <$> time' ( doParse (fmap (const (Right ())) . showTerm) blob `catchError` timingError ) where timingError (SomeException e) = pure (Left (show e)) showTiming Blob{..} (res, duration) = From 51dbc972261c5736ffa074900e1eb61147bcfbad Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:36:36 -0400 Subject: [PATCH 43/84] Abstract rendering terms to JSON graphs. --- src/Semantic/Api/Terms.hs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 5cfc134a7..97e66581b 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -46,17 +46,13 @@ termGraph :: (Traversable t, Member Distribute sig, ParseEffects sig m) => t Blo termGraph blobs = ParseTreeGraphResponse . V.fromList . toList <$> distributeFor blobs go where go :: ParseEffects sig m => Blob -> m ParseTreeFileGraph - go blob = doParse (pure . render) blob + go blob = doParse (pure . jsonGraphTerm blob) blob `catchError` \(SomeException e) -> pure (ParseTreeFileGraph path lang mempty mempty (V.fromList [ParseError (T.pack (show e))])) where path = T.pack $ blobPath blob lang = bridging # blobLanguage blob - render :: (Foldable syntax, Functor syntax, ConstructorName syntax) => Term syntax Loc -> ParseTreeFileGraph - render t = let graph = renderTreeGraph t - toEdge (Edge (a, b)) = TermEdge (vertexId a) (vertexId b) - in ParseTreeFileGraph path lang (V.fromList (vertexList graph)) (V.fromList (fmap toEdge (edgeList graph))) mempty data TermOutputFormat = TermJSONTree @@ -134,6 +130,17 @@ class JSONTerm term where instance ToJSONFields1 syntax => JSONTerm (Term syntax) where jsonTerm' = renderJSONTerm +class JSONGraphTerm term where + jsonGraphTerm :: Blob -> term Loc -> ParseTreeFileGraph + +instance (Foldable syntax, Functor syntax, ConstructorName syntax) => JSONGraphTerm (Term syntax) where + jsonGraphTerm blob t + = let graph = renderTreeGraph t + toEdge (Edge (a, b)) = TermEdge (vertexId a) (vertexId b) + in ParseTreeFileGraph path lang (V.fromList (vertexList graph)) (V.fromList (fmap toEdge (edgeList graph))) mempty where + path = T.pack $ blobPath blob + lang = bridging # blobLanguage blob + doParse :: ( Carrier sig m From 50105fd525e67ae8af3dd52d45aa836e1d0b1523 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:39:50 -0400 Subject: [PATCH 44/84] Express all the necessary constraints over terms, not syntax. --- src/Semantic/Api/Terms.hs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 97e66581b..ca84a6ab2 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -89,19 +89,19 @@ quietTerm blob = showTiming blob <$> time' ( doParse (fmap (const (Right ())) . type ParseEffects sig m = (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Member (Reader Config) sig, Carrier sig m) -class ( ConstructorName t - , Foldable t - , Functor t - , Show1 t - , ToJSONFields1 t +class ( DOTGraphTerm t + , JSONGraphTerm t + , JSONTerm t + , SExprTerm t + , ShowTerm t ) => TermConstraints t -instance ( ConstructorName t - , Foldable t - , Functor t - , Show1 t - , ToJSONFields1 t +instance ( DOTGraphTerm t + , JSONGraphTerm t + , JSONTerm t + , SExprTerm t + , ShowTerm t ) => TermConstraints t @@ -147,7 +147,7 @@ doParse , Member (Error SomeException) sig , Member Parse sig ) - => (forall syntax . TermConstraints syntax => Term syntax Loc -> m a) + => (forall term . TermConstraints term => term Loc -> m a) -> Blob -> m a doParse with blob = case blobLanguage blob of From 3c37459f311aa823d8883e22fc938c8893ac7b38 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:41:50 -0400 Subject: [PATCH 45/84] Spacing. --- src/Semantic/Api/Terms.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index ca84a6ab2..d5db0623a 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -118,18 +118,21 @@ class SExprTerm term where instance (ConstructorName syntax, Foldable syntax, Functor syntax) => SExprTerm (Term syntax) where sexprTerm = serialize (SExpression ByConstructorName) + class DOTGraphTerm term where dotGraphTerm :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder instance (ConstructorName syntax, Foldable syntax, Functor syntax) => DOTGraphTerm (Term syntax) where dotGraphTerm = serialize (DOT (termStyle "terms")) . renderTreeGraph + class JSONTerm term where jsonTerm' :: Blob -> term Loc -> (Rendering.JSON.JSON "trees" SomeJSON) instance ToJSONFields1 syntax => JSONTerm (Term syntax) where jsonTerm' = renderJSONTerm + class JSONGraphTerm term where jsonGraphTerm :: Blob -> term Loc -> ParseTreeFileGraph From aab52d5e36c2fe80c2c2de8c63565efa7cfd5526 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 15:43:36 -0400 Subject: [PATCH 46/84] :fire: redundant parens. --- src/Semantic/Api/Terms.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index d5db0623a..e054849c5 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -127,7 +127,7 @@ instance (ConstructorName syntax, Foldable syntax, Functor syntax) => DOTGraphTe class JSONTerm term where - jsonTerm' :: Blob -> term Loc -> (Rendering.JSON.JSON "trees" SomeJSON) + jsonTerm' :: Blob -> term Loc -> Rendering.JSON.JSON "trees" SomeJSON instance ToJSONFields1 syntax => JSONTerm (Term syntax) where jsonTerm' = renderJSONTerm From 235b2e868b8be82643fd9f26a6e2d4794f4ab9d0 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 16:03:26 -0400 Subject: [PATCH 47/84] Abstract doParse over the constraints. --- src/Semantic/Api/Terms.hs | 53 +++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index e054849c5..cace0243c 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE ConstraintKinds, MonoLocalBinds, RankNTypes, TypeOperators, UndecidableInstances #-} +{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, MonoLocalBinds, RankNTypes, TypeOperators, UndecidableInstances #-} module Semantic.Api.Terms ( termGraph @@ -7,7 +7,6 @@ module Semantic.Api.Terms , doParse , ParseEffects - , TermConstraints ) where @@ -42,11 +41,21 @@ import Serializing.Format hiding (JSON) import qualified Serializing.Format as Format import Source.Loc +import qualified Language.Go.Assignment as Go +import qualified Language.Haskell.Assignment as Haskell +import qualified Language.JSON.Assignment as JSON +import qualified Language.Markdown.Assignment as Markdown +import qualified Language.PHP.Assignment as PHP +import qualified Language.Python.Assignment as Python +import qualified Language.Ruby.Assignment as Ruby +import qualified Language.TSX.Assignment as TSX +import qualified Language.TypeScript.Assignment as TypeScript + termGraph :: (Traversable t, Member Distribute sig, ParseEffects sig m) => t Blob -> m ParseTreeGraphResponse termGraph blobs = ParseTreeGraphResponse . V.fromList . toList <$> distributeFor blobs go where go :: ParseEffects sig m => Blob -> m ParseTreeFileGraph - go blob = doParse (pure . jsonGraphTerm blob) blob + go blob = doParse @JSONGraphTerm (pure . jsonGraphTerm blob) blob `catchError` \(SomeException e) -> pure (ParseTreeFileGraph path lang mempty mempty (V.fromList [ParseError (T.pack (show e))])) where @@ -67,19 +76,19 @@ parseTermBuilder :: (Traversable t, Member Distribute sig, ParseEffects sig m, M => TermOutputFormat -> t Blob -> m Builder parseTermBuilder TermJSONTree = distributeFoldMap jsonTerm >=> serialize Format.JSON -- NB: Serialize happens at the top level for these two JSON formats to collect results of multiple blobs. parseTermBuilder TermJSONGraph = termGraph >=> serialize Format.JSON -parseTermBuilder TermSExpression = distributeFoldMap (doParse sexprTerm) -parseTermBuilder TermDotGraph = distributeFoldMap (doParse dotGraphTerm) -parseTermBuilder TermShow = distributeFoldMap (doParse showTerm) +parseTermBuilder TermSExpression = distributeFoldMap (doParse @SExprTerm sexprTerm) +parseTermBuilder TermDotGraph = distributeFoldMap (doParse @DOTGraphTerm dotGraphTerm) +parseTermBuilder TermShow = distributeFoldMap (doParse @ShowTerm showTerm) parseTermBuilder TermQuiet = distributeFoldMap quietTerm jsonTerm :: ParseEffects sig m => Blob -> m (Rendering.JSON.JSON "trees" SomeJSON) -jsonTerm blob = doParse (pure . jsonTerm' blob) blob `catchError` jsonError blob +jsonTerm blob = doParse @JSONTerm (pure . jsonTerm' blob) blob `catchError` jsonError blob jsonError :: Applicative m => Blob -> SomeException -> m (Rendering.JSON.JSON "trees" SomeJSON) jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) quietTerm :: (ParseEffects sig m, MonadIO m) => Blob -> m Builder -quietTerm blob = showTiming blob <$> time' ( doParse (fmap (const (Right ())) . showTerm) blob `catchError` timingError ) +quietTerm blob = showTiming blob <$> time' ( doParse @ShowTerm (fmap (const (Right ())) . showTerm) blob `catchError` timingError ) where timingError (SomeException e) = pure (Left (show e)) showTiming Blob{..} (res, duration) = @@ -89,21 +98,6 @@ quietTerm blob = showTiming blob <$> time' ( doParse (fmap (const (Right ())) . type ParseEffects sig m = (Member (Error SomeException) sig, Member (Reader PerLanguageModes) sig, Member Parse sig, Member (Reader Config) sig, Carrier sig m) -class ( DOTGraphTerm t - , JSONGraphTerm t - , JSONTerm t - , SExprTerm t - , ShowTerm t - ) - => TermConstraints t - -instance ( DOTGraphTerm t - , JSONGraphTerm t - , JSONTerm t - , SExprTerm t - , ShowTerm t - ) - => TermConstraints t class ShowTerm term where showTerm :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder @@ -146,11 +140,20 @@ instance (Foldable syntax, Functor syntax, ConstructorName syntax) => JSONGraphT doParse - :: ( Carrier sig m + :: ( c (Term (Sum Go.Syntax)) + , c (Term (Sum Haskell.Syntax)) + , c (Term (Sum JSON.Syntax)) + , c (Term (Sum Markdown.Syntax)) + , c (Term (Sum PHP.Syntax)) + , c (Term (Sum Python.Syntax)) + , c (Term (Sum Ruby.Syntax)) + , c (Term (Sum TSX.Syntax)) + , c (Term (Sum TypeScript.Syntax)) + , Carrier sig m , Member (Error SomeException) sig , Member Parse sig ) - => (forall term . TermConstraints term => term Loc -> m a) + => (forall term . c term => term Loc -> m a) -> Blob -> m a doParse with blob = case blobLanguage blob of From 7b256bffef0d720a75cd20149c3333d265e14712 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 16:03:41 -0400 Subject: [PATCH 48/84] Define a ShowTerm instance for precise Python terms. --- src/Semantic/Api/Terms.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index cace0243c..1a2a2289b 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -46,6 +46,7 @@ import qualified Language.Haskell.Assignment as Haskell import qualified Language.JSON.Assignment as JSON import qualified Language.Markdown.Assignment as Markdown import qualified Language.PHP.Assignment as PHP +import qualified Language.Python as Py import qualified Language.Python.Assignment as Python import qualified Language.Ruby.Assignment as Ruby import qualified Language.TSX.Assignment as TSX @@ -105,6 +106,9 @@ class ShowTerm term where instance (Functor syntax, Show1 syntax) => ShowTerm (Term syntax) where showTerm = serialize Show . quieterm +instance ShowTerm Py.Term where + showTerm = serialize Show . Py.getTerm + class SExprTerm term where sexprTerm :: (Carrier sig m, Member (Reader Config) sig) => term Loc -> m Builder From f9e05fc23416ce41423f2b75d120c2324ea93ca9 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 16:11:19 -0400 Subject: [PATCH 49/84] :fire: a redundant language extension. --- src/Semantic/Api/Terms.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 1a2a2289b..9869df747 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, MonoLocalBinds, RankNTypes, TypeOperators, UndecidableInstances #-} +{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, MonoLocalBinds, RankNTypes, TypeOperators #-} module Semantic.Api.Terms ( termGraph From f644a452b237634229e9d085285e53d65c4c22a9 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 17:04:51 -0400 Subject: [PATCH 50/84] Export less. --- src/Semantic/Api/Terms.hs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 9869df747..702c55bcb 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -1,16 +1,10 @@ {-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, MonoLocalBinds, RankNTypes, TypeOperators #-} module Semantic.Api.Terms - ( - termGraph + ( termGraph , parseTermBuilder , TermOutputFormat(..) - - , doParse - , ParseEffects - ) where - import Analysis.ConstructorName (ConstructorName) import Control.Effect.Error import Control.Effect.Parse From 20343598412b6e753b87afdfed788950e93a45db Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 17:15:27 -0400 Subject: [PATCH 51/84] Resume grouping the constraints up. --- src/Semantic/Api/Terms.hs | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 702c55bcb..c2ce09f00 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, MonoLocalBinds, RankNTypes, TypeOperators #-} +{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, MonoLocalBinds, RankNTypes, TypeOperators, UndecidableInstances #-} module Semantic.Api.Terms ( termGraph , parseTermBuilder @@ -35,22 +35,13 @@ import Serializing.Format hiding (JSON) import qualified Serializing.Format as Format import Source.Loc -import qualified Language.Go.Assignment as Go -import qualified Language.Haskell.Assignment as Haskell -import qualified Language.JSON.Assignment as JSON -import qualified Language.Markdown.Assignment as Markdown -import qualified Language.PHP.Assignment as PHP import qualified Language.Python as Py -import qualified Language.Python.Assignment as Python -import qualified Language.Ruby.Assignment as Ruby -import qualified Language.TSX.Assignment as TSX -import qualified Language.TypeScript.Assignment as TypeScript termGraph :: (Traversable t, Member Distribute sig, ParseEffects sig m) => t Blob -> m ParseTreeGraphResponse termGraph blobs = ParseTreeGraphResponse . V.fromList . toList <$> distributeFor blobs go where go :: ParseEffects sig m => Blob -> m ParseTreeFileGraph - go blob = doParse @JSONGraphTerm (pure . jsonGraphTerm blob) blob + go blob = doParse (pure . jsonGraphTerm blob) blob `catchError` \(SomeException e) -> pure (ParseTreeFileGraph path lang mempty mempty (V.fromList [ParseError (T.pack (show e))])) where @@ -71,19 +62,19 @@ parseTermBuilder :: (Traversable t, Member Distribute sig, ParseEffects sig m, M => TermOutputFormat -> t Blob -> m Builder parseTermBuilder TermJSONTree = distributeFoldMap jsonTerm >=> serialize Format.JSON -- NB: Serialize happens at the top level for these two JSON formats to collect results of multiple blobs. parseTermBuilder TermJSONGraph = termGraph >=> serialize Format.JSON -parseTermBuilder TermSExpression = distributeFoldMap (doParse @SExprTerm sexprTerm) -parseTermBuilder TermDotGraph = distributeFoldMap (doParse @DOTGraphTerm dotGraphTerm) -parseTermBuilder TermShow = distributeFoldMap (doParse @ShowTerm showTerm) +parseTermBuilder TermSExpression = distributeFoldMap (doParse sexprTerm) +parseTermBuilder TermDotGraph = distributeFoldMap (doParse dotGraphTerm) +parseTermBuilder TermShow = distributeFoldMap (doParse showTerm) parseTermBuilder TermQuiet = distributeFoldMap quietTerm jsonTerm :: ParseEffects sig m => Blob -> m (Rendering.JSON.JSON "trees" SomeJSON) -jsonTerm blob = doParse @JSONTerm (pure . jsonTerm' blob) blob `catchError` jsonError blob +jsonTerm blob = doParse (pure . jsonTerm' blob) blob `catchError` jsonError blob jsonError :: Applicative m => Blob -> SomeException -> m (Rendering.JSON.JSON "trees" SomeJSON) jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) quietTerm :: (ParseEffects sig m, MonadIO m) => Blob -> m Builder -quietTerm blob = showTiming blob <$> time' ( doParse @ShowTerm (fmap (const (Right ())) . showTerm) blob `catchError` timingError ) +quietTerm blob = showTiming blob <$> time' ( doParse (fmap (const (Right ())) . showTerm) blob `catchError` timingError ) where timingError (SomeException e) = pure (Left (show e)) showTiming Blob{..} (res, duration) = @@ -137,21 +128,15 @@ instance (Foldable syntax, Functor syntax, ConstructorName syntax) => JSONGraphT lang = bridging # blobLanguage blob +class (DOTGraphTerm t, JSONGraphTerm t, JSONTerm t, SExprTerm t, ShowTerm t) => TermActions t +instance (DOTGraphTerm t, JSONGraphTerm t, JSONTerm t, SExprTerm t, ShowTerm t) => TermActions t + doParse - :: ( c (Term (Sum Go.Syntax)) - , c (Term (Sum Haskell.Syntax)) - , c (Term (Sum JSON.Syntax)) - , c (Term (Sum Markdown.Syntax)) - , c (Term (Sum PHP.Syntax)) - , c (Term (Sum Python.Syntax)) - , c (Term (Sum Ruby.Syntax)) - , c (Term (Sum TSX.Syntax)) - , c (Term (Sum TypeScript.Syntax)) - , Carrier sig m + :: ( Carrier sig m , Member (Error SomeException) sig , Member Parse sig ) - => (forall term . c term => term Loc -> m a) + => (forall term . TermActions term => term Loc -> m a) -> Blob -> m a doParse with blob = case blobLanguage blob of From 81847425fa2bf7507ae7acedda58fa319d3bf8c2 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 17:20:37 -0400 Subject: [PATCH 52/84] Rename JSONTerm to JSONTreeTerm. --- src/Semantic/Api/Terms.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index c2ce09f00..6512ad7e1 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -109,10 +109,10 @@ instance (ConstructorName syntax, Foldable syntax, Functor syntax) => DOTGraphTe dotGraphTerm = serialize (DOT (termStyle "terms")) . renderTreeGraph -class JSONTerm term where +class JSONTreeTerm term where jsonTerm' :: Blob -> term Loc -> Rendering.JSON.JSON "trees" SomeJSON -instance ToJSONFields1 syntax => JSONTerm (Term syntax) where +instance ToJSONFields1 syntax => JSONTreeTerm (Term syntax) where jsonTerm' = renderJSONTerm @@ -128,8 +128,8 @@ instance (Foldable syntax, Functor syntax, ConstructorName syntax) => JSONGraphT lang = bridging # blobLanguage blob -class (DOTGraphTerm t, JSONGraphTerm t, JSONTerm t, SExprTerm t, ShowTerm t) => TermActions t -instance (DOTGraphTerm t, JSONGraphTerm t, JSONTerm t, SExprTerm t, ShowTerm t) => TermActions t +class (DOTGraphTerm t, JSONGraphTerm t, JSONTreeTerm t, SExprTerm t, ShowTerm t) => TermActions t +instance (DOTGraphTerm t, JSONGraphTerm t, JSONTreeTerm t, SExprTerm t, ShowTerm t) => TermActions t doParse :: ( Carrier sig m From fdb6d96ab5f90db8aeda543a209d462ec63d7182 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:23:44 -0400 Subject: [PATCH 53/84] Use a class to constrain diffable terms. --- src/Semantic/Api/Diffs.hs | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index 22e750986..1f211f5a0 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE GADTs, ConstraintKinds, TypeOperators, RankNTypes #-} +{-# LANGUAGE GADTs, ConstraintKinds, TypeOperators, RankNTypes, UndecidableInstances #-} module Semantic.Api.Diffs ( parseDiffBuilder , DiffOutputFormat(..) @@ -103,16 +103,26 @@ type DiffEffects sig m = (Member (Error SomeException) sig, Member (Reader Confi type CanDiff syntax = (ConstructorName syntax, Diffable syntax, Eq1 syntax, HasDeclaration syntax, Hashable1 syntax, Show1 syntax, ToJSONFields1 syntax, Traversable syntax) type Decorate a b = forall syntax . CanDiff syntax => Blob -> Term syntax a -> Term syntax b -type TermPairConstraints = - '[ ConstructorName - , Diffable - , Eq1 - , HasDeclaration - , Hashable1 - , Show1 - , Traversable - , ToJSONFields1 - ] +class ( ConstructorName t + , Diffable t + , Eq1 t + , HasDeclaration t + , Hashable1 t + , Show1 t + , Traversable t + , ToJSONFields1 t + ) + => DiffActions t +instance ( ConstructorName t + , Diffable t + , Eq1 t + , HasDeclaration t + , Hashable1 t + , Show1 t + , Traversable t + , ToJSONFields1 t + ) + => DiffActions t doDiff :: (DiffEffects sig m) => BlobPair -> Decorate Loc ann -> (forall syntax . CanDiff syntax => BlobPair -> Diff syntax ann ann -> m output) -> m output @@ -129,7 +139,7 @@ diffTerms blobs terms = time "diff" languageTag $ do where languageTag = languageTagForBlobPair blobs doParse :: (Member (Error SomeException) sig, Member Distribute sig, Member Parse sig, Carrier sig m) - => BlobPair -> Decorate Loc ann -> m (SomeTermPair TermPairConstraints ann) + => BlobPair -> Decorate Loc ann -> m (SomeTermPair DiffActions ann) doParse blobPair decorate = case languageForBlobPair blobPair of Go -> SomeTermPair <$> distributeFor blobPair (\ blob -> decorate blob <$> parse goParser blob) Haskell -> SomeTermPair <$> distributeFor blobPair (\ blob -> decorate blob <$> parse haskellParser blob) @@ -145,7 +155,7 @@ doParse blobPair decorate = case languageForBlobPair blobPair of _ -> noLanguageForBlob (pathForBlobPair blobPair) data SomeTermPair typeclasses ann where - SomeTermPair :: ApplyAll typeclasses syntax => Join These (Term syntax ann) -> SomeTermPair typeclasses ann + SomeTermPair :: typeclasses syntax => Join These (Term syntax ann) -> SomeTermPair typeclasses ann -withSomeTermPair :: (forall syntax . ApplyAll typeclasses syntax => Join These (Term syntax ann) -> a) -> SomeTermPair typeclasses ann -> a +withSomeTermPair :: (forall syntax . typeclasses syntax => Join These (Term syntax ann) -> a) -> SomeTermPair typeclasses ann -> a withSomeTermPair with (SomeTermPair terms) = with terms From 6050f10ecf8792f42c72951a2a3c7950b958d573 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:29:42 -0400 Subject: [PATCH 54/84] :fire: redundant parens. --- src/Semantic/Api/Diffs.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index 1f211f5a0..de69b44b7 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -61,7 +61,7 @@ parseDiffBuilder DiffDotGraph = distributeFoldMap dotGraphDiff type RenderJSON m syntax = forall syntax . CanDiff syntax => BlobPair -> Diff syntax Loc Loc -> m (Rendering.JSON.JSON "diffs" SomeJSON) -jsonDiff :: (DiffEffects sig m) => RenderJSON m syntax -> BlobPair -> m (Rendering.JSON.JSON "diffs" SomeJSON) +jsonDiff :: DiffEffects sig m => RenderJSON m syntax -> BlobPair -> m (Rendering.JSON.JSON "diffs" SomeJSON) jsonDiff f blobPair = doDiff blobPair (const id) f `catchError` jsonError blobPair jsonError :: Applicative m => BlobPair -> SomeException -> m (Rendering.JSON.JSON "diffs" SomeJSON) @@ -73,7 +73,7 @@ renderJSONTree blobPair = pure . renderJSONDiff blobPair diffGraph :: (Traversable t, DiffEffects sig m) => t BlobPair -> m DiffTreeGraphResponse diffGraph blobs = DiffTreeGraphResponse . V.fromList . toList <$> distributeFor blobs go where - go :: (DiffEffects sig m) => BlobPair -> m DiffTreeFileGraph + go :: DiffEffects sig m => BlobPair -> m DiffTreeFileGraph go blobPair = doDiff blobPair (const id) render `catchError` \(SomeException e) -> pure (DiffTreeFileGraph path lang mempty mempty (V.fromList [ParseError (T.pack (show e))])) @@ -88,13 +88,13 @@ diffGraph blobs = DiffTreeGraphResponse . V.fromList . toList <$> distributeFor in pure $ DiffTreeFileGraph path lang (V.fromList (vertexList graph)) (V.fromList (fmap toEdge (edgeList graph))) mempty -sexpDiff :: (DiffEffects sig m) => BlobPair -> m Builder +sexpDiff :: DiffEffects sig m => BlobPair -> m Builder sexpDiff blobPair = doDiff blobPair (const id) (const (serialize (SExpression ByConstructorName))) -showDiff :: (DiffEffects sig m) => BlobPair -> m Builder +showDiff :: DiffEffects sig m => BlobPair -> m Builder showDiff blobPair = doDiff blobPair (const id) (const (serialize Show)) -dotGraphDiff :: (DiffEffects sig m) => BlobPair -> m Builder +dotGraphDiff :: DiffEffects sig m => BlobPair -> m Builder dotGraphDiff blobPair = doDiff blobPair (const id) render where render _ = serialize (DOT (diffStyle "diffs")) . renderTreeGraph @@ -124,7 +124,7 @@ instance ( ConstructorName t ) => DiffActions t -doDiff :: (DiffEffects sig m) +doDiff :: DiffEffects sig m => BlobPair -> Decorate Loc ann -> (forall syntax . CanDiff syntax => BlobPair -> Diff syntax ann ann -> m output) -> m output doDiff blobPair decorate render = do SomeTermPair terms <- doParse blobPair decorate From 05103d8324abfbd03fd9dff81f4a8d6b27564ffd Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:33:43 -0400 Subject: [PATCH 55/84] Reformat the doDiff signature. --- src/Semantic/Api/Diffs.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index de69b44b7..e459419b3 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -124,8 +124,12 @@ instance ( ConstructorName t ) => DiffActions t -doDiff :: DiffEffects sig m - => BlobPair -> Decorate Loc ann -> (forall syntax . CanDiff syntax => BlobPair -> Diff syntax ann ann -> m output) -> m output +doDiff + :: DiffEffects sig m + => BlobPair + -> Decorate Loc ann + -> (forall syntax . CanDiff syntax => BlobPair -> Diff syntax ann ann -> m output) + -> m output doDiff blobPair decorate render = do SomeTermPair terms <- doParse blobPair decorate diff <- diffTerms blobPair terms From 64c228787475feab8e26cc76ec28e4702c7d2ff5 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:35:45 -0400 Subject: [PATCH 56/84] Move the BlobPair to the final position. --- src/Semantic/Api/Diffs.hs | 16 ++++++++-------- src/Semantic/Api/TOCSummaries.hs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index e459419b3..9fba468b2 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -62,7 +62,7 @@ parseDiffBuilder DiffDotGraph = distributeFoldMap dotGraphDiff type RenderJSON m syntax = forall syntax . CanDiff syntax => BlobPair -> Diff syntax Loc Loc -> m (Rendering.JSON.JSON "diffs" SomeJSON) jsonDiff :: DiffEffects sig m => RenderJSON m syntax -> BlobPair -> m (Rendering.JSON.JSON "diffs" SomeJSON) -jsonDiff f blobPair = doDiff blobPair (const id) f `catchError` jsonError blobPair +jsonDiff f blobPair = doDiff (const id) f blobPair `catchError` jsonError blobPair jsonError :: Applicative m => BlobPair -> SomeException -> m (Rendering.JSON.JSON "diffs" SomeJSON) jsonError blobPair (SomeException e) = pure $ renderJSONDiffError blobPair (show e) @@ -74,7 +74,7 @@ diffGraph :: (Traversable t, DiffEffects sig m) => t BlobPair -> m DiffTreeGraph diffGraph blobs = DiffTreeGraphResponse . V.fromList . toList <$> distributeFor blobs go where go :: DiffEffects sig m => BlobPair -> m DiffTreeFileGraph - go blobPair = doDiff blobPair (const id) render + go blobPair = doDiff (const id) render blobPair `catchError` \(SomeException e) -> pure (DiffTreeFileGraph path lang mempty mempty (V.fromList [ParseError (T.pack (show e))])) where @@ -89,13 +89,13 @@ diffGraph blobs = DiffTreeGraphResponse . V.fromList . toList <$> distributeFor sexpDiff :: DiffEffects sig m => BlobPair -> m Builder -sexpDiff blobPair = doDiff blobPair (const id) (const (serialize (SExpression ByConstructorName))) +sexpDiff = doDiff (const id) (const (serialize (SExpression ByConstructorName))) showDiff :: DiffEffects sig m => BlobPair -> m Builder -showDiff blobPair = doDiff blobPair (const id) (const (serialize Show)) +showDiff = doDiff (const id) (const (serialize Show)) dotGraphDiff :: DiffEffects sig m => BlobPair -> m Builder -dotGraphDiff blobPair = doDiff blobPair (const id) render +dotGraphDiff = doDiff (const id) render where render _ = serialize (DOT (diffStyle "diffs")) . renderTreeGraph type DiffEffects sig m = (Member (Error SomeException) sig, Member (Reader Config) sig, Member Telemetry sig, Member Distribute sig, Member Parse sig, Carrier sig m, MonadIO m) @@ -126,11 +126,11 @@ instance ( ConstructorName t doDiff :: DiffEffects sig m - => BlobPair - -> Decorate Loc ann + => Decorate Loc ann -> (forall syntax . CanDiff syntax => BlobPair -> Diff syntax ann ann -> m output) + -> BlobPair -> m output -doDiff blobPair decorate render = do +doDiff decorate render blobPair = do SomeTermPair terms <- doParse blobPair decorate diff <- diffTerms blobPair terms render blobPair diff diff --git a/src/Semantic/Api/TOCSummaries.hs b/src/Semantic/Api/TOCSummaries.hs index dcbdff76f..ea542bd03 100644 --- a/src/Semantic/Api/TOCSummaries.hs +++ b/src/Semantic/Api/TOCSummaries.hs @@ -27,7 +27,7 @@ legacyDiffSummary :: (DiffEffects sig m) => [BlobPair] -> m Summaries legacyDiffSummary = distributeFoldMap go where go :: (DiffEffects sig m) => BlobPair -> m Summaries - go blobPair = doDiff blobPair (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) render + go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) render blobPair `catchError` \(SomeException e) -> pure $ Summaries mempty (Map.singleton path [toJSON (ErrorSummary (T.pack (show e)) lowerBound lang)]) where path = T.pack $ pathKeyForBlobPair blobPair @@ -40,7 +40,7 @@ diffSummary :: (DiffEffects sig m) => [BlobPair] -> m DiffTreeTOCResponse diffSummary blobs = DiffTreeTOCResponse . V.fromList <$> distributeFor blobs go where go :: (DiffEffects sig m) => BlobPair -> m TOCSummaryFile - go blobPair = doDiff blobPair (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) render + go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) render blobPair `catchError` \(SomeException e) -> pure $ TOCSummaryFile path lang mempty (V.fromList [TOCSummaryError (T.pack (show e)) Nothing]) where path = T.pack $ pathKeyForBlobPair blobPair From bc1382388738de7e4d6ab8fcb3f59f2696c0eed3 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:43:00 -0400 Subject: [PATCH 57/84] =?UTF-8?q?Don=E2=80=99t=20pass=20the=20BlobPair=20t?= =?UTF-8?q?o=20the=20render=20function.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Semantic/Api/Diffs.hs | 17 +++++++++-------- src/Semantic/Api/TOCSummaries.hs | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index 9fba468b2..9a3a5c52c 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -62,7 +62,7 @@ parseDiffBuilder DiffDotGraph = distributeFoldMap dotGraphDiff type RenderJSON m syntax = forall syntax . CanDiff syntax => BlobPair -> Diff syntax Loc Loc -> m (Rendering.JSON.JSON "diffs" SomeJSON) jsonDiff :: DiffEffects sig m => RenderJSON m syntax -> BlobPair -> m (Rendering.JSON.JSON "diffs" SomeJSON) -jsonDiff f blobPair = doDiff (const id) f blobPair `catchError` jsonError blobPair +jsonDiff f blobPair = doDiff (const id) (f blobPair) blobPair `catchError` jsonError blobPair jsonError :: Applicative m => BlobPair -> SomeException -> m (Rendering.JSON.JSON "diffs" SomeJSON) jsonError blobPair (SomeException e) = pure $ renderJSONDiffError blobPair (show e) @@ -81,22 +81,23 @@ diffGraph blobs = DiffTreeGraphResponse . V.fromList . toList <$> distributeFor path = T.pack $ pathForBlobPair blobPair lang = bridging # languageForBlobPair blobPair - render :: (Foldable syntax, Functor syntax, ConstructorName syntax, Applicative m) => BlobPair -> Diff syntax Loc Loc -> m DiffTreeFileGraph - render _ diff = + render :: (Foldable syntax, Functor syntax, ConstructorName syntax, Applicative m) => Diff syntax Loc Loc -> m DiffTreeFileGraph + render diff = let graph = renderTreeGraph diff toEdge (Edge (a, b)) = DiffTreeEdge (diffVertexId a) (diffVertexId b) in pure $ DiffTreeFileGraph path lang (V.fromList (vertexList graph)) (V.fromList (fmap toEdge (edgeList graph))) mempty sexpDiff :: DiffEffects sig m => BlobPair -> m Builder -sexpDiff = doDiff (const id) (const (serialize (SExpression ByConstructorName))) +sexpDiff = doDiff (const id) (serialize (SExpression ByConstructorName)) showDiff :: DiffEffects sig m => BlobPair -> m Builder -showDiff = doDiff (const id) (const (serialize Show)) +showDiff = doDiff (const id) (serialize Show) dotGraphDiff :: DiffEffects sig m => BlobPair -> m Builder dotGraphDiff = doDiff (const id) render - where render _ = serialize (DOT (diffStyle "diffs")) . renderTreeGraph + where render :: (Carrier sig m, ConstructorName syntax, Foldable syntax, Functor syntax, Member (Reader Config) sig) => Diff syntax Loc Loc -> m Builder + render = serialize (DOT (diffStyle "diffs")) . renderTreeGraph type DiffEffects sig m = (Member (Error SomeException) sig, Member (Reader Config) sig, Member Telemetry sig, Member Distribute sig, Member Parse sig, Carrier sig m, MonadIO m) @@ -127,13 +128,13 @@ instance ( ConstructorName t doDiff :: DiffEffects sig m => Decorate Loc ann - -> (forall syntax . CanDiff syntax => BlobPair -> Diff syntax ann ann -> m output) + -> (forall syntax . CanDiff syntax => Diff syntax ann ann -> m output) -> BlobPair -> m output doDiff decorate render blobPair = do SomeTermPair terms <- doParse blobPair decorate diff <- diffTerms blobPair terms - render blobPair diff + render diff diffTerms :: (CanDiff syntax, Member Telemetry sig, Carrier sig m, MonadIO m) => BlobPair -> Join These (Term syntax ann) -> m (Diff syntax ann ann) diff --git a/src/Semantic/Api/TOCSummaries.hs b/src/Semantic/Api/TOCSummaries.hs index ea542bd03..8f3c31b1f 100644 --- a/src/Semantic/Api/TOCSummaries.hs +++ b/src/Semantic/Api/TOCSummaries.hs @@ -27,7 +27,7 @@ legacyDiffSummary :: (DiffEffects sig m) => [BlobPair] -> m Summaries legacyDiffSummary = distributeFoldMap go where go :: (DiffEffects sig m) => BlobPair -> m Summaries - go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) render blobPair + go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (render blobPair) blobPair `catchError` \(SomeException e) -> pure $ Summaries mempty (Map.singleton path [toJSON (ErrorSummary (T.pack (show e)) lowerBound lang)]) where path = T.pack $ pathKeyForBlobPair blobPair @@ -40,7 +40,7 @@ diffSummary :: (DiffEffects sig m) => [BlobPair] -> m DiffTreeTOCResponse diffSummary blobs = DiffTreeTOCResponse . V.fromList <$> distributeFor blobs go where go :: (DiffEffects sig m) => BlobPair -> m TOCSummaryFile - go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) render blobPair + go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (render blobPair) blobPair `catchError` \(SomeException e) -> pure $ TOCSummaryFile path lang mempty (V.fromList [TOCSummaryError (T.pack (show e)) Nothing]) where path = T.pack $ pathKeyForBlobPair blobPair From 972653aef2455a87dac74c029d926e83cb9311ad Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:44:25 -0400 Subject: [PATCH 58/84] Show diffs via an abstracted interface. --- src/Semantic/Api/Diffs.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index 9a3a5c52c..4bff483e9 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -56,7 +56,7 @@ parseDiffBuilder :: (Traversable t, DiffEffects sig m) => DiffOutputFormat -> t parseDiffBuilder DiffJSONTree = distributeFoldMap (jsonDiff renderJSONTree) >=> serialize Format.JSON -- NB: Serialize happens at the top level for these two JSON formats to collect results of multiple blob pairs. parseDiffBuilder DiffJSONGraph = diffGraph >=> serialize Format.JSON parseDiffBuilder DiffSExpression = distributeFoldMap sexpDiff -parseDiffBuilder DiffShow = distributeFoldMap showDiff +parseDiffBuilder DiffShow = distributeFoldMap (doDiff (const id) showDiff) parseDiffBuilder DiffDotGraph = distributeFoldMap dotGraphDiff type RenderJSON m syntax = forall syntax . CanDiff syntax => BlobPair -> Diff syntax Loc Loc -> m (Rendering.JSON.JSON "diffs" SomeJSON) @@ -91,9 +91,6 @@ diffGraph blobs = DiffTreeGraphResponse . V.fromList . toList <$> distributeFor sexpDiff :: DiffEffects sig m => BlobPair -> m Builder sexpDiff = doDiff (const id) (serialize (SExpression ByConstructorName)) -showDiff :: DiffEffects sig m => BlobPair -> m Builder -showDiff = doDiff (const id) (serialize Show) - dotGraphDiff :: DiffEffects sig m => BlobPair -> m Builder dotGraphDiff = doDiff (const id) render where render :: (Carrier sig m, ConstructorName syntax, Foldable syntax, Functor syntax, Member (Reader Config) sig) => Diff syntax Loc Loc -> m Builder @@ -104,6 +101,12 @@ type DiffEffects sig m = (Member (Error SomeException) sig, Member (Reader Confi type CanDiff syntax = (ConstructorName syntax, Diffable syntax, Eq1 syntax, HasDeclaration syntax, Hashable1 syntax, Show1 syntax, ToJSONFields1 syntax, Traversable syntax) type Decorate a b = forall syntax . CanDiff syntax => Blob -> Term syntax a -> Term syntax b +class ShowDiff diff where + showDiff :: (Carrier sig m, Member (Reader Config) sig) => diff Loc Loc -> m Builder + +instance Show1 syntax => ShowDiff (Diff syntax) where + showDiff = serialize Show + class ( ConstructorName t , Diffable t , Eq1 t From 868bde86c14a53df5f429804e1f1e57ac0d50ff4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:45:37 -0400 Subject: [PATCH 59/84] :fire: the CanDiff constraint synonym in favour of DiffActions. --- src/Semantic/Api/Diffs.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index 4bff483e9..c0187ccf5 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -59,7 +59,7 @@ parseDiffBuilder DiffSExpression = distributeFoldMap sexpDiff parseDiffBuilder DiffShow = distributeFoldMap (doDiff (const id) showDiff) parseDiffBuilder DiffDotGraph = distributeFoldMap dotGraphDiff -type RenderJSON m syntax = forall syntax . CanDiff syntax => BlobPair -> Diff syntax Loc Loc -> m (Rendering.JSON.JSON "diffs" SomeJSON) +type RenderJSON m syntax = forall syntax . DiffActions syntax => BlobPair -> Diff syntax Loc Loc -> m (Rendering.JSON.JSON "diffs" SomeJSON) jsonDiff :: DiffEffects sig m => RenderJSON m syntax -> BlobPair -> m (Rendering.JSON.JSON "diffs" SomeJSON) jsonDiff f blobPair = doDiff (const id) (f blobPair) blobPair `catchError` jsonError blobPair @@ -98,8 +98,7 @@ dotGraphDiff = doDiff (const id) render type DiffEffects sig m = (Member (Error SomeException) sig, Member (Reader Config) sig, Member Telemetry sig, Member Distribute sig, Member Parse sig, Carrier sig m, MonadIO m) -type CanDiff syntax = (ConstructorName syntax, Diffable syntax, Eq1 syntax, HasDeclaration syntax, Hashable1 syntax, Show1 syntax, ToJSONFields1 syntax, Traversable syntax) -type Decorate a b = forall syntax . CanDiff syntax => Blob -> Term syntax a -> Term syntax b +type Decorate a b = forall syntax . DiffActions syntax => Blob -> Term syntax a -> Term syntax b class ShowDiff diff where showDiff :: (Carrier sig m, Member (Reader Config) sig) => diff Loc Loc -> m Builder @@ -131,7 +130,7 @@ instance ( ConstructorName t doDiff :: DiffEffects sig m => Decorate Loc ann - -> (forall syntax . CanDiff syntax => Diff syntax ann ann -> m output) + -> (forall syntax . DiffActions syntax => Diff syntax ann ann -> m output) -> BlobPair -> m output doDiff decorate render blobPair = do @@ -139,7 +138,7 @@ doDiff decorate render blobPair = do diff <- diffTerms blobPair terms render diff -diffTerms :: (CanDiff syntax, Member Telemetry sig, Carrier sig m, MonadIO m) +diffTerms :: (DiffActions syntax, Member Telemetry sig, Carrier sig m, MonadIO m) => BlobPair -> Join These (Term syntax ann) -> m (Diff syntax ann ann) diffTerms blobs terms = time "diff" languageTag $ do let diff = diffTermPair (runJoin terms) From cc77d7bf17504df22baa3ee253645cd730b59220 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:48:22 -0400 Subject: [PATCH 60/84] Render diffs to s-expressions using an abstracted interface. --- src/Semantic/Api/Diffs.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index c0187ccf5..a3e6a39af 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -55,7 +55,7 @@ data DiffOutputFormat parseDiffBuilder :: (Traversable t, DiffEffects sig m) => DiffOutputFormat -> t BlobPair -> m Builder parseDiffBuilder DiffJSONTree = distributeFoldMap (jsonDiff renderJSONTree) >=> serialize Format.JSON -- NB: Serialize happens at the top level for these two JSON formats to collect results of multiple blob pairs. parseDiffBuilder DiffJSONGraph = diffGraph >=> serialize Format.JSON -parseDiffBuilder DiffSExpression = distributeFoldMap sexpDiff +parseDiffBuilder DiffSExpression = distributeFoldMap (doDiff (const id) sexprDiff) parseDiffBuilder DiffShow = distributeFoldMap (doDiff (const id) showDiff) parseDiffBuilder DiffDotGraph = distributeFoldMap dotGraphDiff @@ -87,10 +87,6 @@ diffGraph blobs = DiffTreeGraphResponse . V.fromList . toList <$> distributeFor toEdge (Edge (a, b)) = DiffTreeEdge (diffVertexId a) (diffVertexId b) in pure $ DiffTreeFileGraph path lang (V.fromList (vertexList graph)) (V.fromList (fmap toEdge (edgeList graph))) mempty - -sexpDiff :: DiffEffects sig m => BlobPair -> m Builder -sexpDiff = doDiff (const id) (serialize (SExpression ByConstructorName)) - dotGraphDiff :: DiffEffects sig m => BlobPair -> m Builder dotGraphDiff = doDiff (const id) render where render :: (Carrier sig m, ConstructorName syntax, Foldable syntax, Functor syntax, Member (Reader Config) sig) => Diff syntax Loc Loc -> m Builder @@ -100,6 +96,12 @@ type DiffEffects sig m = (Member (Error SomeException) sig, Member (Reader Confi type Decorate a b = forall syntax . DiffActions syntax => Blob -> Term syntax a -> Term syntax b +class SExprDiff diff where + sexprDiff :: (Carrier sig m, Member (Reader Config) sig) => diff Loc Loc -> m Builder + +instance (ConstructorName syntax, Foldable syntax, Functor syntax) => SExprDiff (Diff syntax) where + sexprDiff = serialize (SExpression ByConstructorName) + class ShowDiff diff where showDiff :: (Carrier sig m, Member (Reader Config) sig) => diff Loc Loc -> m Builder From bda1269c76ef11b380b6cf16355f499501adde82 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:50:47 -0400 Subject: [PATCH 61/84] Render diffs to DOT graphs using an abstract interface. --- src/Semantic/Api/Diffs.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index a3e6a39af..c5d2c3160 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -57,7 +57,7 @@ parseDiffBuilder DiffJSONTree = distributeFoldMap (jsonDiff renderJSONTree) > parseDiffBuilder DiffJSONGraph = diffGraph >=> serialize Format.JSON parseDiffBuilder DiffSExpression = distributeFoldMap (doDiff (const id) sexprDiff) parseDiffBuilder DiffShow = distributeFoldMap (doDiff (const id) showDiff) -parseDiffBuilder DiffDotGraph = distributeFoldMap dotGraphDiff +parseDiffBuilder DiffDotGraph = distributeFoldMap (doDiff (const id) dotGraphDiff) type RenderJSON m syntax = forall syntax . DiffActions syntax => BlobPair -> Diff syntax Loc Loc -> m (Rendering.JSON.JSON "diffs" SomeJSON) @@ -87,15 +87,16 @@ diffGraph blobs = DiffTreeGraphResponse . V.fromList . toList <$> distributeFor toEdge (Edge (a, b)) = DiffTreeEdge (diffVertexId a) (diffVertexId b) in pure $ DiffTreeFileGraph path lang (V.fromList (vertexList graph)) (V.fromList (fmap toEdge (edgeList graph))) mempty -dotGraphDiff :: DiffEffects sig m => BlobPair -> m Builder -dotGraphDiff = doDiff (const id) render - where render :: (Carrier sig m, ConstructorName syntax, Foldable syntax, Functor syntax, Member (Reader Config) sig) => Diff syntax Loc Loc -> m Builder - render = serialize (DOT (diffStyle "diffs")) . renderTreeGraph - type DiffEffects sig m = (Member (Error SomeException) sig, Member (Reader Config) sig, Member Telemetry sig, Member Distribute sig, Member Parse sig, Carrier sig m, MonadIO m) type Decorate a b = forall syntax . DiffActions syntax => Blob -> Term syntax a -> Term syntax b +class DOTGraphDiff diff where + dotGraphDiff :: (Carrier sig m, Member (Reader Config) sig) => diff Loc Loc -> m Builder + +instance (ConstructorName syntax, Foldable syntax, Functor syntax) => DOTGraphDiff (Diff syntax) where + dotGraphDiff = serialize (DOT (diffStyle "diffs")) . renderTreeGraph + class SExprDiff diff where sexprDiff :: (Carrier sig m, Member (Reader Config) sig) => diff Loc Loc -> m Builder From c0278a970be6ea30daad662ec207655063692d3d Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:53:30 -0400 Subject: [PATCH 62/84] Factor the JSON renderer into jsonDiff. --- src/Semantic/Api/Diffs.hs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index c5d2c3160..59018e423 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -53,16 +53,14 @@ data DiffOutputFormat deriving (Eq, Show) parseDiffBuilder :: (Traversable t, DiffEffects sig m) => DiffOutputFormat -> t BlobPair -> m Builder -parseDiffBuilder DiffJSONTree = distributeFoldMap (jsonDiff renderJSONTree) >=> serialize Format.JSON -- NB: Serialize happens at the top level for these two JSON formats to collect results of multiple blob pairs. +parseDiffBuilder DiffJSONTree = distributeFoldMap jsonDiff >=> serialize Format.JSON -- NB: Serialize happens at the top level for these two JSON formats to collect results of multiple blob pairs. parseDiffBuilder DiffJSONGraph = diffGraph >=> serialize Format.JSON parseDiffBuilder DiffSExpression = distributeFoldMap (doDiff (const id) sexprDiff) parseDiffBuilder DiffShow = distributeFoldMap (doDiff (const id) showDiff) parseDiffBuilder DiffDotGraph = distributeFoldMap (doDiff (const id) dotGraphDiff) -type RenderJSON m syntax = forall syntax . DiffActions syntax => BlobPair -> Diff syntax Loc Loc -> m (Rendering.JSON.JSON "diffs" SomeJSON) - -jsonDiff :: DiffEffects sig m => RenderJSON m syntax -> BlobPair -> m (Rendering.JSON.JSON "diffs" SomeJSON) -jsonDiff f blobPair = doDiff (const id) (f blobPair) blobPair `catchError` jsonError blobPair +jsonDiff :: DiffEffects sig m => BlobPair -> m (Rendering.JSON.JSON "diffs" SomeJSON) +jsonDiff blobPair = doDiff (const id) (renderJSONTree blobPair) blobPair `catchError` jsonError blobPair jsonError :: Applicative m => BlobPair -> SomeException -> m (Rendering.JSON.JSON "diffs" SomeJSON) jsonError blobPair (SomeException e) = pure $ renderJSONDiffError blobPair (show e) From bf14a4f4646c92ede6972388e3af83dce620905a Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:54:29 -0400 Subject: [PATCH 63/84] Rename jsonTerm' to jsonTreeTerm. --- src/Semantic/Api/Terms.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index 6512ad7e1..d8fc41f09 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -68,7 +68,7 @@ parseTermBuilder TermShow = distributeFoldMap (doParse showTerm) parseTermBuilder TermQuiet = distributeFoldMap quietTerm jsonTerm :: ParseEffects sig m => Blob -> m (Rendering.JSON.JSON "trees" SomeJSON) -jsonTerm blob = doParse (pure . jsonTerm' blob) blob `catchError` jsonError blob +jsonTerm blob = doParse (pure . jsonTreeTerm blob) blob `catchError` jsonError blob jsonError :: Applicative m => Blob -> SomeException -> m (Rendering.JSON.JSON "trees" SomeJSON) jsonError blob (SomeException e) = pure $ renderJSONError blob (show e) @@ -110,10 +110,10 @@ instance (ConstructorName syntax, Foldable syntax, Functor syntax) => DOTGraphTe class JSONTreeTerm term where - jsonTerm' :: Blob -> term Loc -> Rendering.JSON.JSON "trees" SomeJSON + jsonTreeTerm :: Blob -> term Loc -> Rendering.JSON.JSON "trees" SomeJSON instance ToJSONFields1 syntax => JSONTreeTerm (Term syntax) where - jsonTerm' = renderJSONTerm + jsonTreeTerm = renderJSONTerm class JSONGraphTerm term where From b401da6c1fdbcd30141b11edf1d5ac7a9851c13a Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 21:58:15 -0400 Subject: [PATCH 64/84] Render diffs to JSON trees using an abstract interface. --- src/Semantic/Api/Diffs.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index 59018e423..ab8d4937c 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -60,14 +60,11 @@ parseDiffBuilder DiffShow = distributeFoldMap (doDiff (const id) showDiff parseDiffBuilder DiffDotGraph = distributeFoldMap (doDiff (const id) dotGraphDiff) jsonDiff :: DiffEffects sig m => BlobPair -> m (Rendering.JSON.JSON "diffs" SomeJSON) -jsonDiff blobPair = doDiff (const id) (renderJSONTree blobPair) blobPair `catchError` jsonError blobPair +jsonDiff blobPair = doDiff (const id) (pure . jsonTreeDiff blobPair) blobPair `catchError` jsonError blobPair jsonError :: Applicative m => BlobPair -> SomeException -> m (Rendering.JSON.JSON "diffs" SomeJSON) jsonError blobPair (SomeException e) = pure $ renderJSONDiffError blobPair (show e) -renderJSONTree :: (Applicative m, ToJSONFields1 syntax) => BlobPair -> Diff syntax Loc Loc -> m (Rendering.JSON.JSON "diffs" SomeJSON) -renderJSONTree blobPair = pure . renderJSONDiff blobPair - diffGraph :: (Traversable t, DiffEffects sig m) => t BlobPair -> m DiffTreeGraphResponse diffGraph blobs = DiffTreeGraphResponse . V.fromList . toList <$> distributeFor blobs go where @@ -95,6 +92,12 @@ class DOTGraphDiff diff where instance (ConstructorName syntax, Foldable syntax, Functor syntax) => DOTGraphDiff (Diff syntax) where dotGraphDiff = serialize (DOT (diffStyle "diffs")) . renderTreeGraph +class JSONTreeDiff diff where + jsonTreeDiff :: BlobPair -> diff Loc Loc -> Rendering.JSON.JSON "diffs" SomeJSON + +instance ToJSONFields1 syntax => JSONTreeDiff (Diff syntax) where + jsonTreeDiff = renderJSONDiff + class SExprDiff diff where sexprDiff :: (Carrier sig m, Member (Reader Config) sig) => diff Loc Loc -> m Builder From 8fc85e8f2bbb2f0dbe4ea46bdff6689b1731a426 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 22:02:50 -0400 Subject: [PATCH 65/84] Render diffs to JSON graphs using an abstract interface. --- src/Semantic/Api/Diffs.hs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index ab8d4937c..4e393a6d3 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -69,19 +69,13 @@ diffGraph :: (Traversable t, DiffEffects sig m) => t BlobPair -> m DiffTreeGraph diffGraph blobs = DiffTreeGraphResponse . V.fromList . toList <$> distributeFor blobs go where go :: DiffEffects sig m => BlobPair -> m DiffTreeFileGraph - go blobPair = doDiff (const id) render blobPair + go blobPair = doDiff (const id) (pure . jsonGraphDiff blobPair) blobPair `catchError` \(SomeException e) -> pure (DiffTreeFileGraph path lang mempty mempty (V.fromList [ParseError (T.pack (show e))])) where path = T.pack $ pathForBlobPair blobPair lang = bridging # languageForBlobPair blobPair - render :: (Foldable syntax, Functor syntax, ConstructorName syntax, Applicative m) => Diff syntax Loc Loc -> m DiffTreeFileGraph - render diff = - let graph = renderTreeGraph diff - toEdge (Edge (a, b)) = DiffTreeEdge (diffVertexId a) (diffVertexId b) - in pure $ DiffTreeFileGraph path lang (V.fromList (vertexList graph)) (V.fromList (fmap toEdge (edgeList graph))) mempty - type DiffEffects sig m = (Member (Error SomeException) sig, Member (Reader Config) sig, Member Telemetry sig, Member Distribute sig, Member Parse sig, Carrier sig m, MonadIO m) type Decorate a b = forall syntax . DiffActions syntax => Blob -> Term syntax a -> Term syntax b @@ -92,6 +86,17 @@ class DOTGraphDiff diff where instance (ConstructorName syntax, Foldable syntax, Functor syntax) => DOTGraphDiff (Diff syntax) where dotGraphDiff = serialize (DOT (diffStyle "diffs")) . renderTreeGraph +class JSONGraphDiff diff where + jsonGraphDiff :: BlobPair -> diff Loc Loc -> DiffTreeFileGraph + +instance (Foldable syntax, Functor syntax, ConstructorName syntax) => JSONGraphDiff (Diff syntax) where + jsonGraphDiff blobPair diff + = let graph = renderTreeGraph diff + toEdge (Edge (a, b)) = DiffTreeEdge (diffVertexId a) (diffVertexId b) + in DiffTreeFileGraph path lang (V.fromList (vertexList graph)) (V.fromList (fmap toEdge (edgeList graph))) mempty where + path = T.pack $ pathForBlobPair blobPair + lang = bridging # languageForBlobPair blobPair + class JSONTreeDiff diff where jsonTreeDiff :: BlobPair -> diff Loc Loc -> Rendering.JSON.JSON "diffs" SomeJSON From 7aa36de3f923acd1fc2643be413e0159abe758b0 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 22:05:29 -0400 Subject: [PATCH 66/84] Spacing. --- src/Semantic/Api/Diffs.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index 4e393a6d3..d60b2a00b 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -80,12 +80,14 @@ type DiffEffects sig m = (Member (Error SomeException) sig, Member (Reader Confi type Decorate a b = forall syntax . DiffActions syntax => Blob -> Term syntax a -> Term syntax b + class DOTGraphDiff diff where dotGraphDiff :: (Carrier sig m, Member (Reader Config) sig) => diff Loc Loc -> m Builder instance (ConstructorName syntax, Foldable syntax, Functor syntax) => DOTGraphDiff (Diff syntax) where dotGraphDiff = serialize (DOT (diffStyle "diffs")) . renderTreeGraph + class JSONGraphDiff diff where jsonGraphDiff :: BlobPair -> diff Loc Loc -> DiffTreeFileGraph @@ -97,24 +99,28 @@ instance (Foldable syntax, Functor syntax, ConstructorName syntax) => JSONGraphD path = T.pack $ pathForBlobPair blobPair lang = bridging # languageForBlobPair blobPair + class JSONTreeDiff diff where jsonTreeDiff :: BlobPair -> diff Loc Loc -> Rendering.JSON.JSON "diffs" SomeJSON instance ToJSONFields1 syntax => JSONTreeDiff (Diff syntax) where jsonTreeDiff = renderJSONDiff + class SExprDiff diff where sexprDiff :: (Carrier sig m, Member (Reader Config) sig) => diff Loc Loc -> m Builder instance (ConstructorName syntax, Foldable syntax, Functor syntax) => SExprDiff (Diff syntax) where sexprDiff = serialize (SExpression ByConstructorName) + class ShowDiff diff where showDiff :: (Carrier sig m, Member (Reader Config) sig) => diff Loc Loc -> m Builder instance Show1 syntax => ShowDiff (Diff syntax) where showDiff = serialize Show + class ( ConstructorName t , Diffable t , Eq1 t From 377d8248986632fabb8f322a02fb3df87e83b91f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 22:10:42 -0400 Subject: [PATCH 67/84] Use distinct type parameters for the annotations on either side. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to ensure that they’re handled soundly. --- src/Diffing/Algorithm/RWS.hs | 10 +++++----- src/Diffing/Interpreter.hs | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Diffing/Algorithm/RWS.hs b/src/Diffing/Algorithm/RWS.hs index ca6966cf8..5097a67c6 100644 --- a/src/Diffing/Algorithm/RWS.hs +++ b/src/Diffing/Algorithm/RWS.hs @@ -30,11 +30,11 @@ import Prologue type ComparabilityRelation syntax ann1 ann2 = forall a b. TermF syntax ann1 a -> TermF syntax ann2 b -> Bool rws :: (Foldable syntax, Functor syntax, Diffable syntax) - => ComparabilityRelation syntax (FeatureVector, ann) (FeatureVector, ann) - -> (Term syntax (FeatureVector, ann) -> Term syntax (FeatureVector, ann) -> Bool) - -> [Term syntax (FeatureVector, ann)] - -> [Term syntax (FeatureVector, ann)] - -> EditScript (Term syntax (FeatureVector, ann)) (Term syntax (FeatureVector, ann)) + => ComparabilityRelation syntax (FeatureVector, ann1) (FeatureVector, ann2) + -> (Term syntax (FeatureVector, ann1) -> Term syntax (FeatureVector, ann2) -> Bool) + -> [Term syntax (FeatureVector, ann1)] + -> [Term syntax (FeatureVector, ann2)] + -> EditScript (Term syntax (FeatureVector, ann1)) (Term syntax (FeatureVector, ann2)) rws _ _ as [] = This <$> as rws _ _ [] bs = That <$> bs rws canCompare _ [a] [b] = if canCompareTerms canCompare a b then [These a b] else [That b, This a] diff --git a/src/Diffing/Interpreter.hs b/src/Diffing/Interpreter.hs index aeb67c242..2c8e3bed9 100644 --- a/src/Diffing/Interpreter.hs +++ b/src/Diffing/Interpreter.hs @@ -16,30 +16,30 @@ import Prologue -- | Diff two à la carte terms recursively. diffTerms :: (Diffable syntax, Eq1 syntax, Hashable1 syntax, Traversable syntax) - => Term syntax ann - -> Term syntax ann - -> Diff.Diff syntax ann ann + => Term syntax ann1 + -> Term syntax ann2 + -> Diff.Diff syntax ann1 ann2 diffTerms t1 t2 = stripDiff (fromMaybe (Diff.replacing t1' t2') (run (runNonDetOnce (runDiff (algorithmForTerms t1' t2'))))) where (t1', t2') = ( defaultFeatureVectorDecorator t1 , defaultFeatureVectorDecorator t2) -- | Strips the head annotation off a diff annotated with non-empty records. stripDiff :: Functor syntax - => Diff.Diff syntax (FeatureVector, ann) (FeatureVector, ann) - -> Diff.Diff syntax ann ann + => Diff.Diff syntax (FeatureVector, ann1) (FeatureVector, ann2) + -> Diff.Diff syntax ann1 ann2 stripDiff = bimap snd snd -- | Diff a 'These' of terms. -diffTermPair :: (Diffable syntax, Eq1 syntax, Hashable1 syntax, Traversable syntax) => These (Term syntax ann) (Term syntax ann) -> Diff.Diff syntax ann ann +diffTermPair :: (Diffable syntax, Eq1 syntax, Hashable1 syntax, Traversable syntax) => These (Term syntax ann1) (Term syntax ann2) -> Diff.Diff syntax ann1 ann2 diffTermPair = these Diff.deleting Diff.inserting diffTerms -- | Run an 'Algorithm' to completion in an 'Alternative' context using the supplied comparability & equivalence relations. runDiff :: Algorithm - (Term syntax (FeatureVector, ann)) - (Term syntax (FeatureVector, ann)) - (Diff.Diff syntax (FeatureVector, ann) (FeatureVector, ann)) - (DiffC (Term syntax (FeatureVector, ann)) (Term syntax (FeatureVector, ann)) (Diff.Diff syntax (FeatureVector, ann) (FeatureVector, ann)) m) + (Term syntax (FeatureVector, ann1)) + (Term syntax (FeatureVector, ann2)) + (Diff.Diff syntax (FeatureVector, ann1) (FeatureVector, ann2)) + (DiffC (Term syntax (FeatureVector, ann1)) (Term syntax (FeatureVector, ann2)) (Diff.Diff syntax (FeatureVector, ann1) (FeatureVector, ann2)) m) result -> m result runDiff = runDiffC . runAlgorithm @@ -57,8 +57,8 @@ instance ( Alternative m , Traversable syntax ) => Carrier - (Diff (Term syntax (FeatureVector, ann)) (Term syntax (FeatureVector, ann)) (Diff.Diff syntax (FeatureVector, ann) (FeatureVector, ann)) :+: sig) - (DiffC (Term syntax (FeatureVector, ann)) (Term syntax (FeatureVector, ann)) (Diff.Diff syntax (FeatureVector, ann) (FeatureVector, ann)) m) where + (Diff (Term syntax (FeatureVector, ann1)) (Term syntax (FeatureVector, ann2)) (Diff.Diff syntax (FeatureVector, ann1) (FeatureVector, ann2)) :+: sig) + (DiffC (Term syntax (FeatureVector, ann1)) (Term syntax (FeatureVector, ann2)) (Diff.Diff syntax (FeatureVector, ann1) (FeatureVector, ann2)) m) where eff (L op) = case op of Diff t1 t2 k -> runDiff (algorithmForTerms t1 t2) <|> pure (Diff.replacing t1 t2) >>= k Linear (Term (In ann1 f1)) (Term (In ann2 f2)) k -> Diff.merge (ann1, ann2) <$> tryAlignWith (runDiff . diffThese) f1 f2 >>= k From 0c5342a030bb07a7634777b645f8fd8f961bbb2c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 22:12:18 -0400 Subject: [PATCH 68/84] Diff via an abstract interface. --- src/Diffing/Interpreter.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Diffing/Interpreter.hs b/src/Diffing/Interpreter.hs index 2c8e3bed9..75d64ef54 100644 --- a/src/Diffing/Interpreter.hs +++ b/src/Diffing/Interpreter.hs @@ -1,7 +1,7 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving, TypeOperators, UndecidableInstances #-} +{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-} module Diffing.Interpreter ( diffTerms -, diffTermPair +, DiffTerms(..) , stripDiff ) where @@ -29,9 +29,12 @@ stripDiff :: Functor syntax -> Diff.Diff syntax ann1 ann2 stripDiff = bimap snd snd --- | Diff a 'These' of terms. -diffTermPair :: (Diffable syntax, Eq1 syntax, Hashable1 syntax, Traversable syntax) => These (Term syntax ann1) (Term syntax ann2) -> Diff.Diff syntax ann1 ann2 -diffTermPair = these Diff.deleting Diff.inserting diffTerms +class DiffTerms term diff where + -- | Diff a 'These' of terms. + diffTermPair :: These (term ann1) (term ann2) -> diff ann1 ann2 + +instance (Diffable syntax, Eq1 syntax, Hashable1 syntax, Traversable syntax) => DiffTerms (Term syntax) (Diff.Diff syntax) where + diffTermPair = these Diff.deleting Diff.inserting diffTerms -- | Run an 'Algorithm' to completion in an 'Alternative' context using the supplied comparability & equivalence relations. From 68ea7e147dc0021a6e1d3d4bcbea00aa79d64e40 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 22:14:12 -0400 Subject: [PATCH 69/84] The diff & term types are mutually supporting. --- src/Diffing/Interpreter.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Diffing/Interpreter.hs b/src/Diffing/Interpreter.hs index 75d64ef54..0359952da 100644 --- a/src/Diffing/Interpreter.hs +++ b/src/Diffing/Interpreter.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-} +{-# LANGUAGE FunctionalDependencies, GeneralizedNewtypeDeriving, TypeOperators, UndecidableInstances #-} module Diffing.Interpreter ( diffTerms , DiffTerms(..) @@ -29,7 +29,7 @@ stripDiff :: Functor syntax -> Diff.Diff syntax ann1 ann2 stripDiff = bimap snd snd -class DiffTerms term diff where +class DiffTerms term diff | diff -> term, term -> diff where -- | Diff a 'These' of terms. diffTermPair :: These (term ann1) (term ann2) -> diff ann1 ann2 From 5fe4b1da749c38d0b291b09b28556756b9eb9cf9 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 22:23:15 -0400 Subject: [PATCH 70/84] :fire: withSomeTermPair. --- src/Semantic/Api/Diffs.hs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index d60b2a00b..45915f988 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -8,7 +8,6 @@ module Semantic.Api.Diffs , DiffEffects , SomeTermPair(..) - , withSomeTermPair ) where import Analysis.ConstructorName (ConstructorName) @@ -178,6 +177,3 @@ doParse blobPair decorate = case languageForBlobPair blobPair of data SomeTermPair typeclasses ann where SomeTermPair :: typeclasses syntax => Join These (Term syntax ann) -> SomeTermPair typeclasses ann - -withSomeTermPair :: (forall syntax . typeclasses syntax => Join These (Term syntax ann) -> a) -> SomeTermPair typeclasses ann -> a -withSomeTermPair with (SomeTermPair terms) = with terms From e5685f9f5c4b452f7bb8c7d5532564c48147bcb2 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 22:26:05 -0400 Subject: [PATCH 71/84] :fire: redundant parens. --- src/Semantic/Api/TOCSummaries.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Semantic/Api/TOCSummaries.hs b/src/Semantic/Api/TOCSummaries.hs index 8f3c31b1f..17bc39855 100644 --- a/src/Semantic/Api/TOCSummaries.hs +++ b/src/Semantic/Api/TOCSummaries.hs @@ -20,13 +20,13 @@ import Semantic.Proto.SemanticPB hiding (Blob, BlobPair) import Semantic.Task as Task import Serializing.Format -diffSummaryBuilder :: (DiffEffects sig m) => Format DiffTreeTOCResponse -> [BlobPair] -> m Builder +diffSummaryBuilder :: DiffEffects sig m => Format DiffTreeTOCResponse -> [BlobPair] -> m Builder diffSummaryBuilder format blobs = diffSummary blobs >>= serialize format -legacyDiffSummary :: (DiffEffects sig m) => [BlobPair] -> m Summaries +legacyDiffSummary :: DiffEffects sig m => [BlobPair] -> m Summaries legacyDiffSummary = distributeFoldMap go where - go :: (DiffEffects sig m) => BlobPair -> m Summaries + go :: DiffEffects sig m => BlobPair -> m Summaries go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (render blobPair) blobPair `catchError` \(SomeException e) -> pure $ Summaries mempty (Map.singleton path [toJSON (ErrorSummary (T.pack (show e)) lowerBound lang)]) @@ -36,10 +36,10 @@ legacyDiffSummary = distributeFoldMap go render :: (Foldable syntax, Functor syntax, Applicative m) => BlobPair -> Diff syntax (Maybe Declaration) (Maybe Declaration) -> m Summaries render blobPair = pure . renderToCDiff blobPair -diffSummary :: (DiffEffects sig m) => [BlobPair] -> m DiffTreeTOCResponse +diffSummary :: DiffEffects sig m => [BlobPair] -> m DiffTreeTOCResponse diffSummary blobs = DiffTreeTOCResponse . V.fromList <$> distributeFor blobs go where - go :: (DiffEffects sig m) => BlobPair -> m TOCSummaryFile + go :: DiffEffects sig m => BlobPair -> m TOCSummaryFile go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (render blobPair) blobPair `catchError` \(SomeException e) -> pure $ TOCSummaryFile path lang mempty (V.fromList [TOCSummaryError (T.pack (show e)) Nothing]) From f08ac25116ce4fb047a440874dc937eea5c4d44d Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 22:29:29 -0400 Subject: [PATCH 72/84] Summarize diffs using an abstract interface. --- src/Semantic/Api/TOCSummaries.hs | 35 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Semantic/Api/TOCSummaries.hs b/src/Semantic/Api/TOCSummaries.hs index 17bc39855..6f264521f 100644 --- a/src/Semantic/Api/TOCSummaries.hs +++ b/src/Semantic/Api/TOCSummaries.hs @@ -40,26 +40,29 @@ diffSummary :: DiffEffects sig m => [BlobPair] -> m DiffTreeTOCResponse diffSummary blobs = DiffTreeTOCResponse . V.fromList <$> distributeFor blobs go where go :: DiffEffects sig m => BlobPair -> m TOCSummaryFile - go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (render blobPair) blobPair + go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (pure . summarizeDiff blobPair) blobPair `catchError` \(SomeException e) -> pure $ TOCSummaryFile path lang mempty (V.fromList [TOCSummaryError (T.pack (show e)) Nothing]) where path = T.pack $ pathKeyForBlobPair blobPair lang = bridging # languageForBlobPair blobPair - render :: (Foldable syntax, Functor syntax, Applicative m) => BlobPair -> Diff syntax (Maybe Declaration) (Maybe Declaration) -> m TOCSummaryFile - render blobPair diff = pure $ foldr go (TOCSummaryFile path lang mempty mempty) (diffTOC diff) - where - path = T.pack $ pathKeyForBlobPair blobPair - lang = bridging # languageForBlobPair blobPair +class SummarizeDiff diff where + summarizeDiff :: BlobPair -> diff (Maybe Declaration) (Maybe Declaration) -> TOCSummaryFile - toChangeType = \case - "added" -> Added - "modified" -> Modified - "removed" -> Removed - _ -> None +instance (Foldable syntax, Functor syntax) => SummarizeDiff (Diff syntax) where + summarizeDiff blobPair diff = foldr go (TOCSummaryFile path lang mempty mempty) (diffTOC diff) + where + path = T.pack $ pathKeyForBlobPair blobPair + lang = bridging # languageForBlobPair blobPair - go :: TOCSummary -> TOCSummaryFile -> TOCSummaryFile - go TOCSummary{..} TOCSummaryFile{..} - = TOCSummaryFile path language (V.cons (TOCSummaryChange summaryCategoryName summaryTermName (converting #? summarySpan) (toChangeType summaryChangeType)) changes) errors - go ErrorSummary{..} TOCSummaryFile{..} - = TOCSummaryFile path language changes (V.cons (TOCSummaryError errorText (converting #? errorSpan)) errors) + toChangeType = \case + "added" -> Added + "modified" -> Modified + "removed" -> Removed + _ -> None + + go :: TOCSummary -> TOCSummaryFile -> TOCSummaryFile + go TOCSummary{..} TOCSummaryFile{..} + = TOCSummaryFile path language (V.cons (TOCSummaryChange summaryCategoryName summaryTermName (converting #? summarySpan) (toChangeType summaryChangeType)) changes) errors + go ErrorSummary{..} TOCSummaryFile{..} + = TOCSummaryFile path language changes (V.cons (TOCSummaryError errorText (converting #? errorSpan)) errors) From fea2338eae014add7379dd7e73a223fd076b7e7f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 22:43:43 -0400 Subject: [PATCH 73/84] :fire: renderToCTerm. --- src/Rendering/TOC.hs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Rendering/TOC.hs b/src/Rendering/TOC.hs index 207898e26..a371aff3c 100644 --- a/src/Rendering/TOC.hs +++ b/src/Rendering/TOC.hs @@ -1,7 +1,6 @@ {-# LANGUAGE DerivingVia, RankNTypes, ScopedTypeVariables #-} module Rendering.TOC ( renderToCDiff -, renderToCTerm , diffTOC , Summaries(..) , TOCSummary(..) @@ -143,15 +142,6 @@ renderToCDiff blobs = uncurry Summaries . bimap toMap toMap . List.partition isV diffTOC :: (Foldable f, Functor f) => Diff f (Maybe Declaration) (Maybe Declaration) -> [TOCSummary] diffTOC = fmap entrySummary . dedupe . tableOfContentsBy declaration -renderToCTerm :: (Foldable f, Functor f) => Blob -> Term f (Maybe Declaration) -> Summaries -renderToCTerm b@Blob{..} = uncurry Summaries . bimap toMap toMap . List.partition isValidSummary . termToC - where - toMap [] = mempty - toMap as = Map.singleton (T.pack (blobPath b)) (toJSON <$> as) - - termToC :: (Foldable f, Functor f) => Term f (Maybe Declaration) -> [TOCSummary] - termToC = fmap (recordSummary "unchanged") . termTableOfContentsBy declaration - -- The user-facing category name toCategoryName :: Declaration -> T.Text toCategoryName declaration = case declaration of From 08247c7444bd7cf46b845331343f65b47d8afe7d Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 22:56:41 -0400 Subject: [PATCH 74/84] Summarize diffs legacy-wise using an abstract interface. --- src/Semantic/Api/TOCSummaries.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Semantic/Api/TOCSummaries.hs b/src/Semantic/Api/TOCSummaries.hs index 6f264521f..eab9f6c3a 100644 --- a/src/Semantic/Api/TOCSummaries.hs +++ b/src/Semantic/Api/TOCSummaries.hs @@ -27,14 +27,17 @@ legacyDiffSummary :: DiffEffects sig m => [BlobPair] -> m Summaries legacyDiffSummary = distributeFoldMap go where go :: DiffEffects sig m => BlobPair -> m Summaries - go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (render blobPair) blobPair + go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (pure . legacySummarizeDiff blobPair) blobPair `catchError` \(SomeException e) -> pure $ Summaries mempty (Map.singleton path [toJSON (ErrorSummary (T.pack (show e)) lowerBound lang)]) where path = T.pack $ pathKeyForBlobPair blobPair lang = languageForBlobPair blobPair - render :: (Foldable syntax, Functor syntax, Applicative m) => BlobPair -> Diff syntax (Maybe Declaration) (Maybe Declaration) -> m Summaries - render blobPair = pure . renderToCDiff blobPair +class LegacySummarizeDiff diff where + legacySummarizeDiff :: BlobPair -> diff (Maybe Declaration) (Maybe Declaration) -> Summaries + +instance (Foldable syntax, Functor syntax) => LegacySummarizeDiff (Diff syntax) where + legacySummarizeDiff = renderToCDiff diffSummary :: DiffEffects sig m => [BlobPair] -> m DiffTreeTOCResponse diffSummary blobs = DiffTreeTOCResponse . V.fromList <$> distributeFor blobs go From bc62f324df94bf6adf5a8c187d8ebafe6f6e0c46 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 23:32:48 -0400 Subject: [PATCH 75/84] Diff using an abstract interface. --- src/Semantic/Api/Diffs.hs | 97 ++++++++++++++++++++++---------- src/Semantic/Api/TOCSummaries.hs | 35 +----------- 2 files changed, 71 insertions(+), 61 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index 45915f988..57887e89a 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE GADTs, ConstraintKinds, TypeOperators, RankNTypes, UndecidableInstances #-} +{-# LANGUAGE GADTs, ConstraintKinds, FunctionalDependencies, LambdaCase, RankNTypes, TypeOperators, UndecidableInstances #-} module Semantic.Api.Diffs ( parseDiffBuilder , DiffOutputFormat(..) @@ -8,10 +8,14 @@ module Semantic.Api.Diffs , DiffEffects , SomeTermPair(..) + + , LegacySummarizeDiff(..) + , SummarizeDiff(..) ) where import Analysis.ConstructorName (ConstructorName) -import Analysis.TOCSummary (HasDeclaration) +import Analysis.Decorator (decoratorWithAlgebra) +import Analysis.TOCSummary (Declaration, HasDeclaration, declarationAlgebra) import Control.Effect.Error import Control.Effect.Parse import Control.Effect.Reader @@ -27,13 +31,13 @@ import Data.Language import Data.Term import qualified Data.Text as T import qualified Data.Vector as V -import Diffing.Algorithm (Diffable) -import Diffing.Interpreter (diffTermPair) +import Diffing.Interpreter (DiffTerms(..)) import Parsing.Parser import Prologue import Rendering.Graph import Rendering.JSON hiding (JSON) import qualified Rendering.JSON +import Rendering.TOC import Semantic.Api.Bridge import Semantic.Config import Semantic.Proto.SemanticPB hiding (Blob, BlobPair) @@ -77,7 +81,7 @@ diffGraph blobs = DiffTreeGraphResponse . V.fromList . toList <$> distributeFor type DiffEffects sig m = (Member (Error SomeException) sig, Member (Reader Config) sig, Member Telemetry sig, Member Distribute sig, Member Parse sig, Carrier sig m, MonadIO m) -type Decorate a b = forall syntax . DiffActions syntax => Blob -> Term syntax a -> Term syntax b +type Decorate a b = forall term diff . DiffActions term diff => Blob -> term a -> term b class DOTGraphDiff diff where @@ -120,31 +124,66 @@ instance Show1 syntax => ShowDiff (Diff syntax) where showDiff = serialize Show -class ( ConstructorName t - , Diffable t - , Eq1 t - , HasDeclaration t - , Hashable1 t - , Show1 t - , Traversable t - , ToJSONFields1 t +class LegacySummarizeDiff term diff | diff -> term, term -> diff where + legacyDecorateTerm :: Blob -> term Loc -> term (Maybe Declaration) + legacySummarizeDiff :: BlobPair -> diff (Maybe Declaration) (Maybe Declaration) -> Summaries + +instance (Foldable syntax, Functor syntax, HasDeclaration syntax) => LegacySummarizeDiff (Term syntax) (Diff syntax) where + legacyDecorateTerm = decoratorWithAlgebra . declarationAlgebra + legacySummarizeDiff = renderToCDiff + + +class SummarizeDiff term diff | diff -> term, term -> diff where + decorateTerm :: Blob -> term Loc -> term (Maybe Declaration) + summarizeDiff :: BlobPair -> diff (Maybe Declaration) (Maybe Declaration) -> TOCSummaryFile + +instance (Foldable syntax, Functor syntax, HasDeclaration syntax) => SummarizeDiff (Term syntax) (Diff syntax) where + decorateTerm = decoratorWithAlgebra . declarationAlgebra + summarizeDiff blobPair diff = foldr go (TOCSummaryFile path lang mempty mempty) (diffTOC diff) + where + path = T.pack $ pathKeyForBlobPair blobPair + lang = bridging # languageForBlobPair blobPair + + toChangeType = \case + "added" -> Added + "modified" -> Modified + "removed" -> Removed + _ -> None + + go :: TOCSummary -> TOCSummaryFile -> TOCSummaryFile + go TOCSummary{..} TOCSummaryFile{..} + = TOCSummaryFile path language (V.cons (TOCSummaryChange summaryCategoryName summaryTermName (converting #? summarySpan) (toChangeType summaryChangeType)) changes) errors + go ErrorSummary{..} TOCSummaryFile{..} + = TOCSummaryFile path language changes (V.cons (TOCSummaryError errorText (converting #? errorSpan)) errors) + + +class ( Bifoldable diff + , DiffTerms term diff + , DOTGraphDiff diff + , JSONGraphDiff diff + , JSONTreeDiff diff + , SExprDiff diff + , ShowDiff diff + , LegacySummarizeDiff term diff + , SummarizeDiff term diff ) - => DiffActions t -instance ( ConstructorName t - , Diffable t - , Eq1 t - , HasDeclaration t - , Hashable1 t - , Show1 t - , Traversable t - , ToJSONFields1 t + => DiffActions term diff +instance ( Bifoldable diff + , DiffTerms term diff + , DOTGraphDiff diff + , JSONGraphDiff diff + , JSONTreeDiff diff + , SExprDiff diff + , ShowDiff diff + , LegacySummarizeDiff term diff + , SummarizeDiff term diff ) - => DiffActions t + => DiffActions term diff doDiff :: DiffEffects sig m => Decorate Loc ann - -> (forall syntax . DiffActions syntax => Diff syntax ann ann -> m output) + -> (forall term diff . DiffActions term diff => diff ann ann -> m output) -> BlobPair -> m output doDiff decorate render blobPair = do @@ -152,15 +191,15 @@ doDiff decorate render blobPair = do diff <- diffTerms blobPair terms render diff -diffTerms :: (DiffActions syntax, Member Telemetry sig, Carrier sig m, MonadIO m) - => BlobPair -> Join These (Term syntax ann) -> m (Diff syntax ann ann) +diffTerms :: (DiffActions term diff, Member Telemetry sig, Carrier sig m, MonadIO m) + => BlobPair -> Join These (term ann) -> m (diff ann ann) diffTerms blobs terms = time "diff" languageTag $ do let diff = diffTermPair (runJoin terms) diff <$ writeStat (Stat.count "diff.nodes" (bilength diff) languageTag) where languageTag = languageTagForBlobPair blobs doParse :: (Member (Error SomeException) sig, Member Distribute sig, Member Parse sig, Carrier sig m) - => BlobPair -> Decorate Loc ann -> m (SomeTermPair DiffActions ann) + => BlobPair -> Decorate Loc ann -> m (SomeTermPair ann) doParse blobPair decorate = case languageForBlobPair blobPair of Go -> SomeTermPair <$> distributeFor blobPair (\ blob -> decorate blob <$> parse goParser blob) Haskell -> SomeTermPair <$> distributeFor blobPair (\ blob -> decorate blob <$> parse haskellParser blob) @@ -175,5 +214,5 @@ doParse blobPair decorate = case languageForBlobPair blobPair of PHP -> SomeTermPair <$> distributeFor blobPair (\ blob -> decorate blob <$> parse phpParser blob) _ -> noLanguageForBlob (pathForBlobPair blobPair) -data SomeTermPair typeclasses ann where - SomeTermPair :: typeclasses syntax => Join These (Term syntax ann) -> SomeTermPair typeclasses ann +data SomeTermPair ann where + SomeTermPair :: DiffActions term diff => Join These (term ann) -> SomeTermPair ann diff --git a/src/Semantic/Api/TOCSummaries.hs b/src/Semantic/Api/TOCSummaries.hs index eab9f6c3a..7d7c9bee5 100644 --- a/src/Semantic/Api/TOCSummaries.hs +++ b/src/Semantic/Api/TOCSummaries.hs @@ -1,14 +1,11 @@ -{-# LANGUAGE GADTs, TypeOperators, DerivingStrategies, LambdaCase #-} +{-# LANGUAGE TypeOperators #-} module Semantic.Api.TOCSummaries (diffSummary, legacyDiffSummary, diffSummaryBuilder) where -import Analysis.Decorator (decoratorWithAlgebra) -import Analysis.TOCSummary (Declaration, declarationAlgebra) import Control.Effect.Error import Control.Lens import Data.Aeson import Data.Blob import Data.ByteString.Builder -import Data.Diff import qualified Data.Map.Monoidal as Map import qualified Data.Text as T import qualified Data.Vector as V @@ -27,45 +24,19 @@ legacyDiffSummary :: DiffEffects sig m => [BlobPair] -> m Summaries legacyDiffSummary = distributeFoldMap go where go :: DiffEffects sig m => BlobPair -> m Summaries - go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (pure . legacySummarizeDiff blobPair) blobPair + go blobPair = doDiff legacyDecorateTerm (pure . legacySummarizeDiff blobPair) blobPair `catchError` \(SomeException e) -> pure $ Summaries mempty (Map.singleton path [toJSON (ErrorSummary (T.pack (show e)) lowerBound lang)]) where path = T.pack $ pathKeyForBlobPair blobPair lang = languageForBlobPair blobPair -class LegacySummarizeDiff diff where - legacySummarizeDiff :: BlobPair -> diff (Maybe Declaration) (Maybe Declaration) -> Summaries - -instance (Foldable syntax, Functor syntax) => LegacySummarizeDiff (Diff syntax) where - legacySummarizeDiff = renderToCDiff diffSummary :: DiffEffects sig m => [BlobPair] -> m DiffTreeTOCResponse diffSummary blobs = DiffTreeTOCResponse . V.fromList <$> distributeFor blobs go where go :: DiffEffects sig m => BlobPair -> m TOCSummaryFile - go blobPair = doDiff (\ blob -> decoratorWithAlgebra (declarationAlgebra blob)) (pure . summarizeDiff blobPair) blobPair + go blobPair = doDiff decorateTerm (pure . summarizeDiff blobPair) blobPair `catchError` \(SomeException e) -> pure $ TOCSummaryFile path lang mempty (V.fromList [TOCSummaryError (T.pack (show e)) Nothing]) where path = T.pack $ pathKeyForBlobPair blobPair lang = bridging # languageForBlobPair blobPair - -class SummarizeDiff diff where - summarizeDiff :: BlobPair -> diff (Maybe Declaration) (Maybe Declaration) -> TOCSummaryFile - -instance (Foldable syntax, Functor syntax) => SummarizeDiff (Diff syntax) where - summarizeDiff blobPair diff = foldr go (TOCSummaryFile path lang mempty mempty) (diffTOC diff) - where - path = T.pack $ pathKeyForBlobPair blobPair - lang = bridging # languageForBlobPair blobPair - - toChangeType = \case - "added" -> Added - "modified" -> Modified - "removed" -> Removed - _ -> None - - go :: TOCSummary -> TOCSummaryFile -> TOCSummaryFile - go TOCSummary{..} TOCSummaryFile{..} - = TOCSummaryFile path language (V.cons (TOCSummaryChange summaryCategoryName summaryTermName (converting #? summarySpan) (toChangeType summaryChangeType)) changes) errors - go ErrorSummary{..} TOCSummaryFile{..} - = TOCSummaryFile path language changes (V.cons (TOCSummaryError errorText (converting #? errorSpan)) errors) From c847990bd63591e85c89d19229eec2387d70d437 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 1 Oct 2019 23:33:11 -0400 Subject: [PATCH 76/84] :fire: a redundant language pragma. --- src/Semantic/Api/TOCSummaries.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Semantic/Api/TOCSummaries.hs b/src/Semantic/Api/TOCSummaries.hs index 7d7c9bee5..9af3fc53a 100644 --- a/src/Semantic/Api/TOCSummaries.hs +++ b/src/Semantic/Api/TOCSummaries.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE TypeOperators #-} module Semantic.Api.TOCSummaries (diffSummary, legacyDiffSummary, diffSummaryBuilder) where import Control.Effect.Error From 9b1c99f15918d6df301cce45734adacd9bc119a5 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 2 Oct 2019 08:47:59 -0400 Subject: [PATCH 77/84] :fire: redundant language extensions. --- src/Semantic/Api/Terms.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index d8fc41f09..be6bd532a 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, MonoLocalBinds, RankNTypes, TypeOperators, UndecidableInstances #-} +{-# LANGUAGE ConstraintKinds, MonoLocalBinds, RankNTypes, UndecidableInstances #-} module Semantic.Api.Terms ( termGraph , parseTermBuilder From 8af41587e42c9bd599673d03e74930bccbdc1fab Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 2 Oct 2019 09:13:41 -0400 Subject: [PATCH 78/84] :fire: more redundant language extensions. --- src/Semantic/Api/Symbols.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Semantic/Api/Symbols.hs b/src/Semantic/Api/Symbols.hs index 921d8fcd2..9aabbe786 100644 --- a/src/Semantic/Api/Symbols.hs +++ b/src/Semantic/Api/Symbols.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE ConstraintKinds, MonoLocalBinds, RankNTypes, TypeOperators #-} +{-# LANGUAGE MonoLocalBinds, RankNTypes #-} module Semantic.Api.Symbols ( legacyParseSymbols , parseSymbols From 764710260c8a6e979e959141a3175edc1d0e0f83 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 2 Oct 2019 09:14:43 -0400 Subject: [PATCH 79/84] :fire: yet more redundant language extensions. --- src/Semantic/Api/Diffs.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index 57887e89a..acea2eaef 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE GADTs, ConstraintKinds, FunctionalDependencies, LambdaCase, RankNTypes, TypeOperators, UndecidableInstances #-} +{-# LANGUAGE GADTs, ConstraintKinds, FunctionalDependencies, LambdaCase, RankNTypes, UndecidableInstances #-} module Semantic.Api.Diffs ( parseDiffBuilder , DiffOutputFormat(..) From 1fdecb0abb4b4782ffaed2ff011e0e328f2b5fe2 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 2 Oct 2019 09:19:47 -0400 Subject: [PATCH 80/84] =?UTF-8?q?Redefine=20TermActions=20as=20a=20constra?= =?UTF-8?q?int=20synonym=20since=20we=E2=80=99re=20specialized=20to=20it.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Semantic/Api/Terms.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Semantic/Api/Terms.hs b/src/Semantic/Api/Terms.hs index be6bd532a..75f95f293 100644 --- a/src/Semantic/Api/Terms.hs +++ b/src/Semantic/Api/Terms.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE ConstraintKinds, MonoLocalBinds, RankNTypes, UndecidableInstances #-} +{-# LANGUAGE ConstraintKinds, MonoLocalBinds, RankNTypes #-} module Semantic.Api.Terms ( termGraph , parseTermBuilder @@ -128,8 +128,7 @@ instance (Foldable syntax, Functor syntax, ConstructorName syntax) => JSONGraphT lang = bridging # blobLanguage blob -class (DOTGraphTerm t, JSONGraphTerm t, JSONTreeTerm t, SExprTerm t, ShowTerm t) => TermActions t -instance (DOTGraphTerm t, JSONGraphTerm t, JSONTreeTerm t, SExprTerm t, ShowTerm t) => TermActions t +type TermActions t = (DOTGraphTerm t, JSONGraphTerm t, JSONTreeTerm t, SExprTerm t, ShowTerm t) doParse :: ( Carrier sig m From 9f68d5b6c5559cf0e4bf4f3286892fd82a11ecc0 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 2 Oct 2019 09:21:08 -0400 Subject: [PATCH 81/84] Redefine DiffActions as a constraint synonym. --- src/Semantic/Api/Diffs.hs | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/Semantic/Api/Diffs.hs b/src/Semantic/Api/Diffs.hs index acea2eaef..5eb41b112 100644 --- a/src/Semantic/Api/Diffs.hs +++ b/src/Semantic/Api/Diffs.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE GADTs, ConstraintKinds, FunctionalDependencies, LambdaCase, RankNTypes, UndecidableInstances #-} +{-# LANGUAGE GADTs, ConstraintKinds, FunctionalDependencies, LambdaCase, RankNTypes #-} module Semantic.Api.Diffs ( parseDiffBuilder , DiffOutputFormat(..) @@ -157,28 +157,17 @@ instance (Foldable syntax, Functor syntax, HasDeclaration syntax) => SummarizeDi = TOCSummaryFile path language changes (V.cons (TOCSummaryError errorText (converting #? errorSpan)) errors) -class ( Bifoldable diff - , DiffTerms term diff - , DOTGraphDiff diff - , JSONGraphDiff diff - , JSONTreeDiff diff - , SExprDiff diff - , ShowDiff diff - , LegacySummarizeDiff term diff - , SummarizeDiff term diff - ) - => DiffActions term diff -instance ( Bifoldable diff - , DiffTerms term diff - , DOTGraphDiff diff - , JSONGraphDiff diff - , JSONTreeDiff diff - , SExprDiff diff - , ShowDiff diff - , LegacySummarizeDiff term diff - , SummarizeDiff term diff - ) - => DiffActions term diff +type DiffActions term diff = + ( Bifoldable diff + , DiffTerms term diff + , DOTGraphDiff diff + , JSONGraphDiff diff + , JSONTreeDiff diff + , SExprDiff diff + , ShowDiff diff + , LegacySummarizeDiff term diff + , SummarizeDiff term diff + ) doDiff :: DiffEffects sig m From 7312997f299140af90e7e05eee1296599cfb14b2 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 2 Oct 2019 09:59:21 -0400 Subject: [PATCH 82/84] :fire: a redundant import. --- semantic-python/test/Directive.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/semantic-python/test/Directive.hs b/semantic-python/test/Directive.hs index d9ed052a2..c3a0cfcdc 100644 --- a/semantic-python/test/Directive.hs +++ b/semantic-python/test/Directive.hs @@ -13,7 +13,6 @@ import qualified Data.Core.Parser as Core.Parser import qualified Data.Core.Pretty as Core.Pretty import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as ByteString -import Data.List.NonEmpty (NonEmpty) import System.Process import qualified Text.Trifecta as Trifecta From eb922e7e01e7e68d2a3bc574a372445fdc3c85a4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 2 Oct 2019 09:59:26 -0400 Subject: [PATCH 83/84] :fire: a redundant binding. --- 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 f24b684dc..cfa758739 100644 --- a/semantic-python/test/Instances.hs +++ b/semantic-python/test/Instances.hs @@ -35,7 +35,7 @@ instance ToJSON1 Named where -- The correct thing to do here is to manually munge the bytestring -- together as a builder, but we don't even hit this code path, -- so it will do for now. - liftToEncoding f _ (Named name a) = f a + liftToEncoding f _ (Named _ a) = f a instance ToJSON2 Incr where liftToJSON2 f _ g _ = \case From 714aac1eea609793a458ad5832c5fdc987baeb9a Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 2 Oct 2019 10:01:41 -0400 Subject: [PATCH 84/84] Fix the tests. --- test/Tags/Spec.hs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/Tags/Spec.hs b/test/Tags/Spec.hs index 90c235805..24089583c 100644 --- a/test/Tags/Spec.hs +++ b/test/Tags/Spec.hs @@ -10,40 +10,40 @@ spec = do describe "go" $ do it "produces tags for functions with docs" $ do (blob, tree) <- parseTestFile goParser (Path.relFile "test/fixtures/go/tags/simple_functions.go") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "TestFromBits" Function (Span (Pos 6 1) (Pos 8 2)) "func TestFromBits(t *testing.T) {" (Just "// TestFromBits ...") , Tag "Hi" Function (Span (Pos 10 1) (Pos 11 2)) "func Hi()" Nothing ] it "produces tags for methods" $ do (blob, tree) <- parseTestFile goParser (Path.relFile "test/fixtures/go/tags/method.go") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "CheckAuth" Method (Span (Pos 3 1) (Pos 3 100)) "func (c *apiClient) CheckAuth(req *http.Request, user, repo string) (*authenticatedActor, error)" Nothing] it "produces tags for calls" $ do (blob, tree) <- parseTestFile goParser (Path.relFile "test/fixtures/go/tags/simple_functions.go") - runTagging blob ["Call"] tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) ["Call"] tree `shouldBe` [ Tag "Hi" Call (Span (Pos 7 2) (Pos 7 6)) "Hi()" Nothing] describe "javascript and typescript" $ do it "produces tags for functions with docs" $ do (blob, tree) <- parseTestFile typescriptParser (Path.relFile "test/fixtures/javascript/tags/simple_function_with_docs.js") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "myFunction" Function (Span (Pos 2 1) (Pos 4 2)) "function myFunction()" (Just "// This is myFunction") ] it "produces tags for classes" $ do (blob, tree) <- parseTestFile typescriptParser (Path.relFile "test/fixtures/typescript/tags/class.ts") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "FooBar" Class (Span (Pos 1 1) (Pos 1 16)) "class FooBar" Nothing ] it "produces tags for modules" $ do (blob, tree) <- parseTestFile typescriptParser (Path.relFile "test/fixtures/typescript/tags/module.ts") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "APromise" Tags.Module (Span (Pos 1 1) (Pos 1 20)) "module APromise { }" Nothing ] describe "python" $ do it "produces tags for functions" $ do (blob, tree) <- parseTestFile pythonParser (Path.relFile "test/fixtures/python/tags/simple_functions.py") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "Foo" Function (Span (Pos 1 1) (Pos 5 17)) "def Foo(x):" Nothing , Tag "Bar" Function (Span (Pos 7 1) (Pos 11 13)) "def Bar():" Nothing , Tag "local" Function (Span (Pos 8 5) (Pos 9 17)) "def local():" Nothing @@ -51,30 +51,30 @@ spec = do it "produces tags for functions with docs" $ do (blob, tree) <- parseTestFile pythonParser (Path.relFile "test/fixtures/python/tags/simple_function_with_docs.py") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "Foo" Function (Span (Pos 1 1) (Pos 3 13)) "def Foo(x):" (Just "\"\"\"This is the foo function\"\"\"") ] it "produces tags for classes" $ do (blob, tree) <- parseTestFile pythonParser (Path.relFile "test/fixtures/python/tags/class.py") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "Foo" Class (Span (Pos 1 1) (Pos 5 17)) "class Foo:" (Just "\"\"\"The Foo class\"\"\"") , Tag "f" Function (Span (Pos 3 5) (Pos 5 17)) "def f(self):" (Just "\"\"\"The f method\"\"\"") ] it "produces tags for multi-line functions" $ do (blob, tree) <- parseTestFile pythonParser (Path.relFile "test/fixtures/python/tags/multiline.py") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "Foo" Function (Span (Pos 1 1) (Pos 3 13)) "def Foo(x," Nothing ] describe "ruby" $ do it "produces tags for methods" $ do (blob, tree) <- parseTestFile rubyParser (Path.relFile "test/fixtures/ruby/tags/simple_method.rb") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "foo" Method (Span (Pos 1 1) (Pos 4 4)) "def foo" Nothing ] it "produces tags for sends" $ do (blob, tree) <- parseTestFile rubyParser (Path.relFile "test/fixtures/ruby/tags/simple_method.rb") - runTagging blob ["Send"] tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) ["Send"] tree `shouldBe` [ Tag "puts" Call (Span (Pos 2 3) (Pos 2 12)) "puts \"hi\"" Nothing , Tag "bar" Call (Span (Pos 3 3) (Pos 3 8)) "a.bar" Nothing , Tag "a" Call (Span (Pos 3 3) (Pos 3 4)) "a" Nothing @@ -82,17 +82,17 @@ spec = do it "produces tags for methods with docs" $ do (blob, tree) <- parseTestFile rubyParser (Path.relFile "test/fixtures/ruby/tags/simple_method_with_docs.rb") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "foo" Method (Span (Pos 2 1) (Pos 3 4)) "def foo" (Just "# Public: foo") ] it "correctly tags files containing multibyte UTF-8 characters" $ do (blob, tree) <- parseTestFile rubyParser (Path.relFile "test/fixtures/ruby/tags/unicode_identifiers.rb") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "日本語" Method (Span (Pos 2 1) (Pos 4 4)) "def 日本語" (Just "# coding: utf-8")] it "produces tags for methods and classes with docs" $ do (blob, tree) <- parseTestFile rubyParser (Path.relFile "test/fixtures/ruby/tags/class_module.rb") - runTagging blob symbolsToSummarize tree `shouldBe` + runTagging (blobLanguage blob) (blobSource blob) symbolsToSummarize tree `shouldBe` [ Tag "Foo" Tags.Module (Span (Pos 2 1 ) (Pos 12 4)) "module Foo" (Just "# Public: Foo") , Tag "Bar" Class (Span (Pos 5 3 ) (Pos 11 6)) "class Bar" (Just "# Public: Bar") , Tag "baz" Method (Span (Pos 8 5 ) (Pos 10 8)) "def baz(a)" (Just "# Public: baz")