Skip to content

Commit e347318

Browse files
committed
Auto merge of #155170 - JonathanBrouwer:rollup-9OwCjU5, r=<try>
Rollup of 4 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1
2 parents bf4fbfb + 22eb361 commit e347318

72 files changed

Lines changed: 1020 additions & 247 deletions

File tree

Some content is hidden

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

compiler/rustc_abi/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ use rustc_hashes::Hash64;
5252
use rustc_index::{Idx, IndexSlice, IndexVec};
5353
#[cfg(feature = "nightly")]
5454
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_Generic};
55+
#[cfg(feature = "nightly")]
56+
use rustc_span::{Symbol, sym};
5557

5658
mod callconv;
5759
mod canon_abi;
@@ -770,6 +772,14 @@ impl Endian {
770772
Self::Big => "big",
771773
}
772774
}
775+
776+
#[cfg(feature = "nightly")]
777+
pub fn desc_symbol(&self) -> Symbol {
778+
match self {
779+
Self::Little => sym::little,
780+
Self::Big => sym::big,
781+
}
782+
}
773783
}
774784

775785
impl fmt::Debug for Endian {

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const GATED_CFGS: &[GatedCfg] = &[
6262
sym::cfg_target_has_reliable_f16_f128,
6363
Features::cfg_target_has_reliable_f16_f128,
6464
),
65+
(sym::target_object_format, sym::cfg_target_object_format, Features::cfg_target_object_format),
6566
];
6667

