Skip to content

Commit 8038489

Browse files
Use LvalueRef instead of MaybeSizedValue
1 parent 4c9995a commit 8038489

File tree

10 files changed

+119
-123
lines changed

10 files changed

+119
-123
lines changed

src/librustc_trans/adt.rs

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use std;
4848
use llvm::{ValueRef, True, IntEQ, IntNE};
4949
use rustc::ty::layout;
5050
use rustc::ty::{self, Ty, AdtKind};
51+
use mir::lvalue::LvalueRef;
5152
use common::*;
5253
use builder::Builder;
5354
use glue;
@@ -64,32 +65,6 @@ pub enum BranchKind {
6465
Single
6566
}
6667

67-
#[derive(Copy, Clone)]
68-
pub struct MaybeSizedValue {
69-
pub value: ValueRef,
70-
pub meta: ValueRef,
71-
}
72-
73-
impl MaybeSizedValue {
74-
pub fn sized(value: ValueRef) -> MaybeSizedValue {
75-
MaybeSizedValue {
76-
value: value,
77-
meta: std::ptr::null_mut()
78-
}
79-
}
80-
81-
pub fn unsized_(value: ValueRef, meta: ValueRef) -> MaybeSizedValue {
82-
MaybeSizedValue {
83-
value: value,
84-
meta: meta
85-
}
86-
}
87-
88-
pub fn has_meta(&self) -> bool {
89-
!self.meta.is_null()
90-
}
91-
}
92-
9368
/// Given an enum, struct, closure, or tuple, extracts fields.
9469
/// Treats closures as a struct with one variant.
9570
/// `empty_if_no_variants` is a switch to deal with empty enums.
@@ -500,11 +475,11 @@ fn assert_discr_in_range(min: Disr, max: Disr, discr: Disr) {
500475
/// Access a field, at a point when the value's case is known.
501476
pub fn trans_field_ptr<'a, 'tcx>(
502477
bcx: &Builder<'a, 'tcx>,
503-
t: Ty<'tcx>,
504-
val: MaybeSizedValue,
478+
val: LvalueRef<'tcx>,
505479
discr: Disr,
506480
ix: usize
507481
) -> ValueRef {
482+
let t = val.ty.to_ty(bcx.tcx());
508483
let l = bcx.ccx.layout_of(t);
509484
debug!("trans_field_ptr on {} represented as {:#?}", t, l);
510485
// Note: if this ever needs to generate conditionals (e.g., if we
@@ -520,7 +495,7 @@ pub fn trans_field_ptr<'a, 'tcx>(
520495
layout::Vector { count, .. } => {
521496
assert_eq!(discr.0, 0);
522497
assert!((ix as u64) < count);
523-
bcx.struct_gep(val.value, ix)
498+
bcx.struct_gep(val.llval, ix)
524499
}
525500
layout::General { discr: d, ref variants, .. } => {
526501
let mut fields = compute_fields(bcx.ccx, t, discr.0 as usize, false);
@@ -532,7 +507,7 @@ pub fn trans_field_ptr<'a, 'tcx>(
532507
layout::UntaggedUnion { .. } => {
533508
let fields = compute_fields(bcx.ccx, t, 0, false);
534509
let ty = type_of::in_memory_type_of(bcx.ccx, fields[ix]);
535-
bcx.pointercast(val.value, ty.ptr_to())
510+
bcx.pointercast(val.llval, ty.ptr_to())
536511
}
537512
layout::RawNullablePointer { nndiscr, .. } |
538513
layout::StructWrappedNullablePointer { nndiscr, .. } if discr.0 != nndiscr => {
@@ -541,14 +516,14 @@ pub fn trans_field_ptr<'a, 'tcx>(
541516
// (e.d., Result of Either with (), as one side.)
542517
let ty = type_of::type_of(bcx.ccx, nullfields[ix]);
543518
assert_eq!(machine::llsize_of_alloc(bcx.ccx, ty), 0);
544-
bcx.pointercast(val.value, ty.ptr_to())
519+
bcx.pointercast(val.llval, ty.ptr_to())
545520
}
546521
layout::RawNullablePointer { nndiscr, .. } => {
547522
let nnty = compute_fields(bcx.ccx, t, nndiscr as usize, false)[0];
548523
assert_eq!(ix, 0);
549524
assert_eq!(discr.0, nndiscr);
550525
let ty = type_of::type_of(bcx.ccx, nnty);
551-
bcx.pointercast(val.value, ty.ptr_to())
526+
bcx.pointercast(val.llval, ty.ptr_to())
552527
}
553528
layout::StructWrappedNullablePointer { ref nonnull, nndiscr, .. } => {
554529
assert_eq!(discr.0, nndiscr);
@@ -564,7 +539,7 @@ fn struct_field_ptr<'a, 'tcx>(
564539
bcx: &Builder<'a, 'tcx>,
565540
st: &layout::Struct,
566541
fields: &Vec<Ty<'tcx>>,
567-
val: MaybeSizedValue,
542+
val: LvalueRef,
568543
ix: usize,
569544
needs_cast: bool
570545
) -> ValueRef {
@@ -576,9 +551,9 @@ fn struct_field_ptr<'a, 'tcx>(
576551
type_of::in_memory_type_of(ccx, fields[i])
577552
}).collect::<Vec<_>>();
578553
let real_ty = Type::struct_(ccx, &fields[..], st.packed);
579-
bcx.pointercast(val.value, real_ty.ptr_to())
554+
bcx.pointercast(val.llval, real_ty.ptr_to())
580555
} else {
581-
val.value
556+
val.llval
582557
};
583558

584559
// Simple case - we can just GEP the field
@@ -600,7 +575,7 @@ fn struct_field_ptr<'a, 'tcx>(
600575
}
601576

602577
// There's no metadata available, log the case and just do the GEP.
603-
if !val.has_meta() {
578+
if !val.has_extra() {
604579
debug!("Unsized field `{}`, of `{:?}` has no metadata for adjustment",
605580
ix, Value(ptr_val));
606581
return bcx.struct_gep(ptr_val, ix);
@@ -621,7 +596,7 @@ fn struct_field_ptr<'a, 'tcx>(
621596
// The type Foo<Foo<Trait>> is represented in LLVM as { u16, { u16, u8 }}, meaning that
622597
// the `y` field has 16-bit alignment.
623598

624-
let meta = val.meta;
599+
let meta = val.llextra;
625600

626601

627602
let offset = st.offsets[ix].bytes();

src/librustc_trans/base.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use session::config::{self, NoDebugInfo};
4747
use rustc_incremental::IncrementalHashesMap;
4848
use session::{self, DataTypeKind, Session};
4949
use abi::{self, Abi, FnType};
50+
use mir::lvalue::LvalueRef;
5051
use adt;
5152
use attributes;
5253
use builder::Builder;
@@ -278,17 +279,17 @@ pub fn coerce_unsized_into<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
278279
monomorphize::field_ty(bcx.tcx(), substs_b, f)
279280
});
280281

281-
let src = adt::MaybeSizedValue::sized(src);
282-
let dst = adt::MaybeSizedValue::sized(dst);
282+
let src = LvalueRef::new_sized_ty(src, src_ty);
283+
let dst = LvalueRef::new_sized_ty(dst, dst_ty);
283284

284285
let iter = src_fields.zip(dst_fields).enumerate();
285286
for (i, (src_fty, dst_fty)) in iter {
286287
if type_is_zero_size(bcx.ccx, dst_fty) {
287288
continue;
288289
}
289290

290-
let src_f = adt::trans_field_ptr(bcx, src_ty, src, Disr(0), i);
291-
let dst_f = adt::trans_field_ptr(bcx, dst_ty, dst, Disr(0), i);
291+
let src_f = adt::trans_field_ptr(bcx, src, Disr(0), i);
292+
let dst_f = adt::trans_field_ptr(bcx, dst, Disr(0), i);
292293
if src_fty == dst_fty {
293294
memcpy_ty(bcx, dst_f, src_f, src_fty, None);
294295
} else {
@@ -620,11 +621,12 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
620621
// final ret value
621622
bcx.alloca(fn_ty.ret.memory_ty(ccx), "sret_slot")
622623
};
623-
let dest_val = adt::MaybeSizedValue::sized(dest); // Can return unsized value
624+
// Can return unsized value
625+
let dest_val = LvalueRef::new_sized_ty(dest, sig.output());
624626
let mut llarg_idx = fn_ty.ret.is_indirect() as usize;
625627
let mut arg_idx = 0;
626628
for (i, arg_ty) in sig.inputs().iter().enumerate() {
627-
let lldestptr = adt::trans_field_ptr(&bcx, sig.output(), dest_val, Disr::from(disr), i);
629+
let lldestptr = adt::trans_field_ptr(&bcx, dest_val, Disr::from(disr), i);
628630
let arg = &fn_ty.args[arg_idx];
629631
arg_idx += 1;
630632
if common::type_is_fat_ptr(bcx.ccx, arg_ty) {

src/librustc_trans/callee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use base;
2626
use builder::Builder;
2727
use common::{self, CrateContext, SharedCrateContext};
2828
use cleanup::CleanupScope;
29-
use adt::MaybeSizedValue;
29+
use mir::lvalue::LvalueRef;
3030
use consts;
3131
use declare;
3232
use value::Value;
@@ -364,7 +364,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
364364
// Call the by-ref closure body with `self` in a cleanup scope,
365365
// to drop `self` when the body returns, or in case it unwinds.
366366
let self_scope = CleanupScope::schedule_drop_mem(
367-
&bcx, MaybeSizedValue::sized(llenv), closure_ty
367+
&bcx, LvalueRef::new_sized_ty(llenv, closure_ty)
368368
);
369369

370370
let llfn = callee.reify(bcx.ccx);

src/librustc_trans/cleanup.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
2121
use llvm::BasicBlockRef;
2222
use base;
23-
use adt::MaybeSizedValue;
23+
use mir::lvalue::LvalueRef;
24+
use rustc::mir::tcx::LvalueTy;
2425
use builder::Builder;
2526
use common::Funclet;
2627
use glue;
2728
use type_::Type;
28-
use rustc::ty::Ty;
2929

3030
pub struct CleanupScope<'tcx> {
3131
// Cleanup to run upon scope exit.
@@ -37,14 +37,13 @@ pub struct CleanupScope<'tcx> {
3737

3838
#[derive(Copy, Clone)]
3939
pub struct DropValue<'tcx> {
40-
val: MaybeSizedValue,
41-
ty: Ty<'tcx>,
40+
val: LvalueRef<'tcx>,
4241
skip_dtor: bool,
4342
}
4443

4544
impl<'tcx> DropValue<'tcx> {
4645
fn trans<'a>(&self, funclet: Option<&'a Funclet>, bcx: &Builder<'a, 'tcx>) {
47-
glue::call_drop_glue(bcx, self.val, self.ty, self.skip_dtor, funclet)
46+
glue::call_drop_glue(bcx, self.val, self.skip_dtor, funclet)
4847
}
4948

5049
/// Creates a landing pad for the top scope. The landing pad will perform all cleanups necessary
@@ -96,12 +95,16 @@ impl<'tcx> DropValue<'tcx> {
9695
impl<'a, 'tcx> CleanupScope<'tcx> {
9796
/// Schedules a (deep) drop of `val`, which is a pointer to an instance of `ty`
9897
pub fn schedule_drop_mem(
99-
bcx: &Builder<'a, 'tcx>, val: MaybeSizedValue, ty: Ty<'tcx>
98+
bcx: &Builder<'a, 'tcx>, val: LvalueRef<'tcx>
10099
) -> CleanupScope<'tcx> {
101-
if !bcx.ccx.shared().type_needs_drop(ty) { return CleanupScope::noop(); }
100+
if let LvalueTy::Downcast { .. } = val.ty {
101+
bug!("Cannot drop downcast ty yet");
102+
}
103+
if !bcx.ccx.shared().type_needs_drop(val.ty.to_ty(bcx.tcx())) {
104+
return CleanupScope::noop();
105+
}
102106
let drop = DropValue {
103107
val: val,
104-
ty: ty,
105108
skip_dtor: false,
106109
};
107110

@@ -114,15 +117,19 @@ impl<'a, 'tcx> CleanupScope<'tcx> {
114117
/// and dropping the contents associated with that variant
115118
/// *without* executing any associated drop implementation.
116119
pub fn schedule_drop_adt_contents(
117-
bcx: &Builder<'a, 'tcx>, val: MaybeSizedValue, ty: Ty<'tcx>
120+
bcx: &Builder<'a, 'tcx>, val: LvalueRef<'tcx>
118121
) -> CleanupScope<'tcx> {
122+
if let LvalueTy::Downcast { .. } = val.ty {
123+
bug!("Cannot drop downcast ty yet");
124+
}
119125
// `if` below could be "!contents_needs_drop"; skipping drop
120126
// is just an optimization, so sound to be conservative.
121-
if !bcx.ccx.shared().type_needs_drop(ty) { return CleanupScope::noop(); }
127+
if !bcx.ccx.shared().type_needs_drop(val.ty.to_ty(bcx.tcx())) {
128+
return CleanupScope::noop();
129+
}
122130

123131
let drop = DropValue {
124132
val: val,
125-
ty: ty,
126133
skip_dtor: true,
127134
};
128135

0 commit comments

Comments
 (0)