Skip to content

Commit

Permalink
Auto merge of #45912 - Zoxc:par-query, r=<try>
Browse files Browse the repository at this point in the history
WIP: Playing with adding thread safety to GlobalCtxt
  • Loading branch information
bors committed Nov 10, 2017
2 parents 968b620 + ad7b865 commit d2cb23b
Show file tree
Hide file tree
Showing 26 changed files with 334 additions and 180 deletions.
67 changes: 67 additions & 0 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod diagnostic;
pub use diagnostic::{Diagnostic, Level};

use std::{ascii, fmt, iter};
use std::rc::Rc;
use std::sync::Arc;
use std::str::FromStr;

use syntax::ast;
Expand Down Expand Up @@ -274,7 +274,7 @@ pub struct LineColumn {
#[unstable(feature = "proc_macro", issue = "38356")]
#[derive(Clone)]
pub struct SourceFile {
filemap: Rc<FileMap>,
filemap: Arc<FileMap>,
}

impl SourceFile {
Expand Down Expand Up @@ -324,7 +324,7 @@ impl fmt::Debug for SourceFile {
#[unstable(feature = "proc_macro", issue = "38356")]
impl PartialEq for SourceFile {
fn eq(&self, other: &Self) -> bool {
Rc::ptr_eq(&self.filemap, &other.filemap)
Arc::ptr_eq(&self.filemap, &other.filemap)
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/librustc/ich/caching_codemap_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::rc::Rc;
use std::sync::Arc;
use syntax::codemap::CodeMap;
use syntax_pos::{BytePos, FileMap};

Expand All @@ -18,7 +18,7 @@ struct CacheEntry {
line_number: usize,
line_start: BytePos,
line_end: BytePos,
file: Rc<FileMap>,
file: Arc<FileMap>,
file_index: usize,
}

Expand Down Expand Up @@ -51,7 +51,7 @@ impl<'cm> CachingCodemapView<'cm> {

pub fn byte_pos_to_line_and_col(&mut self,
pos: BytePos)
-> Option<(Rc<FileMap>, usize, BytePos)> {
-> Option<(Arc<FileMap>, usize, BytePos)> {
self.time_stamp += 1;

// Check if the position is in one of the cached lines
Expand All @@ -78,11 +78,9 @@ impl<'cm> CachingCodemapView<'cm> {
// If the entry doesn't point to the correct file, fix it up
if pos < cache_entry.file.start_pos || pos >= cache_entry.file.end_pos {
let file_valid;
let files = self.codemap.files();

if files.len() > 0 {
if self.codemap.files().len() > 0 {
let file_index = self.codemap.lookup_filemap_idx(pos);
let file = files[file_index].clone();
let file = self.codemap.files()[file_index].clone();

if pos >= file.start_pos && pos < file.end_pos {
cache_entry.file = file;
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"prints the llvm optimization passes being run"),
ast_json: bool = (false, parse_bool, [UNTRACKED],
"print the AST as JSON and halt"),
query_threads: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
"execute queries on a thread pool with N threads"),
ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
"print the pre-expansion AST as JSON and halt"),
ls: bool = (false, parse_bool, [UNTRACKED],
Expand Down Expand Up @@ -1584,6 +1586,10 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
}
}

if debugging_opts.query_threads == Some(0) {
early_error(error_format, "Value for codegen units must be a positive nonzero integer");
}

if codegen_units == Some(0) {
early_error(error_format, "Value for codegen units must be a positive nonzero integer");
}
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,12 @@ impl Session {
ret
}

/// Returns the number of query threads that should be used for this
/// compilation
pub fn query_threads(&self) -> usize {
self.opts.debugging_opts.query_threads.unwrap_or(1)
}

/// Returns the number of codegen units that should be used for this
/// compilation
pub fn codegen_units(&self) -> usize {
Expand Down
Loading

0 comments on commit d2cb23b

Please sign in to comment.