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

Add Fallback to LogEntry #3657

Merged
merged 7 commits into from
Sep 18, 2023
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
1 change: 1 addition & 0 deletions kore-rpc-types/kore-rpc-types.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ library
Kore.JsonRpc.Error
Kore.JsonRpc.Types
Kore.JsonRpc.Types.Log
Kore.JsonRpc.Types.Depth
Kore.JsonRpc.Server
Kore.Syntax.Json.Types
hs-source-dirs:
Expand Down
8 changes: 3 additions & 5 deletions kore-rpc-types/src/Kore/JsonRpc/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ License : BSD-3-Clause
-}
module Kore.JsonRpc.Types (
module Kore.JsonRpc.Types,
module Kore.JsonRpc.Types.Depth,
) where

import Control.Exception (Exception)
Expand All @@ -19,18 +20,14 @@ import Deriving.Aeson (
StripPrefix,
)
import GHC.Generics (Generic)
import Kore.JsonRpc.Types.Depth (Depth (..))
import Kore.JsonRpc.Types.Log (LogEntry)
import Kore.Syntax.Json.Types (KoreJson)
import Network.JSONRPC (
FromRequest (..),
)
import Numeric.Natural
import Prettyprinter qualified as Pretty

newtype Depth = Depth {getNat :: Natural}
deriving stock (Show, Eq)
deriving newtype (FromJSON, ToJSON, Num)

data ExecuteRequest = ExecuteRequest
{ state :: !KoreJson
, maxDepth :: !(Maybe Depth)
Expand All @@ -43,6 +40,7 @@ data ExecuteRequest = ExecuteRequest
, logFailedRewrites :: !(Maybe Bool)
, logSuccessfulSimplifications :: !(Maybe Bool)
, logFailedSimplifications :: !(Maybe Bool)
, logFallbacks :: !(Maybe Bool)
}
deriving stock (Generic, Show, Eq)
deriving
Expand Down
8 changes: 8 additions & 0 deletions kore-rpc-types/src/Kore/JsonRpc/Types/Depth.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Kore.JsonRpc.Types.Depth (module Kore.JsonRpc.Types.Depth) where

import Data.Aeson.Types (FromJSON (..), ToJSON (..))
import Numeric.Natural

newtype Depth = Depth {getNat :: Natural}
deriving stock (Show, Eq)
deriving newtype (FromJSON, ToJSON, Num)
43 changes: 31 additions & 12 deletions kore-rpc-types/src/Kore/JsonRpc/Types/Log.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
module Kore.JsonRpc.Types.Log (module Kore.JsonRpc.Types.Log) where

import Data.Aeson (FromJSON, ToJSON)
import Data.List.NonEmpty (NonEmpty)
import Data.Text (Text)
import GHC.Generics (Generic)
import Kore.JsonRpc.Types.Depth (Depth (..))
import Kore.Syntax.Json.Types (KoreJson)

import Deriving.Aeson (
Expand All @@ -16,7 +18,7 @@ import Deriving.Aeson (
StripPrefix,
)

data LogOrigin = KoreRpc | Booster | Llvm
data LogOrigin = KoreRpc | Booster | Llvm | Proxy
deriving stock (Generic, Show, Eq)
deriving
(FromJSON, ToJSON)
Expand All @@ -26,13 +28,13 @@ data LogOrigin = KoreRpc | Booster | Llvm

data LogRewriteResult
= Success
{ rewrittenTerm :: Maybe KoreJson
, substitution :: Maybe KoreJson
, ruleId :: Text
{ rewrittenTerm :: !(Maybe KoreJson)
, substitution :: !(Maybe KoreJson)
, ruleId :: !Text
}
| Failure
{ reason :: Text
, _ruleId :: Maybe Text
{ reason :: !Text
, _ruleId :: !(Maybe Text)
}
deriving stock (Generic, Show, Eq)
deriving
Expand All @@ -46,14 +48,31 @@ data LogRewriteResult

data LogEntry
= Rewrite
{ result :: LogRewriteResult
, origin :: LogOrigin
{ result :: !(LogRewriteResult)
, origin :: !LogOrigin
}
| Simplification
{ originalTerm :: Maybe KoreJson
, originalTermIndex :: Maybe [Int]
, result :: LogRewriteResult
, origin :: LogOrigin
{ originalTerm :: !(Maybe KoreJson)
, originalTermIndex :: !(Maybe [Int])
, result :: !LogRewriteResult
, origin :: !LogOrigin
}
| -- | Indicates a fallback of an RPC-server to a more powerful, but slower backup server, i.e. Booster to Kore
Fallback
{ originalTerm :: !(Maybe KoreJson)
-- ^ state before fallback
, rewrittenTerm :: !(Maybe KoreJson)
-- ^ state after fallback
, reason :: !Text
-- ^ fallback reason
, fallbackRuleId :: !Text
-- ^ the rule that caused the fallback
, recoveryRuleIds :: !(Maybe (NonEmpty Text))
-- ^ rules applied during fallback, the first rule is the one that caused the fallback
, recoveryDepth :: !Depth
-- ^ depth reached in fallback, must be the same as (length ruleIds)
, origin :: !LogOrigin
-- ^ proxy server the log was emitted from
}
deriving stock (Generic, Show, Eq)
deriving
Expand Down