@@ -38,21 +38,16 @@ use middle::lint;
38
38
39
39
use d = driver:: driver;
40
40
41
- use std:: cast;
42
- use std:: comm;
43
41
use std:: io;
44
- use std:: io:: Reader ;
45
42
use std:: num;
46
43
use std:: os;
47
- use std:: result;
48
44
use std:: str;
49
45
use std:: task;
50
46
use std:: vec;
51
47
use extra:: getopts:: groups;
52
48
use extra:: getopts;
53
49
use syntax:: ast;
54
50
use syntax:: attr;
55
- use syntax:: codemap;
56
51
use syntax:: diagnostic:: Emitter ;
57
52
use syntax:: diagnostic;
58
53
use syntax:: parse;
@@ -126,21 +121,6 @@ pub mod lib {
126
121
pub mod llvmdeps;
127
122
}
128
123
129
- // A curious inner module that allows ::std::foo to be available in here for
130
- // macros.
131
- /*
132
- mod std {
133
- pub use std::clone;
134
- pub use std::cmp;
135
- pub use std::os;
136
- pub use std::str;
137
- pub use std::sys;
138
- pub use std::to_bytes;
139
- pub use std::unstable;
140
- pub use extra::serialize;
141
- }
142
- */
143
-
144
124
pub fn version ( argv0 : & str ) {
145
125
let vers = match option_env ! ( "CFG_VERSION" ) {
146
126
Some ( vers) => vers,
@@ -344,45 +324,12 @@ fn parse_crate_attrs(sess: session::Session,
344
324
}
345
325
}
346
326
347
- #[ deriving( Eq ) ]
348
- pub enum monitor_msg {
349
- fatal,
350
- done,
351
- }
352
-
353
- struct RustcEmitter {
354
- ch_capture : comm:: SharedChan < monitor_msg >
355
- }
356
-
357
- impl diagnostic:: Emitter for RustcEmitter {
358
- fn emit ( & self ,
359
- cmsp : Option < ( & codemap:: CodeMap , codemap:: Span ) > ,
360
- msg : & str ,
361
- lvl : diagnostic:: Level ) {
362
- if lvl == diagnostic:: Fatal {
363
- let this = unsafe { cast:: transmute_mut ( self ) } ;
364
- this. ch_capture . send ( fatal)
365
- }
366
-
367
- diagnostic:: DefaultEmitter . emit ( cmsp, msg, lvl)
368
- }
369
- }
370
-
371
- /*
372
- This is a sanity check that any failure of the compiler is performed
373
- through the diagnostic module and reported properly - we shouldn't be calling
374
- plain-old-fail on any execution path that might be taken. Since we have
375
- console logging off by default, hitting a plain fail statement would make the
376
- compiler silently exit, which would be terrible.
377
-
378
- This method wraps the compiler in a subtask and injects a function into the
379
- diagnostic emitter which records when we hit a fatal error. If the task
380
- fails without recording a fatal error then we've encountered a compiler
381
- bug and need to present an error.
382
- */
327
+ /// Run a procedure which will detect failures in the compiler and print nicer
328
+ /// error messages rather than just failing the test.
329
+ ///
330
+ /// The diagnostic emitter yielded to the procedure should be used for reporting
331
+ /// errors of the compiler.
383
332
pub fn monitor ( f : proc ( @diagnostic:: Emitter ) ) {
384
- use std:: comm:: * ;
385
-
386
333
// XXX: This is a hack for newsched since it doesn't support split stacks.
387
334
// rustc needs a lot of stack! When optimizations are disabled, it needs
388
335
// even *more* stack than usual as well.
@@ -391,8 +338,6 @@ pub fn monitor(f: proc(@diagnostic::Emitter)) {
391
338
#[ cfg( not( rtopt) ) ]
392
339
static STACK_SIZE : uint = 20000000 ; // 20MB
393
340
394
- let ( p, ch) = SharedChan :: new ( ) ;
395
- let ch_capture = ch. clone ( ) ;
396
341
let mut task_builder = task:: task ( ) ;
397
342
task_builder. name ( "rustc" ) ;
398
343
@@ -402,30 +347,18 @@ pub fn monitor(f: proc(@diagnostic::Emitter)) {
402
347
task_builder. opts . stack_size = Some ( STACK_SIZE ) ;
403
348
}
404
349
405
- match task_builder. try ( proc ( ) {
406
- let ch = ch_capture. clone ( ) ;
407
- // The 'diagnostics emitter'. Every error, warning, etc. should
408
- // go through this function.
409
- let demitter = @RustcEmitter {
410
- ch_capture : ch. clone ( ) ,
411
- } as @diagnostic:: Emitter ;
412
-
413
- struct finally {
414
- ch : SharedChan < monitor_msg > ,
415
- }
350
+ let ( p, c) = Chan :: new ( ) ;
351
+ let w = io:: ChanWriter :: new ( c) ;
352
+ let mut r = io:: PortReader :: new ( p) ;
416
353
417
- impl Drop for finally {
418
- fn drop ( & mut self ) { self . ch . send ( done) ; }
419
- }
420
-
421
- let _finally = finally { ch : ch } ;
422
-
423
- f ( demitter) ;
354
+ match task_builder. try ( proc ( ) {
355
+ io:: stdio:: set_stderr ( ~w as ~io:: Writer ) ;
356
+ f ( @diagnostic:: DefaultEmitter )
424
357
} ) {
425
- result :: Ok ( _ ) => { /* fallthrough */ }
426
- result :: Err ( _ ) => {
358
+ Ok ( ( ) ) => { /* fallthrough */ }
359
+ Err ( value ) => {
427
360
// Task failed without emitting a fatal diagnostic
428
- if p . recv ( ) == done {
361
+ if !value . is :: < diagnostic :: FatalError > ( ) {
429
362
diagnostic:: DefaultEmitter . emit (
430
363
None ,
431
364
diagnostic:: ice_msg ( "unexpected failure" ) ,
@@ -434,17 +367,20 @@ pub fn monitor(f: proc(@diagnostic::Emitter)) {
434
367
let xs = [
435
368
~"the compiler hit an unexpected failure path. \
436
369
this is a bug ",
437
- ~"try running with RUST_LOG =rustc=1 \
438
- to get further details and report the results \
439
- to github. com /mozilla/rust/issues"
440
370
] ;
441
371
for note in xs. iter ( ) {
442
372
diagnostic:: DefaultEmitter . emit ( None ,
443
373
* note,
444
374
diagnostic:: Note )
445
375
}
376
+
377
+ println ! ( "{}" , r. read_to_str( ) ) ;
446
378
}
447
- // Fail so the process returns a failure code
379
+
380
+ // Fail so the process returns a failure code, but don't pollute the
381
+ // output with some unnecessary failure messages, we've already
382
+ // printed everything that we needed to.
383
+ io:: stdio:: set_stderr ( ~io:: util:: NullWriter as ~io:: Writer ) ;
448
384
fail ! ( ) ;
449
385
}
450
386
}
0 commit comments