Remove the cstore reference from Session in order to prepare encapsulating CrateStore access in tcx.
This commit is contained in:
parent
817e1b81e2
commit
54fa047d92
22 changed files with 135 additions and 85 deletions
|
|
@ -21,6 +21,7 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
|
|||
use rustc::session::search_paths::PathKind;
|
||||
use rustc::lint;
|
||||
use rustc::middle::{self, stability, reachable};
|
||||
use rustc::middle::cstore::CrateStore;
|
||||
use rustc::middle::privacy::AccessLevels;
|
||||
use rustc::mir::transform::{MIR_CONST, MIR_VALIDATED, MIR_OPTIMIZED, Passes};
|
||||
use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
|
||||
|
|
@ -200,6 +201,7 @@ pub fn compile_input(sess: &Session,
|
|||
};
|
||||
|
||||
phase_3_run_analysis_passes(sess,
|
||||
cstore,
|
||||
hir_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
|
|
@ -272,7 +274,7 @@ pub fn compile_input(sess: &Session,
|
|||
phase5_result);
|
||||
phase5_result?;
|
||||
|
||||
phase_6_link_output(sess, &trans, &outputs);
|
||||
phase_6_link_output(sess, cstore, &trans, &outputs);
|
||||
|
||||
// Now that we won't touch anything in the incremental compilation directory
|
||||
// any more, we can finalize it (which involves renaming it)
|
||||
|
|
@ -385,7 +387,7 @@ pub struct CompileState<'a, 'tcx: 'a> {
|
|||
pub session: &'tcx Session,
|
||||
pub krate: Option<ast::Crate>,
|
||||
pub registry: Option<Registry<'a>>,
|
||||
pub cstore: Option<&'a CStore>,
|
||||
pub cstore: Option<&'tcx CStore>,
|
||||
pub crate_name: Option<&'a str>,
|
||||
pub output_filenames: Option<&'a OutputFilenames>,
|
||||
pub out_dir: Option<&'a Path>,
|
||||
|
|
@ -433,7 +435,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
|
|||
out_dir: &'a Option<PathBuf>,
|
||||
out_file: &'a Option<PathBuf>,
|
||||
krate: ast::Crate,
|
||||
cstore: &'a CStore)
|
||||
cstore: &'tcx CStore)
|
||||
-> Self {
|
||||
CompileState {
|
||||
// Initialize the registry before moving `krate`
|
||||
|
|
@ -449,7 +451,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
|
|||
session: &'tcx Session,
|
||||
out_dir: &'a Option<PathBuf>,
|
||||
out_file: &'a Option<PathBuf>,
|
||||
cstore: &'a CStore,
|
||||
cstore: &'tcx CStore,
|
||||
expanded_crate: &'a ast::Crate,
|
||||
crate_name: &'a str)
|
||||
-> Self {
|
||||
|
|
@ -468,7 +470,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
|
|||
out_file: &'a Option<PathBuf>,
|
||||
arena: &'tcx DroplessArena,
|
||||
arenas: &'tcx GlobalArenas<'tcx>,
|
||||
cstore: &'a CStore,
|
||||
cstore: &'tcx CStore,
|
||||
hir_map: &'a hir_map::Map<'tcx>,
|
||||
analysis: &'a ty::CrateAnalysis,
|
||||
resolutions: &'a Resolutions,
|
||||
|
|
@ -696,6 +698,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
|
|||
let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name);
|
||||
let resolver_arenas = Resolver::arenas();
|
||||
let mut resolver = Resolver::new(sess,
|
||||
cstore,
|
||||
&krate,
|
||||
crate_name,
|
||||
make_glob_map,
|
||||
|
|
@ -844,7 +847,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
|
|||
|
||||
// Lower ast -> hir.
|
||||
let hir_forest = time(time_passes, "lowering ast -> hir", || {
|
||||
let hir_crate = lower_crate(sess, &krate, &mut resolver);
|
||||
let hir_crate = lower_crate(sess, cstore, &krate, &mut resolver);
|
||||
|
||||
if sess.opts.debugging_opts.hir_stats {
|
||||
hir_stats::print_hir_stats(&hir_crate);
|
||||
|
|
@ -886,6 +889,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
|
|||
/// miscellaneous analysis passes on the crate. Return various
|
||||
/// structures carrying the results of the analysis.
|
||||
pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
|
||||
cstore: &'tcx CrateStore,
|
||||
hir_map: hir_map::Map<'tcx>,
|
||||
mut analysis: ty::CrateAnalysis,
|
||||
resolutions: Resolutions,
|
||||
|
|
@ -915,7 +919,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
|
|||
|
||||
let named_region_map = time(time_passes,
|
||||
"lifetime resolution",
|
||||
|| middle::resolve_lifetime::krate(sess, &hir_map))?;
|
||||
|| middle::resolve_lifetime::krate(sess, cstore, &hir_map))?;
|
||||
|
||||
time(time_passes,
|
||||
"looking for entry point",
|
||||
|
|
@ -1012,6 +1016,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
|
|||
passes.push_pass(MIR_OPTIMIZED, mir::transform::dump_mir::Marker("PreTrans"));
|
||||
|
||||
TyCtxt::create_and_enter(sess,
|
||||
cstore,
|
||||
local_providers,
|
||||
extern_providers,
|
||||
Rc::new(passes),
|
||||
|
|
@ -1148,10 +1153,15 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
|
|||
/// This should produce either a finished executable or library.
|
||||
#[cfg(feature="llvm")]
|
||||
pub fn phase_6_link_output(sess: &Session,
|
||||
cstore: &CrateStore,
|
||||
trans: &trans::CrateTranslation,
|
||||
outputs: &OutputFilenames) {
|
||||
time(sess.time_passes(), "linking", || {
|
||||
::rustc_trans::back::link::link_binary(sess, trans, outputs, &trans.crate_name.as_str())
|
||||
::rustc_trans::back::link::link_binary(sess,
|
||||
cstore,
|
||||
trans,
|
||||
outputs,
|
||||
&trans.crate_name.as_str())
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ use rustc::session::config::nightly_options;
|
|||
use rustc::session::{early_error, early_warn};
|
||||
use rustc::lint::Lint;
|
||||
use rustc::lint;
|
||||
use rustc::middle::cstore::CrateStore;
|
||||
use rustc_metadata::locator;
|
||||
use rustc_metadata::cstore::CStore;
|
||||
use rustc::util::common::{time, ErrorReported};
|
||||
|
|
@ -299,7 +300,7 @@ pub fn run_compiler<'a>(args: &[String],
|
|||
let loader = file_loader.unwrap_or(box RealFileLoader);
|
||||
let codemap = Rc::new(CodeMap::with_file_loader(loader, sopts.file_path_mapping()));
|
||||
let mut sess = session::build_session_with_codemap(
|
||||
sopts, &dep_graph, input_file_path, descriptions, cstore.clone(), codemap, emitter_dest,
|
||||
sopts, &dep_graph, input_file_path, descriptions, codemap, emitter_dest,
|
||||
);
|
||||
rustc_trans::init(&sess);
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
|
|
@ -308,7 +309,12 @@ pub fn run_compiler<'a>(args: &[String],
|
|||
target_features::add_configuration(&mut cfg, &sess);
|
||||
sess.parse_sess.config = cfg;
|
||||
|
||||
do_or_return!(callbacks.late_callback(&matches, &sess, &input, &odir, &ofile), Some(sess));
|
||||
do_or_return!(callbacks.late_callback(&matches,
|
||||
&sess,
|
||||
&*cstore,
|
||||
&input,
|
||||
&odir,
|
||||
&ofile), Some(sess));
|
||||
|
||||
let plugins = sess.opts.debugging_opts.extra_plugins.clone();
|
||||
let control = callbacks.build_controller(&sess, &matches);
|
||||
|
|
@ -400,6 +406,7 @@ pub trait CompilerCalls<'a> {
|
|||
fn late_callback(&mut self,
|
||||
_: &getopts::Matches,
|
||||
_: &Session,
|
||||
_: &CrateStore,
|
||||
_: &Input,
|
||||
_: &Option<PathBuf>,
|
||||
_: &Option<PathBuf>)
|
||||
|
|
@ -574,12 +581,10 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||
return None;
|
||||
}
|
||||
let dep_graph = DepGraph::new(sopts.build_dep_graph());
|
||||
let cstore = Rc::new(CStore::new(box ::MetadataLoader));
|
||||
let mut sess = build_session(sopts.clone(),
|
||||
&dep_graph,
|
||||
None,
|
||||
descriptions.clone(),
|
||||
cstore.clone());
|
||||
descriptions.clone());
|
||||
rustc_trans::init(&sess);
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
let mut cfg = config::build_configuration(&sess, cfg.clone());
|
||||
|
|
@ -601,12 +606,13 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||
fn late_callback(&mut self,
|
||||
matches: &getopts::Matches,
|
||||
sess: &Session,
|
||||
cstore: &CrateStore,
|
||||
input: &Input,
|
||||
odir: &Option<PathBuf>,
|
||||
ofile: &Option<PathBuf>)
|
||||
-> Compilation {
|
||||
RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile)
|
||||
.and_then(|| RustcDefaultCalls::list_metadata(sess, matches, input))
|
||||
.and_then(|| RustcDefaultCalls::list_metadata(sess, cstore, matches, input))
|
||||
}
|
||||
|
||||
fn build_controller(&mut self,
|
||||
|
|
@ -627,6 +633,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
|
|||
};
|
||||
control.after_hir_lowering.callback = box move |state| {
|
||||
pretty::print_after_hir_lowering(state.session,
|
||||
state.cstore.unwrap(),
|
||||
state.hir_map.unwrap(),
|
||||
state.analysis.unwrap(),
|
||||
state.resolutions.unwrap(),
|
||||
|
|
@ -711,7 +718,11 @@ fn save_analysis(sess: &Session) -> bool {
|
|||
}
|
||||
|
||||
impl RustcDefaultCalls {
|
||||
pub fn list_metadata(sess: &Session, matches: &getopts::Matches, input: &Input) -> Compilation {
|
||||
pub fn list_metadata(sess: &Session,
|
||||
cstore: &CrateStore,
|
||||
matches: &getopts::Matches,
|
||||
input: &Input)
|
||||
-> Compilation {
|
||||
let r = matches.opt_strs("Z");
|
||||
if r.contains(&("ls".to_string())) {
|
||||
match input {
|
||||
|
|
@ -720,7 +731,7 @@ impl RustcDefaultCalls {
|
|||
let mut v = Vec::new();
|
||||
locator::list_file_metadata(&sess.target.target,
|
||||
path,
|
||||
sess.cstore.metadata_loader(),
|
||||
cstore.metadata_loader(),
|
||||
&mut v)
|
||||
.unwrap();
|
||||
println!("{}", String::from_utf8(v).unwrap());
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use rustc::ty::{self, TyCtxt, GlobalArenas, Resolutions};
|
|||
use rustc::cfg;
|
||||
use rustc::cfg::graphviz::LabelledCFG;
|
||||
use rustc::dep_graph::DepGraph;
|
||||
use rustc::middle::cstore::CrateStore;
|
||||
use rustc::session::Session;
|
||||
use rustc::session::config::Input;
|
||||
use rustc_borrowck as borrowck;
|
||||
|
|
@ -198,6 +199,7 @@ impl PpSourceMode {
|
|||
}
|
||||
fn call_with_pp_support_hir<'tcx, A, F>(&self,
|
||||
sess: &'tcx Session,
|
||||
cstore: &'tcx CrateStore,
|
||||
hir_map: &hir_map::Map<'tcx>,
|
||||
analysis: &ty::CrateAnalysis,
|
||||
resolutions: &Resolutions,
|
||||
|
|
@ -226,6 +228,7 @@ impl PpSourceMode {
|
|||
}
|
||||
PpmTyped => {
|
||||
abort_on_err(driver::phase_3_run_analysis_passes(sess,
|
||||
cstore,
|
||||
hir_map.clone(),
|
||||
analysis.clone(),
|
||||
resolutions.clone(),
|
||||
|
|
@ -875,6 +878,7 @@ pub fn print_after_parsing(sess: &Session,
|
|||
}
|
||||
|
||||
pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
cstore: &'tcx CrateStore,
|
||||
hir_map: &hir_map::Map<'tcx>,
|
||||
analysis: &ty::CrateAnalysis,
|
||||
resolutions: &Resolutions,
|
||||
|
|
@ -891,6 +895,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
|||
|
||||
if ppm.needs_analysis() {
|
||||
print_with_analysis(sess,
|
||||
cstore,
|
||||
hir_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
|
|
@ -929,6 +934,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
|||
(PpmHir(s), None) => {
|
||||
let out: &mut Write = &mut out;
|
||||
s.call_with_pp_support_hir(sess,
|
||||
cstore,
|
||||
hir_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
|
|
@ -952,6 +958,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
|||
(PpmHir(s), Some(uii)) => {
|
||||
let out: &mut Write = &mut out;
|
||||
s.call_with_pp_support_hir(sess,
|
||||
cstore,
|
||||
hir_map,
|
||||
analysis,
|
||||
resolutions,
|
||||
|
|
@ -993,6 +1000,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
|
|||
// with a different callback than the standard driver, so that isn't easy.
|
||||
// Instead, we call that function ourselves.
|
||||
fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
|
||||
cstore: &'a CrateStore,
|
||||
hir_map: &hir_map::Map<'tcx>,
|
||||
analysis: &ty::CrateAnalysis,
|
||||
resolutions: &Resolutions,
|
||||
|
|
@ -1013,6 +1021,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
|
|||
let mut out = Vec::new();
|
||||
|
||||
abort_on_err(driver::phase_3_run_analysis_passes(sess,
|
||||
cstore,
|
||||
hir_map.clone(),
|
||||
analysis.clone(),
|
||||
resolutions.clone(),
|
||||
|
|
|
|||
|
|
@ -109,8 +109,7 @@ fn test_env<F>(source_string: &str,
|
|||
&dep_graph,
|
||||
None,
|
||||
diagnostic_handler,
|
||||
Rc::new(CodeMap::new(FilePathMapping::empty())),
|
||||
cstore.clone());
|
||||
Rc::new(CodeMap::new(FilePathMapping::empty())));
|
||||
rustc_trans::init(&sess);
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
let input = config::Input::Str {
|
||||
|
|
@ -138,8 +137,9 @@ fn test_env<F>(source_string: &str,
|
|||
let hir_map = hir_map::map_crate(&mut hir_forest, defs);
|
||||
|
||||
// run just enough stuff to build a tcx:
|
||||
let named_region_map = resolve_lifetime::krate(&sess, &hir_map);
|
||||
let named_region_map = resolve_lifetime::krate(&sess, &*cstore, &hir_map);
|
||||
TyCtxt::create_and_enter(&sess,
|
||||
&*cstore,
|
||||
ty::maps::Providers::default(),
|
||||
ty::maps::Providers::default(),
|
||||
Rc::new(Passes::new()),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue