-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Analysis effects #379
Analysis effects #379
Changes from 250 commits
3aa3cb5
4f44170
f0739bb
ec94b7d
131c804
7809bd2
6305e66
d8955fd
06ea57e
e58db3d
778f84b
5fef326
9e472c5
0f7be20
eb591f9
6e1383d
d70a169
17da79f
961bf62
6359d96
d23f34b
b1c2f26
ab5b566
2502370
e992998
05de03e
b2a329c
5b8364c
c3327fa
08e1061
aaa4f65
1b8dafc
a17a682
8f50312
327208e
9327861
8127690
ec53cd9
309b5fd
6199c15
29d6654
ca50eb2
d5b180b
641b989
42b7e77
3e987cc
9303d7e
07568e5
a667c65
a55972e
1098d95
664c730
d4190dd
e4caca6
3721ccb
a3e7d51
40d3e5e
24f6159
7208186
99a84e5
20555fc
722e405
6b6581d
c9161d5
ca3bb15
9822b4e
2d362d9
3bafe21
e5bfa87
4b0af27
a5e1d5e
2059137
23d1c84
ea2b679
4811add
cd5165c
95298aa
9f26a4c
9672556
0e69c0a
98acd3a
924e0d0
29b1170
398d377
2f676e8
535ec05
71e4981
50e123a
814f6fe
18bc19a
630759d
a3775a1
4962104
6191f2e
611ae5f
f03de00
d06d73c
b33c694
1b61ce5
e9b6658
56b30e4
f8c26e7
02ae8de
23c65d5
7f6680d
daa24d1
b4c4ddc
f8b1b28
14ff797
ef44b29
812a123
903e73c
374f90d
e8a4749
7b9e1c0
6e1503c
180af3f
d4a1080
0dd17dc
34f3297
445737a
fd19464
4a0aa12
4185f21
27559f8
56cc4e1
4ede4ae
ee8017d
38e42c0
9918460
da11239
34a0afb
a468a66
9a3e06b
d113cc4
a8d670c
fbd86f3
0fc9f5d
aac1c92
3ecb198
8cca0f1
ff4523e
667f894
6485f85
cfc8bdf
63427b9
443b4ca
f85c31c
1d292b0
a60380a
1832212
9f2a2fc
039148a
a3ccc12
1bc3c65
e546950
cb2a995
76c56e3
6810624
c4db1c9
f68bce1
cc403af
4485d36
fdb0f51
d22039b
f7c2c74
e78cc7b
c3b632f
da63c0c
d93686e
585b05f
e518beb
de09619
1f9e0fa
387824a
a64c337
b013780
8743374
875a408
964d8e2
ac274cb
c707fe5
abd647e
6e5cb7f
b007c9d
db5ef7b
3be6999
0f7188a
fec21c7
17a6f02
3ff821b
3f23042
1872847
3003f3f
bcb4eb9
0f030b3
00e506c
89d7bd5
f00affb
2e3713d
26cf1d3
2bbd2e0
3f43fb7
cd96cdb
582c71f
37e5ba4
c05904c
59e5839
624483b
53dda90
10386f7
7418fba
2052c70
580525a
38da7a4
850811b
96f5204
a50ab43
2fe68f3
1948e2b
0860180
d876d01
1e1bd83
1828a1a
58f6298
5093315
7c9c5f0
537f3c3
935fe94
a45de13
c04c59d
3821557
f305c38
8894d73
540b88c
bfec95a
f78d90a
f5efb6a
75a63dd
6612273
c07324f
a167ded
a6fe9b7
1a67082
d278a01
e34444e
29e09be
55e573e
f5c8346
4022643
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,7 +173,7 @@ steps: | |
# `{-#LANGUAGE #-}'. | ||
# | ||
# Default: vertical. | ||
style: compact | ||
style: vertical | ||
|
||
# Align affects alignment of closing pragma brackets. | ||
# | ||
|
@@ -183,7 +183,7 @@ steps: | |
# between actual import and closing bracket. | ||
# | ||
# Default: true | ||
align: true | ||
align: false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This formats {-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
… |
||
|
||
# stylish-haskell can detect redundancy of some language pragmas. If this | ||
# is set to true, it will remove those redundant pragmas. Default: true. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,6 @@ ghc_version="$(ghc --numeric-version)" | |
# recent hie-bios requires us to output to the file at $HIE_BIOS_OUTPUT, but older builds & script/repl don’t set that var, so we default it to stdout | ||
output_file="${HIE_BIOS_OUTPUT:-/dev/stdout}" | ||
|
||
# do a build of dependencies up front to ensure they’re all available | ||
cabal v2-build -v0 all --only-dependencies | ||
|
||
Comment on lines
-13
to
-15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This didn’t work out as well as I’d hoped—the silent build means that you can get I’ve moved this to |
||
build_products_dir="dist-newstyle/build/x86_64-osx/ghc-$ghc_version/build-repl" | ||
|
||
function flags { | ||
|
@@ -43,6 +40,7 @@ function flags { | |
echo "-isemantic-java/src" | ||
echo "-isemantic-json/src" | ||
echo "-isemantic-python/src" | ||
echo "-isemantic-python/test" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This lets |
||
echo "-isemantic-ruby/src" | ||
echo "-isemantic-tags/src" | ||
echo "-iapp" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,8 @@ set -e | |
|
||
cd "$(dirname "$0")/.." | ||
|
||
# do a build of dependencies up front to ensure they’re all available | ||
cabal v2-build all --enable-benchmarks --enable-tests --only-dependencies | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition to moving this back here and removing the |
||
|
||
# exec ghci with the appropriate flags, and without the $GHC_ENVIRONMENT variable interfering | ||
cabal v2-exec env -- -u GHC_ENVIRONMENT ghci -ghci-script=.ghci.repl $(script/ghci-flags) -no-ignore-dot-ghci $@ |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-} | ||
module Analysis.Carrier.Env.Monovariant | ||
( -- * Env carrier | ||
EnvC(..) | ||
-- * Env effect | ||
, module Analysis.Effect.Env | ||
) where | ||
|
||
import Analysis.Effect.Env | ||
import Analysis.Name | ||
import Control.Algebra | ||
import qualified Control.Monad.Fail as Fail | ||
|
||
newtype EnvC m a = EnvC { runEnv :: m a } | ||
deriving (Applicative, Functor, Monad, Fail.MonadFail) | ||
|
||
instance Algebra sig m | ||
=> Algebra (Env Name :+: sig) (EnvC m) where | ||
alg (L (Alloc name k)) = k name | ||
alg (L (Bind _ _ m k)) = m >>= k | ||
alg (L (Lookup name k)) = k (Just name) | ||
alg (R other) = EnvC (alg (handleCoercible other)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-} | ||
module Analysis.Carrier.Env.Precise | ||
( -- * Env carrier | ||
EnvC(..) | ||
-- * Env effect | ||
, A.alloc | ||
, A.bind | ||
, A.lookupEnv | ||
, A.Env(..) | ||
) where | ||
|
||
import qualified Analysis.Effect.Env as A | ||
import Analysis.Name | ||
import Control.Algebra | ||
import Control.Effect.Fresh | ||
import Control.Effect.Reader | ||
import qualified Control.Monad.Fail as Fail | ||
import qualified Data.Map as Map | ||
|
||
type Precise = Int | ||
type Env = Map.Map Name Precise | ||
|
||
newtype EnvC m a = EnvC { runEnv :: m a } | ||
deriving (Applicative, Functor, Monad, Fail.MonadFail) | ||
|
||
instance ( Has Fresh sig m | ||
, Has (Reader Env) sig m | ||
) | ||
=> Algebra (A.Env Precise :+: sig) (EnvC m) where | ||
alg (L (A.Alloc _ k)) = fresh >>= k | ||
alg (L (A.Bind name addr m k)) = local (Map.insert name addr) m >>= k | ||
alg (L (A.Lookup name k)) = asks (Map.lookup name) >>= k | ||
alg (R other) = EnvC (alg (handleCoercible other)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-} | ||
module Analysis.Carrier.Heap.Monovariant | ||
( -- * Heap carrier | ||
HeapC(..) | ||
-- * Heap effect | ||
, module Analysis.Effect.Heap | ||
) where | ||
Comment on lines
+2
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Factoring this out means that the abstract analyses get to share a lot of code. |
||
|
||
import Analysis.Effect.Heap | ||
import Control.Applicative (Alternative) | ||
import Control.Algebra | ||
import Control.Effect.State | ||
import Control.Monad ((>=>)) | ||
import qualified Control.Monad.Fail as Fail | ||
import Data.List.NonEmpty (nonEmpty) | ||
import qualified Data.Map as Map | ||
import Data.Monoid (Alt(..)) | ||
import qualified Data.Set as Set | ||
|
||
newtype HeapC addr value m a = HeapC { runHeap :: m a } | ||
deriving (Alternative, Applicative, Functor, Monad, Fail.MonadFail) | ||
|
||
instance ( Alternative m | ||
, Has (State (Map.Map addr (Set.Set value))) sig m | ||
, Ord addr | ||
, Ord value | ||
) | ||
=> Algebra (Heap addr value :+: sig) (HeapC addr value m) where | ||
alg (L (Deref addr k)) = gets (Map.lookup addr >=> nonEmpty . Set.toList) >>= maybe (pure Nothing) (getAlt . foldMap (Alt . pure . Just)) >>= k | ||
alg (L (Assign addr value k)) = modify (Map.insertWith (<>) addr (Set.singleton value)) >> k | ||
alg (R other) = HeapC (alg (handleCoercible other)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-} | ||
module Analysis.Carrier.Heap.Precise | ||
( -- * Heap carrier | ||
runHeap | ||
, HeapC(..) | ||
-- * Heap effect | ||
, module Analysis.Effect.Heap | ||
) where | ||
|
||
import Analysis.Effect.Heap | ||
import Control.Algebra | ||
import Control.Carrier.State.Strict | ||
import qualified Control.Monad.Fail as Fail | ||
import qualified Data.IntMap as IntMap | ||
|
||
type Precise = Int | ||
|
||
runHeap :: HeapC value m a -> m (IntMap.IntMap value, a) | ||
runHeap (HeapC m) = runState mempty m | ||
|
||
newtype HeapC value m a = HeapC (StateC (IntMap.IntMap value) m a) | ||
deriving (Applicative, Functor, Monad, Fail.MonadFail) | ||
|
||
instance (Algebra sig m, Effect sig) | ||
=> Algebra (Heap Precise value :+: State (IntMap.IntMap value) :+: sig) (HeapC value m) where | ||
alg (L (Deref addr k)) = HeapC (gets (IntMap.lookup addr)) >>= k | ||
alg (L (Assign addr value k)) = HeapC (modify (IntMap.insert addr value)) >> k | ||
alg (R other) = HeapC (alg (handleCoercible other)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semantic-ast
depends onpretty-simple
now, which makes it much more challenging to use-package pretty-simple
in your~/.ghci
file sinceghci
“helpfully” ends up loading it twice.You can avoid that issue by using
-package-id
, at the cost of having to keep that up to date wheneversemantic
gets an updated version of it.I’m not happy with this, but I don’t know a better means of doing this aside from e.g. introducing a new registered package which nothing in
semantic
depends on just to re-exportpretty-simple
’s interface, or using a different pretty-printer insemantic
than used in the REPL.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes! We should probably submit a bug somewhere to somebody?