Skip to content

Commit 5b2f757

Browse files
committed
Make abi::Abi Copy and remove a *lot* of refs
fix fix Remove more refs and clones fix more fix
1 parent 86ff6ae commit 5b2f757

File tree

33 files changed

+139
-163
lines changed

33 files changed

+139
-163
lines changed

compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
9292
fn get_abi_param(&self, tcx: TyCtxt<'tcx>) -> SmallVec<[AbiParam; 2]> {
9393
match self.mode {
9494
PassMode::Ignore => smallvec![],
95-
PassMode::Direct(attrs) => match &self.layout.abi {
95+
PassMode::Direct(attrs) => match self.layout.abi {
9696
Abi::Scalar(scalar) => smallvec![apply_arg_attrs_to_abi_param(
97-
AbiParam::new(scalar_to_clif_type(tcx, scalar.clone())),
97+
AbiParam::new(scalar_to_clif_type(tcx, scalar)),
9898
attrs
9999
)],
100100
Abi::Vector { .. } => {
@@ -103,10 +103,10 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
103103
}
104104
_ => unreachable!("{:?}", self.layout.abi),
105105
},
106-
PassMode::Pair(attrs_a, attrs_b) => match &self.layout.abi {
106+
PassMode::Pair(attrs_a, attrs_b) => match self.layout.abi {
107107
Abi::ScalarPair(a, b) => {
108-
let a = scalar_to_clif_type(tcx, a.clone());
109-
let b = scalar_to_clif_type(tcx, b.clone());
108+
let a = scalar_to_clif_type(tcx, a);
109+
let b = scalar_to_clif_type(tcx, b);
110110
smallvec![
111111
apply_arg_attrs_to_abi_param(AbiParam::new(a), attrs_a),
112112
apply_arg_attrs_to_abi_param(AbiParam::new(b), attrs_b),
@@ -139,20 +139,20 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
139139
fn get_abi_return(&self, tcx: TyCtxt<'tcx>) -> (Option<AbiParam>, Vec<AbiParam>) {
140140
match self.mode {
141141
PassMode::Ignore => (None, vec![]),
142-
PassMode::Direct(_) => match &self.layout.abi {
142+
PassMode::Direct(_) => match self.layout.abi {
143143
Abi::Scalar(scalar) => {
144-
(None, vec![AbiParam::new(scalar_to_clif_type(tcx, scalar.clone()))])
144+
(None, vec![AbiParam::new(scalar_to_clif_type(tcx, scalar))])
145145
}
146146
Abi::Vector { .. } => {
147147
let vector_ty = crate::intrinsics::clif_vector_type(tcx, self.layout).unwrap();
148148
(None, vec![AbiParam::new(vector_ty)])
149149
}
150150
_ => unreachable!("{:?}", self.layout.abi),
151151
},
152-
PassMode::Pair(_, _) => match &self.layout.abi {
152+
PassMode::Pair(_, _) => match self.layout.abi {
153153
Abi::ScalarPair(a, b) => {
154-
let a = scalar_to_clif_type(tcx, a.clone());
155-
let b = scalar_to_clif_type(tcx, b.clone());
154+
let a = scalar_to_clif_type(tcx, a);
155+
let b = scalar_to_clif_type(tcx, b);
156156
(None, vec![AbiParam::new(a), AbiParam::new(b)])
157157
}
158158
_ => unreachable!("{:?}", self.layout.abi),

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ macro validate_simd_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) {
143143
}
144144

145145
pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Option<Type> {
146-
let (element, count) = match &layout.abi {
147-
Abi::Vector { element, count } => (element.clone(), *count),
146+
let (element, count) = match layout.abi {
147+
Abi::Vector { element, count } => (element, count),
148148
_ => unreachable!(),
149149
};
150150

compiler/rustc_codegen_cranelift/src/value_and_place.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ fn codegen_field<'tcx>(
4949
}
5050
}
5151

52-
fn scalar_pair_calculate_b_offset(
53-
tcx: TyCtxt<'_>,
54-
a_scalar: &Scalar,
55-
b_scalar: &Scalar,
56-
) -> Offset32 {
52+
fn scalar_pair_calculate_b_offset(tcx: TyCtxt<'_>, a_scalar: Scalar, b_scalar: Scalar) -> Offset32 {
5753
let b_offset = a_scalar.value.size(&tcx).align_to(b_scalar.value.align(&tcx).abi);
5854
Offset32::new(b_offset.bytes().try_into().unwrap())
5955
}
@@ -124,12 +120,10 @@ impl<'tcx> CValue<'tcx> {
124120
match self.0 {
125121
CValueInner::ByRef(ptr, None) => {
126122
let clif_ty = match layout.abi {
127-
Abi::Scalar(ref scalar) => scalar_to_clif_type(fx.tcx, scalar.clone()),
128-
Abi::Vector { ref element, count } => {
129-
scalar_to_clif_type(fx.tcx, element.clone())
130-
.by(u16::try_from(count).unwrap())
131-
.unwrap()
132-
}
123+
Abi::Scalar(scalar) => scalar_to_clif_type(fx.tcx, scalar),
124+
Abi::Vector { element, count } => scalar_to_clif_type(fx.tcx, element)
125+
.by(u16::try_from(count).unwrap())
126+
.unwrap(),
133127
_ => unreachable!("{:?}", layout.ty),
134128
};
135129
let mut flags = MemFlags::new();
@@ -147,13 +141,13 @@ impl<'tcx> CValue<'tcx> {
147141
let layout = self.1;
148142
match self.0 {
149143
CValueInner::ByRef(ptr, None) => {
150-
let (a_scalar, b_scalar) = match &layout.abi {
144+
let (a_scalar, b_scalar) = match layout.abi {
151145
Abi::ScalarPair(a, b) => (a, b),
152146
_ => unreachable!("load_scalar_pair({:?})", self),
153147
};
154148
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
155-
let clif_ty1 = scalar_to_clif_type(fx.tcx, a_scalar.clone());
156-
let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar.clone());
149+
let clif_ty1 = scalar_to_clif_type(fx.tcx, a_scalar);
150+
let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar);
157151
let mut flags = MemFlags::new();
158152
flags.set_notrap();
159153
let val1 = ptr.load(fx, clif_ty1, flags);
@@ -564,7 +558,7 @@ impl<'tcx> CPlace<'tcx> {
564558
to_ptr.store(fx, val, flags);
565559
return;
566560
}
567-
Abi::ScalarPair(ref a_scalar, ref b_scalar) => {
561+
Abi::ScalarPair(a_scalar, b_scalar) => {
568562
let (value, extra) = from.load_scalar_pair(fx);
569563
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
570564
to_ptr.store(fx, value, flags);

compiler/rustc_codegen_llvm/src/abi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,13 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
536536
}
537537
_ => {}
538538
}
539-
if let abi::Abi::Scalar(ref scalar) = self.ret.layout.abi {
539+
if let abi::Abi::Scalar(scalar) = self.ret.layout.abi {
540540
// If the value is a boolean, the range is 0..2 and that ultimately
541541
// become 0..0 when the type becomes i1, which would be rejected
542542
// by the LLVM verifier.
543543
if let Int(..) = scalar.value {
544544
if !scalar.is_bool() && !scalar.is_always_valid_for(bx) {
545-
bx.range_metadata(callsite, &scalar.valid_range);
545+
bx.range_metadata(callsite, scalar.valid_range);
546546
}
547547
}
548548
}

compiler/rustc_codegen_llvm/src/asm.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll
792792

793793
/// Helper function to get the LLVM type for a Scalar. Pointers are returned as
794794
/// the equivalent integer type.
795-
fn llvm_asm_scalar_type(cx: &CodegenCx<'ll, 'tcx>, scalar: &Scalar) -> &'ll Type {
795+
fn llvm_asm_scalar_type(cx: &CodegenCx<'ll, 'tcx>, scalar: Scalar) -> &'ll Type {
796796
match scalar.value {
797797
Primitive::Int(Integer::I8, _) => cx.type_i8(),
798798
Primitive::Int(Integer::I16, _) => cx.type_i16(),
@@ -812,7 +812,7 @@ fn llvm_fixup_input(
812812
reg: InlineAsmRegClass,
813813
layout: &TyAndLayout<'tcx>,
814814
) -> &'ll Value {
815-
match (reg, &layout.abi) {
815+
match (reg, layout.abi) {
816816
(InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg), Abi::Scalar(s)) => {
817817
if let Primitive::Int(Integer::I8, _) = s.value {
818818
let vec_ty = bx.cx.type_vector(bx.cx.type_i8(), 8);
@@ -835,7 +835,7 @@ fn llvm_fixup_input(
835835
Abi::Vector { element, count },
836836
) if layout.size.bytes() == 8 => {
837837
let elem_ty = llvm_asm_scalar_type(bx.cx, element);
838-
let vec_ty = bx.cx.type_vector(elem_ty, *count);
838+
let vec_ty = bx.cx.type_vector(elem_ty, count);
839839
let indices: Vec<_> = (0..count * 2).map(|x| bx.const_i32(x as i32)).collect();
840840
bx.shuffle_vector(value, bx.const_undef(vec_ty), bx.const_vector(&indices))
841841
}
@@ -890,7 +890,7 @@ fn llvm_fixup_output(
890890
reg: InlineAsmRegClass,
891891
layout: &TyAndLayout<'tcx>,
892892
) -> &'ll Value {
893-
match (reg, &layout.abi) {
893+
match (reg, layout.abi) {
894894
(InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg), Abi::Scalar(s)) => {
895895
if let Primitive::Int(Integer::I8, _) = s.value {
896896
bx.extract_element(value, bx.const_i32(0))
@@ -910,8 +910,8 @@ fn llvm_fixup_output(
910910
Abi::Vector { element, count },
911911
) if layout.size.bytes() == 8 => {
912912
let elem_ty = llvm_asm_scalar_type(bx.cx, element);
913-
let vec_ty = bx.cx.type_vector(elem_ty, *count * 2);
914-
let indices: Vec<_> = (0..*count).map(|x| bx.const_i32(x as i32)).collect();
913+
let vec_ty = bx.cx.type_vector(elem_ty, count * 2);
914+
let indices: Vec<_> = (0..count).map(|x| bx.const_i32(x as i32)).collect();
915915
bx.shuffle_vector(value, bx.const_undef(vec_ty), bx.const_vector(&indices))
916916
}
917917
(InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd), Abi::Scalar(s))
@@ -965,7 +965,7 @@ fn llvm_fixup_output_type(
965965
reg: InlineAsmRegClass,
966966
layout: &TyAndLayout<'tcx>,
967967
) -> &'ll Type {
968-
match (reg, &layout.abi) {
968+
match (reg, layout.abi) {
969969
(InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg), Abi::Scalar(s)) => {
970970
if let Primitive::Int(Integer::I8, _) = s.value {
971971
cx.type_vector(cx.type_i8(), 8)

compiler/rustc_codegen_llvm/src/builder.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
382382
val
383383
}
384384
}
385-
fn to_immediate_scalar(&mut self, val: Self::Value, scalar: &abi::Scalar) -> Self::Value {
385+
fn to_immediate_scalar(&mut self, val: Self::Value, scalar: abi::Scalar) -> Self::Value {
386386
if scalar.is_bool() {
387387
return self.trunc(val, self.cx().type_i1());
388388
}
@@ -460,12 +460,12 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
460460
fn scalar_load_metadata<'a, 'll, 'tcx>(
461461
bx: &mut Builder<'a, 'll, 'tcx>,
462462
load: &'ll Value,
463-
scalar: &abi::Scalar,
463+
scalar: abi::Scalar,
464464
) {
465465
match scalar.value {
466466
abi::Int(..) => {
467467
if !scalar.is_always_valid_for(bx) {
468-
bx.range_metadata(load, &scalar.valid_range);
468+
bx.range_metadata(load, scalar.valid_range);
469469
}
470470
}
471471
abi::Pointer if !scalar.valid_range.contains(0) => {
@@ -488,17 +488,17 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
488488
}
489489
let llval = const_llval.unwrap_or_else(|| {
490490
let load = self.load(place.layout.llvm_type(self), place.llval, place.align);
491-
if let abi::Abi::Scalar(ref scalar) = place.layout.abi {
491+
if let abi::Abi::Scalar(scalar) = place.layout.abi {
492492
scalar_load_metadata(self, load, scalar);
493493
}
494494
load
495495
});
496496
OperandValue::Immediate(self.to_immediate(llval, place.layout))
497-
} else if let abi::Abi::ScalarPair(ref a, ref b) = place.layout.abi {
497+
} else if let abi::Abi::ScalarPair(a, b) = place.layout.abi {
498498
let b_offset = a.value.size(self).align_to(b.value.align(self).abi);
499499
let pair_ty = place.layout.llvm_type(self);
500500

501-
let mut load = |i, scalar: &abi::Scalar, align| {
501+
let mut load = |i, scalar: abi::Scalar, align| {
502502
let llptr = self.struct_gep(pair_ty, place.llval, i as u64);
503503
let llty = place.layout.scalar_pair_element_llvm_type(self, i, false);
504504
let load = self.load(llty, llptr, align);
@@ -554,7 +554,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
554554
next_bx
555555
}
556556

557-
fn range_metadata(&mut self, load: &'ll Value, range: &WrappingRange) {
557+
fn range_metadata(&mut self, load: &'ll Value, range: WrappingRange) {
558558
if self.sess().target.arch == "amdgpu" {
559559
// amdgpu/LLVM does something weird and thinks an i64 value is
560560
// split into a v2i32, halving the bitwidth LLVM expects,

compiler/rustc_codegen_llvm/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
228228
})
229229
}
230230

231-
fn scalar_to_backend(&self, cv: Scalar, layout: &abi::Scalar, llty: &'ll Type) -> &'ll Value {
231+
fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, llty: &'ll Type) -> &'ll Value {
232232
let bitsize = if layout.is_bool() { 1 } else { layout.value.size(self).bits() };
233233
match cv {
234234
Scalar::Int(ScalarInt::ZST) => {

compiler/rustc_codegen_llvm/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll
111111
Pointer::new(alloc_id, Size::from_bytes(ptr_offset)),
112112
&cx.tcx,
113113
),
114-
&Scalar { value: Primitive::Pointer, valid_range: WrappingRange { start: 0, end: !0 } },
114+
Scalar { value: Primitive::Pointer, valid_range: WrappingRange { start: 0, end: !0 } },
115115
cx.type_i8p_ext(address_space),
116116
));
117117
next_offset = offset + pointer_size;

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
16561656
Variants::Multiple {
16571657
tag_encoding:
16581658
TagEncoding::Niche { ref niche_variants, niche_start, dataful_variant },
1659-
ref tag,
1659+
tag,
16601660
ref variants,
16611661
tag_field,
16621662
} => {
@@ -2082,19 +2082,17 @@ fn prepare_enum_metadata(
20822082

20832083
let layout = cx.layout_of(enum_type);
20842084

2085-
if let (
2086-
&Abi::Scalar(_),
2087-
&Variants::Multiple { tag_encoding: TagEncoding::Direct, ref tag, .. },
2088-
) = (&layout.abi, &layout.variants)
2085+
if let (Abi::Scalar(_), Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, .. }) =
2086+
(layout.abi, &layout.variants)
20892087
{
20902088
return FinalMetadata(discriminant_type_metadata(tag.value));
20912089
}
20922090

20932091
if use_enum_fallback(cx) {
20942092
let discriminant_type_metadata = match layout.variants {
20952093
Variants::Single { .. } => None,
2096-
Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, ref tag, .. }
2097-
| Variants::Multiple { tag_encoding: TagEncoding::Direct, ref tag, .. } => {
2094+
Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, tag, .. }
2095+
| Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, .. } => {
20982096
Some(discriminant_type_metadata(tag.value))
20992097
}
21002098
};
@@ -2146,9 +2144,7 @@ fn prepare_enum_metadata(
21462144
// A single-variant enum has no discriminant.
21472145
Variants::Single { .. } => None,
21482146

2149-
Variants::Multiple {
2150-
tag_encoding: TagEncoding::Niche { .. }, ref tag, tag_field, ..
2151-
} => {
2147+
Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, tag, tag_field, .. } => {
21522148
// Find the integer type of the correct size.
21532149
let size = tag.value.size(cx);
21542150
let align = tag.value.align(cx);
@@ -2179,7 +2175,7 @@ fn prepare_enum_metadata(
21792175
}
21802176
}
21812177

2182-
Variants::Multiple { tag_encoding: TagEncoding::Direct, ref tag, tag_field, .. } => {
2178+
Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, tag_field, .. } => {
21832179
let discr_type = tag.value.to_ty(cx.tcx);
21842180
let (size, align) = cx.size_and_align_of(discr_type);
21852181

compiler/rustc_codegen_llvm/src/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
133133
}
134134
sym::va_arg => {
135135
match fn_abi.ret.layout.abi {
136-
abi::Abi::Scalar(ref scalar) => {
136+
abi::Abi::Scalar(scalar) => {
137137
match scalar.value {
138138
Primitive::Int(..) => {
139139
if self.cx().size_of(ret_ty).bytes() < 4 {

compiler/rustc_codegen_llvm/src/type_of.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn uncached_llvm_type<'a, 'tcx>(
2323
) -> &'a Type {
2424
match layout.abi {
2525
Abi::Scalar(_) => bug!("handled elsewhere"),
26-
Abi::Vector { ref element, count } => {
26+
Abi::Vector { element, count } => {
2727
let element = layout.scalar_llvm_type_at(cx, element, Size::ZERO);
2828
return cx.type_vector(element, count);
2929
}
@@ -177,7 +177,7 @@ pub trait LayoutLlvmExt<'tcx> {
177177
fn scalar_llvm_type_at<'a>(
178178
&self,
179179
cx: &CodegenCx<'a, 'tcx>,
180-
scalar: &Scalar,
180+
scalar: Scalar,
181181
offset: Size,
182182
) -> &'a Type;
183183
fn scalar_pair_element_llvm_type<'a>(
@@ -218,7 +218,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
218218
/// of that field's type - this is useful for taking the address of
219219
/// that field and ensuring the struct has the right alignment.
220220
fn llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type {
221-
if let Abi::Scalar(ref scalar) = self.abi {
221+
if let Abi::Scalar(scalar) = self.abi {
222222
// Use a different cache for scalars because pointers to DSTs
223223
// can be either fat or thin (data pointers of fat pointers).
224224
if let Some(&llty) = cx.scalar_lltypes.borrow().get(&self.ty) {
@@ -286,7 +286,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
286286
}
287287

288288
fn immediate_llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type {
289-
if let Abi::Scalar(ref scalar) = self.abi {
289+
if let Abi::Scalar(scalar) = self.abi {
290290
if scalar.is_bool() {
291291
return cx.type_i1();
292292
}
@@ -297,7 +297,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
297297
fn scalar_llvm_type_at<'a>(
298298
&self,
299299
cx: &CodegenCx<'a, 'tcx>,
300-
scalar: &Scalar,
300+
scalar: Scalar,
301301
offset: Size,
302302
) -> &'a Type {
303303
match scalar.value {
@@ -337,7 +337,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
337337
}
338338

339339
let (a, b) = match self.abi {
340-
Abi::ScalarPair(ref a, ref b) => (a, b),
340+
Abi::ScalarPair(a, b) => (a, b),
341341
_ => bug!("TyAndLayout::scalar_pair_element_llty({:?}): not applicable", self),
342342
};
343343
let scalar = [a, b][index];

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ fn push_debuginfo_type_name<'tcx>(
404404

405405
// calculate the range of values for the dataful variant
406406
let dataful_discriminant_range =
407-
&dataful_variant_layout.largest_niche.as_ref().unwrap().scalar.valid_range;
407+
dataful_variant_layout.largest_niche.unwrap().scalar.valid_range;
408408

409409
let min = dataful_discriminant_range.start;
410410
let min = tag.value.size(&tcx).truncate(min);

0 commit comments

Comments
 (0)