From: Hans Kratz Date: Mon, 9 Aug 2021 12:25:33 +0000 (+0000) Subject: TEST: Use SmallVec<[u32; 4]> for field projection. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=c1d0f0a65c36e73ebf7a1ac899b13fb82e3f6483;p=rust.git TEST: Use SmallVec<[u32; 4]> for field projection. --- diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index d28a579ff10..225514ea863 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -24,6 +24,7 @@ use rustc_span::symbol::Symbol; use rustc_target::abi::{HasDataLayout, LayoutOf, PointeeInfo, Size, TargetDataLayout, VariantIdx}; use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel}; +use smallvec::SmallVec; use std::cell::{Cell, RefCell}; use std::ffi::CStr; @@ -102,7 +103,7 @@ pub struct TypeLowering<'ll> { /// If padding is used the slice maps fields from source order /// to llvm order. - pub field_remapping: Option>, + pub field_remapping: Option>>, } fn to_llvm_tls_model(tls_model: TlsModel) -> llvm::ThreadLocalMode { diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index 46e824d879f..225044c8488 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -10,6 +10,7 @@ use rustc_target::abi::{Abi, AddressSpace, Align, FieldsShape}; use rustc_target::abi::{Int, Pointer, F32, F64}; use rustc_target::abi::{LayoutOf, PointeeInfo, Scalar, Size, TyAndLayoutMethods, Variants}; +use smallvec::{smallvec, SmallVec}; use tracing::debug; use std::fmt::Write; @@ -18,7 +19,7 @@ fn uncached_llvm_type<'a, 'tcx>( cx: &CodegenCx<'a, 'tcx>, layout: TyAndLayout<'tcx>, defer: &mut Option<(&'a Type, TyAndLayout<'tcx>)>, - field_remapping: &mut Option>, + field_remapping: &mut Option>>, ) -> &'a Type { match layout.abi { Abi::Scalar(_) => bug!("handled elsewhere"), @@ -93,7 +94,7 @@ fn uncached_llvm_type<'a, 'tcx>( fn struct_llfields<'a, 'tcx>( cx: &CodegenCx<'a, 'tcx>, layout: TyAndLayout<'tcx>, -) -> (Vec<&'a Type>, bool, Option>) { +) -> (Vec<&'a Type>, bool, Option>>) { debug!("struct_llfields: {:#?}", layout); let field_count = layout.fields.count(); @@ -101,7 +102,7 @@ fn struct_llfields<'a, 'tcx>( let mut offset = Size::ZERO; let mut prev_effective_align = layout.align.abi; let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2); - let mut field_remapping = vec![0; field_count]; + let mut field_remapping = smallvec![0; field_count]; for i in layout.fields.index_by_increasing_offset() { let target_offset = layout.fields.offset(i as usize); let field = layout.field(cx, i); @@ -150,7 +151,7 @@ fn struct_llfields<'a, 'tcx>( debug!("struct_llfields: offset: {:?} stride: {:?}", offset, layout.size); } - (result, packed, padding_used.then_some(field_remapping.into_boxed_slice())) + (result, packed, padding_used.then_some(Box::new(field_remapping))) } impl<'a, 'tcx> CodegenCx<'a, 'tcx> {