Skip to content

Commit a0ac348

Browse files
authored
Fixing a few specs and the parse tests (#383)
* update two specs with the new syntax * fix parse tests * fix the error message * address Shon's comments * fix the error message * remove json-diff
1 parent 6721e34 commit a0ac348

22 files changed

+600
-301
lines changed

examples/LamportMutex/LamportMutex.tnt

+47-45
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ module LamportMutex {
4444
val Message = Set(AckMessage, RelMessage).union(Clock.map(c => ReqMessage(c)))
4545

4646
action Init = all {
47-
clock <- Proc.mapBy(p => 0),
48-
req <- Proc.mapBy(p => Proc.mapBy(q => 0)),
49-
ack <- Proc.mapBy(p => Set()),
50-
network <- Proc.mapBy(p => Proc.mapBy(q => List())),
51-
crit <- Set(),
47+
clock' = Proc.mapBy(p => 0),
48+
req' = Proc.mapBy(p => Proc.mapBy(q => 0)),
49+
ack' = Proc.mapBy(p => Set()),
50+
network' = Proc.mapBy(p => Proc.mapBy(q => List())),
51+
crit' = Set(),
5252
}
5353

5454
/* beats(p,q) is true if process p believes that its request has higher
@@ -73,11 +73,11 @@ module LamportMutex {
7373
// Process p requests access to critical section.
7474
action Request(p) = all {
7575
req.get(p).get(p) == 0,
76-
req <- req.setBy(p, r => r.setBy(p, c => clock.get(p))),
77-
network <- network.setBy(p, n => Broadcast(p, ReqMessage(clock.get(p)))),
78-
ack <- ack.set(p,Set(p)),
79-
clock <- clock,
80-
crit <- crit,
76+
req' = req.setBy(p, r => r.setBy(p, c => clock.get(p))),
77+
network' = network.setBy(p, n => Broadcast(p, ReqMessage(clock.get(p)))),
78+
ack' = ack.set(p,Set(p)),
79+
clock' = clock,
80+
crit' = crit,
8181
}
8282

8383
// Process p receives a request from q and acknowledges it.
@@ -87,79 +87,81 @@ module LamportMutex {
8787
val c = m.clock
8888
all {
8989
m.mtype == "req",
90-
req <- req.setBy(p, a => a.setBy(q, b => c)),
91-
clock <- clock.setBy(p, a => if (c > a) c + 1 else a + 1),
92-
network <- network.setBy(q, a => a.setBy(p, b => b.tail()))
90+
req' = req.setBy(p, a => a.setBy(q, b => c)),
91+
clock' = clock.setBy(p, a => if (c > a) c + 1 else a + 1),
92+
network' = network.setBy(q, a => a.setBy(p, b => b.tail()))
9393
.setBy(p, a => a.setBy(q, b => b.append(AckMessage))),
9494
},
95-
ack <- ack,
96-
crit <- crit,
95+
ack' = ack,
96+
crit' = crit,
9797
}
9898

9999
// Process p receives an acknowledgement from q.
100100
action ReceiveAck(p, q) = all {
101101
network.get(p).get(q) != List(),
102102
val m = network.get(p).get(q).head() all {
103103
m.mtype == "ack",
104-
network <- network.setBy(p, a => a.setBy(q, b => b.tail())),
105-
ack <- ack.setBy(p, a => a.union(Set(q))),
104+
network' = network.setBy(p, a => a.setBy(q, b => b.tail())),
105+
ack' = ack.setBy(p, a => a.union(Set(q))),
106106
},
107-
clock <- clock,
108-
req <- req,
109-
crit <- crit,
107+
clock' = clock,
108+
req' = req,
109+
crit' = crit,
110110
}
111111

112112
// Process p enters the critical section.
113113
action Enter(p) = all {
114114
ack.get(p) == Proc,
115115
Proc.forall(q => beats(p, q)),
116-
crit <- crit.union(Set(p)),
117-
clock <- clock,
118-
req <- req,
119-
ack <- ack,
120-
network <- network,
116+
crit' = crit.union(Set(p)),
117+
clock' = clock,
118+
req' = req,
119+
ack' = ack,
120+
network' = network,
121121
}
122122

123123
// Process p exits the critical section and notifies other processes.
124124
action Exit(p) = all {
125125
p.in(crit),
126-
crit <- crit.exclude(Set(p)),
127-
network <- network.set(p, Broadcast(p, RelMessage)),
128-
req <- req.setBy(p, r => r.set(p, 0)),
129-
ack <- ack.set(p, Set()),
130-
clock <- clock,
126+
crit' = crit.exclude(Set(p)),
127+
network' = network.set(p, Broadcast(p, RelMessage)),
128+
req' = req.setBy(p, r => r.set(p, 0)),
129+
ack' = ack.set(p, Set()),
130+
clock' = clock,
131131
}
132132

133133
// Process p receives a release notification from q.
134134
action ReceiveRelease(p,q) = all {
135135
network.get(p).get(q) != List(),
136136
val m = network.get(p).get(q).head() all {
137137
m.mtype == "rel",
138-
req <- req.setBy(p, r => r.set(q, 0)),
139-
network <- network.setBy(p, a => a.setBy(q, b => b.tail())),
138+
req' = req.setBy(p, r => r.set(q, 0)),
139+
network' = network.setBy(p, a => a.setBy(q, b => b.tail())),
140140
},
141-
clock <- clock,
142-
ack <- ack,
143-
crit <- crit,
141+
clock' = clock,
142+
ack' = ack,
143+
crit' = crit,
144144
}
145145

146146
// Next-state relation.
147-
action Next = any {
148-
Proc.guess(p => any {
147+
action Next = {
148+
nondet p = oneOf(Proc)
149+
any {
149150
Request(p),
150151
Enter(p),
151152
Exit(p),
152-
}),
153-
Proc.guess(p => Proc.guess(q => any {
154-
ReceiveRequest(p,q),
155-
ReceiveAck(p,q),
156-
ReceiveRelease(p,q),
157-
})),
158-
}
153+
nondet q = oneOf(Proc)
154+
any {
155+
ReceiveRequest(p,q),
156+
ReceiveAck(p,q),
157+
ReceiveRelease(p,q),
158+
}
159+
}
160+
}
159161

160162
/* A state constraint that is useful for validating the specification
161163
using finite-state model checking. */
162-
val ClockConstraint = Proc.forall(p => clock.get(p) <= maxClock)
164+
val ClockConstraint = Proc.forall(p => (clock.get(p) <= maxClock))
163165

164166
/* No channel ever contains more than three messages. In fact, no channel
165167
ever contains more than one message of the same type, as proved below.*/

examples/Paxos/Paxos.tnt

+41-37
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,18 @@ val TypeOK = and {
101101
}
102102

103103
action Init = all {
104-
maxBal <- Acceptor.mapBy(_ => -1),
105-
maxVBal <- Acceptor.mapBy(_ => -1),
106-
maxVal <- Acceptor.mapBy(_ => None),
107-
msgs <- Set(),
104+
maxBal' = Acceptor.mapBy(_ => -1),
105+
maxVBal' = Acceptor.mapBy(_ => -1),
106+
maxVal' = Acceptor.mapBy(_ => None),
107+
msgs' = Set(),
108108
}
109109

110110
/***************************************************************************)
111111
(* The actions. We begin with the subaction (an action that will be used *)
112112
(* to define the actions that make up the next-state action. *)
113113
(***************************************************************************/
114114
action Send(m) = {
115-
msgs <- msgs.union(Set(m))
115+
msgs' = msgs.union(Set(m))
116116
}
117117

118118
/***************************************************************************)
@@ -123,8 +123,8 @@ action Send(m) = {
123123
(***************************************************************************/
124124
action Phase1a(b) = all {
125125
Send({ tag: "1a", bal: b }),
126-
maxVBal <- maxVBal,
127-
maxVal <- maxVal,
126+
maxVBal' = maxVBal,
127+
maxVal' = maxVal,
128128
}
129129

130130
/***************************************************************************)
@@ -134,15 +134,15 @@ action Phase1a(b) = all {
134134
(* maxVBal[a] and maxVal[a]. *)
135135
(***************************************************************************/
136136
action Phase1b(a) = {
137-
msgs.filter(m => m.tag == "1a")
138-
.guess(m => all {
139-
m.bal > maxBal.get(a),
140-
maxBal <- maxBal.set(a, m.bal),
141-
Send({ tag: "1b", acc: a, bal: m.bal,
142-
mbal: maxVBal.get(a), mval: maxVal.get(a) }),
143-
maxVBal <- maxVBal,
144-
maxVal <- maxVal,
145-
})
137+
nondet m = msgs.filter(m2 => m2.tag == "1a").oneOf()
138+
all {
139+
m.bal > maxBal.get(a),
140+
Send({ tag: "1b", acc: a, bal: m.bal,
141+
mbal: maxVBal.get(a), mval: maxVal.get(a) }),
142+
maxBal' = maxBal.set(a, m.bal),
143+
maxVBal' = maxVBal,
144+
maxVal' = maxVal,
145+
}
146146
}
147147

148148
/***************************************************************************)
@@ -184,8 +184,8 @@ action Phase2a(b, v) = all {
184184
}
185185
),
186186
Send({ tag: "2a", bal: b, value: v }),
187-
maxVBal <- maxVBal,
188-
maxVal <- maxVal,
187+
maxVBal' = maxVBal,
188+
maxVal' = maxVal,
189189
}
190190

191191
/***************************************************************************)
@@ -197,15 +197,16 @@ action Phase2a(b, v) = all {
197197
(* phase 2b message announcing its vote. It also sets maxBal[a] to the *)
198198
(* message's. ballot number *)
199199
(***************************************************************************/
200-
action Phase2b(a) = msgs.filter(m => m.tag == "2a")
201-
.guess(m => all {
202-
m.bal >= maxBal.get(a),
203-
maxBal <- maxBal.set(a, m.bal),
204-
maxVBal <- maxVBal.set(a, m.bal),
205-
maxVal <- maxVal.set(a, m.value),
206-
Send({ tag: "2b", acc: a,
207-
bal: m.bal, value: m.value }),
208-
})
200+
action Phase2b(a) = {
201+
nondet m = msgs.filter(m2 => m2.tag == "2a").oneOf()
202+
all {
203+
m.bal >= maxBal.get(a),
204+
Send({ tag: "2b", acc: a, bal: m.bal, value: m.value }),
205+
maxBal' = maxBal.set(a, m.bal),
206+
maxVBal' = maxVBal.set(a, m.bal),
207+
maxVal' = maxVal.set(a, m.value),
208+
}
209+
}
209210

210211
/***************************************************************************)
211212
(* In an implementation, there will be learner processes that learn from *)
@@ -217,17 +218,20 @@ action Phase2b(a) = msgs.filter(m => m.tag == "2a")
217218
(* Below are defined the next-state action and the complete spec. *)
218219
(***************************************************************************/
219220
action Next = any {
220-
all {
221-
Ballot.guess(b => any {
222-
Phase1a(b),
223-
Value.guess(v => Phase2a(b, v)),
224-
}),
225-
maxBal <- maxBal,
221+
all {
222+
nondet b = oneOf(Ballot)
223+
any {
224+
Phase1a(b),
225+
nondet v = oneOf(Value)
226+
Phase2a(b, v)
226227
},
227-
Acceptor.guess(a => any {
228-
Phase1b(a),
229-
Phase2b(a),
230-
}),
228+
maxBal' = maxBal,
229+
},
230+
nondet a = oneOf(Acceptor)
231+
any {
232+
Phase1b(a),
233+
Phase2b(a),
234+
}
231235
}
232236

233237
temporal Spec = Init and always(stutter(Next, vars))

examples/Paxos/Voting.tnt

+15-12
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ THEOREM ShowsSafety ==
164164
(* straightforward. *)
165165
(***************************************************************************/
166166
action Init = all {
167-
votes <- Acceptor.mapBy(_ => Set()),
168-
maxBal <- Acceptor.mapBy(_ => -1),
167+
votes' = Acceptor.mapBy(_ => Set()),
168+
maxBal' = Acceptor.mapBy(_ => -1),
169169
}
170170

171171

@@ -177,8 +177,8 @@ action Init = all {
177177
(***************************************************************************/
178178
action IncreaseMaxBal(a, b) = all {
179179
b > maxBal.get(a),
180-
maxBal <- maxBal.set(a, b),
181-
votes <- votes,
180+
maxBal' = maxBal.set(a, b),
181+
votes' = votes,
182182
}
183183

184184
/***************************************************************************)
@@ -196,20 +196,23 @@ action VoteFor(a, b, v) = all {
196196
votes.get(c).forall( vt => (vt._1 == b) implies (vt._2 == v) )
197197
),
198198
Quorum.exists( Q => ShowsSafeAt(Q, b, v) ),
199-
votes <- votes.setBy(a, old => old.union(Set((b, v))) ),
200-
maxBal <- maxBal.set(a, b),
199+
votes' = votes.setBy(a, old => old.union(Set((b, v))) ),
200+
maxBal' = maxBal.set(a, b),
201201
}
202202

203203

204204
/***************************************************************************)
205205
(* The next-state action and the invariant. *)
206206
(***************************************************************************/
207-
action Next =
208-
tuples(Acceptor, Ballot).guess((a, b) => any {
209-
IncreaseMaxBal(a, b),
210-
Value.guess(v => VoteFor(a, b, v)),
211-
}
212-
)
207+
action Next = {
208+
nondet a = oneOf(Acceptor)
209+
nondet b = oneOf(Ballot)
210+
any {
211+
IncreaseMaxBal(a, b),
212+
nondet v = oneOf(Value)
213+
VoteFor(a, b, v),
214+
}
215+
}
213216

214217
temporal Spec = Init and always(stutter(Next, (votes, maxBal)))
215218

0 commit comments

Comments
 (0)