Skip to content

Commit

Permalink
Auto merge of rust-lang#30410 - Manishearth:rollup, r=Manishearth
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Dec 16, 2015
2 parents ce7bc51 + f0361a0 commit 785a8a6
Show file tree
Hide file tree
Showing 64 changed files with 455 additions and 270 deletions.
11 changes: 8 additions & 3 deletions src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ use Bound;

/// A set based on a B-Tree.
///
/// See BTreeMap's documentation for a detailed discussion of this collection's performance
/// See [`BTreeMap`]'s documentation for a detailed discussion of this collection's performance
/// benefits and drawbacks.
///
/// It is a logic error for an item to be modified in such a way that the item's ordering relative
/// to any other item, as determined by the `Ord` trait, changes while it is in the set. This is
/// normally only possible through `Cell`, `RefCell`, global state, I/O, or unsafe code.
/// to any other item, as determined by the [`Ord`] trait, changes while it is in the set. This is
/// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code.
///
/// [`BTreeMap`]: ../struct.BTreeMap.html
/// [`Ord`]: ../../core/cmp/trait.Ord.html
/// [`Cell`]: ../../std/cell/struct.Cell.html
/// [`RefCell`]: ../../std/cell/struct.RefCell.html
#[derive(Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct BTreeSet<T> {
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/check_static_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ pub fn check_crate<'ast>(sess: &Session,
ast_map: ast_map,
discriminant_map: RefCell::new(NodeMap()),
};
krate.visit_all_items(&mut visitor);
sess.abort_if_errors();
sess.abort_if_new_errors(|| {
krate.visit_all_items(&mut visitor);
});
}

struct CheckItemRecursionVisitor<'a, 'ast: 'a> {
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/middle/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub enum Def {
DefStruct(DefId),
DefLabel(ast::NodeId),
DefMethod(DefId),
DefErr,
}

/// The result of resolving a path.
Expand Down Expand Up @@ -124,7 +125,7 @@ impl Def {
DefVariant(..) | DefTy(..) | DefAssociatedTy(..) |
DefTyParam(..) | DefUse(..) | DefStruct(..) | DefTrait(..) |
DefMethod(..) | DefConst(..) | DefAssociatedConst(..) |
DefPrimTy(..) | DefLabel(..) | DefSelfTy(..) => {
DefPrimTy(..) | DefLabel(..) | DefSelfTy(..) | DefErr => {
panic!("attempted .def_id() on invalid {:?}", self)
}
}
Expand All @@ -142,7 +143,8 @@ impl Def {

DefLabel(..) |
DefPrimTy(..) |
DefSelfTy(..) => {
DefSelfTy(..) |
DefErr => {
panic!("attempted .def_id() on invalid def: {:?}", self)
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/librustc/middle/infer/region_inference/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub use self::RegionResolutionError::*;
pub use self::VarValue::*;

use super::{RegionVariableOrigin, SubregionOrigin, TypeTrace, MiscVariable};
use super::unify_key;

use rustc_data_structures::graph::{self, Direction, NodeIndex};
use rustc_data_structures::unify::{self, UnificationTable};
Expand Down Expand Up @@ -345,10 +346,13 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
}

pub fn new_region_var(&self, origin: RegionVariableOrigin) -> RegionVid {
let id = self.num_vars();
let vid = RegionVid { index: self.num_vars() };
self.var_origins.borrow_mut().push(origin.clone());
let vid = self.unification_table.borrow_mut().new_key(());
assert_eq!(vid.index, id);

let u_vid = self.unification_table.borrow_mut().new_key(
unify_key::RegionVidKey { min_vid: vid }
);
assert_eq!(vid, u_vid);
if self.in_snapshot() {
self.undo_log.borrow_mut().push(AddVar(vid));
}
Expand Down Expand Up @@ -581,7 +585,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
}

pub fn opportunistic_resolve_var(&self, rid: RegionVid) -> ty::Region {
ty::ReVar(self.unification_table.borrow_mut().find(rid))
ty::ReVar(self.unification_table.borrow_mut().find_value(rid).min_vid)
}

fn combine_map(&self, t: CombineMapType) -> &RefCell<CombineMap> {
Expand Down
24 changes: 22 additions & 2 deletions src/librustc/middle/infer/unify_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use syntax::ast;
use middle::ty::{self, IntVarValue, Ty};
use rustc_data_structures::unify::UnifyKey;
use rustc_data_structures::unify::{Combine, UnifyKey};

pub trait ToType<'tcx> {
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx>;
Expand All @@ -23,8 +23,28 @@ impl UnifyKey for ty::IntVid {
fn tag(_: Option<ty::IntVid>) -> &'static str { "IntVid" }
}

#[derive(PartialEq, Copy, Clone, Debug)]
pub struct RegionVidKey {
/// The minimum region vid in the unification set. This is needed
/// to have a canonical name for a type to prevent infinite
/// recursion.
pub min_vid: ty::RegionVid
}

impl Combine for RegionVidKey {
fn combine(&self, other: &RegionVidKey) -> RegionVidKey {
let min_vid = if self.min_vid.index < other.min_vid.index {
self.min_vid
} else {
other.min_vid
};

RegionVidKey { min_vid: min_vid }
}
}

impl UnifyKey for ty::RegionVid {
type Value = ();
type Value = RegionVidKey;
fn index(&self) -> u32 { self.index }
fn from_index(i: u32) -> ty::RegionVid { ty::RegionVid { index: i } }
fn tag(_: Option<ty::RegionVid>) -> &'static str { "RegionVid" }
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
note: NoteNone
}))
}

def::DefErr => panic!("DefErr in memory categorization")
}
}

