Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
c0ecbb1
:fire: SomeParser.
robrix Oct 1, 2019
e9fc612
Don’t pass the blob into tagging.
robrix Oct 1, 2019
de5de5f
Don’t pass the blob into contextualizing.
robrix Oct 1, 2019
937df79
Don’t pass the blob into runTagging.
robrix Oct 1, 2019
1bc2511
Generalize renderPreciseToSymbols to any term with a ToTags instance.
robrix Oct 1, 2019
09f95d6
Define a helper to provide a ToTags instance for à la carte terms.
robrix Oct 1, 2019
a43e947
Render à la carte terms to symbols via ToTags.
robrix Oct 1, 2019
44b0614
Define renderToSymbols using renderPreciseToSymbols.
robrix Oct 1, 2019
7259059
Combine the code paths.
robrix Oct 1, 2019
f092a30
Parameterize ALaCarteTerm by the symbols to summarize.
robrix Oct 1, 2019
f9c20bc
Use ToTags for the legacy tagging API as well.
robrix Oct 1, 2019
371e0c0
renderToSymbols is pure.
robrix Oct 1, 2019
11091cf
Generalize renderToSymbols for legacy tagging.
robrix Oct 1, 2019
785d523
Copy in our own version of doParse & SomeTerm.
robrix Oct 1, 2019
152e94a
doParse handles the PerLanguageModes.
robrix Oct 1, 2019
0f8da48
Don’t specialize parseSymbols for the PerLanguageModes.
robrix Oct 1, 2019
598dce7
:fire: ParseEffects.
robrix Oct 1, 2019
05e0086
Factor out the term construction.
robrix Oct 1, 2019
5de3d14
:fire: the HasTextElement & Taggable obligations from TermConstraints.
robrix Oct 1, 2019
a97e42a
Simplify the Traversable obligation down to just Foldable/Functor.
robrix Oct 1, 2019
5c6df16
Move SomeTerm/withSomeTerm into Semantic.Api.Terms.
robrix Oct 1, 2019
cca474b
:fire: the Declarations1 obligation.
robrix Oct 1, 2019
7aaaa64
:fire: redundant parens.
robrix Oct 1, 2019
02f46c6
Define TermConstraints as a class.
robrix Oct 1, 2019
13e3788
Reformat the signature for doParse.
robrix Oct 1, 2019
5e1b21c
Export ToSExpression.
robrix Oct 1, 2019
7101733
Reformat the doParse signature.
robrix Oct 1, 2019
a060a15
Align all the blobs.
robrix Oct 1, 2019
6f5e2ff
Eliminate the term directly in doParse.
robrix Oct 1, 2019
19ac4d2
Align the blobs.
robrix Oct 1, 2019
e727b3c
Eliminate the terms directly in doParse.
robrix Oct 1, 2019
197ffdd
Refactor sexpTerm to eliminate the parse.
robrix Oct 1, 2019
41a61e3
Specialize sexpTerm to Term.
robrix Oct 1, 2019
8c6bf14
Factor the parse out of showTerm.
robrix Oct 1, 2019
12a07c2
Factor the parse out of dotGraphTerm.
robrix Oct 1, 2019
2f77374
Define a class abstracting term showing.
robrix Oct 1, 2019
0cc79bb
Define a class abstract s-expression serialization.
robrix Oct 1, 2019
97400fb
Define a class abstracting DOT graphing.
robrix Oct 1, 2019
c6cfa94
Use the abstracted definitions.
robrix Oct 1, 2019
897304c
Use the abstract definitions directly.
robrix Oct 1, 2019
bf26428
Abstract JSON term serialization.
robrix Oct 1, 2019
9d4b7ce
Use the abstract interface for timing.
robrix Oct 1, 2019
51dbc97
Abstract rendering terms to JSON graphs.
robrix Oct 1, 2019
50105fd
Express all the necessary constraints over terms, not syntax.
robrix Oct 1, 2019
3c37459
Spacing.
robrix Oct 1, 2019
aab52d5
:fire: redundant parens.
robrix Oct 1, 2019
235b2e8
Abstract doParse over the constraints.
robrix Oct 1, 2019
7b256bf
Define a ShowTerm instance for precise Python terms.
robrix Oct 1, 2019
f9e05fc
:fire: a redundant language extension.
robrix Oct 1, 2019
f644a45
Export less.
robrix Oct 1, 2019
2034359
Resume grouping the constraints up.
robrix Oct 1, 2019
8184742
Rename JSONTerm to JSONTreeTerm.
robrix Oct 1, 2019
4843d44
Merge branch 'master' into abstract-actions-over-terms
robrix Oct 2, 2019
fdb6d96
Use a class to constrain diffable terms.
robrix Oct 2, 2019
6050f10
:fire: redundant parens.
robrix Oct 2, 2019
05103d8
Reformat the doDiff signature.
robrix Oct 2, 2019
64c2287
Move the BlobPair to the final position.
robrix Oct 2, 2019
bc13823
Don’t pass the BlobPair to the render function.
robrix Oct 2, 2019
972653a
Show diffs via an abstracted interface.
robrix Oct 2, 2019
868bde8
:fire: the CanDiff constraint synonym in favour of DiffActions.
robrix Oct 2, 2019
cc77d7b
Render diffs to s-expressions using an abstracted interface.
robrix Oct 2, 2019
bda1269
Render diffs to DOT graphs using an abstract interface.
robrix Oct 2, 2019
c0278a9
Factor the JSON renderer into jsonDiff.
robrix Oct 2, 2019
bf14a4f
Rename jsonTerm' to jsonTreeTerm.
robrix Oct 2, 2019
b401da6
Render diffs to JSON trees using an abstract interface.
robrix Oct 2, 2019
8fc85e8
Render diffs to JSON graphs using an abstract interface.
robrix Oct 2, 2019
7aa36de
Spacing.
robrix Oct 2, 2019
377d824
Use distinct type parameters for the annotations on either side.
robrix Oct 2, 2019
0c5342a
Diff via an abstract interface.
robrix Oct 2, 2019
68ea7e1
The diff & term types are mutually supporting.
robrix Oct 2, 2019
5fe4b1d
:fire: withSomeTermPair.
robrix Oct 2, 2019
e5685f9
:fire: redundant parens.
robrix Oct 2, 2019
f08ac25
Summarize diffs using an abstract interface.
robrix Oct 2, 2019
fea2338
:fire: renderToCTerm.
robrix Oct 2, 2019
08247c7
Summarize diffs legacy-wise using an abstract interface.
robrix Oct 2, 2019
bc62f32
Diff using an abstract interface.
robrix Oct 2, 2019
c847990
:fire: a redundant language pragma.
robrix Oct 2, 2019
ab72710
Merge branch 'master' into abstract-actions-over-terms
robrix Oct 2, 2019
9b1c99f
:fire: redundant language extensions.
robrix Oct 2, 2019
8af4158
:fire: more redundant language extensions.
robrix Oct 2, 2019
7647102
:fire: yet more redundant language extensions.
robrix Oct 2, 2019
1fdecb0
Redefine TermActions as a constraint synonym since we’re specialized …
robrix Oct 2, 2019
9f68d5b
Redefine DiffActions as a constraint synonym.
robrix Oct 2, 2019
7312997
:fire: a redundant import.
robrix Oct 2, 2019
eb922e7
:fire: a redundant binding.
robrix Oct 2, 2019
714aac1
Fix the tests.
robrix Oct 2, 2019
7d93f39
Merge branch 'master' into abstract-actions-over-terms
Oct 2, 2019
ca2f8a6
Merge branch 'master' into abstract-actions-over-terms
Oct 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion semantic-python/test/Instances.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Control/Carrier/Parse/Measured.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing was using this.

