Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bde4a78

Browse files
committedNov 13, 2024·
Auto merge of rust-lang#132989 - GuillaumeGomez:rollup-p5jdno9, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - rust-lang#132709 (optimize char::to_digit and assert radix is at least 2) - rust-lang#132842 (ABI checks: add support for tier2 arches) - rust-lang#132965 (allow CFGuard on windows-gnullvm) - rust-lang#132967 (fix REGISTRY_USERNAME to reuse cache between auto and pr jobs) - rust-lang#132971 (Handle infer vars in anon consts on stable) - rust-lang#132979 (use `--exact` on `--skip` to avoid unintended substring matches) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 65b3877 + ea16a5e commit bde4a78

File tree

18 files changed

+253
-67
lines changed

18 files changed

+253
-67
lines changed
 

‎compiler/rustc_codegen_llvm/src/context.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,12 @@ pub(crate) unsafe fn create_module<'ll>(
274274
}
275275
}
276276

277-
// Control Flow Guard is currently only supported by the MSVC linker on Windows.
278-
if sess.target.is_like_msvc {
277+
// Control Flow Guard is currently only supported by MSVC and LLVM on Windows.
278+
if sess.target.is_like_msvc
279+
|| (sess.target.options.os == "windows"
280+
&& sess.target.options.env == "gnu"
281+
&& sess.target.options.abi == "llvm")
282+
{
279283
match sess.opts.cg.control_flow_guard {
280284
CFGuard::Disabled => {}
281285
CFGuard::NoChecks => {

‎compiler/rustc_middle/src/mir/consts.rs

+3
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ impl<'tcx> Const<'tcx> {
325325

326326
match c.kind() {
327327
ConstKind::Value(ty, val) => Ok(tcx.valtree_to_const_val((ty, val))),
328+
ConstKind::Expr(_) => {
329+
bug!("Normalization of `ty::ConstKind::Expr` is unimplemented")
330+
}
328331
_ => Err(tcx.dcx().delayed_bug("Unevaluated `ty::Const` in MIR body").into()),
329332
}
330333
}

‎compiler/rustc_monomorphize/messages.ftl

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
monomorphize_abi_error_disabled_vector_type_call =
2-
ABI error: this function call uses a vector type that requires the `{$required_feature}` target feature, which is not enabled in the caller
2+
this function call uses a SIMD vector type that (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled in the caller
33
.label = function called here
44
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
55
monomorphize_abi_error_disabled_vector_type_def =
6-
ABI error: this function definition uses a vector type that requires the `{$required_feature}` target feature, which is not enabled
6+
this function definition uses a SIMD vector type that (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled
77
.label = function defined here
88
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
99
10+
monomorphize_abi_error_unsupported_vector_type_call =
11+
this function call uses a SIMD vector type that is not currently supported with the chosen ABI
12+
.label = function called here
13+
monomorphize_abi_error_unsupported_vector_type_def =
14+
this function definition uses a SIMD vector type that is not currently supported with the chosen ABI
15+
.label = function defined here
16+
1017
monomorphize_couldnt_dump_mono_stats =
1118
unexpected error occurred while dumping monomorphization stats: {$error}
1219

‎compiler/rustc_monomorphize/src/errors.rs

+14
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,17 @@ pub(crate) struct AbiErrorDisabledVectorTypeCall<'a> {
110110
pub span: Span,
111111
pub required_feature: &'a str,
112112
}
113+
114+
#[derive(LintDiagnostic)]
115+
#[diag(monomorphize_abi_error_unsupported_vector_type_def)]
116+
pub(crate) struct AbiErrorUnsupportedVectorTypeDef {
117+
#[label]
118+
pub span: Span,
119+
}
120+
121+
#[derive(LintDiagnostic)]
122+
#[diag(monomorphize_abi_error_unsupported_vector_type_call)]
123+
pub(crate) struct AbiErrorUnsupportedVectorTypeCall {
124+
#[label]
125+
pub span: Span,
126+
}

‎compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

+41-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use rustc_span::{DUMMY_SP, Span, Symbol};
1010
use rustc_target::abi::call::{FnAbi, PassMode};
1111
use rustc_target::abi::{BackendRepr, RegKind};
1212

13-
use crate::errors::{AbiErrorDisabledVectorTypeCall, AbiErrorDisabledVectorTypeDef};
13+
use crate::errors::{
14+
AbiErrorDisabledVectorTypeCall, AbiErrorDisabledVectorTypeDef,
15+
AbiErrorUnsupportedVectorTypeCall, AbiErrorUnsupportedVectorTypeDef,
16+
};
1417

1518
fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
1619
match mode {
@@ -23,11 +26,15 @@ fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
2326
}
2427
}
2528

29+
/// Checks whether a certain function ABI is compatible with the target features currently enabled
30+
/// for a certain function.
31+
/// If not, `emit_err` is called, with `Some(feature)` if a certain feature should be enabled and
32+
/// with `None` if no feature is known that would make the ABI compatible.
2633
fn do_check_abi<'tcx>(
2734
tcx: TyCtxt<'tcx>,
2835
abi: &FnAbi<'tcx, Ty<'tcx>>,
2936
target_feature_def: DefId,
30-
mut emit_err: impl FnMut(&'static str),
37+
mut emit_err: impl FnMut(Option<&'static str>),
3138
) {
3239
let Some(feature_def) = tcx.sess.target.features_for_correct_vector_abi() else {
3340
return;
@@ -40,15 +47,15 @@ fn do_check_abi<'tcx>(
4047
let feature = match feature_def.iter().find(|(bits, _)| size.bits() <= *bits) {
4148
Some((_, feature)) => feature,
4249
None => {
43-
emit_err("<no available feature for this size>");
50+
emit_err(None);
4451
continue;
4552
}
4653
};
4754
let feature_sym = Symbol::intern(feature);
4855
if !tcx.sess.unstable_target_features.contains(&feature_sym)
4956
&& !codegen_attrs.target_features.iter().any(|x| x.name == feature_sym)
5057
{
51-
emit_err(feature);
58+
emit_err(Some(&feature));
5259
}
5360
}
5461
}
@@ -65,12 +72,21 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
6572
};
6673
do_check_abi(tcx, abi, instance.def_id(), |required_feature| {
6774
let span = tcx.def_span(instance.def_id());
68-
tcx.emit_node_span_lint(
69-
ABI_UNSUPPORTED_VECTOR_TYPES,
70-
CRATE_HIR_ID,
71-
span,
72-
AbiErrorDisabledVectorTypeDef { span, required_feature },
73-
);
75+
if let Some(required_feature) = required_feature {
76+
tcx.emit_node_span_lint(
77+
ABI_UNSUPPORTED_VECTOR_TYPES,
78+
CRATE_HIR_ID,
79+
span,
80+
AbiErrorDisabledVectorTypeDef { span, required_feature },
81+
);
82+
} else {
83+
tcx.emit_node_span_lint(
84+
ABI_UNSUPPORTED_VECTOR_TYPES,
85+
CRATE_HIR_ID,
86+
span,
87+
AbiErrorUnsupportedVectorTypeDef { span },
88+
);
89+
}
7490
})
7591
}
7692

@@ -109,12 +125,21 @@ fn check_call_site_abi<'tcx>(
109125
return;
110126
};
111127
do_check_abi(tcx, callee_abi, caller.def_id(), |required_feature| {
112-
tcx.emit_node_span_lint(
113-
ABI_UNSUPPORTED_VECTOR_TYPES,
114-
CRATE_HIR_ID,
115-
span,
116-
AbiErrorDisabledVectorTypeCall { span, required_feature },
117-
);
128+
if let Some(required_feature) = required_feature {
129+
tcx.emit_node_span_lint(
130+
ABI_UNSUPPORTED_VECTOR_TYPES,
131+
CRATE_HIR_ID,
132+
span,
133+
AbiErrorDisabledVectorTypeCall { span, required_feature },
134+
);
135+
} else {
136+
tcx.emit_node_span_lint(
137+
ABI_UNSUPPORTED_VECTOR_TYPES,
138+
CRATE_HIR_ID,
139+
span,
140+
AbiErrorUnsupportedVectorTypeCall { span },
141+
);
142+
}
118143
});
119144
}
120145

‎compiler/rustc_target/src/target_features.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,20 @@ pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
586586
// certain size to have their "proper" ABI on each architecture.
587587
// Note that they must be kept sorted by vector size.
588588
const X86_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] =
589-
&[(128, "sse"), (256, "avx"), (512, "avx512f")];
589+
&[(128, "sse"), (256, "avx"), (512, "avx512f")]; // FIXME: might need changes for AVX10.
590590
const AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "neon")];
591591

