Skip to content

Commit

Permalink
Auto merge of rust-lang#91064 - matthiaskrgr:rollup-2ijidpt, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#88361 (Makes docs for references a little less confusing)
 - rust-lang#90089 (Improve display of enum variants)
 - rust-lang#90956 (Add a regression test for rust-lang#87573)
 - rust-lang#90999 (fix CTFE/Miri simd_insert/extract on array-style repr(simd) types)
 - rust-lang#91026 (rustdoc doctest: detect `fn main` after an unexpected semicolon)
 - rust-lang#91035 (Put back removed empty line)
 - rust-lang#91044 (Turn all 0x1b_u8 into '\x1b' or b'\x1b')
 - rust-lang#91054 (rustdoc: Fix some unescaped HTML tags in docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 20, 2021
2 parents a77da2d + 54bc333 commit 3b65165
Show file tree
Hide file tree
Showing 21 changed files with 293 additions and 129 deletions.
47 changes: 16 additions & 31 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,48 +419,33 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
sym::simd_insert => {
let index = u64::from(self.read_scalar(&args[1])?.to_u32()?);
let elem = &args[2];
let input = &args[0];
let (len, e_ty) = input.layout.ty.simd_size_and_type(*self.tcx);
let (input, input_len) = self.operand_to_simd(&args[0])?;
let (dest, dest_len) = self.place_to_simd(dest)?;
assert_eq!(input_len, dest_len, "Return vector length must match input length");
assert!(
index < len,
"Index `{}` must be in bounds of vector type `{}`: `[0, {})`",
index < dest_len,
"Index `{}` must be in bounds of vector with length {}`",
index,
e_ty,
len
);
assert_eq!(
input.layout, dest.layout,
"Return type `{}` must match vector type `{}`",
dest.layout.ty, input.layout.ty
);
assert_eq!(
elem.layout.ty, e_ty,
"Scalar element type `{}` must match vector element type `{}`",
elem.layout.ty, e_ty
dest_len
);

for i in 0..len {
let place = self.place_index(dest, i)?;
let value = if i == index { *elem } else { self.operand_index(input, i)? };
self.copy_op(&value, &place)?;
for i in 0..dest_len {
let place = self.mplace_index(&dest, i)?;
let value =
if i == index { *elem } else { self.mplace_index(&input, i)?.into() };
self.copy_op(&value, &place.into())?;
}
}
sym::simd_extract => {
let index = u64::from(self.read_scalar(&args[1])?.to_u32()?);
let (len, e_ty) = args[0].layout.ty.simd_size_and_type(*self.tcx);
let (input, input_len) = self.operand_to_simd(&args[0])?;
assert!(
index < len,
"index `{}` is out-of-bounds of vector type `{}` with length `{}`",
index < input_len,
"index `{}` must be in bounds of vector with length `{}`",
index,
e_ty,
len
);
assert_eq!(
e_ty, dest.layout.ty,
"Return type `{}` must match vector element type `{}`",
dest.layout.ty, e_ty
input_len
);
self.copy_op(&self.operand_index(&args[0], index)?, dest)?;
self.copy_op(&self.mplace_index(&input, index)?.into(), dest)?;
}
sym::likely | sym::unlikely | sym::black_box => {
// These just return their argument
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
})
}

/// Converts a repr(simd) operand into an operand where `place_index` accesses the SIMD elements.
/// Also returns the number of elements.
pub fn operand_to_simd(
&self,
base: &OpTy<'tcx, M::PointerTag>,
) -> InterpResult<'tcx, (MPlaceTy<'tcx, M::PointerTag>, u64)> {
// Basically we just transmute this place into an array following simd_size_and_type.
// This only works in memory, but repr(simd) types should never be immediates anyway.
assert!(base.layout.ty.is_simd());
self.mplace_to_simd(&base.assert_mem_place())
}

/// Read from a local. Will not actually access the local if reading from a ZST.
/// Will not access memory, instead an indirect `Operand` is returned.
///
Expand Down
28 changes: 27 additions & 1 deletion compiler/rustc_const_eval/src/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<'tcx, Tag: Provenance> MPlaceTy<'tcx, Tag> {
}
} else {
// Go through the layout. There are lots of types that support a length,
// e.g., SIMD types.
// e.g., SIMD types. (But not all repr(simd) types even have FieldsShape::Array!)
match self.layout.fields {
FieldsShape::Array { count, .. } => Ok(count),
_ => bug!("len not supported on sized type {:?}", self.layout.ty),
Expand Down Expand Up @@ -533,6 +533,22 @@ where
})
}

