Skip to content

Commit 2c11555

Browse files
committed
Auto merge of #46272 - kennytm:rollup, r=kennytm
Rollup of 7 pull requests - Successful merges: #46201, #46224, #46234, #46252, #46259, #46264, #46269 - Failed merges:
2 parents d4dc289 + 0d664f9 commit 2c11555

File tree

8 files changed

+81
-12
lines changed

8 files changed

+81
-12
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.
129129
python x.py build
130130
```
131131

132+
If you are seeing build failure when compiling `rustc_binaryen`, make sure the path
133+
length of the rust folder is not longer than 22 characters.
134+
132135
#### Specifying an ABI
133136
[specifying-an-abi]: #specifying-an-abi
134137

src/liballoc/fmt.rs

+10
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@
236236
//! writeln! // same as write but appends a newline
237237
//! print! // the format string is printed to the standard output
238238
//! println! // same as print but appends a newline
239+
//! eprint! // the format string is printed to the standard error
240+
//! eprintln! // same as eprint but appends a newline
239241
//! format_args! // described below.
240242
//! ```
241243
//!
@@ -264,6 +266,11 @@
264266
//! print!("Hello {}!", "world");
265267
//! println!("I have a newline {}", "character at the end");
266268
//! ```
269+
//! ### `eprint!`
270+
//!
271+
//! The [`eprint!`] and [`eprintln!`] macros are identical to
272+
//! [`print!`] and [`println!`], respectively, except they emit their
273+
//! output to stderr.
267274
//!
268275
//! ### `format_args!`
269276
//!
@@ -490,7 +497,10 @@
490497
//! [`writeln!`]: ../../std/macro.writeln.html
491498
//! [`write_fmt`]: ../../std/io/trait.Write.html#method.write_fmt
492499
//! [`std::io::Write`]: ../../std/io/trait.Write.html
500+
//! [`print!`]: ../../std/macro.print.html
493501
//! [`println!`]: ../../std/macro.println.html
502+
//! [`eprint!`]: ../../std/macro.eprint.html
503+
//! [`eprintln!`]: ../../std/macro.eprintln.html
494504
//! [`write!`]: ../../std/macro.write.html
495505
//! [`format_args!`]: ../../std/macro.format_args.html
496506
//! [`fmt::Arguments`]: struct.Arguments.html

src/liballoc/linked_list.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,8 @@ mod tests {
12881288
let mut node_ptr: &Node<T>;
12891289
match list.head {
12901290
None => {
1291+
// tail node should also be None.
1292+
assert!(list.tail.is_none());
12911293
assert_eq!(0, list.len);
12921294
return;
12931295
}
@@ -1314,6 +1316,11 @@ mod tests {
13141316
}
13151317
}
13161318
}
1319+
1320+
// verify that the tail node points to the last node.
1321+
let tail = list.tail.as_ref().expect("some tail node").as_ref();
1322+
assert_eq!(tail as *const Node<T>, node_ptr as *const Node<T>);
1323+
// check that len matches interior links.
13171324
assert_eq!(len, list.len);
13181325
}
13191326
}

