Skip to content

Rollup of 7 pull requests #46266

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

Closed
wants to merge 14 commits into from
Closed
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.
python x.py build
```

If you are seeing build failure when compiling `rustc_binaryen`, make sure the path
length of the rust folder is not longer than 22 characters.

#### Specifying an ABI
[specifying-an-abi]: #specifying-an-abi

Expand Down
10 changes: 10 additions & 0 deletions src/liballoc/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@
//! writeln! // same as write but appends a newline
//! print! // the format string is printed to the standard output
//! println! // same as print but appends a newline
//! eprint! // the format string is printed to the standard error
//! eprintln! // same as eprint but appends a newline
//! format_args! // described below.
//! ```
//!
Expand Down Expand Up @@ -264,6 +266,11 @@
//! print!("Hello {}!", "world");
//! println!("I have a newline {}", "character at the end");
//! ```
//! ### `eprint!`
//!
//! The [`eprint!`] and [`eprintln!`] macros are identical to
//! [`print!`] and [`println!`], respectively, except they emit their
//! output to stderr.
//!
//! ### `format_args!`
//!
Expand Down Expand Up @@ -490,7 +497,10 @@
//! [`writeln!`]: ../../std/macro.writeln.html
//! [`write_fmt`]: ../../std/io/trait.Write.html#method.write_fmt
//! [`std::io::Write`]: ../../std/io/trait.Write.html
//! [`print!`]: ../../std/macro.print.html
//! [`println!`]: ../../std/macro.println.html
//! [`eprint!`]: ../../std/macro.eprint.html
//! [`eprintln!`]: ../../std/macro.eprintln.html
//! [`write!`]: ../../std/macro.write.html
//! [`format_args!`]: ../../std/macro.format_args.html
//! [`fmt::Arguments`]: struct.Arguments.html
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ pub trait Copy : Clone {
///
/// For cases when one does need thread-safe interior mutability,
/// Rust provides [atomic data types], as well as explicit locking via
/// [`sync::Mutex`][mutex] and [`sync::RWLock`][rwlock]. These types
/// [`sync::Mutex`][mutex] and [`sync::RwLock`][rwlock]. These types
/// ensure that any mutation cannot cause data races, hence the types
/// are `Sync`. Likewise, [`sync::Arc`][arc] provides a thread-safe
/// analogue of [`Rc`][rc].
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ macro_rules! language_item_table {


enum_from_u32! {
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub enum LangItem {
$($variant,)*
}
Expand Down
33 changes: 25 additions & 8 deletions src/librustc_mir/transform/instcombine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

//! Performs various peephole optimizations.

use rustc::mir::{Location, Lvalue, Mir, Operand, ProjectionElem, Rvalue, Local};
use rustc::mir::{Constant, Literal, Location, Lvalue, Mir, Operand, ProjectionElem, Rvalue, Local};
use rustc::mir::visit::{MutVisitor, Visitor};
use rustc::ty::TyCtxt;
use rustc::util::nodemap::FxHashSet;
use rustc::ty::{TyCtxt, TypeVariants};
use rustc::util::nodemap::{FxHashMap, FxHashSet};
use rustc_data_structures::indexed_vec::Idx;
use std::mem;
use transform::{MirPass, MirSource};
Expand Down Expand Up @@ -44,11 +44,11 @@ impl MirPass for InstCombine {
}
}

pub struct InstCombineVisitor {
optimizations: OptimizationList,
pub struct InstCombineVisitor<'tcx> {
optimizations: OptimizationList<'tcx>,
}

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

if let Some(constant) = self.optimizations.arrays_lengths.remove(&location) {
debug!("Replacing `Len([_; N])`: {:?}", rvalue);
*rvalue = Rvalue::Use(Operand::Constant(box constant));
}

self.super_rvalue(rvalue, location)
}
}
Expand All @@ -70,7 +75,7 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor {
struct OptimizationFinder<'b, 'a, 'tcx:'a+'b> {
mir: &'b Mir<'tcx>,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
optimizations: OptimizationList,
optimizations: OptimizationList<'tcx>,
}

impl<'b, 'a, 'tcx:'b> OptimizationFinder<'b, 'a, 'tcx> {
Expand All @@ -93,11 +98,23 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for OptimizationFinder<'b, 'a, 'tcx> {
}
}

if let Rvalue::Len(ref lvalue) = *rvalue {
let lvalue_ty = lvalue.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx);
if let TypeVariants::TyArray(_, len) = lvalue_ty.sty {
let span = self.mir.source_info(location).span;
let ty = self.tcx.types.usize;
let literal = Literal::Value { value: len };
let constant = Constant { span, ty, literal };
self.optimizations.arrays_lengths.insert(location, constant);
}
}

self.super_rvalue(rvalue, location)
}
}

#[derive(Default)]
struct OptimizationList {
struct OptimizationList<'tcx> {
and_stars: FxHashSet<Location>,
arrays_lengths: FxHashMap<Location, Constant<'tcx>>,
}
57 changes: 57 additions & 0 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ use memchr;
use ops;
use os::raw::c_char;
use ptr;
use rc::Rc;
use slice;
use str::{self, Utf8Error};
use sync::Arc;
use sys;

/// A type representing an owned, C-compatible, nul-terminated string with no nul bytes in the
Expand Down Expand Up @@ -704,6 +706,42 @@ impl From<CString> for Box<CStr> {
}
}

#[stable(feature = "shared_from_slice2", since = "1.23.0")]
impl From<CString> for Arc<CStr> {
#[inline]
fn from(s: CString) -> Arc<CStr> {
let arc: Arc<[u8]> = Arc::from(s.into_inner());
unsafe { Arc::from_raw(Arc::into_raw(arc) as *const CStr) }
}
}

