Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit dbf8941

Browse files
committed
Merge branch 'master' into sequence-values-in-the-abstract-domain
2 parents 0f34dce + fb1c27b commit dbf8941

File tree

19 files changed

+148
-104
lines changed

19 files changed

+148
-104
lines changed

.ghci

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22
:set -package pretty-show -package hscolour
33

44
-- See docs/💡ProTip!.md
5-
:undef pretty
6-
:def pretty \ _ -> return ":set -interactive-print Semantic.Util.Pretty.prettyShow"
7-
8-
-- See docs/💡ProTip!.md
9-
:undef no-pretty
10-
:def no-pretty \_ -> return ":set -interactive-print System.IO.print"
11-
12-
-- See docs/💡ProTip!.md
13-
:undef r
14-
:def r \_ -> return (unlines [":reload", ":pretty"])
5+
:def! pretty \ _ -> return ":set -interactive-print Semantic.Util.Pretty.prettyShow"
6+
:def! no-pretty \_ -> return ":set -interactive-print System.IO.print"
7+
:def! r \_ -> return (unlines [":reload", ":pretty"])
158

169
-- See docs/💡ProTip!.md for documentation & examples.
1710
:{
@@ -29,8 +22,7 @@ assignmentExample lang = case lang of
2922
_ -> mk "" ""
3023
where mk fileExtension parser = putStrLn ("example: fmap (() <$) . runTask . parse " ++ parser ++ "Parser =<< Semantic.Util.blob \"example." ++ fileExtension ++ "\"") >> return ("import Parsing.Parser\nimport Semantic.Task\nimport Semantic.Util")
3124
:}
32-
:undef assignment
33-
:def assignment assignmentExample
25+
:def! assignment assignmentExample
3426

3527
-- Enable breaking on errors for code written in the repl.
3628
:seti -fbreak-on-error

script/publish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
set -e
77
cd $(dirname "$0")/..
88

9-
VERSION="0.6.0"
9+
VERSION="0.7.0.0"
1010
BUILD_SHA=$(git rev-parse HEAD 2>/dev/null)
1111
DOCKER_IMAGE=docker.pkg.github.com/github/semantic/semantic
1212

