Skip to content

Commit

Permalink
Auto merge of rust-lang#103225 - matthiaskrgr:rollup-1zkv87y, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#103166 (Optimize `slice_iter.copied().next_chunk()`)
 - rust-lang#103176 (Fix `TyKind::is_simple_path`)
 - rust-lang#103178 (Partially fix `src/test/run-make/coverage-reports` when cross-compiling)
 - rust-lang#103198 (Update cargo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 19, 2022
2 parents 415d8fc + 7f6b581 commit 84365ff
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 8 deletions.
7 changes: 5 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,8 +2060,11 @@ impl TyKind {
}

pub fn is_simple_path(&self) -> Option<Symbol> {
if let TyKind::Path(None, Path { segments, .. }) = &self && segments.len() == 1 {
Some(segments[0].ident.name)
if let TyKind::Path(None, Path { segments, .. }) = &self
&& let [segment] = &segments[..]
&& segment.args.is_none()
{
Some(segment.ident.name)
} else {
None
}
Expand Down
20 changes: 20 additions & 0 deletions library/core/benches/iter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use core::iter::*;
use core::mem;
use core::num::Wrapping;
use test::{black_box, Bencher};

#[bench]
Expand Down Expand Up @@ -398,3 +400,21 @@ fn bench_trusted_random_access_adapters(b: &mut Bencher) {
acc
})
}

/// Exercises the iter::Copied specialization for slice::Iter
#[bench]
fn bench_copied_array_chunks(b: &mut Bencher) {
let v = vec![1u8; 1024];

b.iter(|| {
black_box(&v)
.iter()
.copied()
.array_chunks::<{ mem::size_of::<u64>() }>()
.map(|ary| {
let d = u64::from_ne_bytes(ary);
Wrapping(d.rotate_left(7).wrapping_add(1))
})
.sum::<Wrapping<u64>>()
})
}
1 change: 1 addition & 0 deletions library/core/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![feature(int_log)]
#![feature(test)]
#![feature(trusted_random_access)]
#![feature(iter_array_chunks)]

extern crate test;

Expand Down
74 changes: 74 additions & 0 deletions library/core/src/iter/adapters/copied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use crate::iter::adapters::{
zip::try_get_unchecked, TrustedRandomAccess, TrustedRandomAccessNoCoerce,
};
use crate::iter::{FusedIterator, TrustedLen};
use crate::mem::MaybeUninit;
use crate::mem::SizedTypeProperties;
use crate::ops::Try;
use crate::{array, ptr};

/// An iterator that copies the elements of an underlying iterator.
///
Expand Down Expand Up @@ -44,6 +47,15 @@ where
self.it.next().copied()
}

fn next_chunk<const N: usize>(
&mut self,
) -> Result<[Self::Item; N], array::IntoIter<Self::Item, N>>
where
Self: Sized,
{
<I as SpecNextChunk<'_, N, T>>::spec_next_chunk(&mut self.it)
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.it.size_hint()
}
Expand Down Expand Up @@ -166,3 +178,65 @@ where
T: Copy,
{
}

trait SpecNextChunk<'a, const N: usize, T: 'a>: Iterator<Item = &'a T>
where
T: Copy,
{
fn spec_next_chunk(&mut self) -> Result<[T; N], array::IntoIter<T, N>>;
}

impl<'a, const N: usize, I, T: 'a> SpecNextChunk<'a, N, T> for I
where
I: Iterator<Item = &'a T>,
T: Copy,
{
default fn spec_next_chunk(&mut self) -> Result<[T; N], array::IntoIter<T, N>> {
array::iter_next_chunk(&mut self.map(|e| *e))
}
}

impl<'a, const N: usize, T: 'a> SpecNextChunk<'a, N, T> for crate::slice::Iter<'a, T>
where
T: Copy,
{
fn spec_next_chunk(&mut self) -> Result<[T; N], array::IntoIter<T, N>> {
let mut raw_array = MaybeUninit::uninit_array();

let len = self.len();

if T::IS_ZST {
if len < N {
let _ = self.advance_by(len);
// SAFETY: ZSTs can be conjured ex nihilo; only the amount has to be correct
return Err(unsafe { array::IntoIter::new_unchecked(raw_array, 0..len) });
}

let _ = self.advance_by(N);
// SAFETY: ditto
return Ok(unsafe { MaybeUninit::array_assume_init(raw_array) });
}

if len < N {
// SAFETY: `len` indicates that this many elements are available and we just checked that
// it fits into the array.
unsafe {
ptr::copy_nonoverlapping(
self.as_ref().as_ptr(),
raw_array.as_mut_ptr() as *mut T,
len,
);
let _ = self.advance_by(len);
return Err(array::IntoIter::new_unchecked(raw_array, 0..len));
}
}

// SAFETY: `len` is larger than the array size. Copy a fixed amount here to fully initialize
// the array.
unsafe {
ptr::copy_nonoverlapping(self.as_ref().as_ptr(), raw_array.as_mut_ptr() as *mut T, N);
let _ = self.advance_by(N);
Ok(MaybeUninit::array_assume_init(raw_array))
}
}
}
9 changes: 7 additions & 2 deletions src/test/run-make/coverage-reports/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# needs-profiler-support
# ignore-windows-gnu

