Skip to content

Commit 8d2d001

Browse files
committed
Auto merge of #79167 - m-ou-se:rollup-4g15apk, r=m-ou-se
Rollup of 11 pull requests Successful merges: - #78361 (Updated the list of white-listed target features for x86) - #78785 (linux: try to use libc getrandom to allow interposition) - #78999 (stability: More precise location for deprecation lint on macros) - #79039 (Tighten the bounds on atomic Ordering in std::sys::unix::weak::Weak) - #79079 (Turn top-level comments into module docs in MIR visitor) - #79114 (add trailing_zeros and leading_zeros to non zero types) - #79131 (Enable AVX512 *epi64 variants by updating stdarch) - #79133 (bootstrap: use the same version number for rustc and cargo) - #79145 (Fix handling of panic calls) - #79151 (Fix typo in `std::io::Write` docs) - #79158 (type is too big -> values of the type are too big) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7d747db + 43d13e2 commit 8d2d001

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+549
-222
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+10
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,23 @@ pub fn time_trace_profiler_finish(file_name: &str) {
129129
// WARNING: the features after applying `to_llvm_feature` must be known
130130
// to LLVM or the feature detection code will walk past the end of the feature
131131
// array, leading to crashes.
132+
// To find a list of LLVM's names, check llvm-project/llvm/include/llvm/Support/*TargetParser.def
133+
// where the * matches the architecture's name
134+
// Beware to not use the llvm github project for this, but check the git submodule
135+
// found in src/llvm-project
136+
// Though note that Rust can also be build with an external precompiled version of LLVM
137+
// which might lead to failures if the oldest tested / supported LLVM version
138+
// doesn't yet support the relevant intrinsics
132139
pub fn to_llvm_feature<'a>(sess: &Session, s: &'a str) -> &'a str {
133140
let arch = if sess.target.arch == "x86_64" { "x86" } else { &*sess.target.arch };
134141
match (arch, s) {
135142
("x86", "pclmulqdq") => "pclmul",
136143
("x86", "rdrand") => "rdrnd",
137144
("x86", "bmi1") => "bmi",
138145
("x86", "cmpxchg16b") => "cx16",
146+
("x86", "avx512vaes") => "vaes",
147+
("x86", "avx512gfni") => "gfni",
148+
("x86", "avx512vpclmulqdq") => "vpclmulqdq",
139149
("aarch64", "fp") => "fp-armv8",
140150
("aarch64", "fp16") => "fullfp16",
141151
(_, s) => s,

compiler/rustc_codegen_ssa/src/target_features.rs

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ use rustc_session::Session;
44
use rustc_span::symbol::sym;
55
use rustc_span::symbol::Symbol;
66

7+
// When adding features to the below lists
8+
// check whether they're named already elsewhere in rust
9+
// e.g. in stdarch and whether the given name matches LLVM's
10+
// if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted
11+
712
const ARM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
813
("aclass", Some(sym::arm_target_feature)),
914
("mclass", Some(sym::arm_target_feature)),
@@ -50,15 +55,23 @@ const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
5055
("aes", None),
5156
("avx", None),
5257
("avx2", None),
58+
("avx512bf16", Some(sym::avx512_target_feature)),
59+
("avx512bitalg", Some(sym::avx512_target_feature)),
5360
("avx512bw", Some(sym::avx512_target_feature)),
5461
("avx512cd", Some(sym::avx512_target_feature)),
5562
("avx512dq", Some(sym::avx512_target_feature)),
5663
("avx512er", Some(sym::avx512_target_feature)),
5764
("avx512f", Some(sym::avx512_target_feature)),
65+
("avx512gfni", Some(sym::avx512_target_feature)),
5866
("avx512ifma", Some(sym::avx512_target_feature)),
5967
("avx512pf", Some(sym::avx512_target_feature)),
68+
("avx512vaes", Some(sym::avx512_target_feature)),
6069
("avx512vbmi", Some(sym::avx512_target_feature)),
70+
("avx512vbmi2", Some(sym::avx512_target_feature)),
6171
("avx512vl", Some(sym::avx512_target_feature)),
72+
("avx512vnni", Some(sym::avx512_target_feature)),
73+
("avx512vp2intersect", Some(sym::avx512_target_feature)),
74+
("avx512vpclmulqdq", Some(sym::avx512_target_feature)),
6275
("avx512vpopcntdq", Some(sym::avx512_target_feature)),
6376
("bmi1", None),
6477
("bmi2", None),

compiler/rustc_middle/src/middle/stability.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pub use self::StabilityLevel::*;
55

66
use crate::ty::{self, TyCtxt};
7-
use rustc_ast::CRATE_NODE_ID;
7+
use rustc_ast::NodeId;
88
use rustc_attr::{self as attr, ConstStability, Deprecation, Stability};
99
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010
use rustc_errors::{Applicability, DiagnosticBuilder};
@@ -211,13 +211,14 @@ pub fn early_report_deprecation(
211211
suggestion: Option<Symbol>,
212212
lint: &'static Lint,
213213
span: Span,
214+
node_id: NodeId,
214215
) {
215216
if span.in_derive_expansion() {
216217
return;
217218
}
218219

219220
let diag = BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span);
220-
lint_buffer.buffer_lint_with_diagnostic(lint, CRATE_NODE_ID, span, message, diag);
221+
lint_buffer.buffer_lint_with_diagnostic(lint, node_id, span, message, diag);
221222
}
222223

