Skip to content

Commit

Permalink
Auto merge of #49558 - Zoxc:sync-misc, r=michaelwoerister
Browse files Browse the repository at this point in the history
Even more thread-safety changes

r? @michaelwoerister
  • Loading branch information
bors committed Apr 12, 2018
2 parents 9afed64 + 006f9b2 commit 6c53749
Show file tree
Hide file tree
Showing 40 changed files with 425 additions and 285 deletions.
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

0 comments on commit 6c53749

Please sign in to comment.