592+
// We might want to add "helium" too.
593+
const ARM_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "neon")];
594+
595+
const POWERPC_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "altivec")];
596+
const WASM_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "simd128")];
597+
const S390X_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "vector")];
598+
const RISCV_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] =
599+
&[/*(64, "zvl64b"), */ (128, "v")];
600+
// Always warn on SPARC, as the necessary target features cannot be enabled in Rust at the moment.
601+
const SPARC_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[/*(128, "vis")*/];
602+
592603
impl super::spec::Target {
593604
pub fn rust_target_features(&self) -> &'static [(&'static str, Stability, ImpliedFeatures)] {
594605
match &*self.arch {
@@ -613,8 +624,15 @@ impl super::spec::Target {
613624
pub fn features_for_correct_vector_abi(&self) -> Option<&'static [(u64, &'static str)]> {
614625
match &*self.arch {
615626
"x86" | "x86_64" => Some(X86_FEATURES_FOR_CORRECT_VECTOR_ABI),
616-
"aarch64" => Some(AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI),
617-
// FIXME: add support for non-tier1 architectures
627+
"aarch64" | "arm64ec" => Some(AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI),
628+
"arm" => Some(ARM_FEATURES_FOR_CORRECT_VECTOR_ABI),
629+
"powerpc" | "powerpc64" => Some(POWERPC_FEATURES_FOR_CORRECT_VECTOR_ABI),
630+
"loongarch64" => Some(&[]), // on-stack ABI, so we complain about all by-val vectors
631+
"riscv32" | "riscv64" => Some(RISCV_FEATURES_FOR_CORRECT_VECTOR_ABI),
632+
"wasm32" | "wasm64" => Some(WASM_FEATURES_FOR_CORRECT_VECTOR_ABI),
633+
"s390x" => Some(S390X_FEATURES_FOR_CORRECT_VECTOR_ABI),
634+
"sparc" | "sparc64" => Some(SPARC_FEATURES_FOR_CORRECT_VECTOR_ABI),
635+
// FIXME: add support for non-tier2 architectures
618636
_ => None,
619637
}
620638
}

‎compiler/rustc_trait_selection/src/traits/mod.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -578,16 +578,28 @@ pub fn try_evaluate_const<'tcx>(
578578
(args, param_env)
579579
}
580580
}
581-
} else {
582-
// FIXME: We don't check anything on stable as the only way we can wind up with
583-
// an unevaluated constant containing generic parameters is through array repeat
584-
// expression counts which have a future compat lint for usage of generic parameters
585-
// instead of a hard error.
581+
} else if tcx.def_kind(uv.def) == DefKind::AnonConst && uv.has_non_region_infer() {
582+
// FIXME: remove this when `const_evaluatable_unchecked` is a hard error.
583+
//
584+
// Diagnostics will sometimes replace the identity args of anon consts in
585+
// array repeat expr counts with inference variables so we have to handle this
586+
// even though it is not something we should ever actually encounter.
586587
//
587-
// This codepath is however also reachable by `generic_const_exprs` and some other
588-
// feature gates which allow constants in the type system to use generic parameters.
589-
// In theory we should be checking for generic parameters here and returning an error
590-
// in such cases.
588+
// Array repeat expr counts are allowed to syntactically use generic parameters
589+
// but must not actually depend on them in order to evalaute succesfully. This means
590+
// that it is actually fine to evalaute them in their own environment rather than with
591+
// the actually provided generic arguments.
592+
tcx.dcx().delayed_bug(
593+
"Encountered anon const with inference variable args but no error reported",
594+
);
595+
596+
let args = GenericArgs::identity_for_item(tcx, uv.def);
597+
let param_env = tcx.param_env(uv.def);
598+
(args, param_env)
599+
} else {
600+
// FIXME: This codepath is reachable under `associated_const_equality` and in the
601+
// future will be reachable by `min_generic_const_args`. We should handle inference
602+
// variables and generic parameters properly instead of doing nothing.
591603
(uv.args, param_env)
592604
};
593605
let uv = ty::UnevaluatedConst::new(uv.def, args);