/// Converts a repr(simd) place into a place where `place_index` accesses the SIMD elements.
/// Also returns the number of elements.
pub fn mplace_to_simd(
&self,
base: &MPlaceTy<'tcx, M::PointerTag>,
) -> InterpResult<'tcx, (MPlaceTy<'tcx, M::PointerTag>, u64)> {
// Basically we just transmute this place into an array following simd_size_and_type.
// (Transmuting is okay since this is an in-memory place. We also double-check the size
// stays the same.)
let (len, e_ty) = base.layout.ty.simd_size_and_type(*self.tcx);
let array = self.tcx.mk_array(e_ty, len);
let layout = self.layout_of(array)?;
assert_eq!(layout.size, base.layout.size);
Ok((MPlaceTy { layout, ..*base }, len))
}

/// Gets the place of a field inside the place, and also the field's type.
/// Just a convenience function, but used quite a bit.
/// This is the only projection that might have a side-effect: We cannot project
Expand Down Expand Up @@ -594,6 +610,16 @@ where
})
}

/// Converts a repr(simd) place into a place where `place_index` accesses the SIMD elements.
/// Also returns the number of elements.
pub fn place_to_simd(
&mut self,
base: &PlaceTy<'tcx, M::PointerTag>,
) -> InterpResult<'tcx, (MPlaceTy<'tcx, M::PointerTag>, u64)> {
let mplace = self.force_allocation(base)?;
self.mplace_to_simd(&mplace)
}