#[stable(feature = "shared_from_slice2", since = "1.23.0")]
impl<'a> From<&'a CStr> for Arc<CStr> {
#[inline]
fn from(s: &CStr) -> Arc<CStr> {
let arc: Arc<[u8]> = Arc::from(s.to_bytes_with_nul());
unsafe { Arc::from_raw(Arc::into_raw(arc) as *const CStr) }
}
}

#[stable(feature = "shared_from_slice2", since = "1.23.0")]
impl From<CString> for Rc<CStr> {
#[inline]
fn from(s: CString) -> Rc<CStr> {
let rc: Rc<[u8]> = Rc::from(s.into_inner());
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const CStr) }
}
}

#[stable(feature = "shared_from_slice2", since = "1.23.0")]
impl<'a> From<&'a CStr> for Rc<CStr> {
#[inline]
fn from(s: &CStr) -> Rc<CStr> {
let rc: Rc<[u8]> = Rc::from(s.to_bytes_with_nul());
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const CStr) }
}
}

#[stable(feature = "default_box_extra", since = "1.17.0")]
impl Default for Box<CStr> {
fn default() -> Box<CStr> {
Expand Down Expand Up @@ -1201,6 +1239,8 @@ mod tests {
use borrow::Cow::{Borrowed, Owned};
use hash::{Hash, Hasher};
use collections::hash_map::DefaultHasher;
use rc::Rc;
use sync::Arc;

#[test]
fn c_to_rust() {
Expand Down Expand Up @@ -1337,4 +1377,21 @@ mod tests {
let boxed = <Box<CStr>>::default();
assert_eq!(boxed.to_bytes_with_nul(), &[0]);
}

#[test]
fn into_rc() {
let orig: &[u8] = b"Hello, world!\0";
let cstr = CStr::from_bytes_with_nul(orig).unwrap();
let rc: Rc<CStr> = Rc::from(cstr);
let arc: Arc<CStr> = Arc::from(cstr);

assert_eq!(&*rc, cstr);
assert_eq!(&*arc, cstr);

let rc2: Rc<CStr> = Rc::from(cstr.to_owned());
let arc2: Arc<CStr> = Arc::from(cstr.to_owned());

assert_eq!(&*rc2, cstr);
assert_eq!(&*arc2, cstr);
}
}
58 changes: 58 additions & 0 deletions src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use fmt;
use ops;
use cmp;
use hash::{Hash, Hasher};
use rc::Rc;
use sync::Arc;

use sys::os_str::{Buf, Slice};
use sys_common::{AsInner, IntoInner, FromInner};
Expand Down Expand Up @@ -592,6 +594,42 @@ impl From<OsString> for Box<OsStr> {
}
}

#[stable(feature = "shared_from_slice2", since = "1.23.0")]
impl From<OsString> for Arc<OsStr> {
#[inline]
fn from(s: OsString) -> Arc<OsStr> {
let arc = s.inner.into_arc();
unsafe { Arc::from_raw(Arc::into_raw(arc) as *const OsStr) }
}
}

#[stable(feature = "shared_from_slice2", since = "1.23.0")]
impl<'a> From<&'a OsStr> for Arc<OsStr> {
#[inline]
fn from(s: &OsStr) -> Arc<OsStr> {
let arc = s.inner.into_arc();
unsafe { Arc::from_raw(Arc::into_raw(arc) as *const OsStr) }
}
}

#[stable(feature = "shared_from_slice2", since = "1.23.0")]
impl From<OsString> for Rc<OsStr> {
#[inline]
fn from(s: OsString) -> Rc<OsStr> {
let rc = s.inner.into_rc();
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const OsStr) }
}
}

#[stable(feature = "shared_from_slice2", since = "1.23.0")]
impl<'a> From<&'a OsStr> for Rc<OsStr> {
#[inline]
fn from(s: &OsStr) -> Rc<OsStr> {
let rc = s.inner.into_rc();
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const OsStr) }
}
}

#[stable(feature = "box_default_extra", since = "1.17.0")]
impl Default for Box<OsStr> {
fn default() -> Box<OsStr> {
Expand Down Expand Up @@ -793,6 +831,9 @@ mod tests {
use super::*;
use sys_common::{AsInner, IntoInner};

use rc::Rc;
use sync::Arc;

#[test]
fn test_os_string_with_capacity() {
let os_string = OsString::with_capacity(0);
Expand Down Expand Up @@ -935,4 +976,21 @@ mod tests {
assert_eq!(os_str, os_string);
assert!(os_string.capacity() >= 123);
}

#[test]
fn into_rc() {
let orig = "Hello, world!";
let os_str = OsStr::new(orig);
let rc: Rc<OsStr> = Rc::from(os_str);
let arc: Arc<OsStr> = Arc::from(os_str);

assert_eq!(&*rc, os_str);
assert_eq!(&*arc, os_str);

let rc2: Rc<OsStr> = Rc::from(os_str.to_owned());
let arc2: Arc<OsStr> = Arc::from(os_str.to_owned());

assert_eq!(&*rc2, os_str);
assert_eq!(&*arc2, os_str);
}
}
3 changes: 1 addition & 2 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
/// # }
/// ```
///
/// Read from `&str` because [`&[u8]`] implements [`Read`]:
/// Read from `&str` because [`&[u8]`] implements `Read`:
///
/// ```
/// # use std::io;
Expand All @@ -465,7 +465,6 @@ fn read_to_end<R: Read + ?Sized>(r: &mut R, buf: &mut Vec<u8>) -> Result<usize>
/// [`BufRead`]: trait.BufRead.html
/// [`BufReader`]: struct.BufReader.html
/// [`&[u8]`]: primitive.slice.html
///
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(spotlight)]
pub trait Read {
Expand Down
Loading