Skip to content

Commit

Permalink
Refactoring of collection folding. In the simple case, we can use map…
Browse files Browse the repository at this point in the history
…/collect so we should. The par_iter lint should be able to parallelize these.
  • Loading branch information
Cameron-Low committed Mar 12, 2024
1 parent 1cb81a8 commit f1f5091
Show file tree
Hide file tree
Showing 22 changed files with 444 additions and 570 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mate"
version = "0.1.0"
authors = ["Cameron Low <email>", "Luca Carlig <[email protected]"]
authors = ["Cameron Low <[email protected]>", "Luca Carlig <[email protected]"]
description = "library of lints for automatic parallelization"
edition = "2021"
publish = false
Expand All @@ -13,12 +13,12 @@ crate-type = ["cdylib"]
[dependencies]
for_each = { path = "lints/for_each", features = ["rlib"] }
filter = { path = "lints/filter", features = ["rlib"] }
map = { path = "lints/map", features = ["rlib"] }
fold = { path = "lints/fold", features = ["rlib"] }
par_fold = { path = "lints/par_fold", features = ["rlib"] }
par_iter = { path = "lints/par_iter", features = ["rlib"] }
rayon_imports = { path = "lints/rayon_imports", features = ["rlib"] }


dylint_linting = { version = "2.6.1" }

[package.metadata.rust-analyzer]
Expand All @@ -28,6 +28,7 @@ rustc_private = true
members = [
"lints/for_each",
"lints/filter",
"lints/map",
"lints/fold",
"lints/par_fold",
"lints/par_iter",
Expand Down
110 changes: 0 additions & 110 deletions lints/fold/src/hashmap.rs

This file was deleted.

5 changes: 1 addition & 4 deletions lints/fold/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(rustc_private)]
#![warn(unused_extern_crates)]
#![feature(let_chains)]
#![feature(iter_intersperse)]

#[cfg(not(feature = "rlib"))]
dylint_linting::dylint_library!();
Expand All @@ -11,17 +12,13 @@ extern crate rustc_lint;
extern crate rustc_session;
extern crate rustc_span;

mod hashmap;
mod simple;
mod vec;

#[allow(clippy::no_mangle_with_rust_abi)]
#[cfg_attr(not(feature = "rlib"), no_mangle)]

pub fn register_lints(_sess: &rustc_session::Session, lint_store: &mut rustc_lint::LintStore) {
lint_store.register_late_pass(|_| Box::new(simple::FoldSimple));
lint_store.register_late_pass(|_| Box::new(vec::FoldVec));
lint_store.register_late_pass(|_| Box::new(hashmap::FoldHashmap));
}

#[test]
Expand Down
111 changes: 0 additions & 111 deletions lints/fold/src/vec.rs

This file was deleted.

20 changes: 0 additions & 20 deletions lints/fold/ui/main.fixed
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// run-rustfix
fn main() {
warn_fold_simple();
warn_fold_vec();
warn_fold_hashmap();
get_upload_file_total_size();
}

Expand All @@ -15,24 +13,6 @@ fn warn_fold_simple() {
println!("Sum: {}", sum);
}

fn warn_fold_vec() {
let mut data = vec![];
let numbers = vec![1, 2, 3, 4, 5];
data = numbers.iter().fold(data, |mut data, &num| { data.push(num * 3); data });

println!("Data: {:?}", data);
}

fn warn_fold_hashmap() {
use std::collections::HashMap;

let mut data = HashMap::new();
let numbers = vec![1, 2, 3, 4, 5];
data = numbers.iter().fold(data, |mut data, &num| { data.insert(num, num.to_string()); data });

println!("Data: {:?}", data);
}

fn get_upload_file_total_size() -> u64 {
let some_num = vec![0; 10];
let mut file_total_size = 0;
Expand Down
24 changes: 0 additions & 24 deletions lints/fold/ui/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// run-rustfix
fn main() {
warn_fold_simple();
warn_fold_vec();
warn_fold_hashmap();
get_upload_file_total_size();
}

Expand All @@ -17,28 +15,6 @@ fn warn_fold_simple() {
println!("Sum: {}", sum);
}

fn warn_fold_vec() {
let mut data = vec![];
let numbers = vec![1, 2, 3, 4, 5];
numbers.iter().for_each(|&num| {
data.push(num * 3);
});

println!("Data: {:?}", data);
}

fn warn_fold_hashmap() {
use std::collections::HashMap;

let mut data = HashMap::new();
let numbers = vec![1, 2, 3, 4, 5];
numbers.iter().for_each(|&num| {
data.insert(num, num.to_string());
});

println!("Data: {:?}", data);
}

fn get_upload_file_total_size() -> u64 {
let some_num = vec![0; 10];
let mut file_total_size = 0;
Expand Down
Loading

0 comments on commit f1f5091

Please sign in to comment.