semantic-core/src/Analysis/Concrete.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE DerivingVia, FlexibleContexts, FlexibleInstances, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, OverloadedStrings, RecordWildCards, TypeOperators, UndecidableInstances #-}
1+
{-# LANGUAGE DerivingVia, FlexibleContexts, FlexibleInstances, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, OverloadedStrings, RecordWildCards, TypeApplications, TypeOperators, UndecidableInstances #-}
22
module Analysis.Concrete
33
( Concrete(..)
44
, concrete
@@ -86,7 +86,7 @@ runFile :: ( Carrier sig m
8686
runFile file = traverse run file
8787
where run = runReader (fileLoc file)
8888
. runFailWithLoc
89-
. runReader (mempty :: Env)
89+
. runReader @Env mempty
9090
. fix (eval concreteAnalysis)
9191

9292
concreteAnalysis :: ( Carrier sig m
@@ -166,7 +166,7 @@ heapGraph vertex edge h = foldr (uncurry graph) G.empty (IntMap.toList h)
166166
Bool _ -> G.empty
167167
String _ -> G.empty
168168
Closure _ _ _ env -> foldr (G.overlay . edge (Left Lexical)) G.empty env
169-
Record frame -> foldr (G.overlay . uncurry (edge . Right)) G.empty (Map.toList frame)
169+
Record frame -> Map.foldrWithKey (\ k -> G.overlay . edge (Right k)) G.empty frame
170170

171171
heapValueGraph :: Heap -> G.Graph Concrete
172172
heapValueGraph h = heapGraph (const id) (const fromAddr) h

semantic-core/src/Data/Core.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ do' bindings = fromMaybe unit (foldr bind Nothing bindings)
143143
where bind (n :<- a) v = maybe (a >>>) ((>>>=) . (:<- a)) n <$> v <|> Just a
144144

145145
unstatements :: (Member Core sig, RightModule sig) => Term sig a -> (Stack (Maybe (Named (Either Int a)) :<- Term sig (Either Int a)), Term sig (Either Int a))
146-
unstatements = un (unstatement . Left) . fmap Right
146+
unstatements = unprefix (unstatement . Left) . fmap Right
147147

148148
data a :<- b = a :<- b
149149
deriving (Eq, Foldable, Functor, Ord, Show, Traversable)

semantic-core/src/Data/Core/Parser.hs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Data.Core.Parser
1111

1212
import Control.Applicative
1313
import qualified Data.Char as Char
14-
import Data.Core (Core)
14+
import Data.Core ((:<-) (..), Core)
1515
import qualified Data.Core as Core
1616
import Data.Foldable (foldl')
1717
import Data.Name
@@ -53,7 +53,8 @@ expr :: (TokenParsing m, Monad m) => m (Term Core User)
5353
expr = ifthenelse <|> lambda <|> rec <|> load <|> assign
5454

5555
assign :: (TokenParsing m, Monad m) => m (Term Core User)
56-
assign = application <**> (flip (Core..=) <$ symbolic '=' <*> application <|> pure id) <?> "assignment"
56+
assign = application <**> (symbolic '=' *> rhs <|> pure id) <?> "assignment"
57+
where rhs = flip (Core..=) <$> application
5758

5859
application :: (TokenParsing m, Monad m) => m (Term Core User)
5960
application = projection `chainl1` (pure (Core.$$))
@@ -72,10 +73,10 @@ atom = choice
7273
comp :: (TokenParsing m, Monad m) => m (Term Core User)
7374
comp = braces (Core.do' <$> sepEndByNonEmpty statement semi) <?> "compound statement"
7475

75-
statement :: (TokenParsing m, Monad m) => m (Maybe (Named User) Core.:<- Term Core User)
76+
statement :: (TokenParsing m, Monad m) => m (Maybe (Named User) :<- Term Core User)
7677
statement
77-
= try ((Core.:<-) . Just <$> name <* symbol "<-" <*> expr)
78-
<|> (Nothing Core.:<-) <$> expr
78+
= try ((:<-) . Just <$> name <* symbol "<-" <*> expr)
79+
<|> (Nothing :<-) <$> expr
7980
<?> "statement"
8081

8182
ifthenelse :: (TokenParsing m, Monad m) => m (Term Core User)
@@ -109,14 +110,8 @@ lit = let x `given` n = x <$ reserved n in choice
109110
, Core.bool False `given` "#false"
110111
, Core.unit `given` "#unit"
111112
, record
112-
, token (between (string "\"") (string "\"") (Core.string . fromString <$> many (escape <|> (noneOf "\"" <?> "non-escaped character"))))
113+
, Core.string <$> stringLiteral
113114
] <?> "literal"
114-
where escape = char '\\' *> choice
115-
[ '"' <$ string "\""
116-
, '\n' <$ string "n"
117-
, '\r' <$ string "r"
118-
, '\t' <$ string "t"
119-
] <?> "escape sequence"
120115

121116
record :: (TokenParsing m, Monad m) => m (Term Core User)
122117
record = Core.record <$ reserved "#record" <*> braces (sepEndBy ((,) <$> identifier <* symbolic ':' <*> expr) comma)

semantic-core/src/Data/Scope.hs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ module Data.Scope
1212
, instantiate1
1313
, instantiate
1414
, instantiateEither
15-
, un
16-
, unEither
15+
, unprefix
16+
, unprefixEither
1717
) where
1818

1919
import Control.Applicative (liftA2)
@@ -110,11 +110,23 @@ instantiateEither :: Monad f => (Either a b -> f c) -> Scope a f b -> f c
110110
instantiateEither f = unScope >=> incr (f . Left) (>>= f . Right)
111111

112112

113-
un :: (Int -> t -> Maybe (a, t)) -> t -> (Stack a, t)
114-
un from = unEither (matchMaybe . from)
115-
116-
unEither :: (Int -> t -> Either (a, t) b) -> t -> (Stack a, b)
117-
unEither from = go (0 :: Int) Nil
113+
-- | Unwrap a (possibly-empty) prefix of @a@s wrapping a @t@ using a helper function.
114+
--
115+
-- This allows us to peel a prefix of syntax, typically binders, off of a term, returning a stack of prefixing values (e.g. variables) and the outermost subterm rejected by the function.
116+
unprefix
117+
:: (Int -> t -> Maybe (a, t)) -- ^ A function taking the 0-based index into the prefix & the current term, and optionally returning a pair of the prefixing value and the inner subterm.
118+
-> t -- ^ The initial term.
119+
-> (Stack a, t) -- ^ A stack of prefixing values & the final subterm.
120+
unprefix from = unprefixEither (matchMaybe . from)
121+
122+
-- | Unwrap a (possibly-empty) prefix of @a@s wrapping a @b@ within a @t@ using a helper function.
123+
--
124+
-- Compared to 'unprefix', this allows the helper function to extract inner terms of a different type, for example when @t@ is a right @b@-module.
125+
unprefixEither
126+
:: (Int -> t -> Either (a, t) b) -- ^ A function taking the 0-based index into the prefix & the current term, and returning either a pair of the prefixing value and the next inner subterm of type @t@, or the final inner subterm of type @b@.
127+
-> t -- ^ The initial term.
128+
-> (Stack a, b) -- ^ A stack of prefixing values & the final subterm.
129+
unprefixEither from = go (0 :: Int) Nil
118130
where go i bs t = case from i t of
119131
Left (b, t) -> go (succ i) (bs :> b) t
120132
Right b -> (bs, b)

semantic.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 2.4
22

33
name: semantic
4-
version: 0.6.0.0
4+
version: 0.7.0.0
55
synopsis: Framework and executable for analyzing and diffing untrusted code.
66
description: Semantic is a library for parsing, analyzing, and comparing source code across many languages.
77
homepage: http://github.com/github/semantic#readme

src/Data/Abstract/Address/Monovariant.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Data.Abstract.Name
99
import qualified Data.Set as Set
1010
import Prologue
1111

12-
-- | 'Monovariant' models using one address for a particular name. It trackes the set of values that a particular address takes and uses it's name to lookup in the store and only allocation if new.
12+
-- | 'Monovariant' models using one address for a particular name. It tracks the set of values that a particular address takes and uses it's name to lookup in the store and only allocation if new.
1313
newtype Monovariant = Monovariant { unMonovariant :: Name }
1414
deriving (Eq, Ord)
1515

src/Data/Abstract/ScopeGraph.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ instance Ord AccessControl where
7676
(<=) Private _ = True
7777
(<=) _ Private = False
7878

79-
-- | Protected AccessControl is inbetween Private and Public in the order specification.
79+
-- | Protected AccessControl is in between Private and Public in the order specification.
8080
-- Protected AccessControl "on the left" has access to Protected or Public AccessControls "on the right".
8181
(<=) Protected Public = True
8282
(<=) Protected Protected = True

src/Data/Blob/IO.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ readBlobsFromDir path = liftIO . fmap catMaybes $
3939
findFilesInDir path supportedExts mempty >>= Async.mapConcurrently (readBlobFromFile . fileForPath)
4040

4141
-- | Read all blobs from the Git repo with Language.supportedExts
42-
readBlobsFromGitRepo :: MonadIO m => FilePath -> Git.OID -> [FilePath] -> m [Blob]
43-
readBlobsFromGitRepo path oid excludePaths = liftIO . fmap catMaybes $
42+
readBlobsFromGitRepo :: MonadIO m => FilePath -> Git.OID -> [FilePath] -> [FilePath] -> m [Blob]
43+
readBlobsFromGitRepo path oid excludePaths includePaths = liftIO . fmap catMaybes $
4444
Git.lsTree path oid >>= Async.mapConcurrently (blobFromTreeEntry path)
4545
where
4646
-- Only read tree entries that are normal mode, non-minified blobs in a language we can parse.
@@ -50,6 +50,7 @@ readBlobsFromGitRepo path oid excludePaths = liftIO . fmap catMaybes $
5050
, lang `elem` codeNavLanguages
5151
, not (pathIsMinified path)
5252
, path `notElem` excludePaths
53+
, null includePaths || path `elem` includePaths
5354
= Just . sourceBlob' path lang oid . fromText <$> Git.catFile gitDir oid
5455
blobFromTreeEntry _ _ = pure Nothing
5556

0 commit comments

Comments
 (0)