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 support for sets to the arrays encoding #1093

Merged
merged 54 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
5208883
Add arrays encoding config to solver context
rodrigo7491 Oct 27, 2021
0e19a0f
Add array initialization upon const declaration
rodrigo7491 Oct 28, 2021
163758a
Add array encoding option to OfflineExecutionContext
rodrigo7491 Oct 28, 2021
8606e4d
refactor bmcmt unit tests to account for encoding solver config
rodrigo7491 Oct 28, 2021
dfd8070
Add array updates via smt store
rodrigo7491 Oct 29, 2021
88c03b8
Add metrics update to cells 0 and 1
rodrigo7491 Oct 29, 2021
ad1d4c3
Merge branch 'unstable' of https://github.com/informalsystems/apalach…
rodrigo7491 Oct 29, 2021
4807397
update arrays version of SymbStateRewriterAuto
rodrigo7491 Oct 29, 2021
16cec0a
first iteration of arrays encoding rule table
rodrigo7491 Oct 29, 2021
1f29cc2
Merge branch 'unstable' of https://github.com/informalsystems/apalach…
rodrigo7491 Oct 29, 2021
a7aeed4
Merge branch 'unstable' of https://github.com/informalsystems/apalach…
rodrigo7491 Nov 1, 2021
d97f428
Add set equality using SMT equality
rodrigo7491 Nov 1, 2021
83faa8a
make inCache store "select" expressions
rodrigo7491 Nov 2, 2021
d68bb01
Add set membership rule with smt arrays
rodrigo7491 Nov 2, 2021
b32db1e
remove redundant "select" equalities
rodrigo7491 Nov 2, 2021
7efcec4
Add set inclusion rule with arrays
rodrigo7491 Nov 2, 2021
6f568bb
fix set membership predicate generation
rodrigo7491 Nov 3, 2021
9c84447
Add support for power sets in the arrays encoding
rodrigo7491 Nov 3, 2021
508124d
fix subset relation with power sets
rodrigo7491 Nov 3, 2021
d2e7ee0
Merge branch 'unstable' of https://github.com/informalsystems/apalach…
rodrigo7491 Nov 4, 2021
cbd7898
add integer range with SMT arrays
rodrigo7491 Nov 4, 2021
e00d243
add set map with SMT arrays
rodrigo7491 Nov 9, 2021
a6e86d1
Merge branch 'unstable' of https://github.com/informalsystems/apalach…
rodrigo7491 Nov 9, 2021
0ae3471
fix bug in set membership with smt arrays
rodrigo7491 Nov 9, 2021
89a78e0
fix bug in set inclusion with smt arrays
rodrigo7491 Nov 9, 2021
6f44287
fix issues in the arrays encoding w.r.t. edges being asserted wrongly…
rodrigo7491 Nov 9, 2021
59826d2
add set filter with smt arrays
rodrigo7491 Nov 10, 2021
59cfa4d
add big union with smt arrays
rodrigo7491 Nov 10, 2021
1589b59
fix issue with equality of empty sets with smt arrays
rodrigo7491 Nov 10, 2021
7527ec9
fix issue with equality delegation
rodrigo7491 Nov 10, 2021
7e5bae7
add stub rules for unit tests
rodrigo7491 Nov 10, 2021
da3193b
update context pop
rodrigo7491 Nov 10, 2021
4d1c6b7
add tuple comparisons in set membership rule
rodrigo7491 Nov 10, 2021
8cf4c66
add unit tests for arrays encoding
rodrigo7491 Nov 10, 2021
d263c31
Merge branch 'unstable' of https://github.com/informalsystems/apalach…
rodrigo7491 Nov 10, 2021
883e294
fix powerset membership with arrays
rodrigo7491 Nov 11, 2021
80d9fec
add unit tests for powersets using arrays encoding
rodrigo7491 Nov 11, 2021
8228b22
add additional unit tests for arrays encoding
rodrigo7491 Nov 11, 2021
79657d3
add integration tests for arrays encoding
rodrigo7491 Nov 12, 2021
968439b
polish code and comments
rodrigo7491 Nov 12, 2021
26d5dd0
update adr11
rodrigo7491 Nov 12, 2021
eebfa25
Merge branch 'unstable' of https://github.com/informalsystems/apalach…
rodrigo7491 Nov 12, 2021
9864996
update UNRELEASED.md
rodrigo7491 Nov 12, 2021
0f6b8b6
Merge branch 'unstable' of https://github.com/informalsystems/apalach…
rodrigo7491 Nov 12, 2021
ca863ec
Update docs/src/adr/011adr-smt-arrays.md
rodrigo7491 Nov 17, 2021
7bd5c3b
Merge branch 'unstable' into ro/tla-sets-as-smt-arrays
rodrigo7491 Nov 17, 2021
762ab51
minor refactoring
rodrigo7491 Nov 17, 2021
177b4f5
minor refactoring
rodrigo7491 Nov 17, 2021
ae5c74c
Update tla-bmcmt/src/main/scala/at/forsyte/apalache/tla/bmcmt/smt/Sol…
rodrigo7491 Nov 17, 2021
2301528
change conjunction to implication in membership constraints
rodrigo7491 Nov 18, 2021
e4fb1a3
add comments to set membership constraints
rodrigo7491 Nov 18, 2021
ed582dd
change EncodingBase from trait to object
rodrigo7491 Nov 18, 2021
08116e8
rename useArrays to arraysEnabled
rodrigo7491 Nov 18, 2021
2879cbb
refactor ruleLookupTable
rodrigo7491 Nov 18, 2021
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
4 changes: 4 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
* Some bug fix, see #124

DO NOT LEAVE A BLANK LINE BELOW THIS PREAMBLE -->

### Features

