Skip to content

Commit afd940a

Browse files
committed
Added default impl for DerivedTypeMethods + empty impl for Cranelift BaseTypeMethods
1 parent 376f4fe commit afd940a

23 files changed

+353
-296
lines changed

src/librustc_codegen_llvm/abi.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,11 @@ pub trait FnTypeExt<'tcx> {
325325
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx, &'ll Value>) -> &'ll Type;
326326
fn llvm_cconv(&self) -> llvm::CallConv;
327327
fn apply_attrs_llfn(&self, llfn: &'ll Value);
328-
fn apply_attrs_callsite(&self, bx: &mut Builder<'a, 'll, 'tcx, &'ll Value>, callsite: &'ll Value);
328+
fn apply_attrs_callsite(
329+
&self,
330+
bx: &mut Builder<'a, 'll, 'tcx, &'ll Value>,
331+
callsite: &'ll Value
332+
);
329333
}
330334

331335
impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
@@ -728,7 +732,11 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
728732
}
729733
}
730734

731-
fn apply_attrs_callsite(&self, bx: &mut Builder<'a, 'll, 'tcx, &'ll Value>, callsite: &'ll Value) {
735+
fn apply_attrs_callsite(
736+
&self,
737+
bx: &mut Builder<'a, 'll, 'tcx, &'ll Value>,
738+
callsite: &'ll Value
739+
) {
732740
let mut i = 0;
733741
let mut apply = |attrs: &ArgAttributes| {
734742
attrs.apply_callsite(llvm::AttributePlace::Argument(i), callsite);

src/librustc_codegen_llvm/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl MiscMethods<'ll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll Value> {
470470
}
471471
}
472472

473-
impl<'ll, 'tcx: 'll> CodegenMethods<'ll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll Value> {}
473+
impl<'a, 'll: 'a, 'tcx: 'll> CodegenMethods<'a, 'll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll Value> {}
474474

475475
impl IntrinsicDeclarationMethods<'b> for CodegenCx<'b, 'tcx, &'b Value> {
476476
fn get_intrinsic(&self, key: &str) -> &'b Value {

src/librustc_codegen_llvm/debuginfo/gdb.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ use syntax::attr;
2323

2424
/// Inserts a side-effect free instruction sequence that makes sure that the
2525
/// .debug_gdb_scripts global is referenced, so it isn't removed by the linker.
26-
pub fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Builder<'_, 'll, '_, &'ll Value>) {
26+
pub fn insert_reference_to_gdb_debug_scripts_section_global(
27+
bx: &mut Builder<'_, 'll, '_, &'ll Value>
28+
) {
2729
if needs_gdb_debug_scripts_section(bx.cx()) {
2830
let gdb_debug_scripts_section = get_or_insert_gdb_debug_scripts_section_global(bx.cx());
2931
// Load just the first byte as that's all that's necessary to force

src/librustc_codegen_llvm/type_.rs

+8-126
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ use context::CodegenCx;
1818
use value::Value;
1919
use rustc_codegen_ssa::interfaces::*;
2020

21-
22-
use syntax::ast;
23-
use rustc::ty::layout::{self, Align, Size};
2421
use rustc::util::nodemap::FxHashMap;
25-
use rustc::ty::{self, Ty, TyCtxt};
22+
use rustc::ty::{Ty, TyCtxt};
2623
use rustc::ty::layout::TyLayout;
2724
use rustc_target::abi::call::{CastTarget, FnType, Reg};
2825
use rustc_data_structures::small_c_str::SmallCStr;
2926
use common;
30-
use rustc_codegen_ssa;
3127
use rustc_codegen_ssa::common::TypeKind;
3228
use type_of::LayoutLlvmExt;
3329
use abi::{LlvmType, FnTypeExt};
@@ -111,6 +107,10 @@ impl BaseTypeMethods<'ll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll Value> {
111107
}
112108
}
113109

110+
fn type_isize(&self) -> &'ll Type {
111+
self.isize_ty
112+
}
113+
114114
fn type_f32(&self) -> &'ll Type {
115115
unsafe {
116116
llvm::LLVMFloatTypeInContext(&self.llcx)
@@ -279,126 +279,8 @@ impl Type {
279279
}
280280
}
281281

282-
impl DerivedTypeMethods<'ll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll Value> {
283-
284-
fn type_bool(&self) -> &'ll Type {
285-
&self.type_i8()
286-
}
287-
288-
fn type_char(&self) -> &'ll Type {
289-
&self.type_i32()
290-
}
291-
292-
fn type_i8p(&self) -> &'ll Type {
293-
&self.type_ptr_to(&self.type_i8())
294-
}
295-
296-
fn type_isize(&self) -> &'ll Type {
297-
&self.isize_ty
298-
}
299-
300-
fn type_int(&self) -> &'ll Type {
301-
match &self.sess().target.target.target_c_int_width[..] {
302-
"16" => &self.type_i16(),
303-
"32" => &self.type_i32(),
304-
"64" => &self.type_i64(),
305-
width => bug!("Unsupported target_c_int_width: {}", width),
306-
}
307-
}
308-
309-
fn type_int_from_ty(
310-
&self,
311-
t: ast::IntTy
312-
) -> &'ll Type {
313-
match t {
314-
ast::IntTy::Isize => &self.isize_ty,
315-
ast::IntTy::I8 => &self.type_i8(),
316-
ast::IntTy::I16 => &self.type_i16(),
317-
ast::IntTy::I32 => &self.type_i32(),
318-
ast::IntTy::I64 => &self.type_i64(),
319-
ast::IntTy::I128 => &self.type_i128(),
320-
}
321-
}
322-
323-
fn type_uint_from_ty(
324-
&self,
325-
t: ast::UintTy
326-
) -> &'ll Type {
327-
match t {
328-
ast::UintTy::Usize => &self.isize_ty,
329-
ast::UintTy::U8 => &self.type_i8(),
330-
ast::UintTy::U16 => &self.type_i16(),
331-
ast::UintTy::U32 => &self.type_i32(),
332-
ast::UintTy::U64 => &self.type_i64(),
333-
ast::UintTy::U128 => &self.type_i128(),
334-
}
335-
}
336-
337-
fn type_float_from_ty(
338-
&self,
339-
t: ast::FloatTy
340-
) -> &'ll Type {
341-
match t {
342-
ast::FloatTy::F32 => &self.type_f32(),
343-
ast::FloatTy::F64 => &self.type_f64(),
344-
}
345-
}
346-
347-
fn type_from_integer(&self, i: layout::Integer) -> &'ll Type {
348-
use rustc::ty::layout::Integer::*;
349-
match i {
350-
I8 => &self.type_i8(),
351-
I16 => &self.type_i16(),
352-
I32 => &self.type_i32(),
353-
I64 => &self.type_i64(),
354-
I128 => &self.type_i128(),
355-
}
356-
}
357-
358-
fn type_pointee_for_abi_align(&self, align: Align) -> &'ll Type {
359-
// FIXME(eddyb) We could find a better approximation if ity.align < align.
360-
let ity = layout::Integer::approximate_abi_align(self, align);
361-
&self.type_from_integer(ity)
362-
}
363-
364-
fn type_padding_filler(
365-
&self,
366-
size: Size,
367-
align: Align
368-
) -> &'ll Type {
369-
let unit = layout::Integer::approximate_abi_align(self, align);
370-
let size = size.bytes();
371-
let unit_size = unit.size().bytes();
372-
assert_eq!(size % unit_size, 0);
373-
&self.type_array(&self.type_from_integer(unit), size / unit_size)
374-
}
375-
376-
fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
377-
rustc_codegen_ssa::common::type_needs_drop(*self.tcx(), ty)
378-
}
379-
380-
fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
381-
rustc_codegen_ssa::common::type_is_sized(*self.tcx(), ty)
382-
}
383-
384-
fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
385-
rustc_codegen_ssa::common::type_is_freeze(*self.tcx(), ty)
386-
}
387-
388-
fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
389-
use syntax_pos::DUMMY_SP;
390-
if ty.is_sized(self.tcx().at(DUMMY_SP), ty::ParamEnv::reveal_all()) {
391-
return false;
392-
}
393-
394-
let tail = self.tcx().struct_tail(ty);
395-
match tail.sty {
396-
ty::Foreign(..) => false,
397-
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,
398-
_ => bug!("unexpected unsized tail: {:?}", tail.sty),
399-
}
400-
}
401-
}
282+
impl<'a, 'll: 'a, 'tcx: 'll> DerivedTypeMethods<'a, 'll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll Value>
283+
{}
402284

