From 470070ab7197ef39b47bad4f307fd20b04b24f14 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Mon, 24 Oct 2022 00:13:14 +0200 Subject: [PATCH] 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. --- Cargo.lock | 1 - cranelift/isle/isle/Cargo.toml | 1 - cranelift/isle/isle/src/overlap.rs | 19 ++----------------- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5aab66c852..6ac9187cd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -647,7 +647,6 @@ version = "0.90.0" dependencies = [ "log", "miette", - "rayon", "tempfile", ] diff --git a/cranelift/isle/isle/Cargo.toml b/cranelift/isle/isle/Cargo.toml index 4e31567d87..9689717a5b 100644 --- a/cranelift/isle/isle/Cargo.toml +++ b/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" diff --git a/cranelift/isle/isle/src/overlap.rs b/cranelift/isle/isle/src/overlap.rs index 9703edd089..ecee903913 100644 --- a/cranelift/isle/isle/src/overlap.rs +++ b/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.