Skip to content

Commit 49d139c

Browse files
committed
Auto merge of #60693 - saleemjaffer:refactor_fntype_stuff, r=eddyb
refactor some `FnType` stuff to `rustc::ty::layout` Does work in the direction of #56166.
2 parents 7158ed9 + 44eb607 commit 49d139c

File tree

11 files changed

+419
-411
lines changed

11 files changed

+419
-411
lines changed

src/librustc/ty/layout.rs

+383
Large diffs are not rendered by default.

src/librustc_codegen_llvm/abi.rs

+5-386
Large diffs are not rendered by default.

src/librustc_codegen_llvm/builder.rs

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_codegen_ssa::traits::*;
1818
use rustc_codegen_ssa::base::to_immediate;
1919
use rustc_codegen_ssa::mir::operand::{OperandValue, OperandRef};
2020
use rustc_codegen_ssa::mir::place::PlaceRef;
21+
use rustc_target::spec::{HasTargetSpec, Target};
2122
use std::borrow::Cow;
2223
use std::ops::{Deref, Range};
2324
use std::ptr;
@@ -72,6 +73,12 @@ impl ty::layout::HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {
7273
}
7374
}
7475

76+
impl HasTargetSpec for Builder<'_, '_, 'tcx> {
77+
fn target_spec(&self) -> &Target {
78+
&self.cx.target_spec()
79+
}
80+
}
81+
7582
impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> {
7683
type Ty = Ty<'tcx>;
7784
type TyLayout = TyLayout<'tcx>;

src/librustc_codegen_llvm/declare.rs

+2-2
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, FnTypeExt};
16+
use crate::abi::{FnType, FnTypeLlvmExt};
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::LayoutOf;
22+
use rustc::ty::layout::{FnTypeExt, LayoutOf};
2323
use rustc::session::config::Sanitizer;
2424
use rustc_data_structures::small_c_str::SmallCStr;
2525
use rustc_codegen_ssa::traits::*;

src/librustc_codegen_llvm/type_.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_codegen_ssa::traits::*;
1010

1111
use crate::common;
1212
use crate::type_of::LayoutLlvmExt;
13-
use crate::abi::{LlvmType, FnTypeExt};
13+
use crate::abi::{LlvmType, FnTypeLlvmExt};
1414
use syntax::ast;
1515
use rustc::ty::Ty;
1616
use rustc::ty::layout::{self, Align, Size, TyLayout};

src/librustc_codegen_llvm/type_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::abi::{FnType, FnTypeExt};
1+
use crate::abi::{FnType};
22
use crate::common::*;
33
use crate::type_::Type;
44
use rustc::ty::{self, Ty, TypeFoldable};
5-
use rustc::ty::layout::{self, Align, LayoutOf, PointeeInfo, Size, TyLayout};
5+
use rustc::ty::layout::{self, Align, LayoutOf, FnTypeExt, PointeeInfo, Size, TyLayout};
66
use rustc_target::abi::{FloatTy, TyLayoutMethods};
77
use rustc_mir::monomorphize::item::DefPathBasedNames;
88
use rustc_codegen_ssa::traits::*;

