Skip to content

Commit 5ee005e

Browse files
Merge branch 'develop-forall'. Close #470.
**Description** The Copilot API offers the function `Copilot.Language.Spec.forall`, which future versions of GHC will disallow. To ensure that Copilot keeps working with future versions of the compiler, this function should be renamed. **Type** - Management: change to keep Copilot working with future versions of the language/compiler. **Additional context** The proposal was filed in ghc-proposals/ghc-proposals#281, and subsequently accepted in GHC. Details are also available at: https://downloads.haskell.org/ghc/latest/docs/users_guide/using-warnings.html#ghc-flag--Wforall-identifier. **Requester** - Ivan Perez **Method to check presence of bug** Although not a bug, it is possible to detect the presence of this issue by compiling with GHC >= 9.4. Using `-Werror=forall-identifier` will make the issue become a compile-time error. We cannot yet use a test that will produce a failure (expected) if forall is defined (i.e., with -Werror=forall-keyword) because we have to deprecate the function before we remove it. The following Dockerfile checks that the function forall has been deprecated and that the alterative forAll is offered, in which case prints the message Success: ``` FROM ubuntu:focal RUN apt-get update RUN apt-get install --yes libz-dev RUN apt-get install --yes git RUN apt-get install --yes wget RUN mkdir -p $HOME/.ghcup/bin RUN wget https://downloads.haskell.org/~ghcup/0.1.19.2/x86_64-linux-ghcup-0.1.19.2 -O $HOME/.ghcup/bin/ghcup RUN chmod a+x $HOME/.ghcup/bin/ghcup ENV PATH=$PATH:/root/.ghcup/bin/ ENV PATH=$PATH:/root/.cabal/bin/ RUN apt-get install --yes curl RUN apt-get install --yes gcc g++ make libgmp3-dev SHELL ["/bin/bash", "-c"] RUN ghcup install ghc 9.4 RUN ghcup install cabal 3.2 RUN ghcup set ghc 9.4.8 RUN cabal update SHELL ["/bin/bash", "-c"] CMD git clone $REPO && cd $NAME && git checkout $COMMIT && cd .. \ && cabal v1-sandbox init \ && cabal v1-install alex happy \ && cabal v1-install copilot/**/ \ && ! cabal v1-exec -- runhaskell -Werror=deprecations <<< 'import Copilot.Language (true, forall, theorem); spec = theorem "true" (forall true); main :: IO (); main = pure ();' \ && cabal v1-exec -- runhaskell -Werror=forall-identifier -Werror=deprecations <<< 'import Copilot.Language (true, forAll, theorem); spec = theorem "true" (forAll true); main :: IO (); main = pure ();' \ && echo "Success" ``` Command (substitute variables based on new path after merge): ``` $ docker run -e "REPO=https://github.com/Copilot-Language/copilot" -e "NAME=copilot" -e "COMMIT=<HASH>" -it copilot-verify-470 ``` **Expected result** Running the Dockerfile above prints the message "Success", indicating that the old forall function is deprecated and a new variant is being offered. **Solution implemented** Introduce a new function `forAll` that implements the behavior currently implemented by `forall`. Replace all references of `forall` to point to `forAll`, including occurrences in tests and examples. Deprecate `forall`. **Further notes** None.
2 parents 437b647 + a7aa767 commit 5ee005e

File tree

18 files changed

+97
-85
lines changed

18 files changed

+97
-85
lines changed

