Skip to content

Commit 2c037d5

Browse files
committed
Auto merge of #46779 - Zoxc:par-merge-without-sync, r=arielb1
Work towards thread safety in rustc This PR is split out from #45912. It contains changes which do not require the `sync` module.
2 parents 264af16 + 84ce4f1 commit 2c037d5

File tree

15 files changed

+89
-70
lines changed

15 files changed

+89
-70
lines changed

src/librustc/ich/caching_codemap_view.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ impl<'cm> CachingCodemapView<'cm> {
7878
// If the entry doesn't point to the correct file, fix it up
7979
if pos < cache_entry.file.start_pos || pos >= cache_entry.file.end_pos {
8080
let file_valid;
81-
let files = self.codemap.files();
82-
83-
if files.len() > 0 {
81+
if self.codemap.files().len() > 0 {
8482
let file_index = self.codemap.lookup_filemap_idx(pos);
85-
let file = files[file_index].clone();
83+
let file = self.codemap.files()[file_index].clone();
8684

8785
if pos >= file.start_pos && pos < file.end_pos {
8886
cache_entry.file = file;

src/librustc/session/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
10921092
"prints the llvm optimization passes being run"),
10931093
ast_json: bool = (false, parse_bool, [UNTRACKED],
10941094
"print the AST as JSON and halt"),
1095+
query_threads: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
1096+
"execute queries on a thread pool with N threads"),
10951097
ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
10961098
"print the pre-expansion AST as JSON and halt"),
10971099
ls: bool = (false, parse_bool, [UNTRACKED],
@@ -1688,6 +1690,10 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
16881690
}
16891691
}
16901692

1693+
if debugging_opts.query_threads == Some(0) {
1694+
early_error(error_format, "Value for query threads must be a positive nonzero integer");
1695+
}
1696+
16911697
if codegen_units == Some(0) {
16921698
early_error(error_format, "Value for codegen units must be a positive nonzero integer");
16931699
}

src/librustc/session/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,12 @@ impl Session {
725725
ret
726726
}
727727

728+
/// Returns the number of query threads that should be used for this
729+
/// compilation
730+
pub fn query_threads(&self) -> usize {
731+
self.opts.debugging_opts.query_threads.unwrap_or(1)
732+
}
733+
728734
/// Returns the number of codegen units that should be used for this
729735
/// compilation
730736
pub fn codegen_units(&self) -> usize {

src/librustc/ty/context.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ use syntax_pos::Span;
7676

7777
use hir;
7878

79+
pub struct AllArenas<'tcx> {
80+
pub global: GlobalArenas<'tcx>,
81+
pub interner: DroplessArena,
82+
}
83+
84+
impl<'tcx> AllArenas<'tcx> {
85+
pub fn new() -> Self {
86+
AllArenas {
87+
global: GlobalArenas::new(),
88+
interner: DroplessArena::new(),
89+
}
90+
}
91+
}
92+
7993
/// Internal storage
8094
pub struct GlobalArenas<'tcx> {
8195
// internings
@@ -1120,8 +1134,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11201134
cstore: &'tcx CrateStore,
11211135
local_providers: ty::maps::Providers<'tcx>,
11221136
extern_providers: ty::maps::Providers<'tcx>,
1123-
arenas: &'tcx GlobalArenas<'tcx>,
1124-
arena: &'tcx DroplessArena,
1137+
arenas: &'tcx AllArenas<'tcx>,
11251138
resolutions: ty::Resolutions,
11261139
hir: hir_map::Map<'tcx>,
11271140
on_disk_query_result_cache: maps::OnDiskCache<'tcx>,
@@ -1132,7 +1145,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11321145
where F: for<'b> FnOnce(TyCtxt<'b, 'tcx, 'tcx>) -> R
11331146
{
11341147
let data_layout = TargetDataLayout::parse(s);
1135-
let interners = CtxtInterners::new(arena);
1148+
let interners = CtxtInterners::new(&arenas.interner);
11361149
let common_types = CommonTypes::new(&interners);
11371150
let dep_graph = hir.dep_graph.clone();
11381151
let max_cnum = cstore.crates_untracked().iter().map(|c| c.as_usize()).max().unwrap_or(0);
@@ -1184,7 +1197,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11841197
tls::enter_global(GlobalCtxt {
11851198
sess: s,
11861199
cstore,
1187-
global_arenas: arenas,
1200+
global_arenas: &arenas.global,
11881201
global_interners: interners,
11891202
dep_graph: dep_graph.clone(),
11901203
on_disk_query_result_cache,

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub use self::sty::TypeVariants::*;
7777
pub use self::binding::BindingMode;
7878
pub use self::binding::BindingMode::*;
7979

80-
pub use self::context::{TyCtxt, GlobalArenas, tls, keep_local};
80+
pub use self::context::{TyCtxt, GlobalArenas, AllArenas, tls, keep_local};
8181
pub use self::context::{Lift, TypeckTables};
8282

8383
pub use self::instance::{Instance, InstanceDef};

src/librustc_data_structures/indexed_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ macro_rules! newtype_index {
327327
#[derive(Clone, PartialEq, Eq)]
328328
pub struct IndexVec<I: Idx, T> {
329329
pub raw: Vec<T>,
330-
_marker: PhantomData<Fn(&I)>
330+
_marker: PhantomData<fn(&I)>
331331
}
332332

333333
// Whether `IndexVec` is `Send` depends only on the data,

src/librustc_driver/driver.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc::lint;
2222
use rustc::middle::{self, stability, reachable, resolve_lifetime};
2323
use rustc::middle::cstore::CrateStore;
2424
use rustc::middle::privacy::AccessLevels;
25-
use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
25+
use rustc::ty::{self, TyCtxt, Resolutions, AllArenas};
2626
use rustc::traits;
2727
use rustc::util::common::{ErrorReported, time};
2828
use rustc_allocator as allocator;
@@ -62,7 +62,6 @@ use syntax::util::node_count::NodeCounter;
6262
use syntax_pos::FileName;
6363
use syntax;
6464
use syntax_ext;
65-
use arena::DroplessArena;
6665

6766
use derive_registrar;
6867
use pretty::ReplaceBodyWithLoop;
@@ -184,8 +183,7 @@ pub fn compile_input(sess: &Session,
184183
return Ok(())
185184
}
186185

187-
let arena = DroplessArena::new();
188-
let arenas = GlobalArenas::new();
186+
let arenas = AllArenas::new();
189187

190188
// Construct the HIR map
191189
let hir_map = time(sess.time_passes(),
@@ -200,7 +198,6 @@ pub fn compile_input(sess: &Session,
200198
sess,
201199
outdir,
202200
output,
203-
&arena,
204201
&arenas,
205202
&cstore,
206203
&hir_map,
@@ -230,7 +227,6 @@ pub fn compile_input(sess: &Session,
230227
hir_map,
231228
analysis,
232229
resolutions,
233-
&arena,
234230
&arenas,
235231
&crate_name,
236232
&outputs,
@@ -416,8 +412,7 @@ pub struct CompileState<'a, 'tcx: 'a> {
416412
pub output_filenames: Option<&'a OutputFilenames>,
417413
pub out_dir: Option<&'a Path>,
418414
pub out_file: Option<&'a Path>,
419-
pub arena: Option<&'tcx DroplessArena>,
420-
pub arenas: Option<&'tcx GlobalArenas<'tcx>>,
415+
pub arenas: Option<&'tcx AllArenas<'tcx>>,
421416
pub expanded_crate: Option<&'a ast::Crate>,
422417
pub hir_crate: Option<&'a hir::Crate>,
423418
pub hir_map: Option<&'a hir_map::Map<'tcx>>,
@@ -437,7 +432,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
437432
session,
438433
out_dir: out_dir.as_ref().map(|s| &**s),
439434
out_file: None,
440-
arena: None,
441435
arenas: None,
442436
krate: None,
443437
registry: None,
@@ -492,8 +486,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
492486
session: &'tcx Session,
493487
out_dir: &'a Option<PathBuf>,
494488
out_file: &'a Option<PathBuf>,
495-
arena: &'tcx DroplessArena,
496-
arenas: &'tcx GlobalArenas<'tcx>,
489+
arenas: &'tcx AllArenas<'tcx>,
497490
cstore: &'tcx CStore,
498491
hir_map: &'a hir_map::Map<'tcx>,
499492
analysis: &'a ty::CrateAnalysis,
@@ -505,7 +498,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
505498
-> Self {
506499
CompileState {
507500
crate_name: Some(crate_name),
508-
arena: Some(arena),
509501
arenas: Some(arenas),
510502
cstore: Some(cstore),
511503
hir_map: Some(hir_map),
@@ -974,8 +966,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(control: &CompileController,
974966
hir_map: hir_map::Map<'tcx>,
975967
mut analysis: ty::CrateAnalysis,
976968
resolutions: Resolutions,
977-
arena: &'tcx DroplessArena,
978-
arenas: &'tcx GlobalArenas<'tcx>,
969+
arenas: &'tcx AllArenas<'tcx>,
979970
name: &str,
980971
output_filenames: &OutputFilenames,
981972
f: F)
@@ -1035,7 +1026,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(control: &CompileController,
10351026
local_providers,
10361027
extern_providers,
10371028
arenas,
1038-
arena,
10391029
resolutions,
10401030
hir_map,
10411031
query_result_on_disk_cache,

src/librustc_driver/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub fn run_compiler<'a>(args: &[String],
227227
},
228228
};
229229

230-
let cstore = Rc::new(CStore::new(DefaultTransCrate::metadata_loader()));
230+
let cstore = CStore::new(DefaultTransCrate::metadata_loader());
231231

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

244244
do_or_return!(callbacks.late_callback(&matches,
245245
&sess,
246-
&*cstore,
246+
&cstore,
247247
&input,
248248
&odir,
249249
&ofile), Some(sess));
@@ -580,7 +580,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
580580
&state.expanded_crate.take().unwrap(),
581581
state.crate_name.unwrap(),
582582
ppm,
583-
state.arena.unwrap(),
584583
state.arenas.unwrap(),
585584
state.output_filenames.unwrap(),
586585
opt_uii.clone(),

src/librustc_driver/pretty.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use self::NodesMatchingUII::*;
1717

1818
use {abort_on_err, driver};
1919

20-
use rustc::ty::{self, TyCtxt, GlobalArenas, Resolutions};
20+
use rustc::ty::{self, TyCtxt, Resolutions, AllArenas};
2121
use rustc::cfg;
2222
use rustc::cfg::graphviz::LabelledCFG;
2323
use rustc::middle::cstore::CrateStore;
@@ -51,8 +51,6 @@ use rustc::hir::map::blocks;
5151
use rustc::hir;
5252
use rustc::hir::print as pprust_hir;
5353

54-
use arena::DroplessArena;
55-
5654
#[derive(Copy, Clone, PartialEq, Debug)]
5755
pub enum PpSourceMode {
5856
PpmNormal,
@@ -205,8 +203,7 @@ impl PpSourceMode {
205203
hir_map: &hir_map::Map<'tcx>,
206204
analysis: &ty::CrateAnalysis,
207205
resolutions: &Resolutions,
208-
arena: &'tcx DroplessArena,
209-
arenas: &'tcx GlobalArenas<'tcx>,
206+
arenas: &'tcx AllArenas<'tcx>,
210207
output_filenames: &OutputFilenames,
211208
id: &str,
212209
f: F)
@@ -237,7 +234,6 @@ impl PpSourceMode {
237234
hir_map.clone(),
238235
analysis.clone(),
239236
resolutions.clone(),
240-
arena,
241237
arenas,
242238
id,
243239
output_filenames,
@@ -914,8 +910,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
914910
krate: &ast::Crate,
915911
crate_name: &str,
916912
ppm: PpMode,
917-
arena: &'tcx DroplessArena,
918-
arenas: &'tcx GlobalArenas<'tcx>,
913+
arenas: &'tcx AllArenas<'tcx>,
919914
output_filenames: &OutputFilenames,
920915
opt_uii: Option<UserIdentifiedItem>,
921916
ofile: Option<&Path>) {
@@ -926,7 +921,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
926921
analysis,
927922
resolutions,
928923
crate_name,
929-
arena,
930924
arenas,
931925
output_filenames,
932926
ppm,
@@ -965,7 +959,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
965959
hir_map,
966960
analysis,
967961
resolutions,
968-
arena,
969962
arenas,
970963
output_filenames,
971964
crate_name,
@@ -990,7 +983,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
990983
hir_map,
991984
analysis,
992985
resolutions,
993-
arena,
994986
arenas,
995987
output_filenames,
996988
crate_name,
@@ -1007,7 +999,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
1007999
hir_map,
10081000
analysis,
10091001
resolutions,
1010-
arena,
10111002
arenas,
10121003
output_filenames,
10131004
crate_name,
@@ -1042,7 +1033,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
10421033
hir_map,
10431034
analysis,
10441035
resolutions,
1045-
arena,
10461036
arenas,
10471037
output_filenames,
10481038
crate_name,
@@ -1073,8 +1063,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
10731063
analysis: &ty::CrateAnalysis,
10741064
resolutions: &Resolutions,
10751065
crate_name: &str,
1076-
arena: &'tcx DroplessArena,
1077-
arenas: &'tcx GlobalArenas<'tcx>,
1066+
arenas: &'tcx AllArenas<'tcx>,
10781067
output_filenames: &OutputFilenames,
10791068
ppm: PpMode,
10801069
uii: Option<UserIdentifiedItem>,
@@ -1096,7 +1085,6 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
10961085
hir_map.clone(),
10971086
analysis.clone(),
10981087
resolutions.clone(),
1099-
arena,
11001088
arenas,
11011089
crate_name,
11021090
output_filenames,

src/librustc_driver/test.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use errors::{Level, DiagnosticBuilder};
4040
use syntax::feature_gate::UnstableFeatures;
4141
use syntax::symbol::Symbol;
4242
use syntax_pos::DUMMY_SP;
43-
use arena::DroplessArena;
4443

4544
use rustc::hir;
4645

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

134-
let arena = DroplessArena::new();
135-
let arenas = ty::GlobalArenas::new();
133+
let arenas = ty::AllArenas::new();
136134
let hir_map = hir_map::map_crate(&sess, &*cstore, &mut hir_forest, &defs);
137135

138136
// run just enough stuff to build a tcx:
@@ -149,7 +147,6 @@ fn test_env<F>(source_string: &str,
149147
ty::maps::Providers::default(),
150148
ty::maps::Providers::default(),
151149
&arenas,
152-
&arena,
153150
resolutions,
154151
hir_map,
155152
OnDiskCache::new_empty(sess.codemap()),

0 commit comments

Comments
 (0)