incr.comp.: Always require Session when decoding Spans (as to avoid silently wrong results).
This commit is contained in:
parent
a174951272
commit
102eaa5c10
7 changed files with 71 additions and 57 deletions
|
|
@ -838,7 +838,10 @@ impl<'a> LoweringContext<'a> {
|
|||
return n;
|
||||
}
|
||||
assert!(!def_id.is_local());
|
||||
let n = self.cstore.item_generics_cloned_untracked(def_id).regions.len();
|
||||
let n = self.cstore
|
||||
.item_generics_cloned_untracked(def_id, self.sess)
|
||||
.regions
|
||||
.len();
|
||||
self.type_def_lifetime_params.insert(def_id, n);
|
||||
n
|
||||
});
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ pub trait CrateStore {
|
|||
fn item_children_untracked(&self, did: DefId, sess: &Session) -> Vec<def::Export>;
|
||||
fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro;
|
||||
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
|
||||
fn item_generics_cloned_untracked(&self, def: DefId) -> ty::Generics;
|
||||
fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics;
|
||||
fn associated_item_cloned_untracked(&self, def: DefId) -> ty::AssociatedItem;
|
||||
fn postorder_cnums_untracked(&self) -> Vec<CrateNum>;
|
||||
|
||||
|
|
@ -327,7 +327,7 @@ impl CrateStore for DummyCrateStore {
|
|||
{ bug!("crate_data_as_rc_any") }
|
||||
// item info
|
||||
fn visibility_untracked(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
|
||||
fn item_generics_cloned_untracked(&self, def: DefId) -> ty::Generics
|
||||
fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics
|
||||
{ bug!("item_generics_cloned") }
|
||||
|
||||
// trait/impl-item info
|
||||
|
|
|
|||
|
|
@ -1001,8 +1001,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
&map.object_lifetime_defaults[&id]
|
||||
} else {
|
||||
let cstore = self.cstore;
|
||||
let sess = self.sess;
|
||||
self.xcrate_object_lifetime_defaults.entry(def_id).or_insert_with(|| {
|
||||
cstore.item_generics_cloned_untracked(def_id).types.into_iter().map(|def| {
|
||||
cstore.item_generics_cloned_untracked(def_id, sess)
|
||||
.types
|
||||
.into_iter()
|
||||
.map(|def| {
|
||||
def.object_lifetime_default
|
||||
}).collect()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -685,14 +685,15 @@ impl<'a> CrateLoader<'a> {
|
|||
let mut needs_panic_runtime = attr::contains_name(&krate.attrs,
|
||||
"needs_panic_runtime");
|
||||
|
||||
let sess = self.sess;
|
||||
self.cstore.iter_crate_data(|cnum, data| {
|
||||
needs_panic_runtime = needs_panic_runtime ||
|
||||
data.needs_panic_runtime();
|
||||
if data.is_panic_runtime() {
|
||||
data.needs_panic_runtime(sess);
|
||||
if data.is_panic_runtime(sess) {
|
||||
// Inject a dependency from all #![needs_panic_runtime] to this
|
||||
// #![panic_runtime] crate.
|
||||
self.inject_dependency_if(cnum, "a panic runtime",
|
||||
&|data| data.needs_panic_runtime());
|
||||
&|data| data.needs_panic_runtime(sess));
|
||||
runtime_found = runtime_found || data.dep_kind.get() == DepKind::Explicit;
|
||||
}
|
||||
});
|
||||
|
|
@ -728,7 +729,7 @@ impl<'a> CrateLoader<'a> {
|
|||
|
||||
// Sanity check the loaded crate to ensure it is indeed a panic runtime
|
||||
// and the panic strategy is indeed what we thought it was.
|
||||
if !data.is_panic_runtime() {
|
||||
if !data.is_panic_runtime(self.sess) {
|
||||
self.sess.err(&format!("the crate `{}` is not a panic runtime",
|
||||
name));
|
||||
}
|
||||
|
|
@ -740,7 +741,7 @@ impl<'a> CrateLoader<'a> {
|
|||
|
||||
self.sess.injected_panic_runtime.set(Some(cnum));
|
||||
self.inject_dependency_if(cnum, "a panic runtime",
|
||||
&|data| data.needs_panic_runtime());
|
||||
&|data| data.needs_panic_runtime(self.sess));
|
||||
}
|
||||
|
||||
fn inject_sanitizer_runtime(&mut self) {
|
||||
|
|
@ -835,7 +836,7 @@ impl<'a> CrateLoader<'a> {
|
|||
PathKind::Crate, dep_kind);
|
||||
|
||||
// Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
|
||||
if !data.is_sanitizer_runtime() {
|
||||
if !data.is_sanitizer_runtime(self.sess) {
|
||||
self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
|
||||
name));
|
||||
}
|
||||
|
|
@ -856,7 +857,7 @@ impl<'a> CrateLoader<'a> {
|
|||
PathKind::Crate, dep_kind);
|
||||
|
||||
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
|
||||
if !data.is_profiler_runtime() {
|
||||
if !data.is_profiler_runtime(self.sess) {
|
||||
self.sess.err(&format!("the crate `profiler_builtins` is not \
|
||||
a profiler runtime"));
|
||||
}
|
||||
|
|
@ -875,7 +876,7 @@ impl<'a> CrateLoader<'a> {
|
|||
let mut needs_allocator = attr::contains_name(&krate.attrs,
|
||||
"needs_allocator");
|
||||
self.cstore.iter_crate_data(|_, data| {
|
||||
needs_allocator = needs_allocator || data.needs_allocator();
|
||||
needs_allocator = needs_allocator || data.needs_allocator(self.sess);
|
||||
});
|
||||
if !needs_allocator {
|
||||
return
|
||||
|
|
@ -997,7 +998,7 @@ impl<'a> CrateLoader<'a> {
|
|||
Some(data) => {
|
||||
// We have an allocator. We detect separately what kind it is, to allow for some
|
||||
// flexibility in misconfiguration.
|
||||
let attrs = data.get_item_attrs(CRATE_DEF_INDEX);
|
||||
let attrs = data.get_item_attrs(CRATE_DEF_INDEX, self.sess);
|
||||
let kind_interned = attr::first_attr_value_str_by_name(&attrs, "rustc_alloc_kind")
|
||||
.map(Symbol::as_str);
|
||||
let kind_str = kind_interned
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use rustc::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex};
|
|||
use rustc::hir::map::definitions::DefPathTable;
|
||||
use rustc::hir::svh::Svh;
|
||||
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
|
||||
use rustc::session::CrateDisambiguator;
|
||||
use rustc::session::{Session, CrateDisambiguator};
|
||||
use rustc_back::PanicStrategy;
|
||||
use rustc_data_structures::indexed_vec::IndexVec;
|
||||
use rustc::util::nodemap::{FxHashMap, FxHashSet, NodeMap};
|
||||
|
|
@ -176,8 +176,8 @@ impl CrateMetadata {
|
|||
self.root.disambiguator
|
||||
}
|
||||
|
||||
pub fn needs_allocator(&self) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
|
||||
pub fn needs_allocator(&self, sess: &Session) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
|
||||
attr::contains_name(&attrs, "needs_allocator")
|
||||
}
|
||||
|
||||
|
|
@ -189,43 +189,43 @@ impl CrateMetadata {
|
|||
self.root.has_default_lib_allocator.clone()
|
||||
}
|
||||
|
||||
pub fn is_panic_runtime(&self) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
|
||||
pub fn is_panic_runtime(&self, sess: &Session) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
|
||||
attr::contains_name(&attrs, "panic_runtime")
|
||||
}
|
||||
|
||||
pub fn needs_panic_runtime(&self) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
|
||||
pub fn needs_panic_runtime(&self, sess: &Session) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
|
||||
attr::contains_name(&attrs, "needs_panic_runtime")
|
||||
}
|
||||
|
||||
pub fn is_compiler_builtins(&self) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
|
||||
pub fn is_compiler_builtins(&self, sess: &Session) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
|
||||
attr::contains_name(&attrs, "compiler_builtins")
|
||||
}
|
||||
|
||||
pub fn is_sanitizer_runtime(&self) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
|
||||
pub fn is_sanitizer_runtime(&self, sess: &Session) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
|
||||
attr::contains_name(&attrs, "sanitizer_runtime")
|
||||
}
|
||||
|
||||
pub fn is_profiler_runtime(&self) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
|
||||
pub fn is_profiler_runtime(&self, sess: &Session) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
|
||||
attr::contains_name(&attrs, "profiler_runtime")
|
||||
}
|
||||
|
||||
pub fn is_no_builtins(&self) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
|
||||
pub fn is_no_builtins(&self, sess: &Session) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
|
||||
attr::contains_name(&attrs, "no_builtins")
|
||||
}
|
||||
|
||||
pub fn has_copy_closures(&self) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
|
||||
pub fn has_copy_closures(&self, sess: &Session) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
|
||||
attr::contains_feature_attr(&attrs, "copy_closures")
|
||||
}
|
||||
|
||||
pub fn has_clone_closures(&self) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
|
||||
pub fn has_clone_closures(&self, sess: &Session) -> bool {
|
||||
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, sess);
|
||||
attr::contains_feature_attr(&attrs, "clone_closures")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,11 +99,13 @@ impl IntoArgs for (CrateNum, DefId) {
|
|||
|
||||
provide! { <'tcx> tcx, def_id, other, cdata,
|
||||
type_of => { cdata.get_type(def_id.index, tcx) }
|
||||
generics_of => { tcx.alloc_generics(cdata.get_generics(def_id.index)) }
|
||||
generics_of => {
|
||||
tcx.alloc_generics(cdata.get_generics(def_id.index, tcx.sess))
|
||||
}
|
||||
predicates_of => { cdata.get_predicates(def_id.index, tcx) }
|
||||
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
|
||||
trait_def => {
|
||||
tcx.alloc_trait_def(cdata.get_trait_def(def_id.index))
|
||||
tcx.alloc_trait_def(cdata.get_trait_def(def_id.index, tcx.sess))
|
||||
}
|
||||
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
|
||||
adt_destructor => {
|
||||
|
|
@ -153,7 +155,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
|||
lookup_deprecation_entry => {
|
||||
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
|
||||
}
|
||||
item_attrs => { cdata.get_item_attrs(def_id.index) }
|
||||
item_attrs => { cdata.get_item_attrs(def_id.index, tcx.sess) }
|
||||
// FIXME(#38501) We've skipped a `read` on the `HirBody` of
|
||||
// a `fn` when encoding, so the dep-tracking wouldn't work.
|
||||
// This is only used by rustdoc anyway, which shouldn't have
|
||||
|
|
@ -171,14 +173,14 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
|||
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
|
||||
|
||||
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats()) }
|
||||
is_panic_runtime => { cdata.is_panic_runtime() }
|
||||
is_compiler_builtins => { cdata.is_compiler_builtins() }
|
||||
is_panic_runtime => { cdata.is_panic_runtime(tcx.sess) }
|
||||
is_compiler_builtins => { cdata.is_compiler_builtins(tcx.sess) }
|
||||
has_global_allocator => { cdata.has_global_allocator() }
|
||||
is_sanitizer_runtime => { cdata.is_sanitizer_runtime() }
|
||||
is_profiler_runtime => { cdata.is_profiler_runtime() }
|
||||
is_sanitizer_runtime => { cdata.is_sanitizer_runtime(tcx.sess) }
|
||||
is_profiler_runtime => { cdata.is_profiler_runtime(tcx.sess) }
|
||||
panic_strategy => { cdata.panic_strategy() }
|
||||
extern_crate => { Rc::new(cdata.extern_crate.get()) }
|
||||
is_no_builtins => { cdata.is_no_builtins() }
|
||||
is_no_builtins => { cdata.is_no_builtins(tcx.sess) }
|
||||
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
|
||||
exported_symbol_ids => { Rc::new(cdata.get_exported_symbols()) }
|
||||
native_libraries => { Rc::new(cdata.get_native_libraries()) }
|
||||
|
|
@ -237,8 +239,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
|||
|
||||
used_crate_source => { Rc::new(cdata.source.clone()) }
|
||||
|
||||
has_copy_closures => { cdata.has_copy_closures() }
|
||||
has_clone_closures => { cdata.has_clone_closures() }
|
||||
has_copy_closures => { cdata.has_copy_closures(tcx.sess) }
|
||||
has_clone_closures => { cdata.has_clone_closures(tcx.sess) }
|
||||
}
|
||||
|
||||
pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
|
||||
|
|
@ -358,8 +360,8 @@ impl CrateStore for cstore::CStore {
|
|||
self.get_crate_data(def.krate).get_visibility(def.index)
|
||||
}
|
||||
|
||||
fn item_generics_cloned_untracked(&self, def: DefId) -> ty::Generics {
|
||||
self.get_crate_data(def.krate).get_generics(def.index)
|
||||
fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics {
|
||||
self.get_crate_data(def.krate).get_generics(def.index, sess)
|
||||
}
|
||||
|
||||
fn associated_item_cloned_untracked(&self, def: DefId) -> ty::AssociatedItem
|
||||
|
|
@ -454,7 +456,7 @@ impl CrateStore for cstore::CStore {
|
|||
let body = filemap_to_stream(&sess.parse_sess, filemap, None);
|
||||
|
||||
// Mark the attrs as used
|
||||
let attrs = data.get_item_attrs(id.index);
|
||||
let attrs = data.get_item_attrs(id.index, sess);
|
||||
for attr in attrs.iter() {
|
||||
attr::mark_used(attr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
|
|||
let sess = if let Some(sess) = self.sess {
|
||||
sess
|
||||
} else {
|
||||
return Ok(Span::new(lo, hi, NO_EXPANSION));
|
||||
bug!("Cannot decode Span without Session.")
|
||||
};
|
||||
|
||||
let (lo, hi) = if lo > hi {
|
||||
|
|
@ -313,7 +313,8 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
|
|||
// originate from the same filemap.
|
||||
let last_filemap = &imported_filemaps[self.last_filemap_index];
|
||||
|
||||
if lo >= last_filemap.original_start_pos && lo <= last_filemap.original_end_pos &&
|
||||
if lo >= last_filemap.original_start_pos &&
|
||||
lo <= last_filemap.original_end_pos &&
|
||||
hi >= last_filemap.original_start_pos &&
|
||||
hi <= last_filemap.original_end_pos {
|
||||
last_filemap
|
||||
|
|
@ -335,8 +336,8 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
|
|||
}
|
||||
};
|
||||
|
||||
let lo = (lo - filemap.original_start_pos) + filemap.translated_filemap.start_pos;
|
||||
let hi = (hi - filemap.original_start_pos) + filemap.translated_filemap.start_pos;
|
||||
let lo = (lo + filemap.translated_filemap.start_pos) - filemap.original_start_pos;
|
||||
let hi = (hi + filemap.translated_filemap.start_pos) - filemap.original_start_pos;
|
||||
|
||||
Ok(Span::new(lo, hi, NO_EXPANSION))
|
||||
}
|
||||
|
|
@ -521,9 +522,9 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_trait_def(&self, item_id: DefIndex) -> ty::TraitDef {
|
||||
pub fn get_trait_def(&self, item_id: DefIndex, sess: &Session) -> ty::TraitDef {
|
||||
let data = match self.entry(item_id).kind {
|
||||
EntryKind::Trait(data) => data.decode(self),
|
||||
EntryKind::Trait(data) => data.decode((self, sess)),
|
||||
_ => bug!(),
|
||||
};
|
||||
|
||||
|
|
@ -607,8 +608,11 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_generics(&self, item_id: DefIndex) -> ty::Generics {
|
||||
self.entry(item_id).generics.unwrap().decode(self)
|
||||
pub fn get_generics(&self,
|
||||
item_id: DefIndex,
|
||||
sess: &Session)
|
||||
-> ty::Generics {
|
||||
self.entry(item_id).generics.unwrap().decode((self, sess))
|
||||
}
|
||||
|
||||
pub fn get_type(&self, id: DefIndex, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
|
||||
|
|
@ -908,7 +912,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_item_attrs(&self, node_id: DefIndex) -> Rc<[ast::Attribute]> {
|
||||
pub fn get_item_attrs(&self, node_id: DefIndex, sess: &Session) -> Rc<[ast::Attribute]> {
|
||||
let (node_as, node_index) =
|
||||
(node_id.address_space().index(), node_id.as_array_index());
|
||||
if self.is_proc_macro(node_id) {
|
||||
|
|
@ -928,7 +932,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
if def_key.disambiguated_data.data == DefPathData::StructCtor {
|
||||
item = self.entry(def_key.parent.unwrap());
|
||||
}
|
||||
let result: Rc<[ast::Attribute]> = Rc::from(self.get_attributes(&item));
|
||||
let result: Rc<[ast::Attribute]> = Rc::from(self.get_attributes(&item, sess));
|
||||
let vec_ = &mut self.attribute_cache.borrow_mut()[node_as];
|
||||
if vec_.len() < node_index + 1 {
|
||||
vec_.resize(node_index + 1, None);
|
||||
|
|
@ -945,9 +949,9 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn get_attributes(&self, item: &Entry<'tcx>) -> Vec<ast::Attribute> {
|
||||
fn get_attributes(&self, item: &Entry<'tcx>, sess: &Session) -> Vec<ast::Attribute> {
|
||||
item.attributes
|
||||
.decode(self)
|
||||
.decode((self, sess))
|
||||
.map(|mut attr| {
|
||||
// Need new unique IDs: old thread-local IDs won't map to new threads.
|
||||
attr.id = attr::mk_attr_id();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue