Skip to content

Commit

Permalink
removes AbiMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
saleemjaffer committed May 14, 2019
1 parent e1b3c79 commit 44eb607
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 39 deletions.
20 changes: 2 additions & 18 deletions src/librustc_codegen_llvm/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use rustc_target::abi::call::ArgType;
use rustc_codegen_ssa::traits::*;

use rustc_target::abi::{HasDataLayout, LayoutOf};
use rustc::ty::{self, Ty, Instance};
use rustc::ty::layout::{self, FnTypeExt};
use rustc::ty::{Ty};
use rustc::ty::layout::{self};

use libc::c_uint;

Expand Down Expand Up @@ -471,22 +471,6 @@ impl<'tcx> FnTypeLlvmExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
}
}

impl AbiMethods<'tcx> for CodegenCx<'ll, 'tcx> {
fn new_fn_type(&self, sig: ty::FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> FnType<'tcx, Ty<'tcx>> {
FnType::new(self, sig, extra_args)
}
fn new_vtable(
&self,
sig: ty::FnSig<'tcx>,
extra_args: &[Ty<'tcx>]
) -> FnType<'tcx, Ty<'tcx>> {
FnType::new_vtable(self, sig, extra_args)
}
fn fn_type_of_instance(&self, instance: &Instance<'tcx>) -> FnType<'tcx, Ty<'tcx>> {
FnType::of_instance(self, instance)
}
}

impl AbiBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
fn apply_attrs_callsite(
&mut self,
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use rustc_codegen_ssa::traits::*;
use rustc_codegen_ssa::base::to_immediate;
use rustc_codegen_ssa::mir::operand::{OperandValue, OperandRef};
use rustc_codegen_ssa::mir::place::PlaceRef;
use rustc_target::spec::{HasTargetSpec, Target};
use std::borrow::Cow;
use std::ops::{Deref, Range};
use std::ptr;
Expand Down Expand Up @@ -72,6 +73,12 @@ impl ty::layout::HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {
}
}

impl HasTargetSpec for Builder<'_, '_, 'tcx> {
fn target_spec(&self) -> &Target {
&self.cx.target_spec()
}
}

impl ty::layout::LayoutOf for Builder<'_, '_, 'tcx> {
type Ty = Ty<'tcx>;
type TyLayout = TyLayout<'tcx>;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let sig = self.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
debug!("declare_rust_fn (after region erasure) sig={:?}", sig);

let fty= FnType::new(self, sig, &[]);
let fty = FnType::new(self, sig, &[]);
let llfn = declare_raw_fn(self, name, fty.llvm_cconv(), fty.llvm_type(self));

