1 //! Shims for ControlPlane when chaos mode is disabled. Enables
2 //! unconditional use of the type and its methods throughout cranelift.
3 
4 /// A shim for ControlPlane when chaos mode is disabled.
5 /// Please see the [crate-level documentation](crate).
6 #[derive(Debug, Clone, Default)]
7 pub struct ControlPlane {
8     /// prevent direct instantiation (use `default` instead)
9     _private: (),
10 }
11 
12 /// A shim for ControlPlane's `Arbitrary` implementation when chaos mode is
13 /// disabled. It doesn't consume any bytes and always returns a default
14 /// control plane.
15 #[cfg(feature = "fuzz")]
16 impl arbitrary::Arbitrary<'_> for ControlPlane {
arbitrary(_u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self>17     fn arbitrary(_u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
18         Ok(Self::default())
19     }
20 }
21 
22 impl ControlPlane {
23     /// Set the [fuel limit](crate#fuel-limit). This variant is used when
24     /// chaos mode is disabled. It doesn't do anything.
set_fuel(&mut self, _fuel: u8)25     pub fn set_fuel(&mut self, _fuel: u8) {}
26 
27     /// Returns a pseudo-random boolean. This variant is used when chaos
28     /// mode is disabled. It always returns `false`.
29     #[inline]
get_decision(&mut self) -> bool30     pub fn get_decision(&mut self) -> bool {
31         false
32     }
33 
34     /// Returns an arbitrary value. This variant is used when chaos mode is
35     /// disabled. It always returns the default value.
36     #[inline]
get_arbitrary<T: Default>(&mut self) -> T37     pub fn get_arbitrary<T: Default>(&mut self) -> T {
38         T::default()
39     }
40 
41     /// Shuffles the items in the slice into a pseudo-random permutation.
42     /// This variant is used when chaos mode is disabled. It doesn't do
43     /// anything.
44     #[inline]
shuffle<T>(&mut self, _slice: &mut [T])45     pub fn shuffle<T>(&mut self, _slice: &mut [T]) {}
46 
47     /// Returns a new iterator over the same items as the input iterator in
48     /// a pseudo-random order. This variant is used when chaos mode is
49     /// disabled. It always returns the same order.
50     #[inline]
shuffled<T>(&mut self, iter: impl Iterator<Item = T>) -> impl Iterator<Item = T>51     pub fn shuffled<T>(&mut self, iter: impl Iterator<Item = T>) -> impl Iterator<Item = T> {
52         iter
53     }
54 }
55