403285
impl LayoutTypeMethods<'ll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll Value> {
404286
fn backend_type(&self, ty: &TyLayout<'tcx>) -> &'ll Type {
@@ -435,4 +317,4 @@ impl LayoutTypeMethods<'ll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll Value> {
435317
}
436318
}
437319

438-
impl TypeMethods<'ll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll Value> {}
320+
impl<'a, 'll: 'a, 'tcx: 'll> TypeMethods<'a, 'll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll Value> {}

src/librustc_codegen_ssa/base.rs

+41-15
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ use mir::operand::OperandValue;
7272
use std::marker::PhantomData;
7373

7474

75-
pub struct StatRecorder<'a, 'll: 'a, 'tcx: 'll, Cx: 'a + CodegenMethods<'ll, 'tcx>> {
75+
pub struct StatRecorder<'a, 'll: 'a, 'tcx: 'll, Cx: 'a + CodegenMethods<'a, 'll, 'tcx>>
76+
where &'a Cx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
77+
{
7678
cx: &'a Cx,
7779
name: Option<String>,
7880
istart: usize,
7981
phantom: PhantomData<(&'ll (), &'tcx ())>
8082
}
8183

82-
impl<'a, 'll: 'a, 'tcx: 'll, Cx: 'a + CodegenMethods<'ll, 'tcx>> StatRecorder<'a, 'll, 'tcx, Cx> {
84+
impl<'a, 'll: 'a, 'tcx: 'll, Cx: 'a + CodegenMethods<'a, 'll, 'tcx>> StatRecorder<'a, 'll, 'tcx, Cx>
85+
where &'a Cx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
86+
{
8387
pub fn new(cx: &'a Cx, name: String) -> Self {
8488
let istart = cx.stats().borrow().n_llvm_insns;
8589
StatRecorder {
@@ -91,8 +95,9 @@ impl<'a, 'll: 'a, 'tcx: 'll, Cx: 'a + CodegenMethods<'ll, 'tcx>> StatRecorder<'a
9195
}
9296
}
9397

94-
impl<'a, 'll: 'a, 'tcx: 'll, Cx: 'a + CodegenMethods<'ll, 'tcx>> Drop for
98+
impl<'a, 'll: 'a, 'tcx: 'll, Cx: 'a + CodegenMethods<'a, 'll, 'tcx>> Drop for
9599
StatRecorder<'a, 'll, 'tcx, Cx>
100+
where &'a Cx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
96101
{
97102
fn drop(&mut self) {
98103
if self.cx.sess().codegen_stats() {
@@ -147,7 +152,9 @@ pub fn compare_simd_types<'a, 'll:'a, 'tcx:'ll, Bx : BuilderMethods<'a, 'll, 'tc
147152
t: Ty<'tcx>,
148153
ret_ty: <Bx::CodegenCx as Backend<'ll>>::Type,
149154
op: hir::BinOpKind
150-
) -> <Bx::CodegenCx as Backend<'ll>>::Value {
155+
) -> <Bx::CodegenCx as Backend<'ll>>::Value
156+
where &'a Bx::CodegenCx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
157+
{
151158
let signed = match t.sty {
152159
ty::Float(_) => {
153160
let cmp = bin_op_to_fcmp_predicate(op);
@@ -174,7 +181,7 @@ pub fn compare_simd_types<'a, 'll:'a, 'tcx:'ll, Bx : BuilderMethods<'a, 'll, 'tc
174181
/// The `old_info` argument is a bit funny. It is intended for use
175182
/// in an upcast, where the new vtable for an object will be derived
176183
/// from the old one.
177-
pub fn unsized_info<'a, 'll: 'a, 'tcx: 'll, Cx: 'a + CodegenMethods<'ll, 'tcx>>(
184+
pub fn unsized_info<'a, 'll: 'a, 'tcx: 'll, Cx: 'a + CodegenMethods<'a, 'll, 'tcx>>(
178185
cx: &'a Cx,
179186
source: Ty<'tcx>,
180187
target: Ty<'tcx>,
@@ -326,7 +333,9 @@ pub fn cast_shift_expr_rhs<'a, 'll: 'a, 'tcx: 'll, Bx : BuilderMethods<'a, 'll,
326333
op: hir::BinOpKind,
327334
lhs: <Bx::CodegenCx as Backend<'ll>>::Value,
328335
rhs: <Bx::CodegenCx as Backend<'ll>>::Value
329-
) -> <Bx::CodegenCx as Backend<'ll>>::Value {
336+
) -> <Bx::CodegenCx as Backend<'ll>>::Value
337+
where &'a Bx::CodegenCx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
338+
{
330339
cast_shift_rhs(bx, op, lhs, rhs)
331340
}
332341

@@ -335,7 +344,9 @@ fn cast_shift_rhs<'a, 'll :'a, 'tcx : 'll, Bx : BuilderMethods<'a, 'll, 'tcx>>(
335344
op: hir::BinOpKind,
336345
lhs: <Bx::CodegenCx as Backend<'ll>>::Value,
337346
rhs: <Bx::CodegenCx as Backend<'ll>>::Value,
338-
) -> <Bx::CodegenCx as Backend<'ll>>::Value {
347+
) -> <Bx::CodegenCx as Backend<'ll>>::Value
348+
where &'a Bx::CodegenCx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
349+
{
339350
// Shifts may have any size int on the rhs
340351
if op.is_shift() {
341352
let mut rhs_llty = bx.cx().val_ty(rhs);
@@ -374,15 +385,19 @@ pub fn wants_msvc_seh(sess: &Session) -> bool {
374385
pub fn call_assume<'a, 'll: 'a, 'tcx: 'll, Bx : BuilderMethods<'a, 'll ,'tcx>>(
375386
bx: &mut Bx,
376387
val: <Bx::CodegenCx as Backend<'ll>>::Value
377-
) {
388+
)
389+
where &'a Bx::CodegenCx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
390+
{
378391
let assume_intrinsic = bx.cx().get_intrinsic("llvm.assume");
379392
bx.call(assume_intrinsic, &[val], None);
380393
}
381394

382395
pub fn from_immediate<'a, 'll: 'a, 'tcx: 'll, Bx : BuilderMethods<'a, 'll ,'tcx>>(
383396
bx: &mut Bx,
384397
val: <Bx::CodegenCx as Backend<'ll>>::Value
385-
) -> <Bx::CodegenCx as Backend<'ll>>::Value {
398+
) -> <Bx::CodegenCx as Backend<'ll>>::Value
399+
where &'a Bx::CodegenCx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
400+
{
386401
if bx.cx().val_ty(val) == bx.cx().type_i1() {
387402
bx.zext(val, bx.cx().type_i8())
388403
} else {
@@ -394,7 +409,9 @@ pub fn to_immediate<'a, 'll: 'a, 'tcx: 'll, Bx : BuilderMethods<'a, 'll, 'tcx>>(
394409
bx: &mut Bx,
395410
val: <Bx::CodegenCx as Backend<'ll>>::Value,
396411
layout: layout::TyLayout,
397-
) -> <Bx::CodegenCx as Backend<'ll>>::Value {
412+
) -> <Bx::CodegenCx as Backend<'ll>>::Value
413+
where &'a Bx::CodegenCx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
414+
{
398415
if let layout::Abi::Scalar(ref scalar) = layout.abi {
399416
return to_immediate_scalar(bx, val, scalar);
400417
}
@@ -405,7 +422,9 @@ pub fn to_immediate_scalar<'a, 'll :'a, 'tcx :'ll, Bx : BuilderMethods<'a, 'll,
405422
bx: &mut Bx,
406423
val: <Bx::CodegenCx as Backend<'ll>>::Value,
407424
scalar: &layout::Scalar,
408-
) -> <Bx::CodegenCx as Backend<'ll>>::Value {
425+
) -> <Bx::CodegenCx as Backend<'ll>>::Value
426+
where &'a Bx::CodegenCx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
427+
{
409428
if scalar.is_bool() {
410429
return bx.trunc(val, bx.cx().type_i1());
411430
}
@@ -419,7 +438,9 @@ pub fn memcpy_ty<'a, 'll: 'a, 'tcx: 'll, Bx : BuilderMethods<'a, 'll, 'tcx>>(
419438
layout: TyLayout<'tcx>,
420439
align: Align,
421440
flags: MemFlags,
422-
) {
441+
)
442+
where &'a Bx::CodegenCx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
443+
{
423444
let size = layout.size.bytes();
424445
if size == 0 {
425446
return;
@@ -467,7 +488,9 @@ pub fn codegen_instance<'a, 'll: 'a, 'tcx: 'll, Bx: BuilderMethods<'a, 'll, 'tcx
467488
/// users main function.
468489
pub fn maybe_create_entry_wrapper<'a, 'll: 'a, 'tcx: 'll, Bx: BuilderMethods<'a, 'll, 'tcx>>(
469490
cx: &'a Bx::CodegenCx
470-
) {
491+
)
492+
where &'a Bx::CodegenCx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
493+
{
471494
let (main_def_id, span) = match *cx.sess().entry_fn.borrow() {
472495
Some((id, span, _)) => {
473496
(cx.tcx().hir.local_def_id(id), span)
@@ -498,7 +521,10 @@ pub fn maybe_create_entry_wrapper<'a, 'll: 'a, 'tcx: 'll, Bx: BuilderMethods<'a,
498521
rust_main: <Bx::CodegenCx as Backend<'ll>>::Value,
499522
rust_main_def_id: DefId,
500523
use_start_lang_item: bool,
501-
) {
524+
)
525+
where &'a Bx::CodegenCx :
526+
LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
527+
{
502528
let llfty =
503529
cx.type_func(&[cx.type_int(), cx.type_ptr_to(cx.type_i8p())], cx.type_int());
504530

@@ -551,7 +577,7 @@ pub fn maybe_create_entry_wrapper<'a, 'll: 'a, 'tcx: 'll, Bx: BuilderMethods<'a,
551577
};
552578

553579
let result = bx.call(start_fn, &args, None);
554-
let cast = bx.intcast(result, cx.type_int(), true);
580+
let cast = bx.intcast(result, cx.type_int(), true);
555581
bx.ret(cast);
556582
}
557583
}

src/librustc_codegen_ssa/callee.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99
// except according to those terms.
1010

1111
use interfaces::*;
12-
use rustc::ty;
12+
use rustc::ty::{self, Ty};
13+
use rustc::ty::layout::{LayoutOf, TyLayout, HasTyCtxt};
1314
use rustc::ty::subst::Substs;
1415
use rustc::hir::def_id::DefId;
1516

16-
pub fn resolve_and_get_fn<'ll, 'tcx: 'll, Cx : CodegenMethods<'ll, 'tcx>>(
17+
pub fn resolve_and_get_fn<'a, 'll: 'a, 'tcx: 'll, Cx : 'a + CodegenMethods<'a, 'll, 'tcx>>(
1718
cx: &Cx,
1819
def_id: DefId,
1920
substs: &'tcx Substs<'tcx>,
20-
) -> Cx::Value {
21+
) -> Cx::Value
22+
where &'a Cx : LayoutOf<Ty = Ty<'tcx>, TyLayout = TyLayout<'tcx>> + HasTyCtxt<'tcx>
23+
{
2124
cx.get_fn(
2225
ty::Instance::resolve(
2326
*cx.tcx(),

0 commit comments

Comments
 (0)