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

fix inconsistent navigation state after making choice #467

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Pate/TraceTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
import qualified Prettyprinter.Render.String as PP

import qualified Data.Aeson as JSON
import qualified Compat.Aeson as JSON

Check warning on line 153 in src/Pate/TraceTree.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6.2 on self-hosted pate-ppc

The qualified import of ‘Compat.Aeson’ is redundant

Check warning on line 153 in src/Pate/TraceTree.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6.2 on self-hosted pate-ppc

The qualified import of ‘Compat.Aeson’ is redundant
import Data.Parameterized.Classes
import Data.Parameterized.Some
import Data.Parameterized.SymbolRepr ( knownSymbol, symbolRepr, SomeSym(..), SymbolRepr )
Expand All @@ -161,7 +161,7 @@
import Data.Set (Set)
import GHC.IO (unsafePerformIO)
import qualified Control.Concurrent as IO
import qualified System.IO as IO

Check warning on line 164 in src/Pate/TraceTree.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6.2 on self-hosted pate-ppc

The qualified import of ‘System.IO’ is redundant

Check warning on line 164 in src/Pate/TraceTree.hs

View workflow job for this annotation

GitHub Actions / GHC 9.6.2 on self-hosted pate-ppc

The qualified import of ‘System.IO’ is redundant
import Data.Maybe (catMaybes)
import Control.Concurrent (threadDelay)
import Control.Monad.State.Strict (StateT (..), MonadState (..))
Expand Down Expand Up @@ -884,9 +884,6 @@
, choicePick :: IO ()
-- ^ executed by some interactive client to indicate
-- this is the desired choice
-- FIXME: this needs to coordinate with the 'ChoiceHeader' to ensure
-- that 'choiceReady' will necessarily return 'True' once
-- this function unblocks
, choiceChosen :: IO Bool
-- ^ returns True if this is the desired choice
}
Expand Down
28 changes: 18 additions & 10 deletions tools/pate-repl/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,22 @@ data ReplIOStore =
data LoadOpts = LoadOpts { loadJSONMode :: Bool }

newtype ReplM_ sym arch a = ReplM_ { unReplM :: (StateT (ReplState sym arch) IO a) }
deriving ( Functor, Applicative, Monad, MonadState (ReplState sym arch), IO.MonadIO )
deriving ( Functor, Applicative, Monad, MonadState (ReplState sym arch), IO.MonadIO)

-- | Same as 'IO.liftIO' but ensures that the global 'ref' representing
-- the current state is consistent with the state of 'ReplM'
liftIO_State :: IO a -> ReplM sym arch a
liftIO_State f = ReplM_ $ do
st <- get
ValidSymArchRepr{} <- return $ replValidRepr st
(IO.liftIO $ IO.readIORef ref) >>= \case
NoTreeLoaded -> fail "Inconsistent verifier state: no initial state"
SomeReplState tid _ -> do
IO.liftIO $ IO.writeIORef ref (SomeReplState tid st)
a <- IO.liftIO f
(IO.liftIO $ IO.readIORef ref) >>= \case
SomeReplState _ st' -> put (unsafeCoerce st') >> return a
NoTreeLoaded -> fail "Inconsistent verifier state: lost state"

type ReplM sym arch a = (PA.ValidArch arch, PS.ValidSym sym) => ReplM_ sym arch a

Expand Down Expand Up @@ -696,16 +711,9 @@ goto' idx = do
Just (SomeChoice c) -> do
IO.liftIO $ choicePick c
(IO.liftIO $ IO.threadDelay 100)
let untilReady = do
headerReady <- choiceReady $ choiceHeader c
choiceReady <- choiceChosen c
if headerReady && choiceReady then
return ()
else IO.threadDelay 100 >> untilReady
IO.liftIO $ untilReady
Some curNode <- currentNode
top'
IO.liftIO $ wait
liftIO_State $ wait
(Just <$> currentNode)
Nothing -> do
goto_node' nextNode
Expand Down Expand Up @@ -812,7 +820,7 @@ input' s = withCurrentNode $ \tr -> asInput tr >>= \case
Nothing -> do
IO.liftIO $ IO.threadDelay 100
top'
IO.liftIO $ wait
liftIO_State $ wait
return Nothing
Just err -> return $ Just err
Nothing -> return $ Just (InputChoiceError "Not an input prompt" [])
Expand Down
Loading