Skip to content

Commit

Permalink
rustc_metadata: Remove resolutions for extern crate items from CStore
Browse files Browse the repository at this point in the history
Use a more traditional scheme with providing them as a resolver output
  • Loading branch information
petrochenkov committed Oct 14, 2019
1 parent e843d86 commit f5baad2
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/librustc/middle/cstore.rs
Expand Up @@ -214,7 +214,6 @@ pub trait CrateStore {
fn crate_is_private_dep_untracked(&self, cnum: CrateNum) -> bool;
fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator;
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh;
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics;
fn postorder_cnums_untracked(&self) -> Vec<CrateNum>;

Expand Down
8 changes: 6 additions & 2 deletions src/librustc/ty/context.rs
Expand Up @@ -43,7 +43,7 @@ use crate::ty::subst::{UserSubsts, GenericArgKind};
use crate::ty::{BoundVar, BindingMode};
use crate::ty::CanonicalPolyFnSig;
use crate::util::common::ErrorReported;
use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet};
use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet, NodeMap};
use crate::util::nodemap::{FxHashMap, FxHashSet};
use crate::util::profiling::SelfProfilerRef;

Expand Down Expand Up @@ -1051,6 +1051,9 @@ pub struct GlobalCtxt<'tcx> {
/// Common consts, pre-interned for your convenience.
pub consts: CommonConsts<'tcx>,

/// Resolutions of `extern crate` items produced by resolver.
extern_crate_map: NodeMap<CrateNum>,

