Skip to content

Commit ad8f601

Browse files
committed
Auto merge of #115469 - matthiaskrgr:rollup-25ybx39, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #114349 (rustc_llvm: Link to `zlib` on dragonfly and solaris) - #114845 (Add alignment to the NPO guarantee) - #115427 (kmc-solid: Fix `is_interrupted`) - #115443 (feat(std): Stabilize 'os_str_bytes' feature) - #115444 (Create a SMIR visitor) - #115449 (Const-stabilize `is_ascii`) - #115456 (Add spastorino on vacation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1fb6947 + 6fca6a3 commit ad8f601

File tree

31 files changed

+335
-113
lines changed

31 files changed

+335
-113
lines changed

compiler/rustc_llvm/build.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ fn main() {
252252
} else if target.contains("windows-gnu") {
253253
println!("cargo:rustc-link-lib=shell32");
254254
println!("cargo:rustc-link-lib=uuid");
255-
} else if target.contains("haiku") || target.contains("darwin") {
255+
} else if target.contains("haiku")
256+
|| target.contains("darwin")
257+
|| (is_crossed && (target.contains("dragonfly") || target.contains("solaris")))
258+
{
256259
println!("cargo:rustc-link-lib=z");
257260
} else if target.contains("netbsd") {
258261
println!("cargo:rustc-link-lib=z");

compiler/rustc_smir/src/rustc_internal/mod.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
use std::fmt::Debug;
77
use std::ops::Index;
8-
use std::string::ToString;
98

109
use crate::rustc_internal;
1110
use crate::{
@@ -156,10 +155,23 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
156155
}
157156

158157
/// A type that provides internal information but that can still be used for debug purpose.
159-
pub type Opaque = impl Debug + ToString + Clone;
158+
#[derive(Clone)]
159+
pub struct Opaque(String);
160+
161+
impl std::fmt::Display for Opaque {
162+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
163+
write!(f, "{}", self.0)
164+
}
165+
}
166+
167+
impl std::fmt::Debug for Opaque {
168+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
169+
write!(f, "{:?}", self.0)
170+
}
171+
}
160172

161173
pub(crate) fn opaque<T: Debug>(value: &T) -> Opaque {
162-
format!("{value:?}")
174+
Opaque(format!("{value:?}"))
163175
}
164176

