Skip to content

Commit f0e1e09

Browse files
committed
Review changes
1 parent cacd6b6 commit f0e1e09

File tree

5 files changed

+61
-39
lines changed

5 files changed

+61
-39
lines changed

src/librustc/session/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use syntax::parse::token::InternedString;
3636
use getopts;
3737
use std::collections::HashMap;
3838
use std::collections::hash_map::Entry::{Occupied, Vacant};
39+
use std::env;
3940
use std::fmt;
40-
use std::os;
4141

4242
use llvm;
4343

src/librustc_driver/driver.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -27,6 +27,7 @@ use rustc_trans::back::write;
2727
use rustc_trans::trans;
2828
use rustc_typeck as typeck;
2929
use rustc_privacy;
30+
use super::Compilation;
3031

3132
use serialize::json;
3233

@@ -55,7 +56,7 @@ pub fn compile_input(sess: Session,
5556
let state = $make_state;
5657
(control.$point.callback)(state);
5758
}
58-
if control.$point.stop {
59+
if control.$point.stop == Compilation::Stop {
5960
return;
6061
}
6162
})}
@@ -206,14 +207,14 @@ impl<'a> CompileController<'a> {
206207
}
207208

208209
pub struct PhaseController<'a> {
209-
pub stop: bool,
210+
pub stop: Compilation,
210211
pub callback: Box<Fn(CompileState) -> () + 'a>,
211212
}
212213

213214
impl<'a> PhaseController<'a> {
214215
pub fn basic() -> PhaseController<'a> {
215216
PhaseController {
216-
stop: false,
217+
stop: Compilation::Continue,
217218
callback: box |_| {},
218219
}
219220
}

src/librustc_driver/lib.rs

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -108,8 +108,9 @@ pub fn run(args: Vec<String>) -> int {
108108
pub fn run_compiler<'a>(args: &[String],
109109
callbacks: &mut CompilerCalls<'a>) {
110110
macro_rules! do_or_return {($expr: expr) => {
111-
if $expr {
112-
return;
111+
match $expr {
112+
Compilation::Stop => return,
113+
Compilation::Continue => {}
113114
}
114115
}}
115116

@@ -144,7 +145,7 @@ pub fn run_compiler<'a>(args: &[String],
144145
// It is somewhat unfortunate that this is hardwired in - this is forced by
145146
// the fact that pretty_print_input requires the session by value.
146147
let pretty = callbacks.parse_pretty(&sess, &matches);
147-
match pretty.into_iter().next() {
148+
match pretty {
148149
Some((ppm, opt_uii)) => {
149150
pretty::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);
150151
return;
@@ -180,26 +181,43 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option<Path>)> {
180181
}
181182
}
182183

184+
// Whether to stop or continue compilation.
185+
#[derive(Copy, Debug, Eq, PartialEq)]
186+
pub enum Compilation {
187+
Stop,
188+
Continue,
189+
}
190+
191+
impl Compilation {
192+
pub fn and_then<F: FnOnce() -> Compilation>(self, next: F) -> Compilation {
193+
match self {
194+
Compilation::Stop => Compilation::Stop,
195+
Compilation::Continue => next()
196+
}
197+
}
198+
}
199+
183200
// A trait for customising the compilation process. Offers a number of hooks for
184201
// executing custom code or customising input.
185202
pub trait CompilerCalls<'a> {
186203
// Hook for a callback early in the process of handling arguments. This will
187204
// be called straight after options have been parsed but before anything
188-
// else (e.g., selecting input and output). Return true to terminate compilation,
189-
// false to continue.
190-
fn early_callback(&mut self, &getopts::Matches, &diagnostics::registry::Registry) -> bool;
205+
// else (e.g., selecting input and output).
206+
fn early_callback(&mut self,
207+
&getopts::Matches,
208+
&diagnostics::registry::Registry)
209+
-> Compilation;
191210

192211
// Hook for a callback late in the process of handling arguments. This will
193212
// be called just before actual compilation starts (and before build_controller
194-
// is called), after all arguments etc. have been completely handled. Return
195-
// true to terminate compilation, false to continue.
213+
// is called), after all arguments etc. have been completely handled.
196214
fn late_callback(&mut self,
197215
&getopts::Matches,
198216
&Session,
199217
&Input,
200218
&Option<Path>,
201219
&Option<Path>)
202-
-> bool;
220+
-> Compilation;
203221

204222
// Called after we extract the input from the arguments. Gives the implementer
205223
// an opportunity to change the inputs or to add some custom input handling.
@@ -253,7 +271,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
253271
fn early_callback(&mut self,
254272
matches: &getopts::Matches,
255273
descriptions: &diagnostics::registry::Registry)
256-
-> bool {
274+
-> Compilation {
257275
match matches.opt_str("explain") {
258276
Some(ref code) => {
259277
match descriptions.find_description(&code[]) {
@@ -264,12 +282,12 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
264282
early_error(&format!("no extended information for {}", code)[]);
265283
}
266284
}
267-
return true;
285+
return Compilation::Stop;
268286
},
269287
None => ()
270288
}
271289

272-
return false;
290+
return Compilation::Continue;
273291
}
274292

275293
fn no_input(&mut self,
@@ -288,7 +306,8 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
288306
return None;
289307
}
290308
let sess = build_session(sopts.clone(), None, descriptions.clone());
291-
if RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile) {
309+
let should_stop = RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile);
310+
if should_stop == Compilation::Stop {
292311
return None;
293312
}
294313
early_error("no input filename given");
@@ -328,9 +347,9 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
328347
input: &Input,
329348
odir: &Option<Path>,
330349
ofile: &Option<Path>)
331-
-> bool {
332-
RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile) ||
333-
RustcDefaultCalls::list_metadata(sess, matches, input)
350+
-> Compilation {
351+
RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile).and_then(
352+
|| RustcDefaultCalls::list_metadata(sess, matches, input))
334353
}
335354