copilot-language/CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
2023-12-17
1+
2023-12-27
22
* Add type annotation to help type inference engine. (#469)
3+
* Rename forall to forAll. (#470)
34

45
2023-11-07
56
* Version bump (3.17). (#466)

copilot-language/src/Copilot/Language.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module Copilot.Language
3737
, arg
3838
, prop
3939
, theorem
40+
, forAll
4041
, forall, exists
4142
) where
4243

copilot-language/src/Copilot/Language/Spec.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module Copilot.Language.Spec
2727
, Prop (..)
2828
, prop, properties
2929
, theorem, theorems
30+
, forAll
3031
, forall, exists
3132
, extractProp
3233
, Universal, Existential
@@ -160,9 +161,14 @@ data Prop a where
160161
Forall :: Stream Bool -> Prop Universal
161162
Exists :: Stream Bool -> Prop Existential
162163

164+
-- | Universal quantification of boolean streams over time.
165+
forAll :: Stream Bool -> Prop Universal
166+
forAll = Forall
167+
168+
{-# DEPRECATED forall "Use forAll instead." #-}
163169
-- | Universal quantification of boolean streams over time.
164170
forall :: Stream Bool -> Prop Universal
165-
forall = Forall
171+
forall = forAll
166172

167173
-- | Existential quantification of boolean streams over time.
168174
exists :: Stream Bool -> Prop Existential

copilot-libraries/CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
2023-12-24
1+
2023-12-27
22
* Introduce testing infrastructure for Copilot.Library. (#475)
3+
* Replace uses of forall with forAll. (#470)
34

45
2023-11-07
56
* Version bump (3.17). (#466)

copilot-libraries/tests/Test/Extra.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import Test.QuickCheck.Monadic (monadicIO, run)
4343
import Copilot.Interpret.Eval (ExecTrace (interpObservers),
4444
ShowType (Haskell), eval)
4545
import Copilot.Language (Spec, Stream, Typed,
46-
forall, observer, prop)
46+
observer, prop)
47+
import qualified Copilot.Language as Copilot
4748
import qualified Copilot.Language.Operators.Boolean as Copilot
4849
import qualified Copilot.Language.Operators.Constant as Copilot
4950
import qualified Copilot.Language.Operators.Eq as Copilot
@@ -67,7 +68,7 @@ testWithTheorem gen =
6768
propName = "prop"
6869

6970
spec :: Spec
70-
spec = void $ prop propName $ forall stream
71+
spec = void $ prop propName $ Copilot.forAll stream
7172

7273
monadicIO $ run $ checkResult Z3 propName spec expectation
7374

copilot-theorem/CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
2023-12-18
1+
2023-12-27
22
* Introduce testing infrastructure for Copilot.Theorem.What4. (#474)
3+
* Replace uses of forall with forAll. (#470)
34

45
2023-11-07
56
* Version bump (3.17). (#466)

copilot-theorem/examples/BoyerMoore.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ spec = do
5454
observer ((P.++) "s" (show k)) s
5555
observer "maj" maj
5656

57-
i1 <- prop "i1" (forall $ s1 == 1 && s2 == 1 && s3 == 1 && s4 == 1)
58-
theorem "r1" (forall $ maj == 1) $ assume i1 >> induct
59-
theorem "OK" (forall $ okWith (arbitraryCst "n") ss maj) induct
57+
i1 <- prop "i1" (forAll $ s1 == 1 && s2 == 1 && s3 == 1 && s4 == 1)
58+
theorem "r1" (forAll $ maj == 1) $ assume i1 >> induct
59+
theorem "OK" (forAll $ okWith (arbitraryCst "n") ss maj) induct
6060

6161
where
6262
s1 = externW8 "s1" (Just $ repeat 1)

copilot-theorem/examples/Grey.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ greyTick reset = a && b
2222
b = (not reset) && ([False] ++ a)
2323

2424
spec = do
25-
theorem "iResetOk" (forall $ r ==> (ic == 0)) induct
26-
theorem "eqCounters" (forall $ it == gt) $ kinduct 3
25+
theorem "iResetOk" (forAll $ r ==> (ic == 0)) induct
26+
theorem "eqCounters" (forAll $ it == gt) $ kinduct 3
2727

2828
where
2929
ic = intCounter r

copilot-theorem/examples/Incr.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import Copilot.Theorem
77
import Copilot.Theorem.Prover.Z3
88

99
spec = do
10-
bounds <- prop "bounds" (forall $ x < 255)
11-
theorem "gt1" (forall $ x > 1) (assume bounds >> induct)
12-
theorem "neq0" (forall $ x /= 0) (assume bounds >> induct)
10+
bounds <- prop "bounds" (forAll $ x < 255)
11+
theorem "gt1" (forAll $ x > 1) (assume bounds >> induct)
12+
theorem "neq0" (forAll $ x /= 0) (assume bounds >> induct)
1313

1414
where
1515
x :: Stream Word8

copilot-theorem/examples/SerialBoyerMoore.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ spec = do
4848
observer "s" s
4949
observer "j" j
5050

51-
inRange <- prop "inRange" (forall $ input < 3)
52-
theorem "J" (forall j) $ assume inRange >> induct
51+
inRange <- prop "inRange" (forAll $ input < 3)
52+
theorem "J" (forAll j) $ assume inRange >> induct
5353

5454
where
5555
input = externW64 "in" (Just [1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 2, 1])

0 commit comments

Comments
 (0)