165177
pub struct StableMir {

compiler/rustc_smir/src/stable_mir/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::rustc_smir::Tables;
2020

2121
pub mod mir;
2222
pub mod ty;
23+
pub mod visitor;
2324

2425
/// Use String for now but we should replace it.
2526
pub type Symbol = String;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
use std::ops::ControlFlow;
2+
3+
use crate::rustc_internal::Opaque;
4+
5+
use super::ty::{
6+
Allocation, Binder, Const, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, GenericArgs,
7+
Promoted, RigidTy, TermKind, Ty, UnevaluatedConst,
8+
};
9+
10+
pub trait Visitor: Sized {
11+
type Break;
12+
fn visit_ty(&mut self, ty: &Ty) -> ControlFlow<Self::Break> {
13+
ty.super_visit(self)
14+
}
15+
fn visit_const(&mut self, c: &Const) -> ControlFlow<Self::Break> {
16+
c.super_visit(self)
17+
}
18+
}
19+
20+
pub trait Visitable {
21+
fn visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
22+
self.super_visit(visitor)
23+
}
24+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break>;
25+
}
26+
27+
impl Visitable for Ty {
28+
fn visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
29+
visitor.visit_ty(self)
30+
}
31+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
32+
match self.kind() {
33+
super::ty::TyKind::RigidTy(ty) => ty.visit(visitor),
34+
super::ty::TyKind::Alias(_, alias) => alias.args.visit(visitor),
35+
super::ty::TyKind::Param(_) => todo!(),
36+
super::ty::TyKind::Bound(_, _) => todo!(),
37+
}
38+
}
39+
}
40+
41+
impl Visitable for Const {
42+
fn visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
43+
visitor.visit_const(self)
44+
}
45+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
46+
match &self.literal {
47+
super::ty::ConstantKind::Allocated(alloc) => alloc.visit(visitor),
48+
super::ty::ConstantKind::Unevaluated(uv) => uv.visit(visitor),
49+
super::ty::ConstantKind::ParamCt(param) => param.visit(visitor),
50+
}
51+
}
52+
}
53+
54+
impl Visitable for Opaque {
55+
fn super_visit<V: Visitor>(&self, _visitor: &mut V) -> ControlFlow<V::Break> {
56+
ControlFlow::Continue(())
57+
}
58+
}
59+
60+
impl Visitable for Allocation {
61+
fn super_visit<V: Visitor>(&self, _visitor: &mut V) -> ControlFlow<V::Break> {
62+
ControlFlow::Continue(())
63+
}
64+
}
65+
66+
impl Visitable for UnevaluatedConst {
67+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
68+
let UnevaluatedConst { ty, def, args, promoted } = self;
69+
ty.visit(visitor)?;
70+
def.visit(visitor)?;
71+
args.visit(visitor)?;
72+
promoted.visit(visitor)
73+
}
74+
}
75+
76+
impl Visitable for ConstDef {
77+
fn super_visit<V: Visitor>(&self, _visitor: &mut V) -> ControlFlow<V::Break> {
78+
ControlFlow::Continue(())
79+
}
80+
}
81+
82+
impl<T: Visitable> Visitable for Option<T> {
83+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
84+
match self {
85+
Some(val) => val.visit(visitor),
86+
None => ControlFlow::Continue(()),
87+
}
88+
}
89+
}
90+
91+
impl Visitable for Promoted {
92+
fn super_visit<V: Visitor>(&self, _visitor: &mut V) -> ControlFlow<V::Break> {
93+
ControlFlow::Continue(())
94+
}
95+
}
96+
97+
impl Visitable for GenericArgs {
98+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
99+
self.0.visit(visitor)
100+
}
101+
}
102+
103+
impl Visitable for GenericArgKind {
104+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
105+
match self {
106+
GenericArgKind::Lifetime(lt) => lt.visit(visitor),
107+
GenericArgKind::Type(t) => t.visit(visitor),
108+
GenericArgKind::Const(c) => c.visit(visitor),
109+
}
110+
}
111+
}
112+
113+
impl Visitable for RigidTy {
114+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
115+
match self {
116+
RigidTy::Bool
117+
| RigidTy::Char
118+
| RigidTy::Int(_)
119+
| RigidTy::Uint(_)
120+
| RigidTy::Float(_)
121+
| RigidTy::Never
122+
| RigidTy::Foreign(_)
123+
| RigidTy::Str => ControlFlow::Continue(()),
124+
RigidTy::Array(t, c) => {
125+
t.visit(visitor)?;
126+
c.visit(visitor)
127+
}
128+
RigidTy::Slice(inner) => inner.visit(visitor),
129+
RigidTy::RawPtr(ty, _) => ty.visit(visitor),
130+
RigidTy::Ref(_, ty, _) => ty.visit(visitor),
131+
RigidTy::FnDef(_, args) => args.visit(visitor),
132+
RigidTy::FnPtr(sig) => sig.visit(visitor),
133+
RigidTy::Closure(_, args) => args.visit(visitor),
134+
RigidTy::Generator(_, args, _) => args.visit(visitor),
135+
RigidTy::Dynamic(pred, r, _) => {
136+
pred.visit(visitor)?;
137+
r.visit(visitor)
138+
}
139+
RigidTy::Tuple(fields) => fields.visit(visitor),
140+
RigidTy::Adt(_, args) => args.visit(visitor),
141+
}
142+
}
143+
}
144+
145+
impl<T: Visitable> Visitable for Vec<T> {
146+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
147+
for arg in self {
148+
arg.visit(visitor)?;
149+
}
150+
ControlFlow::Continue(())
151+
}
152+
}
153+
154+
impl<T: Visitable> Visitable for Binder<T> {
155+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
156+
self.value.visit(visitor)
157+
}
158+
}
159+
160+
impl Visitable for ExistentialPredicate {
161+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
162+
match self {
163+
ExistentialPredicate::Trait(tr) => tr.generic_args.visit(visitor),
164+
ExistentialPredicate::Projection(p) => {
165+
p.term.visit(visitor)?;
166+
p.generic_args.visit(visitor)
167+
}
168+
ExistentialPredicate::AutoTrait(_) => ControlFlow::Continue(()),
169+
}
170+
}
171+
}
172+
173+
impl Visitable for TermKind {
174+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
175+
match self {
176+
TermKind::Type(t) => t.visit(visitor),
177+
TermKind::Const(c) => c.visit(visitor),
178+
}
179+
}
180+
}
181+
182+
impl Visitable for FnSig {
183+
fn super_visit<V: Visitor>(&self, visitor: &mut V) -> ControlFlow<V::Break> {
184+
self.inputs_and_output.visit(visitor)
185+
}
186+
}

library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
#![feature(const_slice_from_raw_parts_mut)]
153153
#![feature(const_slice_from_ref)]
154154
#![feature(const_slice_index)]
155-
#![feature(const_slice_is_ascii)]
156155
#![feature(const_slice_ptr_len)]
157156
#![feature(const_slice_split_at_mut)]
158157
#![feature(const_str_from_utf8_unchecked_mut)]

library/core/src/num/nonzero.rs

