Skip to content

Resolve: cachify ExternPreludeEntry.binding through a Cell #144605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,18 +984,17 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
// more details: https://github.com/rust-lang/rust/pull/111761
return;
}
let entry = self
.r
.extern_prelude
.entry(ident)
.or_insert(ExternPreludeEntry { binding: None, introduced_by_item: true });
let entry = self.r.extern_prelude.entry(ident).or_insert(ExternPreludeEntry {
binding: Cell::new(None),
introduced_by_item: true,
});
if orig_name.is_some() {
entry.introduced_by_item = true;
}
// Binding from `extern crate` item in source code can replace
// a binding from `--extern` on command line here.
if !entry.is_import() {
entry.binding = Some(imported_binding)
entry.binding.set(Some(imported_binding));
} else if ident.name != kw::Underscore {
self.r.dcx().span_delayed_bug(
item.span,
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,13 +1009,13 @@ impl<'ra> NameBindingData<'ra> {

#[derive(Default, Clone)]
struct ExternPreludeEntry<'ra> {
binding: Option<NameBinding<'ra>>,
binding: Cell<Option<NameBinding<'ra>>>,
introduced_by_item: bool,
}

impl ExternPreludeEntry<'_> {
fn is_import(&self) -> bool {
self.binding.is_some_and(|binding| binding.is_import())
self.binding.get().is_some_and(|binding| binding.is_import())
}
}

Expand Down Expand Up @@ -2006,7 +2006,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// but not introduce it, as used if they are accessed from lexical scope.
if used == Used::Scope {
if let Some(entry) = self.extern_prelude.get(&ident.normalize_to_macros_2_0()) {
if !entry.introduced_by_item && entry.binding == Some(used_binding) {
if !entry.introduced_by_item && entry.binding.get() == Some(used_binding) {
return;
}
}
Expand Down Expand Up @@ -2170,7 +2170,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

let norm_ident = ident.normalize_to_macros_2_0();
let binding = self.extern_prelude.get(&norm_ident).cloned().and_then(|entry| {
Some(if let Some(binding) = entry.binding {
Some(if let Some(binding) = entry.binding.get() {
if finalize {
if !entry.is_import() {
self.cstore_mut().process_path_extern(self.tcx, ident.name, ident.span);
Expand All @@ -2195,8 +2195,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
})
});

if let Some(entry) = self.extern_prelude.get_mut(&norm_ident) {
entry.binding = binding;
if let Some(entry) = self.extern_prelude.get(&norm_ident) {
entry.binding.set(binding);
}

binding
Expand Down
Loading