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 16 pull requests #47900

Merged
merged 40 commits into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
37771d4
Specialize StepBy::nth
oberien Jan 18, 2018
5850f0b
Fix off-by-ones
oberien Jan 19, 2018
d33cc12
Unit Tests
oberien Jan 19, 2018
f08dec1
Handle Overflow
oberien Jan 19, 2018
f72b7f7
Optimize StepBy::nth overflow handling
oberien Jan 19, 2018
4a0da4c
Spacing
oberien Jan 19, 2018
c6377f8
Avoid underflow in render_source_line
etaoins Jan 23, 2018
0984ee3
Adding ICH to the glossary.
avborhanian Jan 27, 2018
043d461
use correct casing for rename suggestions
euclio Jan 29, 2018
81e4959
Added inline to fmt for debug implementations of primitives.
Jan 29, 2018
c06c707
Fix regression: account for trait methods in arg count mismatch error
CAD97 Jan 29, 2018
e9d7041
std: use more portable error number in from_raw_os_error docs
jcowgill Jan 23, 2018
d8e4142
rustc_trans: clobber $1 (aka $at) on mips
jcowgill Jan 24, 2018
deba389
Changed back inline markings.
Jan 30, 2018
f6a6d84
Update associated constants error message
GuillaumeGomez Jan 30, 2018
eaebfd4
Ignore run-pass/sse2 when using system LLVM
cuviper Jan 30, 2018
d492fe0
rustc: Add some defines for LLVM 7 compat
alexcrichton Jan 30, 2018
a2cc5d6
rustc: Add an option to default hidden visibility
alexcrichton Jan 30, 2018
1e380cb
[MSP430] Don't enable trap_unreachable option by default on msp.
pftbest Jan 30, 2018
973756d
rustc_trans: keep LLVM types for trait objects anonymous.
eddyb Jan 30, 2018
c739254
Fix ICE when reading non-UTF-8 input from stdin
varkor Jan 31, 2018
89ea6d2
Rollup merge of #47838 - euclio:snakecase-suggestion, r=petrochenkov
kennytm Jan 31, 2018
0370717
Rollup merge of #47840 - penpalperson:master, r=bluss
kennytm Jan 31, 2018
c66c6b7
Rollup merge of #47844 - CAD97:patch-1, r=estebank
kennytm Jan 31, 2018
33d175f
Rollup merge of #47874 - jcowgill:mips-from_raw_os_error, r=dtolnay
kennytm Jan 31, 2018
6c0d5f5
Rollup merge of #47875 - jcowgill:mips-clobber-at, r=rkruppe
kennytm Jan 31, 2018
38587a7
Rollup merge of #47876 - GuillaumeGomez:associated-const-error, r=nik…
kennytm Jan 31, 2018
ffb6b46
Rollup merge of #47884 - cuviper:run-pass-sse2, r=alexcrichton
kennytm Jan 31, 2018
2c3e6ac
Rollup merge of #47886 - alexcrichton:llvm-7-start, r=eddyb
kennytm Jan 31, 2018
fde67b6
Rollup merge of #47889 - alexcrichton:wasm-hidden-by-default, r=cramertj
kennytm Jan 31, 2018
3d8279d
Rollup merge of #47890 - pftbest:no_trap, r=alexcrichton
kennytm Jan 31, 2018
bacb5b7
Rollup merge of #47891 - eddyb:issue-47638, r=nikomatsakis
kennytm Jan 31, 2018
00a33d6
Add echo escape flag
varkor Jan 31, 2018
a43d7eb
Use file containing non-UTF-8 character instead of echo -e
varkor Jan 31, 2018
64fc9d2
Rollup merge of #47795 - avborhanian:master, r=rkruppe
kennytm Jan 31, 2018
8ebe542
rustc: Move location of `codegen-backends` dir
alexcrichton Jan 30, 2018
68135d1
Rollup merge of #47677 - etaoins:avoid-underflow-in-rennder-source-li…
kennytm Jan 31, 2018
61972e7
Rollup merge of #47893 - alexcrichton:move-codegen-backends, r=alexcr…
kennytm Jan 31, 2018
86eb725
Rollup merge of #47895 - varkor:non-utf-stdin, r=estebank
kennytm Jan 31, 2018
af95302
Rollup merge of #47552 - oberien:stepby-nth, r=dtolnay
kennytm Jan 31, 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
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
Loading