+14
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ macro_rules! nonzero_integers {
4141
/// with the exception that `0` is not a valid instance.
4242
#[doc = concat!("`Option<", stringify!($Ty), ">` is guaranteed to be compatible with `", stringify!($Int), "`,")]
4343
/// including in FFI.
44+
///
45+
/// Thanks to the [null pointer optimization],
46+
#[doc = concat!("`", stringify!($Ty), "` and `Option<", stringify!($Ty), ">`")]
47+
/// are guaranteed to have the same size and alignment:
48+
///
49+
/// ```
50+
/// # use std::mem::{size_of, align_of};
51+
#[doc = concat!("use std::num::", stringify!($Ty), ";")]
52+
///
53+
#[doc = concat!("assert_eq!(size_of::<", stringify!($Ty), ">(), size_of::<Option<", stringify!($Ty), ">>());")]
54+
#[doc = concat!("assert_eq!(align_of::<", stringify!($Ty), ">(), align_of::<Option<", stringify!($Ty), ">>());")]
55+
/// ```
56+
///
57+
/// [null pointer optimization]: crate::option#representation
4458
#[$stability]
4559
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
4660
#[repr(transparent)]

library/core/src/option.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
//! # Representation
120120
//!
121121
//! Rust guarantees to optimize the following types `T` such that
122-
//! [`Option<T>`] has the same size as `T`:
122+
//! [`Option<T>`] has the same size and alignment as `T`:
123123
//!
124124
//! * [`Box<U>`]
125125
//! * `&U`

library/core/src/ptr/non_null.rs

+18
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,27 @@ use crate::slice::{self, SliceIndex};
4343
/// it is your responsibility to ensure that `as_mut` is never called, and `as_ptr`
4444
/// is never used for mutation.
4545
///
46+
/// # Representation
47+
///
48+
/// Thanks to the [null pointer optimization],
49+
/// `NonNull<T>` and `Option<NonNull<T>>`
50+
/// are guaranteed to have the same size and alignment:
51+
///
52+
/// ```
53+
/// # use std::mem::{size_of, align_of};
54+
/// use std::ptr::NonNull;
55+
///
56+
/// assert_eq!(size_of::<NonNull<i16>>(), size_of::<Option<NonNull<i16>>>());
57+
/// assert_eq!(align_of::<NonNull<i16>>(), align_of::<Option<NonNull<i16>>>());
58+
///
59+
/// assert_eq!(size_of::<NonNull<str>>(), size_of::<Option<NonNull<str>>>());
60+
/// assert_eq!(align_of::<NonNull<str>>(), align_of::<Option<NonNull<str>>>());
61+
/// ```
62+
///
4663
/// [covariant]: https://doc.rust-lang.org/reference/subtyping.html
4764
/// [`PhantomData`]: crate::marker::PhantomData
4865
/// [`UnsafeCell<T>`]: crate::cell::UnsafeCell
66+
/// [null pointer optimization]: crate::option#representation
4967
#[stable(feature = "nonnull", since = "1.25.0")]
5068
#[repr(transparent)]
5169
#[rustc_layout_scalar_valid_range_start(1)]

library/core/src/slice/ascii.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::ops;
1010
impl [u8] {
1111
/// Checks if all bytes in this slice are within the ASCII range.
1212
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
13-
#[rustc_const_unstable(feature = "const_slice_is_ascii", issue = "111090")]
13+
#[rustc_const_stable(feature = "const_slice_is_ascii", since = "CURRENT_RUSTC_VERSION")]
1414
#[must_use]
1515
#[inline]
1616
pub const fn is_ascii(&self) -> bool {

library/core/src/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@ impl str {
23222322
/// assert!(!non_ascii.is_ascii());
23232323
/// ```
23242324
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
2325-
#[rustc_const_unstable(feature = "const_slice_is_ascii", issue = "111090")]
2325+
#[rustc_const_stable(feature = "const_slice_is_ascii", since = "CURRENT_RUSTC_VERSION")]
23262326
#[must_use]
23272327
#[inline]
23282328
pub const fn is_ascii(&self) -> bool {

library/std/src/ffi/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@
132132
//! On all platforms, [`OsStr`] consists of a sequence of bytes that is encoded as a superset of
133133
//! UTF-8; see [`OsString`] for more details on its encoding on different platforms.
134134
//!
135-
//! For limited, inexpensive conversions from and to bytes, see [`OsStr::as_os_str_bytes`] and
136-
//! [`OsStr::from_os_str_bytes_unchecked`].
135+
//! For limited, inexpensive conversions from and to bytes, see [`OsStr::as_encoded_bytes`] and
136+
//! [`OsStr::from_encoded_bytes_unchecked`].
137137
//!
138138
//! [Unicode scalar value]: https://www.unicode.org/glossary/#unicode_scalar_value
139139
//! [Unicode code point]: https://www.unicode.org/glossary/#code_point

0 commit comments

Comments
 (0)