223224
fn late_report_deprecation(

compiler/rustc_middle/src/mir/visit.rs

+62-62
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
1+
//! # The MIR Visitor
2+
//!
3+
//! ## Overview
4+
//!
5+
//! There are two visitors, one for immutable and one for mutable references,
6+
//! but both are generated by the following macro. The code is written according
7+
//! to the following conventions:
8+
//!
9+
//! - introduce a `visit_foo` and a `super_foo` method for every MIR type
10+
//! - `visit_foo`, by default, calls `super_foo`
11+
//! - `super_foo`, by default, destructures the `foo` and calls `visit_foo`
12+
//!
13+
//! This allows you as a user to override `visit_foo` for types are
14+
//! interested in, and invoke (within that method) call
15+
//! `self.super_foo` to get the default behavior. Just as in an OO
16+
//! language, you should never call `super` methods ordinarily except
17+
//! in that circumstance.
18+
//!
19+
//! For the most part, we do not destructure things external to the
20+
//! MIR, e.g., types, spans, etc, but simply visit them and stop. This
21+
//! avoids duplication with other visitors like `TypeFoldable`.
22+
//!
23+
//! ## Updating
24+
//!
25+
//! The code is written in a very deliberate style intended to minimize
26+
//! the chance of things being overlooked. You'll notice that we always
27+
//! use pattern matching to reference fields and we ensure that all
28+
//! matches are exhaustive.
29+
//!
30+
//! For example, the `super_basic_block_data` method begins like this:
31+
//!
32+
//! ```rust
33+
//! fn super_basic_block_data(&mut self,
34+
//! block: BasicBlock,
35+
//! data: & $($mutability)? BasicBlockData<'tcx>) {
36+
//! let BasicBlockData {
37+
//! statements,
38+
//! terminator,
39+
//! is_cleanup: _
40+
//! } = *data;
41+
//!
42+
//! for statement in statements {
43+
//! self.visit_statement(block, statement);
44+
//! }
45+
//!
46+
//! ...
47+
//! }
48+
//! ```
49+
//!
50+
//! Here we used `let BasicBlockData { <fields> } = *data` deliberately,
51+
//! rather than writing `data.statements` in the body. This is because if one
52+
//! adds a new field to `BasicBlockData`, one will be forced to revise this code,
53+
//! and hence one will (hopefully) invoke the correct visit methods (if any).
54+
//!
55+
//! For this to work, ALL MATCHES MUST BE EXHAUSTIVE IN FIELDS AND VARIANTS.
56+
//! That means you never write `..` to skip over fields, nor do you write `_`
57+
//! to skip over variants in a `match`.
58+
//!
59+
//! The only place that `_` is acceptable is to match a field (or
60+
//! variant argument) that does not require visiting, as in
61+
//! `is_cleanup` above.
62+
163
use crate::mir::*;
264
use crate::ty::subst::SubstsRef;
365
use crate::ty::{CanonicalUserTypeAnnotation, Ty};
466
use rustc_span::Span;
567

6-
// # The MIR Visitor
7-
//
8-
// ## Overview
9-
//
10-
// There are two visitors, one for immutable and one for mutable references,
11-
// but both are generated by the following macro. The code is written according
12-
// to the following conventions:
13-
//
14-
// - introduce a `visit_foo` and a `super_foo` method for every MIR type
15-
// - `visit_foo`, by default, calls `super_foo`
16-
// - `super_foo`, by default, destructures the `foo` and calls `visit_foo`
17-
//
18-
// This allows you as a user to override `visit_foo` for types are
19-
// interested in, and invoke (within that method) call
20-
// `self.super_foo` to get the default behavior. Just as in an OO
21-
// language, you should never call `super` methods ordinarily except
22-
// in that circumstance.
23-
//
24-
// For the most part, we do not destructure things external to the
25-
// MIR, e.g., types, spans, etc, but simply visit them and stop. This
26-
// avoids duplication with other visitors like `TypeFoldable`.
27-
//
28-
// ## Updating
29-
//
30-
// The code is written in a very deliberate style intended to minimize
31-
// the chance of things being overlooked. You'll notice that we always
32-
// use pattern matching to reference fields and we ensure that all
33-
// matches are exhaustive.
34-
//
35-
// For example, the `super_basic_block_data` method begins like this:
36-
//
37-
// ```rust
38-
// fn super_basic_block_data(&mut self,
39-
// block: BasicBlock,
40-
// data: & $($mutability)? BasicBlockData<'tcx>) {
41-
// let BasicBlockData {
42-
// statements,
43-
// terminator,
44-
// is_cleanup: _
45-
// } = *data;
46-
//
47-
// for statement in statements {
48-
// self.visit_statement(block, statement);
49-
// }
50-
//
51-
// ...
52-
// }
53-
// ```
54-
//
55-
// Here we used `let BasicBlockData { <fields> } = *data` deliberately,
56-
// rather than writing `data.statements` in the body. This is because if one
57-
// adds a new field to `BasicBlockData`, one will be forced to revise this code,
58-
// and hence one will (hopefully) invoke the correct visit methods (if any).
59-
//
60-
// For this to work, ALL MATCHES MUST BE EXHAUSTIVE IN FIELDS AND VARIANTS.
61-
// That means you never write `..` to skip over fields, nor do you write `_`
62-
// to skip over variants in a `match`.
63-
//
64-
// The only place that `_` is acceptable is to match a field (or
65-
// variant argument) that does not require visiting, as in
66-
// `is_cleanup` above.
67-
6868
macro_rules! make_mir_visitor {
6969
($visitor_trait_name:ident, $($mutability:ident)?) => {
7070
pub trait $visitor_trait_name<'tcx> {

compiler/rustc_middle/src/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
176176
match *self {
177177
LayoutError::Unknown(ty) => write!(f, "the type `{}` has an unknown layout", ty),
178178
LayoutError::SizeOverflow(ty) => {
179-
write!(f, "the type `{}` is too big for the current architecture", ty)
179+
write!(f, "values of the type `{}` are too big for the current architecture", ty)
180180
}
181181
}
182182
}

compiler/rustc_resolve/src/macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,7 @@ impl<'a> Resolver<'a> {
10341034
depr.suggestion,
10351035
lint,
10361036
span,
1037+
node_id,
10371038
);
10381039
}
10391040
}

