Make queries block and handle query cycles

This commit is contained in:
John Kåre Alsaker 2018-04-06 12:56:59 +02:00
parent 685faa2c3e
commit f9e6fbc4f7
7 changed files with 469 additions and 10 deletions

View file

@ -49,7 +49,7 @@ use std::fs;
use std::io::{self, Write};
use std::iter;
use std::path::{Path, PathBuf};
use rustc_data_structures::sync::{self, Lrc};
use rustc_data_structures::sync::{self, Lrc, Lock};
use std::sync::mpsc;
use syntax::{self, ast, attr, diagnostics, visit};
use syntax::ext::base::ExtCtxt;
@ -69,7 +69,9 @@ pub fn spawn_thread_pool<F: FnOnce(config::Options) -> R + sync::Send, R: sync::
opts: config::Options,
f: F
) -> R {
f(opts)
ty::tls::GCX_PTR.set(&Lock::new(0), || {
f(opts)
})
}
#[cfg(parallel_queries)]
@ -81,7 +83,10 @@ pub fn spawn_thread_pool<F: FnOnce(config::Options) -> R + sync::Send, R: sync::
use syntax_pos;
use rayon::{ThreadPoolBuilder, ThreadPool};
let gcx_ptr = &Lock::new(0);
let config = ThreadPoolBuilder::new().num_threads(Session::query_threads_from_opts(&opts))
.deadlock_handler(ty::maps::handle_deadlock)
.stack_size(16 * 1024 * 1024);
let with_pool = move |pool: &ThreadPool| {
@ -98,7 +103,9 @@ pub fn spawn_thread_pool<F: FnOnce(config::Options) -> R + sync::Send, R: sync::
syntax::GLOBALS.set(syntax_globals, || {
syntax_pos::GLOBALS.set(syntax_pos_globals, || {
ty::tls::with_thread_locals(|| {
worker()
ty::tls::GCX_PTR.set(gcx_ptr, || {
worker()
})
})
})
})