Skip to content

Commit cbc70ff

Browse files
committedDec 10, 2022
Auto merge of rust-lang#105357 - oli-obk:feeding, r=cjgillot,petrochenkov
Group some fields in a common struct so we only pass one reference instead of three r? `@cjgillot`
2 parents a000811 + 75ff5c7 commit cbc70ff

File tree

19 files changed

+164
-185
lines changed

19 files changed

+164
-185
lines changed
 

Diff for: ‎Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4343,6 +4343,7 @@ dependencies = [
43434343
"rustc_feature",
43444344
"rustc_fs_util",
43454345
"rustc_hir",
4346+
"rustc_index",
43464347
"rustc_lint_defs",
43474348
"rustc_macros",
43484349
"rustc_serialize",

Diff for: ‎compiler/rustc_interface/src/passes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,9 @@ pub fn create_global_ctxt<'tcx>(
805805
});
806806

807807
let ty::ResolverOutputs {
808-
definitions,
809808
global_ctxt: untracked_resolutions,
810809
ast_lowering: untracked_resolver_for_lowering,
810+
untracked,
811811
} = resolver_outputs;
812812

813813
let gcx = sess.time("setup_global_ctxt", || {
@@ -817,8 +817,8 @@ pub fn create_global_ctxt<'tcx>(
817817
lint_store,
818818
arena,
819819
hir_arena,
820-
definitions,
821820
untracked_resolutions,
821+
untracked,
822822
krate,
823823
dep_graph,
824824
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),

Diff for: ‎compiler/rustc_metadata/src/creader.rs

+32-30
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast::expand::allocator::AllocatorKind;
1313
use rustc_ast::{self as ast, *};
1414
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1515
use rustc_data_structures::svh::Svh;
16-
use rustc_data_structures::sync::Lrc;
16+
use rustc_data_structures::sync::{Lrc, ReadGuard};
1717
use rustc_expand::base::SyntaxExtension;
1818
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, LOCAL_CRATE};
1919
use rustc_hir::definitions::Definitions;
@@ -68,11 +68,12 @@ impl std::fmt::Debug for CStore {
6868
pub struct CrateLoader<'a> {
6969
// Immutable configuration.
7070
sess: &'a Session,
71-
metadata_loader: Box<MetadataLoaderDyn>,
71+
metadata_loader: &'a MetadataLoaderDyn,
72+
definitions: ReadGuard<'a, Definitions>,
7273
local_crate_name: Symbol,
7374
// Mutable output.
74-
cstore: CStore,
75-
used_extern_options: FxHashSet<Symbol>,
75+
cstore: &'a mut CStore,
76+
used_extern_options: &'a mut FxHashSet<Symbol>,
7677
}
7778

7879
pub enum LoadedMacro {
@@ -239,47 +240,49 @@ impl CStore {
239240
);
240241
}
241242
}
243+
244+
pub fn new(sess: &Session) -> CStore {
245+
let mut stable_crate_ids = FxHashMap::default();
246+
stable_crate_ids.insert(sess.local_stable_crate_id(), LOCAL_CRATE);
247+
CStore {
248+
// We add an empty entry for LOCAL_CRATE (which maps to zero) in
249+
// order to make array indices in `metas` match with the
250+
// corresponding `CrateNum`. This first entry will always remain
251+
// `None`.
252+
metas: IndexVec::from_elem_n(None, 1),
253+
injected_panic_runtime: None,
254+
allocator_kind: None,
255+
alloc_error_handler_kind: None,
256+
has_global_allocator: false,
257+
has_alloc_error_handler: false,
258+
stable_crate_ids,
259+
unused_externs: Vec::new(),
260+
}
261+
}
242262
}
243263

