Skip to content

Commit 2e4da3c

Browse files
committed
Auto merge of #65938 - eddyb:fn-abi-rename, r=oli-obk
rustc_target: rename {Fn,Arg}Type to {Fn,Arg}Abi. I was trying to tweak the API of `FnType` (now `FnAbi`) and the name kept bothering me. `FnAbi` is to a function signature a bit like a layout is to a type, so the name still isn't perfect yet, but at least it doesn't have the misleading `Type` in it anymore. If this can't land I think I can continue my original refactor without it, so I'm not strongly attached to it. r? @nagisa cc @oli-obk
2 parents d2185f6 + 8b06209 commit 2e4da3c

35 files changed

+311
-311
lines changed

src/librustc/ty/layout.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_index::vec::{IndexVec, Idx};
2323
pub use rustc_target::abi::*;
2424
use rustc_target::spec::{HasTargetSpec, abi::Abi as SpecAbi};
2525
use rustc_target::abi::call::{
26-
ArgAttribute, ArgAttributes, ArgType, Conv, FnType, PassMode, Reg, RegKind
26+
ArgAttribute, ArgAttributes, ArgAbi, Conv, FnAbi, PassMode, Reg, RegKind
2727
};
2828

2929
pub trait IntegerExt {
@@ -2487,7 +2487,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for LayoutError<'tcx> {
24872487
}
24882488
}
24892489

2490-
pub trait FnTypeExt<'tcx, C>
2490+
pub trait FnAbiExt<'tcx, C>
24912491
where
24922492
C: LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
24932493
+ HasDataLayout
@@ -2502,12 +2502,12 @@ where
25022502
cx: &C,
25032503
sig: ty::FnSig<'tcx>,
25042504
extra_args: &[Ty<'tcx>],
2505-
mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgType<'tcx, Ty<'tcx>>,
2505+
mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgAbi<'tcx, Ty<'tcx>>,
25062506
) -> Self;
25072507
fn adjust_for_abi(&mut self, cx: &C, abi: SpecAbi);
25082508
}
25092509

2510-
impl<'tcx, C> FnTypeExt<'tcx, C> for call::FnType<'tcx, Ty<'tcx>>
2510+
impl<'tcx, C> FnAbiExt<'tcx, C> for call::FnAbi<'tcx, Ty<'tcx>>
25112511
where
25122512
C: LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>>
25132513
+ HasDataLayout
@@ -2520,15 +2520,15 @@ where
25202520
let sig = cx
25212521
.tcx()
25222522
.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
2523-
call::FnType::new(cx, sig, &[])
2523+
call::FnAbi::new(cx, sig, &[])
25242524
}
25252525

25262526
fn new(cx: &C, sig: ty::FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
2527-
call::FnType::new_internal(cx, sig, extra_args, |ty, _| ArgType::new(cx.layout_of(ty)))
2527+
call::FnAbi::new_internal(cx, sig, extra_args, |ty, _| ArgAbi::new(cx.layout_of(ty)))
25282528
}
25292529

