creusot-std 0.12.0

Standard library of Creusot: provides specification macros, contracts for Rust standard library and logic helpers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
//! Resource invariants.
//!
//! Resource invariants allow the use of a shared piece of data to be used in
//! the invariant (see [`Protocol`]), but in return they impose a much more
//! restricted access to the underlying data, as well as the use of [`Tokens`].
//!
//! [Atomic invariants](AtomicInvariant) are used to specify concurrent
//! operations.
//!
//! [Non-atomic invariants](NonAtomicInvariant) are used to specify thread-local
//! operations.
//!
//! Not to be confused with [loop invariants][crate::macros::invariant] or
//! [type invariants][crate::invariant::Invariant].
//!
//! # Example
//!
//! Building a simplified `Cell`, that only asserts its content's type invariant.
//! ```
//! # use creusot_std::{
//! #     cell::PermCell,
//! #     ghost::{
//! #         invariant::{NonAtomicInvariant, Protocol, Tokens, declare_namespace},
//! #         perm::Perm,
//! #     },
//! #     logic::Id,
//! #     prelude::*,
//! # };
//! declare_namespace! { PERMCELL }
//!
//! /// A cell that simply asserts its content's type invariant.
//! pub struct CellInv<T: Invariant> {
//!     data: PermCell<T>,
//!     permission: Ghost<NonAtomicInvariant<PermCellNAInv<T>>>,
//! }
//! impl<T: Invariant> Invariant for CellInv<T> {
//!     #[logic]
//!     fn invariant(self) -> bool {
//!         self.permission.namespace() == PERMCELL() && self.permission.public() == self.data.id()
//!     }
//! }
//!
//! struct PermCellNAInv<T>(Perm<PermCell<T>>);
//! impl<T: Invariant> Protocol for PermCellNAInv<T> {
//!     type Public = Id;
//!
//!     #[logic]
//!     fn public(self) -> Id { self.0.id() }
//!
//!     #[logic]
//!     fn protocol(self) -> bool { true }
//! }
//!
//! impl<T: Invariant> CellInv<T> {
//!     #[requires(tokens.contains(PERMCELL()))]
//!     pub fn write(&self, x: T, tokens: Ghost<Tokens>) {
//!         NonAtomicInvariant::open(self.permission.borrow(), tokens, move |perm| unsafe {
//!             *self.data.borrow_mut(ghost!(&mut perm.into_inner().0)) = x
//!         })
//!     }
//! }
//! ```
//!
//! # Explicit tokens
//!
//! For now, [`Tokens`] must be explicitely passed to [`open`](NonAtomicInvariant::open).
//! We plan to relax this limitation at some point.

#![allow(unused_variables)]

use crate::{
    ghost::{FnGhost, Plain},
    logic::Set,
    prelude::*,
};
use core::marker::PhantomData;

#[cfg(creusot)]
use crate::ghost::Objective;

/// Declare a new namespace.
///
/// # Example
///
/// ```rust
/// use creusot_std::{ghost::invariant::{declare_namespace, Namespace}, logic::Set, prelude::*};
/// declare_namespace! { A }
///
/// #[requires(ns.contains(A()))]
/// fn foo(ns: Ghost<&mut Set<Namespace>>) { /* ... */ }
/// ```
pub use base_macros::declare_namespace;

/// The type of _namespaces_ of associated with non-atomic invariants.
///
/// Can be declared with the [`declare_namespace`] macro, and then attached to a non-atomic
/// invariant when creating it with [`NonAtomicInvariant::new`].
#[intrinsic("namespace")]
pub struct Namespace(());

impl Clone for Namespace {
    #[check(ghost)]
    #[ensures(result == *self)]
    fn clone(&self) -> Self {
        *self
    }
}
impl Copy for Namespace {}