244264
impl<'a> CrateLoader<'a> {
245265
pub fn new(
246266
sess: &'a Session,
247-
metadata_loader: Box<MetadataLoaderDyn>,
267+
metadata_loader: &'a MetadataLoaderDyn,
248268
local_crate_name: Symbol,
269+
cstore: &'a mut CStore,
270+
definitions: ReadGuard<'a, Definitions>,
271+
used_extern_options: &'a mut FxHashSet<Symbol>,
249272
) -> Self {
250-
let mut stable_crate_ids = FxHashMap::default();
251-
stable_crate_ids.insert(sess.local_stable_crate_id(), LOCAL_CRATE);
252-
253273
CrateLoader {
254274
sess,
255275
metadata_loader,
256276
local_crate_name,
257-
cstore: CStore {
258-
// We add an empty entry for LOCAL_CRATE (which maps to zero) in
259-
// order to make array indices in `metas` match with the
260-
// corresponding `CrateNum`. This first entry will always remain
261-
// `None`.
262-
metas: IndexVec::from_elem_n(None, 1),
263-
injected_panic_runtime: None,
264-
allocator_kind: None,
265-
alloc_error_handler_kind: None,
266-
has_global_allocator: false,
267-
has_alloc_error_handler: false,
268-
stable_crate_ids,
269-
unused_externs: Vec::new(),
270-
},
271-
used_extern_options: Default::default(),
277+
cstore,
278+
used_extern_options,
279+
definitions,
272280
}
273281
}
274-
275282
pub fn cstore(&self) -> &CStore {
276283
&self.cstore
277284
}
278285

279-
pub fn into_cstore(self) -> CStore {
280-
self.cstore
281-
}
282-
283286
fn existing_match(&self, name: Symbol, hash: Option<Svh>, kind: PathKind) -> Option<CrateNum> {
284287
for (cnum, data) in self.cstore.iter_crate_data() {
285288
if data.name() != name {
@@ -989,7 +992,6 @@ impl<'a> CrateLoader<'a> {
989992
pub fn process_extern_crate(
990993
&mut self,
991994
item: &ast::Item,
992-
definitions: &Definitions,
993995
def_id: LocalDefId,
994996
) -> Option<CrateNum> {
995997
match item.kind {
@@ -1013,7 +1015,7 @@ impl<'a> CrateLoader<'a> {
10131015

10141016
let cnum = self.resolve_crate(name, item.span, dep_kind)?;
10151017

1016-
let path_len = definitions.def_path(def_id).data.len();
1018+
let path_len = self.definitions.def_path(def_id).data.len();
10171019
self.update_extern_crate(
10181020
cnum,
10191021
ExternCrate {

Diff for: ‎compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+3
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ impl CrateStore for CStore {
629629
fn as_any(&self) -> &dyn Any {
630630
self
631631
}
632+
fn untracked_as_any(&mut self) -> &mut dyn Any {
633+
self
634+
}
632635

633636
fn crate_name(&self, cnum: CrateNum) -> Symbol {
634637
self.get_crate_data(cnum).root.name

Diff for: ‎compiler/rustc_middle/src/hir/map/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_index::vec::Idx;
1414
use rustc_middle::hir::nested_filter;
1515
use rustc_span::def_id::StableCrateId;
1616
use rustc_span::symbol::{kw, sym, Ident, Symbol};
17-
use rustc_span::{Span, DUMMY_SP};
17+
use rustc_span::Span;
1818
use rustc_target::spec::abi::Abi;
1919

2020
#[inline]
@@ -1162,7 +1162,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
11621162
.filter_map(|(def_id, info)| {
11631163
let _ = info.as_owner()?;
11641164
let def_path_hash = definitions.def_path_hash(def_id);
1165-
let span = resolutions.source_span.get(def_id).unwrap_or(&DUMMY_SP);
1165+
let span = tcx.source_span(def_id);
11661166
debug_assert_eq!(span.parent(), None);
11671167
Some((def_path_hash, span))
11681168
})

Diff for: ‎compiler/rustc_middle/src/hir/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ pub fn provide(providers: &mut Providers) {
141141
providers.hir_attrs = |tcx, id| {
142142
tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)
143143
};
144-
providers.source_span =
145-
|tcx, def_id| tcx.resolutions(()).source_span.get(def_id).copied().unwrap_or(DUMMY_SP);
146144
providers.def_span = |tcx, def_id| {
147145
let def_id = def_id.expect_local();
148146
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);

Diff for: ‎compiler/rustc_middle/src/query/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ rustc_queries! {
4343
/// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
4444
/// of rustc_middle::hir::source_map.
4545
query source_span(key: LocalDefId) -> Span {
46+
// Accesses untracked data
47+
eval_always
4648
desc { "getting the source span" }
4749
}
4850

0 commit comments

Comments
 (0)
Please sign in to comment.