Skip to content

Commit

Permalink
Auto merge of #47900 - kennytm:rollup, r=kennytm
Browse files Browse the repository at this point in the history
Rollup of 16 pull requests

- Successful merges: #47838, #47840, #47844, #47874, #47875, #47876, #47884, #47886, #47889, #47890, #47891, #47795, #47677, #47893, #47895, #47552
- Failed merges:
  • Loading branch information
bors committed Jan 31, 2018
2 parents 560a2f4 + af95302 commit 8ccab7e
Show file tree
Hide file tree
Showing 43 changed files with 320 additions and 48 deletions.
5 changes: 5 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ impl<'a> Builder<'a> {
self.ensure(Libdir { compiler, target })
}

pub fn sysroot_codegen_backends(&self, compiler: Compiler) -> PathBuf {
self.sysroot_libdir(compiler, compiler.host)
.with_file_name("codegen-backends")
}

/// Returns the compiler's libdir where it stores the dynamic libraries that
/// it itself links against.
///
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,7 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder,
//
// Here we're looking for the output dylib of the `CodegenBackend` step and
// we're copying that into the `codegen-backends` folder.
let libdir = builder.sysroot_libdir(target_compiler, target);
let dst = libdir.join("codegen-backends");
let dst = builder.sysroot_codegen_backends(target_compiler);
t!(fs::create_dir_all(&dst));