25302530
fn new_vtable(cx: &C, sig: ty::FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
2531-
FnTypeExt::new_internal(cx, sig, extra_args, |ty, arg_idx| {
2531+
FnAbiExt::new_internal(cx, sig, extra_args, |ty, arg_idx| {
25322532
let mut layout = cx.layout_of(ty);
25332533
// Don't pass the vtable, it's not an argument of the virtual fn.
25342534
// Instead, pass just the data pointer, but give it the type `*const/mut dyn Trait`
@@ -2578,17 +2578,17 @@ where
25782578
layout = cx.layout_of(unit_pointer_ty);
25792579
layout.ty = fat_pointer_ty;
25802580
}
2581-
ArgType::new(layout)
2581+
ArgAbi::new(layout)
25822582
})
25832583
}
25842584

25852585
fn new_internal(
25862586
cx: &C,
25872587
sig: ty::FnSig<'tcx>,
25882588
extra_args: &[Ty<'tcx>],
2589-
mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgType<'tcx, Ty<'tcx>>,
2589+
mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgAbi<'tcx, Ty<'tcx>>,
25902590
) -> Self {
2591-
debug!("FnType::new_internal({:?}, {:?})", sig, extra_args);
2591+
debug!("FnAbi::new_internal({:?}, {:?})", sig, extra_args);
25922592

25932593
use rustc_target::spec::abi::Abi::*;
25942594
let conv = match cx.tcx().sess.target.target.adjust_abi(sig.abi) {
@@ -2741,7 +2741,7 @@ where
27412741
arg
27422742
};
27432743

2744-
let mut fn_ty = FnType {
2744+
let mut fn_abi = FnAbi {
27452745
ret: arg_of(sig.output(), None),
27462746
args: inputs
27472747
.iter()
@@ -2753,8 +2753,8 @@ where
27532753
c_variadic: sig.c_variadic,
27542754
conv,
27552755
};
2756-
fn_ty.adjust_for_abi(cx, sig.abi);
2757-
fn_ty
2756+
fn_abi.adjust_for_abi(cx, sig.abi);
2757+
fn_abi
27582758
}
27592759

27602760
fn adjust_for_abi(&mut self, cx: &C, abi: SpecAbi) {
@@ -2767,7 +2767,7 @@ where
27672767
|| abi == SpecAbi::RustIntrinsic
27682768
|| abi == SpecAbi::PlatformIntrinsic
27692769
{
2770-
let fixup = |arg: &mut ArgType<'tcx, Ty<'tcx>>| {
2770+
let fixup = |arg: &mut ArgAbi<'tcx, Ty<'tcx>>| {
27712771
if arg.is_ignore() {
27722772
return;
27732773
}

src/librustc_codegen_llvm/abi.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::type_of::{LayoutLlvmExt};
77
use rustc_codegen_ssa::MemFlags;
88
use rustc_codegen_ssa::mir::place::PlaceRef;
99
use rustc_codegen_ssa::mir::operand::OperandValue;
10-
use rustc_target::abi::call::ArgType;
10+
use rustc_target::abi::call::ArgAbi;
1111

1212
use rustc_codegen_ssa::traits::*;
1313

@@ -163,7 +163,7 @@ impl LlvmType for CastTarget {
163163
}
164164
}
165165

166-
pub trait ArgTypeExt<'ll, 'tcx> {
166+
pub trait ArgAbiExt<'ll, 'tcx> {
167167
fn memory_ty(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
168168
fn store(
169169
&self,
@@ -179,14 +179,14 @@ pub trait ArgTypeExt<'ll, 'tcx> {
179179
);
180180
}
181181

182-
impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
182+
impl ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
183183
/// Gets the LLVM type for a place of the original Rust type of
184184
/// this argument/return, i.e., the result of `type_of::type_of`.
185185
fn memory_ty(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type {
186186
self.layout.llvm_type(cx)
187187
}
188188

189-
/// Stores a direct/indirect value described by this ArgType into a
189+
/// Stores a direct/indirect value described by this ArgAbi into a
190190
/// place for the original Rust type of this argument/return.
191191
/// Can be used for both storing formal arguments into Rust variables
192192
/// or results of call/invoke instructions into their destinations.
@@ -202,7 +202,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
202202
if self.is_sized_indirect() {
203203
OperandValue::Ref(val, None, self.layout.align.abi).store(bx, dst)
204204
} else if self.is_unsized_indirect() {
205-
bug!("unsized ArgType must be handled through store_fn_arg");
205+
bug!("unsized ArgAbi must be handled through store_fn_arg");
206206
} else if let PassMode::Cast(cast) = self.mode {
207207
// FIXME(eddyb): Figure out when the simpler Store is safe, clang
208208
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
@@ -279,36 +279,36 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
279279
}
280280
}
281281

282-
impl ArgTypeMethods<'tcx> for Builder<'a, 'll, 'tcx> {
282+
impl ArgAbiMethods<'tcx> for Builder<'a, 'll, 'tcx> {
283283
fn store_fn_arg(
284284
&mut self,
285-
ty: &ArgType<'tcx, Ty<'tcx>>,
285+
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
286286
idx: &mut usize, dst: PlaceRef<'tcx, Self::Value>
287287
) {
288-
ty.store_fn_arg(self, idx, dst)
288+
arg_abi.store_fn_arg(self, idx, dst)
289289
}
290-
fn store_arg_ty(
290+
fn store_arg(
291291
&mut self,
292-
ty: &ArgType<'tcx, Ty<'tcx>>,
292+
arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
293293
val: &'ll Value,
294294
dst: PlaceRef<'tcx, &'ll Value>
295295
) {
296-
ty.store(self, val, dst)
296+
arg_abi.store(self, val, dst)
297297
}
298-
fn memory_ty(&self, ty: &ArgType<'tcx, Ty<'tcx>>) -> &'ll Type {
299-
ty.memory_ty(self)
298+
fn arg_memory_ty(&self, arg_abi: &ArgAbi<'tcx, Ty<'tcx>>) -> &'ll Type {
299+
arg_abi.memory_ty(self)
300300
}
301301
}
302302

303-
pub trait FnTypeLlvmExt<'tcx> {
303+
pub trait FnAbiLlvmExt<'tcx> {
304304
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
305305
fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
306306
fn llvm_cconv(&self) -> llvm::CallConv;
307307
fn apply_attrs_llfn(&self, cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value);
308308
fn apply_attrs_callsite(&self, bx: &mut Builder<'a, 'll, 'tcx>, callsite: &'ll Value);
309309
}
310310

311-
impl<'tcx> FnTypeLlvmExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
311+
impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
312312
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type {
313313
let args_capacity: usize = self.args.iter().map(|arg|
314314
if arg.pad.is_some() { 1 } else { 0 } +
@@ -478,10 +478,10 @@ impl<'tcx> FnTypeLlvmExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
478478
impl AbiBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
479479
fn apply_attrs_callsite(
480480
&mut self,
481-
ty: &FnType<'tcx, Ty<'tcx>>,
481+
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
482482
callsite: Self::Value
483483
) {
484-
ty.apply_attrs_callsite(self, callsite)
484+
fn_abi.apply_attrs_callsite(self, callsite)
485485
}
486486

487487
fn get_param(&self, index: usize) -> Self::Value {

src/librustc_codegen_llvm/declare.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
1414
use crate::llvm;
1515
use crate::llvm::AttributePlace::Function;
16-
use crate::abi::{FnType, FnTypeLlvmExt};
16+
use crate::abi::{FnAbi, FnAbiLlvmExt};
1717
use crate::attributes;
1818
use crate::context::CodegenCx;
1919
use crate::type_::Type;
2020
use crate::value::Value;
2121
use rustc::ty::{self, PolyFnSig};
22-
use rustc::ty::layout::{FnTypeExt, LayoutOf};
22+
use rustc::ty::layout::{FnAbiExt, LayoutOf};
2323
use rustc::session::config::Sanitizer;
2424
use rustc_data_structures::small_c_str::SmallCStr;
2525
use rustc_codegen_ssa::traits::*;
@@ -100,14 +100,14 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {
100100
let sig = self.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
101101
debug!("declare_rust_fn (after region erasure) sig={:?}", sig);
102102

103-
let fty = FnType::new(self, sig, &[]);
104-
let llfn = declare_raw_fn(self, name, fty.llvm_cconv(), fty.llvm_type(self));
103+
let fn_abi = FnAbi::new(self, sig, &[]);
104+
let llfn = declare_raw_fn(self, name, fn_abi.llvm_cconv(), fn_abi.llvm_type(self));
105105

106106
if self.layout_of(sig.output()).abi.is_uninhabited() {
107107
llvm::Attribute::NoReturn.apply_llfn(Function, llfn);
108108
}
109109

110-
fty.apply_attrs_llfn(self, llfn);
110+
fn_abi.apply_attrs_llfn(self, llfn);
111111

112112
llfn
113113
}

src/librustc_codegen_llvm/intrinsic.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::attributes;
22
use crate::llvm;
33
use crate::llvm_util;
4-
use crate::abi::{Abi, FnType, LlvmType, PassMode};
4+
use crate::abi::{Abi, FnAbi, LlvmType, PassMode};
55
use crate::context::CodegenCx;
66
use crate::type_::Type;
77
use crate::type_of::LayoutLlvmExt;
@@ -84,7 +84,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
8484
fn codegen_intrinsic_call(
8585
&mut self,
8686
instance: ty::Instance<'tcx>,
87-
fn_ty: &FnType<'tcx, Ty<'tcx>>,
87+
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
8888
args: &[OperandRef<'tcx, &'ll Value>],
8989
llresult: &'ll Value,
9090
span: Span,
@@ -104,7 +104,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
104104
let name = &*tcx.item_name(def_id).as_str();
105105

106106
let llret_ty = self.layout_of(ret_ty).llvm_type(self);
107-
let result = PlaceRef::new_sized(llresult, fn_ty.ret.layout);
107+
let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout);
108108

109109
let simple = get_simple_intrinsic(self, name);
110110
let llval = match name {
@@ -147,7 +147,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
147147
self.call(intrinsic, &[args[0].immediate(), args[1].immediate()], None)
148148
}
149149
"va_arg" => {
150-
match fn_ty.ret.layout.abi {
150+
match fn_abi.ret.layout.abi {
151151
layout::Abi::Scalar(ref scalar) => {
152152
match scalar.value {
153153
Primitive::Int(..) => {
@@ -276,7 +276,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
276276
"volatile_load" | "unaligned_volatile_load" => {
277277
let tp_ty = substs.type_at(0);
278278
let mut ptr = args[0].immediate();
279-
if let PassMode::Cast(ty) = fn_ty.ret.mode {
279+
if let PassMode::Cast(ty) = fn_abi.ret.mode {
280280
ptr = self.pointercast(ptr, self.type_ptr_to(ty.llvm_type(self)));
281281
}
282282
let load = self.volatile_load(ptr);
@@ -715,8 +715,8 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
715715
_ => bug!("unknown intrinsic '{}'", name),
716716
};
717717

718-
if !fn_ty.ret.is_ignore() {
719-
if let PassMode::Cast(ty) = fn_ty.ret.mode {
718+
if !fn_abi.ret.is_ignore() {
719+
if let PassMode::Cast(ty) = fn_abi.ret.mode {
720720
let ptr_llty = self.type_ptr_to(ty.llvm_type(self));
721721
let ptr = self.pointercast(result.llval, ptr_llty);
722722
self.store(llval, ptr, result.align);

src/librustc_codegen_llvm/type_.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use rustc_codegen_ssa::traits::*;
88

99
use crate::common;
1010
use crate::type_of::LayoutLlvmExt;
11-
use crate::abi::{LlvmType, FnTypeLlvmExt};
11+
use crate::abi::{LlvmType, FnAbiLlvmExt};
1212
use syntax::ast;
1313
use rustc::ty::Ty;
1414
use rustc::ty::layout::{self, Align, Size, TyLayout};
15-
use rustc_target::abi::call::{CastTarget, FnType, Reg};
15+
use rustc_target::abi::call::{CastTarget, FnAbi, Reg};
1616
use rustc_data_structures::small_c_str::SmallCStr;
1717
use rustc_codegen_ssa::common::TypeKind;
1818

@@ -243,7 +243,7 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
243243

244244
fn type_ptr_to(&self, ty: &'ll Type) -> &'ll Type {
245245
assert_ne!(self.type_kind(ty), TypeKind::Function,
246-
"don't call ptr_to on function types, use ptr_to_llvm_type on FnType instead");
246+
"don't call ptr_to on function types, use ptr_to_llvm_type on FnAbi instead");
247247
ty.ptr_to()
248248
}
249249

@@ -336,8 +336,8 @@ impl LayoutTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
336336
fn cast_backend_type(&self, ty: &CastTarget) -> &'ll Type {
337337
ty.llvm_type(self)
338338
}
339-
fn fn_ptr_backend_type(&self, ty: &FnType<'tcx, Ty<'tcx>>) -> &'ll Type {
340-
ty.ptr_to_llvm_type(self)
339+
fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> &'ll Type {
340+
fn_abi.ptr_to_llvm_type(self)
341341
}
342342
fn reg_backend_type(&self, ty: &Reg) -> &'ll Type {
343343
ty.llvm_type(self)

src/librustc_codegen_llvm/type_of.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::abi::{FnType};
1+
use crate::abi::{FnAbi};
22
use crate::common::*;
33
use crate::type_::Type;
44
use rustc::ty::{self, Ty, TypeFoldable};
5-
use rustc::ty::layout::{self, Align, LayoutOf, FnTypeExt, PointeeInfo, Size, TyLayout};
5+
use rustc::ty::layout::{self, Align, LayoutOf, FnAbiExt, PointeeInfo, Size, TyLayout};
66
use rustc_target::abi::{FloatTy, TyLayoutMethods};
77
use rustc::ty::print::obsolete::DefPathBasedNames;
88
use rustc_codegen_ssa::traits::*;
@@ -239,7 +239,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
239239
ty::ParamEnv::reveal_all(),
240240
&sig,
241241
);
242-
cx.fn_ptr_backend_type(&FnType::new(cx, sig, &[]))
242+
cx.fn_ptr_backend_type(&FnAbi::new(cx, sig, &[]))
243243
}
244244
_ => self.scalar_llvm_type_at(cx, scalar, Size::ZERO)
245245
};

src/librustc_codegen_ssa/meth.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_target::abi::call::FnType;
1+
use rustc_target::abi::call::FnAbi;
22

33
use crate::traits::*;
44

@@ -20,14 +20,14 @@ impl<'a, 'tcx> VirtualIndex {
2020
self,
2121
bx: &mut Bx,
2222
llvtable: Bx::Value,
23-
fn_ty: &FnType<'tcx, Ty<'tcx>>
23+
fn_abi: &FnAbi<'tcx, Ty<'tcx>>
2424
) -> Bx::Value {
2525
// Load the data pointer from the object.
2626
debug!("get_fn({:?}, {:?})", llvtable, self);
2727

2828
let llvtable = bx.pointercast(
2929
llvtable,
30-
bx.type_ptr_to(bx.fn_ptr_backend_type(fn_ty))
30+
bx.type_ptr_to(bx.fn_ptr_backend_type(fn_abi))
3131
);
3232
let ptr_align = bx.tcx().data_layout.pointer_align.abi;
3333
let gep = bx.inbounds_gep(llvtable, &[bx.const_usize(self.0)]);

0 commit comments

Comments
 (0)