Fixed to_sorted => to_sorted_stable_ord

This commit is contained in:
Andrew Xie 2023-06-05 00:16:20 -04:00
parent 6f2d3dee17
commit f5f638c124
6 changed files with 60 additions and 37 deletions

View File

@ -339,6 +339,8 @@ fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
} }
} }
unsafe impl<T1: StableOrd, T2: StableOrd> StableOrd for (T1, T2) {}
impl<T1, T2, T3, CTX> HashStable<CTX> for (T1, T2, T3) impl<T1, T2, T3, CTX> HashStable<CTX> for (T1, T2, T3)
where where
T1: HashStable<CTX>, T1: HashStable<CTX>,
@ -353,6 +355,8 @@ fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
} }
} }
unsafe impl<T1: StableOrd, T2: StableOrd, T3: StableOrd> StableOrd for (T1, T2, T3) {}
impl<T1, T2, T3, T4, CTX> HashStable<CTX> for (T1, T2, T3, T4) impl<T1, T2, T3, T4, CTX> HashStable<CTX> for (T1, T2, T3, T4)
where where
T1: HashStable<CTX>, T1: HashStable<CTX>,
@ -369,6 +373,11 @@ fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
} }
} }
unsafe impl<T1: StableOrd, T2: StableOrd, T3: StableOrd, T4: StableOrd> StableOrd
for (T1, T2, T3, T4)
{
}
impl<T: HashStable<CTX>, CTX> HashStable<CTX> for [T] { impl<T: HashStable<CTX>, CTX> HashStable<CTX> for [T] {
default fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { default fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
self.len().hash_stable(ctx, hasher); self.len().hash_stable(ctx, hasher);
@ -459,6 +468,8 @@ fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
} }
} }
unsafe impl StableOrd for &str {}
impl<CTX> HashStable<CTX> for String { impl<CTX> HashStable<CTX> for String {
#[inline] #[inline]
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {

View File

@ -118,8 +118,8 @@ fn check_attr(&self, attr: &ast::Attribute) {
debug!("mapping '{}' to cgu name '{}'", self.field(attr, sym::module), cgu_name); debug!("mapping '{}' to cgu name '{}'", self.field(attr, sym::module), cgu_name);
if !self.available_cgus.contains(&cgu_name) { if !self.available_cgus.contains(&cgu_name) {
let cgu_names: Vec<String> = let cgu_names: Vec<&str> =
self.available_cgus.items().map(|cgu| cgu.as_str().to_owned()).into_sorted(&()); self.available_cgus.items().map(|cgu| cgu.as_str()).into_sorted_stable_ord(true);
self.tcx.sess.emit_err(errors::NoModuleNamed { self.tcx.sess.emit_err(errors::NoModuleNamed {
span: attr.span, span: attr.span,
user_path, user_path,

View File

@ -198,7 +198,7 @@ fn assertion_auto(&mut self, item_id: LocalDefId, attr: &Attribute) -> Assertion
let (name, mut auto) = self.auto_labels(item_id, attr); let (name, mut auto) = self.auto_labels(item_id, attr);
let except = self.except(attr); let except = self.except(attr);
let loaded_from_disk = self.loaded_from_disk(attr); let loaded_from_disk = self.loaded_from_disk(attr);
for e in except.to_sorted(&(), false) { for e in except.items().map(|x| x.as_str()).into_sorted_stable_ord(false) {
if !auto.remove(e) { if !auto.remove(e) {
self.tcx.sess.emit_fatal(errors::AssertionAuto { span: attr.span, name, e }); self.tcx.sess.emit_fatal(errors::AssertionAuto { span: attr.span, name, e });
} }
@ -377,18 +377,20 @@ fn check_item(&mut self, item_id: LocalDefId) {
continue; continue;
}; };
self.checked_attrs.insert(attr.id); self.checked_attrs.insert(attr.id);
assertion.clean.to_sorted(&(), false).iter().for_each(|label| { for label in assertion.clean.items().map(|x| x.as_str()).into_sorted_stable_ord(false) {
let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap(); let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap();
self.assert_clean(item_span, dep_node); self.assert_clean(item_span, dep_node);
}); }
assertion.dirty.to_sorted(&(), false).iter().for_each(|label| { for label in assertion.dirty.items().map(|x| x.as_str()).into_sorted_stable_ord(false) {
let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap(); let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap();
self.assert_dirty(item_span, dep_node); self.assert_dirty(item_span, dep_node);
}); }
assertion.loaded_from_disk.to_sorted(&(), false).iter().for_each(|label| { for label in
assertion.loaded_from_disk.items().map(|x| x.as_str()).into_sorted_stable_ord(false)
{
let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap(); let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap();
self.assert_loaded_from_disk(item_span, dep_node); self.assert_loaded_from_disk(item_span, dep_node);
}); }
} }
} }
} }

View File

@ -661,8 +661,9 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
session_directories.sort(); session_directories.sort();
// Now map from lock files to session directories // Now map from lock files to session directories
let lock_file_to_session_dir: UnordMap<String, Option<String>> = let lock_file_to_session_dir: UnordMap<String, Option<String>> = lock_files
UnordMap::from(lock_files.into_items().map(|lock_file_name| { .into_items()
.map(|lock_file_name| {
assert!(lock_file_name.ends_with(LOCK_FILE_EXT)); assert!(lock_file_name.ends_with(LOCK_FILE_EXT));
let dir_prefix_end = lock_file_name.len() - LOCK_FILE_EXT.len(); let dir_prefix_end = lock_file_name.len() - LOCK_FILE_EXT.len();
let session_dir = { let session_dir = {
@ -670,41 +671,45 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
session_directories.iter().find(|dir_name| dir_name.starts_with(dir_prefix)) session_directories.iter().find(|dir_name| dir_name.starts_with(dir_prefix))
}; };
(lock_file_name, session_dir.map(String::clone)) (lock_file_name, session_dir.map(String::clone))
})); })
.into();
// Delete all lock files, that don't have an associated directory. They must // Delete all lock files, that don't have an associated directory. They must
// be some kind of leftover // be some kind of leftover
lock_file_to_session_dir.to_sorted(&(), false).iter().for_each( let lock_file_to_session_dir_iter = lock_file_to_session_dir
|(lock_file_name, directory_name)| { .items()
if directory_name.is_none() { .map(|(file, dir)| (file.as_str(), dir.as_ref().map(|y| y.as_str())));
let Ok(timestamp) = extract_timestamp_from_session_dir(lock_file_name) else { for (lock_file_name, directory_name) in
lock_file_to_session_dir_iter.into_sorted_stable_ord(false)
{
if directory_name.is_none() {
let Ok(timestamp) = extract_timestamp_from_session_dir(lock_file_name) else {
debug!( debug!(
"found lock-file with malformed timestamp: {}", "found lock-file with malformed timestamp: {}",
crate_directory.join(&lock_file_name).display() crate_directory.join(&lock_file_name).display()
); );
// Ignore it // Ignore it
return; continue;
}; };
let lock_file_path = crate_directory.join(&**lock_file_name); let lock_file_path = crate_directory.join(&*lock_file_name);
if is_old_enough_to_be_collected(timestamp) { if is_old_enough_to_be_collected(timestamp) {
debug!( debug!(
"garbage_collect_session_directories() - deleting \ "garbage_collect_session_directories() - deleting \
garbage lock file: {}", garbage lock file: {}",
lock_file_path.display() lock_file_path.display()
); );
delete_session_dir_lock_file(sess, &lock_file_path); delete_session_dir_lock_file(sess, &lock_file_path);
} else { } else {
debug!( debug!(
"garbage_collect_session_directories() - lock file with \ "garbage_collect_session_directories() - lock file with \
no session dir not old enough to be collected: {}", no session dir not old enough to be collected: {}",
lock_file_path.display() lock_file_path.display()
); );
}
} }
}, }
); }
// Filter out `None` directories // Filter out `None` directories
let lock_file_to_session_dir: UnordMap<String, String> = let lock_file_to_session_dir: UnordMap<String, String> =

View File

@ -147,7 +147,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
let report_incremental_info = sess.opts.unstable_opts.incremental_info; let report_incremental_info = sess.opts.unstable_opts.incremental_info;
let expected_hash = sess.opts.dep_tracking_hash(false); let expected_hash = sess.opts.dep_tracking_hash(false);
let mut prev_work_products = FxIndexMap::default(); let mut prev_work_products = UnordMap::default();
// If we are only building with -Zquery-dep-graph but without an actual // If we are only building with -Zquery-dep-graph but without an actual
// incr. comp. session directory, we skip this. Otherwise we'd fail // incr. comp. session directory, we skip this. Otherwise we'd fail

View File

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