/// Computes a place. You should only use this if you intend to write into this
/// place; for reading, a more efficient alternative is `eval_place_for_read`.
pub fn eval_place(
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1805,17 +1805,22 @@ impl<'tcx> TyS<'tcx> {
pub fn simd_size_and_type(&self, tcx: TyCtxt<'tcx>) -> (u64, Ty<'tcx>) {
match self.kind() {
Adt(def, substs) => {
assert!(def.repr.simd(), "`simd_size_and_type` called on non-SIMD type");
let variant = def.non_enum_variant();
let f0_ty = variant.fields[0].ty(tcx, substs);

match f0_ty.kind() {
// If the first field is an array, we assume it is the only field and its
// elements are the SIMD components.
Array(f0_elem_ty, f0_len) => {
// FIXME(repr_simd): https://github.com/rust-lang/rust/pull/78863#discussion_r522784112
// The way we evaluate the `N` in `[T; N]` here only works since we use
// `simd_size_and_type` post-monomorphization. It will probably start to ICE
// if we use it in generic code. See the `simd-array-trait` ui test.
(f0_len.eval_usize(tcx, ParamEnv::empty()) as u64, f0_elem_ty)
}
// Otherwise, the fields of this Adt are the SIMD components (and we assume they
// all have the same type).
_ => (variant.fields.len() as u64, f0_ty),
}
}
Expand Down
20 changes: 10 additions & 10 deletions library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ impl char {
/// let percent = '%';
/// let space = ' ';
/// let lf = '\n';
/// let esc: char = 0x1b_u8.into();
/// let esc = '\x1b';
///
/// assert!(uppercase_a.is_ascii_alphabetic());
/// assert!(uppercase_g.is_ascii_alphabetic());
Expand Down Expand Up @@ -1284,7 +1284,7 @@ impl char {
/// let percent = '%';
/// let space = ' ';
/// let lf = '\n';
/// let esc: char = 0x1b_u8.into();
/// let esc = '\x1b';
///
/// assert!(uppercase_a.is_ascii_uppercase());
/// assert!(uppercase_g.is_ascii_uppercase());
Expand Down Expand Up @@ -1318,7 +1318,7 @@ impl char {
/// let percent = '%';
/// let space = ' ';
/// let lf = '\n';
/// let esc: char = 0x1b_u8.into();
/// let esc = '\x1b';
///
/// assert!(!uppercase_a.is_ascii_lowercase());
/// assert!(!uppercase_g.is_ascii_lowercase());
Expand Down Expand Up @@ -1355,7 +1355,7 @@ impl char {
/// let percent = '%';
/// let space = ' ';
/// let lf = '\n';
/// let esc: char = 0x1b_u8.into();
/// let esc = '\x1b';
///
/// assert!(uppercase_a.is_ascii_alphanumeric());
/// assert!(uppercase_g.is_ascii_alphanumeric());
Expand Down Expand Up @@ -1389,7 +1389,7 @@ impl char {
/// let percent = '%';
/// let space = ' ';
/// let lf = '\n';
/// let esc: char = 0x1b_u8.into();
/// let esc = '\x1b';
///
/// assert!(!uppercase_a.is_ascii_digit());
/// assert!(!uppercase_g.is_ascii_digit());
Expand Down Expand Up @@ -1426,7 +1426,7 @@ impl char {
/// let percent = '%';
/// let space = ' ';
/// let lf = '\n';
/// let esc: char = 0x1b_u8.into();
/// let esc = '\x1b';
///
/// assert!(uppercase_a.is_ascii_hexdigit());
/// assert!(!uppercase_g.is_ascii_hexdigit());
Expand Down Expand Up @@ -1464,7 +1464,7 @@ impl char {
/// let percent = '%';
/// let space = ' ';
/// let lf = '\n';
/// let esc: char = 0x1b_u8.into();
/// let esc = '\x1b';
///
/// assert!(!uppercase_a.is_ascii_punctuation());
/// assert!(!uppercase_g.is_ascii_punctuation());
Expand Down Expand Up @@ -1498,7 +1498,7 @@ impl char {
/// let percent = '%';
/// let space = ' ';
/// let lf = '\n';
/// let esc: char = 0x1b_u8.into();
/// let esc = '\x1b';
///
/// assert!(uppercase_a.is_ascii_graphic());
/// assert!(uppercase_g.is_ascii_graphic());
Expand Down Expand Up @@ -1549,7 +1549,7 @@ impl char {
/// let percent = '%';
/// let space = ' ';
/// let lf = '\n';
/// let esc: char = 0x1b_u8.into();
/// let esc = '\x1b';
///
/// assert!(!uppercase_a.is_ascii_whitespace());
/// assert!(!uppercase_g.is_ascii_whitespace());
Expand Down Expand Up @@ -1585,7 +1585,7 @@ impl char {
/// let percent = '%';
/// let space = ' ';
/// let lf = '\n';
/// let esc: char = 0x1b_u8.into();
/// let esc = '\x1b';
///
/// assert!(!uppercase_a.is_ascii_control());
/// assert!(!uppercase_g.is_ascii_control());
Expand Down
20 changes: 10 additions & 10 deletions library/core/src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ impl u8 {
/// let percent = b'%';
/// let space = b' ';
/// let lf = b'\n';
/// let esc = 0x1b_u8;
/// let esc = b'\x1b';
///
/// assert!(uppercase_a.is_ascii_alphabetic());
/// assert!(uppercase_g.is_ascii_alphabetic());
Expand Down Expand Up @@ -462,7 +462,7 @@ impl u8 {
/// let percent = b'%';
/// let space = b' ';
/// let lf = b'\n';
/// let esc = 0x1b_u8;
/// let esc = b'\x1b';
///
/// assert!(uppercase_a.is_ascii_uppercase());
/// assert!(uppercase_g.is_ascii_uppercase());
Expand Down Expand Up @@ -496,7 +496,7 @@ impl u8 {
/// let percent = b'%';
/// let space = b' ';
/// let lf = b'\n';
/// let esc = 0x1b_u8;
/// let esc = b'\x1b';
///
/// assert!(!uppercase_a.is_ascii_lowercase());
/// assert!(!uppercase_g.is_ascii_lowercase());
Expand Down Expand Up @@ -533,7 +533,7 @@ impl u8 {
/// let percent = b'%';
/// let space = b' ';
/// let lf = b'\n';
/// let esc = 0x1b_u8;
/// let esc = b'\x1b';
///
/// assert!(uppercase_a.is_ascii_alphanumeric());
/// assert!(uppercase_g.is_ascii_alphanumeric());
Expand Down Expand Up @@ -567,7 +567,7 @@ impl u8 {
/// let percent = b'%';
/// let space = b' ';
/// let lf = b'\n';
/// let esc = 0x1b_u8;
/// let esc = b'\x1b';
///
/// assert!(!uppercase_a.is_ascii_digit());
/// assert!(!uppercase_g.is_ascii_digit());
Expand Down Expand Up @@ -604,7 +604,7 @@ impl u8 {
/// let percent = b'%';
/// let space = b' ';
/// let lf = b'\n';
/// let esc = 0x1b_u8;
/// let esc = b'\x1b';
///
/// assert!(uppercase_a.is_ascii_hexdigit());
/// assert!(!uppercase_g.is_ascii_hexdigit());
Expand Down Expand Up @@ -642,7 +642,7 @@ impl u8 {
/// let percent = b'%';
/// let space = b' ';
/// let lf = b'\n';
/// let esc = 0x1b_u8;
/// let esc = b'\x1b';
///
/// assert!(!uppercase_a.is_ascii_punctuation());
/// assert!(!uppercase_g.is_ascii_punctuation());
Expand Down Expand Up @@ -676,7 +676,7 @@ impl u8 {
/// let percent = b'%';
/// let space = b' ';
/// let lf = b'\n';
/// let esc = 0x1b_u8;
/// let esc = b'\x1b';
///
/// assert!(uppercase_a.is_ascii_graphic());
/// assert!(uppercase_g.is_ascii_graphic());
Expand Down Expand Up @@ -727,7 +727,7 @@ impl u8 {
/// let percent = b'%';
/// let space = b' ';
/// let lf = b'\n';
/// let esc = 0x1b_u8;
/// let esc = b'\x1b';
///
/// assert!(!uppercase_a.is_ascii_whitespace());
/// assert!(!uppercase_g.is_ascii_whitespace());
Expand Down Expand Up @@ -763,7 +763,7 @@ impl u8 {
/// let percent = b'%';
/// let space = b' ';
/// let lf = b'\n';
/// let esc = 0x1b_u8;
/// let esc = b'\x1b';
///
/// assert!(!uppercase_a.is_ascii_control());
/// assert!(!uppercase_g.is_ascii_control());
Expand Down
8 changes: 3 additions & 5 deletions library/core/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,11 +1104,10 @@ mod prim_usize {}
/// * [`Clone`] \(Note that this will not defer to `T`'s `Clone` implementation if it exists!)
/// * [`Deref`]
/// * [`Borrow`]
/// * [`Pointer`]
/// * [`fmt::Pointer`]
///
/// [`Deref`]: ops::Deref
/// [`Borrow`]: borrow::Borrow
/// [`Pointer`]: fmt::Pointer
///
/// `&mut T` references get all of the above except `Copy` and `Clone` (to prevent creating
/// multiple simultaneous mutable borrows), plus the following, regardless of the type of its
Expand All @@ -1124,7 +1123,7 @@ mod prim_usize {}
/// The following traits are implemented on `&T` references if the underlying `T` also implements
/// that trait:
///
/// * All the traits in [`std::fmt`] except [`Pointer`] and [`fmt::Write`]
/// * All the traits in [`std::fmt`] except [`fmt::Pointer`] (which is implemented regardless of the type of its referent) and [`fmt::Write`]
/// * [`PartialOrd`]
/// * [`Ord`]
/// * [`PartialEq`]
Expand All @@ -1133,9 +1132,9 @@ mod prim_usize {}
/// * [`Fn`] \(in addition, `&T` references get [`FnMut`] and [`FnOnce`] if `T: Fn`)
/// * [`Hash`]
/// * [`ToSocketAddrs`]
/// * [`Send`] \(`&T` references also require <code>T: [Sync]</code>)
///
/// [`std::fmt`]: fmt
/// ['Pointer`]: fmt::Pointer
/// [`Hash`]: hash::Hash
#[doc = concat!("[`ToSocketAddrs`]: ", include_str!("../primitive_docs/net_tosocketaddrs.md"))]
///
Expand All @@ -1150,7 +1149,6 @@ mod prim_usize {}
/// * [`ExactSizeIterator`]
/// * [`FusedIterator`]
/// * [`TrustedLen`]
/// * [`Send`] \(note that `&T` references only get `Send` if <code>T: [Sync]</code>)
/// * [`io::Write`]
/// * [`Read`]
/// * [`Seek`]
Expand Down
Loading

0 comments on commit 3b65165

Please sign in to comment.