Skip to content

Commit 268dbbb

Browse files
committed
Auto merge of rust-lang#120624 - matthiaskrgr:rollup-3gvcl20, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#120484 (Avoid ICE when is_val_statically_known is not of a supported type) - rust-lang#120516 (pattern_analysis: cleanup manual impls) - rust-lang#120517 (never patterns: It is correct to lower `!` to `_`.) - rust-lang#120523 (Improve `io::Read::read_buf_exact` error case) - rust-lang#120528 (Store SHOULD_CAPTURE as AtomicU8) - rust-lang#120529 (Update data layouts in custom target tests for LLVM 18) - rust-lang#120531 (Remove a bunch of `has_errors` checks that have no meaningful or the wrong effect) - rust-lang#120533 (Correct paths for hexagon-unknown-none-elf platform doc) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4e3eed4 + edd2494 commit 268dbbb

34 files changed

+202
-154
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ impl<'ll> CodegenCx<'ll, '_> {
909909
ifn!("llvm.is.constant.isize", fn(t_isize) -> i1);
910910
ifn!("llvm.is.constant.f32", fn(t_f32) -> i1);
911911
ifn!("llvm.is.constant.f64", fn(t_f64) -> i1);
912+
ifn!("llvm.is.constant.ptr", fn(ptr) -> i1);
912913

913914
ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
914915
ifn!("llvm.eh.typeid.for", fn(ptr) -> t_i32);

