Retire rustdocs ANALYSISKEY
The thread-local isn't needed and consists of mostly empty fields which were just used to move the data into `html::render::CACHE_KEY`.
This commit is contained in:
parent
6136a86291
commit
ea83349c9f
@ -15,10 +15,11 @@
|
|||||||
use util::nodemap::{DefIdSet, FnvHashMap};
|
use util::nodemap::{DefIdSet, FnvHashMap};
|
||||||
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
use std::fmt;
|
||||||
use syntax::ast::NodeId;
|
use syntax::ast::NodeId;
|
||||||
|
|
||||||
// Accessibility levels, sorted in ascending order
|
// Accessibility levels, sorted in ascending order
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum AccessLevel {
|
pub enum AccessLevel {
|
||||||
// Exported items + items participating in various kinds of public interfaces,
|
// Exported items + items participating in various kinds of public interfaces,
|
||||||
// but not directly nameable. For example, if function `fn f() -> T {...}` is
|
// but not directly nameable. For example, if function `fn f() -> T {...}` is
|
||||||
@ -56,6 +57,12 @@ impl<Id: Hash + Eq> Default for AccessLevels<Id> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<Id: Hash + Eq + fmt::Debug> fmt::Debug for AccessLevels<Id> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt::Debug::fmt(&self.map, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A set containing all exported definitions from external crates.
|
/// A set containing all exported definitions from external crates.
|
||||||
/// The set does not contain any entries from local crates.
|
/// The set does not contain any entries from local crates.
|
||||||
pub type ExternalExports = DefIdSet;
|
pub type ExternalExports = DefIdSet;
|
||||||
|
@ -116,7 +116,7 @@ fn try_inline_def(cx: &DocContext, tcx: &TyCtxt,
|
|||||||
}
|
}
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
cx.inlined.borrow_mut().as_mut().unwrap().insert(did);
|
cx.renderinfo.borrow_mut().inlined.insert(did);
|
||||||
ret.push(clean::Item {
|
ret.push(clean::Item {
|
||||||
source: clean::Span::empty(),
|
source: clean::Span::empty(),
|
||||||
name: Some(tcx.item_name(did).to_string()),
|
name: Some(tcx.item_name(did).to_string()),
|
||||||
@ -146,7 +146,7 @@ pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) {
|
|||||||
elem.data.to_string()
|
elem.data.to_string()
|
||||||
});
|
});
|
||||||
let fqn = once(crate_name).chain(relative).collect();
|
let fqn = once(crate_name).chain(relative).collect();
|
||||||
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind));
|
cx.renderinfo.borrow_mut().external_paths.insert(did, (fqn, kind));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +295,7 @@ pub fn build_impl(cx: &DocContext,
|
|||||||
tcx: &TyCtxt,
|
tcx: &TyCtxt,
|
||||||
did: DefId,
|
did: DefId,
|
||||||
ret: &mut Vec<clean::Item>) {
|
ret: &mut Vec<clean::Item>) {
|
||||||
if !cx.inlined.borrow_mut().as_mut().unwrap().insert(did) {
|
if !cx.renderinfo.borrow_mut().inlined.insert(did) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ use syntax::ptr::P;
|
|||||||
|
|
||||||
use rustc_trans::back::link;
|
use rustc_trans::back::link;
|
||||||
use rustc::middle::cstore::{self, CrateStore};
|
use rustc::middle::cstore::{self, CrateStore};
|
||||||
|
use rustc::middle::privacy::AccessLevels;
|
||||||
use rustc::hir::def::Def;
|
use rustc::hir::def::Def;
|
||||||
use rustc::hir::def_id::{DefId, DefIndex};
|
use rustc::hir::def_id::{DefId, DefIndex};
|
||||||
use rustc::ty::subst::{self, ParamSpace, VecPerParamSpace};
|
use rustc::ty::subst::{self, ParamSpace, VecPerParamSpace};
|
||||||
@ -46,8 +47,10 @@ use rustc::hir;
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::sync::Arc;
|
||||||
use std::u32;
|
use std::u32;
|
||||||
use std::env::current_dir;
|
use std::env::current_dir;
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
use core::DocContext;
|
use core::DocContext;
|
||||||
use doctree;
|
use doctree;
|
||||||
@ -112,13 +115,16 @@ impl<T: Clean<U>, U> Clean<Vec<U>> for P<[T]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Crate {
|
pub struct Crate {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub src: PathBuf,
|
pub src: PathBuf,
|
||||||
pub module: Option<Item>,
|
pub module: Option<Item>,
|
||||||
pub externs: Vec<(ast::CrateNum, ExternalCrate)>,
|
pub externs: Vec<(ast::CrateNum, ExternalCrate)>,
|
||||||
pub primitives: Vec<PrimitiveType>,
|
pub primitives: Vec<PrimitiveType>,
|
||||||
|
pub access_levels: Arc<AccessLevels<DefId>>,
|
||||||
|
// These are later on moved into `CACHEKEY`, leaving the map empty.
|
||||||
|
// Only here so that they can be filtered through the rustdoc passes.
|
||||||
pub external_traits: HashMap<DefId, Trait>,
|
pub external_traits: HashMap<DefId, Trait>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,6 +136,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
|
|||||||
|
|
||||||
if let Some(t) = cx.tcx_opt() {
|
if let Some(t) = cx.tcx_opt() {
|
||||||
cx.deref_trait_did.set(t.lang_items.deref_trait());
|
cx.deref_trait_did.set(t.lang_items.deref_trait());
|
||||||
|
cx.renderinfo.borrow_mut().deref_trait_did = cx.deref_trait_did.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut externs = Vec::new();
|
let mut externs = Vec::new();
|
||||||
@ -204,14 +211,17 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
|
|||||||
Input::Str { ref name, .. } => PathBuf::from(name.clone()),
|
Input::Str { ref name, .. } => PathBuf::from(name.clone()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut access_levels = cx.access_levels.borrow_mut();
|
||||||
|
let mut external_traits = cx.external_traits.borrow_mut();
|
||||||
|
|
||||||
Crate {
|
Crate {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
src: src,
|
src: src,
|
||||||
module: Some(module),
|
module: Some(module),
|
||||||
externs: externs,
|
externs: externs,
|
||||||
primitives: primitives,
|
primitives: primitives,
|
||||||
external_traits: cx.external_traits.borrow_mut().take()
|
access_levels: Arc::new(mem::replace(&mut access_levels, Default::default())),
|
||||||
.unwrap_or(HashMap::new()),
|
external_traits: mem::replace(&mut external_traits, Default::default()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -540,8 +550,7 @@ impl Clean<TyParam> for hir::TyParam {
|
|||||||
|
|
||||||
impl<'tcx> Clean<TyParam> for ty::TypeParameterDef<'tcx> {
|
impl<'tcx> Clean<TyParam> for ty::TypeParameterDef<'tcx> {
|
||||||
fn clean(&self, cx: &DocContext) -> TyParam {
|
fn clean(&self, cx: &DocContext) -> TyParam {
|
||||||
cx.external_typarams.borrow_mut().as_mut().unwrap()
|
cx.renderinfo.borrow_mut().external_typarams.insert(self.def_id, self.name.clean(cx));
|
||||||
.insert(self.def_id, self.name.clean(cx));
|
|
||||||
TyParam {
|
TyParam {
|
||||||
name: self.name.clean(cx),
|
name: self.name.clean(cx),
|
||||||
did: self.def_id,
|
did: self.def_id,
|
||||||
@ -2668,7 +2677,7 @@ fn register_def(cx: &DocContext, def: Def) -> DefId {
|
|||||||
inline::record_extern_fqn(cx, did, kind);
|
inline::record_extern_fqn(cx, did, kind);
|
||||||
if let TypeTrait = kind {
|
if let TypeTrait = kind {
|
||||||
let t = inline::build_external_trait(cx, tcx, did);
|
let t = inline::build_external_trait(cx, tcx, did);
|
||||||
cx.external_traits.borrow_mut().as_mut().unwrap().insert(did, t);
|
cx.external_traits.borrow_mut().insert(did, t);
|
||||||
}
|
}
|
||||||
did
|
did
|
||||||
}
|
}
|
||||||
|
@ -29,12 +29,13 @@ use syntax::feature_gate::UnstableFeatures;
|
|||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
|
|
||||||
use std::cell::{RefCell, Cell};
|
use std::cell::{RefCell, Cell};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use visit_ast::RustdocVisitor;
|
use visit_ast::RustdocVisitor;
|
||||||
use clean;
|
use clean;
|
||||||
use clean::Clean;
|
use clean::Clean;
|
||||||
|
use html::render::RenderInfo;
|
||||||
|
|
||||||
pub use rustc::session::config::Input;
|
pub use rustc::session::config::Input;
|
||||||
pub use rustc::session::search_paths::SearchPaths;
|
pub use rustc::session::search_paths::SearchPaths;
|
||||||
@ -45,19 +46,20 @@ pub enum MaybeTyped<'a, 'tcx: 'a> {
|
|||||||
NotTyped(&'a session::Session)
|
NotTyped(&'a session::Session)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type ExternalPaths = RefCell<Option<HashMap<DefId,
|
pub type ExternalPaths = HashMap<DefId, (Vec<String>, clean::TypeKind)>;
|
||||||
(Vec<String>, clean::TypeKind)>>>;
|
|
||||||
|
|
||||||
pub struct DocContext<'a, 'tcx: 'a> {
|
pub struct DocContext<'a, 'tcx: 'a> {
|
||||||
pub map: &'a hir_map::Map<'tcx>,
|
pub map: &'a hir_map::Map<'tcx>,
|
||||||
pub maybe_typed: MaybeTyped<'a, 'tcx>,
|
pub maybe_typed: MaybeTyped<'a, 'tcx>,
|
||||||
pub input: Input,
|
pub input: Input,
|
||||||
pub external_paths: ExternalPaths,
|
|
||||||
pub external_traits: RefCell<Option<HashMap<DefId, clean::Trait>>>,
|
|
||||||
pub external_typarams: RefCell<Option<HashMap<DefId, String>>>,
|
|
||||||
pub inlined: RefCell<Option<HashSet<DefId>>>,
|
|
||||||
pub all_crate_impls: RefCell<HashMap<ast::CrateNum, Vec<clean::Item>>>,
|
pub all_crate_impls: RefCell<HashMap<ast::CrateNum, Vec<clean::Item>>>,
|
||||||
|
// Later on moved into `clean::Crate`
|
||||||
|
pub access_levels: RefCell<AccessLevels<DefId>>,
|
||||||
|
// Later on moved into `html::render::CACHE_KEY`
|
||||||
|
pub renderinfo: RefCell<RenderInfo>,
|
||||||
pub deref_trait_did: Cell<Option<DefId>>,
|
pub deref_trait_did: Cell<Option<DefId>>,
|
||||||
|
// Later on moved through `clean::Crate` into `html::render::CACHE_KEY`
|
||||||
|
pub external_traits: RefCell<HashMap<DefId, clean::Trait>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b, 'tcx> DocContext<'b, 'tcx> {
|
impl<'b, 'tcx> DocContext<'b, 'tcx> {
|
||||||
@ -81,20 +83,14 @@ impl<'b, 'tcx> DocContext<'b, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CrateAnalysis {
|
|
||||||
pub access_levels: AccessLevels<DefId>,
|
|
||||||
pub external_paths: ExternalPaths,
|
|
||||||
pub external_typarams: RefCell<Option<HashMap<DefId, String>>>,
|
|
||||||
pub inlined: RefCell<Option<HashSet<DefId>>>,
|
|
||||||
pub deref_trait_did: Option<DefId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type Externs = HashMap<String, Vec<String>>;
|
pub type Externs = HashMap<String, Vec<String>>;
|
||||||
|
|
||||||
pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
|
pub fn run_core(search_paths: SearchPaths,
|
||||||
input: Input, triple: Option<String>)
|
cfgs: Vec<String>,
|
||||||
-> (clean::Crate, CrateAnalysis) {
|
externs: Externs,
|
||||||
|
input: Input,
|
||||||
|
triple: Option<String>) -> (clean::Crate, RenderInfo)
|
||||||
|
{
|
||||||
// Parse, resolve, and typecheck the given crate.
|
// Parse, resolve, and typecheck the given crate.
|
||||||
|
|
||||||
let cpath = match input {
|
let cpath = match input {
|
||||||
@ -148,7 +144,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
|
|||||||
let arenas = ty::CtxtArenas::new();
|
let arenas = ty::CtxtArenas::new();
|
||||||
let hir_map = driver::make_map(&sess, &mut hir_forest);
|
let hir_map = driver::make_map(&sess, &mut hir_forest);
|
||||||
|
|
||||||
let krate_and_analysis = abort_on_err(driver::phase_3_run_analysis_passes(&sess,
|
abort_on_err(driver::phase_3_run_analysis_passes(&sess,
|
||||||
&cstore,
|
&cstore,
|
||||||
hir_map,
|
hir_map,
|
||||||
&arenas,
|
&arenas,
|
||||||
@ -175,42 +171,20 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
|
|||||||
map: &tcx.map,
|
map: &tcx.map,
|
||||||
maybe_typed: Typed(tcx),
|
maybe_typed: Typed(tcx),
|
||||||
input: input,
|
input: input,
|
||||||
external_traits: RefCell::new(Some(HashMap::new())),
|
|
||||||
external_typarams: RefCell::new(Some(HashMap::new())),
|
|
||||||
external_paths: RefCell::new(Some(HashMap::new())),
|
|
||||||
inlined: RefCell::new(Some(HashSet::new())),
|
|
||||||
all_crate_impls: RefCell::new(HashMap::new()),
|
all_crate_impls: RefCell::new(HashMap::new()),
|
||||||
deref_trait_did: Cell::new(None),
|
deref_trait_did: Cell::new(None),
|
||||||
|
access_levels: RefCell::new(access_levels),
|
||||||
|
external_traits: RefCell::new(HashMap::new()),
|
||||||
|
renderinfo: RefCell::new(Default::default()),
|
||||||
};
|
};
|
||||||
debug!("crate: {:?}", ctxt.map.krate());
|
debug!("crate: {:?}", ctxt.map.krate());
|
||||||
|
|
||||||
let mut analysis = CrateAnalysis {
|
|
||||||
access_levels: access_levels,
|
|
||||||
external_paths: RefCell::new(None),
|
|
||||||
external_typarams: RefCell::new(None),
|
|
||||||
inlined: RefCell::new(None),
|
|
||||||
deref_trait_did: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let krate = {
|
let krate = {
|
||||||
let mut v = RustdocVisitor::new(&ctxt, Some(&analysis));
|
let mut v = RustdocVisitor::new(&ctxt);
|
||||||
v.visit(ctxt.map.krate());
|
v.visit(ctxt.map.krate());
|
||||||
v.clean(&ctxt)
|
v.clean(&ctxt)
|
||||||
};
|
};
|
||||||
|
|
||||||
let external_paths = ctxt.external_paths.borrow_mut().take();
|
Some((krate, ctxt.renderinfo.into_inner()))
|
||||||
*analysis.external_paths.borrow_mut() = external_paths;
|
}), &sess).unwrap()
|
||||||
|
|
||||||
let map = ctxt.external_typarams.borrow_mut().take();
|
|
||||||
*analysis.external_typarams.borrow_mut() = map;
|
|
||||||
|
|
||||||
let map = ctxt.inlined.borrow_mut().take();
|
|
||||||
*analysis.inlined.borrow_mut() = map;
|
|
||||||
|
|
||||||
analysis.deref_trait_did = ctxt.deref_trait_did.get();
|
|
||||||
|
|
||||||
Some((krate, analysis))
|
|
||||||
}), &sess);
|
|
||||||
|
|
||||||
krate_and_analysis.unwrap()
|
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ pub struct Cache {
|
|||||||
parent_is_trait_impl: bool,
|
parent_is_trait_impl: bool,
|
||||||
search_index: Vec<IndexItem>,
|
search_index: Vec<IndexItem>,
|
||||||
stripped_mod: bool,
|
stripped_mod: bool,
|
||||||
access_levels: AccessLevels<DefId>,
|
access_levels: Arc<AccessLevels<DefId>>,
|
||||||
deref_trait_did: Option<DefId>,
|
deref_trait_did: Option<DefId>,
|
||||||
|
|
||||||
// In rare case where a structure is defined in one module but implemented
|
// In rare case where a structure is defined in one module but implemented
|
||||||
@ -264,6 +264,16 @@ pub struct Cache {
|
|||||||
orphan_methods: Vec<(DefId, clean::Item)>,
|
orphan_methods: Vec<(DefId, clean::Item)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Temporary storage for data obtained during `RustdocVisitor::clean()`.
|
||||||
|
/// Later on moved into `CACHE_KEY`.
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct RenderInfo {
|
||||||
|
pub inlined: HashSet<DefId>,
|
||||||
|
pub external_paths: ::core::ExternalPaths,
|
||||||
|
pub external_typarams: HashMap<DefId, String>,
|
||||||
|
pub deref_trait_did: Option<DefId>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Helper struct to render all source code to HTML pages
|
/// Helper struct to render all source code to HTML pages
|
||||||
struct SourceCollector<'a> {
|
struct SourceCollector<'a> {
|
||||||
scx: &'a mut SharedContext,
|
scx: &'a mut SharedContext,
|
||||||
@ -415,7 +425,8 @@ pub fn run(mut krate: clean::Crate,
|
|||||||
external_html: &ExternalHtml,
|
external_html: &ExternalHtml,
|
||||||
dst: PathBuf,
|
dst: PathBuf,
|
||||||
passes: HashSet<String>,
|
passes: HashSet<String>,
|
||||||
css_file_extension: Option<PathBuf>) -> Result<(), Error> {
|
css_file_extension: Option<PathBuf>,
|
||||||
|
renderinfo: RenderInfo) -> Result<(), Error> {
|
||||||
let src_root = match krate.src.parent() {
|
let src_root = match krate.src.parent() {
|
||||||
Some(p) => p.to_path_buf(),
|
Some(p) => p.to_path_buf(),
|
||||||
None => PathBuf::new(),
|
None => PathBuf::new(),
|
||||||
@ -482,19 +493,20 @@ pub fn run(mut krate: clean::Crate,
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Crawl the crate to build various caches used for the output
|
// Crawl the crate to build various caches used for the output
|
||||||
let analysis = ::ANALYSISKEY.with(|a| a.clone());
|
let RenderInfo {
|
||||||
let analysis = analysis.borrow();
|
inlined,
|
||||||
let access_levels = analysis.as_ref().map(|a| a.access_levels.clone());
|
external_paths,
|
||||||
let access_levels = access_levels.unwrap_or(Default::default());
|
external_typarams,
|
||||||
let paths: HashMap<DefId, (Vec<String>, ItemType)> =
|
deref_trait_did,
|
||||||
analysis.as_ref().map(|a| {
|
} = renderinfo;
|
||||||
let paths = a.external_paths.borrow_mut().take().unwrap();
|
|
||||||
paths.into_iter().map(|(k, (v, t))| (k, (v, ItemType::from_type_kind(t)))).collect()
|
let paths = external_paths.into_iter()
|
||||||
}).unwrap_or(HashMap::new());
|
.map(|(k, (v, t))| (k, (v, ItemType::from_type_kind(t))))
|
||||||
|
.collect::<HashMap<_, _>>();
|
||||||
|
|
||||||
let mut cache = Cache {
|
let mut cache = Cache {
|
||||||
impls: HashMap::new(),
|
impls: HashMap::new(),
|
||||||
external_paths: paths.iter().map(|(&k, v)| (k, v.0.clone()))
|
external_paths: paths.iter().map(|(&k, v)| (k, v.0.clone())).collect(),
|
||||||
.collect(),
|
|
||||||
paths: paths,
|
paths: paths,
|
||||||
implementors: HashMap::new(),
|
implementors: HashMap::new(),
|
||||||
stack: Vec::new(),
|
stack: Vec::new(),
|
||||||
@ -504,16 +516,12 @@ pub fn run(mut krate: clean::Crate,
|
|||||||
extern_locations: HashMap::new(),
|
extern_locations: HashMap::new(),
|
||||||
primitive_locations: HashMap::new(),
|
primitive_locations: HashMap::new(),
|
||||||
stripped_mod: false,
|
stripped_mod: false,
|
||||||
access_levels: access_levels,
|
access_levels: krate.access_levels.clone(),
|
||||||
orphan_methods: Vec::new(),
|
orphan_methods: Vec::new(),
|
||||||
traits: mem::replace(&mut krate.external_traits, HashMap::new()),
|
traits: mem::replace(&mut krate.external_traits, HashMap::new()),
|
||||||
deref_trait_did: analysis.as_ref().and_then(|a| a.deref_trait_did),
|
deref_trait_did: deref_trait_did,
|
||||||
typarams: analysis.as_ref().map(|a| {
|
typarams: external_typarams,
|
||||||
a.external_typarams.borrow_mut().take().unwrap()
|
inlined: inlined,
|
||||||
}).unwrap_or(HashMap::new()),
|
|
||||||
inlined: analysis.as_ref().map(|a| {
|
|
||||||
a.inlined.borrow_mut().take().unwrap()
|
|
||||||
}).unwrap_or(HashSet::new()),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Cache where all our extern crates are located
|
// Cache where all our extern crates are located
|
||||||
|
@ -48,14 +48,11 @@ extern crate rustc_unicode;
|
|||||||
|
|
||||||
extern crate serialize as rustc_serialize; // used by deriving
|
extern crate serialize as rustc_serialize; // used by deriving
|
||||||
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::io::Read;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::rc::Rc;
|
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
use externalfiles::ExternalHtml;
|
use externalfiles::ExternalHtml;
|
||||||
@ -113,12 +110,9 @@ const DEFAULT_PASSES: &'static [&'static str] = &[
|
|||||||
"unindent-comments",
|
"unindent-comments",
|
||||||
];
|
];
|
||||||
|
|
||||||
thread_local!(pub static ANALYSISKEY: Rc<RefCell<Option<core::CrateAnalysis>>> = {
|
|
||||||
Rc::new(RefCell::new(None))
|
|
||||||
});
|
|
||||||
|
|
||||||
struct Output {
|
struct Output {
|
||||||
krate: clean::Crate,
|
krate: clean::Crate,
|
||||||
|
renderinfo: html::render::RenderInfo,
|
||||||
passes: Vec<String>,
|
passes: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,14 +296,15 @@ pub fn main_args(args: &[String]) -> isize {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let Output { krate, passes, } = out;
|
let Output { krate, passes, renderinfo } = out;
|
||||||
info!("going to format");
|
info!("going to format");
|
||||||
match matches.opt_str("w").as_ref().map(|s| &**s) {
|
match matches.opt_str("w").as_ref().map(|s| &**s) {
|
||||||
Some("html") | None => {
|
Some("html") | None => {
|
||||||
html::render::run(krate, &external_html,
|
html::render::run(krate, &external_html,
|
||||||
output.unwrap_or(PathBuf::from("doc")),
|
output.unwrap_or(PathBuf::from("doc")),
|
||||||
passes.into_iter().collect(),
|
passes.into_iter().collect(),
|
||||||
css_file_extension)
|
css_file_extension,
|
||||||
|
renderinfo)
|
||||||
.expect("failed to generate documentation")
|
.expect("failed to generate documentation")
|
||||||
}
|
}
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
@ -380,12 +375,8 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
|
|||||||
tx.send(core::run_core(paths, cfgs, externs, Input::File(cr),
|
tx.send(core::run_core(paths, cfgs, externs, Input::File(cr),
|
||||||
triple)).unwrap();
|
triple)).unwrap();
|
||||||
});
|
});
|
||||||
let (mut krate, analysis) = rx.recv().unwrap();
|
let (mut krate, renderinfo) = rx.recv().unwrap();
|
||||||
info!("finished with rustc");
|
info!("finished with rustc");
|
||||||
let mut analysis = Some(analysis);
|
|
||||||
ANALYSISKEY.with(|s| {
|
|
||||||
*s.borrow_mut() = analysis.take();
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(name) = matches.opt_str("crate-name") {
|
if let Some(name) = matches.opt_str("crate-name") {
|
||||||
krate.name = name
|
krate.name = name
|
||||||
@ -443,5 +434,5 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
|
|||||||
// Run everything!
|
// Run everything!
|
||||||
info!("Executing passes/plugins");
|
info!("Executing passes/plugins");
|
||||||
let krate = pm.run_plugins(krate);
|
let krate = pm.run_plugins(krate);
|
||||||
Output { krate: krate, passes: passes }
|
Output { krate: krate, renderinfo: renderinfo, passes: passes }
|
||||||
}
|
}
|
||||||
|
@ -88,10 +88,7 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
|
|||||||
pub fn strip_private(mut krate: clean::Crate) -> plugins::PluginResult {
|
pub fn strip_private(mut krate: clean::Crate) -> plugins::PluginResult {
|
||||||
// This stripper collects all *retained* nodes.
|
// This stripper collects all *retained* nodes.
|
||||||
let mut retained = DefIdSet();
|
let mut retained = DefIdSet();
|
||||||
let analysis = super::ANALYSISKEY.with(|a| a.clone());
|
let access_levels = krate.access_levels.clone();
|
||||||
let analysis = analysis.borrow();
|
|
||||||
let analysis = analysis.as_ref().unwrap();
|
|
||||||
let access_levels = analysis.access_levels.clone();
|
|
||||||
|
|
||||||
// strip all private items
|
// strip all private items
|
||||||
{
|
{
|
||||||
|
@ -108,15 +108,14 @@ pub fn run(input: &str,
|
|||||||
map: &map,
|
map: &map,
|
||||||
maybe_typed: core::NotTyped(&sess),
|
maybe_typed: core::NotTyped(&sess),
|
||||||
input: input,
|
input: input,
|
||||||
external_paths: RefCell::new(Some(HashMap::new())),
|
external_traits: RefCell::new(HashMap::new()),
|
||||||
external_traits: RefCell::new(None),
|
|
||||||
external_typarams: RefCell::new(None),
|
|
||||||
inlined: RefCell::new(None),
|
|
||||||
all_crate_impls: RefCell::new(HashMap::new()),
|
all_crate_impls: RefCell::new(HashMap::new()),
|
||||||
deref_trait_did: Cell::new(None),
|
deref_trait_did: Cell::new(None),
|
||||||
|
access_levels: Default::default(),
|
||||||
|
renderinfo: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut v = RustdocVisitor::new(&ctx, None);
|
let mut v = RustdocVisitor::new(&ctx);
|
||||||
v.visit(ctx.map.krate());
|
v.visit(ctx.map.krate());
|
||||||
let mut krate = v.clean(&ctx);
|
let mut krate = v.clean(&ctx);
|
||||||
if let Some(name) = crate_name {
|
if let Some(name) = crate_name {
|
||||||
|
@ -41,14 +41,12 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> {
|
|||||||
pub module: Module,
|
pub module: Module,
|
||||||
pub attrs: hir::HirVec<ast::Attribute>,
|
pub attrs: hir::HirVec<ast::Attribute>,
|
||||||
pub cx: &'a core::DocContext<'a, 'tcx>,
|
pub cx: &'a core::DocContext<'a, 'tcx>,
|
||||||
pub analysis: Option<&'a core::CrateAnalysis>,
|
|
||||||
view_item_stack: HashSet<ast::NodeId>,
|
view_item_stack: HashSet<ast::NodeId>,
|
||||||
inlining_from_glob: bool,
|
inlining_from_glob: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||||
pub fn new(cx: &'a core::DocContext<'a, 'tcx>,
|
pub fn new(cx: &'a core::DocContext<'a, 'tcx>) -> RustdocVisitor<'a, 'tcx> {
|
||||||
analysis: Option<&'a core::CrateAnalysis>) -> RustdocVisitor<'a, 'tcx> {
|
|
||||||
// If the root is reexported, terminate all recursion.
|
// If the root is reexported, terminate all recursion.
|
||||||
let mut stack = HashSet::new();
|
let mut stack = HashSet::new();
|
||||||
stack.insert(ast::CRATE_NODE_ID);
|
stack.insert(ast::CRATE_NODE_ID);
|
||||||
@ -56,7 +54,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
module: Module::new(None),
|
module: Module::new(None),
|
||||||
attrs: hir::HirVec::new(),
|
attrs: hir::HirVec::new(),
|
||||||
cx: cx,
|
cx: cx,
|
||||||
analysis: analysis,
|
|
||||||
view_item_stack: stack,
|
view_item_stack: stack,
|
||||||
inlining_from_glob: false,
|
inlining_from_glob: false,
|
||||||
}
|
}
|
||||||
@ -247,13 +244,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||||||
let def_node_id = match tcx.map.as_local_node_id(def) {
|
let def_node_id = match tcx.map.as_local_node_id(def) {
|
||||||
Some(n) => n, None => return false
|
Some(n) => n, None => return false
|
||||||
};
|
};
|
||||||
let analysis = match self.analysis {
|
|
||||||
Some(analysis) => analysis, None => return false
|
|
||||||
};
|
|
||||||
|
|
||||||
let use_attrs = tcx.map.attrs(id).clean(self.cx);
|
let use_attrs = tcx.map.attrs(id).clean(self.cx);
|
||||||
|
|
||||||
let is_private = !analysis.access_levels.is_public(def);
|
let is_private = !self.cx.access_levels.borrow().is_public(def);
|
||||||
let is_hidden = inherits_doc_hidden(self.cx, def_node_id);
|
let is_hidden = inherits_doc_hidden(self.cx, def_node_id);
|
||||||
let is_no_inline = use_attrs.list("doc").has_word("no_inline");
|
let is_no_inline = use_attrs.list("doc").has_word("no_inline");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user