Skip to content

Commit

Permalink
Auto merge of rust-lang#96108 - Dylan-DPC:rollup-t5f2fc9, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - rust-lang#93969 (Only add codegen backend to dep info if -Zbinary-dep-depinfo is used)
 - rust-lang#94605 (Add missing links in platform support docs)
 - rust-lang#95372 (make unaligned_references lint deny-by-default)
 - rust-lang#95859 (Improve diagnostics for unterminated nested block comment)
 - rust-lang#95961 (implement SIMD gather/scatter via vector getelementptr)
 - rust-lang#96004 (Consider lifetimes when comparing types for equality in MIR validator)
 - rust-lang#96050 (Remove some now-dead code that was only relevant before deaggregation.)
 - rust-lang#96070 ([test] Add test cases for untested functions for BTreeMap)
 - rust-lang#96099 (MaybeUninit array cleanup)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 16, 2022
2 parents 07bb916 + f559cf9 commit c842240
Show file tree
Hide file tree
Showing 37 changed files with 797 additions and 92 deletions.
21 changes: 21 additions & 0 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,27 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
simd_neg: Int => neg, Float => fneg;
}

if name == sym::simd_arith_offset {
// This also checks that the first operand is a ptr type.
let pointee = in_elem.builtin_deref(true).unwrap_or_else(|| {
span_bug!(span, "must be called with a vector of pointer types as first argument")
});
let layout = bx.layout_of(pointee.ty);
let ptrs = args[0].immediate();
// The second argument must be a ptr-sized integer.
// (We don't care about the signedness, this is wrapping anyway.)
let (_offsets_len, offsets_elem) = arg_tys[1].simd_size_and_type(bx.tcx());
if !matches!(offsets_elem.kind(), ty::Int(ty::IntTy::Isize) | ty::Uint(ty::UintTy::Usize)) {
span_bug!(
span,
"must be called with a vector of pointer-sized integers as second argument"
);
}
let offsets = args[1].immediate();

return Ok(bx.gep(bx.backend_type(layout), ptrs, &[offsets]));
}

if name == sym::simd_saturating_add || name == sym::simd_saturating_sub {
let lhs = args[0].immediate();
let rhs = args[1].immediate();
Expand Down
22 changes: 3 additions & 19 deletions compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.write_immediate(*val, &dest)?;
}

