Skip to content

Commit f6068ea

Browse files
committed
fix ICEs with RUST_LOG
1 parent 4fff195 commit f6068ea

File tree

8 files changed

+66
-32
lines changed

8 files changed

+66
-32
lines changed

src/librustc/middle/cstore.rs

+2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ pub trait CrateStore<'tcx> {
163163
-> ty::TypeScheme<'tcx>;
164164
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>>;
165165
fn item_name(&self, def: DefId) -> ast::Name;
166+
fn opt_item_name(&self, def: DefId) -> Option<ast::Name>;
166167
fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
167168
-> ty::GenericPredicates<'tcx>;
168169
fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
@@ -345,6 +346,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
345346
bug!("visible_parent_map")
346347
}
347348
fn item_name(&self, def: DefId) -> ast::Name { bug!("item_name") }
349+
fn opt_item_name(&self, def: DefId) -> Option<ast::Name> { bug!("opt_item_name") }
348350
fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
349351
-> ty::GenericPredicates<'tcx> { bug!("item_predicates") }
350352
fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)

src/librustc/mir/repr.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
942942
ppaux::parameterized(fmt, substs, variant_def.did,
943943
ppaux::Ns::Value, &[],
944944
|tcx| {
945-
tcx.lookup_item_type(variant_def.did).generics
945+
Some(tcx.lookup_item_type(variant_def.did).generics)
946946
})?;
947947

948948
match variant_def.kind() {
@@ -1034,8 +1034,9 @@ impl<'tcx> Debug for Literal<'tcx> {
10341034
use self::Literal::*;
10351035
match *self {
10361036
Item { def_id, substs } => {
1037-
ppaux::parameterized(fmt, substs, def_id, ppaux::Ns::Value, &[],
1038-
|tcx| tcx.lookup_item_type(def_id).generics)
1037+
ppaux::parameterized(
1038+
fmt, substs, def_id, ppaux::Ns::Value, &[],
1039+
|tcx| Some(tcx.lookup_item_type(def_id).generics))
10391040
}
10401041
Value { ref value } => {
10411042
write!(fmt, "const ")?;

src/librustc/ty/item_path.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use middle::cstore::LOCAL_CRATE;
1313
use hir::def_id::{DefId, CRATE_DEF_INDEX};
1414
use ty::{self, Ty, TyCtxt};
1515
use syntax::ast;
16+
use syntax::parse::token;
1617

1718
use std::cell::Cell;
1819

@@ -138,7 +139,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
138139
}
139140
}
140141

141-
cur_path.push(self.sess.cstore.item_name(cur_def));
142+
cur_path.push(self.sess.cstore.opt_item_name(cur_def).unwrap_or_else(||
143+
token::intern("<unnamed>")));
142144
match visible_parent_map.get(&cur_def) {
143145
Some(&def) => cur_def = def,
144146
None => return false,

src/librustc/ty/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -2480,6 +2480,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24802480
|| self.sess.cstore.item_type(self.global_tcx(), did))
24812481
}
24822482

2483+
pub fn opt_lookup_item_type(self, did: DefId) -> Option<TypeScheme<'gcx>> {
2484+
if let Some(scheme) = self.tcache.borrow_mut().get(&did) {
2485+
return Some(scheme.clone());
2486+
}
2487+
2488+
if did.krate == LOCAL_CRATE {
2489+
None
2490+
} else {
2491+
Some(self.sess.cstore.item_type(self.global_tcx(), did))
2492+
}
2493+
}
2494+
24832495
/// Given the did of a trait, returns its canonical trait ref.
24842496
pub fn lookup_trait_def(self, did: DefId) -> &'gcx TraitDef<'gcx> {
24852497
lookup_locally_or_in_crate_store(

src/librustc/util/ppaux.rs

+23-21
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,12 @@ pub enum Ns {
6969
Value
7070
}
7171

72-
fn number_of_supplied_defaults<'a, 'gcx, 'tcx, GG>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
73-
substs: &subst::Substs,
74-
space: subst::ParamSpace,
75-
get_generics: GG)
76-
-> usize
77-
where GG: FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> ty::Generics<'tcx>
72+
fn number_of_supplied_defaults<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
73+
substs: &subst::Substs,
74+
space: subst::ParamSpace,
75+
generics: ty::Generics<'tcx>)
76+
-> usize
7877
{
79-
let generics = get_generics(tcx);
80-
8178
let has_self = substs.self_ty().is_some();
8279
let ty_params = generics.types.get_slice(space);
8380
let tps = substs.types.get_slice(space);
@@ -115,7 +112,8 @@ pub fn parameterized<GG>(f: &mut fmt::Formatter,
115112
projections: &[ty::ProjectionPredicate],
116113
get_generics: GG)
117114
-> fmt::Result
118-
where GG: for<'a, 'gcx, 'tcx> FnOnce(TyCtxt<'a, 'gcx, 'tcx>) -> ty::Generics<'tcx>
115+
where GG: for<'a, 'gcx, 'tcx> FnOnce(TyCtxt<'a, 'gcx, 'tcx>)
116+
-> Option<ty::Generics<'tcx>>
119117
{
120118
if let (Ns::Value, Some(self_ty)) = (ns, substs.self_ty()) {
121119
write!(f, "<{} as ", self_ty)?;
@@ -176,13 +174,12 @@ pub fn parameterized<GG>(f: &mut fmt::Formatter,
176174
let num_supplied_defaults = if verbose {
177175
0
178176
} else {
179-
// It is important to execute this conditionally, only if -Z
180-
// verbose is false. Otherwise, debug logs can sometimes cause
181-
// ICEs trying to fetch the generics early in the pipeline. This
182-
// is kind of a hacky workaround in that -Z verbose is required to
183-
// avoid those ICEs.
184177
ty::tls::with(|tcx| {
185-
number_of_supplied_defaults(tcx, substs, subst::TypeSpace, get_generics)
178+
if let Some(generics) = get_generics(tcx) {
179+
number_of_supplied_defaults(tcx, substs, subst::TypeSpace, generics)
180+
} else {
181+
0
182+
}
186183
})
187184
};
188185

@@ -310,7 +307,7 @@ impl<'tcx> fmt::Display for TraitAndProjections<'tcx> {
310307
trait_ref.def_id,
311308
Ns::Type,
312309
projection_bounds,
313-
|tcx| tcx.lookup_trait_def(trait_ref.def_id).generics.clone())
310+
|tcx| Some(tcx.lookup_trait_def(trait_ref.def_id).generics.clone()))
314311
}
315312
}
316313

