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 impl arbitrary::Arbitrary<'_> for ControlPlane { 16 fn arbitrary(_u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> { 17 Ok(Self::default()) 18 } 19 } 20 21 impl ControlPlane { 22 /// Set the [fuel limit](crate#fuel-limit). This variant is used when 23 /// chaos mode is disabled. It doesn't do anything. 24 pub fn set_fuel(&mut self, _fuel: u8) {} 25 26 /// Returns a pseudo-random boolean. This variant is used when chaos 27 /// mode is disabled. It always returns `false`. 28 #[inline] 29 pub fn get_decision(&mut self) -> bool { 30 false 31 } 32 33 /// Returns an arbitrary value. This variant is used when chaos mode is 34 /// disabled. It always returns the default value. 35 #[inline] 36 pub fn get_arbitrary<T: for<'a> arbitrary::Arbitrary<'a> + Default>(&mut self) -> T { 37 T::default() 38 } 39 40 /// Shuffles the items in the slice into a pseudo-random permutation. 41 /// This variant is used when chaos mode is disabled. It doesn't do 42 /// anything. 43 #[inline] 44 pub fn shuffle<T>(&mut self, _slice: &mut [T]) {} 45 46 /// Returns a new iterator over the same items as the input iterator in 47 /// a pseudo-random order. This variant is used when chaos mode is 48 /// disabled. It always returns the same order. 49 #[inline] 50 pub fn shuffled<T>(&mut self, iter: impl Iterator<Item = T>) -> impl Iterator<Item = T> { 51 iter 52 } 53 } 54