Skip to content

Commit 0e166bb

Browse files
committed
Remove a lot of methods from *TypeMethods
1 parent b0ee1f7 commit 0e166bb

File tree

3 files changed

+92
-114
lines changed

3 files changed

+92
-114
lines changed

src/librustc_codegen_llvm/type_.rs

Lines changed: 84 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use rustc_codegen_ssa::traits::*;
1111
use crate::common;
1212
use crate::type_of::LayoutLlvmExt;
1313
use crate::abi::{LlvmType, FnTypeExt};
14+
use syntax::ast;
1415
use rustc::ty::Ty;
15-
use rustc::ty::layout::TyLayout;
16+
use rustc::ty::layout::{self, Align, Size, TyLayout};
1617
use rustc_target::abi::call::{CastTarget, FnType, Reg};
1718
use rustc_data_structures::small_c_str::SmallCStr;
1819
use rustc_codegen_ssa::common::TypeKind;
@@ -50,21 +51,99 @@ impl CodegenCx<'ll, 'tcx> {
5051
els.len() as c_uint, packed as Bool)
5152
}
5253
}
53-
}
5454

55-
impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
56-
fn type_void(&self) -> &'ll Type {
55+
crate fn type_void(&self) -> &'ll Type {
5756
unsafe {
5857
llvm::LLVMVoidTypeInContext(self.llcx)
5958
}
6059
}
6160

62-
fn type_metadata(&self) -> &'ll Type {
61+
crate fn type_metadata(&self) -> &'ll Type {
6362
unsafe {
6463
llvm::LLVMRustMetadataTypeInContext(self.llcx)
6564
}
6665
}
6766

67+
///x Creates an integer type with the given number of bits, e.g., i24
68+
crate fn type_ix(&self, num_bits: u64) -> &'ll Type {
69+
unsafe {
70+
llvm::LLVMIntTypeInContext(self.llcx, num_bits as c_uint)
71+
}
72+
}
73+
74+
crate fn type_x86_mmx(&self) -> &'ll Type {
75+
unsafe {
76+
llvm::LLVMX86MMXTypeInContext(self.llcx)
77+
}
78+
}
79+
80+
crate fn type_vector(&self, ty: &'ll Type, len: u64) -> &'ll Type {
81+
unsafe {
82+
llvm::LLVMVectorType(ty, len as c_uint)
83+
}
84+
}
85+
86+
crate fn func_params_types(&self, ty: &'ll Type) -> Vec<&'ll Type> {
87+
unsafe {
88+
let n_args = llvm::LLVMCountParamTypes(ty) as usize;
89+
let mut args = Vec::with_capacity(n_args);
90+
llvm::LLVMGetParamTypes(ty, args.as_mut_ptr());
91+
args.set_len(n_args);
92+
args
93+
}
94+
}
95+
96+
crate fn type_bool(&self) -> &'ll Type {
97+
self.type_i8()
98+
}
99+
100+
crate fn type_int_from_ty(&self, t: ast::IntTy) -> &'ll Type {
101+
match t {
102+
ast::IntTy::Isize => self.type_isize(),
103+
ast::IntTy::I8 => self.type_i8(),
104+
ast::IntTy::I16 => self.type_i16(),
105+
ast::IntTy::I32 => self.type_i32(),
106+
ast::IntTy::I64 => self.type_i64(),
107+
ast::IntTy::I128 => self.type_i128(),
108+
}
109+
}
110+
111+
crate fn type_uint_from_ty(&self, t: ast::UintTy) -> &'ll Type {
112+
match t {
113+
ast::UintTy::Usize => self.type_isize(),
114+
ast::UintTy::U8 => self.type_i8(),
115+
ast::UintTy::U16 => self.type_i16(),
116+
ast::UintTy::U32 => self.type_i32(),
117+
ast::UintTy::U64 => self.type_i64(),
118+
ast::UintTy::U128 => self.type_i128(),
119+
}
120+
}
121+
122+
crate fn type_float_from_ty(&self, t: ast::FloatTy) -> &'ll Type {
123+
match t {
124+
ast::FloatTy::F32 => self.type_f32(),
125+
ast::FloatTy::F64 => self.type_f64(),
126+
}
127+
}
128+
129+
crate fn type_pointee_for_align(&self, align: Align) -> &'ll Type {
130+
// FIXME(eddyb) We could find a better approximation if ity.align < align.
131+
let ity = layout::Integer::approximate_align(self, align);
132+
self.type_from_integer(ity)
133+
}
134+
135+
/// Return a LLVM type that has at most the required alignment,
136+
/// and exactly the required size, as a best-effort padding array.
137+
crate fn type_padding_filler(&self, size: Size, align: Align) -> &'ll Type {
138+
let unit = layout::Integer::approximate_align(self, align);
139+
let size = size.bytes();
140+
let unit_size = unit.size().bytes();
141+
assert_eq!(size % unit_size, 0);
142+
self.type_array(self.type_from_integer(unit), size / unit_size)
143+
}
144+
}
145+
146+
impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
68147
fn type_i1(&self) -> &'ll Type {
69148
unsafe {
70149
llvm::LLVMInt1TypeInContext(self.llcx)
@@ -102,12 +181,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
102181
}
103182
}
104183

