Skip to content

Commit f09b6a8

Browse files
committed
Try to sort single_imports before usage to have a stable result
The `FxIndexSet` solution seems costly.
1 parent 5d14c34 commit f09b6a8

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

compiler/rustc_resolve/src/ident.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
984984

985985
// --- From now on we either have a glob resolution or no resolution. ---
986986

987+
// It is sorted before usage so ordering is not important.
988+
#[allow(rustc::potential_query_instability)]
989+
let mut single_imports: Vec<_> = resolution.single_imports.clone().into_iter().collect();
990+
single_imports.sort_by_key(|import| import.0.id());
991+
987992
// Check if one of single imports can still define the name,
988993
// if it can then our result is not determined and can be invalidated.
989-
for single_import in &resolution.single_imports {
994+
for single_import in &single_imports {
990995
if ignore_import == Some(*single_import) {
991996
// This branch handles a cycle in single imports.
992997
//

compiler/rustc_resolve/src/imports.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::cell::Cell;
44
use std::mem;
55

66
use rustc_ast::NodeId;
7-
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
7+
use rustc_data_structures::fx::FxHashSet;
88
use rustc_data_structures::intern::Interned;
99
use rustc_errors::codes::*;
1010
use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err};
@@ -220,7 +220,7 @@ impl<'ra> ImportData<'ra> {
220220
pub(crate) struct NameResolution<'ra> {
221221
/// Single imports that may define the name in the namespace.
222222
/// Imports are arena-allocated, so it's ok to use pointers as keys.
223-
pub single_imports: FxIndexSet<Import<'ra>>,
223+
pub single_imports: FxHashSet<Import<'ra>>,
224224
/// The least shadowable known binding for this name, or None if there are no known bindings.
225225
pub binding: Option<NameBinding<'ra>>,
226226
pub shadowed_glob: Option<NameBinding<'ra>>,
@@ -482,7 +482,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
482482
let key = BindingKey::new(target, ns);
483483
let _ = this.try_define(import.parent_scope.module, key, dummy_binding, false);
484484
this.update_resolution(import.parent_scope.module, key, false, |_, resolution| {
485-
resolution.single_imports.shift_remove(&import);
485+
resolution.single_imports.remove(&import);
486486
})
487487
});
488488
self.record_use(target, dummy_binding, Used::Other);
@@ -837,7 +837,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
837837
}
838838
let key = BindingKey::new(target, ns);
839839
this.update_resolution(parent, key, false, |_, resolution| {
840-
resolution.single_imports.shift_remove(&import);
840+
resolution.single_imports.remove(&import);
841841
});
842842
}
843843
}

0 commit comments

Comments
 (0)