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

Integrating types 4: migrated tests to Snowcat #652

Merged
merged 4 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@

### Features

* Model checker: receiving the types from with the type checker Snowcat, see #668 and #350
* Type checker: the old Apalache type annotations are no longer supported, see #668
* Type checker: tagging all expressions with the reconstructed types, see #608
* Type checker: experimental option `check --with-snowcat`, see #632
* Type checker: handling TLA+ labels like `lab("a", "b") :: e`, see #653
* Preprocessing: handling the general case of EXCEPT, see #647

### Changed

* Preprocessing: massive refactoring of the passes to support types. This may have introduced unexpected bugs.
* Model checker: translation rules for records and functions have been modified, in order to support new types. Bugs to
be expected.

### Known issues

Expand Down
2 changes: 1 addition & 1 deletion mod-tool/src/main/scala/at/forsyte/apalache/tla/Tool.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ object Tool extends App with LazyLogging {
executor.options.set("checker.noDeadlocks", check.noDeadlocks)
executor.options.set("checker.algo", check.algo)
// this option enables the new type checker in the pipeline
executor.options.set("typechecker.snowcatOn", check.withSnowcat)
executor.options.set("typechecker.snowcatOn", true)
// for now, enable polymorphic types. We probably want to disable this option for the type checker
executor.options.set("typechecker.inferPoly", true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,4 @@ class CheckCmd extends Command(name = "check", description = "Check a TLA+ speci
"pre-check, whether a transition is disabled, and discard it, to make SMT queries smaller, default: true")
var noDeadlocks: Boolean =
opt[Boolean](name = "no-deadlock", default = true, description = "do not check for deadlocks, default: true")
var withSnowcat: Boolean =
opt[Boolean](name = "with-snowcat", default = false, description = "use the new type checker Snowcat")
}
5 changes: 4 additions & 1 deletion test/tla/Assignments20200309.tla
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
----- MODULE Assignments20200309 -----
VARIABLE a
VARIABLE
\* @type: Int;
a

\* this specification fails, as it has no expression
\* that can be treated as an assignment
Init == TRUE
Expand Down
10 changes: 4 additions & 6 deletions test/tla/Bug20190118.tla
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
(* BMCMT extensions *)
RM == {"r1", "r2"}

a <: b == a \* a type annotation

\* new: a message type
MT == [type |-> STRING, rm |-> STRING]
(* END OF BMCMT extensions *)
Expand All @@ -23,19 +21,19 @@ VARIABLES
Message ==
{[type |-> t, rm |-> r]: t \in {"Prepared"}, r \in RM }
\cup
{([type |-> t] <: MT) : t \in {"Commit", "Abort"} }
{[type |-> t] : t \in {"Commit", "Abort"} }

Init ==
/\ rmState \in [RM -> {"working", "prepared"}]
/\ msgs \in SUBSET Message \* this is a problematic statement
/\ rmState["r1"] = "working"
/\ rmState["r2"] = "prepared"
/\ tmPrepared = {"r2"}
/\ msgs = {[type |-> "Prepared", rm |-> "r2"] <: MT}
/\ msgs = {[type |-> "Prepared", rm |-> "r2"]}

TMCommit ==
/\ tmPrepared = RM
/\ msgs' = msgs \cup {[type |-> "Commit"] <: MT}
/\ msgs' = msgs \cup {[type |-> "Commit"]}
/\ UNCHANGED <<rmState, tmPrepared>>

RMPrepare(rm) ==
Expand All @@ -47,6 +45,6 @@ RMPrepare(rm) ==
Next == TMCommit \/ RMPrepare("r1")
-----------------------------------------------------------------------------
\* this invariant cannot be violated in one step
Inv == ([type |-> "Commit"] <: MT) \notin msgs
Inv == [type |-> "Commit"] \notin msgs

=============================================================================
8 changes: 6 additions & 2 deletions test/tla/Bug20190921.tla
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ EXTENDS Integers

\* constants and variables should propagate
\* in the transformations
CONSTANT N
CONSTANT
\* @type: Int;
N

VARIABLE x
VARIABLE
\* @type: Int;
x

CInit == N \in 1..10

Expand Down
4 changes: 3 additions & 1 deletion test/tla/Bug20200306.tla
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
----- MODULE Bug20200306 -----
VARIABLE a
VARIABLE
\* @type: Int;
a
Init == a = 1
Next == a' = a
Inv == FALSE
Expand Down
4 changes: 3 additions & 1 deletion test/tla/Callback.tla
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
----------------------------- MODULE Callback ----------------------------
EXTENDS Integers

VARIABLES x
VARIABLES
\* @type: Int;
x

Pick(Cb(_)) ==
\E i \in 1..10:
Expand Down
4 changes: 3 additions & 1 deletion test/tla/Config.tla
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
(* a specification to check whether the configuration files are parsed *)
EXTENDS Integers

VARIABLES x
VARIABLES
\* @type: Int;
x

\* the default init
Init ==
Expand Down
16 changes: 15 additions & 1 deletion test/tla/ConfigParams.tla
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
--------------------------- MODULE ConfigParams -------------------------------
CONSTANTS
\* @type: Int;
MyInt,
\* @type: Str;
MyStr,
\* TODO: use a model type here
\* when #570 is closed: https://github.com/informalsystems/apalache/issues/570
\* @type: Str;
MyModelValue1,
\* @type: Str;
MyModelValue2,
\* @type: Set(Int);
MySet

VARIABLES
x, y, z, w
\* @type: Int;
x,
\* @type: Str;
y,
\* @type: Str;
z,
\* @type: Set(Int);
w

Init ==
/\ x = MyInt
Expand Down
4 changes: 3 additions & 1 deletion test/tla/ConfigReplacements.tla
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
----------------------- MODULE ConfigReplacements -----------------------------
VARIABLES x
VARIABLES
\* @type: Int;
x

Value == 0

Expand Down
4 changes: 3 additions & 1 deletion test/tla/ConfigUnsorted.tla
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
-------------------------- MODULE ConfigUnsorted ----------------------------------------
(* A specification that introduces preprocessing issues *)
VARIABLES x
VARIABLES
\* @type: Int;
x

A == 1
B == 2
Expand Down
4 changes: 3 additions & 1 deletion test/tla/Counter.tla
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
------ MODULE Counter ------
EXTENDS Naturals

VARIABLES x
VARIABLES
\* @type: Int;
x

Init == x \in 1..1000

Expand Down
10 changes: 9 additions & 1 deletion test/tla/EWD840.tla
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ EXTENDS Naturals
N == 4
(*ASSUME NAssumption == N \in Nat \ {0}*)

VARIABLES active, color, tpos, tcolor
VARIABLES
\* @type: Int -> Bool;
active,
\* @type: Int -> Str;
color,
\* @type: Int;
tpos,
\* @type: Str;
tcolor

Nodes == 0 .. N-1
Color == {"white", "black"}
Expand Down
4 changes: 3 additions & 1 deletion test/tla/ExistsAsValue.tla
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
------------------------ MODULE ExistsAsValue -------------------------
\* a test for the issue #148
VARIABLES x
VARIABLES
\* @type: Bool;
x

Init ==
x = TRUE
Expand Down
5 changes: 1 addition & 4 deletions test/tla/Fix365_ExistsSubset3.tla
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
(* A tricky bug that happened in evidence handling *)
EXTENDS Integers

\* old apalache annotations
a <: b == a

Proc == {"p1", "p2"}
Rounds == { 0, 1, 2 }

Expand All @@ -27,7 +24,7 @@ Next ==
LET \* @type: Set(Str);
Y == { m.src: m \in msgs } IN
\* the third ingredient of the bug
/\ msgs /= {} <: {MT}
/\ msgs /= {}
/\ UNCHANGED msgs

===============================================================================
24 changes: 14 additions & 10 deletions test/tla/HandshakeWithTypes.tla
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
*)
EXTENDS Integers