105-
fn type_ix(&self, num_bits: u64) -> &'ll Type {
106-
unsafe {
107-
llvm::LLVMIntTypeInContext(self.llcx, num_bits as c_uint)
108-
}
109-
}
110-
111184
fn type_isize(&self) -> &'ll Type {
112185
self.isize_ty
113186
}
@@ -124,12 +197,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
124197
}
125198
}
126199

127-
fn type_x86_mmx(&self) -> &'ll Type {
128-
unsafe {
129-
llvm::LLVMX86MMXTypeInContext(self.llcx)
130-
}
131-
}
132-
133200
fn type_func(
134201
&self,
135202
args: &[&'ll Type],
@@ -171,12 +238,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
171238
}
172239
}
173240

174-
fn type_vector(&self, ty: &'ll Type, len: u64) -> &'ll Type {
175-
unsafe {
176-
llvm::LLVMVectorType(ty, len as c_uint)
177-
}
178-
}
179-
180241
fn type_kind(&self, ty: &'ll Type) -> TypeKind {
181242
unsafe {
182243
llvm::LLVMRustGetTypeKind(ty).to_generic()
@@ -201,16 +262,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
201262
}
202263
}
203264

204-
fn func_params_types(&self, ty: &'ll Type) -> Vec<&'ll Type> {
205-
unsafe {
206-
let n_args = llvm::LLVMCountParamTypes(ty) as usize;
207-
let mut args = Vec::with_capacity(n_args);
208-
llvm::LLVMGetParamTypes(ty, args.as_mut_ptr());
209-
args.set_len(n_args);
210-
args
211-
}
212-
}
213-
214265
fn float_width(&self, ty: &'ll Type) -> usize {
215266
match self.type_kind(ty) {
216267
TypeKind::Float => 32,
@@ -288,9 +339,6 @@ impl LayoutTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
288339
fn cast_backend_type(&self, ty: &CastTarget) -> &'ll Type {
289340
ty.llvm_type(self)
290341
}
291-
fn fn_backend_type(&self, ty: &FnType<'tcx, Ty<'tcx>>) -> &'ll Type {
292-
ty.llvm_type(self)
293-
}
294342
fn fn_ptr_backend_type(&self, ty: &FnType<'tcx, Ty<'tcx>>) -> &'ll Type {
295343
ty.ptr_to_llvm_type(self)
296344
}

src/librustc_codegen_ssa/common.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(non_camel_case_types, non_snake_case)]
22

3-
use rustc::ty::{self, Ty, TyCtxt};
4-
use syntax_pos::{DUMMY_SP, Span};
3+
use rustc::ty::{Ty, TyCtxt};
4+
use syntax_pos::Span;
55

66
use rustc::hir::def_id::DefId;
77
use rustc::middle::lang_items::LangItem;
@@ -11,18 +11,6 @@ use crate::traits::*;
1111
use rustc::hir;
1212
use crate::traits::BuilderMethods;
1313

14-
pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
15-
ty.needs_drop(tcx, ty::ParamEnv::reveal_all())
16-
}
17-
18-
pub fn type_is_sized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
19-
ty.is_sized(tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all())
20-
}
21-
22-
pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
23-
ty.is_freeze(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP)
24-
}
25-
2614
pub enum IntPredicate {
2715
IntEQ,
2816
IntNE,

src/librustc_codegen_ssa/traits/type_.rs

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,38 @@
11
use super::misc::MiscMethods;
22
use super::Backend;
33
use super::HasCodegen;
4-
use crate::common::{self, TypeKind};
4+
use crate::common::TypeKind;
55
use crate::mir::place::PlaceRef;
6-
use rustc::ty::layout::{self, Align, Size, TyLayout};
76
use rustc::ty::{self, Ty};
7+
use rustc::ty::layout::{self, TyLayout};
88
use rustc_target::abi::call::{ArgType, CastTarget, FnType, Reg};
9-
use syntax::ast;
9+
use syntax_pos::DUMMY_SP;
1010

1111
// This depends on `Backend` and not `BackendTypes`, because consumers will probably want to use
1212
// `LayoutOf` or `HasTyCtxt`. This way, they don't have to add a constraint on it themselves.
1313
pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
14-
fn type_void(&self) -> Self::Type;
15-
fn type_metadata(&self) -> Self::Type;
1614
fn type_i1(&self) -> Self::Type;
1715
fn type_i8(&self) -> Self::Type;
1816
fn type_i16(&self) -> Self::Type;
1917
fn type_i32(&self) -> Self::Type;
2018
fn type_i64(&self) -> Self::Type;
2119
fn type_i128(&self) -> Self::Type;
22-
23-
// Creates an integer type with the given number of bits, e.g., i24
24-
fn type_ix(&self, num_bits: u64) -> Self::Type;
2520
fn type_isize(&self) -> Self::Type;
2621

2722
fn type_f32(&self) -> Self::Type;
2823
fn type_f64(&self) -> Self::Type;
29-
fn type_x86_mmx(&self) -> Self::Type;
3024

3125
fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
3226
fn type_variadic_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;
3327
fn type_struct(&self, els: &[Self::Type], packed: bool) -> Self::Type;
3428
fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type;
35-
fn type_vector(&self, ty: Self::Type, len: u64) -> Self::Type;
3629
fn type_kind(&self, ty: Self::Type) -> TypeKind;
3730
fn type_ptr_to(&self, ty: Self::Type) -> Self::Type;
3831
fn element_type(&self, ty: Self::Type) -> Self::Type;
3932

4033
/// Returns the number of elements in `self` if it is a LLVM vector type.
4134
fn vector_length(&self, ty: Self::Type) -> usize;
4235

43-
fn func_params_types(&self, ty: Self::Type) -> Vec<Self::Type>;
4436
fn float_width(&self, ty: Self::Type) -> usize;
4537

4638
/// Retrieves the bit width of the integer type `self`.
@@ -50,10 +42,6 @@ pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
5042
}
5143