Aggregate(ref kind, ref operands) => {
// active_field_index is for union initialization.
let (dest, active_field_index) = match **kind {
mir::AggregateKind::Adt(adt_did, variant_index, _, _, active_field_index) => {
self.write_discriminant(variant_index, &dest)?;
if self.tcx.adt_def(adt_did).is_enum() {
assert!(active_field_index.is_none());
(self.place_downcast(&dest, variant_index)?, None)
} else {
if active_field_index.is_some() {
assert_eq!(operands.len(), 1);
}
(dest, active_field_index)
}
}
_ => (dest, None),
};
Aggregate(box ref kind, ref operands) => {
assert!(matches!(kind, mir::AggregateKind::Array(..)));

for (i, operand) in operands.iter().enumerate() {
for (field_index, operand) in operands.iter().enumerate() {
let op = self.eval_operand(operand, None)?;
let field_index = active_field_index.unwrap_or(i);
let field_dest = self.place_field(&dest, field_index)?;
self.copy_op(&op, &field_dest)?;
}
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
| ty::FnPtr(..)
)
}
// None of the possible types have lifetimes, so we can just compare
// directly
if a != b {
// The function pointer types can have lifetimes
if !self.mir_assign_valid_types(a, b) {
self.fail(
location,
format!("Cannot compare unequal types {:?} and {:?}", a, b),
Expand Down Expand Up @@ -464,7 +463,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
};
// since CopyNonOverlapping is parametrized by 1 type,
// we only need to check that they are equal and not keep an extra parameter.
if op_src_ty != op_dst_ty {
if !self.mir_assign_valid_types(op_src_ty, op_dst_ty) {
self.fail(location, format!("bad arg ({:?} != {:?})", op_src_ty, op_dst_ty));
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#![feature(thread_id_value)]
#![feature(vec_into_raw_parts)]
#![allow(rustc::default_hash_types)]
#![deny(unaligned_references)]
#![allow(rustc::potential_query_instability)]

#[macro_use]
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,15 @@ fn write_out_deps(
});
files.extend(extra_tracked_files);

if let Some(ref backend) = sess.opts.debugging_opts.codegen_backend {
files.push(backend.to_string());
}

if sess.binary_dep_depinfo() {
if let Some(ref backend) = sess.opts.debugging_opts.codegen_backend {
if backend.contains('.') {
// If the backend name contain a `.`, it is the path to an external dynamic
// library. If not, it is not a path.
files.push(backend.to_string());
}
}

boxed_resolver.borrow_mut().access(|resolver| {
for cnum in resolver.cstore().crates_untracked() {
let source = resolver.cstore().crate_source_untracked(cnum);
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,8 +1110,6 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(unaligned_references)]
///
/// #[repr(packed)]
/// pub struct Foo {
/// field1: u64,
Expand Down Expand Up @@ -1139,10 +1137,11 @@ declare_lint! {
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
/// [issue #82523]: https://github.com/rust-lang/rust/issues/82523
pub UNALIGNED_REFERENCES,
Warn,
Deny,
"detects unaligned references to fields of packed structs",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #82523 <https://github.com/rust-lang/rust/issues/82523>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
};
report_in_external_macro
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2518,7 +2518,8 @@ pub enum Rvalue<'tcx> {
/// * `Offset` has the same semantics as [`offset`](pointer::offset), except that the second
/// parameter may be a `usize` as well.
/// * The comparison operations accept `bool`s, `char`s, signed or unsigned integers, floats,
/// raw pointers, or function pointers of matching types and return a `bool`.
/// raw pointers, or function pointers and return a `bool`. The types of the operands must be
/// matching, up to the usual caveat of the lifetimes in function pointers.
/// * Left and right shift operations accept signed or unsigned integers not necessarily of the
/// same type and return a value of the same type as their LHS. Like in Rust, the RHS is
/// truncated as needed.
Expand Down
60 changes: 50 additions & 10 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,7 @@ impl<'a> StringReader<'a> {
}
rustc_lexer::TokenKind::BlockComment { doc_style, terminated } => {
if !terminated {
let msg = match doc_style {
Some(_) => "unterminated block doc-comment",
None => "unterminated block comment",
};
let last_bpos = self.pos;
self.sess.span_diagnostic.span_fatal_with_code(
self.mk_sp(start, last_bpos),
msg,
error_code!(E0758),
);
self.report_unterminated_block_comment(start, doc_style);
}

// Skip non-doc comments
Expand Down Expand Up @@ -553,6 +544,55 @@ impl<'a> StringReader<'a> {
err.emit()
}

fn report_unterminated_block_comment(&self, start: BytePos, doc_style: Option<DocStyle>) {
let msg = match doc_style {
Some(_) => "unterminated block doc-comment",
None => "unterminated block comment",
};
let last_bpos = self.pos;
let mut err = self.sess.span_diagnostic.struct_span_fatal_with_code(
self.mk_sp(start, last_bpos),
msg,
error_code!(E0758),
);
let mut nested_block_comment_open_idxs = vec![];
let mut last_nested_block_comment_idxs = None;
let mut content_chars = self.str_from(start).char_indices().peekable();

while let Some((idx, current_char)) = content_chars.next() {
match content_chars.peek() {
Some((_, '*')) if current_char == '/' => {
nested_block_comment_open_idxs.push(idx);
}
Some((_, '/')) if current_char == '*' => {
last_nested_block_comment_idxs =
nested_block_comment_open_idxs.pop().map(|open_idx| (open_idx, idx));
}
_ => {}
};
}

if let Some((nested_open_idx, nested_close_idx)) = last_nested_block_comment_idxs {
err.span_label(self.mk_sp(start, start + BytePos(2)), msg)
.span_label(
self.mk_sp(
start + BytePos(nested_open_idx as u32),
start + BytePos(nested_open_idx as u32 + 2),
),
"...as last nested comment starts here, maybe you want to close this instead?",
)
.span_label(
self.mk_sp(
start + BytePos(nested_close_idx as u32),
start + BytePos(nested_close_idx as u32 + 2),
),
"...and last nested comment terminates here.",
);
}

err.emit();
}

// RFC 3101 introduced the idea of (reserved) prefixes. As of Rust 2021,
// using a (unknown) prefix is an error. In earlier editions, however, they
// only result in a (allowed by default) lint, and are treated as regular
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,7 @@ symbols! {
simd,
simd_add,
simd_and,
simd_arith_offset,
simd_as,
simd_bitmask,
simd_cast,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_typeck/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
| sym::simd_fpow
| sym::simd_saturating_add
| sym::simd_saturating_sub => (1, vec![param(0), param(0)], param(0)),
sym::simd_arith_offset => (2, vec![param(0), param(1)], param(0)),
sym::simd_neg
| sym::simd_fsqrt
| sym::simd_fsin
Expand Down
105 changes: 105 additions & 0 deletions library/alloc/src/collections/btree/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,96 @@ fn test_first_last_entry() {
a.check();
}

#[test]
fn test_pop_first_last() {
let mut map = BTreeMap::new();
assert_eq!(map.pop_first(), None);
assert_eq!(map.pop_last(), None);

map.insert(1, 10);
map.insert(2, 20);
map.insert(3, 30);
map.insert(4, 40);

assert_eq!(map.len(), 4);

let (key, val) = map.pop_first().unwrap();
assert_eq!(key, 1);
assert_eq!(val, 10);
assert_eq!(map.len(), 3);

let (key, val) = map.pop_first().unwrap();
assert_eq!(key, 2);
assert_eq!(val, 20);
assert_eq!(map.len(), 2);
let (key, val) = map.pop_last().unwrap();
assert_eq!(key, 4);
assert_eq!(val, 40);
assert_eq!(map.len(), 1);

map.insert(5, 50);
map.insert(6, 60);
assert_eq!(map.len(), 3);

let (key, val) = map.pop_first().unwrap();
assert_eq!(key, 3);
assert_eq!(val, 30);
assert_eq!(map.len(), 2);

let (key, val) = map.pop_last().unwrap();
assert_eq!(key, 6);
assert_eq!(val, 60);
assert_eq!(map.len(), 1);

let (key, val) = map.pop_last().unwrap();
assert_eq!(key, 5);
assert_eq!(val, 50);
assert_eq!(map.len(), 0);

assert_eq!(map.pop_first(), None);
assert_eq!(map.pop_last(), None);

map.insert(7, 70);
map.insert(8, 80);

let (key, val) = map.pop_last().unwrap();
assert_eq!(key, 8);
assert_eq!(val, 80);
assert_eq!(map.len(), 1);

let (key, val) = map.pop_last().unwrap();
assert_eq!(key, 7);
assert_eq!(val, 70);
assert_eq!(map.len(), 0);

assert_eq!(map.pop_first(), None);
assert_eq!(map.pop_last(), None);
}

#[test]
fn test_get_key_value() {
let mut map = BTreeMap::new();

assert!(map.is_empty());
assert_eq!(map.get_key_value(&1), None);
assert_eq!(map.get_key_value(&2), None);

map.insert(1, 10);
map.insert(2, 20);
map.insert(3, 30);

assert_eq!(map.len(), 3);
assert_eq!(map.get_key_value(&1), Some((&1, &10)));
assert_eq!(map.get_key_value(&3), Some((&3, &30)));
assert_eq!(map.get_key_value(&4), None);

map.remove(&3);

assert_eq!(map.len(), 2);
assert_eq!(map.get_key_value(&3), None);
assert_eq!(map.get_key_value(&2), Some((&2, &20)));
}

#[test]
fn test_insert_into_full_height_0() {
let size = node::CAPACITY;
Expand All @@ -1904,6 +1994,21 @@ fn test_insert_into_full_height_1() {
}
}

#[test]
fn test_try_insert() {
let mut map = BTreeMap::new();

assert!(map.is_empty());

assert_eq!(map.try_insert(1, 10).unwrap(), &10);
assert_eq!(map.try_insert(2, 20).unwrap(), &20);

let err = map.try_insert(2, 200).unwrap_err();
assert_eq!(err.entry.key(), &2);
assert_eq!(err.entry.get(), &20);
assert_eq!(err.value, 200);
}

macro_rules! create_append_test {
($name:ident, $len:expr) => {
#[test]
Expand Down
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
#![feature(const_intrinsic_copy)]
#![feature(const_intrinsic_forget)]
#![feature(const_likely)]
#![feature(const_maybe_uninit_uninit_array)]
#![feature(const_maybe_uninit_as_mut_ptr)]
#![feature(const_maybe_uninit_assume_init)]
#![feature(const_num_from_num)]
Expand Down
Loading

0 comments on commit c842240

Please sign in to comment.