336355
fn build_controller(&mut self, sess: &Session) -> CompileController<'a> {
@@ -339,19 +358,19 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
339358
if sess.opts.parse_only ||
340359
sess.opts.show_span.is_some() ||
341360
sess.opts.debugging_opts.ast_json_noexpand {
342-
control.after_parse.stop = true;
361+
control.after_parse.stop = Compilation::Stop;
343362
}
344363

345364
if sess.opts.no_analysis || sess.opts.debugging_opts.ast_json {
346-
control.after_write_deps.stop = true;
365+
control.after_write_deps.stop = Compilation::Stop;
347366
}
348367

349368
if sess.opts.no_trans {
350-
control.after_analysis.stop = true;
369+
control.after_analysis.stop = Compilation::Stop;
351370
}
352371

353372
if !sess.opts.output_types.iter().any(|&i| i == config::OutputTypeExe) {
354-
control.after_llvm.stop = true;
373+
control.after_llvm.stop = Compilation::Stop;
355374
}
356375

357376
if sess.opts.debugging_opts.save_analysis {
@@ -373,7 +392,7 @@ impl RustcDefaultCalls {
373392
pub fn list_metadata(sess: &Session,
374393
matches: &getopts::Matches,
375394
input: &Input)
376-
-> bool {
395+
-> Compilation {
377396
let r = matches.opt_strs("Z");
378397
if r.contains(&("ls".to_string())) {
379398
match input {
@@ -388,20 +407,20 @@ impl RustcDefaultCalls {
388407
early_error("cannot list metadata for stdin");
389408
}
390409
}
391-
return true;
410+
return Compilation::Stop;
392411
}
393412

394-
return false;
413+
return Compilation::Continue;
395414
}
396415

397416

398417
fn print_crate_info(sess: &Session,
399418
input: Option<&Input>,
400419
odir: &Option<Path>,
401420
ofile: &Option<Path>)
402-
-> bool {
421+
-> Compilation {
403422
if sess.opts.prints.len() == 0 {
404-
return false
423+
return Compilation::Continue;
405424
}
406425

407426
let attrs = input.map(|input| parse_crate_attrs(sess, input));
@@ -440,7 +459,7 @@ impl RustcDefaultCalls {
440459
}
441460
}
442461
}
443-
return true;
462+
return Compilation::Stop;
444463
}
445464
}
446465

src/librustdoc/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use testing;
2323
use rustc::session::{self, config};
2424
use rustc::session::config::get_unstable_features_setting;
2525
use rustc::session::search_paths::{SearchPaths, PathKind};
26-
use rustc_driver::driver;
26+
use rustc_driver::{driver, Compilation};
2727
use syntax::ast;
2828
use syntax::codemap::{CodeMap, dummy_spanned};
2929
use syntax::diagnostic;
@@ -178,7 +178,7 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths,
178178
let libdir = sess.target_filesearch(PathKind::All).get_lib_path();
179179
let mut control = driver::CompileController::basic();
180180
if no_run {
181-
control.after_analysis.stop = true;
181+
control.after_analysis.stop = Compilation::Stop;
182182
}
183183
driver::compile_input(sess, cfg, &input, &out, &None, None, control);
184184

src/test/run-pass-fulldeps/compiler-calls.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// Test that the CompilerCalls interface to the compiler works.
1212

13+
// ignore-android
14+
1315
#![feature(rustc_private)]
1416
#![feature(core)]
1517

@@ -20,7 +22,7 @@ extern crate syntax;
2022

2123
use rustc::session::Session;
2224
use rustc::session::config::{self, Input};
23-
use rustc_driver::{driver, CompilerCalls};
25+
use rustc_driver::{driver, CompilerCalls, Compilation};
2426
use syntax::diagnostics;
2527

2628

@@ -32,9 +34,9 @@ impl<'a> CompilerCalls<'a> for TestCalls {
3234
fn early_callback(&mut self,
3335
_: &getopts::Matches,
3436
_: &diagnostics::registry::Registry)
35-
-> bool {
37+
-> Compilation {
3638
self.count *= 2;
37-
false
39+
Compilation::Continue
3840
}
3941

4042
fn late_callback(&mut self,
@@ -43,9 +45,9 @@ impl<'a> CompilerCalls<'a> for TestCalls {
4345
_: &Input,
4446
_: &Option<Path>,
4547
_: &Option<Path>)
46-
-> bool {
48+
-> Compilation {
4749
self.count *= 3;
48-
true
50+
Compilation::Stop
4951
}
5052

5153
fn some_input(&mut self, input: Input, input_path: Option<Path>) -> (Input, Option<Path>) {

0 commit comments

Comments
 (0)