Auto merge of #123230 - matthiaskrgr:rollup-4twuzj4, r=matthiaskrgr

Rollup of 5 pull requests

Successful merges:

 - #121573 (unix_sigpipe: Add test for SIGPIPE disposition in child processes)
 - #123170 (Replace regions in const canonical vars' types with `'static` in next-solver canonicalizer)
 - #123200 (KCFI: Require -C panic=abort)
 - #123201 (Improve wording in std::any explanation)
 - #123224 (compiletest: print reason for failing to read tests)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2024-03-30 13:51:24 +00:00
commit 1852728224
20 changed files with 234 additions and 79 deletions

View File

@ -140,6 +140,10 @@ impl<'tcx> rustc_type_ir::new::Region<TyCtxt<'tcx>> for Region<'tcx> {
fn new_anon_bound(tcx: TyCtxt<'tcx>, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self {
Region::new_bound(tcx, debruijn, ty::BoundRegion { var, kind: ty::BoundRegionKind::BrAnon })
}
fn new_static(tcx: TyCtxt<'tcx>) -> Self {
tcx.lifetimes.re_static
}
}
/// Region utilities

View File

@ -296,10 +296,7 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
Region::new_anon_bound(self.interner(), self.binder_index, var)
}
fn fold_ty(&mut self, t: I::Ty) -> I::Ty
where
I::Ty: TypeSuperFoldable<I>,
{
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
let kind = match t.kind() {
ty::Infer(i) => match i {
ty::TyVar(vid) => {
@ -378,47 +375,48 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
Ty::new_anon_bound(self.interner(), self.binder_index, var)
}
fn fold_const(&mut self, c: I::Const) -> I::Const
where
I::Const: TypeSuperFoldable<I>,
{
fn fold_const(&mut self, c: I::Const) -> I::Const {
// We could canonicalize all consts with static types, but the only ones we
// *really* need to worry about are the ones that we end up putting into `CanonicalVarKind`
// since canonical vars can't reference other canonical vars.
let ty = c
.ty()
.fold_with(&mut RegionsToStatic { interner: self.interner(), binder: ty::INNERMOST });
let kind = match c.kind() {
ty::ConstKind::Infer(i) => {
// FIXME: we should fold the ty too eventually
match i {
ty::InferConst::Var(vid) => {
assert_eq!(
self.infcx.root_ct_var(vid),
vid,
"region vid should have been resolved fully before canonicalization"
);
assert_eq!(
self.infcx.probe_ct_var(vid),
None,
"region vid should have been resolved fully before canonicalization"
);
CanonicalVarKind::Const(self.infcx.universe_of_ct(vid).unwrap(), c.ty())
}
ty::InferConst::EffectVar(_) => CanonicalVarKind::Effect,
ty::InferConst::Fresh(_) => todo!(),
ty::ConstKind::Infer(i) => match i {
ty::InferConst::Var(vid) => {
assert_eq!(
self.infcx.root_ct_var(vid),
vid,
"region vid should have been resolved fully before canonicalization"
);
assert_eq!(
self.infcx.probe_ct_var(vid),
None,
"region vid should have been resolved fully before canonicalization"
);
CanonicalVarKind::Const(self.infcx.universe_of_ct(vid).unwrap(), ty)
}
}
ty::InferConst::EffectVar(_) => CanonicalVarKind::Effect,
ty::InferConst::Fresh(_) => todo!(),
},
ty::ConstKind::Placeholder(placeholder) => match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderConst(
PlaceholderLike::new(placeholder.universe(), self.variables.len().into()),
c.ty(),
ty,
),
CanonicalizeMode::Response { .. } => {
CanonicalVarKind::PlaceholderConst(placeholder, c.ty())
CanonicalVarKind::PlaceholderConst(placeholder, ty)
}
},
ty::ConstKind::Param(_) => match self.canonicalize_mode {
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderConst(
PlaceholderLike::new(ty::UniverseIndex::ROOT, self.variables.len().into()),
c.ty(),
ty,
),
CanonicalizeMode::Response { .. } => panic!("param ty in response: {c:?}"),
},
// FIXME: See comment above -- we could fold the region separately or something.
ty::ConstKind::Bound(_, _)
| ty::ConstKind::Unevaluated(_)
| ty::ConstKind::Value(_)
@ -435,6 +433,35 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
}),
);
Const::new_anon_bound(self.interner(), self.binder_index, var, c.ty())
Const::new_anon_bound(self.interner(), self.binder_index, var, ty)
}
}
struct RegionsToStatic<I> {
interner: I,
binder: ty::DebruijnIndex,
}
impl<I: Interner> TypeFolder<I> for RegionsToStatic<I> {
fn interner(&self) -> I {
self.interner
}
fn fold_binder<T>(&mut self, t: I::Binder<T>) -> I::Binder<T>
where
T: TypeFoldable<I>,
I::Binder<T>: TypeSuperFoldable<I>,
{
self.binder.shift_in(1);
let t = t.fold_with(self);
self.binder.shift_out(1);
t
}
fn fold_region(&mut self, r: I::Region) -> I::Region {
match r.kind() {
ty::ReBound(db, _) if self.binder > db => r,
_ => Region::new_static(self.interner()),
}
}
}

View File

@ -96,6 +96,8 @@ session_sanitizer_cfi_requires_lto = `-Zsanitizer=cfi` requires `-Clto` or `-Cli
session_sanitizer_cfi_requires_single_codegen_unit = `-Zsanitizer=cfi` with `-Clto` requires `-Ccodegen-units=1`
session_sanitizer_kcfi_requires_panic_abort = `-Z sanitizer=kcfi` requires `-C panic=abort`
session_sanitizer_not_supported = {$us} sanitizer is not supported for this target
session_sanitizers_not_supported = {$us} sanitizers are not supported for this target

View File

@ -145,6 +145,10 @@ pub(crate) struct SanitizerCfiGeneralizePointersRequiresCfi;
#[diag(session_sanitizer_cfi_normalize_integers_requires_cfi)]
pub(crate) struct SanitizerCfiNormalizeIntegersRequiresCfi;
#[derive(Diagnostic)]
#[diag(session_sanitizer_kcfi_requires_panic_abort)]
pub(crate) struct SanitizerKcfiRequiresPanicAbort;
#[derive(Diagnostic)]
#[diag(session_split_lto_unit_requires_lto)]
pub(crate) struct SplitLtoUnitRequiresLto;

View File

@ -1211,6 +1211,11 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
sess.dcx().emit_err(errors::SanitizerCfiRequiresLto);
}
// KCFI requires panic=abort
if sess.is_sanitizer_kcfi_enabled() && sess.panic_strategy() != PanicStrategy::Abort {
sess.dcx().emit_err(errors::SanitizerKcfiRequiresPanicAbort);
}
// LLVM CFI using rustc LTO requires a single codegen unit.
if sess.is_sanitizer_cfi_enabled()
&& sess.lto() == config::Lto::Fat

View File

@ -136,31 +136,21 @@ pub trait TypeFolder<I: Interner>: FallibleTypeFolder<I, Error = Never> {
t.super_fold_with(self)
}
fn fold_ty(&mut self, t: I::Ty) -> I::Ty
where
I::Ty: TypeSuperFoldable<I>,
{
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
t.super_fold_with(self)
}
// The default region folder is a no-op because `Region` is non-recursive
// and has no `super_fold_with` method to call. That also explains the
// lack of `I::Region: TypeSuperFoldable<I>` bound on this method.
// and has no `super_fold_with` method to call.
fn fold_region(&mut self, r: I::Region) -> I::Region {
r
}
fn fold_const(&mut self, c: I::Const) -> I::Const
where
I::Const: TypeSuperFoldable<I>,
{
fn fold_const(&mut self, c: I::Const) -> I::Const {
c.super_fold_with(self)
}
fn fold_predicate(&mut self, p: I::Predicate) -> I::Predicate
where
I::Predicate: TypeSuperFoldable<I>,
{
fn fold_predicate(&mut self, p: I::Predicate) -> I::Predicate {
p.super_fold_with(self)
}
}
@ -185,31 +175,21 @@ pub trait FallibleTypeFolder<I: Interner>: Sized {
t.try_super_fold_with(self)
}
fn try_fold_ty(&mut self, t: I::Ty) -> Result<I::Ty, Self::Error>
where
I::Ty: TypeSuperFoldable<I>,
{
fn try_fold_ty(&mut self, t: I::Ty) -> Result<I::Ty, Self::Error> {
t.try_super_fold_with(self)
}
// The default region folder is a no-op because `Region` is non-recursive
// and has no `super_fold_with` method to call. That also explains the
// lack of `I::Region: TypeSuperFoldable<I>` bound on this method.
// and has no `super_fold_with` method to call.
fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, Self::Error> {
Ok(r)
}
fn try_fold_const(&mut self, c: I::Const) -> Result<I::Const, Self::Error>
where
I::Const: TypeSuperFoldable<I>,
{
fn try_fold_const(&mut self, c: I::Const) -> Result<I::Const, Self::Error> {
c.try_super_fold_with(self)
}
fn try_fold_predicate(&mut self, p: I::Predicate) -> Result<I::Predicate, Self::Error>
where
I::Predicate: TypeSuperFoldable<I>,
{
fn try_fold_predicate(&mut self, p: I::Predicate) -> Result<I::Predicate, Self::Error> {
p.try_super_fold_with(self)
}
}
@ -234,10 +214,7 @@ where
Ok(self.fold_binder(t))
}
fn try_fold_ty(&mut self, t: I::Ty) -> Result<I::Ty, Never>
where
I::Ty: TypeSuperFoldable<I>,
{
fn try_fold_ty(&mut self, t: I::Ty) -> Result<I::Ty, Never> {
Ok(self.fold_ty(t))
}
@ -245,17 +222,11 @@ where
Ok(self.fold_region(r))
}
fn try_fold_const(&mut self, c: I::Const) -> Result<I::Const, Never>
where
I::Const: TypeSuperFoldable<I>,
{
fn try_fold_const(&mut self, c: I::Const) -> Result<I::Const, Never> {
Ok(self.fold_const(c))
}
fn try_fold_predicate(&mut self, p: I::Predicate) -> Result<I::Predicate, Never>
where
I::Predicate: TypeSuperFoldable<I>,
{
fn try_fold_predicate(&mut self, p: I::Predicate) -> Result<I::Predicate, Never> {
Ok(self.fold_predicate(p))
}
}

View File

@ -2,13 +2,14 @@ use smallvec::SmallVec;
use std::fmt::Debug;
use std::hash::Hash;
use crate::fold::TypeSuperFoldable;
use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable};
use crate::{
new, BoundVar, BoundVars, CanonicalVarInfo, ConstKind, DebugWithInfcx, RegionKind, TyKind,
UniverseIndex,
};
pub trait Interner: Sized {
pub trait Interner: Sized + Copy {
type DefId: Copy + Debug + Hash + Eq;
type AdtDef: Copy + Debug + Hash + Eq;
@ -34,6 +35,7 @@ pub trait Interner: Sized {
+ Into<Self::GenericArg>
+ IntoKind<Kind = TyKind<Self>>
+ TypeSuperVisitable<Self>
+ TypeSuperFoldable<Self>
+ Flags
+ new::Ty<Self>;
type Tys: Copy + Debug + Hash + Eq + IntoIterator<Item = Self::Ty>;
@ -57,6 +59,7 @@ pub trait Interner: Sized {
+ IntoKind<Kind = ConstKind<Self>>
+ ConstTy<Self>
+ TypeSuperVisitable<Self>
+ TypeSuperFoldable<Self>
+ Flags
+ new::Const<Self>;
type AliasConst: Copy + DebugWithInfcx<Self> + Hash + Eq;
@ -82,7 +85,13 @@ pub trait Interner: Sized {
type PlaceholderRegion: Copy + Debug + Hash + Eq + PlaceholderLike;
// Predicates
type Predicate: Copy + Debug + Hash + Eq + TypeSuperVisitable<Self> + Flags;
type Predicate: Copy
+ Debug
+ Hash
+ Eq
+ TypeSuperVisitable<Self>
+ TypeSuperFoldable<Self>
+ Flags;
type TraitPredicate: Copy + Debug + Hash + Eq;
type RegionOutlivesPredicate: Copy + Debug + Hash + Eq;
type TypeOutlivesPredicate: Copy + Debug + Hash + Eq;

View File

@ -6,6 +6,8 @@ pub trait Ty<I: Interner<Ty = Self>> {
pub trait Region<I: Interner<Region = Self>> {
fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar) -> Self;
fn new_static(interner: I) -> Self;
}
pub trait Const<I: Interner<Const = Self>> {

View File

@ -40,10 +40,10 @@
//!
//! ## Examples
//!
//! Consider a situation where we want to log out a value passed to a function.
//! We know the value we're working on implements Debug, but we don't know its
//! Consider a situation where we want to log a value passed to a function.
//! We know the value we're working on implements `Debug`, but we don't know its
//! concrete type. We want to give special treatment to certain types: in this
//! case printing out the length of String values prior to their value.
//! case printing out the length of `String` values prior to their value.
//! We don't know the concrete type of our value at compile time, so we need to
//! use runtime reflection instead.
//!
@ -51,7 +51,7 @@
//! use std::fmt::Debug;
//! use std::any::Any;
//!
//! // Logger function for any type that implements Debug.
//! // Logger function for any type that implements `Debug`.
//! fn log<T: Any + Debug>(value: &T) {
//! let value_any = value as &dyn Any;
//!

View File

@ -571,7 +571,9 @@ pub fn make_tests(
&modified_tests,
&mut poisoned,
)
.unwrap_or_else(|_| panic!("Could not read tests from {}", config.src_base.display()));
.unwrap_or_else(|reason| {
panic!("Could not read tests from {}: {reason}", config.src_base.display())
});
if poisoned {
eprintln!();

View File

@ -0,0 +1,34 @@
// It is UB to unwind out of `fn start()` according to
// https://doc.rust-lang.org/beta/unstable-book/language-features/start.html so
// panic with abort to avoid UB:
//@ compile-flags: -Cpanic=abort
//@ no-prefer-dynamic so panic=abort works
#![feature(start, rustc_private)]
extern crate libc;
// Use #[start] so we don't have a runtime that messes with SIGPIPE.
#[start]
fn start(argc: isize, argv: *const *const u8) -> isize {
assert_eq!(argc, 2, "Must pass SIG_IGN or SIG_DFL as first arg");
let arg1 = unsafe { std::ffi::CStr::from_ptr(*argv.offset(1) as *const libc::c_char) }
.to_str()
.unwrap();
let expected = match arg1 {
"SIG_IGN" => libc::SIG_IGN,
"SIG_DFL" => libc::SIG_DFL,
arg => panic!("Must pass SIG_IGN or SIG_DFL as first arg. Got: {}", arg),
};
let actual = unsafe {
let mut actual: libc::sigaction = std::mem::zeroed();
libc::sigaction(libc::SIGPIPE, std::ptr::null(), &mut actual);
actual.sa_sigaction
};
assert_eq!(actual, expected, "actual and expected SIGPIPE disposition in child differs");
0
}

View File

@ -0,0 +1,56 @@
//@ revisions: default sig_dfl sig_ign inherit
//@ ignore-cross-compile because aux-bin does not yet support it
//@ only-unix because SIGPIPE is a unix thing
//@ run-pass
//@ aux-bin:assert-sigpipe-disposition.rs
//@ aux-crate:sigpipe_utils=sigpipe-utils.rs
// Checks the signal disposition of `SIGPIPE` in child processes, and in our own
// process for robustness. Without any `unix_sigpipe` attribute, `SIG_IGN` is
// the default. But there is a difference in how `SIGPIPE` is treated in child
// processes with and without the attribute. Search for
// `unix_sigpipe_attr_specified()` in the code base to learn more.
#![feature(rustc_private)]
#![cfg_attr(any(sig_dfl, sig_ign, inherit), feature(unix_sigpipe))]
extern crate libc;
extern crate sigpipe_utils;
use sigpipe_utils::*;
#[cfg_attr(sig_dfl, unix_sigpipe = "sig_dfl")]
#[cfg_attr(sig_ign, unix_sigpipe = "sig_ign")]
#[cfg_attr(inherit, unix_sigpipe = "inherit")]
fn main() {
// By default we get SIG_IGN but the child gets SIG_DFL through an explicit
// reset before exec:
// https://github.com/rust-lang/rust/blob/bf4de3a874753bbee3323081c8b0c133444fed2d/library/std/src/sys/pal/unix/process/process_unix.rs#L363-L384
#[cfg(default)]
let (we_expect, child_expects) = (SignalHandler::Ignore, "SIG_DFL");
// With #[unix_sigpipe = "sig_dfl"] we get SIG_DFL and the child does too
// without any special code running before exec.
#[cfg(sig_dfl)]
let (we_expect, child_expects) = (SignalHandler::Default, "SIG_DFL");
// With #[unix_sigpipe = "sig_ign"] we get SIG_IGN and the child does too
// without any special code running before exec.
#[cfg(sig_ign)]
let (we_expect, child_expects) = (SignalHandler::Ignore, "SIG_IGN");
// With #[unix_sigpipe = "inherit"] we get SIG_DFL and the child does too
// without any special code running before exec.
#[cfg(inherit)]
let (we_expect, child_expects) = (SignalHandler::Default, "SIG_DFL");
assert_sigpipe_handler(we_expect);
assert!(
std::process::Command::new("./auxiliary/bin/assert-sigpipe-disposition")
.arg(child_expects)
.status()
.unwrap()
.success()
);
}

View File

@ -0,0 +1,23 @@
//@ check-pass
#![feature(adt_const_params)]
//~^ WARN the feature `adt_const_params` is incomplete
#![feature(with_negative_coherence, negative_impls)]
pub trait A<const K: &'static str> {}
pub trait C {}
struct W<T>(T);
// Negative coherence:
// Proving `W<!T>: !A<"">` requires proving `CONST alias-eq ""`, which requires proving
// `CONST normalizes-to (?1c: &str)`. The type's region is uniquified, so it ends up being
// put in to the canonical vars list with an infer region => ICE.
impl<T> C for T where T: A<""> {}
impl<T> C for W<T> {}
impl<T> !A<CONST> for W<T> {}
const CONST: &str = "";
fn main() {}

View File

@ -0,0 +1,11 @@
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/regions-in-canonical.rs:3:12
|
LL | #![feature(adt_const_params)]
| ^^^^^^^^^^^^^^^^
|
= note: see issue #95174 <https://github.com/rust-lang/rust/issues/95174> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted

View File

@ -1,4 +1,4 @@
//@ ignore-cross-compile because we run the compiled code
//@ ignore-cross-compile because aux-bin does not yet support it
//@ aux-bin: print-it-works.rs
//@ run-pass

View File

@ -11,6 +11,7 @@
//@[cfi]compile-flags: -Clto -Ccodegen-units=1
//@[kcfi]needs-llvm-components: x86
//@[kcfi]compile-flags: -Zsanitizer=kcfi --cfg kcfi --target x86_64-unknown-none
//@[kcfi]compile-flags: -C panic=abort
//@[leak]needs-sanitizer-leak
//@[leak]compile-flags: -Zsanitizer=leak --cfg leak
//@[memory]needs-sanitizer-memory

View File

@ -14,6 +14,7 @@
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
//@ [cfi] compile-flags: -Z sanitizer=cfi
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
//@ run-pass
pub fn main() {

View File

@ -11,6 +11,7 @@
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
//@ [cfi] compile-flags: -Z sanitizer=cfi
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
//@ run-pass
use std::sync::Arc;

View File

@ -9,6 +9,7 @@
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
//@ [cfi] compile-flags: -Z sanitizer=cfi
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
//@ run-pass
use std::marker::PhantomData;

View File

@ -9,6 +9,7 @@
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
//@ [cfi] compile-flags: -Z sanitizer=cfi
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
//@ run-pass
trait Foo {