Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expend syntax::with_globals coverage and allow nested calls #53526

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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