compiler/rustc_trait_selection/src/traits/query/normalize.rs

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
9797
self.infcx.tcx
9898
}
9999

100+
#[instrument(skip(self))]
100101
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
101102
if !ty.has_projections() {
102103
return ty;

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#![feature(const_mut_refs)]
8181
#![feature(const_int_pow)]
8282
#![feature(constctlz)]
83+
#![feature(const_cttz)]
8384
#![feature(const_panic)]
8485
#![feature(const_pin)]
8586
#![feature(const_fn)]

library/core/src/num/nonzero.rs

+74
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::str::FromStr;
66

77
use super::from_str_radix;
88
use super::{IntErrorKind, ParseIntError};
9+
use crate::intrinsics;
910

1011
macro_rules! doc_comment {
1112
($x:expr, $($tt:tt)*) => {
@@ -189,3 +190,76 @@ macro_rules! from_str_radix_nzint_impl {
189190

190191
from_str_radix_nzint_impl! { NonZeroU8 NonZeroU16 NonZeroU32 NonZeroU64 NonZeroU128 NonZeroUsize
191192
NonZeroI8 NonZeroI16 NonZeroI32 NonZeroI64 NonZeroI128 NonZeroIsize }
193+
194+
macro_rules! nonzero_leading_trailing_zeros {
195+
( $( $Ty: ident($Uint: ty) , $LeadingTestExpr:expr ;)+ ) => {
196+
$(
197+
impl $Ty {
198+
doc_comment! {
199+
concat!("Returns the number of leading zeros in the binary representation of `self`.
200+
201+
On many architectures, this function can perform better than `leading_zeros()` on the underlying integer type, as special handling of zero can be avoided.
202+
203+
# Examples
204+
205+
Basic usage:
206+
207+
```
208+
#![feature(nonzero_leading_trailing_zeros)]
209+
let n = std::num::", stringify!($Ty), "::new(", stringify!($LeadingTestExpr), ").unwrap();
210+
211+
assert_eq!(n.leading_zeros(), 0);
212+
```"),
213+
#[unstable(feature = "nonzero_leading_trailing_zeros", issue = "79143")]
214+
#[rustc_const_unstable(feature = "nonzero_leading_trailing_zeros", issue = "79143")]
215+
#[inline]
216+
pub const fn leading_zeros(self) -> u32 {
217+
// SAFETY: since `self` can not be zero it is safe to call ctlz_nonzero
218+
unsafe { intrinsics::ctlz_nonzero(self.0 as $Uint) as u32 }
219+
}
220+
}
221+
222+
doc_comment! {
223+
concat!("Returns the number of trailing zeros in the binary representation
224+
of `self`.
225+
226+
On many architectures, this function can perform better than `trailing_zeros()` on the underlying integer type, as special handling of zero can be avoided.
227+
228+
# Examples
229+
230+
Basic usage:
231+
232+
```
233+
#![feature(nonzero_leading_trailing_zeros)]
234+
let n = std::num::", stringify!($Ty), "::new(0b0101000).unwrap();
235+
236+
assert_eq!(n.trailing_zeros(), 3);
237+
```"),
238+
#[unstable(feature = "nonzero_leading_trailing_zeros", issue = "79143")]
239+
#[rustc_const_unstable(feature = "nonzero_leading_trailing_zeros", issue = "79143")]
240+
#[inline]
241+
pub const fn trailing_zeros(self) -> u32 {
242+
// SAFETY: since `self` can not be zero it is safe to call cttz_nonzero
243+
unsafe { intrinsics::cttz_nonzero(self.0 as $Uint) as u32 }
244+
}
245+
}
246+
247+
}
248+
)+
249+
}
250+
}
251+
252+
nonzero_leading_trailing_zeros! {
253+
NonZeroU8(u8), u8::MAX;
254+
NonZeroU16(u16), u16::MAX;
255+
NonZeroU32(u32), u32::MAX;
256+
NonZeroU64(u64), u64::MAX;
257+
NonZeroU128(u128), u128::MAX;
258+
NonZeroUsize(usize), usize::MAX;
259+
NonZeroI8(u8), -1i8;
260+
NonZeroI16(u16), -1i16;
261+
NonZeroI32(u32), -1i32;
262+
NonZeroI64(u64), -1i64;
263+
NonZeroI128(u128), -1i128;
264+
NonZeroIsize(usize), -1isize;
265+
}

library/core/tests/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
#![feature(once_cell)]
6161
#![feature(unsafe_block_in_unsafe_fn)]
6262
#![feature(int_bits_const)]
63+
#![feature(nonzero_leading_trailing_zeros)]
64+
#![feature(const_option)]
6365
#![deny(unsafe_op_in_unsafe_fn)]
6466

6567
extern crate test;

0 commit comments

Comments
 (0)