impl Plain for Namespace {
    #[trusted]
    #[ensures(*result == *snap)]
    #[check(ghost)]
    #[allow(unused_variables)]
    fn into_ghost(snap: Snapshot<Self>) -> Ghost<Self> {
        Ghost::conjure()
    }
}

/// Invariant tokens.
///
/// This is given at the start of the program, and must be passed along to
/// [NonAtomicInvariant::open] to prevent opening invariant reentrantly.
///
/// # Tokens and `open`
///
/// Tokens are used to avoid reentrency in [`open`](NonAtomicInvariant::open).
/// To ensure this, `Tokens` acts as a special kind of mutable borrow : only
/// one may exist at a given point in the program, preventing multiple calls to
/// `open` with the same namespace. This is the reason this type has a lifetime
/// attached to it.
///
/// Note that after the execution of `open`, the token that was used is
/// restored. Because of this, we never need to talk about the 'final' value
/// of this borrow, because it never differs from the current value (in places
/// where we can use it).
///
/// To help passing it into functions, it may be [reborrowed](Self::reborrow),
/// similarly to a normal borrow.
#[opaque]
// `*mut ()` so that Tokens are neither Send nor Sync
pub struct Tokens<'a>(PhantomData<&'a ()>, PhantomData<*mut ()>);

impl<'a> Tokens<'a> {
    /// Get the underlying set of namespaces of this token.
    ///
    /// Also accessible via the [`view`](View::view) (`@`) operator.
    #[logic(opaque)]
    pub fn namespaces(self) -> Set<Namespace> {
        dead
    }

    /// Get the tokens for all the namespaces.
    ///
    /// This is only callable _once_, in `main`.
    #[trusted]
    #[ensures(forall<ns: Namespace> result.contains(ns))]
    #[intrinsic("tokens_new")]
    #[check(ghost)]
    pub fn new() -> Ghost<Self> {
        Ghost::conjure()
    }

    /// Reborrow the token, allowing it to be reused later.
    ///
    /// # Example
    /// ```
    /// # use creusot_std::{ghost::invariant::Tokens, prelude::*};
    /// fn foo(tokens: Ghost<Tokens>) {}
    /// fn bar(tokens: Ghost<Tokens>) {}
    /// fn baz(mut tokens: Ghost<Tokens>) {
    ///     foo(ghost!(tokens.reborrow()));
    ///     bar(tokens);
    /// }
    /// ```
    #[trusted]
    #[ensures(result == *self && ^self == *self)]
    #[check(ghost)]
    pub fn reborrow<'b>(&'b mut self) -> Tokens<'b> {
        Tokens(PhantomData, PhantomData)
    }

    /// Split the tokens in two, so that it can be used to access independent invariants.
    ///
    /// # Example
    ///
    /// ```
    /// # use creusot_std::{ghost::invariant::{declare_namespace, Tokens}, prelude::*};
    /// declare_namespace! { FOO }
    /// declare_namespace! { BAR }
    ///
    /// // the lifetime 'locks' the namespace
    /// #[requires(tokens.contains(FOO()))]
    /// fn foo<'a>(tokens: Ghost<Tokens<'a>>) -> &'a i32 {
    /// # todo!()
    ///     // access some invariant to get the reference
    /// }
    /// #[requires(tokens.contains(BAR()))]
    /// fn bar(tokens: Ghost<Tokens>) {}
    ///
    /// #[requires(tokens.contains(FOO()) && tokens.contains(BAR()))]
    /// fn baz(tokens: Ghost<Tokens>) -> i32 {
    ///      let (ns_foo, ns_bar) = ghost!(tokens.into_inner().split(snapshot!(FOO()))).split();
    ///      let x = foo(ns_foo);
    ///      bar(ns_bar);
    ///      *x
    /// }
    /// ```
    #[trusted]
    #[requires(self.contains(*ns))]
    #[ensures(result.0.contains(*ns))]
    #[ensures(result.1.namespaces() == self.namespaces().remove(*ns))]
    #[check(ghost)]
    pub fn split(self, ns: Snapshot<Namespace>) -> (Tokens<'a>, Tokens<'a>) {
        (Tokens(PhantomData, PhantomData), Tokens(PhantomData, PhantomData))
    }

    #[logic(open)]
    pub fn contains(self, namespace: Namespace) -> bool {
        self.namespaces().contains(namespace)
    }
}