6768
/// Find a gated cfg determined by the `pred`icate which is given the cfg's name.

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ declare_features! (
410410
(unstable, cfg_target_has_atomic, "1.60.0", Some(94039)),
411411
/// Allows `cfg(target_has_atomic_equal_alignment = "...")`.
412412
(unstable, cfg_target_has_atomic_equal_alignment, "1.60.0", Some(93822)),
413+
/// Allows `cfg(target_object_format = "...")`.
414+
(unstable, cfg_target_object_format, "CURRENT_RUSTC_VERSION", Some(152586)),
413415
/// Allows `cfg(target_thread_local)`.
414416
(unstable, cfg_target_thread_local, "1.7.0", Some(29594)),
415417
/// Allows the use of `#[cfg(ub_checks)` to check if UB checks are enabled.

compiler/rustc_session/src/config/cfg.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ pub(crate) fn disallow_cfgs(sess: &Session, user_cfgs: &Cfg) {
144144
| (sym::target_endian, Some(_))
145145
| (sym::target_env, None | Some(_))
146146
| (sym::target_family, Some(_))
147+
| (sym::target_object_format, Some(_))
147148
| (sym::target_os, Some(_))
148149
| (sym::target_pointer_width, Some(_))
149150
| (sym::target_vendor, None | Some(_))
@@ -252,8 +253,9 @@ pub(crate) fn default_configuration(sess: &Session) -> Cfg {
252253

253254
ins_sym!(sym::target_abi, sess.target.cfg_abi.desc_symbol());
254255
ins_sym!(sym::target_arch, sess.target.arch.desc_symbol());
255-
ins_str!(sym::target_endian, sess.target.endian.as_str());
256+
ins_sym!(sym::target_endian, sess.target.endian.desc_symbol());
256257
ins_sym!(sym::target_env, sess.target.env.desc_symbol());
258+
ins_sym!(sym::target_object_format, sess.target.options.binary_format.desc_symbol());
257259

258260
for family in sess.target.families.as_ref() {
259261
ins_str!(sym::target_family, family);
@@ -420,12 +422,13 @@ impl CheckCfg {
420422

421423
// sym::target_*
422424
{
423-
const VALUES: [&Symbol; 8] = [
425+
const VALUES: [&Symbol; 9] = [
424426
&sym::target_abi,
425427
&sym::target_arch,
426428
&sym::target_endian,
427429
&sym::target_env,
428430
&sym::target_family,
431+
&sym::target_object_format,
429432
&sym::target_os,
430433
&sym::target_pointer_width,
431434
&sym::target_vendor,
@@ -449,6 +452,7 @@ impl CheckCfg {
449452
Some(values_target_endian),
450453
Some(values_target_env),
451454
Some(values_target_family),
455+
Some(values_target_object_format),
452456
Some(values_target_os),
453457
Some(values_target_pointer_width),
454458
Some(values_target_vendor),
@@ -460,11 +464,12 @@ impl CheckCfg {
460464
for target in Target::builtins().chain(iter::once(current_target.clone())) {
461465
values_target_abi.insert(target.options.cfg_abi.desc_symbol());
462466
values_target_arch.insert(target.arch.desc_symbol());
463-
values_target_endian.insert(Symbol::intern(target.options.endian.as_str()));
467+
values_target_endian.insert(target.options.endian.desc_symbol());
464468
values_target_env.insert(target.options.env.desc_symbol());
465469
values_target_family.extend(
466470
target.options.families.iter().map(|family| Symbol::intern(family)),
467471
);
472+
values_target_object_format.insert(target.options.binary_format.desc_symbol());
468473
values_target_os.insert(target.options.os.desc_symbol());
469474
values_target_pointer_width.insert(sym::integer(target.pointer_width));
470475
values_target_vendor.insert(target.vendor_symbol());

compiler/rustc_span/src/symbol.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ symbols! {
589589
cfg_target_has_atomic,
590590
cfg_target_has_atomic_equal_alignment,
591591
cfg_target_has_reliable_f16_f128,
592+
cfg_target_object_format,
592593
cfg_target_thread_local,
593594
cfg_target_vendor,
594595
cfg_trace: "<cfg_trace>", // must not be a valid identifier
@@ -623,6 +624,7 @@ symbols! {
623624
coerce_pointee_validated,
624625
coerce_shared,
625626
coerce_unsized,
627+
coff,
626628
cold,
627629
cold_path,
628630
collapse_debuginfo,
@@ -853,6 +855,7 @@ symbols! {
853855
eii_internals,
854856
eii_shared_macro,
855857
element_ty,
858+
elf,
856859
// Notes about `sym::empty`:
857860
// - It should only be used when it genuinely means "empty symbol". Use
858861
// `Option<Symbol>` when "no symbol" is a possibility.
@@ -1167,6 +1170,7 @@ symbols! {
11671170
linkonce_odr,
11681171
lint_reasons,
11691172
literal,
1173+
little, big,
11701174
load,
11711175
loaded_from_disk,
11721176
local,
@@ -1193,6 +1197,7 @@ symbols! {
11931197
lt,
11941198
m68k,
11951199
m68k_target_feature,
1200+
macho: "mach-o",
11961201
macro_at_most_once_rep,
11971202
macro_attr,
11981203
macro_attributes_in_derive_output,
@@ -2014,6 +2019,7 @@ symbols! {
20142019
target_has_reliable_f16_math,
20152020
target_has_reliable_f128,
20162021
target_has_reliable_f128_math,
2022+
target_object_format,
20172023
target_os,
20182024
target_pointer_width,
20192025
target_thread_local,
@@ -2237,6 +2243,7 @@ symbols! {
22372243
vtable_size,
22382244
warn,
22392245
wasip2,
2246+
wasm,
22402247
wasm32,
22412248
wasm64,
22422249
wasm_abi,
@@ -2271,6 +2278,7 @@ symbols! {
22712278
x86_amx_intrinsics,
22722279
x87_reg,
22732280
x87_target_feature,
2281+
xcoff,
22742282
xer,
22752283
xmm_reg,
22762284
xop_target_feature,

compiler/rustc_target/src/spec/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,16 @@ impl BinaryFormat {
13951395
Self::Xcoff => object::BinaryFormat::Xcoff,
13961396
}
13971397
}
1398+
1399+
pub fn desc_symbol(&self) -> Symbol {
1400+
match self {
1401+
Self::Coff => sym::coff,
1402+
Self::Elf => sym::elf,
1403+
Self::MachO => sym::macho,
1404+
Self::Wasm => sym::wasm,
1405+
Self::Xcoff => sym::xcoff,
1406+
}
1407+
}
13981408
}
13991409

14001410
impl ToJson for Align {

library/core/src/mem/mod.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
use crate::alloc::Layout;
3434
use crate::clone::TrivialClone;
35+
use crate::cmp::Ordering;
3536
use crate::marker::{Destruct, DiscriminantKind};
3637
use crate::panic::const_assert;
3738
use crate::{clone, cmp, fmt, hash, intrinsics, ptr};
@@ -1088,6 +1089,102 @@ pub const unsafe fn transmute_copy<Src, Dst>(src: &Src) -> Dst {
10881089
}
10891090
}
10901091

1092+
/// Like [`transmute`], but only initializes the "common prefix" of the first
1093+
/// `min(size_of::<Src>(), size_of::<Dst>())` bytes of the destination from the
1094+
/// corresponding bytes of the source.
1095+
///
1096+
/// This is equivalent to a "union cast" through a `union` with `#[repr(C)]`.
1097+
///
1098+
/// That means some size mismatches are not UB, like `[T; 2]` to `[T; 1]`.
1099+
/// Increasing size is usually UB from being insufficiently initialized -- like
1100+
/// `u8` to `u32` -- but isn't always. For example, going from `u8` to
1101+
/// `#[repr(C, align(4))] AlignedU8(u8);` is sound.
1102+
///
1103+
/// Prefer normal `transmute` where possible, for the extra checking, since
1104+
/// both do exactly the same thing at runtime, if they both compile.
1105+
///
1106+
/// # Safety
1107+
///
1108+
/// If `size_of::<Src>() >= size_of::<Dst>()`, the first `size_of::<Dst>()` bytes
1109+
/// of `src` must be be *valid* when interpreted as a `Dst`. (In this case, the
1110+
/// preconditions are the same as for `transmute_copy(&ManuallyDrop::new(src))`.)
1111+
///
1112+
/// If `size_of::<Src>() <= size_of::<Dst>()`, the bytes of `src` padded with
1113+
/// uninitialized bytes afterwards up to a total size of `size_of::<Dst>()`
1114+
/// must be *valid* when interpreted as a `Dst`.
1115+
///
1116+
/// In both cases, any safety preconditions of the `Dst` type must also be upheld.
1117+
///
1118+
/// # Examples
1119+
///
1120+
/// ```
1121+
/// #![feature(transmute_prefix)]
1122+
/// use std::mem::transmute_prefix;
1123+
///
1124+
/// assert_eq!(unsafe { transmute_prefix::<[i32; 4], [i32; 2]>([1, 2, 3, 4]) }, [1, 2]);
1125+
///
1126+
/// let expected = if cfg!(target_endian = "little") { 0x34 } else { 0x12 };
1127+
/// assert_eq!(unsafe { transmute_prefix::<u16, u8>(0x1234) }, expected);
1128+
///
1129+
/// // Would be UB because the destination is incompletely initialized.
1130+
/// // transmute_prefix::<u8, u16>(123)
1131+
///
1132+
/// // OK because the destination is allowed to be partially initialized.
1133+
/// let _: std::mem::MaybeUninit<u16> = unsafe { transmute_prefix(123_u8) };
1134+
/// ```
1135+
#[unstable(feature = "transmute_prefix", issue = "155079")]
1136+
pub const unsafe fn transmute_prefix<Src, Dst>(src: Src) -> Dst {
1137+
#[repr(C)]
1138+
union Transmute<A, B> {
1139+
a: ManuallyDrop<A>,
1140+
b: ManuallyDrop<B>,
1141+
}
1142+
1143+
match const { Ord::cmp(&Src::SIZE, &Dst::SIZE) } {
1144+
// SAFETY: When Dst is bigger, the union is the size of Dst
1145+
Ordering::Less => unsafe {
1146+
let a = transmute_neo(src);
1147+
intrinsics::transmute_unchecked(Transmute::<Src, Dst> { a })
1148+
},
1149+
// SAFETY: When they're the same size, we can use the MIR primitive
1150+
Ordering::Equal => unsafe { intrinsics::transmute_unchecked::<Src, Dst>(src) },
1151+
// SAFETY: When Src is bigger, the union is the size of Src
1152+
Ordering::Greater => unsafe {
1153+
let u: Transmute<Src, Dst> = intrinsics::transmute_unchecked(src);
1154+
transmute_neo(u.b)
1155+
},
1156+
}
1157+
}
1158+
1159+
/// New version of `transmute`, exposed under this name so it can be iterated upon
1160+
/// without risking breakage to uses of "real" transmute.
1161+
///
1162+
/// It will not be stabilized under this name.
1163+
///
1164+
/// # Examples
1165+
///
1166+
/// ```
1167+
/// #![feature(transmute_neo)]
1168+
/// use std::mem::transmute_neo;
1169+
///
1170+
/// assert_eq!(unsafe { transmute_neo::<f32, u32>(0.0) }, 0);
1171+
/// ```
1172+
///
1173+
/// ```compile_fail,E0080
1174+
/// #![feature(transmute_neo)]
1175+
/// use std::mem::transmute_neo;
1176+
///
1177+
/// unsafe { transmute_neo::<u32, u16>(123) };
1178+
/// ```
1179+
#[unstable(feature = "transmute_neo", issue = "155079")]
1180+
pub const unsafe fn transmute_neo<Src, Dst>(src: Src) -> Dst {
1181+
const { assert!(Src::SIZE == Dst::SIZE) };
1182+
1183+
// SAFETY: the const-assert just checked that they're the same size,
1184+
// and any other safety invariants need to be upheld by the caller.
1185+
unsafe { intrinsics::transmute_unchecked(src) }
1186+
}
1187+
10911188
/// Opaque type representing the discriminant of an enum.
10921189
///
10931190
/// See the [`discriminant`] function in this module for more information.

library/portable-simd/.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ For a given vector math operation on TxN, please add tests for interactions with
1010
- [ ] 0
1111

1212

13-
For a given vector math operation on TxN where T is a float, please add tests for test interactions with:
13+
For a given vector math operation on TxN where T is a float, please add tests for interactions with:
1414
- [ ] a really large number, larger than the mantissa
1515
- [ ] a really small "subnormal" number
1616
- [ ] NaN

0 commit comments

Comments
 (0)