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

Even more thread-safety changes #49558

Merged
merged 25 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e5a602e
Add OneThread which only allows its inner value to be used in one thread
Zoxc Apr 1, 2018
60d0cbe
Add insert_same extension to HashMap
Zoxc Apr 1, 2018
26f16e8
Add a Once type for values which are only written once
Zoxc Apr 1, 2018
49a2b80
Make sure the lint store is only used on one thread
Zoxc Apr 1, 2018
472b416
Querify all_traits
Zoxc Apr 1, 2018
cf3b790
Make recursion_limit and type_length_limit thread-safe
Zoxc Apr 1, 2018
05c4ea4
Remove derive_macros
Zoxc Apr 1, 2018
7aa7198
Make PerfStats thread-safe and remove unused fields
Zoxc Apr 1, 2018
27adb31
Combine Session.entry_fn and Session.entry_type and make them thread-…
Zoxc Apr 1, 2018
e82b6c4
Make Session.plugin_registrar_fn and Session.derive_registrar_fn thre…
Zoxc Apr 1, 2018
753cd9a
Make sure Session.incr_comp_session is only used on one thread
Zoxc Apr 1, 2018
a23e90a
Remove Cell from const_eval_stack_frame_limit and const_eval_step_limit
Zoxc Apr 1, 2018
a46f059
Disable optimization fuel when using multiple threads
Zoxc Apr 1, 2018
904e2b6
Make Session::features_untracked thread-safe
Zoxc Apr 1, 2018
b0c7bda
Make Session.code_stats thread-safe
Zoxc Apr 1, 2018
8380539
Make sure Session.next_node_id is only used on one thread
Zoxc Apr 1, 2018
271c8d3
Make Session.crate_disambiguator thread-safe
Zoxc Apr 1, 2018
73b26f7
Make sure Session.imported_macro_spans is only used on one thread
Zoxc Apr 1, 2018
7d33d1a
Make Session.has_global_allocator thread-safe
Zoxc Apr 1, 2018
0e51d48
Make sure Session.plugin_llvm_passes is only used on one thread
Zoxc Apr 1, 2018
046af1c
Make sure Session.plugin_attributes is only used on one thread
Zoxc Apr 1, 2018
cbf8ad4
Make Session.crate_types thread-safe
Zoxc Apr 1, 2018
66488a5
Make Session.dependency_formats thread-safe
Zoxc Apr 1, 2018
dacf9ba
Make Session.injected_allocator and Session.allocator_kind thread-safe
Zoxc Apr 1, 2018
006f9b2
Make Session.injected_panic_runtime thread-safe
Zoxc Apr 1, 2018
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
1 change: 1 addition & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ define_dep_nodes!( <'tcx>
[input] MaybeUnusedTraitImport(DefId),
[input] MaybeUnusedExternCrates,
[eval_always] StabilityIndex,
[eval_always] AllTraits,
[input] AllCrateNums,
[] ExportedSymbols(CrateNum),
[eval_always] CollectAndPartitionTranslationItems,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ use rustc_data_structures::indexed_vec::Idx;
use serialize::UseSpecializedDecodable;
use std::fmt::Debug;
use std::ops::Index;
use std::sync::atomic::Ordering;
use syntax::codemap::Span;
use traits::{Obligation, ObligationCause, PredicateObligation};
use ty::{self, CanonicalVar, Lift, Region, Slice, Ty, TyCtxt, TypeFlags};
use ty::subst::{Kind, UnpackedKind};
use ty::fold::{TypeFoldable, TypeFolder};
use util::captures::Captures;
use util::common::CellUsizeExt;

use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -473,7 +473,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
where
V: Canonicalize<'gcx, 'tcx>,
{
self.tcx.sess.perf_stats.queries_canonicalized.increment();
self.tcx.sess.perf_stats.queries_canonicalized.fetch_add(1, Ordering::Relaxed);

Canonicalizer::canonicalize(
value,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ fn create_and_seed_worklist<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}

// Seed entry point
if let Some((id, _)) = *tcx.sess.entry_fn.borrow() {
if let Some((id, _, _)) = *tcx.sess.entry_fn.borrow() {
worklist.push(id);
}

Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ pub enum Linkage {

pub fn calculate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
let sess = &tcx.sess;
let mut fmts = sess.dependency_formats.borrow_mut();
let mut fmts = FxHashMap();
for &ty in sess.crate_types.borrow().iter() {
let linkage = calculate_type(tcx, ty);
verify_ok(tcx, &linkage);
fmts.insert(ty, linkage);
}
sess.abort_if_errors();
sess.dependency_formats.set(fmts);
}

fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
Expand Down Expand Up @@ -222,7 +223,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
//
// Things like allocators and panic runtimes may not have been activated
// quite yet, so do so here.
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
&|cnum| tcx.is_panic_runtime(cnum));
activate_injected_allocator(sess, &mut ret);

Expand Down Expand Up @@ -301,7 +302,7 @@ fn attempt_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<DependencyLis
// Our allocator/panic runtime may not have been linked above if it wasn't
// explicitly linked, which is the case for any injected dependency. Handle
// that here and activate them.
activate_injected_dep(sess.injected_panic_runtime.get(), &mut ret,
activate_injected_dep(*sess.injected_panic_runtime.get(), &mut ret,
&|cnum| tcx.is_panic_runtime(cnum));
activate_injected_allocator(sess, &mut ret);

Expand Down
19 changes: 9 additions & 10 deletions src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ pub fn find_entry_point(session: &Session,
});
if !any_exe {
// No need to find a main function
session.entry_fn.set(None);
return
}

// If the user wants no main function at all, then stop here.
if attr::contains_name(&hir_map.krate().attrs, "no_main") {
session.entry_type.set(Some(config::EntryNone));
session.entry_fn.set(None);
return
}

Expand Down Expand Up @@ -153,17 +154,15 @@ fn find_item(item: &Item, ctxt: &mut EntryContext, at_root: bool) {
}

fn configure_main(this: &mut EntryContext, crate_name: &str) {
if this.start_fn.is_some() {
*this.session.entry_fn.borrow_mut() = this.start_fn;
this.session.entry_type.set(Some(config::EntryStart));
} else if this.attr_main_fn.is_some() {
*this.session.entry_fn.borrow_mut() = this.attr_main_fn;
this.session.entry_type.set(Some(config::EntryMain));
} else if this.main_fn.is_some() {
*this.session.entry_fn.borrow_mut() = this.main_fn;
this.session.entry_type.set(Some(config::EntryMain));
if let Some((node_id, span)) = this.start_fn {
this.session.entry_fn.set(Some((node_id, span, config::EntryStart)));
} else if let Some((node_id, span)) = this.attr_main_fn {
this.session.entry_fn.set(Some((node_id, span, config::EntryMain)));
} else if let Some((node_id, span)) = this.main_fn {
this.session.entry_fn.set(Some((node_id, span, config::EntryMain)));
} else {
// No main function
this.session.entry_fn.set(None);
let mut err = struct_err!(this.session, E0601,
"`main` function not found in crate `{}`", crate_name);
if !this.non_main_fns.is_empty() {
Expand Down
11 changes: 6 additions & 5 deletions src/librustc/middle/recursion_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
use session::Session;
use syntax::ast;

use std::cell::Cell;
use rustc_data_structures::sync::Once;

pub fn update_limits(sess: &Session, krate: &ast::Crate) {
update_limit(sess, krate, &sess.recursion_limit, "recursion_limit",
"recursion limit");
"recursion limit", 64);
update_limit(sess, krate, &sess.type_length_limit, "type_length_limit",
"type length limit");
"type length limit", 1048576);
}

fn update_limit(sess: &Session, krate: &ast::Crate, limit: &Cell<usize>,
name: &str, description: &str) {
fn update_limit(sess: &Session, krate: &ast::Crate, limit: &Once<usize>,
name: &str, description: &str, default: usize) {
for attr in &krate.attrs {
if !attr.check_name(name) {
continue;
Expand All @@ -45,4 +45,5 @@ fn update_limit(sess: &Session, krate: &ast::Crate, limit: &Cell<usize>,
"malformed {} attribute, expected #![{}=\"N\"]",
description, name);
}
limit.set(default);
}
11 changes: 8 additions & 3 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,11 @@ impl Options {

// The type of entry function, so
// users can have their own entry
// functions that don't start a
// scheduler
// functions
#[derive(Copy, Clone, PartialEq)]
pub enum EntryFnType {
EntryMain,
EntryStart,
EntryNone,
}

#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug)]
Expand Down Expand Up @@ -1861,6 +1859,13 @@ pub fn build_session_options_and_crate_config(
);
}

if debugging_opts.query_threads.unwrap_or(1) > 1 && debugging_opts.fuel.is_some() {
early_error(
error_format,
"Optimization fuel is incompatible with multiple query threads",
);
}

if codegen_units == Some(0) {
early_error(
error_format,
Expand Down
Loading