* Added support for sets to the SMT encoding with arrays, see #1092
54 changes: 36 additions & 18 deletions docs/src/adr/011adr-smt-arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

| author | revision |
| ------------- | --------:|
| Rodrigo Otoni | 1 |
| Rodrigo Otoni | 1.1 |

This ADR describes an alternative encoding of the [KerA+] fragment of TLA+ into SMT.
Compound data structures, e.g. sets, are currently encoded using the [core theory] of SMT,
Expand All @@ -19,37 +19,40 @@ treatment of different TLA+ operators are described.

The encoding using arrays is to be an alternative, not a replacement, to the already existing encoding.
Given this, a new option is to be added to the `check` command of the CLI. The default encoding will be
the existing one. The option description is shown below.
the existing one. The option description is shown below. The envvar `SMT_ENCODING` can also be used to
set the encoding, see the [model checking parameters] for details.

```
--smt-encoding=STRING : the SMT encoding: oopsla19, arrays (experimental), default: oopsla19
--smt-encoding : the SMT encoding: oopsla19, arrays (experimental), default: oopsla19 (overrides envvar SMT_ENCODING)
```

### Code changes

The following changes will be made to implement the new CLI option:

- Add new string variable to class `CheckCmd` to enable the new option.
- Add new `smtEncoding` field to `SolverConfig`.
- Add new class `SymbStateRewriterImplWithArrays`, which extends class `SymbStateRewriterImpl`.
- Use the new option to select between different `SymbStateRewriter`
- Use the new option to set the `SolverConfig` encoding field and select between different `SymbStateRewriter`
implementations in classes `BoundedCheckerPassImpl` and `SymbStateRewriterAuto`.

## 2. Testing the new encoding

The new encoding should provide the same results as the existing one, the available test suit
will thus be used to test the new encoding. To achieve this, the test suit needs to be made parametric
w.r.t. the implementations of `SymbStateRewriter`.
The new encoding should provide the same results as the existing one, the available test suite
will thus be used to test the new encoding. To achieve this, the unit tests needs to be made parametric
w.r.t. the `SolverConfig` encoding field and the implementations of `SymbStateRewriter`, and the
integration tests need to be tagged to run with the new encoding.

### Code changes

The following changes will be made to implement the tests for the new encoding:

- Refactor the classes in `tla-bmcmt/src/test` to enable unit testing with different
implementations of `SymbStateRewriter`.
- Add unit tests for the new encoding, which should be similar to existing tests, but use
`SymbStateRewriterImplWithArrays` instead of `SymbStateRewriterImpl`.
- Add integration tests for the new encoding, which should be similar to existing tests, but
have the `smt-encoding` flag set to `arrays`.
- Refactor the classes in `tla-bmcmt/src/test` to enable unit testing with different configurations
of `SolverConfig` and implementations of `SymbStateRewriter`.
- Add unit tests for the new encoding, which should be similar to existing tests, but use a
different solver configuration and `SymbStateRewriterImplWithArrays` instead of `SymbStateRewriterImpl`.
- Add integration tests for the new encoding by tagging existing tests with `array-encoding`, which
will be run by the CI with envvar `SMT_ENCODING` set to `arrays`.

## 3. Encoding sets

Expand Down Expand Up @@ -126,11 +129,25 @@ For consistency, the new encoding uses constant arrays to declare both finite an

The following changes will be made to implement the new encoding of sets:

- Add alternative rewriting rules for sets, via new classes extending `RewritingRule`.
- The new rules will use SMT equality directly, instead of relying on class `LazyEquality`.
- In class `SymbStateRewriterImplWithArrays`, overwrite `ruleLookupTable` with the new rules.
- Existing rules will be reused when appropriate, e.g. rules for handling Boolean constants.
- In class `Z3SolverContext`, add appropriate methods to handle SMT constraints over arrays.
- Add alternative rewriting rules for sets when appropriate, by extending the existing rules.
- All alternative rules will be suffixed with `WithArrays`.
- The new rules will not rely on `LazyEquality` and will aim to use SMT equality directly.
- Only the generation of SMT constraints will be modified by the new rules, the other Arena
elements will remain unchanged.
- In class `SymbStateRewriterImplWithArrays`, add the new rules to `ruleLookupTable` by overriding
the entries to their older versions.
- In class `Z3SolverContext`, add/change appropriate methods to handle SMT constraints over arrays.
- The main changes will de done in `declareCell`, `declareInPredIfNeeded`, and `getInPred`, as
these methods are directly responsible for creating the SMT constraints representing sets and
set membership.
- Cases for `FinSetT` and `PowSetT` will be added to `getOrMkCellSort`, as these types are no
longer represented by uninterpreted constants.
- `cellCache` will be changed to contain a list of cells, in order to handle the effects of
`push` and `pop` in the SSA assignment of sets.
- A new cache, `inStored`, will provide the required information to `getInPred` to enable it to
return either a `store` or a `select` constraint, when appropriate.
- Special cases for `TlaOper.eq` and `TlaBoolOper.equiv` will be added to `toExpr`, to allow the
set filter rule to propagate SSA sets when the filter predicate evaluates for false.

## 4. Encoding tuples and records

Expand All @@ -151,4 +168,5 @@ TODO
[SMT-LIB Standard]: http://smtlib.cs.uiowa.edu/index.shtml
[Version 2.6]: https://smtlib.cs.uiowa.edu/papers/smt-lib-reference-v2.6-r2017-07-18.pdf
[TLA+ Model Checking Made Symbolic]: https://dl.acm.org/doi/10.1145/3360549
[model checking parameters]: https://apalache.informal.systems/docs/apalache/running.html#model-checker-command-line-parameters
[represented internally in Z3]: https://theory.stanford.edu/~nikolaj/programmingz3.html#sec-arrays
Loading