Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 17412ba

Browse files
committed
Removed use of iteration through a HashMap/HashSet in rustc_incremental and replaced with IndexMap/IndexSet
1 parent dcf3571 commit 17412ba

File tree

12 files changed

+47
-48
lines changed

12 files changed

+47
-48
lines changed

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_codegen_ssa::back::write::{
3434
use rustc_codegen_ssa::traits::*;
3535
use rustc_codegen_ssa::ModuleCodegen;
3636
use rustc_codegen_ssa::{CodegenResults, CompiledModule};
37-
use rustc_data_structures::fx::FxHashMap;
37+
use rustc_data_structures::fx::FxIndexMap;
3838
use rustc_errors::{DiagnosticMessage, ErrorGuaranteed, FatalError, Handler, SubdiagnosticMessage};
3939
use rustc_fluent_macro::fluent_messages;
4040
use rustc_metadata::EncodedMetadata;
@@ -356,7 +356,7 @@ impl CodegenBackend for LlvmCodegenBackend {
356356
ongoing_codegen: Box<dyn Any>,
357357
sess: &Session,
358358
outputs: &OutputFilenames,
359-
) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
359+
) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
360360
let (codegen_results, work_products) = ongoing_codegen
361361
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<LlvmCodegenBackend>>()
362362
.expect("Expected LlvmCodegenBackend's OngoingCodegen, found Box<Any>")

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
};
1010
use jobserver::{Acquired, Client};
1111
use rustc_ast::attr;
12-
use rustc_data_structures::fx::FxHashMap;
12+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
1313
use rustc_data_structures::memmap::Mmap;
1414
use rustc_data_structures::profiling::SelfProfilerRef;
1515
use rustc_data_structures::profiling::TimingGuard;
@@ -498,8 +498,8 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
498498
fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
499499
sess: &Session,
500500
compiled_modules: &CompiledModules,
501-
) -> FxHashMap<WorkProductId, WorkProduct> {
502-
let mut work_products = FxHashMap::default();
501+
) -> FxIndexMap<WorkProductId, WorkProduct> {
502+
let mut work_products = FxIndexMap::default();
503503

504504
if sess.opts.incremental.is_none() {
505505
return work_products;
@@ -1885,7 +1885,7 @@ pub struct OngoingCodegen<B: ExtraBackendMethods> {
18851885
}
18861886

18871887
impl<B: ExtraBackendMethods> OngoingCodegen<B> {
1888-
pub fn join(self, sess: &Session) -> (CodegenResults, FxHashMap<WorkProductId, WorkProduct>) {
1888+
pub fn join(self, sess: &Session) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
18891889
let _timer = sess.timer("finish_ongoing_codegen");
18901890

18911891
self.shared_emitter_main.check(sess, true);

compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::back::write::TargetMachineFactoryFn;
66
use crate::{CodegenResults, ModuleCodegen};
77

88
use rustc_ast::expand::allocator::AllocatorKind;
9-
use rustc_data_structures::fx::FxHashMap;
9+
use rustc_data_structures::fx::FxIndexMap;
1010
use rustc_data_structures::sync::{DynSend, DynSync};
1111
use rustc_errors::ErrorGuaranteed;
1212
use rustc_metadata::EncodedMetadata;
@@ -101,7 +101,7 @@ pub trait CodegenBackend {
101101
ongoing_codegen: Box<dyn Any>,
102102
sess: &Session,
103103
outputs: &OutputFilenames,
104-
) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorGuaranteed>;
104+
) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed>;
105105

106106
/// This is called on the returned `Box<dyn Any>` from `join_codegen`
107107
///

compiler/rustc_incremental/src/assert_dep_graph.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
3636
use crate::errors;
3737
use rustc_ast as ast;
38-
use rustc_data_structures::fx::FxHashSet;
38+
use rustc_data_structures::fx::FxIndexSet;
3939
use rustc_data_structures::graph::implementation::{Direction, NodeIndex, INCOMING, OUTGOING};
4040
use rustc_graphviz as dot;
4141
use rustc_hir as hir;
@@ -258,7 +258,7 @@ fn dump_graph(query: &DepGraphQuery) {
258258
}
259259

260260
#[allow(missing_docs)]
261-
pub struct GraphvizDepGraph(FxHashSet<DepKind>, Vec<(DepKind, DepKind)>);
261+
pub struct GraphvizDepGraph(FxIndexSet<DepKind>, Vec<(DepKind, DepKind)>);
262262

263263
impl<'a> dot::GraphWalk<'a> for GraphvizDepGraph {
264264
type Node = DepKind;
@@ -303,7 +303,7 @@ impl<'a> dot::Labeller<'a> for GraphvizDepGraph {
303303
fn node_set<'q>(
304304
query: &'q DepGraphQuery,
305305
filter: &DepNodeFilter,
306-
) -> Option<FxHashSet<&'q DepNode>> {
306+
) -> Option<FxIndexSet<&'q DepNode>> {
307307
debug!("node_set(filter={:?})", filter);
308308

309309
if filter.accepts_all() {
@@ -315,9 +315,9 @@ fn node_set<'q>(
315315

316316
fn filter_nodes<'q>(
317317
query: &'q DepGraphQuery,
318-
sources: &Option<FxHashSet<&'q DepNode>>,
319-
targets: &Option<FxHashSet<&'q DepNode>>,
320-
) -> FxHashSet<DepKind> {
318+
sources: &Option<FxIndexSet<&'q DepNode>>,
319+
targets: &Option<FxIndexSet<&'q DepNode>>,
320+
) -> FxIndexSet<DepKind> {
321321
if let Some(sources) = sources {
322322
if let Some(targets) = targets {
323323
walk_between(query, sources, targets)
@@ -333,10 +333,10 @@ fn filter_nodes<'q>(
333333

334334
fn walk_nodes<'q>(
335335
query: &'q DepGraphQuery,
336-
starts: &FxHashSet<&'q DepNode>,
336+
starts: &FxIndexSet<&'q DepNode>,
337337
direction: Direction,
338-
) -> FxHashSet<DepKind> {
339-
let mut set = FxHashSet::default();
338+
) -> FxIndexSet<DepKind> {
339+
let mut set = FxIndexSet::default();
340340
for &start in starts {
341341
debug!("walk_nodes: start={:?} outgoing?={:?}", start, direction == OUTGOING);
342342
if set.insert(start.kind) {
@@ -357,9 +357,9 @@ fn walk_nodes<'q>(
357357

358358
fn walk_between<'q>(
359359
query: &'q DepGraphQuery,
360-
sources: &FxHashSet<&'q DepNode>,
361-
targets: &FxHashSet<&'q DepNode>,
362-
) -> FxHashSet<DepKind> {
360+
sources: &FxIndexSet<&'q DepNode>,
361+
targets: &FxIndexSet<&'q DepNode>,
362+
) -> FxIndexSet<DepKind> {
363363
// This is a bit tricky. We want to include a node only if it is:
364364
// (a) reachable from a source and (b) will reach a target. And we
365365
// have to be careful about cycles etc. Luckily efficiency is not
@@ -426,8 +426,8 @@ fn walk_between<'q>(
426426
}
427427
}
428428

429-
fn filter_edges(query: &DepGraphQuery, nodes: &FxHashSet<DepKind>) -> Vec<(DepKind, DepKind)> {
430-
let uniq: FxHashSet<_> = query
429+
fn filter_edges(query: &DepGraphQuery, nodes: &FxIndexSet<DepKind>) -> Vec<(DepKind, DepKind)> {
430+
let uniq: FxIndexSet<_> = query
431431
.edges()
432432
.into_iter()
433433
.map(|(s, t)| (s.kind, t.kind))

compiler/rustc_incremental/src/assert_module_sources.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
use crate::errors;
2626
use rustc_ast as ast;
27-
use rustc_data_structures::fx::FxHashSet;
27+
use rustc_data_structures::fx::FxIndexSet;
2828
use rustc_hir::def_id::LOCAL_CRATE;
2929
use rustc_middle::mir::mono::CodegenUnitNameBuilder;
3030
use rustc_middle::ty::TyCtxt;
@@ -52,7 +52,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
5252

5353
struct AssertModuleSource<'tcx> {
5454
tcx: TyCtxt<'tcx>,
55-
available_cgus: FxHashSet<Symbol>,
55+
available_cgus: FxIndexSet<Symbol>,
5656
}
5757

5858
impl<'tcx> AssertModuleSource<'tcx> {

compiler/rustc_incremental/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
55
#![feature(never_type)]
66
#![recursion_limit = "256"]
7-
#![allow(rustc::potential_query_instability)]
87
#![deny(rustc::untranslatable_diagnostic)]
98
#![deny(rustc::diagnostic_outside_of_impl)]
109

compiler/rustc_incremental/src/persist/dirty_clean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
2222
use crate::errors;
2323
use rustc_ast::{self as ast, Attribute, NestedMetaItem};
24-
use rustc_data_structures::fx::FxHashSet;
24+
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
2525
use rustc_hir::def_id::LocalDefId;
2626
use rustc_hir::intravisit;
2727
use rustc_hir::Node as HirNode;
@@ -125,7 +125,7 @@ const LABELS_ADT: &[&[&str]] = &[BASE_HIR, BASE_STRUCT];
125125
//
126126
// type_of for these.
127127

128-
type Labels = FxHashSet<String>;
128+
type Labels = FxIndexSet<String>;
129129

130130
/// Represents the requested configuration by rustc_clean/dirty
131131
struct Assertion {

compiler/rustc_incremental/src/persist/fs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
//! implemented.
105105
106106
use crate::errors;
107-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
107+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
108108
use rustc_data_structures::svh::Svh;
109109
use rustc_data_structures::{base_n, flock};
110110
use rustc_errors::ErrorGuaranteed;
@@ -635,8 +635,8 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
635635

636636
// First do a pass over the crate directory, collecting lock files and
637637
// session directories
638-
let mut session_directories = FxHashSet::default();
639-
let mut lock_files = FxHashSet::default();
638+
let mut session_directories = FxIndexSet::default();
639+
let mut lock_files = FxIndexSet::default();
640640

641641
for dir_entry in crate_directory.read_dir()? {
642642
let Ok(dir_entry) = dir_entry else {
@@ -659,7 +659,7 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
659659
}
660660

661661
// Now map from lock files to session directories
662-
let lock_file_to_session_dir: FxHashMap<String, Option<String>> = lock_files
662+
let lock_file_to_session_dir: FxIndexMap<String, Option<String>> = lock_files
663663
.into_iter()
664664
.map(|lock_file_name| {
665665
assert!(lock_file_name.ends_with(LOCK_FILE_EXT));
@@ -705,7 +705,7 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
705705
}
706706

707707
// Filter out `None` directories
708-
let lock_file_to_session_dir: FxHashMap<String, String> = lock_file_to_session_dir
708+
let lock_file_to_session_dir: FxIndexMap<String, String> = lock_file_to_session_dir
709709
.into_iter()
710710
.filter_map(|(lock_file_name, directory_name)| directory_name.map(|n| (lock_file_name, n)))
711711
.collect();
@@ -846,7 +846,7 @@ fn delete_old(sess: &Session, path: &Path) {
846846

847847
fn all_except_most_recent(
848848
deletion_candidates: Vec<(SystemTime, PathBuf, Option<flock::Lock>)>,
849-
) -> FxHashMap<PathBuf, Option<flock::Lock>> {
849+
) -> FxIndexMap<PathBuf, Option<flock::Lock>> {
850850
let most_recent = deletion_candidates.iter().map(|&(timestamp, ..)| timestamp).max();
851851

852852
if let Some(most_recent) = most_recent {
@@ -856,7 +856,7 @@ fn all_except_most_recent(
856856
.map(|(_, path, lock)| (path, lock))
857857
.collect()
858858
} else {
859-
FxHashMap::default()
859+
FxIndexMap::default()
860860
}
861861
}
862862

compiler/rustc_incremental/src/persist/load.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Code to save/load the dep-graph from files.
22
33
use crate::errors;
4-
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_data_structures::fx::FxIndexMap;
55
use rustc_data_structures::memmap::Mmap;
66
use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
77
use rustc_middle::query::on_disk_cache::OnDiskCache;
@@ -16,7 +16,7 @@ use super::file_format;
1616
use super::fs::*;
1717
use super::work_product;
1818

19-
type WorkProductMap = FxHashMap<WorkProductId, WorkProduct>;
19+
type WorkProductMap = FxIndexMap<WorkProductId, WorkProduct>;
2020

2121
#[derive(Debug)]
2222
/// Represents the result of an attempt to load incremental compilation data.
@@ -147,7 +147,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
147147
let report_incremental_info = sess.opts.unstable_opts.incremental_info;
148148
let expected_hash = sess.opts.dep_tracking_hash(false);
149149

150-
let mut prev_work_products = FxHashMap::default();
150+
let mut prev_work_products = FxIndexMap::default();
151151

152152
// If we are only building with -Zquery-dep-graph but without an actual
153153
// incr. comp. session directory, we skip this. Otherwise we'd fail

compiler/rustc_incremental/src/persist/save.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::errors;
2-
use rustc_data_structures::fx::FxHashMap;
2+
use rustc_data_structures::fx::FxIndexMap;
33
use rustc_data_structures::sync::join;
44
use rustc_middle::dep_graph::{DepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
55
use rustc_middle::ty::TyCtxt;
@@ -79,7 +79,7 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
7979
pub fn save_work_product_index(
8080
sess: &Session,
8181
dep_graph: &DepGraph,
82-
new_work_products: FxHashMap<WorkProductId, WorkProduct>,
82+
new_work_products: FxIndexMap<WorkProductId, WorkProduct>,
8383
) {
8484
if sess.opts.incremental.is_none() {
8585
return;
@@ -119,7 +119,7 @@ pub fn save_work_product_index(
119119
}
120120

121121
fn encode_work_product_index(
122-
work_products: &FxHashMap<WorkProductId, WorkProduct>,
122+
work_products: &FxIndexMap<WorkProductId, WorkProduct>,
123123
encoder: &mut FileEncoder,
124124
) {
125125
let serialized_products: Vec<_> = work_products
@@ -146,7 +146,7 @@ fn encode_query_cache(tcx: TyCtxt<'_>, encoder: FileEncoder) -> FileEncodeResult
146146
pub fn build_dep_graph(
147147
sess: &Session,
148148
prev_graph: SerializedDepGraph,
149-
prev_work_products: FxHashMap<WorkProductId, WorkProduct>,
149+
prev_work_products: FxIndexMap<WorkProductId, WorkProduct>,
150150
) -> Option<DepGraph> {
151151
if sess.opts.incremental.is_none() {
152152
// No incremental compilation.

compiler/rustc_incremental/src/persist/work_product.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use crate::errors;
66
use crate::persist::fs::*;
7-
use rustc_data_structures::fx::FxHashMap;
7+
use rustc_data_structures::fx::FxIndexMap;
88
use rustc_fs_util::link_or_copy;
99
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
1010
use rustc_session::Session;
@@ -20,7 +20,7 @@ pub fn copy_cgu_workproduct_to_incr_comp_cache_dir(
2020
debug!(?cgu_name, ?files);
2121
sess.opts.incremental.as_ref()?;
2222

23-
let mut saved_files = FxHashMap::default();
23+
let mut saved_files = FxIndexMap::default();
2424
for (ext, path) in files {
2525
let file_name = format!("{cgu_name}.{ext}");
2626
let path_in_incr_dir = in_incr_comp_dir_sess(sess, &file_name);

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use parking_lot::Mutex;
22
use rustc_data_structures::fingerprint::Fingerprint;
3-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
44
use rustc_data_structures::profiling::{EventId, QueryInvocationId, SelfProfilerRef};
55
use rustc_data_structures::sharded::{self, Sharded};
66
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -93,7 +93,7 @@ pub struct DepGraphData<K: DepKind> {
9393
/// things available to us. If we find that they are not dirty, we
9494
/// load the path to the file storing those work-products here into
9595
/// this map. We can later look for and extract that data.
96-
previous_work_products: FxHashMap<WorkProductId, WorkProduct>,
96+
previous_work_products: FxIndexMap<WorkProductId, WorkProduct>,
9797

9898
dep_node_debug: Lock<FxHashMap<DepNode<K>, String>>,
9999

@@ -116,7 +116,7 @@ impl<K: DepKind> DepGraph<K> {
116116
pub fn new(
117117
profiler: &SelfProfilerRef,
118118
prev_graph: SerializedDepGraph<K>,
119-
prev_work_products: FxHashMap<WorkProductId, WorkProduct>,
119+
prev_work_products: FxIndexMap<WorkProductId, WorkProduct>,
120120
encoder: FileEncoder,
121121
record_graph: bool,
122122
record_stats: bool,
@@ -688,7 +688,7 @@ impl<K: DepKind> DepGraph<K> {
688688

689689
/// Access the map of work-products created during the cached run. Only
690690
/// used during saving of the dep-graph.
691-
pub fn previous_work_products(&self) -> &FxHashMap<WorkProductId, WorkProduct> {
691+
pub fn previous_work_products(&self) -> &FxIndexMap<WorkProductId, WorkProduct> {
692692
&self.data.as_ref().unwrap().previous_work_products
693693
}
694694

@@ -1048,7 +1048,7 @@ pub struct WorkProduct {
10481048
///
10491049
/// By convention, file extensions are currently used as identifiers, i.e. the key "o" maps to
10501050
/// the object file's path, and "dwo" to the dwarf object file's path.
1051-
pub saved_files: FxHashMap<String, String>,
1051+
pub saved_files: FxIndexMap<String, String>,
10521052
}
10531053

10541054
// Index type for `DepNodeData`'s edges.

0 commit comments

Comments
 (0)