5244
pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
53-
fn type_bool(&self) -> Self::Type {
54-
self.type_i8()
55-
}
56-
5745
fn type_i8p(&self) -> Self::Type {
5846
self.type_ptr_to(self.type_i8())
5947
}
@@ -67,35 +55,6 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
6755
}
6856
}
6957

70-
fn type_int_from_ty(&self, t: ast::IntTy) -> Self::Type {
71-
match t {
72-
ast::IntTy::Isize => self.type_isize(),
73-
ast::IntTy::I8 => self.type_i8(),
74-
ast::IntTy::I16 => self.type_i16(),
75-
ast::IntTy::I32 => self.type_i32(),
76-
ast::IntTy::I64 => self.type_i64(),
77-
ast::IntTy::I128 => self.type_i128(),
78-
}
79-
}
80-
81-
fn type_uint_from_ty(&self, t: ast::UintTy) -> Self::Type {
82-
match t {
83-
ast::UintTy::Usize => self.type_isize(),
84-
ast::UintTy::U8 => self.type_i8(),
85-
ast::UintTy::U16 => self.type_i16(),
86-
ast::UintTy::U32 => self.type_i32(),
87-
ast::UintTy::U64 => self.type_i64(),
88-
ast::UintTy::U128 => self.type_i128(),
89-
}
90-
}
91-
92-
fn type_float_from_ty(&self, t: ast::FloatTy) -> Self::Type {
93-
match t {
94-
ast::FloatTy::F32 => self.type_f32(),
95-
ast::FloatTy::F64 => self.type_f64(),
96-
}
97-
}
98-
9958
fn type_from_integer(&self, i: layout::Integer) -> Self::Type {
10059
use rustc::ty::layout::Integer::*;
10160
match i {
@@ -107,32 +66,16 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
10766
}
10867
}
10968

110-
fn type_pointee_for_align(&self, align: Align) -> Self::Type {
111-
// FIXME(eddyb) We could find a better approximation if ity.align < align.
112-
let ity = layout::Integer::approximate_align(self, align);
113-
self.type_from_integer(ity)
114-
}
115-
116-
/// Return a LLVM type that has at most the required alignment,
117-
/// and exactly the required size, as a best-effort padding array.
118-
fn type_padding_filler(&self, size: Size, align: Align) -> Self::Type {
119-
let unit = layout::Integer::approximate_align(self, align);
120-
let size = size.bytes();
121-
let unit_size = unit.size().bytes();
122-
assert_eq!(size % unit_size, 0);
123-
self.type_array(self.type_from_integer(unit), size / unit_size)
124-
}
125-
12669
fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
127-
common::type_needs_drop(self.tcx(), ty)
70+
ty.needs_drop(self.tcx(), ty::ParamEnv::reveal_all())
12871
}
12972

13073
fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
131-
common::type_is_sized(self.tcx(), ty)
74+
ty.is_sized(self.tcx().at(DUMMY_SP), ty::ParamEnv::reveal_all())
13275
}
13376

13477
fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
135-
common::type_is_freeze(self.tcx(), ty)
78+
ty.is_freeze(self.tcx(), ty::ParamEnv::reveal_all(), DUMMY_SP)
13679
}
13780

13881
fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
@@ -155,7 +98,6 @@ impl<T> DerivedTypeMethods<'tcx> for T where Self: BaseTypeMethods<'tcx> + MiscM
15598
pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
15699
fn backend_type(&self, layout: TyLayout<'tcx>) -> Self::Type;
157100
fn cast_backend_type(&self, ty: &CastTarget) -> Self::Type;
158-
fn fn_backend_type(&self, ty: &FnType<'tcx, Ty<'tcx>>) -> Self::Type;
159101
fn fn_ptr_backend_type(&self, ty: &FnType<'tcx, Ty<'tcx>>) -> Self::Type;
160102
fn reg_backend_type(&self, ty: &Reg) -> Self::Type;
161103
fn immediate_backend_type(&self, layout: TyLayout<'tcx>) -> Self::Type;

0 commit comments

Comments
 (0)