Skip to content

Commit

Permalink
Auto merge of #46779 - Zoxc:par-merge-without-sync, r=arielb1
Browse files Browse the repository at this point in the history
Work towards thread safety in rustc

This PR is split out from #45912. It contains changes which do not require the `sync` module.
  • Loading branch information
bors committed Dec 22, 2017
2 parents 264af16 + 84ce4f1 commit 2c037d5
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 70 deletions.
6 changes: 2 additions & 4 deletions src/librustc/ich/caching_codemap_view.rs
Expand Up @@ -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
Expand Up @@ -1092,6 +1092,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 @@ -1688,6 +1690,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 query threads 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
Expand Up @@ -725,6 +725,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
21 changes: 17 additions & 4 deletions src/librustc/ty/context.rs
Expand Up @@ -76,6 +76,20 @@ use syntax_pos::Span;

use hir;

pub struct AllArenas<'tcx> {
pub global: GlobalArenas<'tcx>,
pub interner: DroplessArena,
}

impl<'tcx> AllArenas<'tcx> {
pub fn new() -> Self {
AllArenas {
global: GlobalArenas::new(),
interner: DroplessArena::new(),
}
}
}

/// Internal storage
pub struct GlobalArenas<'tcx> {
// internings
Expand Down Expand Up @@ -1120,8 +1134,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
cstore: &'tcx CrateStore,
local_providers: ty::maps::Providers<'tcx>,
extern_providers: ty::maps::Providers<'tcx>,
arenas: &'tcx GlobalArenas<'tcx>,
arena: &'tcx DroplessArena,
arenas: &'tcx AllArenas<'tcx>,
resolutions: ty::Resolutions,
hir: hir_map::Map<'tcx>,
on_disk_query_result_cache: maps::OnDiskCache<'tcx>,
Expand All @@ -1132,7 +1145,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
where F: for<'b> FnOnce(TyCtxt<'b, 'tcx, 'tcx>) -> R
{
let data_layout = TargetDataLayout::parse(s);
let interners = CtxtInterners::new(arena);
let interners = CtxtInterners::new(&arenas.interner);
let common_types = CommonTypes::new(&interners);
let dep_graph = hir.dep_graph.clone();
let max_cnum = cstore.crates_untracked().iter().map(|c| c.as_usize()).max().unwrap_or(0);
Expand Down Expand Up @@ -1184,7 +1197,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
tls::enter_global(GlobalCtxt {
sess: s,
cstore,
global_arenas: arenas,
global_arenas: &arenas.global,
global_interners: interners,
dep_graph: dep_graph.clone(),
on_disk_query_result_cache,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Expand Up @@ -77,7 +77,7 @@ pub use self::sty::TypeVariants::*;
pub use self::binding::BindingMode;
pub use self::binding::BindingMode::*;

pub use self::context::{TyCtxt, GlobalArenas, tls, keep_local};
pub use self::context::{TyCtxt, GlobalArenas, AllArenas, tls, keep_local};
pub use self::context::{Lift, TypeckTables};

pub use self::instance::{Instance, InstanceDef};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/indexed_vec.rs
Expand Up @@ -327,7 +327,7 @@ macro_rules! newtype_index {
#[derive(Clone, PartialEq, Eq)]
pub struct IndexVec<I: Idx, T> {
pub raw: Vec<T>,
_marker: PhantomData<Fn(&I)>
_marker: PhantomData<fn(&I)>
}

// Whether `IndexVec` is `Send` depends only on the data,
Expand Down
20 changes: 5 additions & 15 deletions src/librustc_driver/driver.rs
Expand Up @@ -22,7 +22,7 @@ use rustc::lint;
use rustc::middle::{self, stability, reachable, resolve_lifetime};
use rustc::middle::cstore::CrateStore;
use rustc::middle::privacy::AccessLevels;
use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
use rustc::ty::{self, TyCtxt, Resolutions, AllArenas};
use rustc::traits;
use rustc::util::common::{ErrorReported, time};
use rustc_allocator as allocator;
Expand Down Expand Up @@ -62,7 +62,6 @@ use syntax::util::node_count::NodeCounter;
use syntax_pos::FileName;
use syntax;
use syntax_ext;
use arena::DroplessArena;

use derive_registrar;
use pretty::ReplaceBodyWithLoop;
Expand Down Expand Up @@ -184,8 +183,7 @@ pub fn compile_input(sess: &Session,
return Ok(())
}

let arena = DroplessArena::new();
let arenas = GlobalArenas::new();
let arenas = AllArenas::new();

// Construct the HIR map
let hir_map = time(sess.time_passes(),
Expand All @@ -200,7 +198,6 @@ pub fn compile_input(sess: &Session,
sess,
outdir,
output,
&arena,
&arenas,
&cstore,
&hir_map,
Expand Down Expand Up @@ -230,7 +227,6 @@ pub fn compile_input(sess: &Session,
hir_map,
analysis,
resolutions,
&arena,
&arenas,
&crate_name,
&outputs,
Expand Down Expand Up @@ -416,8 +412,7 @@ pub struct CompileState<'a, 'tcx: 'a> {
pub output_filenames: Option<&'a OutputFilenames>,
pub out_dir: Option<&'a Path>,
pub out_file: Option<&'a Path>,
pub arena: Option<&'tcx DroplessArena>,
pub arenas: Option<&'tcx GlobalArenas<'tcx>>,
pub arenas: Option<&'tcx AllArenas<'tcx>>,
pub expanded_crate: Option<&'a ast::Crate>,
pub hir_crate: Option<&'a hir::Crate>,
pub hir_map: Option<&'a hir_map::Map<'tcx>>,
Expand All @@ -437,7 +432,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
session,
out_dir: out_dir.as_ref().map(|s| &**s),
out_file: None,
arena: None,
arenas: None,
krate: None,
registry: None,
Expand Down Expand Up @@ -492,8 +486,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
session: &'tcx Session,
out_dir: &'a Option<PathBuf>,
out_file: &'a Option<PathBuf>,
arena: &'tcx DroplessArena,
arenas: &'tcx GlobalArenas<'tcx>,
arenas: &'tcx AllArenas<'tcx>,
cstore: &'tcx CStore,
hir_map: &'a hir_map::Map<'tcx>,
analysis: &'a ty::CrateAnalysis,
Expand All @@ -505,7 +498,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
-> Self {
CompileState {
crate_name: Some(crate_name),
arena: Some(arena),
arenas: Some(arenas),
cstore: Some(cstore),
hir_map: Some(hir_map),
Expand Down Expand Up @@ -974,8 +966,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(control: &CompileController,
hir_map: hir_map::Map<'tcx>,
mut analysis: ty::CrateAnalysis,
resolutions: Resolutions,
arena: &'tcx DroplessArena,
arenas: &'tcx GlobalArenas<'tcx>,
arenas: &'tcx AllArenas<'tcx>,
name: &str,
output_filenames: &OutputFilenames,
f: F)
Expand Down Expand Up @@ -1035,7 +1026,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(control: &CompileController,
local_providers,
extern_providers,
arenas,
arena,
resolutions,
hir_map,
query_result_on_disk_cache,
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_driver/lib.rs
Expand Up @@ -227,7 +227,7 @@ pub fn run_compiler<'a>(args: &[String],
},
};

let cstore = Rc::new(CStore::new(DefaultTransCrate::metadata_loader()));
let cstore = CStore::new(DefaultTransCrate::metadata_loader());

let loader = file_loader.unwrap_or(box RealFileLoader);
let codemap = Rc::new(CodeMap::with_file_loader(loader, sopts.file_path_mapping()));
Expand All @@ -243,7 +243,7 @@ pub fn run_compiler<'a>(args: &[String],

do_or_return!(callbacks.late_callback(&matches,
&sess,
&*cstore,
&cstore,
&input,
&odir,
&ofile), Some(sess));
Expand Down Expand Up @@ -580,7 +580,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
&state.expanded_crate.take().unwrap(),
state.crate_name.unwrap(),
ppm,
state.arena.unwrap(),
state.arenas.unwrap(),
state.output_filenames.unwrap(),
opt_uii.clone(),
Expand Down
20 changes: 4 additions & 16 deletions src/librustc_driver/pretty.rs
Expand Up @@ -17,7 +17,7 @@ use self::NodesMatchingUII::*;

use {abort_on_err, driver};

use rustc::ty::{self, TyCtxt, GlobalArenas, Resolutions};
use rustc::ty::{self, TyCtxt, Resolutions, AllArenas};
use rustc::cfg;
use rustc::cfg::graphviz::LabelledCFG;
use rustc::middle::cstore::CrateStore;
Expand Down Expand Up @@ -51,8 +51,6 @@ use rustc::hir::map::blocks;
use rustc::hir;
use rustc::hir::print as pprust_hir;

use arena::DroplessArena;

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum PpSourceMode {
PpmNormal,
Expand Down Expand Up @@ -205,8 +203,7 @@ impl PpSourceMode {
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
arena: &'tcx DroplessArena,
arenas: &'tcx GlobalArenas<'tcx>,
arenas: &'tcx AllArenas<'tcx>,
output_filenames: &OutputFilenames,
id: &str,
f: F)
Expand Down Expand Up @@ -237,7 +234,6 @@ impl PpSourceMode {
hir_map.clone(),
analysis.clone(),
resolutions.clone(),
arena,
arenas,
id,
output_filenames,
Expand Down Expand Up @@ -914,8 +910,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
krate: &ast::Crate,
crate_name: &str,
ppm: PpMode,
arena: &'tcx DroplessArena,
arenas: &'tcx GlobalArenas<'tcx>,
arenas: &'tcx AllArenas<'tcx>,
output_filenames: &OutputFilenames,
opt_uii: Option<UserIdentifiedItem>,
ofile: Option<&Path>) {
Expand All @@ -926,7 +921,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
analysis,
resolutions,
crate_name,
arena,
arenas,
output_filenames,
ppm,
Expand Down Expand Up @@ -965,7 +959,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
hir_map,
analysis,
resolutions,
arena,
arenas,
output_filenames,
crate_name,
Expand All @@ -990,7 +983,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
hir_map,
analysis,
resolutions,
arena,
arenas,
output_filenames,
crate_name,
Expand All @@ -1007,7 +999,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
hir_map,
analysis,
resolutions,
arena,
arenas,
output_filenames,
crate_name,
Expand Down Expand Up @@ -1042,7 +1033,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
hir_map,
analysis,
resolutions,
arena,
arenas,
output_filenames,
crate_name,
Expand Down Expand Up @@ -1073,8 +1063,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
crate_name: &str,
arena: &'tcx DroplessArena,
arenas: &'tcx GlobalArenas<'tcx>,
arenas: &'tcx AllArenas<'tcx>,
output_filenames: &OutputFilenames,
ppm: PpMode,
uii: Option<UserIdentifiedItem>,
Expand All @@ -1096,7 +1085,6 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
hir_map.clone(),
analysis.clone(),
resolutions.clone(),
arena,
arenas,
crate_name,
output_filenames,
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_driver/test.rs
Expand Up @@ -40,7 +40,6 @@ use errors::{Level, DiagnosticBuilder};
use syntax::feature_gate::UnstableFeatures;
use syntax::symbol::Symbol;
use syntax_pos::DUMMY_SP;
use arena::DroplessArena;

use rustc::hir;

Expand Down Expand Up @@ -131,8 +130,7 @@ fn test_env<F>(source_string: &str,
.expect("phase 2 aborted")
};

let arena = DroplessArena::new();
let arenas = ty::GlobalArenas::new();
let arenas = ty::AllArenas::new();
let hir_map = hir_map::map_crate(&sess, &*cstore, &mut hir_forest, &defs);

// run just enough stuff to build a tcx:
Expand All @@ -149,7 +147,6 @@ fn test_env<F>(source_string: &str,
ty::maps::Providers::default(),
ty::maps::Providers::default(),
&arenas,
&arena,
resolutions,
hir_map,
OnDiskCache::new_empty(sess.codemap()),
Expand Down

0 comments on commit 2c037d5

Please sign in to comment.