Expand Down Expand Up @@ -1196,7 +1198,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
(*op)(self, cmt.clone(), pat);

let opt_def = if let Some(path_res) = self.tcx().def_map.borrow().get(&pat.id) {
if path_res.depth != 0 {
if path_res.depth != 0 || path_res.base_def == def::DefErr {
// Since patterns can be associated constants
// which are resolved during typeck, we might have
// some unresolved patterns reaching this stage
Expand Down Expand Up @@ -1261,7 +1263,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
_ => {
self.tcx().sess.span_bug(
pat.span,
"enum pattern didn't resolve to enum or struct");
&format!("enum pattern didn't resolve to enum or struct {:?}", opt_def));
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,16 @@ static ROOT_SCOPE: ScopeChain<'static> = RootScope;

pub fn krate(sess: &Session, krate: &hir::Crate, def_map: &DefMap) -> NamedRegionMap {
let mut named_region_map = NodeMap();
krate.visit_all_items(&mut LifetimeContext {
sess: sess,
named_region_map: &mut named_region_map,
scope: &ROOT_SCOPE,
def_map: def_map,
trait_ref_hack: false,
labels_in_fn: vec![],
sess.abort_if_new_errors(|| {
krate.visit_all_items(&mut LifetimeContext {
sess: sess,
named_region_map: &mut named_region_map,
scope: &ROOT_SCOPE,
def_map: def_map,
trait_ref_hack: false,
labels_in_fn: vec![],
});
});
sess.abort_if_errors();
named_region_map
}

Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2100,9 +2100,8 @@ impl<'tcx> ctxt<'tcx> {
}) => {
true
}

Some(&def::PathResolution { base_def: def::DefErr, .. })=> true,
Some(..) => false,

None => self.sess.span_bug(expr.span, &format!(
"no def for path {}", expr.id))
}
Expand Down
9 changes: 9 additions & 0 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ impl Session {
_ => {}
}
}
pub fn abort_if_new_errors<F>(&self, mut f: F)
where F: FnMut()
{
let count = self.err_count();
f();
if self.err_count() > count {
self.abort_if_errors();
}
}
pub fn span_warn(&self, sp: Span, msg: &str) {
if self.can_print_warnings {
self.diagnostic().span_warn(sp, msg)
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_borrowck/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ use rustc_front::hir::{Expr, FnDecl, Block, Pat};
use rustc_front::intravisit;
use rustc_front::intravisit::Visitor;

use self::restrictions::RestrictionResult;

mod lifetime;
mod restrictions;
mod gather_moves;
Expand Down Expand Up @@ -354,12 +356,12 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {

// Create the loan record (if needed).
let loan = match restr {
restrictions::Safe => {
RestrictionResult::Safe => {
// No restrictions---no loan record necessary
return;
}

restrictions::SafeIf(loan_path, restricted_paths) => {
RestrictionResult::SafeIf(loan_path, restricted_paths) => {
let loan_scope = match loan_region {
ty::ReScope(scope) => scope,

Expand Down
22 changes: 10 additions & 12 deletions src/librustc_borrowck/borrowck/gather_loans/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

//! Computes the restrictions that result from a borrow.
pub use self::RestrictionResult::*;

use borrowck::*;
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc;
Expand Down Expand Up @@ -69,19 +67,19 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
// are inherently non-aliasable, they can only be
// accessed later through the borrow itself and hence
// must inherently comply with its terms.
Safe
RestrictionResult::Safe
}

Categorization::Local(local_id) => {
// R-Variable, locally declared
let lp = new_lp(LpVar(local_id));
SafeIf(lp.clone(), vec![lp])
RestrictionResult::SafeIf(lp.clone(), vec![lp])
}

Categorization::Upvar(mc::Upvar { id, .. }) => {
// R-Variable, captured into closure
let lp = new_lp(LpUpvar(id));
SafeIf(lp.clone(), vec![lp])
RestrictionResult::SafeIf(lp.clone(), vec![lp])
}

Categorization::Downcast(cmt_base, _) => {
Expand All @@ -106,7 +104,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
}

Categorization::StaticItem => {
Safe
RestrictionResult::Safe
}

Categorization::Deref(cmt_base, _, pk) => {
Expand All @@ -133,11 +131,11 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
cmt: cmt_base,
code: err_borrowed_pointer_too_short(
self.loan_region, lt)});
return Safe;
return RestrictionResult::Safe;
}

match bk {
ty::ImmBorrow => Safe,
ty::ImmBorrow => RestrictionResult::Safe,
ty::MutBorrow | ty::UniqueImmBorrow => {
// R-Deref-Mut-Borrowed
//
Expand All @@ -150,7 +148,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
}
}
// Borrowck is not relevant for raw pointers
mc::UnsafePtr(..) => Safe
mc::UnsafePtr(..) => RestrictionResult::Safe
}
}
}
Expand All @@ -161,12 +159,12 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
cmt: &mc::cmt<'tcx>,
elem: LoanPathElem) -> RestrictionResult<'tcx> {
match result {
Safe => Safe,
SafeIf(base_lp, mut base_vec) => {
RestrictionResult::Safe => RestrictionResult::Safe,
RestrictionResult::SafeIf(base_lp, mut base_vec) => {
let v = LpExtend(base_lp, cmt.mutbl, elem);
let lp = Rc::new(LoanPath::new(v, cmt.ty));
base_vec.push(lp.clone());
SafeIf(lp, base_vec)
RestrictionResult::SafeIf(lp, base_vec)
}
}
}
Expand Down
21 changes: 18 additions & 3 deletions src/librustc_data_structures/unify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ pub trait UnifyKey : Copy + Clone + Debug + PartialEq {
fn tag(k: Option<Self>) -> &'static str;
}

/// This trait is implemented for unify values that can be
/// combined. This relation should be a monoid.
pub trait Combine {
fn combine(&self, other: &Self) -> Self;
}

impl Combine for () {
fn combine(&self, _other: &()) {}
}

/// Value of a unification key. We implement Tarjan's union-find
/// algorithm: when two keys are unified, one of them is converted
/// into a "redirect" pointing at the other. These redirects form a
Expand Down Expand Up @@ -243,23 +253,28 @@ impl<K:UnifyKey> sv::SnapshotVecDelegate for Delegate<K> {
///////////////////////////////////////////////////////////////////////////
// Base union-find algorithm, where we are just making sets

impl<'tcx,K> UnificationTable<K>
where K : UnifyKey<Value=()>,
impl<'tcx,K:UnifyKey> UnificationTable<K>
where K::Value: Combine
{
pub fn union(&mut self, a_id: K, b_id: K) {
let node_a = self.get(a_id);
let node_b = self.get(b_id);
let a_id = node_a.key();
let b_id = node_b.key();
if a_id != b_id {
self.unify(node_a, node_b, ());
let new_value = node_a.value.combine(&node_b.value);
self.unify(node_a, node_b, new_value);
}
}

pub fn find(&mut self, id: K) -> K {
self.get(id).key()
}

pub fn find_value(&mut self, id: K) -> K::Value {
self.get(id).value
}

pub fn unioned(&mut self, a_id: K, b_id: K) -> bool {
self.find(a_id) == self.find(b_id)
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_metadata/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ impl tr for def::Def {
def::DefUpvar(did1, nid1, index, nid2)
}
def::DefStruct(did) => def::DefStruct(did.tr(dcx)),
def::DefLabel(nid) => def::DefLabel(dcx.tr_id(nid))
def::DefLabel(nid) => def::DefLabel(dcx.tr_id(nid)),
def::DefErr => def::DefErr,
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
DefUse(..) |
DefUpvar(..) |
DefLabel(..) |
DefSelfTy(..) => {
DefSelfTy(..) |
DefErr => {
panic!("didn't expect `{:?}`", def);
}
}
Expand Down
Loading

0 comments on commit 785a8a6

Please sign in to comment.