Skip to content

Commit b61a682

Browse files
committed
resource: make Loc a newtype to avoid int confusion
1 parent f95ae8a commit b61a682

File tree

8 files changed

+35
-19
lines changed

8 files changed

+35
-19
lines changed

examples/pcm/agreement.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ impl<T> AgreementResource<T> {
132132
ensures
133133
self.inv(),
134134
result.inv(),
135-
self.id() == result.id() == old(self).id(),
135+
self.id() == old(self).id(),
136+
result.id() == old(self).id(),
136137
self@ == result@,
137138
self@ == old(self)@,
138139
{

examples/pcm/count_to_two.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::sync::Arc;
1010
use vstd::atomic::*;
1111
use vstd::atomic_ghost::*;
1212
use vstd::invariant::*;
13+
use vstd::resource::Loc;
1314

1415
verus! {
1516

@@ -40,8 +41,8 @@ pub struct CounterTrackedState {
4041
// `oneshot1_id` -- the ID of thread 1's one-shot
4142
pub struct CounterInvariantConstants {
4243
pub x_id: int,
43-
pub oneshot0_id: int,
44-
pub oneshot1_id: int,
44+
pub oneshot0_id: Loc,
45+
pub oneshot1_id: Loc,
4546
}
4647

4748
// This is the invariant predicate that will be maintained for the
@@ -99,7 +100,7 @@ impl CounterSharedState {
99100

100101
// This function gets, from the shared state's constants, the ID
101102
// of the one-shot associated with the given thread.
102-
pub open spec fn get_oneshot_id(self, which_thread: int) -> int
103+
pub open spec fn get_oneshot_id(self, which_thread: int) -> Loc
103104
recommends
104105
which_thread == 0 || which_thread == 1,
105106
{

examples/pcm/log.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ impl<T> LogResource<T> {
205205
let (half1, half2) = halves;
206206
&&& half1@ is HalfAuthority
207207
&&& half2@ is HalfAuthority
208-
&&& half1.id() == half2.id() == self.id()
208+
&&& half1.id() == self.id()
209+
&&& half2.id() == self.id()
209210
&&& half1@.log() == self@.log()
210211
&&& half2@ == half1@
211212
}),
@@ -234,7 +235,8 @@ impl<T> LogResource<T> {
234235
old(self).id() == old(other).id(),
235236
ensures
236237
self@ is HalfAuthority,
237-
self.id() == other.id() == old(self).id(),
238+
self.id() == old(self).id(),
239+
other.id() == old(self).id(),
238240
self@.log() == old(self)@.log() + seq![v],
239241
other@ == self@,
240242
{

examples/pcm/monotonic_counter.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ impl MonotonicCounterResource {
240240
({
241241
let (r1, r2) = return_value;
242242
let value = self@->FullRightToAdvance_value;
243-
&&& r1.id() == r2.id() == self.id()
243+
&&& r1.id() == self.id()
244+
&&& r2.id() == self.id()
244245
&&& r1@ == (MonotonicCounterResourceValue::HalfRightToAdvance { value })
245246
&&& r2@ == r1@
246247
}),
@@ -281,7 +282,8 @@ impl MonotonicCounterResource {
281282
old(other)@ is HalfRightToAdvance,
282283
ensures
283284
old(self)@ == old(other)@,
284-
self.id() == other.id() == old(self).id(),
285+
self.id() == old(self).id(),
286+
other.id() == old(self).id(),
285287
other@ == self@,
286288
self@ == (MonotonicCounterResourceValue::HalfRightToAdvance {
287289
value: old(self)@->HalfRightToAdvance_value + 1,
@@ -339,7 +341,8 @@ fn main() {
339341
proof {
340342
half1.increment_using_two_halves(&mut half2);
341343
}
342-
assert(half1.id() == half2.id() == id);
344+
assert(half1.id() == id);
345+
assert(half2.id() == id);
343346
assert(half1@.n() == half2@.n() == v1 + 1);
344347
assert(half1@.n() == 1);
345348
let tracked mut lower_bound = half1.extract_lower_bound();

examples/pcm/oneshot.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
//! ```
4242
//! let ghost id = half1.id();
4343
//! proof { half1.perform_using_two_halves(&mut half2); }
44-
//! assert(half1.id() == half2.id() == id);
44+
//! assert(half1.id() == id);
45+
//! assert(half2.id() == id);
4546
//! assert(half1@ is Complete);
4647
//! assert(half2@ is Complete);
4748
//! ```
@@ -173,7 +174,8 @@ impl OneShotResource {
173174
let (half1, half2) = return_value;
174175
&&& half1@ is HalfRightToComplete
175176
&&& half2@ is HalfRightToComplete
176-
&&& half2.id() == half1.id() == self.id()
177+
&&& half1.id() == self.id()
178+
&&& half2.id() == self.id()
177179
}),
178180
{
179181
let half = OneShotResourceValue::HalfRightToComplete { };
@@ -219,7 +221,8 @@ impl OneShotResource {
219221
old(other)@ is HalfRightToComplete,
220222
self@ is Complete,
221223
other@ is Complete,
222-
other.id() == self.id() == old(self).id(),
224+
self.id() == old(self).id(),
225+
other.id() == old(self).id(),
223226
{
224227
self.r.validate();
225228
other.r.validate();
@@ -277,11 +280,13 @@ fn main() {
277280
proof {
278281
half1.perform_using_two_halves(&mut half2);
279282
}
280-
assert(half1.id() == half2.id() == id);
283+
assert(half1.id() == id);
284+
assert(half2.id() == id);
281285
assert(half1@ is Complete);
282286
assert(half2@ is Complete);
283287
let tracked knowledge = half1.duplicate();
284-
assert(knowledge.id() == half1.id() == id);
288+
assert(knowledge.id() == id);
289+
assert(half1.id() == id);
285290
assert(knowledge@ is Complete);
286291
}
287292

source/vstd/resource/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ pub proof fn split_mut<P: PCM>(tracked r: &mut Resource<P>, left: P, right: P) -
114114
requires
115115
old(r).value() == P::op(left, right),
116116
ensures
117-
r.loc() == other.loc() == old(r).loc(),
117+
r.loc() == old(r).loc(),
118+
other.loc() == old(r).loc(),
118119
r.value() == left,
119120
other.value() == right,
120121
{
@@ -152,7 +153,8 @@ pub proof fn redistribute<P: PCM>(
152153
old(r1).loc() == old(r2).loc(),
153154
P::op(old(r1).value(), old(r2).value()) == P::op(v1, v2),
154155
ensures
155-
r1.loc() == r2.loc() == old(r1).loc(),
156+
r1.loc() == old(r1).loc(),
157+
r2.loc() == old(r1).loc(),
156158
r1.value() == v1,
157159
r2.value() == v2,
158160
{
@@ -178,7 +180,8 @@ pub proof fn update_and_redistribute<P: PCM>(
178180
old(r1).loc() == old(r2).loc(),
179181
frame_preserving_update(P::op(old(r1).value(), old(r2).value()), P::op(v1, v2)),
180182
ensures
181-
r1.loc() == r2.loc() == old(r1).loc(),
183+
r1.loc() == old(r1).loc(),
184+
r2.loc() == old(r1).loc(),
182185
r1.value() == v1,
183186
r2.value() == v2,
184187
{

source/vstd/resource/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub use lib::*;
1313

1414
verus! {
1515

16-
pub type Loc = int;
16+
#[derive(Eq, PartialEq)]
17+
pub struct Loc(int);
1718

1819
} // verus!

source/vstd/tokens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ broadcast use {
1919
/// Unique identifier for every VerusSync instance.
2020
/// Every "Token" and "Instance" object has an `InstanceId`. These ID values must agree
2121
/// to perform any token operation.
22-
pub ghost struct InstanceId(pub int);
22+
pub type InstanceId = super::resource::Loc;
2323

2424
/// Interface for VerusSync tokens created for a field marked with the
2525
/// `variable`, `option` or `persistent_option` strategies.

0 commit comments

Comments
 (0)