vstd/
invariant.rs

1#[allow(unused_imports)]
2use super::pervasive::*;
3#[allow(unused_imports)]
4use super::prelude::*;
5
6// TODO:
7//  * utility for conveniently creating unique namespaces
8
9// An invariant storing objects of type V needs to be able to have some kind of configurable
10// predicate `V -> bool`. However, doing this naively with a fully configurable
11// predicate function would result in V being reject_recursive_types,
12// which is too limiting and prevents important use cases with recursive types.
13
14//
15// Instead, we allow the user to specify a predicate which is fixed *at the type level*
16// which we do through this trait, InvariantPredicate. However, the predicate still
17// needs to be "dynamically configurable" upon the call to the invariant constructor.
18// To support this, we add another type parameter K, a constant is fixed for a given
19// Invariant object.
20//
21// So each Invariant object has 3 type parameters:
22//  * K - A "constant" which is specified at constructor time
23//  * V - Type of the stored 'tracked' object
24//  * Pred: InvariantPredicate - provides the predicate (K, V) -> bool
25//
26// With this setup, we can now declare both K and V without reject_recursive_types.
27// To be sure, note that the following, based on our trait formalism,
28// is well-formed CIC (Coq), without any type polarity issues:
29//
30// ```
31//    Inductive InvariantPredicate K V :=
32//        | inv_pred : (K -> V -> bool) -> InvariantPredicate K V.
33//
34//    Inductive Inv (K V: Type) (x: InvariantPredicate K V) :=
35//      | inv : K -> Inv K V x.
36//
37//    Definition some_predicate (V: Type) : InvariantPredicate nat V :=
38//      inv_pred nat V (fun k v => false). (* an arbitrary predicate *)
39//
40//    (* example recursive type *)
41//    Inductive T :=
42//      | A : (Inv nat T (some_predicate T)) -> T.
43// ```
44//
45// Note that the user can always just set K to be `V -> bool` in order to make the
46// Invariant's predicate maximally configurable without having to restrict it at the
47// type level. By doing so, the user opts in to the negative usage of V in exchange
48// for the flexibility.
49
50verus! {
51
52/// Trait used to specify an _invariant predicate_ for
53/// [`LocalInvariant`] and [`AtomicInvariant`].
54pub trait InvariantPredicate<K, V> {
55    spec fn inv(k: K, v: V) -> bool;
56}
57
58} // verus!
59// LocalInvariant is NEVER `Sync`.
60//
61// Furthermore, for either type:
62//
63//  * If an Invariant<T> is Sync, then T must be Send
64//      * We could put the T in an Invariant, sync the invariant to another thread,
65//        and then extract the T, having effectively send it to the other thread.
66//  * If Invariant<T> is Send, then T must be Send
67//      * We could put the T in an Invariant, send the invariant to another thread,
68//        and then take the T out.
69//
70// So the Sync/Send-ness of the Invariant depends on the Send-ness of T;
71// however, the Sync-ness of T is unimportant (the invariant doesn't give you an extra
72// ability to share a reference to a T across threads).
73//
74// In conclusion, we should have:
75//
76//    T                   AtomicInvariant<T>  LocalInvariant<T>
77//
78//    {}          ==>     {}                  {}
79//    Send        ==>     Send+Sync           Send
80//    Sync        ==>     {}                  {}
81//    Sync+Send   ==>     Send+Sync           Send
82/// An `AtomicInvariant` is a ghost object that provides "interior mutability"
83/// for ghost objects, specifically, for `tracked` ghost objects.
84/// A reference `&AtomicInvariant` may be shared between clients.
85/// A client holding such a reference may _open_ the invariant
86/// to obtain ghost ownership of `v1: V`, and then _close_ the invariant by returning
87/// ghost ownership of a (potentially) different object `v2: V`.
88///
89/// An `AtomicInvariant` implements [`Sync`](https://doc.rust-lang.org/std/sync/)
90/// and may be shared between threads.
91/// However, this means that an `AtomicInvariant` can be only opened for
92/// the duration of a single _sequentially consistent atomic_ operation.
93/// Such operations are provided by our [`PAtomic`](crate::atomic) library.
94/// For an invariant object without this atomicity restriction,
95/// see [`LocalInvariant`], which gives up thread safety in exchange.
96///
97/// An `AtomicInvariant` consists of:
98///
99///  * A _predicate_ specified via the `InvariantPredicate` type bound, that determines
100///    what values `V` may be saved inside the invariant.
101///  * A _constant_ `K`, specified at construction type. The predicate function takes
102///    this constant as a parameter, so the constant allows users to dynamically configure
103///    the predicate function in a way that can't be done at the type level.
104///  * A _namespace_. This is a bit of a technicality, and you can often just declare
105///    it as an arbitrary integer with no issues. See the [`open_local_invariant!`]
106///    documentation for more details.
107///
108/// The constant and namespace are specified at construction time ([`AtomicInvariant::new`]).
109/// These values are fixed for the lifetime of the `AtomicInvariant` object.
110/// To open the invariant and access the stored object `V`,
111/// use the macro [`open_atomic_invariant!`].
112///
113/// The `AtomicInvariant` API is an instance of the ["invariant" method in Verus's general philosophy on interior mutability](https://verus-lang.github.io/verus/guide/interior_mutability.html).
114///
115/// **Note:** Rather than using `AtomicInvariant` directly, we generally recommend
116/// using the [`atomic_ghost` APIs](crate::atomic_ghost).
117#[cfg_attr(verus_keep_ghost, verifier::proof)]
118#[cfg_attr(verus_keep_ghost, verifier::external_body)] /* vattr */
119#[cfg_attr(verus_keep_ghost, verifier::accept_recursive_types(K))]
120#[cfg_attr(verus_keep_ghost, verifier::accept_recursive_types(V))]
121#[cfg_attr(verus_keep_ghost, verifier::accept_recursive_types(Pred))]
122pub struct AtomicInvariant<K, V, Pred> {
123    dummy: super::prelude::SyncSendIfSend<V>,
124    dummy1: super::prelude::AlwaysSyncSend<(K, Pred, *mut V)>,
125}
126
127/// A `LocalInvariant` is a ghost object that provides "interior mutability"
128/// for ghost objects, specifically, for `tracked` ghost objects.
129/// A reference `&LocalInvariant` may be shared between clients.
130/// A client holding such a reference may _open_ the invariant
131/// to obtain ghost ownership of `v1: V`, and then _close_ the invariant by returning
132/// ghost ownership of a (potentially) different object `v2: V`.
133///
134/// A `LocalInvariant` cannot be shared between threads
135/// (that is, it does not implement [`Sync`](https://doc.rust-lang.org/std/sync/)).
136/// However, this means that a `LocalInvariant` can be opened for an indefinite length
137/// of time, since there is no risk of a race with another thread.
138/// For an invariant object with the opposite properties, see [`AtomicInvariant`].
139///
140/// A `LocalInvariant` consists of:
141///
142///  * A _predicate_ specified via the `InvariantPredicate` type bound, that determines
143///    what values `V` may be saved inside the invariant.
144///  * A _constant_ `K`, specified at construction type. The predicate function takes
145///    this constant as a parameter, so the constant allows users to dynamically configure
146///    the predicate function in a way that can't be done at the type level.
147///  * A _namespace_. This is a bit of a technicality, and you can often just declare
148///    it as an arbitrary integer with no issues. See the [`open_local_invariant!`]
149///    documentation for more details.
150///
151/// The constant and namespace are specified at construction time ([`LocalInvariant::new`]).
152/// These values are fixed for the lifetime of the `LocalInvariant` object.
153/// To open the invariant and access the stored object `V`,
154/// use the macro [`open_local_invariant!`].
155///
156/// The `LocalInvariant` API is an instance of the ["invariant" method in Verus's general philosophy on interior mutability](https://verus-lang.github.io/verus/guide/interior_mutability.html).
157
158#[cfg_attr(verus_keep_ghost, verifier::proof)]
159#[cfg_attr(verus_keep_ghost, verifier::external_body)] /* vattr */
160#[cfg_attr(verus_keep_ghost, verifier::accept_recursive_types(K))]
161#[cfg_attr(verus_keep_ghost, verifier::accept_recursive_types(V))]
162#[cfg_attr(verus_keep_ghost, verifier::accept_recursive_types(Pred))]
163pub struct LocalInvariant<K, V, Pred> {
164    dummy: super::prelude::SendIfSend<V>,
165    dummy1: super::prelude::AlwaysSyncSend<(K, Pred, *mut V)>,
166}
167
168// redundant, just makes the error msg a bit nicer
169#[cfg(verus_keep_ghost)]
170impl<K, V, Pred> !Sync for LocalInvariant<K, V, Pred> {}
171
172macro_rules! declare_invariant_impl {
173    ($invariant:ident) => {
174        // note the path names of `inv` and `namespace` are harcoded into the VIR crate.
175
176        verus!{
177
178        impl<K, V, Pred> $invariant<K, V, Pred> {
179            /// The constant specified upon the initialization of this `
180            #[doc = stringify!($invariant)]
181            ///`.
182            pub uninterp spec fn constant(&self) -> K;
183
184            /// Namespace the invariant was declared in.
185            #[rustc_diagnostic_item = concat!("verus::vstd::invariant::", stringify!($invariant), "::namespace")]
186            pub uninterp spec fn namespace(&self) -> int;
187        }
188
189        impl<K, V, Pred: InvariantPredicate<K, V>> $invariant<K, V, Pred> {
190            /// Returns `true` if it is possible to store the value `v` into the `
191            #[doc = stringify!($invariant)]
192            ///`.
193            ///
194            /// This is equivalent to `Pred::inv(self.constant(), v)`.
195
196            #[rustc_diagnostic_item = concat!("verus::vstd::invariant::", stringify!($invariant), "::inv")]
197            pub open spec fn inv(&self, v: V) -> bool {
198                Pred::inv(self.constant(), v)
199            }
200
201            /// Initialize a new `
202            #[doc = stringify!($invariant)]
203            ///` with constant `k`. initial stored (tracked) value `v`,
204            /// and in the namespace `ns`.
205
206            pub axiom fn new(k: K, tracked v: V, ns: int) -> (tracked i: $invariant<K, V, Pred>)
207                requires
208                    Pred::inv(k, v),
209                ensures
210                    i.constant() == k,
211                    i.namespace() == ns;
212
213            /// Destroys the `
214            #[doc = stringify!($invariant)]
215            ///`, returning the tracked value contained within.
216
217            pub axiom fn into_inner(#[verifier::proof] self) -> (tracked v: V)
218                ensures self.inv(v),
219                opens_invariants [ self.namespace() ];
220        }
221
222        }
223    };
224}
225
226declare_invariant_impl!(AtomicInvariant);
227declare_invariant_impl!(LocalInvariant);
228
229#[doc(hidden)]
230#[cfg_attr(verus_keep_ghost, verifier::proof)]
231pub struct InvariantBlockGuard;
232
233// In the "Logical Paradoxes" section of the Iris 4.1 Reference
234// (`https://plv.mpi-sws.org/iris/appendix-4.1.pdf`), they show that
235// opening invariants carries the risk of unsoundness.
236//
237// The paradox is similar to "Landin's knot", a short program that implements
238// an infinite loop by combining two features: higher-order closures
239// and mutable state:
240//
241//    let r := new_ref();
242//    r := () -> {
243//        let f = !r;
244//        f();
245//    };
246//    let f = !r;
247//    f();
248//
249// Invariants effectively serve as "mutable state"
250// Therefore, in order to implement certain higher-order features
251// like "proof closures" or "dyn", we need to make sure we have an
252// answer to this paradox.
253//
254// One solution to
255// this, described in the paper "Later Credits: Resourceful Reasoning
256// for the Later Modality" by Spies et al. (available at
257// `https://plv.mpi-sws.org/later-credits/paper-later-credits.pdf`) is
258// to use "later credits". That is, require the expenditure of a later
259// credit, only obtainable in exec mode, when opening an invariant. So
260// we require the relinquishment of a tracked
261// `OpenInvariantCredit` to open an invariant, and we provide an
262// exec-mode function `create_open_invariant_credit` to obtain one.
263
264verus! {
265
266#[doc(hidden)]
267#[cfg_attr(verus_keep_ghost, verifier::proof)]
268#[verifier::external_body]
269pub struct OpenInvariantCredit {}
270
271// It's intentional that `create_open_invariant_credit` uses `exec` mode. This prevents
272// creation of an infinite number of credits to open invariants infinitely often.
273#[cfg_attr(verus_keep_ghost, rustc_diagnostic_item = "verus::vstd::invariant::create_open_invariant_credit")]
274#[verifier::external_body]
275#[inline(always)]
276pub fn create_open_invariant_credit() -> Tracked<OpenInvariantCredit>
277    opens_invariants none
278    no_unwind
279{
280    Tracked::<OpenInvariantCredit>::assume_new()
281}
282
283#[cfg(verus_keep_ghost)]
284#[rustc_diagnostic_item = "verus::vstd::invariant::spend_open_invariant_credit_in_proof"]
285#[doc(hidden)]
286#[inline(always)]
287pub proof fn spend_open_invariant_credit_in_proof(tracked credit: OpenInvariantCredit) {
288}
289
290#[cfg_attr(verus_keep_ghost, rustc_diagnostic_item = "verus::vstd::invariant::spend_open_invariant_credit")]
291#[doc(hidden)]
292#[inline(always)]
293pub fn spend_open_invariant_credit(
294    #[allow(unused_variables)]
295    credit: Tracked<OpenInvariantCredit>,
296)
297    opens_invariants none
298    no_unwind
299{
300    proof {
301        spend_open_invariant_credit_in_proof(credit.get());
302    }
303}
304
305} // verus!
306// NOTE: These 3 methods are removed in the conversion to VIR; they are only used
307// for encoding and borrow-checking.
308// In the VIR these are all replaced by the OpenInvariant block.
309// This means that the bodies, preconditions, and even their modes are not important.
310//
311// An example usage of the macro is like
312//
313//   i: AtomicInvariant<X>
314//
315//   open_invariant!(&i => inner => {
316//      { modify `inner` here }
317//   });
318//
319//  where `inner` will have type `X`.
320#[cfg(verus_keep_ghost)]
321#[rustc_diagnostic_item = "verus::vstd::invariant::open_atomic_invariant_begin"]
322#[doc(hidden)]
323#[verifier::external] /* vattr */
324pub fn open_atomic_invariant_begin<'a, K, V, Pred: InvariantPredicate<K, V>>(
325    _inv: &'a AtomicInvariant<K, V, Pred>,
326) -> (InvariantBlockGuard, V) {
327    unimplemented!();
328}
329
330#[cfg(verus_keep_ghost)]
331#[rustc_diagnostic_item = "verus::vstd::invariant::open_local_invariant_begin"]
332#[doc(hidden)]
333#[verifier::external] /* vattr */
334pub fn open_local_invariant_begin<'a, K, V, Pred: InvariantPredicate<K, V>>(
335    _inv: &'a LocalInvariant<K, V, Pred>,
336) -> (InvariantBlockGuard, V) {
337    unimplemented!();
338}
339
340#[cfg(verus_keep_ghost)]
341#[rustc_diagnostic_item = "verus::vstd::invariant::open_invariant_end"]
342#[doc(hidden)]
343#[verifier::external] /* vattr */
344pub fn open_invariant_end<V>(_guard: InvariantBlockGuard, _v: V) {
345    unimplemented!();
346}
347
348/// Macro used to temporarily "open" an [`AtomicInvariant`] object, obtaining the stored
349/// value within.
350///
351/// ### Usage
352///
353/// The form of the macro looks like,
354///
355/// ```rust
356/// open_atomic_invariant($inv => $id => {
357///     // Inner scope
358/// });
359/// ```
360///
361/// This operation is very similar to [`open_local_invariant!`], so we refer to its
362/// documentation for the basics. There is only one difference, besides
363/// the fact that `$inv` should be an [`&AtomicInvariant`](AtomicInvariant)
364/// rather than a [`&LocalInvariant`](LocalInvariant).
365/// The difference is that `open_atomic_invariant!` has an additional _atomicity constraint_:
366///
367///  * **Atomicity constraint**: The code body of an `open_atomic_invariant!` block
368///    cannot contain any `exec`-mode code with the exception of a _single_ atomic operation.
369///
370/// (Of course, the code block can still contain an arbitrary amount of ghost code.)
371///
372/// The atomicity constraint is needed because an `AtomicInvariant` must be thread-safe;
373/// that is, it can be shared across threads. In order for the ghost state to be shared
374/// safely, it must be restored after each atomic operation.
375///
376/// The atomic operations may be found in the [`PAtomic`](crate::atomic) library.
377/// The user can also mark their own functions as "atomic operations" using
378/// `#[verifier::atomic)]`; however, this is not useful for very much other than defining
379/// wrappers around the existing atomic operations from [`PAtomic`](crate::atomic).
380/// Note that reading and writing through a [`PCell`](crate::cell::PCell)
381/// or a [`PPtr`](crate::simple_pptr::PPtr) are _not_ atomic operations.
382///
383/// **Note:** Rather than using `open_atomic_invariant!` directly, we generally recommend
384/// using the [`atomic_ghost` APIs](crate::atomic_ghost).
385///
386/// It's not legal to use `open_atomic_invariant!` in proof mode. In proof mode, you need
387/// to use `open_atomic_invariant_in_proof!` instead. This takes one extra parameter,
388/// an open-invariant credit, which you can get by calling
389/// `create_open_invariant_credit()` before you enter proof mode.
390
391/// ### Example
392///
393/// TODO fill this in
394
395// TODO the `$eexpr` argument here should be macro'ed in ghost context, not exec
396
397#[macro_export]
398macro_rules! open_atomic_invariant {
399    [$($tail:tt)*] => {
400        #[allow(unexpected_cfgs)] // make sure client crates don't see "unexpected `cfg` condition name: `verus_...`"
401        {
402            $crate::vstd::prelude::verus_exec_inv_macro_exprs!(
403                $crate::vstd::invariant::open_atomic_invariant_internal!($crate::vstd::invariant::create_open_invariant_credit() => $($tail)*)
404            )
405        }
406    };
407}
408
409#[macro_export]
410macro_rules! open_atomic_invariant_in_proof {
411    [$($tail:tt)*] => {
412        $crate::vstd::prelude::verus_ghost_inv_macro_exprs!($crate::vstd::invariant::open_atomic_invariant_in_proof_internal!($($tail)*))
413    };
414}
415
416#[macro_export]
417macro_rules! open_atomic_invariant_internal {
418    ($credit_expr:expr => $eexpr:expr => $iident:ident => $bblock:block) => {
419        #[cfg_attr(verus_keep_ghost, verifier::invariant_block)] /* vattr */ {
420            #[cfg(verus_keep_ghost_body)]
421            $crate::vstd::invariant::spend_open_invariant_credit($credit_expr);
422            #[cfg(verus_keep_ghost_body)]
423            #[allow(unused_mut)] let (guard, mut $iident) =
424                $crate::vstd::invariant::open_atomic_invariant_begin($eexpr);
425            $bblock
426            #[cfg(verus_keep_ghost_body)]
427            $crate::vstd::invariant::open_invariant_end(guard, $iident);
428        }
429    }
430}
431
432#[macro_export]
433macro_rules! open_atomic_invariant_in_proof_internal {
434    ($credit_expr:expr => $eexpr:expr => $iident:ident => $bblock:block) => {
435        #[cfg_attr(verus_keep_ghost, verifier::invariant_block)] /* vattr */ {
436            #[cfg(verus_keep_ghost_body)]
437            $crate::vstd::invariant::spend_open_invariant_credit_in_proof($credit_expr);
438            #[cfg(verus_keep_ghost_body)]
439            #[allow(unused_mut)] let (guard, mut $iident) =
440                $crate::vstd::invariant::open_atomic_invariant_begin($eexpr);
441            $bblock
442            #[cfg(verus_keep_ghost_body)]
443            $crate::vstd::invariant::open_invariant_end(guard, $iident);
444        }
445    }
446}
447
448pub use open_atomic_invariant;
449pub use open_atomic_invariant_in_proof;
450#[doc(hidden)]
451pub use open_atomic_invariant_in_proof_internal;
452#[doc(hidden)]
453pub use open_atomic_invariant_internal;
454
455/// Macro used to temporarily "open" a [`LocalInvariant`] object, obtaining the stored
456/// value within.
457///
458/// ### Usage
459///
460/// The form of the macro looks like,
461///
462/// ```rust
463/// open_local_invariant($inv => $id => {
464///     // Inner scope
465/// });
466/// ```
467///
468/// The operation of opening an invariant is a ghost one; however, the inner code block
469/// may contain arbitrary `exec`-mode code. The invariant remains "open" for the duration
470/// of the inner code block, and it is closed again of the end of the block.
471///
472/// The `$inv` parameter should be an expression of type `&LocalInvariant<K, V, Pred>`,
473/// the invariant object to be opened. The `$id` is an identifier which is bound within
474/// the code block as a `mut` variable of type `V`. This gives the user ownership over
475/// the `V` value, which they may manipulate freely within the code block. At the end
476/// of the code block, the variable `$id` is consumed.
477///
478/// The obtained object `v: V`, will satisfy the `LocalInvariant`'s invariant predicate
479/// [`$inv.inv(v)`](LocalInvariant::inv). Furthermore, the user must prove that this
480/// invariant still holds at the end. In other words, the macro usage is
481/// roughly equivalent to the following:
482///
483/// ```rust
484/// {
485///     let $id: V = /* an arbitrary value */;
486///     assume($inv.inv($id));
487///     /* user code block here */
488///     assert($inv.inv($id));
489///     consume($id);
490/// }
491/// ```
492///
493/// ### Avoiding Reentrancy
494///
495/// Verus adds additional checks to ensure that an invariant is never opened
496/// more than once at the same time. For example, suppose that you attempt to nest
497/// the use of `open_invariant`, supplying the same argument `inv` to each:
498///
499/// ```rust
500/// open_local_invariant(inv => id1 => {
501///     open_local_invariant(inv => id2 => {
502///     });
503/// });
504/// ```
505///
506/// In this situation, Verus would produce an error:
507///
508/// ```
509/// error: possible invariant collision
510///   |
511///   |   open_local_invariant!(&inv => id1 => {
512///   |                           ^ this invariant
513///   |       open_local_invariant!(&inv => id2 => {
514///   |                               ^ might be the same as this invariant
515///   ...
516///   |       }
517///   |   }
518/// ```
519///
520/// When generating these conditions, Verus compares invariants via their
521/// [`namespace()`](LocalInvariant::namespace) values.
522/// An invariant's namespace (represented simply as an integer)
523/// is specified upon the call to [`LocalInvariant::new`].
524/// If you have the need to open multiple invariants at once, make sure to given
525/// them different namespaces.
526///
527/// So that Verus can ensure that there are no nested invariant accesses across function
528/// boundaries, every `proof` and `exec` function has, as part of its specification,
529/// the set of invariant namespaces that it might open.
530///
531/// The invariant set of a function can be specified via the [`opens_invariants` clause](https://verus-lang.github.io/verus/guide/reference-opens-invariants.html).
532/// The default for an `exec`-mode function is to open any, while the default
533/// for a `proof`-mode function is to open none.
534///
535/// It's not legal to use `open_local_invariant!` in proof mode. In proof mode, you need
536/// to use `open_local_invariant_in_proof!` instead. This takes one extra parameter,
537/// an open-invariant credit, which you can get by calling
538/// `create_open_invariant_credit()` before you enter proof mode.
539///
540/// ### Example
541///
542/// TODO fill this in
543///
544/// ### More Examples
545///
546/// TODO fill this in
547
548#[macro_export]
549macro_rules! open_local_invariant {
550    [$($tail:tt)*] => {
551        #[allow(unexpected_cfgs)] // make sure client crates don't see "unexpected `cfg` condition name: `verus_...`"
552        {
553            #[cfg(verus_keep_ghost_body)]
554            let credit = $crate::vstd::invariant::create_open_invariant_credit();
555            $crate::vstd::prelude::verus_exec_inv_macro_exprs!(
556                $crate::vstd::invariant::open_local_invariant_internal!(credit => $($tail)*))
557        }
558    };
559}
560
561#[macro_export]
562macro_rules! open_local_invariant_in_proof {
563    [$($tail:tt)*] => {
564        $crate::vstd::prelude::verus_ghost_inv_macro_exprs!($crate::vstd::invariant::open_local_invariant_in_proof_internal!($($tail)*))
565    };
566}
567
568#[macro_export]
569macro_rules! open_local_invariant_internal {
570    ($credit_expr:expr => $eexpr:expr => $iident:ident => $bblock:block) => {
571        #[cfg_attr(verus_keep_ghost, verifier::invariant_block)] /* vattr */ {
572            #[cfg(verus_keep_ghost_body)]
573            $crate::vstd::invariant::spend_open_invariant_credit($credit_expr);
574            #[cfg(verus_keep_ghost_body)]
575            #[allow(unused_mut)] let (guard, mut $iident) = $crate::vstd::invariant::open_local_invariant_begin($eexpr);
576            $bblock
577            #[cfg(verus_keep_ghost_body)]
578            $crate::vstd::invariant::open_invariant_end(guard, $iident);
579        }
580    }
581}
582
583#[macro_export]
584macro_rules! open_local_invariant_in_proof_internal {
585    ($credit_expr:expr => $eexpr:expr => $iident:ident => $bblock:block) => {
586        #[cfg_attr(verus_keep_ghost, verifier::invariant_block)] /* vattr */ {
587            #[cfg(verus_keep_ghost_body)]
588            $crate::vstd::invariant::spend_open_invariant_credit_in_proof($credit_expr);
589            #[cfg(verus_keep_ghost_body)]
590            #[allow(unused_mut)] let (guard, mut $iident) = $crate::vstd::invariant::open_local_invariant_begin($eexpr);
591            $bblock
592            #[cfg(verus_keep_ghost_body)]
593            $crate::vstd::invariant::open_invariant_end(guard, $iident);
594        }
595    }
596}
597
598pub use open_local_invariant;
599pub use open_local_invariant_in_proof;
600#[doc(hidden)]
601pub use open_local_invariant_in_proof_internal;
602#[doc(hidden)]
603pub use open_local_invariant_internal;