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

Rollup of 7 pull requests #47235

Merged
merged 16 commits into from
Jan 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions src/liballoc/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@ impl<T: Ord> BTreeSet<T> {
/// The value may be any borrowed form of the set's value type,
/// but the ordering on the borrowed form *must* match the
/// ordering on the value type.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeSet;
///
/// let set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect();
/// assert_eq!(set.get(&2), Some(&2));
/// assert_eq!(set.get(&4), None);
/// ```
#[stable(feature = "set_recovery", since = "1.9.0")]
pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>
where T: Borrow<Q>,
Expand Down Expand Up @@ -540,6 +550,19 @@ impl<T: Ord> BTreeSet<T> {

/// Adds a value to the set, replacing the existing value, if any, that is equal to the given
/// one. Returns the replaced value.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeSet;
///
/// let mut set = BTreeSet::new();
/// set.insert(Vec::<i32>::new());
///
/// assert_eq!(set.get(&[][..]).unwrap().capacity(), 0);
/// set.replace(Vec::with_capacity(10));
/// assert_eq!(set.get(&[][..]).unwrap().capacity(), 10);
/// ```
#[stable(feature = "set_recovery", since = "1.9.0")]
pub fn replace(&mut self, value: T) -> Option<T> {
Recover::replace(&mut self.map, value)
Expand Down Expand Up @@ -576,6 +599,16 @@ impl<T: Ord> BTreeSet<T> {
/// The value may be any borrowed form of the set's value type,
/// but the ordering on the borrowed form *must* match the
/// ordering on the value type.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeSet;
///
/// let mut set: BTreeSet<_> = [1, 2, 3].iter().cloned().collect();
/// assert_eq!(set.take(&2), Some(2));
/// assert_eq!(set.take(&2), None);
/// ```
#[stable(feature = "set_recovery", since = "1.9.0")]
pub fn take<Q: ?Sized>(&mut self, value: &Q) -> Option<T>
where T: Borrow<Q>,
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ macro_rules! int_impl {
}

/// Checked integer division. Computes `self / rhs`, returning `None`
/// if `rhs == 0` or the operation results in overflow.
/// if `rhs == 0` or the division results in overflow.
///
/// # Examples
///
Expand All @@ -461,7 +461,7 @@ macro_rules! int_impl {
}

/// Checked integer remainder. Computes `self % rhs`, returning `None`
/// if `rhs == 0` or the operation results in overflow.
/// if `rhs == 0` or the division results in overflow.
///
/// # Examples
///
Expand Down Expand Up @@ -1607,7 +1607,7 @@ macro_rules! uint_impl {
}

/// Checked integer division. Computes `self / rhs`, returning `None`
/// if `rhs == 0` or the operation results in overflow.
/// if `rhs == 0`.
///
/// # Examples
///
Expand All @@ -1627,7 +1627,7 @@ macro_rules! uint_impl {
}

/// Checked integer remainder. Computes `self % rhs`, returning `None`
/// if `rhs == 0` or the operation results in overflow.
/// if `rhs == 0`.
///
/// # Examples
///
Expand Down
2 changes: 1 addition & 1 deletion src/libpanic_abort/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8),
pub unsafe extern fn __rust_start_panic(_data: usize, _vtable: usize) -> u32 {
abort();

#[cfg(unix)]
#[cfg(any(unix, target_os = "cloudabi"))]
unsafe fn abort() -> ! {
extern crate libc;
libc::abort();
Expand Down
1 change: 1 addition & 0 deletions src/libpanic_unwind/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ mod imp;

// i686-pc-windows-gnu and all others
#[cfg(any(all(unix, not(target_os = "emscripten")),
target_os = "cloudabi",
target_os = "redox",
all(windows, target_arch = "x86", target_env = "gnu")))]
#[path = "gcc.rs"]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ impl_stable_hash_for!(enum ::syntax::ast::LitKind {
Bool(value)
});

impl_stable_hash_for!(enum ::syntax::ast::IntTy { Is, I8, I16, I32, I64, I128 });
impl_stable_hash_for!(enum ::syntax::ast::UintTy { Us, U8, U16, U32, U64, U128 });
impl_stable_hash_for!(enum ::syntax::ast::IntTy { Isize, I8, I16, I32, I64, I128 });
impl_stable_hash_for!(enum ::syntax::ast::UintTy { Usize, U8, U16, U32, U64, U128 });
impl_stable_hash_for!(enum ::syntax::ast::FloatTy { F32, F64 });
impl_stable_hash_for!(enum ::syntax::ast::Unsafety { Unsafe, Normal });
impl_stable_hash_for!(enum ::syntax::ast::Constness { Const, NotConst });
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'tcx> MemoryPointer {
}