VARIABLES msgs, \* the set of all messages
iseqno, \* Initiator's sequence number
rseqno, \* Receiver's sequence number
istate, \* Initiator's state
rstate \* Receiver's state

a <: b == a
VARIABLES
\* @type: Set([syn: Bool, ack: Bool, seqno: Int, ackno: Int]);
msgs, \* the set of all messages
\* @type: Int;
iseqno, \* Initiator's sequence number
\* @type: Int;
rseqno, \* Receiver's sequence number
\* @type: Str;
istate, \* Initiator's state
\* @type: Str;
rstate \* Receiver's state

MT == [syn |-> BOOLEAN, ack |-> BOOLEAN, seqno |-> Int, ackno |-> Int]

Init ==
/\ msgs = {} <: {MT}
/\ msgs = {}
/\ iseqno = 0
/\ rseqno = 0
/\ istate = "INIT"
Expand All @@ -28,15 +32,15 @@ SendSyn ==
/\ istate = "INIT"
/\ \E no \in Nat:
/\ msgs' = msgs \union {[syn |-> TRUE,
ack |-> FALSE, seqno |-> no] <: MT}
ack |-> FALSE, seqno |-> no]}
/\ iseqno' = no + 1
/\ istate' = "SYN-SENT"
/\ UNCHANGED <<rseqno, rstate>>

