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 2895e07

Browse files
committedApr 12, 2025·
Auto merge of rust-lang#139725 - davidtwco:sized-hierarchy-no-constness, r=<try>
[PERF] sized hierarchy w/out constness rust-lang#137944 w/out the constness parts - for benchmarking. r? `@ghost`
2 parents 9ffde4b + beb875d commit 2895e07

File tree

275 files changed

+4086
-1017
lines changed

Some content is hidden

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

275 files changed

+4086
-1017
lines changed
 

Diff for: ‎compiler/rustc_codegen_cranelift/example/mini_core.rs

+36-30
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@
1414
#![no_core]
1515
#![allow(dead_code, internal_features, ambiguous_wide_pointer_comparisons)]
1616

17+
#[lang = "pointee_sized"]
18+
pub trait PointeeSized {}
19+
20+
#[lang = "meta_sized"]
21+
pub trait MetaSized: PointeeSized {}
22+
1723
#[lang = "sized"]
18-
pub trait Sized {}
24+
pub trait Sized: MetaSized {}
1925

2026
#[lang = "destruct"]
2127
pub trait Destruct {}
@@ -24,35 +30,35 @@ pub trait Destruct {}
2430
pub trait Tuple {}
2531

2632
#[lang = "unsize"]
27-
pub trait Unsize<T: ?Sized> {}
33+
pub trait Unsize<T: PointeeSized>: PointeeSized {}
2834

2935
#[lang = "coerce_unsized"]
3036
pub trait CoerceUnsized<T> {}
3137

32-
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
33-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
34-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
35-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
38+
impl<'a, 'b: 'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
39+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {}
40+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*const U> for *const T {}
41+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {}
3642

3743
#[lang = "dispatch_from_dyn"]
3844
pub trait DispatchFromDyn<T> {}
3945

4046
// &T -> &U
41-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
47+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {}
4248
// &mut T -> &mut U
43-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
49+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {}
4450
// *const T -> *const U
45-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
51+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
4652
// *mut T -> *mut U
47-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
48-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {}
53+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
54+
impl<T: MetaSized + Unsize<U>, U: MetaSized> DispatchFromDyn<Box<U>> for Box<T> {}
4955

5056
#[lang = "legacy_receiver"]
5157
pub trait LegacyReceiver {}
5258

53-
impl<T: ?Sized> LegacyReceiver for &T {}
54-
impl<T: ?Sized> LegacyReceiver for &mut T {}
55-
impl<T: ?Sized> LegacyReceiver for Box<T> {}
59+
impl<T: PointeeSized> LegacyReceiver for &T {}
60+
impl<T: PointeeSized> LegacyReceiver for &mut T {}
61+
impl<T: MetaSized> LegacyReceiver for Box<T> {}
5662

5763
#[lang = "copy"]
5864
pub trait Copy {}
@@ -74,9 +80,9 @@ impl Copy for isize {}
7480
impl Copy for f32 {}
7581
impl Copy for f64 {}
7682
impl Copy for char {}
77-
impl<'a, T: ?Sized> Copy for &'a T {}
78-
impl<T: ?Sized> Copy for *const T {}
79-
impl<T: ?Sized> Copy for *mut T {}
83+
impl<'a, T: PointeeSized> Copy for &'a T {}
84+
impl<T: PointeeSized> Copy for *const T {}
85+
impl<T: PointeeSized> Copy for *mut T {}
8086
impl<T: Copy> Copy for Option<T> {}
8187

8288
#[lang = "sync"]
@@ -94,17 +100,17 @@ unsafe impl Sync for i32 {}
94100
unsafe impl Sync for isize {}
95101
unsafe impl Sync for char {}
96102
unsafe impl Sync for f32 {}
97-
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
103+
unsafe impl<'a, T: PointeeSized> Sync for &'a T {}
98104
unsafe impl<T: Sync, const N: usize> Sync for [T; N] {}
99105

100106
#[lang = "freeze"]
101107
unsafe auto trait Freeze {}
102108

103-
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
104-
unsafe impl<T: ?Sized> Freeze for *const T {}
105-
unsafe impl<T: ?Sized> Freeze for *mut T {}
106-
unsafe impl<T: ?Sized> Freeze for &T {}
107-
unsafe impl<T: ?Sized> Freeze for &mut T {}
109+
unsafe impl<T: PointeeSized> Freeze for PhantomData<T> {}
110+
unsafe impl<T: PointeeSized> Freeze for *const T {}
111+
unsafe impl<T: PointeeSized> Freeze for *mut T {}
112+
unsafe impl<T: PointeeSized> Freeze for &T {}
113+
unsafe impl<T: PointeeSized> Freeze for &mut T {}
108114

109115
#[lang = "structural_peq"]
110116
pub trait StructuralPartialEq {}
@@ -443,7 +449,7 @@ pub enum Option<T> {
443449
pub use Option::*;
444450

445451
#[lang = "phantom_data"]
446-
pub struct PhantomData<T: ?Sized>;
452+
pub struct PhantomData<T: PointeeSized>;
447453

448454
#[lang = "fn_once"]
449455
#[rustc_paren_sugar]
@@ -546,18 +552,18 @@ pub trait Deref {
546552
#[repr(transparent)]
547553
#[rustc_layout_scalar_valid_range_start(1)]
548554
#[rustc_nonnull_optimization_guaranteed]
549-
pub struct NonNull<T: ?Sized>(pub *const T);
555+
pub struct NonNull<T: PointeeSized>(pub *const T);
550556

551-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
552-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
557+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
558+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
553559

554-
pub struct Unique<T: ?Sized> {
560+
pub struct Unique<T: PointeeSized> {
555561
pub pointer: NonNull<T>,
556562
pub _marker: PhantomData<T>,
557563
}
558564

559-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
560-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
565+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
566+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
561567

562568
#[lang = "global_alloc_ty"]
563569
pub struct Global;

Diff for: ‎compiler/rustc_codegen_gcc/example/mini_core.rs

+36-30
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ unsafe extern "C" fn _Unwind_Resume() {
1111
intrinsics::unreachable();
1212
}
1313

14+
#[lang = "pointee_sized"]
15+
pub trait PointeeSized {}
16+
17+
#[lang = "meta_sized"]
18+
pub trait MetaSized: PointeeSized {}
19+
1420
#[lang = "sized"]
15-
pub trait Sized {}
21+
pub trait Sized: MetaSized {}
1622

1723
#[lang = "destruct"]
1824
pub trait Destruct {}
@@ -21,35 +27,35 @@ pub trait Destruct {}
2127
pub trait Tuple {}
2228

2329
#[lang = "unsize"]
24-
pub trait Unsize<T: ?Sized> {}
30+
pub trait Unsize<T: PointeeSized>: PointeeSized {}
2531

2632
#[lang = "coerce_unsized"]
2733
pub trait CoerceUnsized<T> {}
2834

29-
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
30-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
31-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
32-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
35+
impl<'a, 'b: 'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
36+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {}
37+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*const U> for *const T {}
38+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {}
3339

3440
#[lang = "dispatch_from_dyn"]
3541
pub trait DispatchFromDyn<T> {}
3642

3743
// &T -> &U
38-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
44+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {}
3945
// &mut T -> &mut U
40-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
46+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {}
4147
// *const T -> *const U
42-
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
48+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
4349
// *mut T -> *mut U
44-
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
45-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
50+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
51+
impl<T: MetaSized + Unsize<U>, U: MetaSized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
4652

4753
#[lang = "legacy_receiver"]
4854
pub trait LegacyReceiver {}
4955

50-
impl<T: ?Sized> LegacyReceiver for &T {}
51-
impl<T: ?Sized> LegacyReceiver for &mut T {}
52-
impl<T: ?Sized, A: Allocator> LegacyReceiver for Box<T, A> {}
56+
impl<T: PointeeSized> LegacyReceiver for &T {}
57+
impl<T: PointeeSized> LegacyReceiver for &mut T {}
58+
impl<T: MetaSized> LegacyReceiver for Box<T> {}
5359

5460
#[lang = "copy"]
5561
pub trait Copy {}
@@ -70,9 +76,9 @@ impl Copy for isize {}
7076
impl Copy for f32 {}
7177
impl Copy for f64 {}
7278
impl Copy for char {}
73-
impl<'a, T: ?Sized> Copy for &'a T {}
74-
impl<T: ?Sized> Copy for *const T {}
75-
impl<T: ?Sized> Copy for *mut T {}
79+
impl<'a, T: PointeeSized> Copy for &'a T {}
80+
impl<T: PointeeSized> Copy for *const T {}
81+
impl<T: PointeeSized> Copy for *mut T {}
7682

7783
#[lang = "sync"]
7884
pub unsafe trait Sync {}
@@ -88,17 +94,17 @@ unsafe impl Sync for i16 {}
8894
unsafe impl Sync for i32 {}
8995
unsafe impl Sync for isize {}
9096
unsafe impl Sync for char {}
91-
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
97+
unsafe impl<'a, T: PointeeSized> Sync for &'a T {}
9298
unsafe impl Sync for [u8; 16] {}
9399

94100
#[lang = "freeze"]
95101
unsafe auto trait Freeze {}
96102

97-
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
98-
unsafe impl<T: ?Sized> Freeze for *const T {}
99-
unsafe impl<T: ?Sized> Freeze for *mut T {}
100-
unsafe impl<T: ?Sized> Freeze for &T {}
101-
unsafe impl<T: ?Sized> Freeze for &mut T {}
103+
unsafe impl<T: PointeeSized> Freeze for PhantomData<T> {}
104+
unsafe impl<T: PointeeSized> Freeze for *const T {}
105+
unsafe impl<T: PointeeSized> Freeze for *mut T {}
106+
unsafe impl<T: PointeeSized> Freeze for &T {}
107+
unsafe impl<T: PointeeSized> Freeze for &mut T {}
102108

103109
#[lang = "structural_peq"]
104110
pub trait StructuralPartialEq {}
@@ -403,7 +409,7 @@ pub enum Option<T> {
403409
pub use Option::*;
404410

405411
#[lang = "phantom_data"]
406-
pub struct PhantomData<T: ?Sized>;
412+
pub struct PhantomData<T: PointeeSized>;
407413

408414
#[lang = "fn_once"]
409415
#[rustc_paren_sugar]
@@ -520,18 +526,18 @@ impl Allocator for Global {}
520526
#[repr(transparent)]
521527
#[rustc_layout_scalar_valid_range_start(1)]
522528
#[rustc_nonnull_optimization_guaranteed]
523-
pub struct NonNull<T: ?Sized>(pub *const T);
529+
pub struct NonNull<T: PointeeSized>(pub *const T);
524530

525-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
526-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
531+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
532+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
527533

528-
pub struct Unique<T: ?Sized> {
534+
pub struct Unique<T: PointeeSized> {
529535
pub pointer: NonNull<T>,
530536
pub _marker: PhantomData<T>,
531537
}
532538

533-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
534-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
539+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
540+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
535541

536542
#[lang = "owned_box"]
537543
pub struct Box<T: ?Sized, A: Allocator = Global>(Unique<T>, A);

0 commit comments

Comments
 (0)
Please sign in to comment.