if self.layout_of(sig.output()).abi.is_uninhabited() {
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc::middle::lang_items;
use rustc::ty::{self, Ty, TypeFoldable};
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt};
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, FnTypeExt};
use rustc::mir::{self, Place, PlaceBase, Static, StaticKind};
use rustc::mir::interpret::InterpError;
use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode};
Expand Down Expand Up @@ -334,14 +334,14 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
ty::ParamEnv::reveal_all(),
&sig,
);
let fn_ty = bx.new_vtable(sig, &[]);
let fn_ty = FnType::new_vtable(&bx, sig, &[]);
let vtable = args[1];
args = &args[..1];
(meth::DESTRUCTOR.get_fn(&mut bx, vtable, &fn_ty), fn_ty)
}
_ => {
(bx.get_fn(drop_fn),
bx.fn_type_of_instance(&drop_fn))
FnType::of_instance(&bx, &drop_fn))
}
};
helper.do_call(self, &mut bx, fn_ty, drop_fn, args,
Expand Down Expand Up @@ -439,7 +439,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// Obtain the panic entry point.
let def_id = common::langcall(bx.tcx(), Some(span), "", lang_item);
let instance = ty::Instance::mono(bx.tcx(), def_id);
let fn_ty = bx.fn_type_of_instance(&instance);
let fn_ty = FnType::of_instance(&bx, &instance);
let llfn = bx.get_fn(instance);

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

let fn_ty = match def {
Some(ty::InstanceDef::Virtual(..)) => {
bx.new_vtable(sig, &extra_args)
FnType::new_vtable(&bx, sig, &extra_args)
}
Some(ty::InstanceDef::DropGlue(_, None)) => {
// Empty drop glue; a no-op.
let &(_, target) = destination.as_ref().unwrap();
helper.funclet_br(self, &mut bx, target);
return;
}
_ => bx.new_fn_type(sig, &extra_args)
_ => FnType::new(&bx, sig, &extra_args)
};

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

// Codegen the actual panic invoke/call.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc::ty::{self, Ty, TypeFoldable, UpvarSubsts};
use rustc::ty::layout::{TyLayout, HasTyCtxt};
use rustc::ty::layout::{TyLayout, HasTyCtxt, FnTypeExt};
use rustc::mir::{self, Mir};
use rustc::session::config::DebugInfo;
use rustc_mir::monomorphize::Instance;
Expand Down Expand Up @@ -202,7 +202,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
) {
assert!(!instance.substs.needs_infer());

let fn_ty = cx.new_fn_type(sig, &[]);
let fn_ty = FnType::new(cx, sig, &[]);
debug!("fn_ty: {:?}", fn_ty);
let mut debug_context =
cx.create_function_debug_context(instance, sig, llfn, mir);
Expand Down
8 changes: 1 addition & 7 deletions src/librustc_codegen_ssa/traits/abi.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
use super::BackendTypes;
use rustc::ty::{FnSig, Instance, Ty};
use rustc::ty::{Ty};
use rustc_target::abi::call::FnType;

pub trait AbiMethods<'tcx> {
fn new_fn_type(&self, sig: FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> FnType<'tcx, Ty<'tcx>>;
fn new_vtable(&self, sig: FnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> FnType<'tcx, Ty<'tcx>>;
fn fn_type_of_instance(&self, instance: &Instance<'tcx>) -> FnType<'tcx, Ty<'tcx>>;
}

pub trait AbiBuilderMethods<'tcx>: BackendTypes {
fn apply_attrs_callsite(&mut self, ty: &FnType<'tcx, Ty<'tcx>>, callsite: Self::Value);
fn get_param(&self, index: usize) -> Self::Value;
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_codegen_ssa/traits/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::mir::place::PlaceRef;
use crate::MemFlags;
use rustc::ty::Ty;
use rustc::ty::layout::{Align, Size, HasParamEnv};
use rustc_target::spec::{HasTargetSpec};
use std::ops::Range;
use std::iter::TrustedLen;

Expand All @@ -30,6 +31,7 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
+ AsmBuilderMethods<'tcx>
+ StaticBuilderMethods<'tcx>
+ HasParamEnv<'tcx>
+ HasTargetSpec

{
fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Value, name: &'b str) -> Self;
Expand Down
11 changes: 7 additions & 4 deletions src/librustc_codegen_ssa/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod statics;
mod type_;
mod write;

pub use self::abi::{AbiBuilderMethods, AbiMethods};
pub use self::abi::{AbiBuilderMethods};
pub use self::asm::{AsmBuilderMethods, AsmMethods};
pub use self::backend::{Backend, BackendTypes, ExtraBackendMethods};
pub use self::builder::{BuilderMethods, OverflowOp};
Expand All @@ -41,7 +41,8 @@ pub use self::type_::{
ArgTypeMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
};
pub use self::write::{ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
use rustc::ty::layout::{HasParamEnv};
use rustc::ty::layout::{HasParamEnv, HasTyCtxt};
use rustc_target::spec::{HasTargetSpec};


use std::fmt;
Expand All @@ -56,11 +57,12 @@ pub trait CodegenMethods<'tcx>:
+ ConstMethods<'tcx>
+ StaticMethods
+ DebugInfoMethods<'tcx>
+ AbiMethods<'tcx>
+ DeclareMethods<'tcx>
+ AsmMethods<'tcx>
+ PreDefineMethods<'tcx>
+ HasParamEnv<'tcx>
+ HasTyCtxt<'tcx>
+ HasTargetSpec
{
}

Expand All @@ -71,11 +73,12 @@ impl<'tcx, T> CodegenMethods<'tcx> for T where
+ ConstMethods<'tcx>
+ StaticMethods
+ DebugInfoMethods<'tcx>
+ AbiMethods<'tcx>
+ DeclareMethods<'tcx>
+ AsmMethods<'tcx>
+ PreDefineMethods<'tcx>
+ HasParamEnv<'tcx>
+ HasTyCtxt<'tcx>
+ HasTargetSpec
{
}

Expand Down

0 comments on commit 44eb607

Please sign in to comment.