[tmp] Pass TyCtxt through to the render backend

First actually useful step in https://github.com/rust-lang/rust/issues/76382

This doesn't yet compile because there's no way to get a `Lrc<Session>`
from a TyCtxt, only a `&Session`.
This commit is contained in:
Joshua Nelson 2020-12-16 14:23:14 -05:00
parent 79ab333cf0
commit 9221d4d1d3
4 changed files with 15 additions and 17 deletions

View file

@ -1,7 +1,6 @@
use std::sync::Arc; use std::sync::Arc;
use rustc_data_structures::sync::Lrc; use rustc_middle::ty;
use rustc_session::Session;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use crate::clean; use crate::clean;
@ -21,7 +20,7 @@ crate trait FormatRenderer: Clone {
render_info: RenderInfo, render_info: RenderInfo,
edition: Edition, edition: Edition,
cache: &mut Cache, cache: &mut Cache,
sess: Lrc<Session>, tcx: ty::TyCtxt<'_>,
) -> 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.
@ -52,7 +51,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>, tcx: ty::TyCtxt<'_>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let (krate, mut cache) = Cache::from_krate( let (krate, mut cache) = Cache::from_krate(
render_info.clone(), render_info.clone(),
@ -63,7 +62,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, sess)?; T::init(krate, options, render_info, edition, &mut cache, tcx)?;
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

@ -57,6 +57,7 @@ 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_middle::ty;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::hygiene::MacroKind; use rustc_span::hygiene::MacroKind;
@ -388,7 +389,7 @@ impl FormatRenderer for Context {
_render_info: RenderInfo, _render_info: RenderInfo,
edition: Edition, edition: Edition,
cache: &mut Cache, cache: &mut Cache,
sess: Lrc<Session>, tcx: ty::TyCtxt<'_>,
) -> 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();
@ -462,7 +463,7 @@ impl FormatRenderer for Context {
} }
let (sender, receiver) = channel(); let (sender, receiver) = channel();
let mut scx = SharedContext { let mut scx = SharedContext {
sess, tcx,
collapsed: krate.collapsed, collapsed: krate.collapsed,
src_root, src_root,
include_sources, include_sources,

View file

@ -14,6 +14,7 @@ use std::rc::Rc;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_middle::ty;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
@ -127,12 +128,12 @@ impl FormatRenderer for JsonRenderer {
_render_info: RenderInfo, _render_info: RenderInfo,
_edition: Edition, _edition: Edition,
_cache: &mut Cache, _cache: &mut Cache,
sess: Lrc<Session>, tcx: ty::TyCtxt<'_>,
) -> Result<(Self, clean::Crate), Error> { ) -> Result<(Self, clean::Crate), Error> {
debug!("Initializing json renderer"); debug!("Initializing json renderer");
Ok(( Ok((
JsonRenderer { JsonRenderer {
sess, sess: tcx.sess,
index: Rc::new(RefCell::new(FxHashMap::default())), index: Rc::new(RefCell::new(FxHashMap::default())),
out_path: options.output, out_path: options.output,
}, },

View file

@ -62,13 +62,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_driver::abort_on_err; use rustc_driver::abort_on_err;
use rustc_errors::ErrorReported; use rustc_errors::ErrorReported;
use rustc_interface::interface; use rustc_middle::ty;
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]
@ -476,9 +474,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>, tcx: ty::TyCtxt<'_>,
) -> MainResult { ) -> MainResult {
match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition, sess) { match formats::run_format::<T>(krate, renderopts, render_info, &diag, edition, tcx) {
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));
@ -577,7 +575,6 @@ fn main_options(options: config::Options) -> MainResult {
info!("going to format"); info!("going to format");
let (error_format, edition, debugging_options) = diag_opts; let (error_format, edition, debugging_options) = diag_opts;
let diag = core::new_handler(error_format, None, &debugging_options); let diag = core::new_handler(error_format, None, &debugging_options);
let sess_format = sess.clone();
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>( run_renderer::<html::render::Context>(
@ -586,7 +583,7 @@ fn main_options(options: config::Options) -> MainResult {
render_info, render_info,
&diag, &diag,
edition, edition,
sess_format, tcx,
) )
}), }),
Some(config::OutputFormat::Json) => sess.time("render_json", || { Some(config::OutputFormat::Json) => sess.time("render_json", || {
@ -596,7 +593,7 @@ fn main_options(options: config::Options) -> MainResult {
render_info, render_info,
&diag, &diag,
edition, edition,
sess_format, tcx,
) )
}), }),
} }