Skip to content

Commit e36eb0b

Browse files
authored
Unrolled build for #147539
Rollup merge of #147539 - petrochenkov:cmresolve, r=eholk resolve: Use primitives for conditional mutability more consistently No bare `(Ref)Cell`s remain in `rustc_resolve`, only `Cm(Ref)Cell`s checking that nothing is modified during speculative resolution, and `Cache(Ref)Cell` aliases for cells that need to be migrated to mutexes/atomics. cc `@LorrensP-2158466`
2 parents 235a4c0 + 204508d commit e36eb0b

File tree

6 files changed

+71
-77
lines changed

6 files changed

+71
-77
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
8787
// because they can be fetched by glob imports from those modules, and bring traits
8888
// into scope both directly and through glob imports.
8989
let key = BindingKey::new_disambiguated(ident, ns, || {
90-
// FIXME(batched): Will be fixed in batched resolution.
9190
parent.underscore_disambiguator.update_unchecked(|d| d + 1);
9291
parent.underscore_disambiguator.get()
9392
});
9493
if self
9594
.resolution_or_default(parent, key)
96-
.borrow_mut()
95+
.borrow_mut_unchecked()
9796
.non_glob_binding
9897
.replace(binding)
9998
.is_some()
@@ -499,7 +498,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
499498
if !type_ns_only || ns == TypeNS {
500499
let key = BindingKey::new(target, ns);
501500
this.resolution_or_default(current_module, key)
502-
.borrow_mut()
501+
.borrow_mut(this)
503502
.single_imports
504503
.insert(import);
505504
}

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl Resolver<'_, '_> {
507507

508508
let unused_imports = visitor.unused_imports;
509509
let mut check_redundant_imports = FxIndexSet::default();
510-
for module in self.arenas.local_modules().iter() {
510+
for module in &self.local_modules {
511511
for (_key, resolution) in self.resolutions(*module).borrow().iter() {
512512
if let Some(binding) = resolution.borrow().best_binding()
513513
&& let NameBindingKind::Import { import, .. } = binding.kind

compiler/rustc_resolve/src/ident.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
891891
// the exclusive access infinite recursion will crash the compiler with stack overflow.
892892
let resolution = &*self
893893
.resolution_or_default(module, key)
894-
.try_borrow_mut()
894+
.try_borrow_mut_unchecked()
895895
.map_err(|_| (Determined, Weak::No))?;
896896

897897
// If the primary binding is unusable, search further and return the shadowed glob

compiler/rustc_resolve/src/imports.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_data_structures::intern::Interned;
88
use rustc_errors::codes::*;
99
use rustc_errors::{Applicability, MultiSpan, pluralize, struct_span_code_err};
1010
use rustc_hir::def::{self, DefKind, PartialRes};
11-
use rustc_hir::def_id::DefId;
11+
use rustc_hir::def_id::{DefId, LocalDefIdMap};
1212
use rustc_middle::metadata::{ModChild, Reexport};
1313
use rustc_middle::span_bug;
1414
use rustc_middle::ty::Visibility;
@@ -320,7 +320,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
320320
&& (vis == import_vis
321321
|| max_vis.get().is_none_or(|max_vis| vis.is_at_least(max_vis, self.tcx)))
322322
{
323-
// FIXME(batched): Will be fixed in batched import resolution.
324323
max_vis.set_unchecked(Some(vis.expect_local()))
325324
}
326325

@@ -350,7 +349,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
350349
// because they can be fetched by glob imports from those modules, and bring traits
351350
// into scope both directly and through glob imports.
352351
let key = BindingKey::new_disambiguated(ident, ns, || {
353-
// FIXME(batched): Will be fixed in batched resolution.
354352
module.underscore_disambiguator.update_unchecked(|d| d + 1);
355353
module.underscore_disambiguator.get()
356354
});
@@ -470,7 +468,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
470468
// Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
471469
// during which the resolution might end up getting re-defined via a glob cycle.
472470
let (binding, t, warn_ambiguity) = {
473-
let resolution = &mut *self.resolution_or_default(module, key).borrow_mut();
471+
let resolution = &mut *self.resolution_or_default(module, key).borrow_mut_unchecked();
474472
let old_binding = resolution.binding();
475473

476474
let t = f(self, resolution);
@@ -553,12 +551,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
553551
/// Resolves all imports for the crate. This method performs the fixed-
554552
/// point iteration.
555553
pub(crate) fn resolve_imports(&mut self) {
556-
self.assert_speculative = true;
557554
let mut prev_indeterminate_count = usize::MAX;
558555
let mut indeterminate_count = self.indeterminate_imports.len() * 3;
559556
while indeterminate_count < prev_indeterminate_count {
560557
prev_indeterminate_count = indeterminate_count;
561558
indeterminate_count = 0;
559+
self.assert_speculative = true;
562560
for import in mem::take(&mut self.indeterminate_imports) {
563561
let import_indeterminate_count = self.cm().resolve_import(import);
564562
indeterminate_count += import_indeterminate_count;
@@ -567,14 +565,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
567565
_ => self.indeterminate_imports.push(import),
568566
}
569567
}
568+
self.assert_speculative = false;
570569
}
571-
self.assert_speculative = false;
572570
}
573571

574572
pub(crate) fn finalize_imports(&mut self) {
575-
for module in self.arenas.local_modules().iter() {
576-
self.finalize_resolutions_in(*module);
573+
let mut module_children = Default::default();
574+
for module in &self.local_modules {
575+
self.finalize_resolutions_in(*module, &mut module_children);
577576
}
577+
self.module_children = module_children;
578578

579579
let mut seen_spans = FxHashSet::default();
580580
let mut errors = vec![];
@@ -651,7 +651,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
651651
}
652652

653653
pub(crate) fn lint_reexports(&mut self, exported_ambiguities: FxHashSet<NameBinding<'ra>>) {
654-
for module in self.arenas.local_modules().iter() {
654+
for module in &self.local_modules {
655655
for (key, resolution) in self.resolutions(*module).borrow().iter() {
656656
let resolution = resolution.borrow();
657657
let Some(binding) = resolution.best_binding() else { continue };
@@ -860,15 +860,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
860860
}
861861
};
862862

863-
// FIXME(batched): Will be fixed in batched import resolution.
864863
import.imported_module.set_unchecked(Some(module));
865864
let (source, target, bindings, type_ns_only) = match import.kind {
866865
ImportKind::Single { source, target, ref bindings, type_ns_only, .. } => {
867866
(source, target, bindings, type_ns_only)
868867
}
869868
ImportKind::Glob { .. } => {
870-
// FIXME: Use mutable resolver directly as a hack, this should be an output of
871-
// speculative resolution.
872869
self.get_mut_unchecked().resolve_glob_import(import);
873870
return 0;
874871
}
@@ -904,8 +901,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
904901
}
905902
// We need the `target`, `source` can be extracted.
906903
let imported_binding = this.import(binding, import);
907-
// FIXME: Use mutable resolver directly as a hack, this should be an output of
908-
// speculative resolution.
909904
this.get_mut_unchecked().define_binding_local(
910905
parent,
911906
target,
@@ -918,8 +913,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
918913
// Don't remove underscores from `single_imports`, they were never added.
919914
if target.name != kw::Underscore {
920915
let key = BindingKey::new(target, ns);
921-
// FIXME: Use mutable resolver directly as a hack, this should be an output of
922-
// speculative resolution.
923916
this.get_mut_unchecked().update_local_resolution(
924917
parent,
925918
key,
@@ -936,7 +929,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
936929
PendingBinding::Pending
937930
}
938931
};
939-
// FIXME(batched): Will be fixed in batched import resolution.
940932
bindings[ns].set_unchecked(binding);
941933
}
942934
});
@@ -1548,7 +1540,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15481540

15491541
// Miscellaneous post-processing, including recording re-exports,
15501542
// reporting conflicts, and reporting unresolved imports.
1551-
fn finalize_resolutions_in(&mut self, module: Module<'ra>) {
1543+
fn finalize_resolutions_in(
1544+
&self,
1545+
module: Module<'ra>,
1546+
module_children: &mut LocalDefIdMap<Vec<ModChild>>,
1547+
) {
15521548
// Since import resolution is finished, globs will not define any more names.
15531549
*module.globs.borrow_mut(self) = Vec::new();
15541550

@@ -1573,7 +1569,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15731569

15741570
if !children.is_empty() {
15751571
// Should be fine because this code is only called for local modules.
1576-
self.module_children.insert(def_id.expect_local(), children);
1572+
module_children.insert(def_id.expect_local(), children);
15771573
}
15781574
}
15791575
}

0 commit comments

Comments
 (0)