1
Fork 0

Pass Session into renderer

This commit is contained in:
Joshua Nelson 2020-12-11 22:36:51 -05:00
parent 39b841dfe3
commit af6aa9f431
4 changed files with 21 additions and 4 deletions

View file

@ -1,5 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use rustc_data_structures::sync::Lrc;
use rustc_session::Session;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use crate::clean; use crate::clean;
@ -19,6 +21,7 @@ crate trait FormatRenderer: Clone {
render_info: RenderInfo, render_info: RenderInfo,
edition: Edition, edition: Edition,
cache: &mut Cache, cache: &mut Cache,
sess: Lrc<Session>,
) -> Result<(Self, clean::Crate), Error>; ) -> Result<(Self, clean::Crate), Error>;
/// Renders a single non-module item. This means no recursive sub-item rendering is required. /// Renders a single non-module item. This means no recursive sub-item rendering is required.
@ -49,6 +52,7 @@ crate fn run_format<T: FormatRenderer>(
render_info: RenderInfo, render_info: RenderInfo,
diag: &rustc_errors::Handler, diag: &rustc_errors::Handler,
edition: Edition, edition: Edition,
sess: Lrc<Session>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let (krate, mut cache) = Cache::from_krate( let (krate, mut cache) = Cache::from_krate(
render_info.clone(), render_info.clone(),
@ -59,7 +63,7 @@ crate fn run_format<T: FormatRenderer>(
); );
let (mut format_renderer, mut krate) = let (mut format_renderer, mut krate) =
T::init(krate, options, render_info, edition, &mut cache)?; T::init(krate, options, render_info, edition, &mut cache, sess)?;
let cache = Arc::new(cache); let cache = Arc::new(cache);
// Freeze the cache now that the index has been built. Put an Arc into TLS for future // Freeze the cache now that the index has been built. Put an Arc into TLS for future

View file

@ -52,10 +52,12 @@ use rustc_ast_pretty::pprust;
use rustc_attr::StabilityLevel; use rustc_attr::StabilityLevel;
use rustc_data_structures::flock; use rustc_data_structures::flock;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::Mutability; use rustc_hir::Mutability;
use rustc_middle::middle::stability; use rustc_middle::middle::stability;
use rustc_session::Session;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::hygiene::MacroKind; use rustc_span::hygiene::MacroKind;
use rustc_span::source_map::FileName; use rustc_span::source_map::FileName;
@ -101,6 +103,7 @@ crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
/// rustdoc tree). /// rustdoc tree).
#[derive(Clone)] #[derive(Clone)]
crate struct Context { crate struct Context {
crate sess: Lrc<Session>,
/// Current hierarchy of components leading down to what's currently being /// Current hierarchy of components leading down to what's currently being
/// rendered /// rendered
crate current: Vec<String>, crate current: Vec<String>,
@ -383,6 +386,7 @@ impl FormatRenderer for Context {
_render_info: RenderInfo, _render_info: RenderInfo,
edition: Edition, edition: Edition,
cache: &mut Cache, cache: &mut Cache,
sess: Lrc<Session>,
) -> Result<(Context, clean::Crate), Error> { ) -> Result<(Context, clean::Crate), Error> {
// need to save a copy of the options for rendering the index page // need to save a copy of the options for rendering the index page
let md_opts = options.clone(); let md_opts = options.clone();
@ -494,6 +498,7 @@ impl FormatRenderer for Context {
let cache = Arc::new(cache); let cache = Arc::new(cache);
let mut cx = Context { let mut cx = Context {
sess,
current: Vec::new(), current: Vec::new(),
dst, dst,
render_redirect_pages: false, render_redirect_pages: false,

View file

@ -13,6 +13,8 @@ use std::path::PathBuf;
use std::rc::Rc; use std::rc::Rc;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc;
use rustc_session::Session;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use crate::clean; use crate::clean;
@ -124,6 +126,7 @@ impl FormatRenderer for JsonRenderer {
_render_info: RenderInfo, _render_info: RenderInfo,
_edition: Edition, _edition: Edition,
_cache: &mut Cache, _cache: &mut Cache,
_sess: Lrc<Session>,
) -> Result<(Self, clean::Crate), Error> { ) -> Result<(Self, clean::Crate), Error> {
debug!("Initializing json renderer"); debug!("Initializing json renderer");
Ok(( Ok((

View file

@ -61,9 +61,11 @@ use std::default::Default;
use std::env; use std::env;
use std::process; use std::process;
use rustc_data_structures::sync::Lrc;
use rustc_errors::ErrorReported; use rustc_errors::ErrorReported;
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup}; use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
use rustc_session::getopts; use rustc_session::getopts;
use rustc_session::Session;
use rustc_session::{early_error, early_warn}; use rustc_session::{early_error, early_warn};
#[macro_use] #[macro_use]
@ -483,8 +485,9 @@ fn run_renderer<T: formats::FormatRenderer>(
render_info: config::RenderInfo, render_info: config::RenderInfo,
diag: &rustc_errors::Handler, diag: &rustc_errors::Handler,
edition: rustc_span::edition::Edition, edition: rustc_span::edition::Edition,
sess: Lrc<Session>,
) -> MainResult { ) -> MainResult {
match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition) { match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition, sess) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(e) => { Err(e) => {
let mut msg = diag.struct_err(&format!("couldn't generate documentation: {}", e.error)); let mut msg = diag.struct_err(&format!("couldn't generate documentation: {}", e.error));
@ -554,10 +557,12 @@ fn main_options(options: config::Options) -> MainResult {
let diag = core::new_handler(error_format, None, &debugging_options); let diag = core::new_handler(error_format, None, &debugging_options);
match output_format { match output_format {
None | Some(config::OutputFormat::Html) => sess.time("render_html", || { None | Some(config::OutputFormat::Html) => sess.time("render_html", || {
run_renderer::<html::render::Context>(krate, renderopts, renderinfo, &diag, edition) run_renderer::<html::render::Context>(
krate, renderopts, renderinfo, &diag, edition, sess,
)
}), }),
Some(config::OutputFormat::Json) => sess.time("render_json", || { Some(config::OutputFormat::Json) => sess.time("render_json", || {
run_renderer::<json::JsonRenderer>(krate, renderopts, renderinfo, &diag, edition) run_renderer::<json::JsonRenderer>(krate, renderopts, renderinfo, &diag, edition, sess)
}), }),
} }
} }