impl View for Tokens<'_> {
    type ViewTy = Set<Namespace>;
    #[logic(open, inline)]
    fn view(self) -> Set<Namespace> {
        self.namespaces()
    }
}

/// A variant of [`Invariant`] for use in [`AtomicInvariantSC`]s,
/// [`AtomicInvariant`]s and [`NonAtomicInvariant`]s.
///
/// This allows specifying an invariant that depends on some public
/// data ([`AtomicInvariantSC::public`], [`AtomicInvariant::public`],
/// [`NonAtomicInvariant::public`]).
pub trait Protocol {
    type Public;

    /// The public data of the invariant, derived from the inner content.
    ///
    /// It is called public, because it is visible simply by holding the
    /// invariant, without needing to open it.
    ///
    /// Because of this, calls to `open` must not modify this value.
    #[logic]
    fn public(self) -> Self::Public;

    /// The protocol for the invariant.
    ///
    /// When opening the invariant ([`AtomicInvariantSC::open`],
    /// [`AtomicInvariant::open`], [`NonAtomicInvariant::open`]), the data in
    /// guaranteed to respect this protocol; then, you must ensure that it is
    /// still verified when the invariant is closed.
    #[logic(prophetic)]
    fn protocol(self) -> bool;
}

/// A shareable invariant for sequentially consistent accesses between threads.
///
/// If you need non-sequentially consistent accesses, use [`AtomicInvariant`].
///
/// If you do not need to share the invariant across threads, see
/// [`NonAtomicInvariant`].
#[opaque]
pub struct AtomicInvariantSC<T>(PhantomData<*mut T>);

#[trusted]
unsafe impl<T: Send> Sync for AtomicInvariantSC<T> {}
#[trusted]
unsafe impl<T: Send> Send for AtomicInvariantSC<T> {}

impl<T: Protocol> AtomicInvariantSC<T> {
    /// Construct a `AtomicInvariantSC`, aka a sequentially consistent atomic invariant.
    ///
    /// # Parameters
    ///
    /// - `value`: the actual data contained in the invariant. Use [`Self::open`] to
    /// access it. Also called the 'private' part of the invariant.
    /// - `namespace`: the namespace of the invariant.
    ///   This is required to avoid [open](Self::open)ing the same invariant twice.
    #[trusted]
    #[requires(value.protocol())]
    #[ensures(result.public() == value.public())]
    #[ensures(result.namespace() == *namespace)]
    #[check(ghost)]
    pub fn new(value: Ghost<T>, namespace: Snapshot<Namespace>) -> Ghost<Self> {
        Ghost::conjure()
    }

    /// Get the namespace associated with this invariant.
    #[logic(opaque)]
    pub fn namespace(self) -> Namespace {
        dead
    }

    /// Get the 'public' part of this invariant.
    #[logic(opaque)]
    pub fn public(self) -> T::Public {
        dead
    }

    /// Gives the actual invariant held by the `AtomicInvariantSC`.
    #[trusted]
    #[ensures(result.public() == self.public() && result.protocol())]
    #[check(ghost)]
    pub fn into_inner(self) -> T {
        panic!("Should not be called outside ghost code")
    }

