Skip to content

Remove the cstore reference from Session #44341

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

Closed
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
9 changes: 7 additions & 2 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use hir::map::definitions::DefPathData;
use hir::def_id::{DefIndex, DefId, CRATE_DEF_INDEX};
use hir::def::{Def, PathResolution};
use lint::builtin::PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES;
use middle::cstore::CrateStore;
use rustc_data_structures::indexed_vec::IndexVec;
use session::Session;
use util::common::FN_OUTPUT_NAME;
Expand Down Expand Up @@ -75,6 +76,8 @@ pub struct LoweringContext<'a> {
// Use to assign ids to hir nodes that do not directly correspond to an ast node
sess: &'a Session,

cstore: &'a CrateStore,

// As we walk the AST we must keep track of the current 'parent' def id (in
// the form of a DefIndex) so that if we create a new node which introduces
// a definition, then we can properly create the def id.
Expand Down Expand Up @@ -119,6 +122,7 @@ pub trait Resolver {
}

pub fn lower_crate(sess: &Session,
cstore: &CrateStore,
krate: &Crate,
resolver: &mut Resolver)
-> hir::Crate {
Expand All @@ -130,6 +134,7 @@ pub fn lower_crate(sess: &Session,
LoweringContext {
crate_root: std_inject::injected_crate_name(krate),
sess,
cstore,
parent_def: None,
resolver,
name_map: FxHashMap(),
Expand Down Expand Up @@ -535,7 +540,7 @@ impl<'a> LoweringContext<'a> {
if id.is_local() {
self.resolver.definitions().def_key(id.index)
} else {
self.sess.cstore.def_key(id)
self.cstore.def_key(id)
}
}

Expand Down Expand Up @@ -787,7 +792,7 @@ impl<'a> LoweringContext<'a> {
return n;
}
assert!(!def_id.is_local());
let n = self.sess.cstore.item_generics_cloned(def_id).regions.len();
let n = self.cstore.item_generics_cloned(def_id).regions.len();
self.type_def_lifetime_params.insert(def_id, n);
n
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
// for imported and non-imported crates
if exp_path == found_path
|| exp_abs_path == found_abs_path {
let crate_name = self.tcx.sess.cstore.crate_name(did1.krate);
let crate_name = self.tcx.cstore().crate_name(did1.krate);
err.span_note(sp, &format!("Perhaps two different versions \
of crate `{}` are being used?",
crate_name));
Expand Down
63 changes: 32 additions & 31 deletions src/librustc/middle/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use hir::def_id::CrateNum;
use session;
use session::config;
use ty::TyCtxt;
use middle::cstore::DepKind;
use middle::cstore::{CrateStore, DepKind};
use middle::cstore::LinkagePreference::{self, RequireStatic, RequireDynamic};
use util::nodemap::FxHashMap;
use rustc_back::PanicStrategy;
Expand Down Expand Up @@ -132,12 +132,12 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if let Some(v) = attempt_static(tcx) {
return v;
}
for cnum in sess.cstore.crates() {
if sess.cstore.dep_kind(cnum).macros_only() { continue }
let src = sess.cstore.used_crate_source(cnum);
for cnum in tcx.cstore().crates() {
if tcx.cstore().dep_kind(cnum).macros_only() { continue }
let src = tcx.cstore().used_crate_source(cnum);
if src.rlib.is_some() { continue }
sess.err(&format!("dependency `{}` not found in rlib format",
sess.cstore.crate_name(cnum)));
tcx.cstore().crate_name(cnum)));
}
return Vec::new();
}
Expand Down Expand Up @@ -165,24 +165,24 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// Sweep all crates for found dylibs. Add all dylibs, as well as their
// dependencies, ensuring there are no conflicts. The only valid case for a
// dependency to be relied upon twice is for both cases to rely on a dylib.
for cnum in sess.cstore.crates() {
if sess.cstore.dep_kind(cnum).macros_only() { continue }
let name = sess.cstore.crate_name(cnum);
let src = sess.cstore.used_crate_source(cnum);
for cnum in tcx.cstore().crates() {
if tcx.cstore().dep_kind(cnum).macros_only() { continue }
let name = tcx.cstore().crate_name(cnum);
let src = tcx.cstore().used_crate_source(cnum);
if src.dylib.is_some() {
info!("adding dylib: {}", name);
add_library(sess, cnum, RequireDynamic, &mut formats);
add_library(sess, tcx.cstore(), cnum, RequireDynamic, &mut formats);
let deps = tcx.dylib_dependency_formats(cnum.as_def_id());
for &(depnum, style) in deps.iter() {
info!("adding {:?}: {}", style,
sess.cstore.crate_name(depnum));
add_library(sess, depnum, style, &mut formats);
tcx.cstore().crate_name(depnum));
add_library(sess, tcx.cstore(), depnum, style, &mut formats);
}
}
}

// Collect what we've got so far in the return vector.
let last_crate = sess.cstore.crates().len();
let last_crate = tcx.cstore().crates().len();
let mut ret = (1..last_crate+1).map(|cnum| {
match formats.get(&CrateNum::new(cnum)) {
Some(&RequireDynamic) => Linkage::Dynamic,
Expand All @@ -196,14 +196,14 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
//
// If the crate hasn't been included yet and it's not actually required
// (e.g. it's an allocator) then we skip it here as well.
for cnum in sess.cstore.crates() {
let src = sess.cstore.used_crate_source(cnum);
for cnum in tcx.cstore().crates() {
let src = tcx.cstore().used_crate_source(cnum);
if src.dylib.is_none() &&
!formats.contains_key(&cnum) &&
sess.cstore.dep_kind(cnum) == DepKind::Explicit {
tcx.cstore().dep_kind(cnum) == DepKind::Explicit {
assert!(src.rlib.is_some() || src.rmeta.is_some());
info!("adding staticlib: {}", sess.cstore.crate_name(cnum));
add_library(sess, cnum, RequireStatic, &mut formats);
info!("adding staticlib: {}", tcx.cstore().crate_name(cnum));
add_library(sess, tcx.cstore(), cnum, RequireStatic, &mut formats);
ret[cnum.as_usize() - 1] = Linkage::Static;
}
}
Expand All @@ -226,7 +226,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// making sure that everything is available in the requested format.
for (cnum, kind) in ret.iter().enumerate() {
let cnum = CrateNum::new(cnum + 1);
let src = sess.cstore.used_crate_source(cnum);
let src = tcx.cstore().used_crate_source(cnum);
match *kind {
Linkage::NotLinked |
Linkage::IncludedFromDylib => {}
Expand All @@ -237,7 +237,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
Linkage::Static => "rlib",
_ => "dylib",
};
let name = sess.cstore.crate_name(cnum);
let name = tcx.cstore().crate_name(cnum);
sess.err(&format!("crate `{}` required to be available in {}, \
but it was not available in this form",
name, kind));
Expand All @@ -249,6 +249,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}

fn add_library(sess: &session::Session,
cstore: &CrateStore,
cnum: CrateNum,
link: LinkagePreference,
m: &mut FxHashMap<CrateNum, LinkagePreference>) {
Expand All @@ -263,7 +264,7 @@ fn add_library(sess: &session::Session,
// can be refined over time.
if link2 != link || link == RequireStatic {
sess.struct_err(&format!("cannot satisfy dependencies so `{}` only \
shows up once", sess.cstore.crate_name(cnum)))
shows up once", cstore.crate_name(cnum)))
.help("having upstream crates all available in one format \
will likely make this go away")
.emit();
Expand All @@ -275,16 +276,16 @@ fn add_library(sess: &session::Session,

fn attempt_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<DependencyList> {
let sess = &tcx.sess;
let crates = sess.cstore.used_crates(RequireStatic);
let crates = tcx.cstore().used_crates(RequireStatic);
if !crates.iter().by_ref().all(|&(_, ref p)| p.is_some()) {
return None
}

// All crates are available in an rlib format, so we're just going to link
// everything in explicitly so long as it's actually required.
let last_crate = sess.cstore.crates().len();
let last_crate = tcx.cstore().crates().len();
let mut ret = (1..last_crate+1).map(|cnum| {
if sess.cstore.dep_kind(CrateNum::new(cnum)) == DepKind::Explicit {
if tcx.cstore().dep_kind(CrateNum::new(cnum)) == DepKind::Explicit {
Linkage::Static
} else {
Linkage::NotLinked
Expand Down Expand Up @@ -357,13 +358,13 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {

if tcx.is_panic_runtime(cnum.as_def_id()) {
if let Some((prev, _)) = panic_runtime {
let prev_name = sess.cstore.crate_name(prev);
let cur_name = sess.cstore.crate_name(cnum);
let prev_name = tcx.cstore().crate_name(prev);
let cur_name = tcx.cstore().crate_name(cnum);
sess.err(&format!("cannot link together two \
panic runtimes: {} and {}",
prev_name, cur_name));
}
panic_runtime = Some((cnum, sess.cstore.panic_strategy(cnum)));
panic_runtime = Some((cnum, tcx.cstore().panic_strategy(cnum)));
}
}

Expand All @@ -379,7 +380,7 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
sess.err(&format!("the linked panic runtime `{}` is \
not compiled with this crate's \
panic strategy `{}`",
sess.cstore.crate_name(cnum),
tcx.cstore().crate_name(cnum),
desired_strategy.desc()));
}

Expand All @@ -395,8 +396,8 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
continue
}
let cnum = CrateNum::new(i + 1);
let found_strategy = sess.cstore.panic_strategy(cnum);
let is_compiler_builtins = sess.cstore.is_compiler_builtins(cnum);
let found_strategy = tcx.cstore().panic_strategy(cnum);
let is_compiler_builtins = tcx.cstore().is_compiler_builtins(cnum);
if is_compiler_builtins || desired_strategy == found_strategy {
continue
}
Expand All @@ -405,7 +406,7 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) {
panic strategy `{}` which is \
incompatible with this crate's \
strategy of `{}`",
sess.cstore.crate_name(cnum),
tcx.cstore().crate_name(cnum),
found_strategy.desc(),
desired_strategy.desc()));
}
Expand Down
23 changes: 12 additions & 11 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use hir::map as hir_map;
use session::Session;
use hir::def_id::DefId;
use ty;
use middle::cstore::CrateStore;
use middle::weak_lang_items;
use util::nodemap::FxHashMap;

Expand Down Expand Up @@ -115,11 +116,9 @@ impl LanguageItems {

struct LanguageItemCollector<'a, 'tcx: 'a> {
items: LanguageItems,

hir_map: &'a hir_map::Map<'tcx>,

session: &'a Session,

cstore: &'a CrateStore,
item_refs: FxHashMap<&'static str, usize>,
}

Expand Down Expand Up @@ -149,14 +148,17 @@ impl<'a, 'v, 'tcx> ItemLikeVisitor<'v> for LanguageItemCollector<'a, 'tcx> {
}

impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
pub fn new(session: &'a Session, hir_map: &'a hir_map::Map<'tcx>)
pub fn new(session: &'a Session,
cstore: &'a CrateStore,
hir_map: &'a hir_map::Map<'tcx>)
-> LanguageItemCollector<'a, 'tcx> {
let mut item_refs = FxHashMap();

$( item_refs.insert($name, $variant as usize); )*

LanguageItemCollector {
session,
cstore,
hir_map,
items: LanguageItems::new(),
item_refs,
Expand All @@ -168,7 +170,7 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
// Check for duplicates.
match self.items.items[item_index] {
Some(original_def_id) if original_def_id != item_def_id => {
let cstore = &self.session.cstore;
let cstore = self.cstore;
let name = LanguageItems::item_name(item_index);
let mut err = match self.hir_map.span_if_local(item_def_id) {
Some(span) => struct_span_err!(
Expand Down Expand Up @@ -205,10 +207,8 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
}

pub fn collect_external_language_items(&mut self) {
let cstore = &self.session.cstore;

for cnum in cstore.crates() {
for (index, item_index) in cstore.lang_items(cnum) {
for cnum in self.cstore.crates() {
for (index, item_index) in self.cstore.lang_items(cnum) {
let def_id = DefId { krate: cnum, index: index };
self.collect_item(item_index, def_id);
}
Expand All @@ -234,13 +234,14 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<Symbol> {
}

pub fn collect_language_items(session: &Session,
cstore: &CrateStore,
map: &hir_map::Map)
-> LanguageItems {
let krate: &hir::Crate = map.krate();
let mut collector = LanguageItemCollector::new(session, map);
let mut collector = LanguageItemCollector::new(session, cstore, map);
collector.collect(krate);
let LanguageItemCollector { mut items, .. } = collector;
weak_lang_items::check_crate(krate, session, &mut items);
weak_lang_items::check_crate(krate, session, cstore, &mut items);
items
}

Expand Down
13 changes: 9 additions & 4 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
//! way. Therefore we break lifetime name resolution into a separate pass.

use hir::map::Map;
use session::Session;
use hir::def::Def;
use hir::def_id::DefId;
use middle::cstore::CrateStore;
use session::Session;
use ty;

use std::cell::Cell;
Expand Down Expand Up @@ -160,6 +161,7 @@ pub struct NamedRegionMap {

struct LifetimeContext<'a, 'tcx: 'a> {
sess: &'a Session,
cstore: &'a CrateStore,
hir_map: &'a Map<'tcx>,
map: &'a mut NamedRegionMap,
scope: ScopeRef<'a>,
Expand Down Expand Up @@ -251,6 +253,7 @@ type ScopeRef<'a> = &'a Scope<'a>;
const ROOT_SCOPE: ScopeRef<'static> = &Scope::Root;

pub fn krate(sess: &Session,
cstore: &CrateStore,
hir_map: &Map)
-> Result<NamedRegionMap, ErrorReported> {
let krate = hir_map.krate();
Expand All @@ -262,6 +265,7 @@ pub fn krate(sess: &Session,
sess.track_errors(|| {
let mut visitor = LifetimeContext {
sess,
cstore,
hir_map,
map: &mut map,
scope: ROOT_SCOPE,
Expand Down Expand Up @@ -765,12 +769,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
fn with<F>(&mut self, wrap_scope: Scope, f: F) where
F: for<'b> FnOnce(ScopeRef, &mut LifetimeContext<'b, 'tcx>),
{
let LifetimeContext {sess, hir_map, ref mut map, ..} = *self;
let LifetimeContext {sess, cstore, hir_map, ref mut map, ..} = *self;
let labels_in_fn = replace(&mut self.labels_in_fn, vec![]);
let xcrate_object_lifetime_defaults =
replace(&mut self.xcrate_object_lifetime_defaults, DefIdMap());
let mut this = LifetimeContext {
sess,
cstore,
hir_map,
map: *map,
scope: &wrap_scope,
Expand Down Expand Up @@ -932,7 +937,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let def_key = if def_id.is_local() {
this.hir_map.def_key(def_id)
} else {
this.sess.cstore.def_key(def_id)
this.cstore.def_key(def_id)
};
DefId {
krate: def_id.krate,
Expand Down Expand Up @@ -976,7 +981,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let unsubst = if let Some(id) = self.hir_map.as_local_node_id(def_id) {
&map.object_lifetime_defaults[&id]
} else {
let cstore = &self.sess.cstore;
let cstore = self.cstore;
self.xcrate_object_lifetime_defaults.entry(def_id).or_insert_with(|| {
cstore.item_generics_cloned(def_id).types.into_iter().map(|def| {
def.object_lifetime_default
Expand Down
Loading