#[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd, Debug)]
#[derive(Copy, Clone, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Debug)]
pub struct AllocId(pub u64);

impl fmt::Display for AllocId {
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"gather borrowck statistics"),
no_landing_pads: bool = (false, parse_bool, [TRACKED],
"omit landing pads for unwinding"),
fewer_names: bool = (false, parse_bool, [TRACKED],
"reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR)"),
debug_llvm: bool = (false, parse_bool, [UNTRACKED],
"enable debug output from LLVM"),
meta_stats: bool = (false, parse_bool, [UNTRACKED],
Expand Down Expand Up @@ -2811,6 +2813,10 @@ mod tests {
opts.debugging_opts.no_landing_pads = true;
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

opts = reference.clone();
opts.debugging_opts.fewer_names = true;
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

opts = reference.clone();
opts.debugging_opts.no_trans = true;
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
Expand Down
9 changes: 8 additions & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use lint;
use middle::allocator::AllocatorKind;
use middle::dependency_format;
use session::search_paths::PathKind;
use session::config::{BorrowckMode, DebugInfoLevel};
use session::config::{BorrowckMode, DebugInfoLevel, OutputType};
use ty::tls;
use util::nodemap::{FxHashMap, FxHashSet};
use util::common::{duration_to_secs_str, ErrorReported};
Expand Down Expand Up @@ -504,6 +504,13 @@ impl Session {
pub fn linker_flavor(&self) -> LinkerFlavor {
self.opts.debugging_opts.linker_flavor.unwrap_or(self.target.target.linker_flavor)
}

pub fn fewer_names(&self) -> bool {
let more_names = self.opts.output_types.contains_key(&OutputType::LlvmAssembly) ||
self.opts.output_types.contains_key(&OutputType::Bitcode);
self.opts.debugging_opts.fewer_names || !more_names
}

pub fn no_landing_pads(&self) -> bool {
self.opts.debugging_opts.no_landing_pads || self.panic_strategy() == PanicStrategy::Abort
}
Expand Down
40 changes: 19 additions & 21 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,13 @@ impl<'tcx> CommonTypes<'tcx> {
char: mk(TyChar),
never: mk(TyNever),
err: mk(TyError),
isize: mk(TyInt(ast::IntTy::Is)),
isize: mk(TyInt(ast::IntTy::Isize)),
i8: mk(TyInt(ast::IntTy::I8)),
i16: mk(TyInt(ast::IntTy::I16)),
i32: mk(TyInt(ast::IntTy::I32)),
i64: mk(TyInt(ast::IntTy::I64)),
i128: mk(TyInt(ast::IntTy::I128)),
usize: mk(TyUint(ast::UintTy::Us)),
usize: mk(TyUint(ast::UintTy::Usize)),
u8: mk(TyUint(ast::UintTy::U8)),
u16: mk(TyUint(ast::UintTy::U16)),
u32: mk(TyUint(ast::UintTy::U32)),
Expand Down Expand Up @@ -895,31 +895,29 @@ pub struct InterpretInterner<'tcx> {
allocs: FxHashSet<&'tcx interpret::Allocation>,

/// Allows obtaining function instance handles via a unique identifier
functions: FxHashMap<u64, Instance<'tcx>>,
functions: FxHashMap<interpret::AllocId, Instance<'tcx>>,

/// Inverse map of `interpret_functions`.
/// Used so we don't allocate a new pointer every time we need one
function_cache: FxHashMap<Instance<'tcx>, u64>,
function_cache: FxHashMap<Instance<'tcx>, interpret::AllocId>,

/// Allows obtaining const allocs via a unique identifier
alloc_by_id: FxHashMap<u64, &'tcx interpret::Allocation>,
alloc_by_id: FxHashMap<interpret::AllocId, &'tcx interpret::Allocation>,

/// The AllocId to assign to the next new regular allocation.
/// Always incremented, never gets smaller.
next_id: u64,
next_id: interpret::AllocId,

/// Allows checking whether a constant already has an allocation
///
/// The pointers are to the beginning of an `alloc_by_id` allocation
alloc_cache: FxHashMap<interpret::GlobalId<'tcx>, interpret::Pointer>,
alloc_cache: FxHashMap<interpret::GlobalId<'tcx>, interpret::AllocId>,

/// A cache for basic byte allocations keyed by their contents. This is used to deduplicate
/// allocations for string and bytestring literals.
literal_alloc_cache: FxHashMap<Vec<u8>, u64>,
literal_alloc_cache: FxHashMap<Vec<u8>, interpret::AllocId>,
}

impl<'tcx> InterpretInterner<'tcx> {
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> u64 {
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> interpret::AllocId {
if let Some(&alloc_id) = self.function_cache.get(&instance) {
return alloc_id;
}
Expand All @@ -932,29 +930,29 @@ impl<'tcx> InterpretInterner<'tcx> {

pub fn get_fn(
&self,
id: u64,
id: interpret::AllocId,
) -> Option<Instance<'tcx>> {
self.functions.get(&id).cloned()
}

pub fn get_alloc(
&self,
id: u64,
id: interpret::AllocId,
) -> Option<&'tcx interpret::Allocation> {
self.alloc_by_id.get(&id).cloned()
}

pub fn get_cached(
&self,
global_id: interpret::GlobalId<'tcx>,
) -> Option<interpret::Pointer> {
) -> Option<interpret::AllocId> {
self.alloc_cache.get(&global_id).cloned()
}

pub fn cache(
&mut self,
global_id: interpret::GlobalId<'tcx>,
ptr: interpret::Pointer,
ptr: interpret::AllocId,
) {
if let Some(old) = self.alloc_cache.insert(global_id, ptr) {
bug!("tried to cache {:?}, but was already existing as {:#?}", global_id, old);
Expand All @@ -963,7 +961,7 @@ impl<'tcx> InterpretInterner<'tcx> {

pub fn intern_at_reserved(
&mut self,
id: u64,
id: interpret::AllocId,
alloc: &'tcx interpret::Allocation,
) {
if let Some(old) = self.alloc_by_id.insert(id, alloc) {
Expand All @@ -975,9 +973,9 @@ impl<'tcx> InterpretInterner<'tcx> {
/// yet have an allocation backing it.
pub fn reserve(
&mut self,
) -> u64 {
) -> interpret::AllocId {
let next = self.next_id;
self.next_id = self.next_id
self.next_id.0 = self.next_id.0
.checked_add(1)
.expect("You overflowed a u64 by incrementing by 1... \
You've just earned yourself a free drink if we ever meet. \
Expand Down Expand Up @@ -1069,7 +1067,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}

/// Allocates a byte or string literal for `mir::interpret`
pub fn allocate_cached(self, bytes: &[u8]) -> u64 {
pub fn allocate_cached(self, bytes: &[u8]) -> interpret::AllocId {
// check whether we already allocated this literal or a constant with the same memory
if let Some(&alloc_id) = self.interpret_interner.borrow().literal_alloc_cache.get(bytes) {
return alloc_id;
Expand Down Expand Up @@ -1912,7 +1910,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {
match tm {
ast::IntTy::Is => self.types.isize,
ast::IntTy::Isize => self.types.isize,
ast::IntTy::I8 => self.types.i8,
ast::IntTy::I16 => self.types.i16,
ast::IntTy::I32 => self.types.i32,
Expand All @@ -1923,7 +1921,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

pub fn mk_mach_uint(self, tm: ast::UintTy) -> Ty<'tcx> {
match tm {
ast::UintTy::Us => self.types.usize,
ast::UintTy::Usize => self.types.usize,
ast::UintTy::U8 => self.types.u8,
ast::UintTy::U16 => self.types.u16,
ast::UintTy::U32 => self.types.u32,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ impl<'a, 'tcx> Integer {
attr::SignedInt(IntTy::I32) | attr::UnsignedInt(UintTy::U32) => I32,
attr::SignedInt(IntTy::I64) | attr::UnsignedInt(UintTy::U64) => I64,
attr::SignedInt(IntTy::I128) | attr::UnsignedInt(UintTy::U128) => I128,
attr::SignedInt(IntTy::Is) | attr::UnsignedInt(UintTy::Us) => {
attr::SignedInt(IntTy::Isize) | attr::UnsignedInt(UintTy::Usize) => {
dl.ptr_sized_integer()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ impl ReprOptions {
pub fn linear(&self) -> bool { self.flags.contains(ReprFlags::IS_LINEAR) }

pub fn discr_type(&self) -> attr::IntType {
self.int.unwrap_or(attr::SignedInt(ast::IntTy::Is))
self.int.unwrap_or(attr::SignedInt(ast::IntTy::Isize))
}

/// Returns true if this `#[repr()]` should inhabit "smart enum
Expand Down
9 changes: 1 addition & 8 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1478,13 +1478,6 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
}
}

pub fn is_uint(&self) -> bool {
match self.sty {
TyInfer(IntVar(_)) | TyUint(ast::UintTy::Us) => true,
_ => false
}
}

pub fn is_char(&self) -> bool {
match self.sty {
TyChar => true,
Expand Down Expand Up @@ -1512,7 +1505,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {

pub fn is_machine(&self) -> bool {
match self.sty {
TyInt(ast::IntTy::Is) | TyUint(ast::UintTy::Us) => false,
TyInt(ast::IntTy::Isize) | TyUint(ast::UintTy::Usize) => false,
TyInt(..) | TyUint(..) | TyFloat(..) => true,
_ => false,
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ macro_rules! typed_literal {
SignedInt(ast::IntTy::I32) => ConstInt::I32($lit),
SignedInt(ast::IntTy::I64) => ConstInt::I64($lit),
SignedInt(ast::IntTy::I128) => ConstInt::I128($lit),
SignedInt(ast::IntTy::Is) => match $tcx.sess.target.isize_ty {
SignedInt(ast::IntTy::Isize) => match $tcx.sess.target.isize_ty {
ast::IntTy::I16 => ConstInt::Isize(ConstIsize::Is16($lit)),
ast::IntTy::I32 => ConstInt::Isize(ConstIsize::Is32($lit)),
ast::IntTy::I64 => ConstInt::Isize(ConstIsize::Is64($lit)),
Expand All @@ -66,7 +66,7 @@ macro_rules! typed_literal {
UnsignedInt(ast::UintTy::U32) => ConstInt::U32($lit),
UnsignedInt(ast::UintTy::U64) => ConstInt::U64($lit),
UnsignedInt(ast::UintTy::U128) => ConstInt::U128($lit),
UnsignedInt(ast::UintTy::Us) => match $tcx.sess.target.usize_ty {
UnsignedInt(ast::UintTy::Usize) => match $tcx.sess.target.usize_ty {
ast::UintTy::U16 => ConstInt::Usize(ConstUsize::Us16($lit)),
ast::UintTy::U32 => ConstInt::Usize(ConstUsize::Us32($lit)),
ast::UintTy::U64 => ConstInt::Usize(ConstUsize::Us64($lit)),
Expand All @@ -84,13 +84,13 @@ impl IntTypeExt for attr::IntType {
SignedInt(ast::IntTy::I32) => tcx.types.i32,
SignedInt(ast::IntTy::I64) => tcx.types.i64,
SignedInt(ast::IntTy::I128) => tcx.types.i128,
SignedInt(ast::IntTy::Is) => tcx.types.isize,
SignedInt(ast::IntTy::Isize) => tcx.types.isize,
UnsignedInt(ast::UintTy::U8) => tcx.types.u8,
UnsignedInt(ast::UintTy::U16) => tcx.types.u16,
UnsignedInt(ast::UintTy::U32) => tcx.types.u32,
UnsignedInt(ast::UintTy::U64) => tcx.types.u64,
UnsignedInt(ast::UintTy::U128) => tcx.types.u128,
UnsignedInt(ast::UintTy::Us) => tcx.types.usize,
UnsignedInt(ast::UintTy::Usize) => tcx.types.usize,
}
}

Expand All @@ -105,13 +105,13 @@ impl IntTypeExt for attr::IntType {
(SignedInt(ast::IntTy::I32), ConstInt::I32(_)) => {},
(SignedInt(ast::IntTy::I64), ConstInt::I64(_)) => {},
(SignedInt(ast::IntTy::I128), ConstInt::I128(_)) => {},
(SignedInt(ast::IntTy::Is), ConstInt::Isize(_)) => {},
(SignedInt(ast::IntTy::Isize), ConstInt::Isize(_)) => {},
(UnsignedInt(ast::UintTy::U8), ConstInt::U8(_)) => {},
(UnsignedInt(ast::UintTy::U16), ConstInt::U16(_)) => {},
(UnsignedInt(ast::UintTy::U32), ConstInt::U32(_)) => {},
(UnsignedInt(ast::UintTy::U64), ConstInt::U64(_)) => {},
(UnsignedInt(ast::UintTy::U128), ConstInt::U128(_)) => {},
(UnsignedInt(ast::UintTy::Us), ConstInt::Usize(_)) => {},
(UnsignedInt(ast::UintTy::Usize), ConstInt::Usize(_)) => {},
_ => bug!("disr type mismatch: {:?} vs {:?}", self, val),
}
}
Expand Down
Loading