Skip to content

Commit

Permalink
Remove rayon dependency of cranelift-isle (#5101)
Browse files Browse the repository at this point in the history
Using rayon adds a lot of dependencies to Cranelift. The total
unparallelized time the code that uses rayon takes is less than half a
second and it runs at compile time, so there is pretty much no benefit
to parallelizing it.
  • Loading branch information
bjorn3 authored Oct 23, 2022
1 parent 442f9fa commit 470070a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 19 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion cranelift/isle/isle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ version = "0.90.0"
[dependencies]
log = { workspace = true, optional = true }
miette = { version = "5.1.0", optional = true }
rayon = "^1.5"

[dev-dependencies]
tempfile = "3"
Expand Down
19 changes: 2 additions & 17 deletions cranelift/isle/isle/src/overlap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Overlap detection for rules in ISLE.
use rayon::prelude::*;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};

Expand Down Expand Up @@ -30,17 +29,6 @@ struct Errors {
}

impl Errors {
/// Merge together two Error graphs.
fn union(mut self, other: Self) -> Self {
for (id, edges) in other.nodes {
match self.nodes.entry(id) {
Entry::Occupied(entry) => entry.into_mut().extend(edges),
Entry::Vacant(entry) => _ = entry.insert(edges),
}
}
self
}

/// Condense the overlap information down into individual errors. We iteratively remove the
/// nodes from the graph with the highest degree, reporting errors for them and their direct
/// connections. The goal with reporting errors this way is to prefer reporting rules that
Expand Down Expand Up @@ -145,19 +133,16 @@ fn check_overlaps(env: &TermEnv) -> Errors {
}
}

// Process rule pairs in parallel. Rayon makes this easy and we have independent bite-sized
// chunks of work, so we might as well take advantage of multiple CPUs if they're available.
pairs
.into_par_iter()
.fold(Errors::default, |mut errs, (left, right)| {
.into_iter()
.fold(Errors::default(), |mut errs, (left, right)| {
if left.rule.prio == right.rule.prio {
if check_overlap_pair(&left.pats, &right.pats) {
errs.add_edge(left.rule.id, right.rule.id);
}
}
errs
})
.reduce(Errors::default, Errors::union)
}

/// Check if two rules overlap in the inputs they accept.
Expand Down

0 comments on commit 470070a

Please sign in to comment.