    /// Open the invariant to get the data stored inside.
    ///
    /// This will call the closure `f` with the inner data. You must restore the
    /// contained [`Protocol`] before returning from the closure.
    ///
    /// NOTE: This function can only be called from ghost code, because atomic
    /// invariants are always wrapped in `Ghost`. This guarantees atomicity.
    #[trusted]
    #[requires(tokens.contains(self.namespace()))]
    #[requires(forall<t: &mut T> t.public() == self.public() && t.protocol() && inv(t) ==>
        f.precondition((t,)) &&
        // f must restore the invariant
        (forall<res: A> f.postcondition_once((t,), res) ==> (^t).public() == self.public() && (^t).protocol()))]
    #[ensures(exists<t: &mut T> t.public() == self.public() && t.protocol() && inv(t) &&
        f.postcondition_once((t,), result))]
    #[check(ghost)]
    pub fn open<A>(&self, tokens: Tokens, f: impl FnGhost + for<'a> FnOnce(&'a mut T) -> A) -> A {
        panic!("Should not be called outside ghost code")
    }
}

/// A shareable invariant for atomic accesses between threads.
///
/// If you need _sequentially consistent_ accesses, use [`AtomicInvariant`].
///
/// If you do not need to share the invariant across threads, see
/// [`NonAtomicInvariant`].
#[opaque]
pub struct AtomicInvariant<T>(PhantomData<*mut T>);

// TODO: Find a real hack to achieve this.
#[cfg(creusot)]
#[trusted]
unsafe impl<T: Send + Objective> Sync for AtomicInvariant<T> {}
#[cfg(not(creusot))]
unsafe impl<T: Send> Sync for AtomicInvariant<T> {}

#[trusted]
unsafe impl<T: Send> Send for AtomicInvariant<T> {}

impl<T: Protocol> AtomicInvariant<T> {
    /// Construct a `AtomicInvariant`
    ///
    /// # Parameters
    /// - `value`: the actual data contained in the invariant. Use [`Self::open`] to
    /// access it. Also called the 'private' part of the invariant.
    /// - `namespace`: the namespace of the invariant.
    ///   This is required to avoid [open](Self::open)ing the same invariant twice.
    #[trusted]
    #[requires(value.protocol())]
    #[ensures(result.public() == value.public())]
    #[ensures(result.namespace() == *namespace)]
    #[check(ghost)]
    pub fn new(value: Ghost<T>, namespace: Snapshot<Namespace>) -> Ghost<Self> {
        Ghost::conjure()
    }

    /// Get the namespace associated with this invariant.
    #[logic(opaque)]
    pub fn namespace(self) -> Namespace {
        dead
    }

    /// Get the 'public' part of this invariant.
    #[logic(opaque)]
    pub fn public(self) -> T::Public {
        dead
    }

    /// Gives the actual invariant held by the `AtomicInvariant`.
    #[trusted]
    #[ensures(result.public() == self.public() && result.protocol())]
    #[check(ghost)]
    pub fn into_inner(self) -> T {
        panic!("Should not be called outside ghost code")
    }

    /// Open the invariant to get the data stored inside.
    ///
    /// This will call the closure `f` with the inner data. You must restore the
    /// contained [`Protocol`] before returning from the closure.
    ///
    /// NOTE: This function can only be called from ghost code, because atomic
    /// invariants are always wrapped in `Ghost`. This guarantees atomicity.
    #[trusted]
    #[requires(tokens.contains(self.namespace()))]
    #[requires(forall<t: &mut T> t.public() == self.public() && t.protocol() && inv(t) ==>
        f.precondition((t,)) &&
        // f must restore the invariant
        (forall<res: A> f.postcondition_once((t,), res) ==> (^t).public() == self.public() && (^t).protocol()))]
    #[ensures(exists<t: &mut T> t.public() == self.public() && t.protocol() && inv(t) &&
        f.postcondition_once((t,), result))]
    #[check(ghost)]
    pub fn open<A>(&self, tokens: Tokens, f: impl FnGhost + for<'a> FnOnce(&'a mut T) -> A) -> A {
        panic!("Should not be called outside ghost code")
    }
}

