Skip to content

Commit 6dcaa0a

Browse files
committed
Rollup merge of rust-lang#47661 - bjorn3:refactor_driver, r=michaelwoerister
Inline some rustc_driver function
2 parents 117eb68 + c3fabce commit 6dcaa0a

File tree

2 files changed

+22
-39
lines changed

2 files changed

+22
-39
lines changed

src/librustc_driver/driver.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ use std::iter;
5151
use std::path::{Path, PathBuf};
5252
use std::rc::Rc;
5353
use std::sync::mpsc;
54-
use syntax::{ast, diagnostics, visit};
55-
use syntax::attr;
54+
use syntax::{self, ast, attr, diagnostics, visit};
5655
use syntax::ext::base::ExtCtxt;
5756
use syntax::fold::Folder;
5857
use syntax::parse::{self, PResult};
5958
use syntax::util::node_count::NodeCounter;
6059
use syntax_pos::FileName;
61-
use syntax;
6260
use syntax_ext;
6361

6462
use derive_registrar;
@@ -274,10 +272,6 @@ pub fn compile_input(trans: Box<TransCrate>,
274272
Ok(())
275273
}
276274

277-
fn keep_hygiene_data(sess: &Session) -> bool {
278-
sess.opts.debugging_opts.keep_hygiene_data
279-
}
280-
281275
pub fn source_name(input: &Input) -> FileName {
282276
match *input {
283277
Input::File(ref ifile) => ifile.clone().into(),
@@ -851,7 +845,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
851845
|| lint::check_ast_crate(sess, &krate));
852846

853847
// Discard hygiene data, which isn't required after lowering to HIR.
854-
if !keep_hygiene_data(sess) {
848+
if !sess.opts.debugging_opts.keep_hygiene_data {
855849
syntax::ext::hygiene::clear_markings();
856850
}
857851

@@ -915,18 +909,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(trans: &TransCrate,
915909
mpsc::Receiver<Box<Any + Send>>,
916910
CompileResult) -> R
917911
{
918-
macro_rules! try_with_f {
919-
($e: expr, ($($t:tt)*)) => {
920-
match $e {
921-
Ok(x) => x,
922-
Err(x) => {
923-
f($($t)*, Err(x));
924-
return Err(x);
925-
}
926-
}
927-
}
928-
}
929-
930912
let time_passes = sess.time_passes();
931913

932914
let query_result_on_disk_cache = time(time_passes,
@@ -987,7 +969,13 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(trans: &TransCrate,
987969
|| stability::check_unstable_api_usage(tcx));
988970

989971
// passes are timed inside typeck
990-
try_with_f!(typeck::check_crate(tcx), (tcx, analysis, rx));
972+
match typeck::check_crate(tcx) {
973+
Ok(x) => x,
974+
Err(x) => {
975+
f(tcx, analysis, rx, Err(x));
976+
return Err(x);
977+
}
978+
}
991979

992980
time(time_passes,
993981
"const checking",

src/librustc_driver/lib.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
670670
control.after_hir_lowering.stop = Compilation::Stop;
671671
}
672672

673-
if save_analysis(sess) {
673+
if sess.opts.debugging_opts.save_analysis {
674674
enable_save_analysis(&mut control);
675675
}
676676

@@ -705,10 +705,6 @@ pub fn enable_save_analysis(control: &mut CompileController) {
705705
control.make_glob_map = resolve::MakeGlobMap::Yes;
706706
}
707707

708-
fn save_analysis(sess: &Session) -> bool {
709-
sess.opts.debugging_opts.save_analysis
710-
}
711-
712708
impl RustcDefaultCalls {
713709
pub fn list_metadata(sess: &Session,
714710
cstore: &CrateStore,
@@ -1330,20 +1326,19 @@ pub fn diagnostics_registry() -> errors::registry::Registry {
13301326
Registry::new(&all_errors)
13311327
}
13321328

1333-
pub fn get_args() -> Vec<String> {
1334-
env::args_os().enumerate()
1335-
.map(|(i, arg)| arg.into_string().unwrap_or_else(|arg| {
1336-
early_error(ErrorOutputType::default(),
1337-
&format!("Argument {} is not valid Unicode: {:?}", i, arg))
1338-
}))
1339-
.collect()
1340-
}
1341-
13421329
pub fn main() {
13431330
env_logger::init().unwrap();
1344-
let result = run(|| run_compiler(&get_args(),
1345-
&mut RustcDefaultCalls,
1346-
None,
1347-
None));
1331+
let result = run(|| {
1332+
let args = env::args_os().enumerate()
1333+
.map(|(i, arg)| arg.into_string().unwrap_or_else(|arg| {
1334+
early_error(ErrorOutputType::default(),
1335+
&format!("Argument {} is not valid Unicode: {:?}", i, arg))
1336+
}))
1337+
.collect::<Vec<_>>();
1338+
run_compiler(&args,
1339+
&mut RustcDefaultCalls,
1340+
None,
1341+
None)
1342+
});
13481343
process::exit(result as i32);
13491344
}

0 commit comments

Comments
 (0)