src/libcore/marker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ pub trait Copy : Clone {
314314
///
315315
/// For cases when one does need thread-safe interior mutability,
316316
/// Rust provides [atomic data types], as well as explicit locking via
317-
/// [`sync::Mutex`][mutex] and [`sync::RWLock`][rwlock]. These types
317+
/// [`sync::Mutex`][mutex] and [`sync::RwLock`][rwlock]. These types
318318
/// ensure that any mutation cannot cause data races, hence the types
319319
/// are `Sync`. Likewise, [`sync::Arc`][arc] provides a thread-safe
320320
/// analogue of [`Rc`][rc].

src/librustc/middle/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ macro_rules! language_item_table {
4040

4141

4242
enum_from_u32! {
43-
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
43+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
4444
pub enum LangItem {
4545
$($variant,)*
4646
}

src/librustc_mir/transform/instcombine.rs

+25-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
//! Performs various peephole optimizations.
1212
13-
use rustc::mir::{Location, Lvalue, Mir, Operand, ProjectionElem, Rvalue, Local};
13+
use rustc::mir::{Constant, Literal, Location, Lvalue, Mir, Operand, ProjectionElem, Rvalue, Local};
1414
use rustc::mir::visit::{MutVisitor, Visitor};
15-
use rustc::ty::TyCtxt;
16-
use rustc::util::nodemap::FxHashSet;
15+
use rustc::ty::{TyCtxt, TypeVariants};
16+
use rustc::util::nodemap::{FxHashMap, FxHashSet};
1717
use rustc_data_structures::indexed_vec::Idx;
1818
use std::mem;
1919
use transform::{MirPass, MirSource};
@@ -44,11 +44,11 @@ impl MirPass for InstCombine {
4444
}
4545
}
4646

47-
pub struct InstCombineVisitor {
48-
optimizations: OptimizationList,
47+
pub struct InstCombineVisitor<'tcx> {
48+
optimizations: OptimizationList<'tcx>,
4949
}
5050

51-
impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor {
51+
impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> {
5252
fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>, location: Location) {
5353
if self.optimizations.and_stars.remove(&location) {
5454
debug!("Replacing `&*`: {:?}", rvalue);
@@ -62,6 +62,11 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor {
6262
*rvalue = Rvalue::Use(Operand::Consume(new_lvalue))
6363
}
6464

65+
if let Some(constant) = self.optimizations.arrays_lengths.remove(&location) {
66+
debug!("Replacing `Len([_; N])`: {:?}", rvalue);
67+
*rvalue = Rvalue::Use(Operand::Constant(box constant));
68+
}
69+
6570
self.super_rvalue(rvalue, location)
6671
}
6772
}
@@ -70,7 +75,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor {
7075
struct OptimizationFinder<'b, 'a, 'tcx:'a+'b> {
7176
mir: &'b Mir<'tcx>,
7277
tcx: TyCtxt<'a, 'tcx, 'tcx>,
73-
optimizations: OptimizationList,
78+
optimizations: OptimizationList<'tcx>,
7479
}
7580

7681
impl<'b, 'a, 'tcx:'b> OptimizationFinder<'b, 'a, 'tcx> {
@@ -93,11 +98,23 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for OptimizationFinder<'b, 'a, 'tcx> {
9398
}
9499
}
95100

101+
if let Rvalue::Len(ref lvalue) = *rvalue {
102+
let lvalue_ty = lvalue.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx);
103+
if let TypeVariants::TyArray(_, len) = lvalue_ty.sty {
104+
let span = self.mir.source_info(location).span;
105+
let ty = self.tcx.types.usize;
106+
let literal = Literal::Value { value: len };
107+
let constant = Constant { span, ty, literal };
108+
self.optimizations.arrays_lengths.insert(location, constant);
109+
}
110+
}
111+
96112
self.super_rvalue(rvalue, location)
97113
}
98114
}
99115

100116
#[derive(Default)]
101-
struct OptimizationList {
117+
struct OptimizationList<'tcx> {
102118
and_stars: FxHashSet<Location>,
119+
arrays_lengths: FxHashMap<Location, Constant<'tcx>>,
103120
}

src/libstd/io/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
441441
/// # }
442442
/// ```
443443
///
444-
/// Read from `&str` because [`&[u8]`] implements [`Read`]:
444+
/// Read from `&str` because [`&[u8]`] implements `Read`:
445445
///
446446
/// ```
447447
/// # use std::io;
@@ -465,7 +465,6 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
465465
/// [`BufRead`]: trait.BufRead.html
466466
/// [`BufReader`]: struct.BufReader.html
467467
/// [`&[u8]`]: primitive.slice.html
468-
///
469468
#[stable(feature = "rust1", since = "1.0.0")]
470469
#[doc(spotlight)]
471470
pub trait Read {

src/test/mir-opt/combine_array_len.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn norm2(x: [f32; 2]) -> f32 {
12+
let a = x[0];
13+
let b = x[1];
14+
a*a + b*b
15+
}
16+
17+
fn main() {
18+
assert_eq!(norm2([3.0, 4.0]), 5.0*5.0);
19+
}
20+
21+
// END RUST SOURCE
22+
23+
// START rustc.norm2.InstCombine.before.mir
24+
// _5 = Len(_1);
25+
// ...
26+
// _10 = Len(_1);
27+
// END rustc.norm2.InstCombine.before.mir
28+
29+
// START rustc.norm2.InstCombine.after.mir
30+
// _5 = const 2usize;
31+
// ...
32+
// _10 = const 2usize;
33+
// END rustc.norm2.InstCombine.after.mir

0 commit comments

Comments
 (0)