SendSynAck ==
/\ rstate = "LISTEN"
/\ \E seqno, ackno \in Nat:
/\ ([syn |-> TRUE, ack |-> FALSE, seqno |-> seqno] <: MT) \in msgs
/\ [syn |-> TRUE, ack |-> FALSE, seqno |-> seqno] \in msgs
/\ msgs' = msgs \union {[syn |-> TRUE, ack |-> TRUE,
seqno |-> seqno + 1,
ackno |-> ackno]}
Expand Down
5 changes: 4 additions & 1 deletion test/tla/HourClock.tla
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
\* This is a local copy of the example from Specifying Systems:
\* https://github.com/tlaplus/Examples/blob/master/specifications/SpecifyingSystems/RealTime/HourClock.tla
EXTENDS Naturals
VARIABLE hr
VARIABLE
\* @type: Int;
hr

HCini == hr \in (1 .. 12)
HCnxt == hr' = IF hr # 12 THEN hr + 1 ELSE 1
HC == HCini /\ [][HCnxt]_hr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
------------------------------ MODULE ITE_CASE ------------------------------
VARIABLES x, y
VARIABLES
\* @type: Int;
x,
\* @type: Int;
y

S == {1,2,3}

Expand All @@ -11,6 +15,9 @@ ITE(p, et, ee) == /\ IF p THEN et ELSE ee

Next == ITE( x = y', x' = 2, x' \in S )

Spec == /\ Init /\ [][Next]_<<x,y>>
\* @type: <<Int, Int>>;
vars == <<x, y>>

Spec == /\ Init /\ [][Next]_vars

=============================================================================
4 changes: 3 additions & 1 deletion test/tla/Inline.tla
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---------------------------- MODULE Inline -------------------------------
VARIABLE x
VARIABLE
\* @type: Int;
x

A == 3

Expand Down
4 changes: 3 additions & 1 deletion test/tla/NatCounter.tla
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
----------------------------- MODULE NatCounter ------------------------
EXTENDS Naturals

VARIABLE x
VARIABLE
\* @type: Int;
x

Init == x = 3

Expand Down
16 changes: 10 additions & 6 deletions test/tla/NeedForTypesWithTypes.tla
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
*)
EXTENDS Integers, Sequences, FiniteSets

CONSTANTS InSet \* an input set
VARIABLES Left, \* a storage for the yet untransformed elements
OutSeq \* the output sequence
CONSTANTS
\* @type: Set(Int);
InSet \* an input set

a <: b == a
VARIABLES
\* @type: Set(Int);
Left, \* a storage for the yet untransformed elements
\* @type: Seq(Int);
OutSeq \* the output sequence

ConstInit == InSet = 1..4

Init ==
/\ OutSeq = << >> <: Seq(Int)
/\ OutSeq = << >>
/\ Left = InSet

Next ==
IF Left = {} <: {Int}
IF Left = {}
THEN UNCHANGED <<Left, OutSeq>>
ELSE \E x \in Left:
/\ OutSeq' = Append(OutSeq, x)
Expand Down
6 changes: 4 additions & 2 deletions test/tla/NonNullaryLet.tla
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
--------------- MODULE NonNullaryLet ----------------
EXTENDS Integers
VARIABLE n
VARIABLE
\* @type: Int;
n

Foo == LET r(x) == TRUE IN r(1)

Init == n = 0

Next == Foo /\ n' = 1
===========================================
===========================================
Loading