Skip to content

Commit ba8b102

Browse files
bors[bot]CAD97
andauthored
Merge #57
57: LLVM can have little a #[inline] as a treat r=CAD97 a=CAD97 Co-authored-by: CAD97 <[email protected]>
2 parents b67df9c + b0b09fd commit ba8b102

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

crates/erasable/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ pub unsafe trait Erasable {
195195
/// Turn this erasable pointer into an erased pointer.
196196
///
197197
/// To retrieve the original pointer, use `unerase`.
198+
#[inline(always)]
198199
fn erase(this: ptr::NonNull<Self>) -> ErasedPtr {
199200
erase(this)
200201
}
@@ -266,6 +267,7 @@ pub unsafe trait Erasable {
266267
}
267268

268269
/// Erase a pointer.
270+
#[inline(always)]
269271
pub fn erase<T: ?Sized>(ptr: ptr::NonNull<T>) -> ErasedPtr {
270272
unsafe { ptr::NonNull::new_unchecked(ptr.as_ptr() as *mut Erased) }
271273
}
@@ -298,6 +300,7 @@ unsafe impl<P: ErasablePtr> Send for Thin<P> where P: Send {}
298300
unsafe impl<P: ErasablePtr> Sync for Thin<P> where P: Sync {}
299301

300302
impl<P: ErasablePtr> From<P> for Thin<P> {
303+
#[inline(always)]
301304
fn from(this: P) -> Self {
302305
Thin::<P> {
303306
ptr: P::erase(this),
@@ -698,11 +701,13 @@ macro_rules! impl_erasable {
698701
where
699702
T: Erasable,
700703
{
704+
#[inline]
701705
fn erase(this: Self) -> ErasedPtr {
702706
let ptr = unsafe { ptr::NonNull::new_unchecked(<$ty>::into_raw(this) as *mut _) };
703707
T::erase(ptr)
704708
}
705709

710+
#[inline]
706711
unsafe fn unerase(this: ErasedPtr) -> Self {
707712
Self::from_raw(T::unerase(this).as_ptr())
708713
}
@@ -723,10 +728,12 @@ impl_erasable!(for<T>
723728

724729
#[cfg(has_never)]
725730
unsafe impl ErasablePtr for ! {
731+
#[inline(always)]
726732
fn erase(this: !) -> ErasedPtr {
727733
this
728734
}
729735
#[rustfmt::skip]
736+
#[inline(always)]
730737
unsafe fn unerase(_this: ErasedPtr) -> Self {
731738
#[cfg(debug_assertions)] {
732739
panic!("attempted to unerase erased pointer to !")
@@ -737,10 +744,12 @@ unsafe impl ErasablePtr for ! {
737744
}
738745
}
739746

747+
#[inline(always)]
740748
unsafe fn erase_lt<'a, 'b, T: ?Sized>(this: &'a T) -> &'b T {
741749
&*(this as *const T)
742750
}
743751

752+
#[inline(always)]
744753
unsafe fn erase_lt_mut<'a, 'b, T: ?Sized>(this: &'a mut T) -> &'b mut T {
745754
&mut *(this as *mut T)
746755
}

crates/ptr-union/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@ const TAG_B: usize = 0b01;
2424
const TAG_C: usize = 0b10;
2525
const TAG_D: usize = 0b11;
2626

27+
#[inline(always)]
2728
fn check_tag(ptr: ErasedPtr, mask: usize, tag: usize) -> bool {
2829
debug_assert_eq!(tag & mask, tag);
2930
(ptr.as_ptr() as usize & mask) == tag
3031
}
3132

33+
#[inline(always)]
3234
fn set_tag(ptr: ErasedPtr, mask: usize, tag: usize) -> ErasedPtr {
3335
debug_assert_eq!(tag & mask, tag);
3436
debug_assert!(check_tag(ptr, mask, 0));
35-
let high = ptr.as_ptr() as usize & !mask;
36-
let low = tag & mask;
37-
unsafe { ErasedPtr::new_unchecked((high | low) as *mut _) }
37+
unsafe { ErasedPtr::new_unchecked((ptr.as_ptr() as usize | tag) as *mut _) }
3838
}
3939

40+
#[inline(always)]
4041
fn unset_tag(ptr: ErasedPtr, mask: usize, tag: usize) -> ErasedPtr {
42+
debug_assert_eq!(tag & mask, tag);
4143
debug_assert!(check_tag(ptr, mask, tag));
4244
unsafe { ErasedPtr::new_unchecked((ptr.as_ptr() as usize & !mask) as *mut _) }
4345
}
@@ -52,9 +54,11 @@ mod never_ptr {
5254
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
5355
pub enum NeverPtr {}
5456
unsafe impl ErasablePtr for NeverPtr {
57+
#[inline]
5558
fn erase(this: Self) -> ErasedPtr {
5659
match this {}
5760
}
61+
#[inline]
5862
unsafe fn unerase(_this: ErasedPtr) -> Self {
5963
unreachable!()
6064
}

crates/rc-borrow/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ trait RawRc<T: ?Sized> {
6565

6666
impl<T: ?Sized> RawRc<T> for Arc<T> {
6767
#[rustfmt::skip]
68+
#[inline(always)]
6869
fn as_raw(this: &Self) -> *const T {
6970
#[cfg(not(has_Arc__as_raw))] {
7071
Arc::into_raw(unsafe { ptr::read(this) })
@@ -75,6 +76,7 @@ impl<T: ?Sized> RawRc<T> for Arc<T> {
7576
}
7677

7778
#[rustfmt::skip]
79+
#[inline(always)]
7880
unsafe fn clone_raw(this: *const T) -> Self {
7981
#[cfg(not(has_Arc__clone_raw))] {
8082
Arc::clone(&ManuallyDrop::new(Arc::from_raw(this)))
@@ -87,6 +89,7 @@ impl<T: ?Sized> RawRc<T> for Arc<T> {
8789

8890
impl<T: ?Sized> RawRc<T> for Rc<T> {
8991
#[rustfmt::skip]
92+
#[inline(always)]
9093
fn as_raw(this: &Self) -> *const T {
9194
#[cfg(not(has_Rc__as_raw))] {
9295
Rc::into_raw(unsafe { ptr::read(this) })
@@ -97,6 +100,7 @@ impl<T: ?Sized> RawRc<T> for Rc<T> {
97100
}
98101

99102
#[rustfmt::skip]
103+
#[inline(always)]
100104
unsafe fn clone_raw(this: *const T) -> Self {
101105
#[cfg(not(has_Rc__clone_raw))] {
102106
Rc::clone(&ManuallyDrop::new(Rc::from_raw(this)))
@@ -181,10 +185,12 @@ between the two types, and the types must be transmute-compatible."),
181185
where
182186
T: Erasable
183187
{
188+
#[inline(always)]
184189
fn erase(this: Self) -> ErasedPtr {
185190
T::erase(this.raw)
186191
}
187192

193+
#[inline(always)]
188194
unsafe fn unerase(this: ErasedPtr) -> Self {
189195
$RcBorrow {
190196
raw: T::unerase(this),

crates/rc-box/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ print_if_string(my_number.try_into().unwrap());
123123
124124
The unsizing as `", stringify!($Rc), "` is required until
125125
[DST coercions](https://github.com/rust-lang/rust/issues/27732) are stabilized."),
126+
#[inline]
126127
pub fn downcast<T>(self) -> Result<$RcBox<T>, Self>
127128
where T: Any,
128129
{
@@ -164,6 +165,7 @@ print_if_string(my_number.try_into().unwrap());
164165
165166
The unsizing as `", stringify!($Rc), "` is required until
166167
[DST coercions](https://github.com/rust-lang/rust/issues/27732) are stabilized."),
168+
#[inline]
167169
pub fn downcast<T>(self) -> Result<$RcBox<T>, Self>
168170
where T: Any + Send
169171
{
@@ -205,6 +207,7 @@ print_if_string(my_number.try_into().unwrap());
205207
206208
The unsizing as `", stringify!($Rc), "` is required until
207209
[DST coercions](https://github.com/rust-lang/rust/issues/27732) are stabilized."),
210+
#[inline]
208211
pub fn downcast<T>(self) -> Result<$RcBox<T>, Self>
209212
where T: Any + Send + Sync
210213
{

crates/slice-dst/src/layout_polyfill.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use core::{
33
cmp,
44
};
55

6+
#[inline]
67
pub(crate) fn extend_layout(this: &Layout, next: Layout) -> Result<(Layout, usize), LayoutErr> {
78
let new_align = cmp::max(this.align(), next.align());
89
let pad = layout_padding_needed_for(&this, next.align());
@@ -12,16 +13,19 @@ pub(crate) fn extend_layout(this: &Layout, next: Layout) -> Result<(Layout, usiz
1213
Ok((layout, offset))
1314
}
1415

16+
#[inline]
1517
pub(crate) fn pad_layout_to_align(this: &Layout) -> Layout {
1618
let pad = layout_padding_needed_for(this, this.align());
1719
let new_size = this.size() + pad;
1820
unsafe { Layout::from_size_align_unchecked(new_size, this.align()) }
1921
}
2022

23+
#[inline]
2124
pub(crate) fn layout_array<T>(n: usize) -> Result<Layout, LayoutErr> {
2225
repeat_layout(&Layout::new::<T>(), n).map(|(k, _)| k)
2326
}
2427

28+
#[inline]
2529
pub(crate) fn repr_c_3(fields: [Layout; 3]) -> Result<(Layout, [usize; 3]), LayoutErr> {
2630
let mut offsets: [usize; 3] = [0; 3];
2731
let mut layout = fields[0];
@@ -33,12 +37,14 @@ pub(crate) fn repr_c_3(fields: [Layout; 3]) -> Result<(Layout, [usize; 3]), Layo
3337
Ok((pad_layout_to_align(&layout), offsets))
3438
}
3539

40+
#[inline]
3641
fn layout_padding_needed_for(this: &Layout, align: usize) -> usize {
3742
let len = this.size();
3843
let len_rounded_up = len.wrapping_add(align).wrapping_sub(1) & !align.wrapping_sub(1);
3944
len_rounded_up.wrapping_sub(len)
4045
}
4146

47+
#[inline]
4248
fn repeat_layout(this: &Layout, n: usize) -> Result<(Layout, usize), LayoutErr> {
4349
let padded_size = pad_layout_to_align(this).size();
4450
let alloc_size = padded_size.checked_mul(n).ok_or_else(layout_err)?;
@@ -50,6 +56,7 @@ fn repeat_layout(this: &Layout, n: usize) -> Result<(Layout, usize), LayoutErr>
5056
}
5157
}
5258

59+
#[inline]
5360
fn layout_err() -> LayoutErr {
5461
Layout::from_size_align(0, 0).unwrap_err()
5562
}

0 commit comments

Comments
 (0)