Skip to content

Commit 69dd31c

Browse files
arielb1Ariel Ben-Yehuda
authored andcommitted
make check works
1 parent 0adda66 commit 69dd31c

File tree

7 files changed

+130
-79
lines changed

7 files changed

+130
-79
lines changed

src/librustc/metadata/util.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use middle::def;
1919
use middle::lang_items;
2020
use middle::ty::{self, Ty};
2121
use middle::def_id::{DefId, DefIndex};
22-
use util::nodemap::{NodeMap, NodeSet};
22+
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
2323

2424
use std::any::Any;
2525
use std::cell::RefCell;
@@ -75,6 +75,7 @@ pub trait CrateStore<'tcx> : Any {
7575
fn item_symbol(&self, def: DefId) -> String;
7676
fn trait_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId)-> ty::TraitDef<'tcx>;
7777
fn adt_def(&self, tcx: &ty::ctxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>;
78+
fn method_arg_names(&self, did: DefId) -> Vec<String>;
7879
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>;
7980

8081
// trait info
@@ -104,10 +105,12 @@ pub trait CrateStore<'tcx> : Any {
104105
fn is_const_fn(&self, did: DefId) -> bool;
105106
fn is_defaulted_trait(&self, did: DefId) -> bool;
106107
fn is_impl(&self, did: DefId) -> bool;
107-
fn is_static_method(&self, did: DefId) -> bool;
108+
fn is_default_impl(&self, impl_did: DefId) -> bool;
108109
fn is_extern_fn(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool;
109110
fn is_static(&self, did: DefId) -> bool;
111+
fn is_static_method(&self, did: DefId) -> bool;
110112
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
113+
fn is_typedef(&self, did: DefId) -> bool;
111114

112115
// crate metadata
113116
fn dylib_dependency_formats(&self, cnum: ast::CrateNum)
@@ -117,8 +120,11 @@ pub trait CrateStore<'tcx> : Any {
117120
fn is_staged_api(&self, cnum: ast::CrateNum) -> bool;
118121
fn is_explicitly_linked(&self, cnum: ast::CrateNum) -> bool;
119122
fn is_allocator(&self, cnum: ast::CrateNum) -> bool;
123+
fn crate_attrs(&self, cnum: ast::CrateNum) -> Vec<ast::Attribute>;
120124
fn crate_name(&self, cnum: ast::CrateNum) -> String;
121125
fn crate_hash(&self, cnum: ast::CrateNum) -> Svh;
126+
fn crate_struct_field_attrs(&self, cnum: ast::CrateNum)
127+
-> FnvHashMap<DefId, Vec<ast::Attribute>>;
122128
fn plugin_registrar_fn(&self, cnum: ast::CrateNum) -> Option<DefId>;
123129
fn native_libraries(&self, cnum: ast::CrateNum) -> Vec<(NativeLibraryKind, String)>;
124130
fn reachable_ids(&self, cnum: ast::CrateNum) -> Vec<DefId>;
@@ -232,6 +238,12 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
232238
decoder::get_adt_def(&self.intr, &*cdata, def.index, tcx)
233239
}
234240

241+
fn method_arg_names(&self, did: DefId) -> Vec<String>
242+
{
243+
let cdata = self.get_crate_data(did.krate);
244+
decoder::get_method_arg_names(&cdata, did.index)
245+
}
246+
235247
fn item_path(&self, def: DefId) -> Vec<ast_map::PathElem> {
236248
let cdata = self.get_crate_data(def.krate);
237249
let path = decoder::get_item_path(&*cdata, def.index);
@@ -352,10 +364,9 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
352364
decoder::is_impl(&*cdata, did.index)
353365
}
354366

355-
fn is_static_method(&self, def: DefId) -> bool
356-
{
357-
let cdata = self.get_crate_data(def.krate);
358-
decoder::is_static_method(&*cdata, def.index)
367+
fn is_default_impl(&self, impl_did: DefId) -> bool {
368+
let cdata = self.get_crate_data(impl_did.krate);
369+
decoder::is_default_impl(&*cdata, impl_did.index)
359370
}
360371

361372
fn is_extern_fn(&self, tcx: &ty::ctxt<'tcx>, did: DefId) -> bool
@@ -370,11 +381,22 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
370381
decoder::is_static(&*cdata, did.index)
371382
}
372383

384+
fn is_static_method(&self, def: DefId) -> bool
385+
{
386+
let cdata = self.get_crate_data(def.krate);
387+
decoder::is_static_method(&*cdata, def.index)
388+
}
389+
373390
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool
374391
{
375392
self.do_is_statically_included_foreign_item(id)
376393
}
377394

395+
fn is_typedef(&self, did: DefId) -> bool {
396+
let cdata = self.get_crate_data(did.krate);
397+
decoder::is_typedef(&*cdata, did.index)
398+
}
399+
378400
fn dylib_dependency_formats(&self, cnum: ast::CrateNum)
379401
-> Vec<(ast::CrateNum, LinkagePreference)>
380402
{
@@ -414,6 +436,11 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
414436
self.get_crate_data(cnum).is_allocator()
415437
}
416438

439+
fn crate_attrs(&self, cnum: ast::CrateNum) -> Vec<ast::Attribute>
440+
{
441+
decoder::get_crate_attributes(self.get_crate_data(cnum).data())
442+
}
443+
417444
fn crate_name(&self, cnum: ast::CrateNum) -> String
418445
{
419446
self.get_crate_data(cnum).name.clone()
@@ -425,6 +452,12 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
425452
decoder::get_crate_hash(cdata.data())
426453
}
427454

455+
fn crate_struct_field_attrs(&self, cnum: ast::CrateNum)
456+
-> FnvHashMap<DefId, Vec<ast::Attribute>>
457+
{
458+
decoder::get_struct_field_attrs(&*self.get_crate_data(cnum))
459+
}
460+
428461
fn plugin_registrar_fn(&self, cnum: ast::CrateNum) -> Option<DefId>
429462
{
430463
let cdata = self.get_crate_data(cnum);

src/librustdoc/clean/inline.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use syntax::ast;
1616
use syntax::attr::AttrMetaMethods;
1717
use rustc_front::hir;
1818

19-
use rustc::metadata::csearch;
20-
use rustc::metadata::decoder;
19+
use rustc::metadata::util::{self as mdutil, CrateStore};
2120
use rustc::middle::def;
2221
use rustc::middle::def_id::DefId;
2322
use rustc::middle::ty;
@@ -129,8 +128,7 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
129128

130129
pub fn load_attrs(cx: &DocContext, tcx: &ty::ctxt,
131130
did: DefId) -> Vec<clean::Attribute> {
132-
let attrs = csearch::get_item_attrs(&tcx.sess.cstore, did);
133-
attrs.into_iter().map(|a| a.clean(cx)).collect()
131+
tcx.get_attrs(did).iter().map(|a| a.clean(cx)).collect()
134132
}
135133

136134
/// Record an external fully qualified name in the external_paths cache.
@@ -140,7 +138,7 @@ pub fn load_attrs(cx: &DocContext, tcx: &ty::ctxt,
140138
pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) {
141139
match cx.tcx_opt() {
142140
Some(tcx) => {
143-
let fqn = csearch::get_item_path(tcx, did);
141+
let fqn = tcx.sess.cstore.item_path(did);
144142
let fqn = fqn.into_iter().map(|i| i.to_string()).collect();
145143
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind));
146144
}
@@ -211,7 +209,7 @@ fn build_type(cx: &DocContext, tcx: &ty::ctxt, did: DefId) -> clean::ItemEnum {
211209
let t = tcx.lookup_item_type(did);
212210
let predicates = tcx.lookup_predicates(did);
213211
match t.ty.sty {
214-
ty::TyEnum(edef, _) if !csearch::is_typedef(&tcx.sess.cstore, did) => {
212+
ty::TyEnum(edef, _) if !tcx.sess.cstore.is_typedef(did) => {
215213
return clean::EnumItem(clean::Enum {
216214
generics: (&t.generics, &predicates, subst::TypeSpace).clean(cx),
217215
variants_stripped: false,
@@ -250,23 +248,19 @@ pub fn build_impls(cx: &DocContext, tcx: &ty::ctxt,
250248
// type being inlined, but impls can also be used when generating
251249
// documentation for primitives (no way to find those specifically).
252250
if cx.populated_crate_impls.borrow_mut().insert(did.krate) {
253-
csearch::each_top_level_item_of_crate(&tcx.sess.cstore,
254-
did.krate,
255-
|def, _, _| {
256-
populate_impls(cx, tcx, def, &mut impls)
257-
});
251+
for item in tcx.sess.cstore.crate_top_level_items(did.krate) {
252+
populate_impls(cx, tcx, item.def, &mut impls);
253+
}
258254

259255
fn populate_impls(cx: &DocContext, tcx: &ty::ctxt,
260-
def: decoder::DefLike,
256+
def: mdutil::DefLike,
261257
impls: &mut Vec<clean::Item>) {
262258
match def {
263-
decoder::DlImpl(did) => build_impl(cx, tcx, did, impls),
264-
decoder::DlDef(def::DefMod(did)) => {
265-
csearch::each_child_of_item(&tcx.sess.cstore,
266-
did,
267-
|def, _, _| {
268-
populate_impls(cx, tcx, def, impls)
269-
})
259+
mdutil::DlImpl(did) => build_impl(cx, tcx, did, impls),
260+
mdutil::DlDef(def::DefMod(did)) => {
261+
for item in tcx.sess.cstore.item_children(did) {
262+
populate_impls(cx, tcx, item.def, impls)
263+
}
270264
}
271265
_ => {}
272266
}
@@ -285,7 +279,7 @@ pub fn build_impl(cx: &DocContext,
285279
}
286280

287281
let attrs = load_attrs(cx, tcx, did);
288-
let associated_trait = csearch::get_impl_trait(tcx, did);
282+
let associated_trait = tcx.impl_trait_ref(did);
289283
if let Some(ref t) = associated_trait {
290284
// If this is an impl for a #[doc(hidden)] trait, be sure to not inline
291285
let trait_attrs = load_attrs(cx, tcx, t.def_id);
@@ -295,7 +289,7 @@ pub fn build_impl(cx: &DocContext,
295289
}
296290

297291
// If this is a defaulted impl, then bail out early here
298-
if csearch::is_default_impl(&tcx.sess.cstore, did) {
292+
if tcx.sess.cstore.is_default_impl(did) {
299293
return ret.push(clean::Item {
300294
inner: clean::DefaultImplItem(clean::DefaultImpl {
301295
// FIXME: this should be decoded
@@ -315,7 +309,7 @@ pub fn build_impl(cx: &DocContext,
315309
}
316310

317311
let predicates = tcx.lookup_predicates(did);
318-
let trait_items = csearch::get_impl_items(&tcx.sess.cstore, did)
312+
let trait_items = tcx.sess.cstore.impl_items(did)
319313
.iter()
320314
.filter_map(|did| {
321315
let did = did.def_id();
@@ -393,7 +387,7 @@ pub fn build_impl(cx: &DocContext,
393387
}
394388
}
395389
}).collect::<Vec<_>>();
396-
let polarity = csearch::get_impl_polarity(tcx, did);
390+
let polarity = tcx.trait_impl_polarity(did);
397391
let ty = tcx.lookup_item_type(did);
398392
let trait_ = associated_trait.clean(cx).map(|bound| {
399393
match bound {
@@ -454,24 +448,24 @@ fn build_module(cx: &DocContext, tcx: &ty::ctxt,
454448
// two namespaces, so the target may be listed twice. Make sure we only
455449
// visit each node at most once.
456450
let mut visited = HashSet::new();
457-
csearch::each_child_of_item(&tcx.sess.cstore, did, |def, _, vis| {
458-
match def {
459-
decoder::DlDef(def::DefForeignMod(did)) => {
451+
for item in tcx.sess.cstore.item_children(did) {
452+
match item.def {
453+
mdutil::DlDef(def::DefForeignMod(did)) => {
460454
fill_in(cx, tcx, did, items);
461455
}
462-
decoder::DlDef(def) if vis == hir::Public => {
456+
mdutil::DlDef(def) if item.vis == hir::Public => {
463457
if !visited.insert(def) { return }
464458
match try_inline_def(cx, tcx, def) {
465459
Some(i) => items.extend(i),
466460
None => {}
467461
}
468462
}
469-
decoder::DlDef(..) => {}
463+
mdutil::DlDef(..) => {}
470464
// All impls were inlined above
471-
decoder::DlImpl(..) => {}
472-
decoder::DlField => panic!("unimplemented field"),
465+
mdutil::DlImpl(..) => {}
466+
mdutil::DlField => panic!("unimplemented field"),
473467
}
474-
});
468+
}
475469
}
476470
}
477471

src/librustdoc/clean/mod.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ use syntax::parse::token::{self, InternedString, special_idents};
3535
use syntax::ptr::P;
3636

3737
use rustc_trans::back::link;
38-
use rustc::metadata::cstore;
39-
use rustc::metadata::csearch;
40-
use rustc::metadata::decoder;
38+
use rustc::metadata::util::{self as mdutil, CrateStore};
4139
use rustc::middle::def;
4240
use rustc::middle::def_id::{DefId, DefIndex};
4341
use rustc::middle::subst::{self, ParamSpace, VecPerParamSpace};
@@ -126,6 +124,8 @@ pub struct Crate {
126124
pub external_traits: HashMap<DefId, Trait>,
127125
}
128126

127+
struct CrateNum(ast::CrateNum);
128+
129129
impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
130130
fn clean(&self, cx: &DocContext) -> Crate {
131131
use rustc::session::config::Input;
@@ -135,9 +135,9 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
135135
}
136136

137137
let mut externs = Vec::new();
138-
cx.sess().cstore.iter_crate_data(|n, meta| {
139-
externs.push((n, meta.clean(cx)));
140-
});
138+
for cnum in cx.sess().cstore.crates() {
139+
externs.push((cnum, CrateNum(cnum).clean(cx)));
140+
}
141141
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
142142

143143
// Figure out the name of this crate
@@ -219,24 +219,22 @@ pub struct ExternalCrate {
219219
pub primitives: Vec<PrimitiveType>,
220220
}
221221

222-
impl Clean<ExternalCrate> for cstore::crate_metadata {
222+
impl Clean<ExternalCrate> for CrateNum {
223223
fn clean(&self, cx: &DocContext) -> ExternalCrate {
224224
let mut primitives = Vec::new();
225225
cx.tcx_opt().map(|tcx| {
226-
csearch::each_top_level_item_of_crate(&tcx.sess.cstore,
227-
self.cnum,
228-
|def, _, _| {
229-
let did = match def {
230-
decoder::DlDef(def::DefMod(did)) => did,
231-
_ => return
226+
for item in tcx.sess.cstore.crate_top_level_items(self.0) {
227+
let did = match item.def {
228+
mdutil::DlDef(def::DefMod(did)) => did,
229+
_ => continue
232230
};
233231
let attrs = inline::load_attrs(cx, tcx, did);
234232
PrimitiveType::find(&attrs).map(|prim| primitives.push(prim));
235-
})
233+
}
236234
});
237235
ExternalCrate {
238-
name: self.name.to_string(),
239-
attrs: decoder::get_crate_attributes(self.data()).clean(cx),
236+
name: cx.sess().cstore.crate_name(self.0),
237+
attrs: cx.sess().cstore.crate_attrs(self.0).clean(cx),
240238
primitives: primitives,
241239
}
242240
}
@@ -656,7 +654,7 @@ impl Clean<TyParamBound> for ty::BuiltinBound {
656654
(tcx.lang_items.sync_trait().unwrap(),
657655
external_path(cx, "Sync", None, vec![], &empty)),
658656
};
659-
let fqn = csearch::get_item_path(tcx, did);
657+
let fqn = tcx.sess.cstore.item_path(did);
660658
let fqn = fqn.into_iter().map(|i| i.to_string()).collect();
661659
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did,
662660
(fqn, TypeTrait));
@@ -678,7 +676,7 @@ impl<'tcx> Clean<TyParamBound> for ty::TraitRef<'tcx> {
678676
Some(tcx) => tcx,
679677
None => return RegionBound(Lifetime::statik())
680678
};
681-
let fqn = csearch::get_item_path(tcx, self.def_id);
679+
let fqn = tcx.sess.cstore.item_path(self.def_id);
682680
let fqn = fqn.into_iter().map(|i| i.to_string())
683681
.collect::<Vec<String>>();
684682
let path = external_path(cx, fqn.last().unwrap(),
@@ -1140,7 +1138,7 @@ impl<'a, 'tcx> Clean<FnDecl> for (DefId, &'a ty::PolyFnSig<'tcx>) {
11401138
let mut names = if let Some(_) = cx.map.as_local_node_id(did) {
11411139
vec![].into_iter()
11421140
} else {
1143-
csearch::get_method_arg_names(&cx.tcx().sess.cstore, did).into_iter()
1141+
cx.tcx().sess.cstore.method_arg_names(did).into_iter()
11441142
}.peekable();
11451143
if names.peek().map(|s| &**s) == Some("self") {
11461144
let _ = names.next();
@@ -1665,7 +1663,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
16651663
ty::TyStruct(def, substs) |
16661664
ty::TyEnum(def, substs) => {
16671665
let did = def.did;
1668-
let fqn = csearch::get_item_path(cx.tcx(), did);
1666+
let fqn = cx.tcx().sess.cstore.item_path(did);
16691667
let fqn: Vec<_> = fqn.into_iter().map(|i| i.to_string()).collect();
16701668
let kind = match self.sty {
16711669
ty::TyStruct(..) => TypeStruct,
@@ -1683,7 +1681,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
16831681
}
16841682
ty::TyTrait(box ty::TraitTy { ref principal, ref bounds }) => {
16851683
let did = principal.def_id();
1686-
let fqn = csearch::get_item_path(cx.tcx(), did);
1684+
let fqn = cx.tcx().sess.cstore.item_path(did);
16871685
let fqn: Vec<_> = fqn.into_iter().map(|i| i.to_string()).collect();
16881686
let (typarams, bindings) = bounds.clean(cx);
16891687
let path = external_path(cx, &fqn.last().unwrap().to_string(),
@@ -1737,9 +1735,9 @@ impl Clean<Item> for hir::StructField {
17371735
impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
17381736
fn clean(&self, cx: &DocContext) -> Item {
17391737
use syntax::parse::token::special_idents::unnamed_field;
1740-
use rustc::metadata::csearch;
1741-
1742-
let attr_map = csearch::get_struct_field_attrs(&cx.tcx().sess.cstore, self.did);
1738+
// FIXME: possible O(n^2)-ness! Not my fault.
1739+
let attr_map =
1740+
cx.tcx().sess.cstore.crate_struct_field_attrs(self.did.krate);
17431741

17441742
let (name, attrs) = if self.name == unnamed_field.name {
17451743
(None, None)
@@ -2815,7 +2813,7 @@ fn lang_struct(cx: &DocContext, did: Option<DefId>,
28152813
Some(did) => did,
28162814
None => return fallback(box t.clean(cx)),
28172815
};
2818-
let fqn = csearch::get_item_path(cx.tcx(), did);
2816+
let fqn = cx.tcx().sess.cstore.item_path(did);
28192817
let fqn: Vec<String> = fqn.into_iter().map(|i| {
28202818
i.to_string()
28212819
}).collect();

0 commit comments

Comments
 (0)