/// Map indicating what traits are in scope for places where this
/// is relevant; generated by resolve.
trait_map: FxHashMap<DefIndex,
Expand Down Expand Up @@ -1274,6 +1277,7 @@ impl<'tcx> TyCtxt<'tcx> {
types: common_types,
lifetimes: common_lifetimes,
consts: common_consts,
extern_crate_map: resolutions.extern_crate_map,
trait_map,
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
let exports: Vec<_> = v.into_iter().map(|e| {
Expand Down Expand Up @@ -2951,7 +2955,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
};
providers.extern_mod_stmt_cnum = |tcx, id| {
let id = tcx.hir().as_local_node_id(id).unwrap();
tcx.cstore.extern_mod_stmt_cnum_untracked(id)
tcx.extern_crate_map.get(&id).cloned()
};
providers.all_crate_nums = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/ty/mod.rs
Expand Up @@ -28,7 +28,7 @@ use crate::ty::subst::{Subst, InternalSubsts, SubstsRef};
use crate::ty::util::{IntTypeExt, Discr};
use crate::ty::walk::TypeWalker;
use crate::util::captures::Captures;
use crate::util::nodemap::{NodeSet, DefIdMap, FxHashMap};
use crate::util::nodemap::{NodeMap, NodeSet, DefIdMap, FxHashMap};
use arena::SyncDroplessArena;
use crate::session::DataTypeKind;

Expand Down Expand Up @@ -121,6 +121,7 @@ mod sty;

#[derive(Clone)]
pub struct Resolutions {
pub extern_crate_map: NodeMap<CrateNum>,
pub trait_map: TraitMap,
pub maybe_unused_trait_imports: NodeSet,
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_interface/passes.rs
Expand Up @@ -169,6 +169,7 @@ impl ExpansionResult {
ExpansionResult {
defs: Steal::new(resolver.definitions),
resolutions: Steal::new(Resolutions {
extern_crate_map: resolver.extern_crate_map,
export_map: resolver.export_map,
trait_map: resolver.trait_map,
glob_map: resolver.glob_map,
Expand All @@ -187,6 +188,7 @@ impl ExpansionResult {
ExpansionResult {
defs: Steal::new(resolver.definitions.clone()),
resolutions: Steal::new(Resolutions {
extern_crate_map: resolver.extern_crate_map.clone(),
export_map: resolver.export_map.clone(),
trait_map: resolver.trait_map.clone(),
glob_map: resolver.glob_map.clone(),
Expand Down
1 change: 0 additions & 1 deletion src/librustc_metadata/creader.rs
Expand Up @@ -1004,7 +1004,6 @@ impl<'a> CrateLoader<'a> {
},
&mut FxHashSet::default(),
);
self.cstore.add_extern_mod_stmt_cnum(item.id, cnum);
cnum
}
_ => bug!(),
Expand Down
13 changes: 1 addition & 12 deletions src/librustc_metadata/cstore.rs
Expand Up @@ -8,7 +8,7 @@ use rustc::hir::map::definitions::DefPathTable;
use rustc::middle::cstore::{CrateSource, DepKind, ExternCrate, MetadataLoader};
use rustc::mir::interpret::AllocDecodingState;
use rustc_index::vec::IndexVec;
use rustc::util::nodemap::{FxHashMap, NodeMap};
use rustc::util::nodemap::FxHashMap;
use rustc_data_structures::sync::{Lrc, RwLock, Lock, MetadataRef, AtomicCell};
use syntax::ast;
use syntax::ext::base::SyntaxExtension;
Expand Down Expand Up @@ -96,8 +96,6 @@ pub struct CrateMetadata {

pub struct CStore {
metas: RwLock<IndexVec<CrateNum, Option<Lrc<CrateMetadata>>>>,
/// Map from NodeId's of local extern crate statements to crate numbers
extern_mod_crate_map: Lock<NodeMap<CrateNum>>,
crate metadata_loader: Box<dyn MetadataLoader + Sync>,
}

Expand All @@ -114,7 +112,6 @@ impl CStore {
// corresponding `CrateNum`. This first entry will always remain
// `None`.
metas: RwLock::new(IndexVec::from_elem_n(None, 1)),
extern_mod_crate_map: Default::default(),
metadata_loader,
}
}
Expand Down Expand Up @@ -178,12 +175,4 @@ impl CStore {
}
return ordering
}

crate fn add_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId, cnum: CrateNum) {
self.extern_mod_crate_map.borrow_mut().insert(emod_id, cnum);
}

crate fn do_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> {
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
}
}
5 changes: 0 additions & 5 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -538,11 +538,6 @@ impl CrateStore for cstore::CStore {
result
}

fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum>
{
self.do_extern_mod_stmt_cnum(emod_id)
}

fn postorder_cnums_untracked(&self) -> Vec<CrateNum> {
self.do_postorder_cnums_untracked()
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -617,6 +617,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let crate_id = self.r.crate_loader.process_extern_crate(
item, &self.r.definitions
);
self.r.extern_crate_map.insert(item.id, crate_id);
self.r.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX })
};

Expand Down
5 changes: 4 additions & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -26,7 +26,7 @@ use rustc::session::Session;
use rustc::lint;
use rustc::hir::def::{self, DefKind, PartialRes, CtorKind, CtorOf, NonMacroAttrKind, ExportMap};
use rustc::hir::def::Namespace::*;
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, CrateNum, DefId};
use rustc::hir::{TraitMap, GlobMap};
use rustc::ty::{self, DefIdTree};
use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap};
Expand Down Expand Up @@ -855,6 +855,8 @@ pub struct Resolver<'a> {
/// Resolutions for labels (node IDs of their corresponding blocks or loops).
label_res_map: NodeMap<NodeId>,

/// `CrateNum` resolutions of `extern crate` items.
pub extern_crate_map: NodeMap<CrateNum>,
pub export_map: ExportMap<NodeId>,
pub trait_map: TraitMap,

Expand Down Expand Up @@ -1155,6 +1157,7 @@ impl<'a> Resolver<'a> {
partial_res_map: Default::default(),
import_res_map: Default::default(),
label_res_map: Default::default(),
extern_crate_map: Default::default(),
export_map: FxHashMap::default(),
trait_map: Default::default(),
empty_module,
Expand Down

0 comments on commit f5baad2

Please sign in to comment.