Skip to content

#[inline] non-generic pub fns in rustc_target::abi and ty::layout. #88326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub trait IntegerExt {
}

impl IntegerExt for Integer {
#[inline]
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>, signed: bool) -> Ty<'tcx> {
match (*self, signed) {
(I8, false) => tcx.types.u8,
Expand Down Expand Up @@ -149,6 +150,7 @@ pub trait PrimitiveExt {
}

impl PrimitiveExt for Primitive {
#[inline]
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match *self {
Int(i, signed) => i.to_ty(tcx, signed),
Expand All @@ -160,6 +162,7 @@ impl PrimitiveExt for Primitive {

/// Return an *integer* type matching this primitive.
/// Useful in particular when dealing with enum discriminants.
#[inline]
fn to_int_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match *self {
Int(i, signed) => i.to_ty(tcx, signed),
Expand Down Expand Up @@ -2016,12 +2019,14 @@ pub trait HasParamEnv<'tcx> {
}

impl<'tcx> HasDataLayout for TyCtxt<'tcx> {
#[inline]
fn data_layout(&self) -> &TargetDataLayout {
&self.data_layout
}
}

impl<'tcx> HasTyCtxt<'tcx> for TyCtxt<'tcx> {
#[inline]
fn tcx(&self) -> TyCtxt<'tcx> {
*self
}
Expand Down Expand Up @@ -2053,6 +2058,7 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> {

/// Computes the layout of a type. Note that this implicitly
/// executes in "reveal all" mode, and will normalize the input type.
#[inline]
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout {
self.tcx.layout_of(self.param_env.and(ty))
}
Expand All @@ -2064,6 +2070,7 @@ impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> {

/// Computes the layout of a type. Note that this implicitly
/// executes in "reveal all" mode, and will normalize the input type.
#[inline]
fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout {
self.tcx.layout_of(self.param_env.and(ty))
}
Expand Down Expand Up @@ -2414,6 +2421,7 @@ where
}

impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for LayoutError<'tcx> {
#[inline]
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
use crate::ty::layout::LayoutError::*;
mem::discriminant(self).hash_stable(hcx, hasher);
Expand Down Expand Up @@ -2604,6 +2612,7 @@ where
/// compiled with `-Cpanic=unwind` and referenced from another crate compiled
/// with `-Cpanic=abort` will look like they can't unwind when in fact they
/// might (from a foreign exception or similar).
#[inline]
pub fn fn_can_unwind(
tcx: TyCtxt<'tcx>,
codegen_fn_attr_flags: CodegenFnAttrFlags,
Expand Down Expand Up @@ -2679,6 +2688,7 @@ pub fn fn_can_unwind(
}
}

#[inline]
pub fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi) -> Conv {
use rustc_target::spec::abi::Abi::*;
match tcx.sess.target.adjust_abi(abi) {
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl TargetDataLayout {
/// to represent object size in bits. It would need to be 1 << 61 to account for this, but is
/// currently conservatively bounded to 1 << 47 as that is enough to cover the current usable
/// address space on 64-bit ARMv8 and x86_64.
#[inline]
pub fn obj_size_bound(&self) -> u64 {
match self.pointer_size.bits() {
16 => 1 << 15,
Expand All @@ -203,6 +204,7 @@ impl TargetDataLayout {
}
}

#[inline]
pub fn ptr_sized_integer(&self) -> Integer {
match self.pointer_size.bits() {
16 => I16,
Expand All @@ -212,6 +214,7 @@ impl TargetDataLayout {
}
}

#[inline]
pub fn vector_align(&self, vec_size: Size) -> AbiAndPrefAlign {
for &(size, align) in &self.vector_align {
if size == vec_size {
Expand Down Expand Up @@ -562,14 +565,17 @@ pub struct AbiAndPrefAlign {
}

impl AbiAndPrefAlign {
#[inline]
pub fn new(align: Align) -> AbiAndPrefAlign {
AbiAndPrefAlign { abi: align, pref: align }
}

#[inline]
pub fn min(self, other: AbiAndPrefAlign) -> AbiAndPrefAlign {
AbiAndPrefAlign { abi: self.abi.min(other.abi), pref: self.pref.min(other.pref) }
}

#[inline]
pub fn max(self, other: AbiAndPrefAlign) -> AbiAndPrefAlign {
AbiAndPrefAlign { abi: self.abi.max(other.abi), pref: self.pref.max(other.pref) }
}
Expand All @@ -586,6 +592,7 @@ pub enum Integer {
}

impl Integer {
#[inline]
pub fn size(self) -> Size {
match self {
I8 => Size::from_bytes(1),
Expand All @@ -609,6 +616,7 @@ impl Integer {
}

/// Finds the smallest Integer type which can represent the signed value.
#[inline]
pub fn fit_signed(x: i128) -> Integer {
match x {
-0x0000_0000_0000_0080..=0x0000_0000_0000_007f => I8,
Expand All @@ -620,6 +628,7 @@ impl Integer {
}

/// Finds the smallest Integer type which can represent the unsigned value.
#[inline]
pub fn fit_unsigned(x: u128) -> Integer {
match x {
0..=0x0000_0000_0000_00ff => I8,
Expand Down Expand Up @@ -655,6 +664,9 @@ impl Integer {
I8
}

// FIXME(eddyb) consolidate this and other methods that find the appropriate
// `Integer` given some requirements.
#[inline]
fn from_size(size: Size) -> Result<Self, String> {
match size.bits() {
8 => Ok(Integer::I8),
Expand Down Expand Up @@ -706,10 +718,14 @@ impl Primitive {
}
}

// FIXME(eddyb) remove, it's trivial thanks to `matches!`.
#[inline]
pub fn is_float(self) -> bool {
matches!(self, F32 | F64)
}

// FIXME(eddyb) remove, it's completely unused.
#[inline]
pub fn is_int(self) -> bool {
matches!(self, Int(..))
}
Expand Down Expand Up @@ -786,6 +802,7 @@ pub struct Scalar {
}

impl Scalar {
#[inline]
pub fn is_bool(&self) -> bool {
matches!(self.value, Int(I8, false))
&& matches!(self.valid_range, WrappingRange { start: 0, end: 1 })
Expand Down Expand Up @@ -852,6 +869,7 @@ pub enum FieldsShape {
}

impl FieldsShape {
#[inline]
pub fn count(&self) -> usize {
match *self {
FieldsShape::Primitive => 0,
Expand All @@ -861,6 +879,7 @@ impl FieldsShape {
}
}

#[inline]
pub fn offset(&self, i: usize) -> Size {
match *self {
FieldsShape::Primitive => {
Expand All @@ -884,6 +903,7 @@ impl FieldsShape {
}
}

#[inline]
pub fn memory_index(&self, i: usize) -> usize {
match *self {
FieldsShape::Primitive => {
Expand Down Expand Up @@ -967,6 +987,7 @@ impl Abi {
}

/// Returns `true` if this is a single signed integer scalar
#[inline]
pub fn is_signed(&self) -> bool {
match *self {
Abi::Scalar(ref scal) => match scal.value {
Expand Down