Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
centralize conditional compilation of chaos mode
Also cleanup a few straggling dependencies on cranelift-control
that aren't needed anymore.

Co-authored-by: Falk Zwimpfer <[email protected]>
Co-authored-by: Moritz Waser <[email protected]>
  • Loading branch information
3 people committed Apr 4, 2023
commit 9e907a40d3f8ecd1696294413cbd168f783d4335
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions cranelift/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ isle-errors = ["cranelift-isle/fancy-errors"]
# inspection, rather than inside of target/.
isle-in-source-tree = []

chaos = ["cranelift-control/chaos"]

[badges]
maintenance = { status = "experimental" }

Expand Down
5 changes: 2 additions & 3 deletions cranelift/codegen/src/machinst/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,8 @@ impl<I: VCodeInst> MachBuffer<I> {
// fixup record referring to that last branch is removed.
}

fn optimize_branches(&mut self, _ctrl_plane: &mut ControlPlane) {
#[cfg(feature = "chaos")]
if _ctrl_plane.get_decision() {
fn optimize_branches(&mut self, ctrl_plane: &mut ControlPlane) {
if ctrl_plane.get_decision() {
return;
}

Expand Down
8 changes: 4 additions & 4 deletions cranelift/control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
//! [arbitrary]: ControlPlane#method.arbitrary
//! [default]: ControlPlane#method.default

#[cfg(not(any(feature = "chaos", doc)))]
#[cfg(not(feature = "chaos"))]
mod zero_sized;
#[cfg(not(any(feature = "chaos", doc)))]
#[cfg(not(feature = "chaos"))]
pub use zero_sized::*;

#[cfg(any(feature = "chaos", doc))]
#[cfg(feature = "chaos")]
mod chaos;
#[cfg(any(feature = "chaos", doc))]
#[cfg(feature = "chaos")]
pub use chaos::*;
23 changes: 23 additions & 0 deletions cranelift/control/src/zero_sized.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
//! Shims for ControlPlane when chaos mode is disabled. Enables
//! unconditional use of the type and its methods throughout cranelift.

/// A shim for ControlPlane when chaos mode is disabled.
/// Please see the [crate-level documentation](crate).
#[derive(Debug, Clone, Default)]
pub struct ControlPlane {
/// prevent direct instantiation (use `default` instead)
_private: (),
}

/// A shim for ControlPlane's `Arbitrary` implementation when chaos mode is
/// disabled. It doesn't consume any bytes and always returns a default
/// control plane.
impl arbitrary::Arbitrary<'_> for ControlPlane {
fn arbitrary<'a>(_u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(Self::default())
}
}

impl ControlPlane {
/// Returns a pseudo-random boolean. This variant is used when chaos
/// mode is disabled. It always returns `false`.
#[inline]
pub fn get_decision(&mut self) -> bool {
false
}
}
4 changes: 0 additions & 4 deletions cranelift/fuzzgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ publish = false
[dependencies]
cranelift = { workspace = true }
cranelift-native = { workspace = true }
cranelift-control = { workspace = true }

anyhow = { workspace = true }
arbitrary = "1.0.0"
once_cell = { workspace = true }
target-lexicon = { workspace = true, features = ["std"] }

[features]
chaos = ["cranelift-control/chaos"]
1 change: 0 additions & 1 deletion cranelift/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ edition.workspace = true

[dependencies]
cranelift-codegen = { workspace = true }
cranelift-control = { workspace = true }
target-lexicon = { workspace = true }

[target.'cfg(any(target_arch = "s390x", target_arch = "riscv64"))'.dependencies]
Expand Down
1 change: 0 additions & 1 deletion cranelift/reader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ edition.workspace = true
[dependencies]
anyhow.workspace = true
cranelift-codegen = { workspace = true }
cranelift-control = { workspace = true }
smallvec = { workspace = true }
target-lexicon = { workspace = true }

Expand Down
6 changes: 1 addition & 5 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ component-fuzz-util = { workspace = true }
[features]
default = ['fuzz-spec-interpreter']
fuzz-spec-interpreter = ['wasmtime-fuzzing/fuzz-spec-interpreter']
chaos = [
"cranelift-codegen/chaos",
"cranelift-control/chaos",
"cranelift-fuzzgen/chaos",
]
chaos = ["cranelift-control/chaos"]

[[bin]]
name = "compile"
Expand Down
3 changes: 0 additions & 3 deletions fuzz/fuzz_targets/cranelift-fuzzgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,6 @@ impl TestCase {
)?;
functions.push(func);

#[cfg(not(feature = "chaos"))]
ctrl_planes.push(ControlPlane::default());
#[cfg(feature = "chaos")]
ctrl_planes.push(ControlPlane::arbitrary(gen.u)?);
}
// Now reverse the functions so that the main function is at the start.
Expand Down