1
Fork 0

Removed stable/unstable sort arg from into_sorted_stable_ord, fixed a few misc issues, added collect to UnordItems

This commit is contained in:
Andrew Xie 2023-06-08 00:38:50 -04:00
parent f5f638c124
commit 54d7b327e5
13 changed files with 81 additions and 48 deletions

View file

@ -119,7 +119,7 @@ impl<'tcx> AssertModuleSource<'tcx> {
if !self.available_cgus.contains(&cgu_name) {
let cgu_names: Vec<&str> =
self.available_cgus.items().map(|cgu| cgu.as_str()).into_sorted_stable_ord(true);
self.available_cgus.items().map(|cgu| cgu.as_str()).into_sorted_stable_ord();
self.tcx.sess.emit_err(errors::NoModuleNamed {
span: attr.span,
user_path,

View file

@ -198,7 +198,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
let (name, mut auto) = self.auto_labels(item_id, attr);
let except = self.except(attr);
let loaded_from_disk = self.loaded_from_disk(attr);
for e in except.items().map(|x| x.as_str()).into_sorted_stable_ord(false) {
for e in except.items().map(|x| x.as_str()).into_sorted_stable_ord() {
if !auto.remove(e) {
self.tcx.sess.emit_fatal(errors::AssertionAuto { span: attr.span, name, e });
}
@ -377,16 +377,16 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
continue;
};
self.checked_attrs.insert(attr.id);
for label in assertion.clean.items().map(|x| x.as_str()).into_sorted_stable_ord(false) {
for label in assertion.clean.items().map(|x| x.as_str()).into_sorted_stable_ord() {
let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap();
self.assert_clean(item_span, dep_node);
}
for label in assertion.dirty.items().map(|x| x.as_str()).into_sorted_stable_ord(false) {
for label in assertion.dirty.items().map(|x| x.as_str()).into_sorted_stable_ord() {
let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap();
self.assert_dirty(item_span, dep_node);
}
for label in
assertion.loaded_from_disk.items().map(|x| x.as_str()).into_sorted_stable_ord(false)
assertion.loaded_from_disk.items().map(|x| x.as_str()).into_sorted_stable_ord()
{
let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap();
self.assert_loaded_from_disk(item_span, dep_node);

View file

@ -676,11 +676,8 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
// Delete all lock files, that don't have an associated directory. They must
// be some kind of leftover
let lock_file_to_session_dir_iter = lock_file_to_session_dir
.items()
.map(|(file, dir)| (file.as_str(), dir.as_ref().map(|y| y.as_str())));
for (lock_file_name, directory_name) in
lock_file_to_session_dir_iter.into_sorted_stable_ord(false)
lock_file_to_session_dir.items().into_sorted_stable_ord()
{
if directory_name.is_none() {
let Ok(timestamp) = extract_timestamp_from_session_dir(lock_file_name) else {
@ -712,10 +709,10 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
}
// Filter out `None` directories
let lock_file_to_session_dir: UnordMap<String, String> =
UnordMap::from(lock_file_to_session_dir.into_items().filter_map(
|(lock_file_name, directory_name)| directory_name.map(|n| (lock_file_name, n)),
));
let lock_file_to_session_dir: UnordMap<String, String> = lock_file_to_session_dir
.into_items()
.filter_map(|(lock_file_name, directory_name)| directory_name.map(|n| (lock_file_name, n)))
.into();
// Delete all session directories that don't have a lock file.
for directory_name in session_directories {
@ -821,7 +818,7 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
}
None
});
let deletion_candidates = UnordMap::from(deletion_candidates);
let deletion_candidates = deletion_candidates.into();
// Delete all but the most recent of the candidates
all_except_most_recent(deletion_candidates).into_items().all(|(path, lock)| {

View file

@ -2,23 +2,16 @@ use super::*;
#[test]
fn test_all_except_most_recent() {
let computed: UnordMap<_, Option<flock::Lock>> = UnordMap::from_iter([
let input: UnordMap<_, Option<flock::Lock>> = UnordMap::from_iter([
((UNIX_EPOCH + Duration::new(4, 0), PathBuf::from("4")), None),
((UNIX_EPOCH + Duration::new(1, 0), PathBuf::from("1")), None),
((UNIX_EPOCH + Duration::new(5, 0), PathBuf::from("5")), None),
((UNIX_EPOCH + Duration::new(3, 0), PathBuf::from("3")), None),
((UNIX_EPOCH + Duration::new(2, 0), PathBuf::from("2")), None),
]);
let mut paths = UnordSet::default();
paths.extend_unord(all_except_most_recent(computed).into_items().map(|(path, _)| path));
assert_eq!(
UnordSet::from(paths),
UnordSet::from_iter([
PathBuf::from("1"),
PathBuf::from("2"),
PathBuf::from("3"),
PathBuf::from("4")
])
all_except_most_recent(input).into_items().map(|(path, _)| path).into_sorted_stable_ord(),
vec![PathBuf::from("1"), PathBuf::from("2"), PathBuf::from("3"), PathBuf::from("4")]
);
assert!(all_except_most_recent(UnordMap::default()).is_empty());

View file

@ -46,12 +46,7 @@ pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
/// Removes files for a given work product.
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {
for path in work_product
.saved_files
.items()
.map(|(_, path)| path.as_str())
.into_sorted_stable_ord(false)
{
for (_, path) in work_product.saved_files.items().into_sorted_stable_ord() {
let path = in_incr_comp_dir_sess(sess, path);
if let Err(err) = std_fs::remove_file(&path) {
sess.emit_warning(errors::DeleteWorkProduct { path: &path, err });