Skip to content

Commit a8a1fa2

Browse files
committed
---
yaml --- r: 277979 b: refs/heads/auto c: 7ee02d9 h: refs/heads/master i: 277977: c6898c2 277975: 78a6a9b
1 parent 12e580c commit a8a1fa2

File tree

5 files changed

+81
-81
lines changed

5 files changed

+81
-81
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: a4000cbbf8be9f21884077bee1361b5221e1f78f
11+
refs/heads/auto: 7ee02d9f4d94f6a826d10529419b64a4ccd2a405
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/librustc_driver/driver.rs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub fn compile_input(sess: &Session,
7070
control: &CompileController) -> CompileResult {
7171
macro_rules! controller_entry_point {
7272
($point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => {{
73-
let state = $make_state;
73+
let state = &mut $make_state;
7474
let phase_result: &CompileResult = &$phase_result;
7575
if phase_result.is_ok() || control.$point.run_callback_on_error {
7676
(control.$point.callback)(state);
@@ -95,10 +95,17 @@ pub fn compile_input(sess: &Session,
9595
}
9696
};
9797

98+
let mut compile_state = CompileState::state_after_parse(input,
99+
sess,
100+
outdir,
101+
output,
102+
krate,
103+
&cstore);
98104
controller_entry_point!(after_parse,
99105
sess,
100-
CompileState::state_after_parse(input, sess, outdir, &krate),
106+
compile_state,
101107
Ok(()));
108+
let krate = compile_state.krate.unwrap();
102109

103110
let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess);
104111
let id = link::find_crate_name(Some(sess), &krate.attrs, input);
@@ -194,16 +201,16 @@ pub fn compile_input(sess: &Session,
194201
// Eventually, we will want to track plugins.
195202
let _ignore = tcx.dep_graph.in_ignore();
196203

197-
let state = CompileState::state_after_analysis(input,
198-
&tcx.sess,
199-
outdir,
200-
opt_crate,
201-
tcx.map.krate(),
202-
&analysis,
203-
mir_map.as_ref(),
204-
tcx,
205-
&id);
206-
(control.after_analysis.callback)(state);
204+
let mut state = CompileState::state_after_analysis(input,
205+
&tcx.sess,
206+
outdir,
207+
opt_crate,
208+
tcx.map.krate(),
209+
&analysis,
210+
mir_map.as_ref(),
211+
tcx,
212+
&id);
213+
(control.after_analysis.callback)(&mut state);
207214

208215
if control.after_analysis.stop == Compilation::Stop {
209216
return result.and_then(|_| Err(0usize));
@@ -311,7 +318,7 @@ pub struct PhaseController<'a> {
311318
// If true then the compiler will try to run the callback even if the phase
312319
// ends with an error. Note that this is not always possible.
313320
pub run_callback_on_error: bool,
314-
pub callback: Box<Fn(CompileState) -> () + 'a>,
321+
pub callback: Box<Fn(&mut CompileState) + 'a>,
315322
}
316323

317324
impl<'a> PhaseController<'a> {
@@ -330,11 +337,12 @@ impl<'a> PhaseController<'a> {
330337
pub struct CompileState<'a, 'ast: 'a, 'tcx: 'a> {
331338
pub input: &'a Input,
332339
pub session: &'a Session,
333-
pub cfg: Option<&'a ast::CrateConfig>,
334-
pub krate: Option<&'a ast::Crate>,
340+
pub krate: Option<ast::Crate>,
341+
pub cstore: Option<&'a CStore>,
335342
pub crate_name: Option<&'a str>,
336343
pub output_filenames: Option<&'a OutputFilenames>,
337344
pub out_dir: Option<&'a Path>,
345+
pub out_file: Option<&'a Path>,
338346
pub expanded_crate: Option<&'a ast::Crate>,
339347
pub hir_crate: Option<&'a hir::Crate>,
340348
pub ast_map: Option<&'a hir_map::Map<'ast>>,
@@ -353,8 +361,9 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
353361
input: input,
354362
session: session,
355363
out_dir: out_dir.as_ref().map(|s| &**s),
356-
cfg: None,
364+
out_file: None,
357365
krate: None,
366+
cstore: None,
358367
crate_name: None,
359368
output_filenames: None,
360369
expanded_crate: None,
@@ -370,9 +379,16 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
370379
fn state_after_parse(input: &'a Input,
371380
session: &'a Session,
372381
out_dir: &'a Option<PathBuf>,
373-
krate: &'a ast::Crate)
382+
out_file: &'a Option<PathBuf>,
383+
krate: ast::Crate,
384+
cstore: &'a CStore)
374385
-> CompileState<'a, 'ast, 'tcx> {
375-
CompileState { krate: Some(krate), ..CompileState::empty(input, session, out_dir) }
386+
CompileState {
387+
krate: Some(krate),
388+
cstore: Some(cstore),
389+
out_file: out_file.as_ref().map(|s| &**s),
390+
..CompileState::empty(input, session, out_dir)
391+
}
376392
}
377393

378394
fn state_after_expand(input: &'a Input,
@@ -399,7 +415,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
399415
CompileState {
400416
crate_name: Some(crate_name),
401417
ast_map: Some(hir_map),
402-
krate: Some(krate),
418+
expanded_crate: Some(krate),
403419
hir_crate: Some(hir_crate),
404420
..CompileState::empty(input, session, out_dir)
405421
}
@@ -419,7 +435,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
419435
analysis: Some(analysis),
420436
mir_map: mir_map,
421437
tcx: Some(tcx),
422-
krate: krate,
438+
expanded_crate: krate,
423439
hir_crate: Some(hir_crate),
424440
crate_name: Some(crate_name),
425441
..CompileState::empty(input, session, out_dir)

branches/auto/src/librustc_driver/lib.rs

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#![feature(set_stdio)]
3232
#![feature(staged_api)]
3333
#![feature(question_mark)]
34+
#![feature(unboxed_closures)]
3435

3536
extern crate arena;
3637
extern crate flate;
@@ -208,15 +209,8 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
208209

209210
do_or_return!(callbacks.late_callback(&matches, &sess, &input, &odir, &ofile), Some(sess));
210211

211-
// It is somewhat unfortunate that this is hardwired in.
212-
let pretty = callbacks.parse_pretty(&sess, &matches);
213-
if let Some((ppm, opt_uii)) = pretty {
214-
pretty::pretty_print_input(&sess, &cstore, cfg, &input, ppm, opt_uii, ofile);
215-
return (Ok(()), None);
216-
}
217-
218212
let plugins = sess.opts.debugging_opts.extra_plugins.clone();
219-
let control = callbacks.build_controller(&sess);
213+
let control = callbacks.build_controller(&sess, &matches);
220214
(driver::compile_input(&sess, &cstore, cfg, &input, &odir, &ofile,
221215
Some(plugins), &control),
222216
Some(sess))
@@ -247,6 +241,27 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option<PathBuf>)> {
247241
}
248242
}
249243

244+
fn parse_pretty(sess: &Session,
245+
matches: &getopts::Matches)
246+
-> Option<(PpMode, Option<UserIdentifiedItem>)> {
247+
let pretty = if sess.opts.debugging_opts.unstable_options {
248+
matches.opt_default("pretty", "normal").map(|a| {
249+
// stable pretty-print variants only
250+
pretty::parse_pretty(sess, &a, false)
251+
})
252+
} else {
253+
None
254+
};
255+
if pretty.is_none() && sess.unstable_options() {
256+
matches.opt_str("unpretty").map(|a| {
257+
// extended with unstable pretty-print variants
258+
pretty::parse_pretty(sess, &a, true)
259+
})
260+
} else {
261+
pretty
262+
}
263+
}
264+
250265
// Whether to stop or continue compilation.
251266
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
252267
pub enum Compilation {
@@ -316,29 +331,9 @@ pub trait CompilerCalls<'a> {
316331
None
317332
}
318333

319-
// Parse pretty printing information from the arguments. The implementer can
320-
// choose to ignore this (the default will return None) which will skip pretty
321-
// printing. If you do want to pretty print, it is recommended to use the
322-
// implementation of this method from RustcDefaultCalls.
323-
// FIXME, this is a terrible bit of API. Parsing of pretty printing stuff
324-
// should be done as part of the framework and the implementor should customise
325-
// handling of it. However, that is not possible atm because pretty printing
326-
// essentially goes off and takes another path through the compiler which
327-
// means the session is either moved or not depending on what parse_pretty
328-
// returns (we could fix this by cloning, but it's another hack). The proper
329-
// solution is to handle pretty printing as if it were a compiler extension,
330-
// extending CompileController to make this work (see for example the treatment
331-
// of save-analysis in RustcDefaultCalls::build_controller).
332-
fn parse_pretty(&mut self,
333-
_sess: &Session,
334-
_matches: &getopts::Matches)
335-
-> Option<(PpMode, Option<UserIdentifiedItem>)> {
336-
None
337-
}
338-
339334
// Create a CompilController struct for controlling the behaviour of
340335
// compilation.
341-
fn build_controller(&mut self, &Session) -> CompileController<'a>;
336+
fn build_controller(&mut self, &Session, &getopts::Matches) -> CompileController<'a>;
342337
}
343338

344339
// CompilerCalls instance for a regular rustc build.
@@ -441,28 +436,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
441436
None
442437
}
443438

444-
fn parse_pretty(&mut self,
445-
sess: &Session,
446-
matches: &getopts::Matches)
447-
-> Option<(PpMode, Option<UserIdentifiedItem>)> {
448-
let pretty = if sess.opts.debugging_opts.unstable_options {
449-
matches.opt_default("pretty", "normal").map(|a| {
450-
// stable pretty-print variants only
451-
pretty::parse_pretty(sess, &a, false)
452-
})
453-
} else {
454-
None
455-
};
456-
if pretty.is_none() && sess.unstable_options() {
457-
matches.opt_str("unpretty").map(|a| {
458-
// extended with unstable pretty-print variants
459-
pretty::parse_pretty(sess, &a, true)
460-
})
461-
} else {
462-
pretty
463-
}
464-
}
465-
466439
fn late_callback(&mut self,
467440
matches: &getopts::Matches,
468441
sess: &Session,
@@ -474,9 +447,22 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
474447
.and_then(|| RustcDefaultCalls::list_metadata(sess, matches, input))
475448
}
476449

477-
fn build_controller(&mut self, sess: &Session) -> CompileController<'a> {
450+
fn build_controller(&mut self, sess: &Session, matches: &getopts::Matches) -> CompileController<'a> {
478451
let mut control = CompileController::basic();
479452

453+
if let Some((ppm, opt_uii)) = parse_pretty(&sess, &matches) {
454+
control.after_parse.stop = Compilation::Stop;
455+
control.after_parse.callback = box move |state| {
456+
pretty::pretty_print_input(state.session,
457+
state.cstore.unwrap(),
458+
state.input,
459+
state.krate.take().unwrap(),
460+
ppm,
461+
opt_uii.clone(),
462+
state.out_file);
463+
};
464+
}
465+
480466
if sess.opts.parse_only || sess.opts.debugging_opts.show_span.is_some() ||
481467
sess.opts.debugging_opts.ast_json_noexpand {
482468
control.after_parse.stop = Compilation::Stop;
@@ -498,7 +484,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
498484
control.after_analysis.callback = box |state| {
499485
time(state.session.time_passes(), "save analysis", || {
500486
save::process_crate(state.tcx.unwrap(),
501-
state.krate.unwrap(),
487+
state.expanded_crate.unwrap(),
502488
state.analysis.unwrap(),
503489
state.crate_name.unwrap(),
504490
state.out_dir,

branches/auto/src/librustc_driver/pretty.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use std::fs::File;
4949
use std::io::{self, Write};
5050
use std::iter;
5151
use std::option;
52-
use std::path::PathBuf;
52+
use std::path::Path;
5353
use std::str::FromStr;
5454

5555
use rustc::hir::map as hir_map;
@@ -702,13 +702,11 @@ impl fold::Folder for ReplaceBodyWithLoop {
702702

703703
pub fn pretty_print_input(sess: &Session,
704704
cstore: &CStore,
705-
cfg: ast::CrateConfig,
706705
input: &Input,
706+
krate: ast::Crate,
707707
ppm: PpMode,
708708
opt_uii: Option<UserIdentifiedItem>,
709-
ofile: Option<PathBuf>) {
710-
let krate = panictry!(driver::phase_1_parse_input(sess, cfg, input));
711-
709+
ofile: Option<&Path>) {
712710
let krate = if let PpmSource(PpmEveryBodyLoops) = ppm {
713711
let mut fold = ReplaceBodyWithLoop::new();
714712
fold.fold_crate(krate)
@@ -922,7 +920,7 @@ pub fn pretty_print_input(sess: &Session,
922920
match ofile {
923921
None => print!("{}", String::from_utf8(out).unwrap()),
924922
Some(p) => {
925-
match File::create(&p) {
923+
match File::create(p) {
926924
Ok(mut w) => w.write_all(&out).unwrap(),
927925
Err(e) => panic!("print-print failed to open {} due to {}", p.display(), e),
928926
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'a> CompilerCalls<'a> for TestCalls {
6969
panic!("This shouldn't happen");
7070
}
7171

72-
fn build_controller(&mut self, _: &Session) -> driver::CompileController<'a> {
72+
fn build_controller(&mut self, _: &Session, _: &getopts::Matches) -> driver::CompileController<'a> {
7373
panic!("This shouldn't be called");
7474
}
7575
}

0 commit comments

Comments
 (0)