Skip to content

Commit 2e7622e

Browse files
committed
copilot-theorem: Add Show and ShowF instances for counterexamples. Refs Copilot-Language#589.
Currently, the `Copilot.Theorem.What4.prove` function returns a list of results, where each result contains a `SatResult` that describes whether a property is `Valid`, `Invalid`, or `Unknown`. The `Invalid` result has the limitation that it does not give any information about a specific counterexample that could drive Copilot into falsifying the property, however. This makes it challenging to interpret what the results of prove mean. The `CounterExample`, `SatResultCex`, and `CopilotValue` data types lack `Show` and `ShowF` instances, which makes it impractical for users to display them. This commit adds `Show` and `ShowF` instances for all three data types so that they can be shown.
1 parent 50ef315 commit 2e7622e

File tree

1 file changed

+21
-0
lines changed
  • copilot-theorem/src/Copilot/Theorem

1 file changed

+21
-0
lines changed

copilot-theorem/src/Copilot/Theorem/What4.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import qualified Data.BitVector.Sized as BV
6969
import Data.Foldable (foldrM)
7070
import Data.List (genericLength)
7171
import qualified Data.Map as Map
72+
import Data.Parameterized.Classes (ShowF)
7273
import Data.Parameterized.NatRepr
7374
import Data.Parameterized.Nonce
7475
import Data.Parameterized.Some
@@ -100,6 +101,7 @@ data SatResult = Valid | Invalid | Unknown
100101
-- each property in a spec. This is largely the same as 'SatResult', except that
101102
-- 'InvalidCex' also records a 'CounterExample'.
102103
data SatResultCex = ValidCex | InvalidCex CounterExample | UnknownCex
104+
deriving Show
103105

104106
-- | Concrete values that cause a property in a Copilot specification to be
105107
-- invalid. As a simple example, consider the following spec:
@@ -250,6 +252,7 @@ data CounterExample = CounterExample
250252
-- is the concrete value of the extern stream at that time step.
251253
, concreteStreamValues :: Map.Map (CE.Id, StreamOffset) (Some CopilotValue)
252254
}
255+
deriving Show
253256

254257
-- | Attempt to prove all of the properties in a spec via an SMT solver (which
255258
-- must be installed locally on the host). Return an association list mapping
@@ -625,6 +628,24 @@ expectedBool what xe =
625628
data CopilotValue a where
626629
CopilotValue :: CT.Typed a => CT.Type a -> a -> CopilotValue a
627630

631+
instance Show (CopilotValue a) where
632+
showsPrec p (CopilotValue ty val) =
633+
case ty of
634+
CT.Bool -> showsPrec p val
635+
CT.Int8 -> showsPrec p val
636+
CT.Int16 -> showsPrec p val
637+
CT.Int32 -> showsPrec p val
638+
CT.Int64 -> showsPrec p val
639+
CT.Word8 -> showsPrec p val
640+
CT.Word16 -> showsPrec p val
641+
CT.Word32 -> showsPrec p val
642+
CT.Word64 -> showsPrec p val
643+
CT.Float -> showsPrec p val
644+
CT.Double -> showsPrec p val
645+
CT.Array {} -> showsPrec p val
646+
CT.Struct {} -> showsPrec p val
647+
instance ShowF CopilotValue
648+
628649
-- | Convert a symbolic 'XExpr' into a concrete 'CopilotValue'. Note that
629650
-- struct values are not currently supported, so attempting to convert an
630651
-- 'XStruct' fail will raise an error.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy