Skip to content

Commit 897df45

Browse files
authored
Merge pull request #878 from rust-lang/sync_from_rust_2026_04_29
Sync from rust 2026/04/29
2 parents c936fd9 + d46f3aa commit 897df45

12 files changed

Lines changed: 139 additions & 70 deletions

File tree

example/mini_core.rs

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,36 @@
99
transparent_unions,
1010
auto_traits,
1111
freeze_impls,
12+
pattern_types,
1213
thread_local
1314
)]
1415
#![no_core]
1516
#![allow(dead_code, internal_features, ambiguous_wide_pointer_comparisons)]
1617

18+
#[lang = "pointee_trait"]
19+
pub trait Pointee: PointeeSized {
20+
#[lang = "metadata_type"]
21+
// needed so that layout_of will return `TooGeneric` instead of `Unknown`
22+
// when asked for the layout of `*const T`. Which is important for making
23+
// transmutes between raw pointers (and especially pattern types of raw pointers)
24+
// work.
25+
type Metadata: Copy + Sync + Unpin + Freeze;
26+
}
27+
28+
#[lang = "dyn_metadata"]
29+
pub struct DynMetadata<Dyn: PointeeSized> {
30+
_vtable_ptr: NonNull<VTable>,
31+
_phantom: PhantomData<Dyn>,
32+
}
33+
34+
unsafe extern "C" {
35+
/// Opaque type for accessing vtables.
36+
///
37+
/// Private implementation detail of `DynMetadata::size_of` etc.
38+
/// There is conceptually not actually any Abstract Machine memory behind this pointer.
39+
type VTable;
40+
}
41+
1742
#[no_mangle]
1843
unsafe extern "C" fn _Unwind_Resume() {
1944
intrinsics::unreachable();
@@ -112,7 +137,7 @@ unsafe impl<'a, T: PointeeSized> Sync for &'a T {}
112137
unsafe impl Sync for [u8; 16] {}
113138

114139
#[lang = "freeze"]
115-
unsafe auto trait Freeze {}
140+
pub unsafe auto trait Freeze {}
116141

117142
unsafe impl<T: PointeeSized> Freeze for PhantomData<T> {}
118143
unsafe impl<T: PointeeSized> Freeze for *const T {}
@@ -580,9 +605,23 @@ pub struct Global;
580605
impl Allocator for Global {}
581606

582607
#[repr(transparent)]
583-
#[rustc_layout_scalar_valid_range_start(1)]
584608
#[rustc_nonnull_optimization_guaranteed]
585-
pub struct NonNull<T: PointeeSized>(pub *const T);
609+
pub struct NonNull<T: PointeeSized>(pub pattern_type!(*const T is !null));
610+
611+
#[rustc_builtin_macro(pattern_type)]
612+
#[macro_export]
613+
macro_rules! pattern_type {
614+
($($arg:tt)*) => {
615+
/* compiler built-in */
616+
};
617+
}
618+
619+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<pattern_type!(*const U is !null)> for pattern_type!(*const T is !null) where
620+
T: Unsize<U>
621+
{
622+
}
623+
624+
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<pattern_type!(U is !null)> for pattern_type!(T is !null) {}
586625

587626
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
588627
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
@@ -596,26 +635,37 @@ impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<Unique<U>> for Unique<T> wh
596635
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
597636

598637
#[lang = "owned_box"]
599-
pub struct Box<T: ?Sized, A: Allocator = Global>(Unique<T>, A);
638+
pub struct Box<T: ?Sized, A = Global>(Unique<T>, A);
600639

601-
impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
640+
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
602641

603642
impl<T> Box<T> {
604643
pub fn new(val: T) -> Box<T> {
605644
unsafe {
606645
let size = size_of::<T>();
607646
let ptr = libc::malloc(size);
608647
intrinsics::copy(&val as *const T as *const u8, ptr, size);
609-
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global)
648+
Box(
649+
Unique {
650+
pointer: NonNull(intrinsics::transmute::<
651+
*mut u8,
652+
pattern_type!(*const T is !null),
653+
>(ptr)),
654+
_marker: PhantomData,
655+
},
656+
Global,
657+
)
610658
}
611659
}
612660
}
613661

