Skip to content

Commit 5b08e81

Browse files
committed
copilot-core: Preserve proposition quantifiers. Refs #254.
Currently, `copilot-language` remembers whether a proposition (i.e., a stream of booleans) is quantified universally (i.e., using `forAll`) or existentially (i.e., using `exists`). When translating from `copilot-language` to `copilot-core`, however, the quantifier is discarded. This means that a `copilot-core` `Property` does not record any quantifier information at all, making it impossible for downstream libraries that use `copilot-core` to handle universal quantification differently from existential quantification. This commit changes the `copilot-core` API to preserve quantifier information. Specifically, it introduces a `Prop` data type in `copilot-core` (largely inspired by a data type of the same name in `copilot-language`) to record a proposition's quantifier, and it changes the `propertyExpr :: Expr Bool` field of `copilot-core`'s `Property` data type to `propertyProp :: Prop`. This commit also introduces an `extractProp :: Prop -> Expr Bool` function for retrieving the underlying boolean expression. Generally, this function should not be used, as different quantifiers usually require different treatment, and misuse of the `extractProp` function can potentially lead to unsoundness. There are a handful of places where the use of `extractProp` is justified, however. In each such place, a comment should be left to justify why the use of `extractProp` is sound.
1 parent 0845db1 commit 5b08e81

File tree

1 file changed

+20
-1
lines changed
  • copilot-core/src/Copilot/Core

1 file changed

+20
-1
lines changed

copilot-core/src/Copilot/Core/Spec.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module Copilot.Core.Spec
2020
, Trigger (..)
2121
, Spec (..)
2222
, Property (..)
23+
, Prop (..)
24+
, extractProp
2325
)
2426
where
2527

@@ -62,9 +64,26 @@ data Trigger = Trigger
6264
-- universally quantified over time.
6365
data Property = Property
6466
{ propertyName :: Name
65-
, propertyExpr :: Expr Bool
67+
, propertyProp :: Prop
6668
}
6769

70+
-- | A proposition, representing a boolean stream that is existentially or
71+
-- universally quantified over time.
72+
data Prop
73+
= Forall (Expr Bool)
74+
| Exists (Expr Bool)
75+
76+
-- | Extract the underlying stream from a quantified proposition.
77+
--
78+
-- Think carefully before using this function, as this function will remove the
79+
-- quantifier from a proposition. Universally quantified streams usually require
80+
-- separate treatment from existentially quantified ones, so carelessly using
81+
-- this function to remove quantifiers can result in hard-to-spot soundness
82+
-- bugs.
83+
extractProp :: Prop -> Expr Bool
84+
extractProp (Forall e) = e
85+
extractProp (Exists e) = e
86+
6887
-- | A Copilot specification is a list of streams, together with monitors on
6988
-- these streams implemented as observers, triggers or properties.
7089
data Spec = Spec

0 commit comments

Comments
 (0)