Skip to content

Commit fd73d01

Browse files
committed
rustc_resolve: Remove Resolver::clone_output
And remove `Clone` impls and `Lrc`s that are no longer necessary
1 parent 9080b79 commit fd73d01

File tree

6 files changed

+18
-79
lines changed

6 files changed

+18
-79
lines changed

compiler/rustc_hir/src/definitions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl DefPathTable {
9292
/// The definition table containing node definitions.
9393
/// It holds the `DefPathTable` for `LocalDefId`s/`DefPath`s.
9494
/// It also stores mappings to convert `LocalDefId`s to/from `HirId`s.
95-
#[derive(Clone, Debug)]
95+
#[derive(Debug)]
9696
pub struct Definitions {
9797
table: DefPathTable,
9898
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3460,7 +3460,7 @@ pub struct Upvar {
34603460
// The TraitCandidate's import_ids is empty if the trait is defined in the same module, and
34613461
// has length > 0 if the trait is found through an chain of imports, starting with the
34623462
// import/use statement in the scope where the trait is used.
3463-
#[derive(Encodable, Decodable, Clone, Debug, HashStable_Generic)]
3463+
#[derive(Encodable, Decodable, Debug, HashStable_Generic)]
34643464
pub struct TraitCandidate {
34653465
pub def_id: DefId,
34663466
pub import_ids: SmallVec<[LocalDefId; 1]>,

compiler/rustc_interface/src/passes.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ use rustc_target::spec::PanicStrategy;
3535
use rustc_trait_selection::traits;
3636

3737
use std::any::Any;
38-
use std::cell::RefCell;
3938
use std::ffi::OsString;
4039
use std::io::{self, BufWriter, Write};
4140
use std::marker::PhantomPinned;
4241
use std::path::{Path, PathBuf};
4342
use std::pin::Pin;
44-
use std::rc::Rc;
4543
use std::sync::{Arc, LazyLock};
4644
use std::{env, fs, iter};
4745

@@ -131,21 +129,12 @@ mod boxed_resolver {
131129
f((&mut *resolver).as_mut().unwrap())
132130
}
133131

134-
pub fn to_resolver_outputs(resolver: Rc<RefCell<BoxedResolver>>) -> ty::ResolverOutputs {
135-
match Rc::try_unwrap(resolver) {
136-
Ok(resolver) => {
137-
let mut resolver = resolver.into_inner();
138-
// SAFETY: The resolver doesn't need to be pinned.
139-
let mut resolver = unsafe {
140-
resolver
141-
.0
142-
.as_mut()
143-
.map_unchecked_mut(|boxed_resolver| &mut boxed_resolver.resolver)
144-
};
145-
resolver.take().unwrap().into_outputs()
146-
}
147-
Err(resolver) => resolver.borrow_mut().access(|resolver| resolver.clone_outputs()),
148-
}
132+
pub fn into_outputs(mut self) -> ty::ResolverOutputs {
133+
// SAFETY: The resolver doesn't need to be pinned.
134+
let mut resolver = unsafe {
135+
self.0.as_mut().map_unchecked_mut(|boxed_resolver| &mut boxed_resolver.resolver)
136+
};
137+
resolver.take().unwrap().into_outputs()
149138
}
150139
}
151140
}

compiler/rustc_interface/src/queries.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rustc_span::symbol::sym;
2121
use rustc_span::Symbol;
2222
use std::any::Any;
2323
use std::cell::{RefCell, RefMut};
24-
use std::rc::Rc;
2524
use std::sync::Arc;
2625

2726
/// Represent the result of a query.
@@ -88,7 +87,7 @@ pub struct Queries<'tcx> {
8887
parse: Query<ast::Crate>,
8988
crate_name: Query<Symbol>,
9089
register_plugins: Query<(ast::Crate, Lrc<LintStore>)>,
91-
expansion: Query<(Lrc<ast::Crate>, Rc<RefCell<BoxedResolver>>, Lrc<LintStore>)>,
90+
expansion: Query<(Lrc<ast::Crate>, BoxedResolver, Lrc<LintStore>)>,
9291
dep_graph: Query<DepGraph>,
9392
// This just points to what's in `gcx_cell`.
9493
gcx: Query<&'tcx GlobalCtxt<'tcx>>,
@@ -171,8 +170,7 @@ impl<'tcx> Queries<'tcx> {
171170

172171
pub fn expansion(
173172
&self,
174-
) -> Result<QueryResult<'_, (Lrc<ast::Crate>, Rc<RefCell<BoxedResolver>>, Lrc<LintStore>)>>
175-
{
173+
) -> Result<QueryResult<'_, (Lrc<ast::Crate>, BoxedResolver, Lrc<LintStore>)>> {
176174
trace!("expansion");
177175
self.expansion.compute(|| {
178176
let crate_name = *self.crate_name()?.borrow();
@@ -188,7 +186,7 @@ impl<'tcx> Queries<'tcx> {
188186
let krate = resolver.access(|resolver| {
189187
passes::configure_and_expand(sess, &lint_store, krate, crate_name, resolver)
190188
})?;
191-
Ok((Lrc::new(krate), Rc::new(RefCell::new(resolver)), lint_store))
189+
Ok((Lrc::new(krate), resolver, lint_store))
192190
})
193191
}
194192

@@ -217,7 +215,7 @@ impl<'tcx> Queries<'tcx> {
217215
untracked,
218216
global_ctxt: untracked_resolutions,
219217
ast_lowering: untracked_resolver_for_lowering,
220-
} = BoxedResolver::to_resolver_outputs(resolver);
218+
} = resolver.into_outputs();
221219

222220
let gcx = passes::create_global_ctxt(
223221
self.compiler,

compiler/rustc_metadata/src/creader.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_ast::expand::allocator::AllocatorKind;
88
use rustc_ast::{self as ast, *};
99
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010
use rustc_data_structures::svh::Svh;
11-
use rustc_data_structures::sync::{Lrc, ReadGuard};
11+
use rustc_data_structures::sync::ReadGuard;
1212
use rustc_expand::base::SyntaxExtension;
1313
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, LOCAL_CRATE};
1414
use rustc_hir::definitions::Definitions;
@@ -30,11 +30,10 @@ use proc_macro::bridge::client::ProcMacro;
3030
use std::ops::Fn;
3131
use std::path::Path;
3232
use std::time::Duration;
33-
use std::{cmp, env};
33+
use std::{cmp, env, iter};
3434

35-
#[derive(Clone)]
3635
pub struct CStore {
37-
metas: IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>,
36+
metas: IndexVec<CrateNum, Option<Box<CrateMetadata>>>,
3837
injected_panic_runtime: Option<CrateNum>,
3938
/// This crate needs an allocator and either provides it itself, or finds it in a dependency.
4039
/// If the above is true, then this field denotes the kind of the found allocator.
@@ -153,7 +152,7 @@ impl CStore {
153152

154153
fn set_crate_data(&mut self, cnum: CrateNum, data: CrateMetadata) {
155154
assert!(self.metas[cnum].is_none(), "Overwriting crate metadata entry");
156-
self.metas[cnum] = Some(Lrc::new(data));
155+
self.metas[cnum] = Some(Box::new(data));
157156
}
158157

159158
pub(crate) fn iter_crate_data(&self) -> impl Iterator<Item = (CrateNum, &CrateMetadata)> {
@@ -245,7 +244,7 @@ impl CStore {
245244
// order to make array indices in `metas` match with the
246245
// corresponding `CrateNum`. This first entry will always remain
247246
// `None`.
248-
metas: IndexVec::from_elem_n(None, 1),
247+
metas: IndexVec::from_iter(iter::once(None)),
249248
injected_panic_runtime: None,
250249
allocator_kind: None,
251250
alloc_error_handler_kind: None,

compiler/rustc_resolve/src/lib.rs

+1-48
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl ModuleOrUniformRoot<'_> {
378378
}
379379
}
380380

381-
#[derive(Clone, Debug)]
381+
#[derive(Debug)]
382382
enum PathResult<'a> {
383383
Module(ModuleOrUniformRoot<'a>),
384384
NonModule(PartialRes),
@@ -1472,53 +1472,6 @@ impl<'a> Resolver<'a> {
14721472
ResolverOutputs { global_ctxt, ast_lowering, untracked }
14731473
}
14741474

1475-
pub fn clone_outputs(&self) -> ResolverOutputs {
1476-
let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect();
1477-
let definitions = self.untracked.definitions.clone();
1478-
let cstore = Box::new(self.cstore().clone());
1479-
let untracked =
1480-
Untracked { cstore, source_span: self.untracked.source_span.clone(), definitions };
1481-
let global_ctxt = ResolverGlobalCtxt {
1482-
expn_that_defined: self.expn_that_defined.clone(),
1483-
visibilities: self.visibilities.clone(),
1484-
has_pub_restricted: self.has_pub_restricted,
1485-
extern_crate_map: self.extern_crate_map.clone(),
1486-
reexport_map: self.reexport_map.clone(),
1487-
glob_map: self.glob_map.clone(),
1488-
maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(),
1489-
maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(),
1490-
extern_prelude: self
1491-
.extern_prelude
1492-
.iter()
1493-
.map(|(ident, entry)| (ident.name, entry.introduced_by_item))
1494-
.collect(),
1495-
main_def: self.main_def,
1496-
trait_impls: self.trait_impls.clone(),
1497-
proc_macros,
1498-
confused_type_with_std_module: self.confused_type_with_std_module.clone(),
1499-
registered_tools: self.registered_tools.clone(),
1500-
effective_visibilities: self.effective_visibilities.clone(),
1501-
doc_link_resolutions: self.doc_link_resolutions.clone(),
1502-
doc_link_traits_in_scope: self.doc_link_traits_in_scope.clone(),
1503-
all_macro_rules: self.all_macro_rules.clone(),
1504-
};
1505-
let ast_lowering = ty::ResolverAstLowering {
1506-
legacy_const_generic_args: self.legacy_const_generic_args.clone(),
1507-
partial_res_map: self.partial_res_map.clone(),
1508-
import_res_map: self.import_res_map.clone(),
1509-
label_res_map: self.label_res_map.clone(),
1510-
lifetimes_res_map: self.lifetimes_res_map.clone(),
1511-
extra_lifetime_params_map: self.extra_lifetime_params_map.clone(),
1512-
next_node_id: self.next_node_id,
1513-
node_id_to_def_id: self.node_id_to_def_id.clone(),
1514-
def_id_to_node_id: self.def_id_to_node_id.clone(),
1515-
trait_map: self.trait_map.clone(),
1516-
builtin_macro_kinds: self.builtin_macro_kinds.clone(),
1517-
lifetime_elision_allowed: self.lifetime_elision_allowed.clone(),
1518-
};
1519-
ResolverOutputs { global_ctxt, ast_lowering, untracked }
1520-
}
1521-
15221475
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
15231476
StableHashingContext::new(self.session, &self.untracked)
15241477
}

0 commit comments

Comments
 (0)