Browse Source

Remove rayon dependency of cranelift-isle (#5101)

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.
pull/5103/head
bjorn3 2 years ago
committed by GitHub
parent
commit
470070ab71
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Cargo.lock
  2. 1
      cranelift/isle/isle/Cargo.toml
  3. 19
      cranelift/isle/isle/src/overlap.rs

1
Cargo.lock

@ -647,7 +647,6 @@ version = "0.90.0"
dependencies = [
"log",
"miette",
"rayon",
"tempfile",
]

1
cranelift/isle/isle/Cargo.toml

@ -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"

19
cranelift/isle/isle/src/overlap.rs

@ -1,6 +1,5 @@
//! Overlap detection for rules in ISLE.
use rayon::prelude::*;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
@ -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
@ -145,11 +133,9 @@ 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);
@ -157,7 +143,6 @@ fn check_overlaps(env: &TermEnv) -> Errors {
}
errs
})
.reduce(Errors::default, Errors::union)
}
/// Check if two rules overlap in the inputs they accept.

Loading…
Cancel
Save