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 7 pull requests #70826

Merged
merged 22 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift click to select a range
415aff0
move OS constants to platform crate
stlankes Mar 30, 2020
4120834
minor changes to pass the format check
stlankes Mar 30, 2020
6c80bdb
reorder imports to pass the format check
stlankes Mar 30, 2020
9f6b96e
move the definition of thread priorities to hermit-abi
stlankes Mar 30, 2020
f8d6fc1
Open-code Fuse's Option matches
cuviper Apr 3, 2020
6fdd4f3
Use a macro to expand the specialized Fuse
cuviper Apr 3, 2020
aa22330
Merge branch 'master' into abi
stlankes Apr 4, 2020
e2780b3
Merge branch 'master' into abi
stlankes Apr 4, 2020
13bd25e
Do not lose or reorder user-provided linker arguments
petrochenkov Apr 1, 2020
d06b26f
Stop importing the float modules. Use assoc consts
faern Apr 5, 2020
daf8afd
Remove more std::f32 imports in libstd
faern Apr 5, 2020
28c9231
Make libcore float constant examples similar to libstd
faern Apr 5, 2020
935683b
Simplify dtor registration for HermitCore by using a list of destructors
stlankes Apr 5, 2020
0cd4c89
"cannot resolve" → "cannot satisfy"
estebank Apr 5, 2020
004ce25
Remove labels in libstd/lib.rs macro imports
yoshuawuyts Apr 5, 2020
be93b1c
Rollup merge of #70553 - hermitcore:abi, r=dtolnay
Centril Apr 5, 2020
aafbe07
Rollup merge of #70665 - petrochenkov:linkargs, r=nagisa
Centril Apr 5, 2020
618ba73
Rollup merge of #70750 - cuviper:direct-fuse, r=scottmcm
Centril Apr 5, 2020
269eeea
Rollup merge of #70782 - faern:use-assoc-float-consts, r=dtolnay
Centril Apr 5, 2020
e1b380a
Rollup merge of #70798 - estebank:satisfy, r=Centril
Centril Apr 5, 2020
534f8da
Rollup merge of #70808 - hermitcore:tls, r=dtolnay
Centril Apr 5, 2020
23acf87
Rollup merge of #70824 - yoshuawuyts:fix-labels-in-std-macro-imports,…
Centril Apr 5, 2020
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
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1377,9 1377,9 @@ dependencies = [

[[package]]
name = "hermit-abi"
version = "0.1.8"
version = "0.1.10"
source = "registry https://github.com/rust-lang/crates.io-index"
checksum = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8"
checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e"
dependencies = [
"compiler_builtins",
"libc",
Expand Down
137 changes: 63 additions & 74 deletions src/libcore/iter/adapters/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 28,22 @@ impl<I> Fuse<I> {
#[stable(feature = "fused", since = "1.26.0")]
impl<I> FusedIterator for Fuse<I> where I: Iterator {}

/// Fuse the iterator if the expression is `None`.
macro_rules! fuse {
($self:ident . iter . $($call:tt) ) => {
match $self.iter {
Some(ref mut iter) => match iter.$($call) {
None => {
$self.iter = None;
None
}
item => item,
},
None => None,
}
};
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<I> Iterator for Fuse<I>
where
Expand All @@ -37,35 53,36 @@ where

#[inline]
default fn next(&mut self) -> Option<<I as Iterator>::Item> {
let next = self.iter.as_mut()?.next();
if next.is_none() {
self.iter = None;
}
next
fuse!(self.iter.next())
}

#[inline]
default fn nth(&mut self, n: usize) -> Option<I::Item> {
let nth = self.iter.as_mut()?.nth(n);
if nth.is_none() {
self.iter = None;
}
nth
fuse!(self.iter.nth(n))
}

#[inline]
default fn last(self) -> Option<I::Item> {
self.iter?.last()
match self.iter {
Some(iter) => iter.last(),
None => None,
}
}

#[inline]
default fn count(self) -> usize {
self.iter.map_or(0, I::count)
match self.iter {
Some(iter) => iter.count(),
None => 0,
}
}

#[inline]
default fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.as_ref().map_or((0, Some(0)), I::size_hint)
match self.iter {
Some(ref iter) => iter.size_hint(),
None => (0, Some(0)),
}
}

#[inline]
Expand Down Expand Up @@ -98,11 115,7 @@ where
where
P: FnMut(&Self::Item) -> bool,
{
let found = self.iter.as_mut()?.find(predicate);
if found.is_none() {
self.iter = None;
}
found
fuse!(self.iter.find(predicate))
}
}

Expand All @@ -113,20 126,12 @@ where
{
#[inline]
default fn next_back(&mut self) -> Option<<I as Iterator>::Item> {
let next = self.iter.as_mut()?.next_back();
if next.is_none() {
self.iter = None;
}
next
fuse!(self.iter.next_back())
}

#[inline]
default fn nth_back(&mut self, n: usize) -> Option<<I as Iterator>::Item> {
let nth = self.iter.as_mut()?.nth_back(n);
if nth.is_none() {
self.iter = None;
}
nth
fuse!(self.iter.nth_back(n))
}

#[inline]
Expand Down Expand Up @@ -159,11 164,7 @@ where
where
P: FnMut(&Self::Item) -> bool,
{
let found = self.iter.as_mut()?.rfind(predicate);
if found.is_none() {
self.iter = None;
}
found
fuse!(self.iter.rfind(predicate))
}
}

Expand All @@ -173,42 174,30 @@ where
I: ExactSizeIterator,
{
default fn len(&self) -> usize {
self.iter.as_ref().map_or(0, I::len)
}

default fn is_empty(&self) -> bool {
self.iter.as_ref().map_or(true, I::is_empty)
}
}

// NOTE: for `I: FusedIterator`, we assume that the iterator is always `Some`
impl<I: FusedIterator> Fuse<I> {
#[inline(always)]
fn as_inner(&self) -> &I {
match self.iter {
Some(ref iter) => iter,
// SAFETY: the specialized iterator never sets `None`
None => unsafe { intrinsics::unreachable() },
Some(ref iter) => iter.len(),
None => 0,
}
}

#[inline(always)]
fn as_inner_mut(&mut self) -> &mut I {
default fn is_empty(&self) -> bool {
match self.iter {
Some(ref mut iter) => iter,
// SAFETY: the specialized iterator never sets `None`
None => unsafe { intrinsics::unreachable() },
Some(ref iter) => iter.is_empty(),
None => true,
}
}
}

#[inline(always)]
fn into_inner(self) -> I {
match self.iter {
Some(iter) => iter,
// NOTE: for `I: FusedIterator`, we assume that the iterator is always `Some`.
// Implementing this as a directly-expanded macro helps codegen performance.
macro_rules! unchecked {
($self:ident) => {
match $self {
Fuse { iter: Some(iter) } => iter,
// SAFETY: the specialized iterator never sets `None`
None => unsafe { intrinsics::unreachable() },
Fuse { iter: None } => unsafe { intrinsics::unreachable() },
}
}
};
}

#[stable(feature = "fused", since = "1.26.0")]
Expand All @@ -218,27 207,27 @@ where
{
#[inline]
fn next(&mut self) -> Option<<I as Iterator>::Item> {
self.as_inner_mut().next()
unchecked!(self).next()
}

#[inline]
fn nth(&mut self, n: usize) -> Option<I::Item> {
self.as_inner_mut().nth(n)
unchecked!(self).nth(n)
}

#[inline]
fn last(self) -> Option<I::Item> {
self.into_inner().last()
unchecked!(self).last()
}

#[inline]
fn count(self) -> usize {
self.into_inner().count()
unchecked!(self).count()
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.as_inner().size_hint()
unchecked!(self).size_hint()
}

#[inline]
Expand All @@ -248,23 237,23 @@ where
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
{
self.as_inner_mut().try_fold(init, fold)
unchecked!(self).try_fold(init, fold)
}

#[inline]
fn fold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc
where
Fold: FnMut(Acc, Self::Item) -> Acc,
{
self.into_inner().fold(init, fold)
unchecked!(self).fold(init, fold)
}

#[inline]
fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where
P: FnMut(&Self::Item) -> bool,
{
self.as_inner_mut().find(predicate)
unchecked!(self).find(predicate)
}
}

Expand All @@ -275,12 264,12 @@ where
{
#[inline]
fn next_back(&mut self) -> Option<<I as Iterator>::Item> {
self.as_inner_mut().next_back()
unchecked!(self).next_back()
}

#[inline]
fn nth_back(&mut self, n: usize) -> Option<<I as Iterator>::Item> {
self.as_inner_mut().nth_back(n)
unchecked!(self).nth_back(n)
}

#[inline]
Expand All @@ -290,23 279,23 @@ where
Fold: FnMut(Acc, Self::Item) -> R,
R: Try<Ok = Acc>,
{
self.as_inner_mut().try_rfold(init, fold)
unchecked!(self).try_rfold(init, fold)
}

#[inline]
fn rfold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc
where
Fold: FnMut(Acc, Self::Item) -> Acc,
{
self.into_inner().rfold(init, fold)
unchecked!(self).rfold(init, fold)
}

#[inline]
fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>
where
P: FnMut(&Self::Item) -> bool,
{
self.as_inner_mut().rfind(predicate)
unchecked!(self).rfind(predicate)
}
}

Expand All @@ -316,11 305,11 @@ where
I: ExactSizeIterator FusedIterator,
{
fn len(&self) -> usize {
self.as_inner().len()
unchecked!(self).len()
}

fn is_empty(&self) -> bool {
self.as_inner().is_empty()
unchecked!(self).is_empty()
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 394,7 @@ impl f32 {
/// Converts radians to degrees.
///
/// ```
/// use std::f32::consts;
///
/// let angle = consts::PI;
/// let angle = std::f32::consts::PI;
///
/// let abs_difference = (angle.to_degrees() - 180.0).abs();
///
Expand All @@ -413,11 411,9 @@ impl f32 {
/// Converts degrees to radians.
///
/// ```
/// use std::f32::consts;
///
/// let angle = 180.0f32;
///
/// let abs_difference = (angle.to_radians() - consts::PI).abs();
/// let abs_difference = (angle.to_radians() - std::f32::consts::PI).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
Expand Down
8 changes: 2 additions & 6 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 407,7 @@ impl f64 {
/// Converts radians to degrees.
///
/// ```
/// use std::f64::consts;
///
/// let angle = consts::PI;
/// let angle = std::f64::consts::PI;
///
/// let abs_difference = (angle.to_degrees() - 180.0).abs();
///
Expand All @@ -427,11 425,9 @@ impl f64 {
/// Converts degrees to radians.
///
/// ```
/// use std::f64::consts;
///
/// let angle = 180.0_f64;
///
/// let abs_difference = (angle.to_radians() - consts::PI).abs();
/// let abs_difference = (angle.to_radians() - std::f64::consts::PI).abs();
///
/// assert!(abs_difference < 1e-10);
/// ```
Expand Down
Loading