for backend in builder.config.rust_codegen_backends.iter() {
Expand Down
8 changes: 3 additions & 5 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,9 @@ impl Step for Rustc {
}

// Copy over the codegen backends
let backends_src = builder.sysroot_libdir(compiler, host)
.join("codegen-backends");
let backends_dst = image.join("lib/rustlib")
.join(&*host)
.join("lib/codegen-backends");
let backends_src = builder.sysroot_codegen_backends(compiler);
let backends_rel = backends_src.strip_prefix(&src).unwrap();
let backends_dst = image.join(&backends_rel);
t!(fs::create_dir_all(&backends_dst));
cp_r(&backends_src, &backends_dst);

Expand Down
2 changes: 2 additions & 0 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,7 @@ impl Display for ! {

#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for bool {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result {
Display::fmt(self, f)
}
Expand Down Expand Up @@ -1748,6 +1749,7 @@ impl<T: Debug> Debug for [T] {

#[stable(feature = "rust1", since = "1.0.0")]
impl Debug for () {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result {
f.pad("()")
}
Expand Down
1 change: 1 addition & 0 deletions src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ macro_rules! debug {
($T:ident) => {
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for $T {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
Expand Down
44 changes: 44 additions & 0 deletions src/libcore/iter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ use fmt;
use iter_private::TrustedRandomAccess;
use ops::Try;
use usize;
use intrinsics;

#[stable(feature = "rust1", since = "1.0.0")]
pub use self::iterator::Iterator;
Expand Down Expand Up @@ -694,6 +695,49 @@ impl<I> Iterator for StepBy<I> where I: Iterator {
(f(inner_hint.0), inner_hint.1.map(f))
}
}

#[inline]
fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
if self.first_take {
self.first_take = false;
let first = self.iter.next();
if n == 0 {
return first;
}
n -= 1;
}
// n and self.step are indices, we need to add 1 to get the amount of elements
// When calling `.nth`, we need to subtract 1 again to convert back to an index
// step + 1 can't overflow because `.step_by` sets `self.step` to `step - 1`
let mut step = self.step + 1;
// n + 1 could overflow
// thus, if n is usize::MAX, instead of adding one, we call .nth(step)
if n == usize::MAX {
self.iter.nth(step - 1);
} else {
n += 1;
}

// overflow handling
loop {
let mul = n.checked_mul(step);
if unsafe { intrinsics::likely(mul.is_some()) } {
return self.iter.nth(mul.unwrap() - 1);
}
let div_n = usize::MAX / n;
let div_step = usize::MAX / step;
let nth_n = div_n * n;
let nth_step = div_step * step;
let nth = if nth_n > nth_step {
step -= div_n;
nth_n
} else {
n -= div_step;
nth_step
};
self.iter.nth(nth - 1);
}
}
}

// StepBy can only make the iterator shorter, so the len will still fit.
Expand Down
62 changes: 62 additions & 0 deletions src/libcore/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,68 @@ fn test_iterator_step_by() {
assert_eq!(it.next(), None);
}

#[test]
fn test_iterator_step_by_nth() {
let mut it = (0..16).step_by(5);
assert_eq!(it.nth(0), Some(0));
assert_eq!(it.nth(0), Some(5));
assert_eq!(it.nth(0), Some(10));
assert_eq!(it.nth(0), Some(15));
assert_eq!(it.nth(0), None);

let it = (0..18).step_by(5);
assert_eq!(it.clone().nth(0), Some(0));
assert_eq!(it.clone().nth(1), Some(5));
assert_eq!(it.clone().nth(2), Some(10));
assert_eq!(it.clone().nth(3), Some(15));
assert_eq!(it.clone().nth(4), None);
assert_eq!(it.clone().nth(42), None);
}

#[test]
fn test_iterator_step_by_nth_overflow() {
#[cfg(target_pointer_width = "8")]
type Bigger = u16;
#[cfg(target_pointer_width = "16")]
type Bigger = u32;
#[cfg(target_pointer_width = "32")]
type Bigger = u64;
#[cfg(target_pointer_width = "64")]
type Bigger = u128;

#[derive(Clone)]
struct Test(Bigger);
impl<'a> Iterator for &'a mut Test {
type Item = i32;
fn next(&mut self) -> Option<Self::Item> { Some(21) }
fn nth(&mut self, n: usize) -> Option<Self::Item> {
self.0 += n as Bigger + 1;
Some(42)
}
}

let mut it = Test(0);
let root = usize::MAX >> (::std::mem::size_of::<usize>() * 8 / 2);
let n = root + 20;
(&mut it).step_by(n).nth(n);
assert_eq!(it.0, n as Bigger * n as Bigger);

// large step
let mut it = Test(0);
(&mut it).step_by(usize::MAX).nth(5);
assert_eq!(it.0, (usize::MAX as Bigger) * 5);

// n + 1 overflows
let mut it = Test(0);
(&mut it).step_by(2).nth(usize::MAX);
assert_eq!(it.0, (usize::MAX as Bigger) * 2);

// n + 1 overflows
let mut it = Test(0);
(&mut it).step_by(1).nth(usize::MAX);
assert_eq!(it.0, (usize::MAX as Bigger) * 1);
}

#[test]
#[should_panic]
fn test_iterator_step_by_zero() {
Expand Down
3 changes: 3 additions & 0 deletions src/libpanic_abort/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
#![feature(libc)]
#![feature(panic_runtime)]
#![feature(staged_api)]
#![feature(rustc_attrs)]

// Rust's "try" function, but if we're aborting on panics we just call the
// function as there's nothing else we need to do here.
#[no_mangle]
#[rustc_std_internal_symbol]
pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8),
data: *mut u8,
_data_ptr: *mut usize,
Expand All @@ -50,6 +52,7 @@ pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8),
// will kill us with an illegal instruction, which will do a good enough job for
// now hopefully.
#[no_mangle]
#[rustc_std_internal_symbol]
pub unsafe extern fn __rust_start_panic(_data: usize, _vtable: usize) -> u32 {
abort();

Expand Down
1 change: 1 addition & 0 deletions src/librustc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pointers for understanding them better.
- `'gcx` -- the lifetime of the global arena (see `librustc/ty`).
- generics -- the set of generic type parameters defined on a type or item
- ICE -- internal compiler error. When the compiler crashes.
- ICH -- incremental compilation hash.
- infcx -- the inference context (see `librustc/infer`)
- MIR -- the **Mid-level IR** that is created after type-checking for use by borrowck and trans.
Defined in the `src/librustc/mir/` module, but much of the code that manipulates it is
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,9 @@ define_dep_nodes!( <'tcx>
[] TargetFeaturesEnabled(DefId),

[] InstanceDefSizeEstimate { instance_def: InstanceDef<'tcx> },

[] GetSymbolExportLevel(DefId),

);

trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
span,
node: hir::ImplItemKind::Method(hir::MethodSig { ref decl, .. }, _),
..
}) |
hir::map::NodeTraitItem(&hir::TraitItem {
span,
node: hir::TraitItemKind::Method(hir::MethodSig { ref decl, .. }, _),
..
}) => {
(self.tcx.sess.codemap().def_span(span), decl.inputs.iter()
.map(|arg| match arg.clone().into_inner().node {
Expand Down
1 change: 1 addition & 0 deletions src/librustc/ty/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ define_maps! { <'tcx>
-> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>),
[] fn export_name: ExportName(DefId) -> Option<Symbol>,
[] fn contains_extern_indicator: ContainsExternIndicator(DefId) -> bool,
[] fn symbol_export_level: GetSymbolExportLevel(DefId) -> SymbolExportLevel,
[] fn is_translated_function: IsTranslatedFunction(DefId) -> bool,
[] fn codegen_unit: CodegenUnit(InternedString) -> Arc<CodegenUnit<'tcx>>,
[] fn compile_codegen_unit: CompileCodegenUnit(InternedString) -> Stats,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/ty/maps/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,8 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,

DepKind::TargetFeaturesWhitelist => { force!(target_features_whitelist, LOCAL_CRATE); }
DepKind::TargetFeaturesEnabled => { force!(target_features_enabled, def_id!()); }

DepKind::GetSymbolExportLevel => { force!(symbol_export_level, def_id!()); }
}

true
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ pub struct TargetOptions {

/// The codegen backend to use for this target, typically "llvm"
pub codegen_backend: String,

/// The default visibility for symbols in this target should be "hidden"
/// rather than "default"
pub default_hidden_visibility: bool,
}

impl Default for TargetOptions {
Expand Down Expand Up @@ -538,6 +542,7 @@ impl Default for TargetOptions {
no_builtins: false,
i128_lowering: false,
codegen_backend: "llvm".to_string(),
default_hidden_visibility: false,
}
}
}
Expand Down Expand Up @@ -785,6 +790,7 @@ impl Target {
key!(singlethread, bool);
key!(no_builtins, bool);
key!(codegen_backend);
key!(default_hidden_visibility, bool);

if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
for name in array.iter().filter_map(|abi| abi.as_string()) {
Expand Down Expand Up @@ -982,6 +988,7 @@ impl ToJson for Target {
target_option_val!(singlethread);
target_option_val!(no_builtins);
target_option_val!(codegen_backend);
target_option_val!(default_hidden_visibility);

if default.abi_blacklist != self.options.abi_blacklist {
d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_back/target/msp430_none_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ pub fn target() -> TargetResult {
// don't want to invoke that many gcc instances.
default_codegen_units: Some(1),

// Since MSP430 doesn't meaningfully support faulting on illegal
// instructions, LLVM generates a call to abort() function instead
// of a trap instruction. Such calls are 4 bytes long, and that is
// too much overhead for such small target.
trap_unreachable: false,

.. Default::default( )
}
})
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_back/target/wasm32_unknown_unknown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ pub fn target() -> Result<Target, String> {
// performing LTO with compiler-builtins.
no_builtins: true,

// no dynamic linking, no need for default visibility!
default_hidden_visibility: true,

.. Default::default()
};
Ok(Target {
Expand Down
11 changes: 9 additions & 2 deletions src/librustc_const_eval/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,27 @@ impl<'a, 'tcx> Visitor<'tcx> for MatchVisitor<'a, 'tcx> {
}
}


impl<'a, 'tcx> PatternContext<'a, 'tcx> {
fn report_inlining_errors(&self, pat_span: Span) {
for error in &self.errors {
match *error {
PatternError::StaticInPattern(span) => {
span_err!(self.tcx.sess, span, E0158,
"statics cannot be referenced in patterns");
self.span_e0158(span, "statics cannot be referenced in patterns")
}
PatternError::AssociatedConstInPattern(span) => {
self.span_e0158(span, "associated consts cannot be referenced in patterns")
}
PatternError::ConstEval(ref err) => {
err.report(self.tcx, pat_span, "pattern");
}
}
}
}

fn span_e0158(&self, span: Span, text: &str) {
span_err!(self.tcx.sess, span, E0158, "{}", text)
}
}

impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
Expand Down
11 changes: 10 additions & 1 deletion src/librustc_const_eval/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use syntax_pos::Span;

#[derive(Clone, Debug)]
pub enum PatternError<'tcx> {
AssociatedConstInPattern(Span),
StaticInPattern(Span),
ConstEval(ConstEvalErr<'tcx>),
}
Expand Down Expand Up @@ -635,6 +636,10 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
-> Pattern<'tcx> {
let ty = self.tables.node_id_to_type(id);
let def = self.tables.qpath_def(qpath, id);
let is_associated_const = match def {
Def::AssociatedConst(_) => true,
_ => false,
};
let kind = match def {
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
let substs = self.tables.node_substs(id);
Expand All @@ -656,7 +661,11 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
return pat;
}
None => {
self.errors.push(PatternError::StaticInPattern(span));
self.errors.push(if is_associated_const {
PatternError::AssociatedConstInPattern(span)
} else {
PatternError::StaticInPattern(span)
});
PatternKind::Wild
}
}
Expand Down

0 comments on commit 8ccab7e

Please sign in to comment.