Skip to content

Commit

Permalink
Merge branch 'unstable' into ik/sequences1486-2
Browse files Browse the repository at this point in the history
  • Loading branch information
konnov committed Mar 25, 2022
2 parents 8e147b5 + 617adca commit 5c02e06
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Look up modules in the same directory, see #1491
* Support for the community module `SequencesExt`, see #1539
* Support for the community module `BagsExt`, see #1555
* Support for the community module `Folds`, see #1558

### Improvements

Expand Down
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ lazy val root = (project in file("."))
"tla2sany/StandardModules/__rewire_finite_sets_ext_in_apalache.tla",
(src_dir / "__rewire_sequences_ext_in_apalache.tla") ->
"tla2sany/StandardModules/__rewire_sequences_ext_in_apalache.tla",
(src_dir / "__rewire_folds_in_apalache.tla") ->
"tla2sany/StandardModules/__rewire_folds_in_apalache.tla",
),
)
},
Expand Down
39 changes: 39 additions & 0 deletions src/tla/__rewire_folds_in_apalache.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--------------------------- MODULE Folds -----------------------------------
\*------ MODULE __rewire_folds_in_apalache -----------------------
(**
* ^^^^^^^^^^^^^^^^^^^^^^ We have to call this module Folds in any
* case, otherwise, SANY complains.
*
* This file contains alternative definitions for the operators defined in
* Folds. Most importantly, we are adding type annotations. We also
* define the Apalache-compatible behavior.
*
* These definitions are automatically rewired by the Apalache importer.
*
* Compare with the original definitions in Folds.tla:
*
* https://github.com/tlaplus/CommunityModules/blob/master/modules/Folds.tla
*)

EXTENDS __apalache_internal


(**
* Starting from base, apply op to f(x), for all x \in S, by choosing the set
* elements with `choose`. If there are multiple ways for choosing an element,
* op should be associative and commutative. Otherwise, the result may depend
* on the concrete implementation of `choose`.
*
* FoldSet, a simpler version for sets is contained in FiniteSetsEx.
* FoldFunction, a simpler version for functions is contained in Functions.
* FoldSeq, a simpler version for sequences is contained in SequencesExt.
*
* Apalache (the model checker) does not support MapThenFoldSet.
* However, we introduce this definition for the type checker.
*
* @type: ((a, b) => b, b, c => a, Set(c) => c, Set(c)) => b;
*)
MapThenFoldSet(op(_, _), base, f(_), choose(_), S) ==
__NotSupportedByModelChecker("MapThenFoldSet. Use FoldSet, FoldSeq, FoldFunction.")

=============================================================================
26 changes: 26 additions & 0 deletions test/tla/TestFolds.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
------------------------ MODULE TestFolds -------------------------------------
(**
* A test for the community module Folds.
* Since our implementation calls __NotSupportedByModelChecker,
* it is only useful to test it with a type checker.
*)

EXTENDS Folds

Init == TRUE

Next == TRUE

Test1 ==
LET \* @type: Seq(Set(Str));
seq == <<{"a"}, {"b"}, {"c"}>>
IN
LET F(i) == seq[i] IN
LET unite(S, T) == S \union T IN
LET choose(S) == CHOOSE x \in S: TRUE IN
MapThenFoldSet(unite, {}, F, choose, { 2, 3 }) = { "b", "c" }

AllTests ==
Test1

===============================================================================
20 changes: 20 additions & 0 deletions test/tla/cli-integration-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,16 @@ $ apalache-mc check --length=0 --inv=AllTests TestBagsExt.tla | sed 's/[IEW]@.*/
EXITCODE: OK
```
### check TestFolds.tla reports no error
```sh
$ apalache-mc check --length=0 --inv=AllTests TestFolds.tla | sed 's/[IEW]@.*//'
...
TestFolds.tla:21:5-21:50: unsupported expression: Not supported: MapThenFoldSet. Use FoldSet, FoldSeq, FoldFunction.
...
EXITCODE: ERROR (12)
```
### check Test1343.tla reports no error
Regression test for #1343
Expand Down Expand Up @@ -2485,6 +2495,16 @@ $ apalache-mc typecheck MC_LamportMutexTyped.tla | sed 's/[IEW]@.*//'
EXITCODE: OK
```
### typecheck TestFolds.tla
Typecheck the test for Folds.tla.
```sh
$ apalache-mc typecheck TestFolds.tla | sed 's/[IEW]@.*//'
...
EXITCODE: OK
```
## configuring the output manager
### output manager: set out-dir by CLI flag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ object StandardLibrary {
"Functions.tla" -> "__rewire_functions_in_apalache.tla",
"FiniteSetsExt.tla" -> "__rewire_finite_sets_ext_in_apalache.tla",
"SequencesExt.tla" -> "__rewire_sequences_ext_in_apalache.tla",
"Folds.tla" -> "__rewire_folds_in_apalache.tla",
) ////

/**
Expand Down

0 comments on commit 5c02e06

Please sign in to comment.