Skip to content
Snippets Groups Projects
Commit b1e72cbd authored by chrg's avatar chrg
Browse files

Let's try this

parent 36ccf237
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import Criterion.Main import Criterion.Main
import Control.DeepSeq
import qualified Language.C as C import qualified Language.C as C
import qualified Language.C.System.GCC as C import qualified Language.C.System.GCC as C
import ReduceC import ReduceC
...@@ -17,6 +18,10 @@ main = do ...@@ -17,6 +18,10 @@ main = do
in bgroup in bgroup
"clang-26760" "clang-26760"
[ bench "extract" $ nf IRTree.extract r [ bench "extract" $ nf IRTree.extract r
, bench "probe 11" $ nf (`IRTree.probe` "11") r , bench "probe 11" $ nf (\r -> let (i, _, _) = IRTree.probe r "11" in i) r
, bench "reduce true" $
nfAppIO
(IRTree.reduceAdaptive (\_ i -> i `deepseq` pure True))
r
] ]
] ]
...@@ -53,7 +53,6 @@ process sev p ma = do ...@@ -53,7 +53,6 @@ process sev p ma = do
data Mode data Mode
= Lin = Lin
| Exp | Exp
| Fib
deriving (Show, Read, Eq, Ord, Enum) deriving (Show, Read, Eq, Ord, Enum)
run :: (HasCallStack) => Parser (IO ()) run :: (HasCallStack) => Parser (IO ())
...@@ -62,8 +61,8 @@ run = do ...@@ -62,8 +61,8 @@ run = do
option auto $ option auto $
fold fold
[ long "mode" [ long "mode"
, help "search mode (Lin, Exp, Fib)" , help "search mode (Lin, Exp)"
, value Lin , value Exp
] ]
checkmode <- checkmode <-
...@@ -150,18 +149,18 @@ run = do ...@@ -150,18 +149,18 @@ run = do
liftIO exitFailure liftIO exitFailure
check' f l c = process D "Checking predictate" do check' f l c = process D "Checking predictate" do
let xs = NE.nonEmpty (filter fst l) let xs = NE.nonEmpty (filter ((RPath.Yes ==) . RPath.choice) l)
logInfo logInfo
( "Checking D=" ( "Checking D="
<> Text.pack (show (maybe 0 NE.length xs)) <> Text.pack (show (RPath.numberOfUndecided l) <> "/" <> show (length l))
<> ": " <> ": "
<> Text.pack (maybe "-" ((\(r, p) -> r <> " at " <> show p) . snd . NE.last) xs) <> Text.pack (maybe "-" ((\(r, p) -> r <> " at " <> show p) . RPath.label . NE.last) xs)
) )
when debug do when debug do
pPrint (void c) pPrint (void c)
when pedandic do when pedandic do
liftIO $ copyFile f (f <.> "last") liftIO $ copyFile f (f <.> "last")
logDebug (Text.pack . show $ RPath.fromChoiceList $ map fst l) -- logDebug (Text.pack . show $ RPath.fromChoiceList $ map fst l)
output f c output f c
v <- validiate f v <- validiate f
res <- res <-
...@@ -220,24 +219,18 @@ run = do ...@@ -220,24 +219,18 @@ run = do
l <- l <-
c & fix \rec prevc -> do c & fix \rec prevc -> do
mc' <- c' <-
( case mode of ( case mode of
Lin -> IRTree.reduce Lin -> IRTree.reduce
Exp -> IRTree.reduceExp Exp -> IRTree.reduceAdaptive
Fib -> IRTree.reduceFib
) )
(check' file) (check' file)
(ReduceC.defaultReduceC prevc) (ReduceC.defaultReduceC prevc)
case mc' of
Just c' ->
if fixpoint && (c' $> ()) /= (prevc $> ()) if fixpoint && (c' $> ()) /= (prevc $> ())
then do then do
logInfo "Running again until fixpoint" logInfo "Running again until fixpoint"
rec c' rec c'
else pure c' else pure c'
Nothing -> do
logError "Was unable to produce any output"
cleanup file
when pedandic do when pedandic do
liftIO $ copyFile file (file <.> "last") liftIO $ copyFile file (file <.> "last")
......
...@@ -5,7 +5,7 @@ name: rtree-c ...@@ -5,7 +5,7 @@ name: rtree-c
# category: categories # category: categories
# extra-source-files: [] # extra-source-files: []
ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-auto ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-late
dependencies: dependencies:
- base >= 4.9 && < 5 - base >= 4.9 && < 5
...@@ -83,3 +83,4 @@ benchmarks: ...@@ -83,3 +83,4 @@ benchmarks:
- filepath - filepath
- typed-process - typed-process
- text - text
- deepseq
...@@ -15,7 +15,7 @@ library ...@@ -15,7 +15,7 @@ library
Paths_rtree_c Paths_rtree_c
hs-source-dirs: hs-source-dirs:
src src
ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-auto ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-late
build-depends: build-depends:
base >=4.9 && <5 base >=4.9 && <5
, containers , containers
...@@ -34,7 +34,7 @@ executable rtree-c ...@@ -34,7 +34,7 @@ executable rtree-c
Paths_rtree_c Paths_rtree_c
hs-source-dirs: hs-source-dirs:
bin/ bin/
ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-auto ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-late
build-depends: build-depends:
base >=4.9 && <5 base >=4.9 && <5
, co-log , co-log
...@@ -64,7 +64,7 @@ test-suite rtree-c-test ...@@ -64,7 +64,7 @@ test-suite rtree-c-test
Paths_rtree_c Paths_rtree_c
hs-source-dirs: hs-source-dirs:
test/src test/src
ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-auto ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-late
build-depends: build-depends:
base >=4.9 && <5 base >=4.9 && <5
, containers , containers
...@@ -93,7 +93,7 @@ benchmark rtree-c-bench ...@@ -93,7 +93,7 @@ benchmark rtree-c-bench
Paths_rtree_c Paths_rtree_c
hs-source-dirs: hs-source-dirs:
bench/ bench/
ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-auto -O2 -threaded ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-late -O2 -threaded
build-depends: build-depends:
base >=4.9 && <5 base >=4.9 && <5
, containers , containers
...@@ -119,11 +119,12 @@ benchmark rtree-c-profile ...@@ -119,11 +119,12 @@ benchmark rtree-c-profile
Paths_rtree_c Paths_rtree_c
hs-source-dirs: hs-source-dirs:
bench/ bench/
ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-auto -O -threaded -fprof-late "-with-rtsopts=-N -p -s -hc -i0.1 -L500" ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-late -O -threaded -fprof-late "-with-rtsopts=-N -p -s -hc -i0.1 -L500"
build-depends: build-depends:
base >=4.9 && <5 base >=4.9 && <5
, containers , containers
, criterion , criterion
, deepseq
, directory , directory
, filepath , filepath
, language-c , language-c
......
...@@ -5,7 +5,7 @@ name: rtree ...@@ -5,7 +5,7 @@ name: rtree
# category: categories # category: categories
# extra-source-files: [] # extra-source-files: []
ghc-options: -Wall -fno-warn-incomplete-uni-patterns ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-late
dependencies: dependencies:
- base >= 4.9 && < 5 - base >= 4.9 && < 5
......
...@@ -19,7 +19,7 @@ library ...@@ -19,7 +19,7 @@ library
Paths_rtree Paths_rtree
hs-source-dirs: hs-source-dirs:
src src
ghc-options: -Wall -fno-warn-incomplete-uni-patterns ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-late
build-depends: build-depends:
base >=4.9 && <5 base >=4.9 && <5
, containers , containers
...@@ -41,7 +41,7 @@ test-suite rtree-test ...@@ -41,7 +41,7 @@ test-suite rtree-test
Paths_rtree Paths_rtree
hs-source-dirs: hs-source-dirs:
test/src test/src
ghc-options: -Wall -fno-warn-incomplete-uni-patterns ghc-options: -Wall -fno-warn-incomplete-uni-patterns -fprof-late
build-depends: build-depends:
base >=4.9 && <5 base >=4.9 && <5
, bytestring , bytestring
......
...@@ -53,6 +53,7 @@ newtype IRTreeT l m i = IRTreeT (RWST RPath (Endo [l]) Int m i) ...@@ -53,6 +53,7 @@ newtype IRTreeT l m i = IRTreeT (RWST RPath (Endo [l]) Int m i)
instance (Monad m) => MonadReduce l (IRTreeT l m) where instance (Monad m) => MonadReduce l (IRTreeT l m) where
check l = IRTreeT . RWST $ \rp i -> do check l = IRTreeT . RWST $ \rp i -> do
pure (indexChoice rp i, i + 1, Endo (l :)) pure (indexChoice rp i, i + 1, Endo (l :))
{-# INLINE check #-}
extract :: IRTree l i -> i extract :: IRTree l i -> i
extract t = runIdentity $ extractT t extract t = runIdentity $ extractT t
...@@ -77,7 +78,7 @@ probeT (IRTreeT m) pth = ...@@ -77,7 +78,7 @@ probeT (IRTreeT m) pth =
{-# INLINE probeT #-} {-# INLINE probeT #-}
reduce reduce
:: (Monad m, m ~ IO, Show l) :: (Monad m)
=> ([AnnotatedChoice l] -> i -> m Bool) => ([AnnotatedChoice l] -> i -> m Bool)
-> IRTree l i -> IRTree l i
-> m i -> m i
...@@ -86,7 +87,7 @@ reduce = reduceT (pure . runIdentity) ...@@ -86,7 +87,7 @@ reduce = reduceT (pure . runIdentity)
-- | Interpreted reduction with an m base monad -- | Interpreted reduction with an m base monad
reduceT reduceT
:: (Monad m, Functor t, m ~ IO, Show l) :: (Monad m, Functor t)
=> (forall a. t a -> m a) => (forall a. t a -> m a)
-> ([AnnotatedChoice l] -> i -> m Bool) -> ([AnnotatedChoice l] -> i -> m Bool)
-> IRTreeT l t i -> IRTreeT l t i
...@@ -105,7 +106,7 @@ reduceT lift_ p rt = do ...@@ -105,7 +106,7 @@ reduceT lift_ p rt = do
{-# INLINE reduceT #-} {-# INLINE reduceT #-}
reduceAdaptive reduceAdaptive
:: (Monad m, m ~ IO, Show i, Show l) :: (Monad m)
=> ([AnnotatedChoice l] -> i -> m Bool) => ([AnnotatedChoice l] -> i -> m Bool)
-> IRTree l i -> IRTree l i
-> m i -> m i
...@@ -114,7 +115,7 @@ reduceAdaptive = reduceAdaptiveT (pure . runIdentity) ...@@ -114,7 +115,7 @@ reduceAdaptive = reduceAdaptiveT (pure . runIdentity)
-- | Interpreted reduction with an m base monad, but using exponential search. -- | Interpreted reduction with an m base monad, but using exponential search.
reduceAdaptiveT reduceAdaptiveT
:: (Monad m, Functor t, IO ~ m, Show i, Show l) :: (Monad m, Functor t)
=> (forall a. t a -> m a) => (forall a. t a -> m a)
-- ^ a lift of monad m into t (normally @id@ or @lift@) -- ^ a lift of monad m into t (normally @id@ or @lift@)
-> ([AnnotatedChoice l] -> i -> m Bool) -> ([AnnotatedChoice l] -> i -> m Bool)
......
...@@ -100,6 +100,7 @@ type MonadReducePlus l m = (MonadReduce l m, MonadPlus m) ...@@ -100,6 +100,7 @@ type MonadReducePlus l m = (MonadReduce l m, MonadPlus m)
instance (MonadReduce l m) => MonadReduce l (MaybeT m) where instance (MonadReduce l m) => MonadReduce l (MaybeT m) where
split l (MaybeT lhs) (MaybeT rhs) = MaybeT (split l lhs rhs) split l (MaybeT lhs) (MaybeT rhs) = MaybeT (split l lhs rhs)
{-# INLINE split #-}
-- | Continues if the fact is true. -- | Continues if the fact is true.
given :: (MonadReducePlus l m) => l -> m () given :: (MonadReducePlus l m) => l -> m ()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment