Skip to content
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

2100 & 2132 - command line completion issues #2135

Merged
merged 12 commits into from
Feb 23, 2023
Next Next commit
fix issues
  • Loading branch information
daniilsvc committed Jan 19, 2023
commit ca0e82f2db79724a588056e1766aa295d9f70528
4 changes: 4 additions & 0 deletions CMDL/DataTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import Driver.Options

import Network.Socket

import Proofs.AbstractState (G_cons_checker)

import System.IO (Handle)

data CmdlGoalAxiom =
Expand All @@ -70,6 +72,7 @@ data CmdlState = CmdlState
, output :: CmdlMessage -- ^ output of interface
, hetsOpts :: HetcatsOpts -- ^ hets command options
, errorCode :: Int
, consCheckers :: [G_cons_checker]
}

data ProveCmdType = Prove | Disprove | ConsCheck
Expand All @@ -91,6 +94,7 @@ emptyCmdlState opts = CmdlState
, connections = []
, hetsOpts = opts
, errorCode = 0
, consCheckers = []
}

data CmdlPrompterState = CmdlPrompterState
Expand Down
22 changes: 16 additions & 6 deletions CMDL/Interface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module CMDL.Interface where
import System.Console.Haskeline
import Interfaces.DataTypes
import Comorphisms.LogicGraph (logicGraph)
import Proofs.AbstractState (getConsCheckers, sublogicOfTheory, getCcName )
import Proofs.AbstractState (getAllConsCheckers, sublogicOfTheory, getCcName
, getListOfConsCheckers, usableCC)
import Logic.Grothendieck
#endif

Expand Down Expand Up @@ -81,10 +82,13 @@ cmdlComplete st (left, _) = do
case elements pS of
Element z _ : _ ->
do
consCheckList <- getConsCheckers $ findComorphismPaths
logicGraph $ sublogicOfTheory z
let shortConsCList = nub $ map (\ (y, _) -> getCcName y)
consCheckList
let fullConsCheckerList = map fst $ getAllConsCheckers
$ findComorphismPaths logicGraph $ sublogicOfTheory z
stateConsCheckList = consCheckers state
filteredConsCheckerList =
filter (\cc -> elem cc stateConsCheckList) fullConsCheckList
shortConsCList = nub $ map getCcName filteredConsCheckList

showCmdComplete state shortConsCList comps left
[] -> showCmdComplete state [] comps left
Nothing -> showCmdComplete state [] comps left
Expand Down Expand Up @@ -172,11 +176,17 @@ shellLoop st isTerminal =
liftIO $ writeIORef st newState'
shellLoop st isTerminal

saveConsCheckersInState :: CmdlState -> IO CmdlState
saveConsCheckersInState state = do
consCheckerList <- filterM usableCC getListOfConsCheckers
return $ state { consCheckers = consCheckerList }

-- | The function runs hets in a shell
cmdlRunShell :: CmdlState -> IO CmdlState
cmdlRunShell state = do
isTerminal <- hIsTerminalDevice stdin
st <- newIORef state
st' <- saveConsCheckersInState state
st <- newIORef st'
#ifdef HASKELINE
runInputT (shellSettings st) $ shellLoop st isTerminal
#else
Expand Down
11 changes: 7 additions & 4 deletions Common/ProverTools.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ check4FileAux name env = do

-- | Checks if a file exists in PATH
checkBinary :: String -> IO (Maybe String)
checkBinary name = fmap
(\ l -> if null l
checkBinary name =
fmap
( \l ->
if null l
then Just $ "missing binary in $PATH: " ++ name
else Nothing)
$ check4FileAux name "PATH"
else Nothing
)
$ check4FileAux name "PATH"

