Skip to content
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

Group some fields in a common struct so we only pass one reference instead of three #105357

Merged
merged 4 commits into from
Dec 10, 2022
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4342,6 +4342,7 @@ dependencies = [
"rustc_feature",
"rustc_fs_util",
"rustc_hir",
"rustc_index",
"rustc_lint_defs",
"rustc_macros",
"rustc_serialize",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,9 @@ pub fn create_global_ctxt<'tcx>(
});

let ty::ResolverOutputs {
definitions,
global_ctxt: untracked_resolutions,
ast_lowering: untracked_resolver_for_lowering,
untracked,
} = resolver_outputs;

let gcx = sess.time("setup_global_ctxt", || {
Expand All @@ -817,8 +817,8 @@ pub fn create_global_ctxt<'tcx>(
lint_store,
arena,
hir_arena,
definitions,
untracked_resolutions,
untracked,
krate,
dep_graph,
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),
Expand Down
62 changes: 32 additions & 30 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_ast::expand::allocator::AllocatorKind;
use rustc_ast::{self as ast, *};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::sync::{Lrc, ReadGuard};
use rustc_expand::base::SyntaxExtension;
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, LOCAL_CRATE};
use rustc_hir::definitions::Definitions;
Expand Down Expand Up @@ -68,11 +68,12 @@ impl std::fmt::Debug for CStore {
pub struct CrateLoader<'a> {
// Immutable configuration.
sess: &'a Session,
metadata_loader: Box<MetadataLoaderDyn>,
metadata_loader: &'a MetadataLoaderDyn,
definitions: ReadGuard<'a, Definitions>,
local_crate_name: Symbol,
// Mutable output.
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
cstore: CStore,
used_extern_options: FxHashSet<Symbol>,
cstore: &'a mut CStore,
used_extern_options: &'a mut FxHashSet<Symbol>,
}

pub enum LoadedMacro {
Expand Down Expand Up @@ -239,47 +240,49 @@ impl CStore {
);
}
}

pub fn new(sess: &Session) -> CStore {
let mut stable_crate_ids = FxHashMap::default();
stable_crate_ids.insert(sess.local_stable_crate_id(), LOCAL_CRATE);
CStore {
// We add an empty entry for LOCAL_CRATE (which maps to zero) in
// order to make array indices in `metas` match with the
// corresponding `CrateNum`. This first entry will always remain
// `None`.
metas: IndexVec::from_elem_n(None, 1),
injected_panic_runtime: None,
allocator_kind: None,
alloc_error_handler_kind: None,
has_global_allocator: false,
has_alloc_error_handler: false,
stable_crate_ids,
unused_externs: Vec::new(),
}
}
}

impl<'a> CrateLoader<'a> {
pub fn new(
sess: &'a Session,
metadata_loader: Box<MetadataLoaderDyn>,
metadata_loader: &'a MetadataLoaderDyn,
local_crate_name: Symbol,
cstore: &'a mut CStore,
definitions: ReadGuard<'a, Definitions>,
used_extern_options: &'a mut FxHashSet<Symbol>,
) -> Self {
let mut stable_crate_ids = FxHashMap::default();
stable_crate_ids.insert(sess.local_stable_crate_id(), LOCAL_CRATE);

CrateLoader {
sess,
metadata_loader,
local_crate_name,
cstore: CStore {
// We add an empty entry for LOCAL_CRATE (which maps to zero) in
// order to make array indices in `metas` match with the
// corresponding `CrateNum`. This first entry will always remain
// `None`.
metas: IndexVec::from_elem_n(None, 1),
injected_panic_runtime: None,
allocator_kind: None,
alloc_error_handler_kind: None,
has_global_allocator: false,
has_alloc_error_handler: false,
stable_crate_ids,
unused_externs: Vec::new(),
},
used_extern_options: Default::default(),
cstore,
used_extern_options,
definitions,
}
}

pub fn cstore(&self) -> &CStore {
&self.cstore
}

pub fn into_cstore(self) -> CStore {
self.cstore
}

fn existing_match(&self, name: Symbol, hash: Option<Svh>, kind: PathKind) -> Option<CrateNum> {
for (cnum, data) in self.cstore.iter_crate_data() {
if data.name() != name {
Expand Down Expand Up @@ -989,7 +992,6 @@ impl<'a> CrateLoader<'a> {
pub fn process_extern_crate(
&mut self,
item: &ast::Item,
definitions: &Definitions,
def_id: LocalDefId,
) -> Option<CrateNum> {
match item.kind {
Expand All @@ -1013,7 +1015,7 @@ impl<'a> CrateLoader<'a> {

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

let path_len = definitions.def_path(def_id).data.len();
let path_len = self.definitions.def_path(def_id).data.len();
self.update_extern_crate(
cnum,
ExternCrate {
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,9 @@ impl CrateStore for CStore {
fn as_any(&self) -> &dyn Any {
self
}
fn untracked_as_any(&mut self) -> &mut dyn Any {
self
}

fn crate_name(&self, cnum: CrateNum) -> Symbol {
self.get_crate_data(cnum).root.name
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_index::vec::Idx;
use rustc_middle::hir::nested_filter;
use rustc_span::def_id::StableCrateId;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
use rustc_span::Span;
use rustc_target::spec::abi::Abi;

#[inline]
Expand Down Expand Up @@ -1162,7 +1162,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
.filter_map(|(def_id, info)| {
let _ = info.as_owner()?;
let def_path_hash = definitions.def_path_hash(def_id);
let span = resolutions.source_span.get(def_id).unwrap_or(&DUMMY_SP);
let span = tcx.source_span(def_id);
debug_assert_eq!(span.parent(), None);
Some((def_path_hash, span))
})
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ pub fn provide(providers: &mut Providers) {
providers.hir_attrs = |tcx, id| {
tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)
};
providers.source_span =
|tcx, def_id| tcx.resolutions(()).source_span.get(def_id).copied().unwrap_or(DUMMY_SP);
providers.def_span = |tcx, def_id| {
let def_id = def_id.expect_local();
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ rustc_queries! {
/// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
/// of rustc_middle::hir::source_map.
query source_span(key: LocalDefId) -> Span {
// Accesses untracked data
eval_always
desc { "getting the source span" }
}

Expand Down
Loading