compiler/rustc_codegen_llvm/src/intrinsic.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,18 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
119119
sym::likely => {
120120
self.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(true)])
121121
}
122-
sym::is_val_statically_known => self.call_intrinsic(
123-
&format!("llvm.is.constant.{:?}", args[0].layout.immediate_llvm_type(self.cx)),
124-
&[args[0].immediate()],
125-
),
122+
sym::is_val_statically_known => {
123+
let intrinsic_type = args[0].layout.immediate_llvm_type(self.cx);
124+
match self.type_kind(intrinsic_type) {
125+
TypeKind::Pointer | TypeKind::Integer | TypeKind::Float | TypeKind::Double => {
126+
self.call_intrinsic(
127+
&format!("llvm.is.constant.{:?}", intrinsic_type),
128+
&[args[0].immediate()],
129+
)
130+
}
131+
_ => self.const_bool(false),
132+
}
133+
}
126134
sym::unlikely => self
127135
.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(false)]),
128136
kw::Try => {

compiler/rustc_pattern_analysis/src/constructor.rs

+1-69
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151
use std::cmp::{self, max, min, Ordering};
152152
use std::fmt;
153153
use std::iter::once;
154-
use std::mem;
155154

156155
use smallvec::SmallVec;
157156

@@ -648,6 +647,7 @@ impl OpaqueId {
648647
/// `specialize_constructor` returns the list of fields corresponding to a pattern, given a
649648
/// constructor. `Constructor::apply` reconstructs the pattern from a pair of `Constructor` and
650649
/// `Fields`.
650+
#[derive(Debug)]
651651
pub enum Constructor<Cx: TypeCx> {
652652
/// Tuples and structs.
653653
Struct,
@@ -717,74 +717,6 @@ impl<Cx: TypeCx> Clone for Constructor<Cx> {
717717
}
718718
}
719719

720-
impl<Cx: TypeCx> fmt::Debug for Constructor<Cx> {
721-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
722-
match self {
723-
Constructor::Struct => f.debug_tuple("Struct").finish(),
724-
Constructor::Variant(idx) => f.debug_tuple("Variant").field(idx).finish(),
725-
Constructor::Ref => f.debug_tuple("Ref").finish(),
726-
Constructor::Slice(slice) => f.debug_tuple("Slice").field(slice).finish(),
727-
Constructor::UnionField => f.debug_tuple("UnionField").finish(),
728-
Constructor::Bool(b) => f.debug_tuple("Bool").field(b).finish(),
729-
Constructor::IntRange(range) => f.debug_tuple("IntRange").field(range).finish(),
730-
Constructor::F32Range(lo, hi, end) => {
731-
f.debug_tuple("F32Range").field(lo).field(hi).field(end).finish()
732-
}
733-
Constructor::F64Range(lo, hi, end) => {
734-
f.debug_tuple("F64Range").field(lo).field(hi).field(end).finish()
735-
}
736-
Constructor::Str(value) => f.debug_tuple("Str").field(value).finish(),
737-
Constructor::Opaque(inner) => f.debug_tuple("Opaque").field(inner).finish(),
738-
Constructor::Or => f.debug_tuple("Or").finish(),
739-
Constructor::Wildcard => f.debug_tuple("Wildcard").finish(),
740-
Constructor::NonExhaustive => f.debug_tuple("NonExhaustive").finish(),
741-
Constructor::Hidden => f.debug_tuple("Hidden").finish(),
742-
Constructor::Missing => f.debug_tuple("Missing").finish(),
743-
}
744-
}
745-
}
746-
747-
impl<Cx: TypeCx> PartialEq for Constructor<Cx> {
748-
fn eq(&self, other: &Self) -> bool {
749-
(mem::discriminant(self) == mem::discriminant(other))
750-
&& match (self, other) {
751-
(Constructor::Struct, Constructor::Struct) => true,
752-
(Constructor::Variant(self_variant), Constructor::Variant(other_variant)) => {
753-
self_variant == other_variant
754-
}
755-
(Constructor::Ref, Constructor::Ref) => true,
756-
(Constructor::Slice(self_slice), Constructor::Slice(other_slice)) => {
757-
self_slice == other_slice
758-
}
759-
(Constructor::UnionField, Constructor::UnionField) => true,
760-
(Constructor::Bool(self_b), Constructor::Bool(other_b)) => self_b == other_b,
761-
(Constructor::IntRange(self_range), Constructor::IntRange(other_range)) => {
762-
self_range == other_range
763-
}
764-
(
765-
Constructor::F32Range(self_lo, self_hi, self_end),
766-
Constructor::F32Range(other_lo, other_hi, other_end),
767-
) => self_lo == other_lo && self_hi == other_hi && self_end == other_end,
768-
(
769-
Constructor::F64Range(self_lo, self_hi, self_end),
770-
Constructor::F64Range(other_lo, other_hi, other_end),
771-
) => self_lo == other_lo && self_hi == other_hi && self_end == other_end,
772-
(Constructor::Str(self_value), Constructor::Str(other_value)) => {
773-
self_value == other_value
774-
}
775-
(Constructor::Opaque(self_inner), Constructor::Opaque(other_inner)) => {
776-
self_inner == other_inner
777-
}
778-
(Constructor::Or, Constructor::Or) => true,
779-
(Constructor::Wildcard, Constructor::Wildcard) => true,
780-
(Constructor::NonExhaustive, Constructor::NonExhaustive) => true,
781-
(Constructor::Hidden, Constructor::Hidden) => true,
782-
(Constructor::Missing, Constructor::Missing) => true,
783-
_ => unreachable!(),
784-
}
785-
}
786-
}
787-
788720
impl<Cx: TypeCx> Constructor<Cx> {
789721
pub(crate) fn is_non_exhaustive(&self) -> bool {
790722
matches!(self, NonExhaustive)

compiler/rustc_pattern_analysis/src/pat.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ impl<'p, Cx: TypeCx> fmt::Debug for PatOrWild<'p, Cx> {
297297

298298
/// Same idea as `DeconstructedPat`, except this is a fictitious pattern built up for diagnostics
299299
/// purposes. As such they don't use interning and can be cloned.
300+
#[derive(Debug)]
300301
pub struct WitnessPat<Cx: TypeCx> {
301302
ctor: Constructor<Cx>,
302303
pub(crate) fields: Vec<WitnessPat<Cx>>,
@@ -309,16 +310,6 @@ impl<Cx: TypeCx> Clone for WitnessPat<Cx> {
309310
}
310311
}
311312

312-
impl<Cx: TypeCx> fmt::Debug for WitnessPat<Cx> {
313-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
314-
fmt.debug_struct("WitnessPat")
315-
.field("ctor", &self.ctor)
316-
.field("fields", &self.fields)
317-
.field("ty", &self.ty)
318-
.finish()
319-
}
320-
}
321-
322313
impl<Cx: TypeCx> WitnessPat<Cx> {
323314
pub(crate) fn new(ctor: Constructor<Cx>, fields: Vec<Self>, ty: Cx::Ty) -> Self {
324315
Self { ctor, fields, ty }

compiler/rustc_pattern_analysis/src/rustc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,9 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
675675
cx.pattern_arena.alloc_from_iter(pats.into_iter().map(|p| self.lower_pat(p)))
676676
}
677677
PatKind::Never => {
678-
// FIXME(never_patterns): handle `!` in exhaustiveness. This is a sane default
679-
// in the meantime.
678+
// A never pattern matches all the values of its type (namely none). Moreover it
679+
// must be compatible with other constructors, since we can use `!` on a type like
680+
// `Result<!, !>` which has other constructors. Hence we lower it as a wildcard.
680681
ctor = Wildcard;
681682
fields = &[];
682683
}

compiler/rustc_pattern_analysis/src/usefulness.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ impl<'p, Cx: TypeCx> fmt::Debug for Matrix<'p, Cx> {
12071207
/// The final `Pair(Some(_), true)` is then the resulting witness.
12081208
///
12091209
/// See the top of the file for more detailed explanations and examples.
1210+
#[derive(Debug)]
12101211
struct WitnessStack<Cx: TypeCx>(Vec<WitnessPat<Cx>>);
12111212

12121213
impl<Cx: TypeCx> Clone for WitnessStack<Cx> {
@@ -1215,12 +1216,6 @@ impl<Cx: TypeCx> Clone for WitnessStack<Cx> {
12151216
}
12161217
}
12171218

1218-
impl<Cx: TypeCx> fmt::Debug for WitnessStack<Cx> {
1219-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1220-
fmt.debug_tuple("WitnessStack").field(&self.0).finish()
1221-
}
1222-
}
1223-
12241219
impl<Cx: TypeCx> WitnessStack<Cx> {
12251220
/// Asserts that the witness contains a single pattern, and returns it.
12261221
fn single_pattern(self) -> WitnessPat<Cx> {
@@ -1265,6 +1260,7 @@ impl<Cx: TypeCx> WitnessStack<Cx> {
12651260
///
12661261
/// Just as the `Matrix` starts with a single column, by the end of the algorithm, this has a single
12671262
/// column, which contains the patterns that are missing for the match to be exhaustive.
1263+
#[derive(Debug)]
12681264
struct WitnessMatrix<Cx: TypeCx>(Vec<WitnessStack<Cx>>);
12691265

12701266
impl<Cx: TypeCx> Clone for WitnessMatrix<Cx> {
@@ -1273,12 +1269,6 @@ impl<Cx: TypeCx> Clone for WitnessMatrix<Cx> {
12731269
}
12741270
}
12751271

1276-
impl<Cx: TypeCx> fmt::Debug for WitnessMatrix<Cx> {
1277-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1278-
fmt.debug_tuple("WitnessMatrix").field(&self.0).finish()
1279-
}
1280-
}
1281-
12821272
impl<Cx: TypeCx> WitnessMatrix<Cx> {
12831273
/// New matrix with no witnesses.
12841274
fn empty() -> Self {

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
448448
// FIXME(effects)
449449
let predicate_is_const = false;
450450

451-
if let Some(guar) = self.dcx().has_errors()
452-
&& trait_predicate.references_error()
451+
if let Err(guar) = trait_predicate.error_reported()
453452
{
454453
return guar;
455454
}
@@ -2625,9 +2624,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
26252624
if let Some(e) = self.tainted_by_errors() {
26262625
return e;
26272626
}
2628-
if let Some(e) = self.dcx().has_errors() {
2629-
return e;
2630-
}
26312627

26322628
self.emit_inference_failure_err(
26332629
obligation.cause.body_id,
@@ -2645,10 +2641,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
26452641
if let Some(e) = self.tainted_by_errors() {
26462642
return e;
26472643
}
2648-
if let Some(e) = self.dcx().has_errors() {
2649-
// no need to overload user in such cases
2650-
return e;
2651-
}
26522644
let SubtypePredicate { a_is_expected: _, a, b } = data;
26532645
// both must be type variables, or the other would've been instantiated
26542646
assert!(a.is_ty_var() && b.is_ty_var());
@@ -2728,10 +2720,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
27282720
if let Some(e) = self.tainted_by_errors() {
27292721
return e;
27302722
}
2731-
if let Some(e) = self.dcx().has_errors() {
2732-
// no need to overload user in such cases
2733-
return e;
2734-
}
27352723
struct_span_code_err!(
27362724
self.dcx(),
27372725
span,

library/std/src/io/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,10 @@ pub trait Read {
994994
}
995995

996996
if cursor.written() == prev_written {
997-
return Err(Error::new(ErrorKind::UnexpectedEof, "failed to fill buffer"));
997+
return Err(error::const_io_error!(
998+
ErrorKind::UnexpectedEof,
999+
"failed to fill whole buffer"
1000+
));
9981001
}
9991002
}
10001003

library/std/src/panic.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::any::Any;
66
use crate::collections;
77
use crate::panicking;
8-
use crate::sync::atomic::{AtomicUsize, Ordering};
8+
use crate::sync::atomic::{AtomicU8, Ordering};
99
use crate::sync::{Mutex, RwLock};
1010
use crate::thread::Result;
1111

@@ -228,15 +228,15 @@ impl BacktraceStyle {
228228
if cfg!(feature = "backtrace") { Some(BacktraceStyle::Full) } else { None }
229229
}
230230

231-
fn as_usize(self) -> usize {
231+
fn as_u8(self) -> u8 {
232232
match self {
233233
BacktraceStyle::Short => 1,
234234
BacktraceStyle::Full => 2,
235235
BacktraceStyle::Off => 3,
236236
}
237237
}
238238

239-
fn from_usize(s: usize) -> Option<Self> {
239+
fn from_u8(s: u8) -> Option<Self> {
240240
Some(match s {
241241
0 => return None,
242242
1 => BacktraceStyle::Short,
@@ -251,7 +251,7 @@ impl BacktraceStyle {
251251
// that backtrace.
252252
//
253253
// Internally stores equivalent of an Option<BacktraceStyle>.
254-
static SHOULD_CAPTURE: AtomicUsize = AtomicUsize::new(0);
254+
static SHOULD_CAPTURE: AtomicU8 = AtomicU8::new(0);
255255

256256
/// Configure whether the default panic hook will capture and display a
257257
/// backtrace.
@@ -264,7 +264,7 @@ pub fn set_backtrace_style(style: BacktraceStyle) {
264264
// If the `backtrace` feature of this crate isn't enabled, skip setting.
265265
return;
266266
}
267-
SHOULD_CAPTURE.store(style.as_usize(), Ordering::Release);
267+
SHOULD_CAPTURE.store(style.as_u8(), Ordering::Release);
268268
}
269269

270270
/// Checks whether the standard library's panic hook will capture and print a
@@ -296,7 +296,7 @@ pub fn get_backtrace_style() -> Option<BacktraceStyle> {
296296
// to optimize away callers.
297297
return None;
298298
}
299-
if let Some(style) = BacktraceStyle::from_usize(SHOULD_CAPTURE.load(Ordering::Acquire)) {
299+
if let Some(style) = BacktraceStyle::from_u8(SHOULD_CAPTURE.load(Ordering::Acquire)) {
300300
return Some(style);
301301
}
302302

src/doc/rustc/src/platform-support/hexagon-unknown-none-elf.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ q6_arch=v65
128128
g0_lib_path=${sdk_libs}/${q6_arch}/G0
129129
pic_lib_path=${sdk_libs}/${q6_arch}/G0/pic
130130

131-
cargo build --target=hexagon-unknown-none-elf -Zbuild-std
131+
build_cfg=release
132+
cargo build --target=hexagon-unknown-none-elf -Zbuild-std --release
132133

133134
# Builds an executable against "hexagon standalone OS" suitable for emulation:
134135
${cc} --target=hexagon-unknown-none-elf -o testit \
@@ -142,12 +143,12 @@ ${cc} --target=hexagon-unknown-none-elf -o testit \
142143
-L${sdk_libs}/${q6_arch}/ \
143144
-L${sdk_libs}/ \
144145
testit.c \
145-
target/hexagon-unknown-none-elf/debug/libmin_ex_lib_lin.rlib \
146-
target/hexagon-unknown-none-elf/debug/deps/libcore-*.rlib \
147-
target/hexagon-unknown-none-elf/debug/deps/libcompiler_builtins-*.rlib \
146+
target/hexagon-unknown-none-elf/${build_cfg}/libdemo1_hexagon.rlib \
147+
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcore-*.rlib \
148+
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcompiler_builtins-*.rlib \
148149
-Wl,--start-group \
149150
-Wl,--defsym,_SDA_BASE_=0,--defsym,__sbss_start=0,--defsym,__sbss_end=0 \
150-
-lstandalone \
151+
${g0_lib_path}/libstandalone.a \
151152
${g0_lib_path}/libc.a \
152153
-lgcc \
153154
-lc_eh \
@@ -248,9 +249,9 @@ ${cc} --target=hexagon-unknown-none-elf -o testit.so \
248249
-Wl,--wrap=memalign \
249250
-m${q6_arch} \
250251
testit.c \
251-
target/hexagon-unknown-none-elf/debug/libmin_ex_lib_lin.rlib \
252-
target/hexagon-unknown-none-elf/debug/deps/libcore-*.rlib \
253-
target/hexagon-unknown-none-elf/debug/deps/libcompiler_builtins-*.rlib \
252+
target/hexagon-unknown-none-elf/${build_cfg}/libdemo2_hexagon.rlib \
253+
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcore-*.rlib \
254+
target/hexagon-unknown-none-elf/${build_cfg}/deps/libcompiler_builtins-*.rlib \
254255
-Wl,-soname=testit \
255256
${pic_lib_path}/libc.so
256257

tests/codegen/is_val_statically_known.rs

+38
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,41 @@ pub fn _bool_false(b: bool) -> i32 {
4646
// CHECK: ret i32 2
4747
_bool(b)
4848
}
49+
50+
#[inline]
51+
pub fn _iref(a: &u8) -> i32 {
52+
if unsafe { is_val_statically_known(a) } { 5 } else { 4 }
53+
}
54+
55+
// CHECK-LABEL: @_iref_borrow(
56+
#[no_mangle]
57+
pub fn _iref_borrow() -> i32 {
58+
// CHECK: ret i32 4
59+
_iref(&0)
60+
}
61+
62+
// CHECK-LABEL: @_iref_arg(
63+
#[no_mangle]
64+
pub fn _iref_arg(a: &u8) -> i32 {
65+
// CHECK: ret i32 4
66+
_iref(a)
67+
}
68+
69+
#[inline]
70+
pub fn _slice_ref(a: &[u8]) -> i32 {
71+
if unsafe { is_val_statically_known(a) } { 7 } else { 6 }
72+
}
73+
74+
// CHECK-LABEL: @_slice_ref_borrow(
75+
#[no_mangle]
76+
pub fn _slice_ref_borrow() -> i32 {
77+
// CHECK: ret i32 6
78+
_slice_ref(&[0;3])
79+
}
80+
81+
// CHECK-LABEL: @_slice_ref_arg(
82+
#[no_mangle]
83+
pub fn _slice_ref_arg(a: &[u8]) -> i32 {
84+
// CHECK: ret i32 6
85+
_slice_ref(a)
86+
}

tests/run-make/rust-lld-custom-target/custom-target.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"arch": "x86_64",
33
"cpu": "x86-64",
44
"crt-static-respected": true,
5-
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
5+
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
66
"dynamic-linking": true,
77
"env": "gnu",
88
"has-rpath": true,

0 commit comments

Comments
 (0)