# FIXME(pietroalbini): this test currently does not work on cross-compiled
# targets because remote-test is not capable of sending back the *.profraw
# files generated by the LLVM instrumentation.
# ignore-cross-compile

# Rust coverage maps support LLVM Coverage Mapping Format versions 5 and 6,
# corresponding with LLVM versions 12 and 13, respectively.
# When upgrading LLVM versions, consider whether to enforce a minimum LLVM
Expand Down Expand Up @@ -81,13 +86,13 @@ include clear_expected_if_blessed
# Compile the test library with coverage instrumentation
$(RUSTC) $(SOURCEDIR)/lib/$@.rs \
$$( sed -n 's/^\/\/ compile-flags: \([^#]*\).*/\1/p' $(SOURCEDIR)/lib/$@.rs ) \
--crate-type rlib -Cinstrument-coverage
--crate-type rlib -Cinstrument-coverage --target $(TARGET)

%: $(SOURCEDIR)/%.rs
# Compile the test program with coverage instrumentation
$(RUSTC) $(SOURCEDIR)/$@.rs \
$$( sed -n 's/^\/\/ compile-flags: \([^#]*\).*/\1/p' $(SOURCEDIR)/$@.rs ) \
-L "$(TMPDIR)" -Cinstrument-coverage
-L "$(TMPDIR)" -Cinstrument-coverage --target $(TARGET)

# Run it in order to generate some profiling data,
# with `LLVM_PROFILE_FILE=<profdata_file>` environment variable set to
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/deriving/deriving-all-codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ enum Mixed {
P,
Q,
R(u32),
S { d1: u32, d2: u32 },
S { d1: Option<u32>, d2: Option<i32> },
}

// An enum with no fieldless variants. Note that `Default` cannot be derived
Expand Down
8 changes: 6 additions & 2 deletions src/test/ui/deriving/deriving-all-codegen.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -809,15 +809,17 @@ enum Mixed {
Q,
R(u32),
S {
d1: u32,
d2: u32,
d1: Option<u32>,
d2: Option<i32>,
},
}
#[automatically_derived]
impl ::core::clone::Clone for Mixed {
#[inline]
fn clone(&self) -> Mixed {
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<Option<u32>>;
let _: ::core::clone::AssertParamIsClone<Option<i32>>;
*self
}
}
Expand Down Expand Up @@ -886,6 +888,8 @@ impl ::core::cmp::Eq for Mixed {
#[no_coverage]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<u32>;
let _: ::core::cmp::AssertParamIsEq<Option<u32>>;
let _: ::core::cmp::AssertParamIsEq<Option<i32>>;
}
}
#[automatically_derived]
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/deriving/issue-103157.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// check-fail

#[derive(PartialEq, Eq)]
pub enum Value {
Boolean(Option<bool>),
Float(Option<f64>), //~ ERROR the trait bound `f64: Eq` is not satisfied
}

fn main() {
let a = Value::Float(Some(f64::NAN));
assert!(a == a);
}
30 changes: 30 additions & 0 deletions src/test/ui/deriving/issue-103157.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
error[E0277]: the trait bound `f64: Eq` is not satisfied
--> $DIR/issue-103157.rs:6:11
|
LL | #[derive(PartialEq, Eq)]
| -- in this derive macro expansion
...
LL | Float(Option<f64>),
| ^^^^^^^^^^^ the trait `Eq` is not implemented for `f64`
|
= help: the following other types implement trait `Eq`:
i128
i16
i32
i64
i8
isize
u128
u16
and 4 others
= note: required for `Option<f64>` to implement `Eq`
note: required by a bound in `AssertParamIsEq`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
|
LL | pub struct AssertParamIsEq<T: Eq + ?Sized> {
| ^^ required by this bound in `AssertParamIsEq`
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

0 comments on commit 84365ff

Please sign in to comment.