src/librustc_codegen_ssa/mir/block.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::middle::lang_items;
22
use rustc::ty::{self, Ty, TypeFoldable};
3-
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt};
3+
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, FnTypeExt};
44
use rustc::mir::{self, Place, PlaceBase, Static, StaticKind};
55
use rustc::mir::interpret::InterpError;
66
use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode};
@@ -334,14 +334,14 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
334334
ty::ParamEnv::reveal_all(),
335335
&sig,
336336
);
337-
let fn_ty = bx.new_vtable(sig, &[]);
337+
let fn_ty = FnType::new_vtable(&bx, sig, &[]);
338338
let vtable = args[1];
339339
args = &args[..1];
340340
(meth::DESTRUCTOR.get_fn(&mut bx, vtable, &fn_ty), fn_ty)
341341
}
342342
_ => {
343343
(bx.get_fn(drop_fn),
344-
bx.fn_type_of_instance(&drop_fn))
344+
FnType::of_instance(&bx, &drop_fn))
345345
}
346346
};
347347
helper.do_call(self, &mut bx, fn_ty, drop_fn, args,
@@ -439,7 +439,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
439439
// Obtain the panic entry point.
440440
let def_id = common::langcall(bx.tcx(), Some(span), "", lang_item);
441441
let instance = ty::Instance::mono(bx.tcx(), def_id);
442-
let fn_ty = bx.fn_type_of_instance(&instance);
442+
let fn_ty = FnType::of_instance(&bx, &instance);
443443
let llfn = bx.get_fn(instance);
444444

445445
// Codegen the actual panic invoke/call.
@@ -518,15 +518,15 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
518518

519519
let fn_ty = match def {
520520
Some(ty::InstanceDef::Virtual(..)) => {
521-
bx.new_vtable(sig, &extra_args)
521+
FnType::new_vtable(&bx, sig, &extra_args)
522522
}
523523
Some(ty::InstanceDef::DropGlue(_, None)) => {
524524
// Empty drop glue; a no-op.
525525
let &(_, target) = destination.as_ref().unwrap();
526526
helper.funclet_br(self, &mut bx, target);
527527
return;
528528
}
529-
_ => bx.new_fn_type(sig, &extra_args)
529+
_ => FnType::new(&bx, sig, &extra_args)
530530
};
531531

532532
// Emit a panic or a no-op for `panic_if_uninhabited`.
@@ -556,7 +556,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
556556
let def_id =
557557
common::langcall(bx.tcx(), Some(span), "", lang_items::PanicFnLangItem);
558558
let instance = ty::Instance::mono(bx.tcx(), def_id);
559-
let fn_ty = bx.fn_type_of_instance(&instance);
559+
let fn_ty = FnType::of_instance(&bx, &instance);
560560
let llfn = bx.get_fn(instance);
561561

562562
// Codegen the actual panic invoke/call.

src/librustc_codegen_ssa/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc::ty::{self, Ty, TypeFoldable, UpvarSubsts};
2-
use rustc::ty::layout::{TyLayout, HasTyCtxt};
2+
use rustc::ty::layout::{TyLayout, HasTyCtxt, FnTypeExt};
33
use rustc::mir::{self, Mir};
44
use rustc::session::config::DebugInfo;
55
use rustc_mir::monomorphize::Instance;
@@ -202,7 +202,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
202202
) {
203203
assert!(!instance.substs.needs_infer());
204204

205-
let fn_ty = cx.new_fn_type(sig, &[]);
205+
let fn_ty = FnType::new(cx, sig, &[]);
206206
debug!("fn_ty: {:?}", fn_ty);
207207
let mut debug_context =
208208
cx.create_function_debug_context(instance, sig, llfn, mir);

src/librustc_codegen_ssa/traits/abi.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
use super::BackendTypes;
2-
use rustc::ty::{FnSig, Instance, Ty};
2+
use rustc::ty::{Ty};
33
use rustc_target::abi::call::FnType;
44

5-
pub trait AbiMethods<'tcx> {
6-
fn new_fn_type(&self, sig: FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> FnType<'tcx, Ty<'tcx>>;
7-
fn new_vtable(&self, sig: FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> FnType<'tcx, Ty<'tcx>>;
8-
fn fn_type_of_instance(&self, instance: &Instance<'tcx>) -> FnType<'tcx, Ty<'tcx>>;
9-
}
10-
115
pub trait AbiBuilderMethods<'tcx>: BackendTypes {
126
fn apply_attrs_callsite(&mut self, ty: &FnType<'tcx, Ty<'tcx>>, callsite: Self::Value);
137
fn get_param(&self, index: usize) -> Self::Value;

src/librustc_codegen_ssa/traits/builder.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::mir::place::PlaceRef;
1111
use crate::MemFlags;
1212
use rustc::ty::Ty;
1313
use rustc::ty::layout::{Align, Size, HasParamEnv};
14+
use rustc_target::spec::{HasTargetSpec};
1415
use std::ops::Range;
1516
use std::iter::TrustedLen;
1617

@@ -30,6 +31,7 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
3031
+ AsmBuilderMethods<'tcx>
3132
+ StaticBuilderMethods<'tcx>
3233
+ HasParamEnv<'tcx>
34+
+ HasTargetSpec
3335

3436
{
3537
fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Value, name: &'b str) -> Self;

src/librustc_codegen_ssa/traits/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod statics;
2727
mod type_;
2828
mod write;
2929

30-
pub use self::abi::{AbiBuilderMethods, AbiMethods};
30+
pub use self::abi::{AbiBuilderMethods};
3131
pub use self::asm::{AsmBuilderMethods, AsmMethods};
3232
pub use self::backend::{Backend, BackendTypes, ExtraBackendMethods};
3333
pub use self::builder::{BuilderMethods, OverflowOp};
@@ -41,7 +41,8 @@ pub use self::type_::{
4141
ArgTypeMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
4242
};
4343
pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
44-
use rustc::ty::layout::{HasParamEnv};
44+
use rustc::ty::layout::{HasParamEnv, HasTyCtxt};
45+
use rustc_target::spec::{HasTargetSpec};
4546

4647

4748
use std::fmt;
@@ -56,11 +57,12 @@ pub trait CodegenMethods<'tcx>:
5657
+ ConstMethods<'tcx>
5758
+ StaticMethods
5859
+ DebugInfoMethods<'tcx>
59-
+ AbiMethods<'tcx>
6060
+ DeclareMethods<'tcx>
6161
+ AsmMethods<'tcx>
6262
+ PreDefineMethods<'tcx>
6363
+ HasParamEnv<'tcx>
64+
+ HasTyCtxt<'tcx>
65+
+ HasTargetSpec
6466
{
6567
}
6668

@@ -71,11 +73,12 @@ impl<'tcx, T> CodegenMethods<'tcx> for T where
7173
+ ConstMethods<'tcx>
7274
+ StaticMethods
7375
+ DebugInfoMethods<'tcx>
74-
+ AbiMethods<'tcx>
7576
+ DeclareMethods<'tcx>
7677
+ AsmMethods<'tcx>
7778
+ PreDefineMethods<'tcx>
7879
+ HasParamEnv<'tcx>
80+
+ HasTyCtxt<'tcx>
81+
+ HasTargetSpec
7982
{
8083
}
8184

0 commit comments

Comments
 (0)