Skip to content

Commit 857a9c4

Browse files
authored
kore-repl: do not remove direct children of branchings when using clear command (#1952)
* kore-repl: do not remove direct children of branchings when using clear command * Clean-up * Address review comments * Fix
1 parent 1739884 commit 857a9c4

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

kore/src/Kore/Repl/Data.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ helpText =
358358
\tryf (<a|c><num>)|<name> attempts <a>xiom or <c>laim at\
359359
\ index <num> or rule with <name>,\
360360
\ and if successful, it will apply it.\n\
361-
\clear [n] removes all node children from the\
362-
\ proof graph\n\
361+
\clear [n] removes all the node's children from the\
362+
\ proof graph (****)\n\
363363
\ (defaults to current node)\n\
364364
\save-session file saves the current session to file\n\
365365
\save-partial-proof [n] file creates a file, <file>.kore, containing a kore module\
@@ -414,6 +414,9 @@ helpText =
414414
\ the current node is advanced to the (only) non-bottom leaf. If no such\n\
415415
\ leaf exists (i.e the proof is complete), the current node remains the same\n\
416416
\ and a message is emitted.\n\
417+
\ (****) The clear command doesn't allow the removal of nodes which are direct\n\
418+
\ descendants of branchings. The steps which create branchings cannot be\n\
419+
\ partially redone. Therefore, if this were allowed it would result in invalid proofs.\n\
417420
\\n\n\
418421
\Rule names can be added in two ways:\n\
419422
\ a) rule <k> ... </k> [label(myName)]\n\

kore/src/Kore/Repl/Interpreter.hs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import Control.Lens
3232
import qualified Control.Lens as Lens
3333
import Control.Monad
3434
( void
35+
, (<=<)
3536
)
3637
import Control.Monad.Extra
3738
( ifM
@@ -935,16 +936,19 @@ clear
935936
=> Maybe ReplNode
936937
-- ^ 'Nothing' for current node, or @Just n@ for a specific node identifier
937938
-> m ()
938-
clear =
939-
\case
939+
clear maybeNode = do
940+
graph <- getInnerGraph
941+
case maybeNode of
940942
Nothing -> Lens.use (field @"node") >>= clear . Just
941943
Just node
942-
| unReplNode node == 0 -> putStrLn' "Cannot clear initial node (0)."
943-
| otherwise -> clear0 node
944+
| unReplNode node == 0 ->
945+
putStrLn' "Cannot clear initial node (0)."
946+
| isDirectDescendentOfBranching node graph ->
947+
putStrLn' "Cannot clear a direct descendant of a branching node."
948+
| otherwise -> clear0 node graph
944949
where
945-
clear0 :: ReplNode -> m ()
946-
clear0 rnode = do
947-
graph <- getInnerGraph
950+
clear0 :: ReplNode -> InnerGraph Axiom -> m ()
951+
clear0 rnode graph = do
948952
let node = unReplNode rnode
949953
let
950954
nodesToBeRemoved = collect (next graph) node
@@ -962,6 +966,11 @@ clear =
962966
prevNode :: InnerGraph axiom -> Graph.Node -> Graph.Node
963967
prevNode graph = fromMaybe 0 . headMay . fmap fst . Graph.lpre graph
964968

969+
isDirectDescendentOfBranching :: ReplNode -> InnerGraph axiom -> Bool
970+
isDirectDescendentOfBranching (ReplNode node) graph =
971+
let childrenOfParent = (Graph.suc graph <=< Graph.pre graph) node
972+
in length childrenOfParent /= 1
973+
965974
-- | Save this sessions' commands to the specified file.
966975
saveSession
967976
:: forall m

0 commit comments

Comments
 (0)