Skip to content

Commit

Permalink
Collect features only once
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Jun 23, 2019
1 parent ebbc662 commit 6c5c78d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 37 deletions.
61 changes: 33 additions & 28 deletions src/tools/tidy/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,36 @@ pub struct Feature {

pub type Features = HashMap<String, Feature>;

pub fn check(path: &Path, bad: &mut bool, verbose: bool) {
pub struct CollectedFeatures {
pub lib: Features,
pub lang: Features,
}

// Currently only used for unstable book generation
pub fn collect_lib_features(base_src_path: &Path) -> Features {
let mut lib_features = Features::new();

// This library feature is defined in the `compiler_builtins` crate, which
// has been moved out-of-tree. Now it can no longer be auto-discovered by
// `tidy`, because we need to filter out its (submodule) directory. Manually
// add it to the set of known library features so we can still generate docs.
lib_features.insert("compiler_builtins_lib".to_owned(), Feature {
level: Status::Unstable,
since: None,
has_gate_test: false,
tracking_issue: None,
});

map_lib_features(base_src_path,
&mut |res, _, _| {
if let Ok((name, feature)) = res {
lib_features.insert(name.to_owned(), feature);
}
});
lib_features
}

pub fn check(path: &Path, bad: &mut bool, verbose: bool) -> CollectedFeatures {
let mut features = collect_lang_features(path, bad);
assert!(!features.is_empty());

Expand Down Expand Up @@ -125,7 +154,7 @@ pub fn check(path: &Path, bad: &mut bool, verbose: bool) {
}

if *bad {
return;
return CollectedFeatures { lib: lib_features, lang: features };
}

if verbose {
Expand All @@ -140,6 +169,8 @@ pub fn check(path: &Path, bad: &mut bool, verbose: bool) {
} else {
println!("* {} features", features.len());
}

CollectedFeatures { lib: lib_features, lang: features }
}

fn format_features<'a>(features: &'a Features, family: &'a str) -> impl Iterator<Item = String> + 'a {
Expand Down Expand Up @@ -303,32 +334,6 @@ pub fn collect_lang_features(base_src_path: &Path, bad: &mut bool) -> Features {
.collect()
}

pub fn collect_lib_features(base_src_path: &Path) -> Features {
let mut lib_features = Features::new();

// This library feature is defined in the `compiler_builtins` crate, which
// has been moved out-of-tree. Now it can no longer be auto-discovered by
// `tidy`, because we need to filter out its (submodule) directory. Manually
// add it to the set of known library features so we can still generate docs.
lib_features.insert("compiler_builtins_lib".to_owned(), Feature {
level: Status::Unstable,
since: None,
has_gate_test: false,
tracking_issue: None,
});

map_lib_features(base_src_path,
&mut |res, _, _| {
if let Ok((name, feature)) = res {
if lib_features.contains_key(name) {
return;
}
lib_features.insert(name.to_owned(), feature);
}
});
lib_features
}

fn get_and_check_lib_features(base_src_path: &Path,
bad: &mut bool,
lang_features: &Features) -> Features {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ fn main() {
style::check(&path, &mut bad);
errors::check(&path, &mut bad);
cargo::check(&path, &mut bad);
features::check(&path, &mut bad, verbose);
let collected = features::check(&path, &mut bad, verbose);
pal::check(&path, &mut bad);
unstable_book::check(&path, &mut bad);
unstable_book::check(&path, collected, &mut bad);
libcoretest::check(&path, &mut bad);
if !args.iter().any(|s| *s == "--no-vendor") {
deps::check(&path, &mut bad);
Expand Down
23 changes: 16 additions & 7 deletions src/tools/tidy/src/unstable_book.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeSet;
use std::fs;
use std::path::{PathBuf, Path};
use crate::features::{collect_lang_features, collect_lib_features, Features, Status};
use crate::features::{CollectedFeatures, Features, Feature, Status};

pub const PATH_STR: &str = "doc/unstable-book";

Expand Down Expand Up @@ -73,13 +73,22 @@ fn collect_unstable_book_lib_features_section_file_names(base_src_path: &Path) -
collect_unstable_book_section_file_names(&unstable_book_lib_features_path(base_src_path))
}

pub fn check(path: &Path, bad: &mut bool) {
// Library features

let lang_features = collect_lang_features(path, bad);
let lib_features = collect_lib_features(path).into_iter().filter(|&(ref name, _)| {
pub fn check(path: &Path, features: CollectedFeatures, bad: &mut bool) {
let lang_features = features.lang;
let mut lib_features = features.lib.into_iter().filter(|&(ref name, _)| {
!lang_features.contains_key(name)
}).collect();
}).collect::<Features>();

// This library feature is defined in the `compiler_builtins` crate, which
// has been moved out-of-tree. Now it can no longer be auto-discovered by
// `tidy`, because we need to filter out its (submodule) directory. Manually
// add it to the set of known library features so we can still generate docs.
lib_features.insert("compiler_builtins_lib".to_owned(), Feature {
level: Status::Unstable,
since: None,
has_gate_test: false,
tracking_issue: None,
});

// Library features
let unstable_lib_feature_names = collect_unstable_feature_names(&lib_features);
Expand Down

0 comments on commit 6c5c78d

Please sign in to comment.