Skip to content

Commit

Permalink
Auto merge of #121549 - matthiaskrgr:rollup-1hvu3lb, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #121435 (Account for RPITIT in E0310 explicit lifetime constraint suggestion)
 - #121490 (Rustdoc: include crate name in links for local primitives)
 - #121520 (delay cloning of iterator items)
 - #121522 (check that simd_insert/extract indices are in-bounds)
 - #121531 (Ignore less tests in debug builds)
 - #121539 (compiler/rustc_target/src/spec/base/apple/tests.rs: Avoid unnecessary large move)
 - #121542 (update stdarch)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 24, 2024
2 parents 6bdb8a4 + ee23b78 commit 381d699
Show file tree
Hide file tree
Showing 76 changed files with 190 additions and 153 deletions.
53 changes: 34 additions & 19 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
.map(|(arg_idx, val)| {
let idx = val.unwrap_leaf().try_to_i32().unwrap();
if idx >= i32::try_from(total_len).unwrap() {
bx.sess().dcx().emit_err(InvalidMonomorphization::ShuffleIndexOutOfBounds {
bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds {
span,
name,
arg_idx: arg_idx as u64,
Expand Down Expand Up @@ -1138,24 +1138,15 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
let val = bx.const_get_elt(vector, i as u64);
match bx.const_to_opt_u128(val, true) {
None => {
bx.sess().dcx().emit_err(
InvalidMonomorphization::ShuffleIndexNotConstant {
span,
name,
arg_idx,
},
);
None
bug!("typeck should have already ensured that these are const")
}
Some(idx) if idx >= total_len => {
bx.sess().dcx().emit_err(
InvalidMonomorphization::ShuffleIndexOutOfBounds {
span,
name,
arg_idx,
total_len,
},
);
bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds {
span,
name,
arg_idx,
total_len,
});
None
}
Some(idx) => Some(bx.const_i32(idx as i32)),
Expand Down Expand Up @@ -1184,18 +1175,42 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
out_ty: arg_tys[2]
}
);
let idx = bx
.const_to_opt_u128(args[1].immediate(), false)
.expect("typeck should have ensure that this is a const");
if idx >= in_len.into() {
bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds {
span,
name,
arg_idx: 1,
total_len: in_len.into(),
});
return Ok(bx.const_null(llret_ty));
}
return Ok(bx.insert_element(
args[0].immediate(),
args[2].immediate(),
args[1].immediate(),
bx.const_i32(idx as i32),
));
}
if name == sym::simd_extract {
require!(
ret_ty == in_elem,
InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
);
return Ok(bx.extract_element(args[0].immediate(), args[1].immediate()));
let idx = bx
.const_to_opt_u128(args[1].immediate(), false)
.expect("typeck should have ensure that this is a const");
if idx >= in_len.into() {
bx.sess().dcx().emit_err(InvalidMonomorphization::SimdIndexOutOfBounds {
span,
name,
arg_idx: 1,
total_len: in_len.into(),
});
return Ok(bx.const_null(llret_ty));
}
return Ok(bx.extract_element(args[0].immediate(), bx.const_i32(idx as i32)));
}

if name == sym::simd_select {
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,12 @@ codegen_ssa_invalid_monomorphization_return_type = invalid monomorphization of `
codegen_ssa_invalid_monomorphization_second_argument_length = invalid monomorphization of `{$name}` intrinsic: expected second argument with length {$in_len} (same as input type `{$in_ty}`), found `{$arg_ty}` with length {$out_len}
codegen_ssa_invalid_monomorphization_shuffle_index_not_constant = invalid monomorphization of `{$name}` intrinsic: shuffle index #{$arg_idx} is not a constant
codegen_ssa_invalid_monomorphization_shuffle_index_out_of_bounds = invalid monomorphization of `{$name}` intrinsic: shuffle index #{$arg_idx} is out of bounds (limit {$total_len})
codegen_ssa_invalid_monomorphization_simd_argument = invalid monomorphization of `{$name}` intrinsic: expected SIMD argument type, found non-SIMD `{$ty}`
codegen_ssa_invalid_monomorphization_simd_first = invalid monomorphization of `{$name}` intrinsic: expected SIMD first type, found non-SIMD `{$ty}`
codegen_ssa_invalid_monomorphization_simd_index_out_of_bounds = invalid monomorphization of `{$name}` intrinsic: SIMD index #{$arg_idx} is out of bounds (limit {$total_len})
codegen_ssa_invalid_monomorphization_simd_input = invalid monomorphization of `{$name}` intrinsic: expected SIMD input type, found non-SIMD `{$ty}`
codegen_ssa_invalid_monomorphization_simd_return = invalid monomorphization of `{$name}` intrinsic: expected SIMD return type, found non-SIMD `{$ty}`
Expand Down
12 changes: 2 additions & 10 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,16 +797,8 @@ pub enum InvalidMonomorphization<'tcx> {
out_ty: Ty<'tcx>,
},

#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_not_constant, code = E0511)]
ShuffleIndexNotConstant {
#[primary_span]
span: Span,
name: Symbol,
arg_idx: u64,
},

#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_out_of_bounds, code = E0511)]
ShuffleIndexOutOfBounds {
#[diag(codegen_ssa_invalid_monomorphization_simd_index_out_of_bounds, code = E0511)]
SimdIndexOutOfBounds {
#[primary_span]
span: Span,
name: Symbol,
Expand Down
20 changes: 12 additions & 8 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
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 < dest_len,
"Index `{index}` must be in bounds of vector with length {dest_len}"
);
// Bounds are not checked by typeck so we have to do it ourselves.
if index >= input_len {
throw_ub_format!(
"`simd_insert` index {index} is out-of-bounds of vector with length {input_len}"
);
}

for i in 0..dest_len {
let place = self.project_index(&dest, i)?;
Expand All @@ -397,10 +399,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
sym::simd_extract => {
let index = u64::from(self.read_scalar(&args[1])?.to_u32()?);
let (input, input_len) = self.operand_to_simd(&args[0])?;
assert!(
index < input_len,
"index `{index}` must be in bounds of vector with length {input_len}"
);
// Bounds are not checked by typeck so we have to do it ourselves.
if index >= input_len {
throw_ub_format!(
"`simd_extract` index {index} is out-of-bounds of vector with length {input_len}"
);
}
self.copy_op(&self.project_index(&input, index)?, dest)?;
}
sym::likely | sym::unlikely | sym::black_box => {
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let suggestion =
if has_lifetimes { format!(" + {lt_name}") } else { format!(": {lt_name}") };
suggs.push((sp, suggestion))
} else if let GenericKind::Alias(ref p) = bound_kind
&& let ty::Projection = p.kind(self.tcx)
&& let DefKind::AssocTy = self.tcx.def_kind(p.def_id)
&& let Some(ty::ImplTraitInTraitData::Trait { .. }) =
self.tcx.opt_rpitit_info(p.def_id)
{
// The lifetime found in the `impl` is longer than the one on the RPITIT.
// Do not suggest `<Type as Trait>::{opaque}: 'static`.
} else if let Some(generics) = self.tcx.hir().get_generics(suggestion_scope) {
let pred = format!("{bound_kind}: {lt_name}");
let suggestion = format!("{} {}", generics.add_where_or_trailing_comma(), pred);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/base/apple/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn simulator_targets_set_abi() {
aarch64_apple_watchos_sim::target(),
];

for target in all_sim_targets {
for target in &all_sim_targets {
assert_eq!(target.abi, "sim")
}
}
Expand Down
35 changes: 19 additions & 16 deletions compiler/rustc_trait_selection/src/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,22 +320,25 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>(
let mut errors = fulfill_cx.select_where_possible(infcx);
errors.pop().map(|err| err.obligation)
} else {
obligations.iter().cloned().find(|obligation| {
// We use `evaluate_root_obligation` to correctly track intercrate
// ambiguity clauses. We cannot use this in the new solver.
let evaluation_result = selcx.evaluate_root_obligation(obligation);

match evaluation_result {
Ok(result) => !result.may_apply(),
// If overflow occurs, we need to conservatively treat the goal as possibly holding,
// since there can be instantiations of this goal that don't overflow and result in
// success. This isn't much of a problem in the old solver, since we treat overflow
// fatally (this still can be encountered: <https://github.com/rust-lang/rust/issues/105231>),
// but in the new solver, this is very important for correctness, since overflow
// *must* be treated as ambiguity for completeness.
Err(_overflow) => false,
}
})
obligations
.iter()
.find(|obligation| {
// We use `evaluate_root_obligation` to correctly track intercrate
// ambiguity clauses. We cannot use this in the new solver.
let evaluation_result = selcx.evaluate_root_obligation(obligation);

match evaluation_result {
Ok(result) => !result.may_apply(),
// If overflow occurs, we need to conservatively treat the goal as possibly holding,
// since there can be instantiations of this goal that don't overflow and result in
// success. This isn't much of a problem in the old solver, since we treat overflow
// fatally (this still can be encountered: <https://github.com/rust-lang/rust/issues/105231>),
// but in the new solver, this is very important for correctness, since overflow
// *must* be treated as ambiguity for completeness.
Err(_overflow) => false,
}
})
.cloned()
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/stdarch
Submodule stdarch updated 38 files
+2 −1 crates/core_arch/src/aarch64/neon/mod.rs
+1 −3 crates/core_arch/src/arm_shared/neon/mod.rs
+0 −1 crates/core_arch/src/lib.rs
+0 −2 crates/core_arch/src/mod.rs
+163 −5 crates/core_arch/src/powerpc/altivec.rs
+1 −1 crates/core_arch/src/powerpc/vsx.rs
+0 −16 crates/core_arch/src/simd_llvm.rs
+1 −1 crates/core_arch/src/v64.rs
+1 −5 crates/core_arch/src/wasm32/simd128.rs
+30 −4 crates/core_arch/src/x86/avx.rs
+2 −4 crates/core_arch/src/x86/avx2.rs
+2 −4 crates/core_arch/src/x86/avx512bf16.rs
+1 −1 crates/core_arch/src/x86/avx512bitalg.rs
+3 −3 crates/core_arch/src/x86/avx512bw.rs
+2 −4 crates/core_arch/src/x86/avx512cd.rs
+30 −3 crates/core_arch/src/x86/avx512f.rs
+2 −1 crates/core_arch/src/x86/avx512vbmi.rs
+2 −1 crates/core_arch/src/x86/avx512vbmi2.rs
+2 −4 crates/core_arch/src/x86/avx512vnni.rs
+1 −1 crates/core_arch/src/x86/avx512vpopcntdq.rs
+1 −5 crates/core_arch/src/x86/f16c.rs
+1 −1 crates/core_arch/src/x86/fma.rs
+1 −1 crates/core_arch/src/x86/gfni.rs
+3 −1 crates/core_arch/src/x86/mod.rs
+1 −4 crates/core_arch/src/x86/sha.rs
+76 −7 crates/core_arch/src/x86/sse.rs
+30 −4 crates/core_arch/src/x86/sse2.rs
+2 −4 crates/core_arch/src/x86/sse3.rs
+2 −4 crates/core_arch/src/x86/sse41.rs
+2 −2 crates/core_arch/src/x86/sse42.rs
+19 −4 crates/core_arch/src/x86/sse4a.rs
+2 −2 crates/core_arch/src/x86/ssse3.rs
+1 −4 crates/core_arch/src/x86_64/avx.rs
+2 −1 crates/core_arch/src/x86_64/avx2.rs
+2 −1 crates/core_arch/src/x86_64/avx512f.rs
+11 −2 crates/core_arch/src/x86_64/sse2.rs
+1 −4 crates/core_arch/src/x86_64/sse41.rs
+48 −0 triagebot.toml
9 changes: 7 additions & 2 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,11 +879,16 @@ fn primitive_link_fragment(
match m.primitive_locations.get(&prim) {
Some(&def_id) if def_id.is_local() => {
let len = cx.current.len();
let len = if len == 0 { 0 } else { len - 1 };
let path = if len == 0 {
let cname_sym = ExternalCrate { crate_num: def_id.krate }.name(cx.tcx());
format!("{cname_sym}/")
} else {
"../".repeat(len - 1)
};
write!(
f,
"<a class=\"primitive\" href=\"{}primitive.{}.html{fragment}\">",
"../".repeat(len),
path,
prim.as_sym()
)?;
needs_termination = true;
Expand Down
7 changes: 5 additions & 2 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2503,8 +2503,11 @@ impl<'test> TestCx<'test> {
// overridden by `compile-flags`.
rustc.arg("-Copt-level=2");
}
RunPassValgrind | Pretty | DebugInfo | Codegen | Rustdoc | RustdocJson | RunMake
| CodegenUnits | JsDocTest | Assembly => {
Assembly | Codegen => {
rustc.arg("-Cdebug-assertions=no");
}
RunPassValgrind | Pretty | DebugInfo | Rustdoc | RustdocJson | RunMake
| CodegenUnits | JsDocTest => {
// do not use JSON output
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/tools/miri/src/shims/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let right_idx = src_index.checked_sub(left_len).unwrap();
this.read_immediate(&this.project_index(&right, right_idx)?)?
} else {
span_bug!(
this.cur_span(),
"simd_shuffle index {src_index} is out of bounds for 2 vectors of size {left_len}",
throw_ub_format!(
"`simd_shuffle_generic` index {src_index} is out-of-bounds for 2 vectors with length {dest_len}"
);
};
this.write_immediate(*val, &dest)?;
Expand Down Expand Up @@ -604,9 +603,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let right_idx = src_index.checked_sub(left_len).unwrap();
this.read_immediate(&this.project_index(&right, right_idx)?)?
} else {
span_bug!(
this.cur_span(),
"simd_shuffle index {src_index} is out of bounds for 2 vectors of size {left_len}",
throw_ub_format!(
"`simd_shuffle` index {src_index} is out-of-bounds for 2 vectors with length {dest_len}"
);
};
this.write_immediate(*val, &dest)?;
Expand Down
8 changes: 8 additions & 0 deletions src/tools/miri/tests/fail/intrinsics/simd-extract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(portable_simd, core_intrinsics)]
use std::simd::*;

fn main() {
let v = i32x4::splat(0);
let _x: i32 = unsafe { std::intrinsics::simd::simd_extract(v, 4) };
//~^ERROR: index 4 is out-of-bounds
}
15 changes: 15 additions & 0 deletions src/tools/miri/tests/fail/intrinsics/simd-extract.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: Undefined Behavior: `simd_extract` index 4 is out-of-bounds of vector with length 4
--> $DIR/simd-extract.rs:LL:CC
|
LL | let _x: i32 = unsafe { std::intrinsics::simd::simd_extract(v, 4) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `simd_extract` index 4 is out-of-bounds of vector with length 4
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `main` at $DIR/simd-extract.rs:LL:CC

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

1 change: 0 additions & 1 deletion tests/assembly/option-nonzero-eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//@ compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel
//@ only-x86_64
//@ ignore-sgx
//@ ignore-debug

use std::cmp::Ordering;

Expand Down
1 change: 0 additions & 1 deletion tests/assembly/slice-is_ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//@ compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel
//@ only-x86_64
//@ ignore-sgx
//@ ignore-debug

#![feature(str_internals)]

Expand Down
1 change: 0 additions & 1 deletion tests/assembly/static-relocation-model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//@ [A64] needs-llvm-components: aarch64
//@ [ppc64le] compile-flags: --target powerpc64le-unknown-linux-gnu -Crelocation-model=static
//@ [ppc64le] needs-llvm-components: powerpc
//@ ignore-debug: alignment checks insert panics that we don't have a lang item for

#![feature(no_core, lang_items)]
#![no_core]
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/align-offset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: -O
//@ ignore-debug (debug assertions in `slice::from_raw_parts` block optimizations)

#![crate_type = "lib"]

Expand Down
1 change: 0 additions & 1 deletion tests/codegen/array-map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ compile-flags: -C opt-level=3 -C target-cpu=x86-64-v3
//@ only-x86_64
//@ ignore-debug (the extra assertions get in the way)

#![crate_type = "lib"]

Expand Down
1 change: 0 additions & 1 deletion tests/codegen/ascii-char.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: -C opt-level=1
//@ ignore-debug (the extra assertions get in the way)

#![crate_type = "lib"]
#![feature(ascii_char)]
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/binary-search-index-no-bound-check.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: -O
//@ ignore-debug: the debug assertions get in the way
#![crate_type = "lib"]

// Make sure no bounds checks are emitted when slicing or indexing
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/infallible-unwrap-in-opt-z.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: -C opt-level=z --edition=2021
//@ ignore-debug

#![crate_type = "lib"]

Expand Down
1 change: 0 additions & 1 deletion tests/codegen/issue-97217.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: -C opt-level=3
//@ ignore-debug: the debug assertions get in the way
//@ min-llvm-version: 17.0.2
#![crate_type = "lib"]

Expand Down
1 change: 0 additions & 1 deletion tests/codegen/issues/issue-101082.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: -O
//@ ignore-debug: the debug assertions get in the way

#![crate_type = "lib"]

Expand Down
1 change: 0 additions & 1 deletion tests/codegen/issues/issue-101814.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: -O
//@ ignore-debug: the debug assertions get in the way

#![crate_type = "lib"]

Expand Down
1 change: 0 additions & 1 deletion tests/codegen/issues/issue-106369.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: -O
//@ ignore-debug (the extra assertions get in the way)

#![crate_type = "lib"]

Expand Down
1 change: 0 additions & 1 deletion tests/codegen/issues/issue-116878.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ compile-flags: -O
//@ ignore-debug: the debug assertions get in the way
#![crate_type = "lib"]

/// Make sure no bounds checks are emitted after a `get_unchecked`.
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/issues/issue-37945.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ compile-flags: -O -Zmerge-functions=disabled
//@ ignore-32bit LLVM has a bug with them
//@ ignore-debug

// Check that LLVM understands that `Iter` pointer is not null. Issue #37945.

Expand Down
Loading

0 comments on commit 381d699

Please sign in to comment.