@@ -811,7 +808,7 @@ impl fmt::Display for ty::Binder<ty::OutlivesPredicate<ty::Region, ty::Region>>
811808
impl<'tcx> fmt::Display for ty::TraitRef<'tcx> {
812809
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
813810
parameterized(f, self.substs, self.def_id, Ns::Type, &[],
814-
|tcx| tcx.lookup_trait_def(self.def_id).generics.clone())
811+
|tcx| Some(tcx.lookup_trait_def(self.def_id).generics.clone()))
815812
}
816813
}
817814

@@ -863,8 +860,9 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
863860
}
864861

865862
write!(f, "{} {{", bare_fn.sig.0)?;
866-
parameterized(f, substs, def_id, Ns::Value, &[],
867-
|tcx| tcx.lookup_item_type(def_id).generics)?;
863+
parameterized(
864+
f, substs, def_id, Ns::Value, &[],
865+
|tcx| tcx.opt_lookup_item_type(def_id).map(|t| t.generics))?;
868866
write!(f, "}}")
869867
}
870868
TyFnPtr(ref bare_fn) => {
@@ -887,8 +885,12 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
887885
!tcx.tcache.borrow().contains_key(&def.did) {
888886
write!(f, "{}<..>", tcx.item_path_str(def.did))
889887
} else {
890-
parameterized(f, substs, def.did, Ns::Type, &[],
891-
|tcx| tcx.lookup_item_type(def.did).generics)
888+
parameterized(
889+
f, substs, def.did, Ns::Type, &[],
890+
|tcx| {
891+
tcx.opt_lookup_item_type(def.did).
892+
map(|t| t.generics)
893+
})
892894
}
893895
})
894896
}

src/librustc_metadata/csearch.rs

+5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
142142
decoder::get_item_name(&self.intr, &cdata, def.index)
143143
}
144144

145+
fn opt_item_name(&self, def: DefId) -> Option<ast::Name> {
146+
self.dep_graph.read(DepNode::MetaData(def));
147+
let cdata = self.get_crate_data(def.krate);
148+
decoder::maybe_get_item_name(&self.intr, &cdata, def.index)
149+
}
145150

146151
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>
147152
{

src/librustc_metadata/decoder.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,17 @@ fn item_trait_ref<'a, 'tcx>(doc: rbml::Doc, tcx: TyCtxt<'a, 'tcx, 'tcx>, cdata:
285285
}
286286

287287
fn item_name(intr: &IdentInterner, item: rbml::Doc) -> ast::Name {
288-
let name = reader::get_doc(item, tag_paths_data_name);
289-
let string = name.as_str_slice();
290-
match intr.find(string) {
291-
None => token::intern(string),
292-
Some(val) => val,
293-
}
288+
maybe_item_name(intr, item).expect("no item in item_name")
289+
}
290+
291+
fn maybe_item_name(intr: &IdentInterner, item: rbml::Doc) -> Option<ast::Name> {
292+
reader::maybe_get_doc(item, tag_paths_data_name).map(|name| {
293+
let string = name.as_str_slice();
294+
match intr.find(string) {
295+
None => token::intern(string),
296+
Some(val) => val,
297+
}
298+
})
294299
}
295300

296301
fn family_to_variant_kind<'tcx>(family: Family) -> Option<ty::VariantKind> {
@@ -792,6 +797,11 @@ pub fn get_item_name(intr: &IdentInterner, cdata: Cmd, id: DefIndex) -> ast::Nam
792797
item_name(intr, cdata.lookup_item(id))
793798
}
794799

800+
pub fn maybe_get_item_name(intr: &IdentInterner, cdata: Cmd, id: DefIndex)
801+
-> Option<ast::Name> {
802+
maybe_item_name(intr, cdata.lookup_item(id))
803+
}
804+
795805
pub fn maybe_get_item_ast<'a, 'tcx>(cdata: Cmd, tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefIndex)
796806
-> FoundAst<'tcx> {
797807
debug!("Looking up item: {:?}", id);

src/librustc_trans/monomorphize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub struct Instance<'tcx> {
173173
impl<'tcx> fmt::Display for Instance<'tcx> {
174174
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
175175
ppaux::parameterized(f, &self.substs, self.def, ppaux::Ns::Value, &[],
176-
|tcx| tcx.lookup_item_type(self.def).generics)
176+
|tcx| Some(tcx.lookup_item_type(self.def).generics))
177177
}
178178
}
179179

0 commit comments

Comments
 (0)