Skip to content

Commit f1f5091

Browse files
committed
Refactoring of collection folding. In the simple case, we can use map/collect so we should. The par_iter lint should be able to parallelize these.
1 parent 1cb81a8 commit f1f5091

22 files changed

+444
-570
lines changed

Cargo.lock

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "mate"
33
version = "0.1.0"
4-
authors = ["Cameron Low <email>", "Luca Carlig <luca.carlig@huawei.com"]
4+
authors = ["Cameron Low <cameron.low.2018@bristol.ac.uk>", "Luca Carlig <luca.carlig@huawei.com"]
55
description = "library of lints for automatic parallelization"
66
edition = "2021"
77
publish = false
@@ -13,12 +13,12 @@ crate-type = ["cdylib"]
1313
[dependencies]
1414
for_each = { path = "lints/for_each", features = ["rlib"] }
1515
filter = { path = "lints/filter", features = ["rlib"] }
16+
map = { path = "lints/map", features = ["rlib"] }
1617
fold = { path = "lints/fold", features = ["rlib"] }
1718
par_fold = { path = "lints/par_fold", features = ["rlib"] }
1819
par_iter = { path = "lints/par_iter", features = ["rlib"] }
1920
rayon_imports = { path = "lints/rayon_imports", features = ["rlib"] }
2021

21-
2222
dylint_linting = { version = "2.6.1" }
2323

2424
[package.metadata.rust-analyzer]
@@ -28,6 +28,7 @@ rustc_private = true
2828
members = [
2929
"lints/for_each",
3030
"lints/filter",
31+
"lints/map",
3132
"lints/fold",
3233
"lints/par_fold",
3334
"lints/par_iter",

lints/fold/src/hashmap.rs

-110
This file was deleted.

lints/fold/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(rustc_private)]
22
#![warn(unused_extern_crates)]
33
#![feature(let_chains)]
4+
#![feature(iter_intersperse)]
45

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

14-
mod hashmap;
1515
mod simple;
16-
mod vec;
1716

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

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

2724
#[test]

lints/fold/src/vec.rs

-111
This file was deleted.

lints/fold/ui/main.fixed

-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// run-rustfix
22
fn main() {
33
warn_fold_simple();
4-
warn_fold_vec();
5-
warn_fold_hashmap();
64
get_upload_file_total_size();
75
}
86

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

18-
fn warn_fold_vec() {
19-
let mut data = vec![];
20-
let numbers = vec![1, 2, 3, 4, 5];
21-
data = numbers.iter().fold(data, |mut data, &num| { data.push(num * 3); data });
22-
23-
println!("Data: {:?}", data);
24-
}
25-
26-
fn warn_fold_hashmap() {
27-
use std::collections::HashMap;
28-
29-
let mut data = HashMap::new();
30-
let numbers = vec![1, 2, 3, 4, 5];
31-
data = numbers.iter().fold(data, |mut data, &num| { data.insert(num, num.to_string()); data });
32-
33-
println!("Data: {:?}", data);
34-
}
35-
3616
fn get_upload_file_total_size() -> u64 {
3717
let some_num = vec![0; 10];
3818
let mut file_total_size = 0;

lints/fold/ui/main.rs

-24
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// run-rustfix
22
fn main() {
33
warn_fold_simple();
4-
warn_fold_vec();
5-
warn_fold_hashmap();
64
get_upload_file_total_size();
75
}
86

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

20-
fn warn_fold_vec() {
21-
let mut data = vec![];
22-
let numbers = vec![1, 2, 3, 4, 5];
23-
numbers.iter().for_each(|&num| {
24-
data.push(num * 3);
25-
});
26-
27-
println!("Data: {:?}", data);
28-
}
29-
30-
fn warn_fold_hashmap() {
31-
use std::collections::HashMap;
32-
33-
let mut data = HashMap::new();
34-
let numbers = vec![1, 2, 3, 4, 5];
35-
numbers.iter().for_each(|&num| {
36-
data.insert(num, num.to_string());
37-
});
38-
39-
println!("Data: {:?}", data);
40-
}
41-
4218
fn get_upload_file_total_size() -> u64 {
4319
let some_num = vec![0; 10];
4420
let mut file_total_size = 0;

0 commit comments

Comments
 (0)