where languageTag = [("language" :: String, show (blobLanguage blob))]

data ParserCancelled = ParserTimedOut | AssignmentTimedOut
Expand Down
1 change: 0 additions & 1 deletion src/Control/Carrier/Parse/Simple.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/Diffing/Algorithm/RWS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use distinct type parameters for the annotations on either side of the diffing process to guarantee we don’t get them crossed.

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]
Expand Down
35 changes: 19 additions & 16 deletions src/Diffing/Interpreter.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# LANGUAGE GeneralizedNewtypeDeriving, TypeOperators, UndecidableInstances #-}
{-# LANGUAGE FunctionalDependencies, GeneralizedNewtypeDeriving, TypeOperators, UndecidableInstances #-}
module Diffing.Interpreter
( diffTerms
, diffTermPair
, DiffTerms(..)
, stripDiff
) where

Expand All @@ -16,30 +16,33 @@ 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 = these Diff.deleting Diff.inserting diffTerms
class DiffTerms term diff | diff -> term, term -> diff where
-- | Diff a 'These' of terms.
diffTermPair :: These (term ann1) (term ann2) -> diff ann1 ann2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstracting diffing over the term & diff types allows us to express the operation over à la carte & precise terms uniformly (when precise terms support diffing).


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.
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
Expand All @@ -57,8 +60,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
Expand Down
11 changes: 1 addition & 10 deletions src/Parsing/Parser.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, GADTs, RankNTypes, ScopedTypeVariables, TypeFamilies, TypeOperators #-}
module Parsing.Parser
( Parser(..)
, SomeTerm(..)
, withSomeTerm
, SomeAnalysisParser(..)
, SomeASTParser(..)
, someASTParser
Expand Down Expand Up @@ -112,8 +110,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
Expand Down Expand Up @@ -168,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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only Semantic.Api.Terms was using this, so I moved it in there (and eventually deleted it).


-- | A parser for producing specialized (tree-sitter) ASTs.
data SomeASTParser where
SomeASTParser :: (Bounded grammar, Enum grammar, Show grammar)
Expand Down
10 changes: 0 additions & 10 deletions src/Rendering/TOC.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{-# LANGUAGE DerivingVia, RankNTypes, ScopedTypeVariables #-}
module Rendering.TOC
( renderToCDiff
, renderToCTerm
, diffTOC
, Summaries(..)
, TOCSummary(..)
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused.


-- The user-facing category name
toCategoryName :: Declaration -> T.Text
toCategoryName declaration = case declaration of
Expand Down
Loading