Skip to content

Commit

Permalink
Move syntax::with_globals call from run_compiler to run
Browse files Browse the repository at this point in the history
  • Loading branch information
earthengine committed Aug 23, 2018
1 parent c648b0b commit b6f254b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
42 changes: 22 additions & 20 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,28 +184,30 @@ pub fn abort_on_err<T>(result: Result<T, CompileIncomplete>, sess: &Session) ->
pub fn run<F>(run_compiler: F) -> isize
where F: FnOnce() -> (CompileResult, Option<Session>) + Send + 'static
{
let result = monitor(move || {
let (result, session) = run_compiler();
if let Err(CompileIncomplete::Errored(_)) = result {
match session {
Some(sess) => {
sess.abort_if_errors();
panic!("error reported but abort_if_errors didn't abort???");
}
None => {
let emitter =
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
None,
true,
false);
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
handler.emit(&MultiSpan::new(),
"aborting due to previous error(s)",
errors::Level::Fatal);
panic::resume_unwind(Box::new(errors::FatalErrorMarker));
let result = syntax::with_globals(|| {
monitor(move || {
let (result, session) = run_compiler();
if let Err(CompileIncomplete::Errored(_)) = result {
match session {
Some(sess) => {
sess.abort_if_errors();
panic!("error reported but abort_if_errors didn't abort???");
}
None => {
let emitter =
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
None,
true,
false);
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
handler.emit(&MultiSpan::new(),
"aborting due to previous error(s)",
errors::Level::Fatal);
panic::resume_unwind(Box::new(errors::FatalErrorMarker));
}
}
}
}
})
});

match result {
Expand Down
18 changes: 14 additions & 4 deletions src/libsyntax/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,20 @@ impl Globals {
pub fn with_globals<F, R>(f: F) -> R
where F: FnOnce() -> R
{
let globals = Globals::new();
GLOBALS.set(&globals, || {
syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
})
if GLOBALS.is_set() {
if syntax_pos::GLOBALS.is_set() {
f()
} else {
GLOBALS.with(|globals| {
syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
})
}
} else {
let globals = Globals::new();
GLOBALS.set(&globals, || {
syntax_pos::GLOBALS.set(&globals.syntax_pos_globals, f)
})
}
}

scoped_thread_local!(pub static GLOBALS: Globals);
Expand Down

0 comments on commit b6f254b

Please sign in to comment.