614-
impl<T: ?Sized, A: Allocator> Drop for Box<T, A> {
662+
impl<T: ?Sized, A> Drop for Box<T, A> {
615663
fn drop(&mut self) {
616-
// inner value is dropped by compiler.
664+
// inner value is dropped by compiler
617665
unsafe {
618-
libc::free(self.0.pointer.0 as *mut u8);
666+
libc::free(intrinsics::transmute::<pattern_type!(*const T is !null), *const T>(
667+
self.0.pointer.0,
668+
) as *mut u8);
619669
}
620670
}
621671
}

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2026-04-05"
2+
channel = "nightly-2026-04-29"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

src/abi.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ impl GccType for Reg {
9090
64 => cx.type_f64(),
9191
_ => bug!("unsupported float: {:?}", self),
9292
},
93-
RegKind::Vector => cx.type_vector(cx.type_i8(), self.size.bytes()),
93+
RegKind::Vector { hint_vector_elem: _ } => {
94+
cx.type_vector(cx.type_i8(), self.size.bytes())
95+
}
9496
}
9597
}
9698
}

src/asm.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,15 @@ fn reg_class_to_gcc(reg_class: InlineAsmRegClass) -> &'static str {
694694
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
695695
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
696696
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => "r",
697+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg_pair) => "r",
697698
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
698699
unreachable!("clobber-only")
699700
}
701+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::vreg) => "v",
702+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::vreg_pair) => "v",
703+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::qreg) => {
704+
unreachable!("clobber-only")
705+
}
700706
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
701707
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
702708
InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg) => "r",
@@ -786,9 +792,19 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
786792
cx.type_vector(cx.type_i64(), 2)
787793
}
788794
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => cx.type_i32(),
795+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg_pair) => cx.type_i64(),
789796
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
790797
unreachable!("clobber-only")
791798
}
799+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::vreg) => {
800+
cx.type_vector(cx.type_i32(), 16)
801+
}
802+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::vreg_pair) => {
803+
cx.type_vector(cx.type_i32(), 32)
804+
}
805+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::qreg) => {
806+
unreachable!("clobber-only")
807+
}
792808
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => cx.type_i32(),
793809
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => cx.type_f32(),
794810
InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg) => cx.type_i32(),

src/back/lto.rs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use rustc_data_structures::memmap::Mmap;
3131
use rustc_data_structures::profiling::SelfProfilerRef;
3232
use rustc_errors::{DiagCtxt, DiagCtxtHandle};
3333
use rustc_log::tracing::info;
34-
use rustc_session::config::Lto;
3534
use tempfile::{TempDir, tempdir};
3635

3736
use crate::back::write::{codegen, save_temp_bitcode};
@@ -45,11 +44,7 @@ struct LtoData {
4544
tmp_path: TempDir,
4645
}
4746

