Skip to content

Commit 9aff332

Browse files
committed
Fix GHC warnings
GHC warns when using PartialTypeSignatures, so we just fill in the inferred signature. It also now warns on the use of head, so we've replaced those in the instances where we are able, with two (safe) uses remaining in GenMonad.
1 parent 4071308 commit 9aff332

File tree

7 files changed

+29
-26
lines changed

7 files changed

+29
-26
lines changed

src/PropR/Configuration/Materializeable.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
module PropR.Configuration.Materializeable where
44

55
import Data.Default
6+
import Data.Kind (Type)
67

78
-- | The materializeable class defines the data we know how to materialize, i.e.
89
-- bring from undefined data, and override
910
-- TODO: We could definitely derive this
1011
class Default a => Materializeable a where
11-
data Unmaterialized a :: *
12+
data Unmaterialized a :: Type
1213
materialize :: Maybe (Unmaterialized a) -> a
1314
conjure :: Unmaterialized a
1415
override :: a -> Maybe (Unmaterialized a) -> a

src/PropR/Eval.hs

+4-12
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Control.Concurrent (threadDelay)
3131
import Control.Concurrent.Async (mapConcurrently)
3232
import Control.Lens (Getting, to, universeOf, universeOn, universeOnOf)
3333
import Control.Lens.Combinators (Fold)
34-
import Control.Monad (forM, forM_, unless, void, when, zipWithM_, (>=>))
34+
import Control.Monad (forM, forM_, unless, void, when, zipWithM_, (>=>), join)
3535
import qualified GHC.Core.Utils as CoreUtils
3636
import qualified Data.Bifunctor
3737
import Data.Bits (complement)
@@ -40,7 +40,7 @@ import Data.Data.Lens (template, tinplate, uniplate)
4040
import Data.Dynamic (Dynamic, fromDynamic)
4141
import Data.Function (on)
4242
import Data.IORef (IORef, modifyIORef, newIORef, readIORef)
43-
import Data.List (groupBy, intercalate, nub, partition, stripPrefix)
43+
import Data.List (groupBy, intercalate, nub, partition, stripPrefix, uncons)
4444
import Data.Map (Map)
4545
import qualified Data.Map as Map
4646
import Data.Maybe (catMaybes, isJust, isNothing, mapMaybe)
@@ -212,7 +212,6 @@ addPreludeIfNotPresent decls =
212212
where
213213
isPrelude (IIModule mname) = mname == pRELUDE_NAME
214214
isPrelude (IIDecl ImportDecl {..}) = unLoc ideclName == pRELUDE_NAME
215-
isPrelude _ = False
216215
prelImport = IIDecl $ simpleImportDecl pRELUDE_NAME
217216

218217
justParseExpr :: CompileConfig -> RExpr -> Ghc (LHsExpr GhcPs)
@@ -585,7 +584,6 @@ moduleToProb baseCC@CompConf {tempDirBase = baseTempDir, ..} mod_path mb_target
585584
fh@FunRhs {mc_fun = L l''' _} ->
586585
fh {mc_fun = L l''' $ unLoc nfid}
587586
o -> o
588-
nalt alt = alt
589587
nalts = map nalt alts
590588
nvpat :: IdP GhcPs -> LPat GhcPs
591589
nvpat t_name =
@@ -594,7 +592,6 @@ moduleToProb baseCC@CompConf {tempDirBase = baseTempDir, ..} mod_path mb_target
594592
(noLocA $ VarPat noExtField $ noLocA t_name)
595593
noHsTok)
596594
nvpats = map nvpat $ filter (`Set.member` vars) targets
597-
nmatches _ _ mg = mg
598595

