Skip to content

Commit c1d0f0a

Browse files
committed
TEST: Use SmallVec<[u32; 4]> for field projection.
1 parent c627c0d commit c1d0f0a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_span::source_map::{Span, DUMMY_SP};
2424
use rustc_span::symbol::Symbol;
2525
use rustc_target::abi::{HasDataLayout, LayoutOf, PointeeInfo, Size, TargetDataLayout, VariantIdx};
2626
use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
27+
use smallvec::SmallVec;
2728

2829
use std::cell::{Cell, RefCell};
2930
use std::ffi::CStr;
@@ -102,7 +103,7 @@ pub struct TypeLowering<'ll> {
102103

103104
/// If padding is used the slice maps fields from source order
104105
/// to llvm order.
105-
pub field_remapping: Option<Box<[u32]>>,
106+
pub field_remapping: Option<Box<SmallVec<[u32; 4]>>>,
106107
}
107108

108109
fn to_llvm_tls_model(tls_model: TlsModel) -> llvm::ThreadLocalMode {

compiler/rustc_codegen_llvm/src/type_of.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_middle::ty::{self, Ty, TypeFoldable};
1010
use rustc_target::abi::{Abi, AddressSpace, Align, FieldsShape};
1111
use rustc_target::abi::{Int, Pointer, F32, F64};
1212
use rustc_target::abi::{LayoutOf, PointeeInfo, Scalar, Size, TyAndLayoutMethods, Variants};
13+
use smallvec::{smallvec, SmallVec};
1314
use tracing::debug;
1415

1516
use std::fmt::Write;
@@ -18,7 +19,7 @@ fn uncached_llvm_type<'a, 'tcx>(
1819
cx: &CodegenCx<'a, 'tcx>,
1920
layout: TyAndLayout<'tcx>,
2021
defer: &mut Option<(&'a Type, TyAndLayout<'tcx>)>,
21-
field_remapping: &mut Option<Box<[u32]>>,
22+
field_remapping: &mut Option<Box<SmallVec<[u32; 4]>>>,
2223
) -> &'a Type {
2324
match layout.abi {
2425
Abi::Scalar(_) => bug!("handled elsewhere"),
@@ -93,15 +94,15 @@ fn uncached_llvm_type<'a, 'tcx>(
9394
fn struct_llfields<'a, 'tcx>(
9495
cx: &CodegenCx<'a, 'tcx>,
9596
layout: TyAndLayout<'tcx>,
96-
) -> (Vec<&'a Type>, bool, Option<Box<[u32]>>) {
97+
) -> (Vec<&'a Type>, bool, Option<Box<SmallVec<[u32; 4]>>>) {
9798
debug!("struct_llfields: {:#?}", layout);
9899
let field_count = layout.fields.count();
99100

100101
let mut packed = false;
101102
let mut offset = Size::ZERO;
102103
let mut prev_effective_align = layout.align.abi;
103104
let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2);
104-
let mut field_remapping = vec![0; field_count];
105+
let mut field_remapping = smallvec![0; field_count];
105106
for i in layout.fields.index_by_increasing_offset() {
106107
let target_offset = layout.fields.offset(i as usize);
107108
let field = layout.field(cx, i);
@@ -150,7 +151,7 @@ fn struct_llfields<'a, 'tcx>(
150151
debug!("struct_llfields: offset: {:?} stride: {:?}", offset, layout.size);
151152
}
152153

153-
(result, packed, padding_used.then_some(field_remapping.into_boxed_slice()))
154+
(result, packed, padding_used.then_some(Box::new(field_remapping)))
154155
}
155156

156157
impl<'a, 'tcx> CodegenCx<'a, 'tcx> {

0 commit comments

Comments
 (0)