48-
fn prepare_lto(
49-
cgcx: &CodegenContext,
50-
each_linked_rlib_for_lto: &[PathBuf],
51-
dcx: DiagCtxtHandle<'_>,
52-
) -> LtoData {
47+
fn prepare_lto(each_linked_rlib_for_lto: &[PathBuf], dcx: DiagCtxtHandle<'_>) -> LtoData {
5348
let tmp_path = match tempdir() {
5449
Ok(tmp_path) => tmp_path,
5550
Err(error) => {
@@ -64,32 +59,30 @@ fn prepare_lto(
6459
// We save off all the bytecode and GCC module file path for later processing
6560
// with either fat or thin LTO
6661
let mut upstream_modules = Vec::new();
67-
if cgcx.lto != Lto::ThinLocal {
68-
for path in each_linked_rlib_for_lto {
69-
let archive_data = unsafe {
70-
Mmap::map(File::open(path).expect("couldn't open rlib")).expect("couldn't map rlib")
71-
};
72-
let archive = ArchiveFile::parse(&*archive_data).expect("wanted an rlib");
73-
let obj_files = archive
74-
.members()
75-
.filter_map(|child| {
76-
child.ok().and_then(|c| {
77-
std::str::from_utf8(c.name()).ok().map(|name| (name.trim(), c))
78-
})
79-
})
80-
.filter(|&(name, _)| looks_like_rust_object_file(name));
81-
for (name, child) in obj_files {
82-
info!("adding bitcode from {}", name);
83-
let path = tmp_path.path().join(name);
84-
match save_as_file(child.data(&*archive_data).expect("corrupt rlib"), &path) {
85-
Ok(()) => {
86-
let buffer = ModuleBuffer::new(path);
87-
let module = SerializedModule::Local(buffer);
88-
upstream_modules.push((module, CString::new(name).unwrap()));
89-
}
90-
Err(e) => {
91-
dcx.emit_fatal(e);
92-
}
62+
for path in each_linked_rlib_for_lto {
63+
let archive_data = unsafe {
64+
Mmap::map(File::open(path).expect("couldn't open rlib")).expect("couldn't map rlib")
65+
};
66+
let archive = ArchiveFile::parse(&*archive_data).expect("wanted an rlib");
67+
let obj_files = archive
68+
.members()
69+
.filter_map(|child| {
70+
child
71+
.ok()
72+
.and_then(|c| std::str::from_utf8(c.name()).ok().map(|name| (name.trim(), c)))
73+
})
74+
.filter(|&(name, _)| looks_like_rust_object_file(name));
75+
for (name, child) in obj_files {
76+
info!("adding bitcode from {}", name);
77+
let path = tmp_path.path().join(name);
78+
match save_as_file(child.data(&*archive_data).expect("corrupt rlib"), &path) {
79+
Ok(()) => {
80+
let buffer = ModuleBuffer::new(path);
81+
let module = SerializedModule::Local(buffer);
82+
upstream_modules.push((module, CString::new(name).unwrap()));
83+
}
84+
Err(e) => {
85+
dcx.emit_fatal(e);
9386
}
9487
}
9588
}
@@ -115,7 +108,7 @@ pub(crate) fn run_fat(
115108
) -> CompiledModule {
116109
let dcx = DiagCtxt::new(Box::new(shared_emitter.clone()));
117110
let dcx = dcx.handle();
118-
let lto_data = prepare_lto(cgcx, each_linked_rlib_for_lto, dcx);
111+
let lto_data = prepare_lto(each_linked_rlib_for_lto, dcx);
119112
/*let symbols_below_threshold =
120113
lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();*/
121114
fat_lto(
@@ -151,9 +144,12 @@ fn fat_lto(
151144
for module in modules {
152145
match module {
153146
FatLtoInput::InMemory(m) => in_memory.push(m),
154-
FatLtoInput::Serialized { name, buffer } => {
147+
FatLtoInput::Serialized { name, bitcode_path } => {
155148
info!("pushing serialized module {:?}", name);
156-
serialized_modules.push((buffer, CString::new(name).unwrap()));
149+
serialized_modules.push((
150+
SerializedModule::from_file(&bitcode_path),
151+
CString::new(name).unwrap(),
152+
));
157153
}
158154
}
159155
}

src/base.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir::attrs::{AttributeKind, Linkage};
1212
use rustc_hir::find_attr;
1313
use rustc_middle::dep_graph;
1414
#[cfg(feature = "master")]
15-
use rustc_middle::mir::mono::Visibility;
15+
use rustc_middle::mono::Visibility;
1616
use rustc_middle::ty::TyCtxt;
1717
use rustc_session::config::DebugInfo;
1818
use rustc_span::Symbol;
@@ -84,8 +84,7 @@ pub fn compile_codegen_unit(
8484
let (module, _) = tcx.dep_graph.with_task(
8585
dep_node,
8686
tcx,
87-
(cgu_name, target_info, lto_supported),
88-
module_codegen,
87+
|| module_codegen(tcx, cgu_name, target_info, lto_supported),
8988
Some(dep_graph::hash_result),
9089
);
9190
let time_to_codegen = start_time.elapsed();
@@ -97,7 +96,9 @@ pub fn compile_codegen_unit(
9796

9897
fn module_codegen(
9998
tcx: TyCtxt<'_>,
100-
(cgu_name, target_info, lto_supported): (Symbol, LockedTargetInfo, bool),
99+
cgu_name: Symbol,
100+
target_info: LockedTargetInfo,
101+
lto_supported: bool,
101102
) -> ModuleCodegen<GccContext> {
102103
let cgu = tcx.codegen_unit(cgu_name);
103104
// Instantiate monomorphizations without filling out definitions yet...

src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, MiscCodege
1111
use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, ToBaseN};
1212
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1313
use rustc_middle::mir::interpret::Allocation;
14-
use rustc_middle::mir::mono::CodegenUnit;
14+
use rustc_middle::mono::CodegenUnit;
1515
use rustc_middle::span_bug;
1616
use rustc_middle::ty::layout::{
1717
FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError,

src/intrinsic/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ mod simd;
55
use std::iter;
66

77
use gccjit::{ComparisonOp, Function, FunctionType, RValue, ToRValue, Type, UnaryOp};
8-
#[cfg(feature = "master")]
9-
use rustc_abi::ExternAbi;
108
use rustc_abi::{BackendRepr, HasDataLayout, WrappingRange};
119
use rustc_codegen_ssa::MemFlags;
1210
use rustc_codegen_ssa::base::wants_msvc_seh;
@@ -1455,32 +1453,26 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(
14551453
// `unsafe fn(*mut i8) -> ()`
14561454
let try_fn_ty = Ty::new_fn_ptr(
14571455
tcx,
1458-
ty::Binder::dummy(tcx.mk_fn_sig(
1456+
ty::Binder::dummy(tcx.mk_fn_sig_rust_abi(
14591457
iter::once(i8p),
14601458
tcx.types.unit,
1461-
false,
14621459
rustc_hir::Safety::Unsafe,
1463-
ExternAbi::Rust,
14641460
)),
14651461
);
14661462
// `unsafe fn(*mut i8, *mut i8) -> ()`
14671463
let catch_fn_ty = Ty::new_fn_ptr(
14681464
tcx,
1469-
ty::Binder::dummy(tcx.mk_fn_sig(
1465+
ty::Binder::dummy(tcx.mk_fn_sig_rust_abi(
14701466
[i8p, i8p].iter().cloned(),
14711467
tcx.types.unit,
1472-
false,
14731468
rustc_hir::Safety::Unsafe,
1474-
ExternAbi::Rust,
14751469
)),
14761470
);
14771471
// `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
1478-
let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig(
1472+
let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig_rust_abi(
14791473
[try_fn_ty, i8p, catch_fn_ty],
14801474
tcx.types.i32,
1481-
false,
14821475
rustc_hir::Safety::Unsafe,
1483-
ExternAbi::Rust,
14841476
));
14851477
let rust_try = gen_fn(cx, "__rust_try", rust_fn_sig, codegen);
14861478
cx.rust_try_fn.set(Some(rust_try));

src/intrinsic/simd.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods};
1616
use rustc_hir as hir;
1717
use rustc_middle::mir::BinOp;
1818
use rustc_middle::ty::layout::HasTyCtxt;
19-
use rustc_middle::ty::{self, Ty};
19+
use rustc_middle::ty::{self, Ty, Unnormalized};
2020
use rustc_span::{Span, Symbol, sym};
2121

2222
use crate::builder::Builder;
@@ -539,7 +539,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
539539
match *in_elem.kind() {
540540
ty::RawPtr(p_ty, _) => {
541541
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
542-
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
542+
bx.tcx.normalize_erasing_regions(
543+
ty::TypingEnv::fully_monomorphized(),
544+
Unnormalized::new_wip(ty),
545+
)
543546
});
544547
require!(
545548
metadata.is_unit(),
@@ -553,7 +556,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
553556
match *out_elem.kind() {
554557
ty::RawPtr(p_ty, _) => {
555558
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
556-
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
559+
bx.tcx.normalize_erasing_regions(
560+
ty::TypingEnv::fully_monomorphized(),
561+
Unnormalized::new_wip(ty),
562+
)
557563
});
558564
require!(
559565
metadata.is_unit(),

0 commit comments

Comments
 (0)