/// A ghost structure, that holds a piece of data (`T`) together with an
/// [protocol](Protocol).
///
/// # Note
///
/// `NonAtomicInvariant` is not [`Sync`], and is invariant in the underlying data.
/// - It is not `Sync` precisely because it is non-atomic, so access to the data is unsynchronized.
/// - It is invariant because it gives access to a mutable borrow of this data.
///
/// If you need to share an invariant across threads, consider
/// [`AtomicInvariantSC`] or [`AtomicInvariant`].
#[opaque]
pub struct NonAtomicInvariant<T: Protocol>(PhantomData<*mut T>);

#[trusted]
unsafe impl<T: Protocol> Send for NonAtomicInvariant<T> {}

/// Define method call syntax for [`NonAtomicInvariant::open`].
pub trait NonAtomicInvariantExt<'a> {
    type Inner: 'a;

    /// Alias for [`NonAtomicInvariant::open`], to use method call syntax (`inv.open(...)`).
    #[requires(false)]
    fn open<A, F>(self, tokens: Ghost<Tokens<'a>>, f: F) -> A
    where
        F: FnOnce(Ghost<&'a mut Self::Inner>) -> A;
}

impl<'a, T: Protocol> NonAtomicInvariantExt<'a> for Ghost<&'a NonAtomicInvariant<T>> {
    type Inner = T;

    #[requires(tokens.contains(self.namespace()))]
    #[requires(forall<t: Ghost<&mut T>> t.public() == self.public() && t.protocol() && inv(t) ==>
        f.precondition((t,)) &&
        // f must restore the invariant
        (forall<res: A> f.postcondition_once((t,), res) ==> (^t).public() == self.public() && (^t).protocol()))]
    #[ensures(exists<t: Ghost<&mut T>> t.public() == self.public() && t.protocol() && inv(t) && f.postcondition_once((t,), result))]
    fn open<A, F>(self, tokens: Ghost<Tokens<'a>>, f: F) -> A
    where
        F: FnOnce(Ghost<&'a mut Self::Inner>) -> A,
    {
        NonAtomicInvariant::open(self, tokens, f)
    }
}

impl<'a, T> NonAtomicInvariantExt<'a> for Ghost<&'a T>
where
    T: core::ops::Deref,
    Ghost<&'a T::Target>: NonAtomicInvariantExt<'a>,
{
    type Inner = <Ghost<&'a T::Target> as NonAtomicInvariantExt<'a>>::Inner;

    #[requires(T::deref.precondition((*self,)))]
    #[requires(forall<this> T::deref.postcondition((*self,), this) ==>
        <Ghost<&'a T::Target> as NonAtomicInvariantExt<'a>>::open.precondition((Ghost::new_logic(this), tokens, f))
    )]
    #[ensures(exists<this> T::deref.postcondition((*self,), this) &&
        <Ghost<&'a T::Target> as NonAtomicInvariantExt<'a>>::open.postcondition((Ghost::new_logic(this), tokens, f), result)
    )]
    fn open<A, F>(self, tokens: Ghost<Tokens<'a>>, f: F) -> A
    where
        F: FnOnce(Ghost<&'a mut Self::Inner>) -> A,
    {
        let this: Ghost<&T::Target> = ghost!(&self);
        this.open(tokens, f)
    }
}

impl<'a, L> NonAtomicInvariantExt<'a> for &'a Ghost<L>
where
    Ghost<&'a L>: NonAtomicInvariantExt<'a>,
{
    type Inner = <Ghost<&'a L> as NonAtomicInvariantExt<'a>>::Inner;

    #[requires(<Ghost<&'a L> as NonAtomicInvariantExt<'a>>::open.precondition((Ghost::new_logic(&**self), tokens, f)))]
    #[ensures(<Ghost<&'a L> as NonAtomicInvariantExt<'a>>::open.postcondition((Ghost::new_logic(&**self), tokens, f), result))]
    fn open<A, F>(self, tokens: Ghost<Tokens<'a>>, f: F) -> A
    where
        F: FnOnce(Ghost<&'a mut Self::Inner>) -> A,
    {
        self.borrow().open(tokens, f)
    }
}

impl<T: Protocol> NonAtomicInvariant<T> {
    /// Construct a `NonAtomicInvariant`
    ///
    /// # Parameters
    ///
    /// - `value`: the actual data contained in the invariant. Use [`Self::open`] to
    /// access it. Also called the 'private' part of the invariant.
    /// - `namespace`: the namespace of the invariant.
    ///   This is required to avoid [open](Self::open)ing the same invariant twice.
    #[trusted]
    #[requires(value.protocol())]
    #[ensures(result.public() == value.public())]
    #[ensures(result.namespace() == *namespace)]
    #[check(ghost)]
    pub fn new(value: Ghost<T>, namespace: Snapshot<Namespace>) -> Ghost<Self> {
        Ghost::conjure()
    }

    /// Gives the actual invariant held by the `NonAtomicInvariant`.
    #[trusted]
    #[ensures(result.public() == self.public() && result.protocol())]
    #[check(ghost)]
    pub fn into_inner(self) -> T {
        panic!("Should not be called outside ghost code")
    }

    /// Get the namespace associated with this invariant.
    #[logic(opaque)]
    pub fn namespace(self) -> Namespace {
        dead
    }

    /// Get the 'public' part of this invariant.
    #[logic(opaque)]
    pub fn public(self) -> T::Public {
        dead
    }

    /// Open the invariant to get the data stored inside.
    ///
    /// This will call the closure `f` with the inner data. You must restore the
    /// contained [`Protocol`] before returning from the closure.
    #[trusted]
    #[requires(tokens.contains(this.namespace()))]
    #[requires(forall<t: Ghost<&mut T>> t.public() == this.public() && t.protocol() && inv(t) ==>
        f.precondition((t,)) &&
        // f must restore the invariant
        (forall<res: A> f.postcondition_once((t,), res) ==> (^t).public() == this.public() && (^t).protocol()))]
    #[ensures(exists<t: Ghost<&mut T>> t.public() == this.public() && t.protocol() && inv(t) &&
        f.postcondition_once((t,), result))]
    pub fn open<'a, A>(
        this: Ghost<&'a Self>,
        tokens: Ghost<Tokens<'a>>,
        f: impl FnOnce(Ghost<&'a mut T>) -> A,
    ) -> A {
        f(Ghost::conjure())
    }

    /// Open the invariant to get the data stored inside, immutably.
    /// This allows reentrant access to the invariant.
    #[trusted]
    #[requires(tokens.contains(self.namespace()))]
    #[ensures(result.public() == self.public() && result.protocol())]
    #[check(ghost)]
    pub fn open_const<'a>(&'a self, tokens: &'a Tokens) -> &'a T {
        panic!("Should not be called outside ghost code")
    }

    /// Open the invariant to get the data stored inside.
    ///
    /// See [`Self::open`].
    ///
    /// This requires a mutable borrow on the invariant, but in exchange, you
    /// are allowed to change the public part of the invariant.
    #[trusted]
    #[check(ghost)]
    #[requires(forall<t: Ghost<&mut T>> t.protocol() && t.public() == this.public() && inv(t) ==>
        f.precondition((t,)) &&
        (forall<res: A> f.postcondition_once((t,), res) ==> (^t).protocol()))]
    #[ensures(exists<t: Ghost<&mut T>> t.protocol() && t.public() == this.public() && inv(t) &&
        f.postcondition_once((t,), result) && (^this).public() == (^t).public())]
    #[ensures(this.namespace() == (^this).namespace())]
    pub fn open_mut<'a, A>(this: Ghost<&'a mut Self>, f: impl FnOnce(Ghost<&'a mut T>) -> A) -> A {
        unreachable!("ghost code only")
    }
}