599596
wrapProp :: LHsBind GhcPs -> [(LHsBind GhcPs, [Sig GhcPs])]
600597
wrapProp prop@(L l fb@FunBind {..})
@@ -615,15 +612,11 @@ moduleToProb baseCC@CompConf {tempDirBase = baseTempDir, ..} mod_path mb_target
615612
run_i_only mg@MG {mg_alts = (L l' alts)} = mg {mg_alts = L l' $ map nalt alts}
616613
where
617614
nalt (L l'' m@Match {..}) = L l'' m {m_grhss = n_grhss m_grhss}
618-
nalt m = m
619615
n_grhss grhss@GRHSs {..} = grhss {grhssGRHSs = map nGRHSS grhssGRHSs}
620-
n_grhss g = g
621616
nGRHSS (L l3 (GRHS x guards bod)) = L l3 (GRHS x guards nbod)
622617
where
623618
nbod = noLocA $ HsApp noAnn nthapp (noLocA $ HsPar noAnn noHsTok bod noHsTok)
624619
nthapp = noLocA $ HsPar noAnn noHsTok (noLocA $ HsApp noAnn (tf "testTreeNthTest") (il $ fromIntegral i)) noHsTok
625-
nGRHSS xg = xg
626-
run_i_only mg = mg
627620
wrapProp prop@(L l fb@FunBind {..}) =
628621
[(L l fb {fun_id = nfid, fun_matches = nmatches prop_vars nfid fun_matches}, sig)]
629622
where
@@ -658,7 +651,6 @@ moduleToProb baseCC@CompConf {tempDirBase = baseTempDir, ..} mod_path mb_target
658651
tyApps (ty : tys) =
659652
noLocA $ HsFunTy noAnn arr (noLocA ty) (tyApps tys)
660653
where arr = HsUnrestrictedArrow noHsUniTok
661-
toWrapSig e = e
662654
wrapped_props :: [EProp]
663655
prop_sigs :: [LSig GhcPs]
664656
(wrapped_props, prop_sigs) =
@@ -805,7 +797,7 @@ traceTarget ::
805797
EProp ->
806798
[RExpr] ->
807799
IO (Maybe TraceRes)
808-
traceTarget cc tp e fp ce = head <$> traceTargets cc tp e [(fp, ce)]
800+
traceTarget cc tp e fp ce = (join . fmap fst . uncons) <$> traceTargets cc tp e [(fp, ce)]
809801

810802
toNonZeroInvokes :: Trace -> Map.Map (EExpr, SrcAnn AnnListItem) Integer
811803
toNonZeroInvokes (ex, res) = Map.fromList $ mapMaybe only_max $ flatten res
@@ -1195,7 +1187,7 @@ getExprFitCands expr_or_mod = do
11951187
let flat = flattenExpr tcd_context
11961188
-- We remove the ones already present and drop the first one
11971189
-- (since it will be the program itself)
1198-
flat' = filter nonTriv $ tail flat
1190+
flat' = filter nonTriv $ drop 1 flat
11991191
in toEsAnNames wc flat'
12001192
_ -> []
12011193
liftIO $ logStr TRACE "Getting the session..."

src/PropR/Repair.hs

+7-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import GHC.Tc.Types.Constraint
3636
import Control.Arrow (first, second, (***))
3737
import Control.Concurrent (getNumCapabilities, threadDelay, threadWaitRead)
3838
import Control.Concurrent.Async (mapConcurrently)
39-
import Control.Monad (forM_, void, when, (>=>), unless)
39+
import Control.Monad (forM_, void, when, (>=>), unless, join)
4040
import qualified Data.Bifunctor
4141
import Data.ByteString.Char8 (ByteString)
4242
import qualified Data.ByteString.Char8 as BSC
@@ -51,7 +51,7 @@ import qualified Data.Functor
5151
import Data.IORef (IORef, modifyIORef, modifyIORef', newIORef, readIORef, writeIORef)
5252
import Data.IntMap (IntMap)
5353
import qualified Data.IntMap as IntMap
54-
import Data.List (groupBy, intercalate, nub, nubBy, partition, sort, sortOn, transpose)
54+
import Data.List (groupBy, intercalate, nub, nubBy, partition, sort, sortOn, transpose, uncons)
5555
import qualified Data.List as L
5656
import Data.Map (Map)
5757
import qualified Data.Map as Map
@@ -354,7 +354,7 @@ detranslate _ = error "Cannot detranlsate external problem!"
354354
-- | Get a list of strings which represent shrunk arguments to the property that
355355
-- makes it fail.
356356
propCounterExample :: CompileConfig -> EProblem -> EProp -> IO (Maybe [RExpr])
357-
propCounterExample cc ep prop = head <$> propCounterExamples (fakeDesc [] cc ep) [prop]
357+
propCounterExample cc ep prop = (join . fmap fst . uncons) <$> propCounterExamples (fakeDesc [] cc ep) [prop]
358358

359359
-- | Get a list of strings which represent shrunk arguments to the property that
360360
-- makes it fail.
@@ -643,7 +643,10 @@ generateFixCandidates
643643
)
644644
(map ((subexprs Map.!) . fst) nzh)
645645
raw_wrapped_fits
646-
wrapped_holes = map (first head) wrapped_in_holes
646+
wrapped_holes =
647+
map (first $ \case (h:_) -> h
648+
[] -> error "generateFixCandidates: No locations in hole!")
649+
wrapped_in_holes
647650
liftIO $ logStr TRACE "Hole fits were:"
648651
liftIO $ mapM_ (logOut DEBUG) hole_fits
649652

src/PropR/Search/Genetic/GenMonad.hs

+10-4
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,22 @@ runGenMonad' conf desc gen fc action = do
235235
withGen = ST.runStateT withParams gen
236236
ST.runStateT withGen fc
237237

238-
liftConf :: R.ReaderT GeneticConfiguration _ a -> GenMonad a
238+
type CacheM = ST.StateT FitnessCache IO
239+
type GenM = ST.StateT StdGen CacheM
240+
type DescM = R.ReaderT ProblemDescription GenM
241+
type ConfM = R.ReaderT GeneticConfiguration DescM
242+
243+
liftConf :: ConfM a -> GenMonad a
239244
liftConf = id
240245

241-
liftDesc :: R.ReaderT ProblemDescription _ a -> GenMonad a
246+
liftDesc :: DescM a -> GenMonad a
242247
liftDesc = lift
243248

244-
liftGen :: ST.StateT StdGen _ a -> GenMonad a
249+
liftGen :: GenM a -> GenMonad a
245250
liftGen = lift . lift
246251

247-
liftCache :: ST.StateT FitnessCache _ a -> GenMonad a
252+
253+
liftCache :: CacheM a -> GenMonad a
248254
liftCache = lift . lift . lift
249255

250256
-- Some getters and setters for the monad

src/PropR/Search/Genetic/Search.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,13 @@ geneticSearch = collectStats $ do
336336
sortPopByFitness shuffledIslandPop
337337
gen <- getGen
338338
let -- Select the best M species per island
339-
migrators = [take (migrationSize iConf) pop | pop <- sortedIslands]
339+
migrators@(m:ms) = [take (migrationSize iConf) pop | pop <- sortedIslands]
340340
-- Drop the worst M species per Island
341341
receivers = [drop (migrationSize iConf) pop | pop <- sortedIslands]
342342
-- Rearrange the migrating species either by moving one clockwise, or by shuffling them
343343
(migrators', gen') =
344344
if ringwiseMigration iConf
345-
then (tail migrators ++ [head migrators], gen)
345+
then (ms ++ [m], gen)
346346
else shuffle migrators gen
347347
islandMigrationPairs = zip receivers migrators'
348348
newIslands = map (uncurry (++)) islandMigrationPairs

src/PropR/Search/Genetic/Utils.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ pickRandomElements :: (RandomGen g, Eq a) => Int -> g -> [a] -> ([a], g)
8989
pickRandomElements 0 g _ = ([], g)
9090
pickRandomElements _ g [] = ([], g)
9191
pickRandomElements n g as =
92-
let (asShuffled, g') = shuffle as g
92+
let ((x:_), g') = shuffle as g
9393
(recursiveResults, g'') = pickRandomElements (n - 1) g' as
94-
x = head asShuffled
9594
in (x : recursiveResults, g'')
9695

9796
-- | Picks a random pair of a given List.

src/PropR/Search/PseudoGenetic/Search.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import PropR.Traversals (replaceExpr)
3131
import PropR.Types
3232
import PropR.Util
3333

34+
import qualified Data.List.NonEmpty as NE
35+
3436
-- |
3537
-- An Individual consists of a "Fix", that is a change to be applied,
3638
-- and a list of properties they fulfill or fail, expressed as an boolean array.
@@ -165,4 +167,4 @@ deDupOn f as = map snd $ filter ((`Set.member` grouped) . fst) zas
165167
where
166168
zas = zip [(0 :: Int) ..] as
167169
zbs = zip [(0 :: Int) ..] $ map f as
168-
grouped = Set.fromList $ map (fst . head) $ groupBy ((==) `on` snd) $ sortOn snd zbs
170+
grouped = Set.fromList $ map (fst . NE.head) $ NE.groupBy ((==) `on` snd) $ sortOn snd zbs

0 commit comments

Comments
 (0)