Skip to content

Commit

Permalink
Auto merge of #67220 - Centril:rollup-n3u9wd5, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - #66881 (Optimize Ord trait implementation for bool)
 - #67015 (Fix constant propagation for scalar pairs)
 - #67074 (Add options to --extern flag.)
 - #67164 (Ensure that panicking in constants eventually errors)
 - #67174 (Remove `checked_add` in `Layout::repeat`)
 - #67205 (Make `publish_toolstate.sh` executable)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Dec 11, 2019
2 parents ddca1e0 + f6ceef5 commit 033662d
Show file tree
Hide file tree
Showing 40 changed files with 684 additions and 211 deletions.
Empty file modified src/ci/publish_toolstate.sh
100644 → 100755
Empty file.
7 changes: 5 additions & 2 deletions src/libcore/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,11 @@ impl Layout {
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
#[inline]
pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutErr> {
let padded_size = self.size().checked_add(self.padding_needed_for(self.align()))
.ok_or(LayoutErr { private: () })?;
// This cannot overflow. Quoting from the invariant of Layout:
// > `size`, when rounded up to the nearest multiple of `align`,
// > must not overflow (i.e., the rounded value must be less than
// > `usize::MAX`)
let padded_size = self.size() + self.padding_needed_for(self.align());
let alloc_size = padded_size.checked_mul(n)
.ok_or(LayoutErr { private: () })?;

Expand Down
12 changes: 11 additions & 1 deletion src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ pub fn max_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {

// Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types
mod impls {
use crate::hint::unreachable_unchecked;
use crate::cmp::Ordering::{self, Less, Greater, Equal};

macro_rules! partial_eq_impl {
Expand Down Expand Up @@ -1125,7 +1126,16 @@ mod impls {
impl Ord for bool {
#[inline]
fn cmp(&self, other: &bool) -> Ordering {
(*self as u8).cmp(&(*other as u8))
// Casting to i8's and converting the difference to an Ordering generates
// more optimal assembly.
// See <https:/rust-lang/rust/issues/66780> for more info.
match (*self as i8) - (*other as i8) {
-1 => Less,
0 => Equal,
1 => Greater,
// SAFETY: bool as i8 returns 0 or 1, so the difference can't be anything else
_ => unsafe { unreachable_unchecked() },
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/libcore/tests/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ fn test_int_totalord() {
assert_eq!(12.cmp(&-5), Greater);
}

#[test]
fn test_bool_totalord() {
assert_eq!(true.cmp(&false), Greater);
assert_eq!(false.cmp(&true), Less);
assert_eq!(true.cmp(&true), Equal);
assert_eq!(false.cmp(&false), Equal);
}

#[test]
fn test_mut_int_totalord() {
assert_eq!((&mut 5).cmp(&&mut 10), Less);
Expand Down
23 changes: 12 additions & 11 deletions src/librustc_interface/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc::middle::cstore;
use rustc::session::config::{build_configuration, build_session_options, to_crate_config};
use rustc::session::config::{LtoCli, LinkerPluginLto, SwitchWithOptPath, ExternEntry};
use rustc::session::config::{Externs, OutputType, OutputTypes, SymbolManglingVersion};
use rustc::session::config::{rustc_optgroups, Options, ErrorOutputType, Passes};
use rustc::session::config::{rustc_optgroups, Options, ErrorOutputType, Passes, ExternLocation};
use rustc::session::{build_session, Session};
use rustc::session::search_paths::SearchPath;
use std::collections::{BTreeMap, BTreeSet};
Expand Down Expand Up @@ -38,14 +38,15 @@ fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
fn new_public_extern_entry<S, I>(locations: I) -> ExternEntry
where
S: Into<String>,
I: IntoIterator<Item = Option<S>>,
I: IntoIterator<Item = S>,
{
let locations: BTreeSet<_> = locations.into_iter().map(|o| o.map(|s| s.into()))
let locations: BTreeSet<_> = locations.into_iter().map(|s| s.into())
.collect();

ExternEntry {
locations,
is_private_dep: false
location: ExternLocation::ExactPaths(locations),
is_private_dep: false,
add_prelude: true,
}
}

Expand Down Expand Up @@ -160,33 +161,33 @@ fn test_externs_tracking_hash_different_construction_order() {
v1.externs = Externs::new(mk_map(vec![
(
String::from("a"),
new_public_extern_entry(vec![Some("b"), Some("c")])
new_public_extern_entry(vec!["b", "c"])
),
(
String::from("d"),
new_public_extern_entry(vec![Some("e"), Some("f")])
new_public_extern_entry(vec!["e", "f"])
),
]));

v2.externs = Externs::new(mk_map(vec![
(
String::from("d"),
new_public_extern_entry(vec![Some("e"), Some("f")])
new_public_extern_entry(vec!["e", "f"])
),
(
String::from("a"),
new_public_extern_entry(vec![Some("b"), Some("c")])
new_public_extern_entry(vec!["b", "c"])
),
]));

v3.externs = Externs::new(mk_map(vec![
(
String::from("a"),
new_public_extern_entry(vec![Some("b"), Some("c")])
new_public_extern_entry(vec!["b", "c"])
),
(
String::from("d"),
new_public_extern_entry(vec![Some("f"), Some("e")])
new_public_extern_entry(vec!["f", "e"])
),
]));

Expand Down
15 changes: 8 additions & 7 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,14 @@ impl<'a> CrateLoader<'a> {
let source = self.cstore.get_crate_data(cnum).source();
if let Some(entry) = self.sess.opts.externs.get(&name.as_str()) {
// Only use `--extern crate_name=path` here, not `--extern crate_name`.
let found = entry.locations.iter().filter_map(|l| l.as_ref()).any(|l| {
let l = fs::canonicalize(l).ok();
source.dylib.as_ref().map(|p| &p.0) == l.as_ref() ||
source.rlib.as_ref().map(|p| &p.0) == l.as_ref()
});
if found {
ret = Some(cnum);
if let Some(mut files) = entry.files() {
if files.any(|l| {
let l = fs::canonicalize(l).ok();
source.dylib.as_ref().map(|p| &p.0) == l.as_ref() ||
source.rlib.as_ref().map(|p| &p.0) == l.as_ref()
}) {
ret = Some(cnum);
}
}
return
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_metadata/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ impl<'a> CrateLocator<'a> {
crate_name,
exact_paths: if hash.is_none() {
sess.opts.externs.get(&crate_name.as_str()).into_iter()
.flat_map(|entry| entry.locations.iter())
.filter_map(|location| location.clone().map(PathBuf::from)).collect()
.filter_map(|entry| entry.files())
.flatten()
.map(|location| PathBuf::from(location)).collect()
} else {
// SVH being specified means this is a transitive dependency,
// so `--extern` options do not apply.
Expand Down
9 changes: 8 additions & 1 deletion src/librustc_mir/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
_ => false,
};

unpack!(block = this.as_local_rvalue(block, source));
// (#66975) Source could be a const of type `!`, so has to
// exist in the generated MIR.
unpack!(block = this.as_temp(
block,
this.local_scope(),
source,
Mutability::Mut,
));

// This is an optimization. If the expression was a call then we already have an
// unreachable block. Don't bother to terminate it and create a new one.
Expand Down
48 changes: 37 additions & 11 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,19 +636,45 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
ScalarMaybeUndef::Scalar(one),
ScalarMaybeUndef::Scalar(two)
) => {
// Found a value represented as a pair. For now only do cont-prop if type of
// Rvalue is also a pair with two scalars. The more general case is more
// complicated to implement so we'll do it later.
let ty = &value.layout.ty.kind;
// Only do it for tuples
if let ty::Tuple(substs) = ty {
*rval = Rvalue::Aggregate(
Box::new(AggregateKind::Tuple),
vec![
self.operand_from_scalar(
one, substs[0].expect_ty(), source_info.span
),
self.operand_from_scalar(
two, substs[1].expect_ty(), source_info.span
),
],
);
// Only do it if tuple is also a pair with two scalars
if substs.len() == 2 {
let opt_ty1_ty2 = self.use_ecx(source_info, |this| {
let ty1 = substs[0].expect_ty();
let ty2 = substs[1].expect_ty();
let ty_is_scalar = |ty| {
this.ecx
.layout_of(ty)
.ok()
.map(|ty| ty.details.abi.is_scalar())
== Some(true)
};
if ty_is_scalar(ty1) && ty_is_scalar(ty2) {
Ok(Some((ty1, ty2)))
} else {
Ok(None)
}
});

if let Some(Some((ty1, ty2))) = opt_ty1_ty2 {
*rval = Rvalue::Aggregate(
Box::new(AggregateKind::Tuple),
vec![
self.operand_from_scalar(
one, ty1, source_info.span
),
self.operand_from_scalar(
two, ty2, source_info.span
),
],
);
}
}
}
},
_ => { }
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,10 @@ impl<'a> Resolver<'a> {
definitions.create_root_def(crate_name, session.local_crate_disambiguator());

let mut extern_prelude: FxHashMap<Ident, ExternPreludeEntry<'_>> =
session.opts.externs.iter().map(|kv| (Ident::from_str(kv.0), Default::default()))
.collect();
session.opts.externs.iter()
.filter(|(_, entry)| entry.add_prelude)
.map(|(name, _)| (Ident::from_str(name), Default::default()))
.collect();

if !attr::contains_name(&krate.attrs, sym::no_core) {
extern_prelude.insert(Ident::with_dummy_span(sym::core), Default::default());
Expand Down
Loading

0 comments on commit 033662d

Please sign in to comment.