‎library/core/src/char/methods.rs

+31-13
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl char {
301301
///
302302
/// # Panics
303303
///
304-
/// Panics if given a radix larger than 36.
304+
/// Panics if given a radix smaller than 2 or larger than 36.
305305
///
306306
/// # Examples
307307
///
@@ -319,6 +319,13 @@ impl char {
319319
/// // this panics
320320
/// '1'.is_digit(37);
321321
/// ```
322+
///
323+
/// Passing a small radix, causing a panic:
324+
///
325+
/// ```should_panic
326+
/// // this panics
327+
/// '1'.is_digit(1);
328+
/// ```
322329
#[stable(feature = "rust1", since = "1.0.0")]
323330
#[rustc_const_unstable(feature = "const_char_classify", issue = "132241")]
324331
#[inline]
@@ -345,7 +352,7 @@ impl char {
345352
///
346353
/// # Panics
347354
///
348-
/// Panics if given a radix larger than 36.
355+
/// Panics if given a radix smaller than 2 or larger than 36.
349356
///
350357
/// # Examples
351358
///
@@ -369,24 +376,35 @@ impl char {
369376
/// // this panics
370377
/// let _ = '1'.to_digit(37);
371378
/// ```
379+
/// Passing a small radix, causing a panic:
380+
///
381+
/// ```should_panic
382+
/// // this panics
383+
/// let _ = '1'.to_digit(1);
384+
/// ```
372385
#[stable(feature = "rust1", since = "1.0.0")]
373386
#[rustc_const_stable(feature = "const_char_convert", since = "1.67.0")]
374387
#[must_use = "this returns the result of the operation, \
375388
without modifying the original"]
376389
#[inline]
377390
pub const fn to_digit(self, radix: u32) -> Option<u32> {
378-
// If not a digit, a number greater than radix will be created.
379-
let mut digit = (self as u32).wrapping_sub('0' as u32);
380-
if radix > 10 {
381-
assert!(radix <= 36, "to_digit: radix is too high (maximum 36)");
382-
if digit < 10 {
383-
return Some(digit);
384-
}
385-
// Force the 6th bit to be set to ensure ascii is lower case.
386-
digit = (self as u32 | 0b10_0000).wrapping_sub('a' as u32).saturating_add(10);
387-
}
391+
assert!(
392+
radix >= 2 && radix <= 36,
393+
"to_digit: invalid radix -- radix must be in the range 2 to 36 inclusive"
394+
);
395+
// check radix to remove letter handling code when radix is a known constant
396+
let value = if self > '9' && radix > 10 {
397+
// convert ASCII letters to lowercase
398+
let lower = self as u32 | 0x20;
399+
// convert an ASCII letter to the corresponding value,
400+
// non-letters convert to values > 36
401+
lower.wrapping_sub('a' as u32) as u64 + 10
402+
} else {
403+
// convert digit to value, non-digits wrap to values > 36
404+
(self as u32).wrapping_sub('0' as u32) as u64
405+
};
388406
// FIXME(const-hack): once then_some is const fn, use it here
389-
if digit < radix { Some(digit) } else { None }
407+
if value < radix as u64 { Some(value as u32) } else { None }
390408
}
391409

392410
/// Returns an iterator that yields the hexadecimal Unicode escape of a

‎src/ci/docker/run.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
9696
docker --version
9797

9898
REGISTRY=ghcr.io
99-
REGISTRY_USERNAME=${GITHUB_REPOSITORY_OWNER:-rust-lang-ci}
99+
# Hardcode username to reuse cache between auto and pr jobs
100+
# FIXME: should be changed after move from rust-lang-ci
101+
REGISTRY_USERNAME=rust-lang-ci
100102
# Tag used to push the final Docker image, so that it can be pulled by e.g. rustup
101103
IMAGE_TAG=${REGISTRY}/${REGISTRY_USERNAME}/rust-ci:${cksum}
102104
# Tag used to cache the Docker build

‎src/ci/github-actions/jobs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ runners:
4848

4949
envs:
5050
env-x86_64-apple-tests: &env-x86_64-apple-tests
51-
SCRIPT: ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc
51+
SCRIPT: ./x.py --stage 2 test --skip tests/ui --skip tests/rustdoc -- --exact
5252
RUST_CONFIGURE_ARGS: --build=x86_64-apple-darwin --enable-sanitizers --enable-profiler --set rust.jemalloc
5353
RUSTC_RETRY_LINKER_ON_SEGFAULT: 1
5454
MACOSX_DEPLOYMENT_TARGET: 10.12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Regression test for #132955 checking that we handle anon consts with
2+
// inference variables in their generic arguments correctly.
3+
//
4+
// This arose via diagnostics where we would have some failing goal such
5+
// as `[u8; AnonConst<Self>]: PartialEq<Self::A>`, then as part of diagnostics
6+
// we would replace all generic parameters with inference vars which would yield
7+
// a self type of `[u8; AnonConst<?x>]` and then attempt to normalize `AnonConst<?x>`.
8+
9+
pub trait T {
10+
type A;
11+
const P: Self::A;
12+
13+
fn a() {
14+
[0u8; std::mem::size_of::<Self::A>()] == Self::P;
15+
//~^ ERROR: can't compare
16+
//~| ERROR: constant expression depends on a generic parameter
17+
//~| ERROR: constant expression depends on a generic parameter
18+
}
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: constant expression depends on a generic parameter
2+
--> $DIR/failing_goal_with_repeat_expr_anon_const.rs:14:15
3+
|
4+
LL | [0u8; std::mem::size_of::<Self::A>()] == Self::P;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this may fail depending on what value the parameter takes
8+
9+
error: constant expression depends on a generic parameter
10+
--> $DIR/failing_goal_with_repeat_expr_anon_const.rs:14:47
11+
|
12+
LL | [0u8; std::mem::size_of::<Self::A>()] == Self::P;
13+
| ^^
14+
|
15+
= note: this may fail depending on what value the parameter takes
16+
17+
error[E0277]: can't compare `[u8; std::mem::size_of::<Self::A>()]` with `<Self as T>::A`
18+
--> $DIR/failing_goal_with_repeat_expr_anon_const.rs:14:47
19+
|
20+
LL | [0u8; std::mem::size_of::<Self::A>()] == Self::P;
21+
| ^^ no implementation for `[u8; std::mem::size_of::<Self::A>()] == <Self as T>::A`
22+
|
23+
= help: the trait `PartialEq<<Self as T>::A>` is not implemented for `[u8; std::mem::size_of::<Self::A>()]`
24+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
25+
|
26+
LL | pub trait T where [u8; std::mem::size_of::<Self::A>()]: PartialEq<<Self as T>::A> {
27+
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28+
29+
error: aborting due to 3 previous errors
30+
31+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)
Please sign in to comment.