-- | Checks if a file exists
check4File :: String -- ^ file name
Expand Down
12 changes: 6 additions & 6 deletions Common/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,20 @@ is normally initially empty. The stop list update function is given a list
element a and the current stop list b, and returns 'Nothing' if the element is
already in the stop list, else 'Just' b', where b' is a new stop list updated
to contain a. -}
nubWith :: (a -> b -> Maybe b) -> b -> [a] -> [a]
nubWith f s es = case es of
[] -> []
nubWith :: [a] -> (a -> b -> Maybe b) -> b -> [a] -> [a]
nubWith acc f s es = case es of
[] -> reverse acc
e : rs -> case f e s of
Just s' -> e : nubWith f s' rs
Nothing -> nubWith f s rs
Just s' -> nubWith (e:acc) f s' rs
Nothing -> nubWith acc f s rs

nubOrd :: Ord a => [a] -> [a]
nubOrd = nubOrdOn id

nubOrdOn :: Ord b => (a -> b) -> [a] -> [a]
nubOrdOn g = let f a s = let e = g a in
if Set.member e s then Nothing else Just (Set.insert e s)
in nubWith f Set.empty
in nubWith [] f Set.empty

-- | safe variant of !!
atMaybe :: [a] -> Int -> Maybe a
Expand Down
2 changes: 1 addition & 1 deletion Logic/Grothendieck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ findComorphismPaths lg (G_sublogics lid sub) =
coMors = Map.elems $ comorphisms lg
-- compute possible compositions, but only up to depth 4
iterateComp n l =
if n > 2 || l == newL then newL else iterateComp (n + 1) newL
if n > 0 || l == newL then newL else iterateComp (n + 1) newL
where
newL = nubOrd $ l ++ concatMap extend l
-- extend comorphism list in all directions, but no cylces
Expand Down
33 changes: 29 additions & 4 deletions Proofs/AbstractState.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable #-}
{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable, StandaloneDeriving #-}
{- |
Module : ./Proofs/AbstractState.hs
Description : State data structure used by the goal management GUI.
Expand Down Expand Up @@ -44,10 +44,12 @@ module Proofs.AbstractState
, getAllProvers
, getUsableProvers
, getConsCheckers
, getListOfConsCheckers
, getAllConsCheckers
, lookupKnownProver
, lookupKnownConsChecker
, autoProofAtNode
, usableCC
) where

import qualified Data.Map as Map
Expand Down Expand Up @@ -76,6 +78,7 @@ import Logic.Comorphism
import Logic.Coerce

import Comorphisms.KnownProvers
import Comorphisms.LogicGraph (logicGraph)

import Static.GTheory

Expand Down Expand Up @@ -125,6 +128,9 @@ data G_cons_checker =
(ConsChecker sign sentence sublogics morphism proof_tree)
deriving (Typeable)

instance Eq G_cons_checker where
G_cons_checker _ cc1 == G_cons_checker _ cc2 = ccName cc1 == ccName cc2

instance Show G_cons_checker where
show _ = "G_cons_checker "

Expand Down Expand Up @@ -365,9 +371,28 @@ getConsCheckers :: [AnyComorphism] -> IO [(G_cons_checker, AnyComorphism)]
getConsCheckers = filterM (usableCC . fst) . getAllConsCheckers

getAllConsCheckers :: [AnyComorphism] -> [(G_cons_checker, AnyComorphism)]
getAllConsCheckers = concatMap (\ cm@(Comorphism cid) ->
map (\ cc -> (G_cons_checker (targetLogic cid) cc, cm))
$ cons_checkers $ targetLogic cid)
getAllConsCheckers lst =
snd $
foldr
( \el@(G_cons_checker _ cc, _) (s, l) ->
if not $ Set.member (ccName cc) s
then (Set.insert (ccName cc) s, el : l)
else (s, l)
)
(Set.empty, [])
$
concatMap
( \cm@(Comorphism cid) ->
map
( \cc ->
(G_cons_checker (targetLogic cid) cc, cm)
)
$ cons_checkers $ targetLogic cid
)
$ lst

getListOfConsCheckers :: [G_cons_checker]
getListOfConsCheckers = concatMap (\(Logic lid) -> map (\cc -> G_cons_checker lid cc) $ cons_checkers lid) (logics logicGraph)

lookupKnownConsChecker :: Fail.MonadFail m => ProofState
-> m (G_cons_checker, AnyComorphism)
Expand Down