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 5 pull requests #91041

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
69df43b
Improve display of enum variants
jsha Oct 20, 2021
483cff7
Add SourceMap::indentation_before.
m-ou-se Nov 4, 2021
453e242
Improve suggestion for unit Option/Result at the end of a block.
m-ou-se Nov 4, 2021
b331b66
Improve compatible enum variant suggestions.
m-ou-se Nov 4, 2021
4877756
Update tests.
m-ou-se Nov 4, 2021
5a25751
Add new tests for compatible variant diagnostics.
m-ou-se Nov 4, 2021
09e4a75
Use span_suggestions instead of multipart_suggestions.
m-ou-se Nov 4, 2021
b66fb64
Update test output.
m-ou-se Nov 16, 2021
f5dc388
Point at source of trait bound obligations in more places
estebank Oct 5, 2021
3fe48b2
Change `trait_defs.rs` incremental hash test
estebank Oct 6, 2021
412793f
Point at bounds when comparing impl items to trait
estebank Oct 6, 2021
abf70a9
Do not mention associated items when they introduce an obligation
estebank Oct 12, 2021
a6b31eb
Align multiline messages to their label (add left margin)
estebank Oct 13, 2021
70e8240
Point at `impl` blocks when they introduce unmet obligations
estebank Oct 13, 2021
8d443ea
Suggest constraining `fn` type params when appropriate
estebank Oct 13, 2021
1cadfe6
Move tests for missing trait bounds to their own directory
estebank Oct 14, 2021
2c173af
review comments
estebank Nov 18, 2021
a8dcc87
Move tests from ui directory
estebank Nov 18, 2021
2f1a1f5
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types
RalfJung Nov 18, 2021
0304e16
CTFE SIMD: also test 1-element array
RalfJung Nov 18, 2021
67a5b19
Check for duplicate attributes.
ehuss Sep 5, 2021
4c60ea8
Add checks for more empty attributes.
ehuss Sep 6, 2021
9ac19a5
Rollup merge of #88681 - ehuss:duplicate-attributes, r=petrochenkov
matthiaskrgr Nov 19, 2021
af2c2b2
Rollup merge of #89580 - estebank:trait-bounds-are-tricky, r=nagisa
matthiaskrgr Nov 19, 2021
a256b31
Rollup merge of #90089 - jsha:enum-fields-headings, r=camelid,Guillau…
matthiaskrgr Nov 19, 2021
3ccfe8b
Rollup merge of #90575 - m-ou-se:compatible-variant-improvements, r=e…
matthiaskrgr Nov 19, 2021
9b87fa5
Rollup merge of #90999 - RalfJung:miri_simd, r=oli-obk
matthiaskrgr Nov 19, 2021
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
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
17 changes: 16 additions & 1 deletion compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,22 +1266,37 @@ impl EmitterWriter {
}
self.msg_to_buffer(&mut buffer, msg, max_line_num_len, "note", None);
} else {
let mut label_width = 0;
// The failure note level itself does not provide any useful diagnostic information
if *level != Level::FailureNote {
buffer.append(0, level.to_str(), Style::Level(*level));
label_width += level.to_str().len();
}
// only render error codes, not lint codes
if let Some(DiagnosticId::Error(ref code)) = *code {
buffer.append(0, "[", Style::Level(*level));
buffer.append(0, &code, Style::Level(*level));
buffer.append(0, "]", Style::Level(*level));
label_width += 2 + code.len();
}
let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
if *level != Level::FailureNote {
buffer.append(0, ": ", header_style);
label_width += 2;
}
for &(ref text, _) in msg.iter() {
buffer.append(0, &replace_tabs(text), header_style);
// Account for newlines to align output to its label.
for (line, text) in replace_tabs(text).lines().enumerate() {
buffer.append(
0 + line,
&format!(
"{}{}",
if line == 0 { String::new() } else { " ".repeat(label_width) },
text
),
header_style,
);
}
}
}

Expand Down
Loading