Skip to content

Commit c488d59

Browse files
committed
Integrate OperandValue::UnsizedRef into OperandValue::Ref.
1 parent 6e15e7c commit c488d59

File tree

7 files changed

+27
-43
lines changed

7 files changed

+27
-43
lines changed

src/librustc_codegen_llvm/abi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
188188
}
189189
let cx = bx.cx;
190190
if self.is_sized_indirect() {
191-
OperandValue::Ref(val, self.layout.align).store(bx, dst)
191+
OperandValue::Ref(val, None, self.layout.align).store(bx, dst)
192192
} else if self.is_unsized_indirect() {
193193
bug!("unsized ArgType must be handled through store_fn_arg");
194194
} else if let PassMode::Cast(cast) = self.mode {
@@ -249,7 +249,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
249249
OperandValue::Pair(next(), next()).store(bx, dst);
250250
}
251251
PassMode::Indirect(_, Some(_)) => {
252-
OperandValue::UnsizedRef(next(), next()).store(bx, dst);
252+
OperandValue::Ref(next(), Some(next()), self.layout.align).store(bx, dst);
253253
}
254254
PassMode::Direct(_) | PassMode::Indirect(_, None) | PassMode::Cast(_) => {
255255
self.store(bx, next(), dst);

src/librustc_codegen_llvm/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub fn coerce_unsized_into(
295295
OperandValue::Immediate(base) => {
296296
unsize_thin_ptr(bx, base, src_ty, dst_ty)
297297
}
298-
OperandValue::Ref(..) | OperandValue::UnsizedRef(..) => bug!()
298+
OperandValue::Ref(..) => bug!()
299299
};
300300
OperandValue::Pair(base, info).store(bx, dst);
301301
};

src/librustc_codegen_llvm/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ pub fn codegen_intrinsic_call(
605605
// etc.
606606
assert!(!bx.cx.type_needs_drop(arg.layout.ty));
607607
let (ptr, align) = match arg.val {
608-
OperandValue::Ref(ptr, align) => (ptr, align),
608+
OperandValue::Ref(ptr, None, align) => (ptr, align),
609609
_ => bug!()
610610
};
611611
let arg = PlaceRef::new_sized(ptr, arg.layout, align);

src/librustc_codegen_llvm/mir/block.rs

+11-20
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use syntax_pos::Pos;
3232
use super::{FunctionCx, LocalRef};
3333
use super::place::PlaceRef;
3434
use super::operand::OperandRef;
35-
use super::operand::OperandValue::{Pair, Ref, UnsizedRef, Immediate};
35+
use super::operand::OperandValue::{Pair, Ref, Immediate};
3636

3737
impl FunctionCx<'a, 'll, 'tcx> {
3838
pub fn codegen_block(&mut self, bb: mir::BasicBlock) {
@@ -232,10 +232,8 @@ impl FunctionCx<'a, 'll, 'tcx> {
232232

233233
PassMode::Direct(_) | PassMode::Pair(..) => {
234234
let op = self.codegen_consume(&bx, &mir::Place::Local(mir::RETURN_PLACE));
235-
if let Ref(llval, align) = op.val {
235+
if let Ref(llval, _, align) = op.val {
236236
bx.load(llval, align)
237-
} else if let UnsizedRef(..) = op.val {
238-
bug!("return type must be sized");
239237
} else {
240238
op.immediate_or_packed_pair(&bx)
241239
}
@@ -247,7 +245,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
247245
LocalRef::Operand(None) => bug!("use of return before def"),
248246
LocalRef::Place(cg_place) => {
249247
OperandRef {
250-
val: Ref(cg_place.llval, cg_place.align),
248+
val: Ref(cg_place.llval, None, cg_place.align),
251249
layout: cg_place.layout
252250
}
253251
}
@@ -259,12 +257,11 @@ impl FunctionCx<'a, 'll, 'tcx> {
259257
op.val.store(&bx, scratch);
260258
scratch.llval
261259
}
262-
Ref(llval, align) => {
260+
Ref(llval, _, align) => {
263261
assert_eq!(align.abi(), op.layout.align.abi(),
264262
"return place is unaligned!");
265263
llval
266264
}
267-
UnsizedRef(..) => bug!("return type must be sized"),
268265
};
269266
bx.load(
270267
bx.pointercast(llslot, cast_ty.llvm_type(bx.cx).ptr_to()),
@@ -605,15 +602,11 @@ impl FunctionCx<'a, 'll, 'tcx> {
605602
// The callee needs to own the argument memory if we pass it
606603
// by-ref, so make a local copy of non-immediate constants.
607604
match (arg, op.val) {
608-
(&mir::Operand::Copy(_), Ref(..)) |
609-
(&mir::Operand::Constant(_), Ref(..)) => {
605+
(&mir::Operand::Copy(_), Ref(_, None, _)) |
606+
(&mir::Operand::Constant(_), Ref(_, None, _)) => {
610607
let tmp = PlaceRef::alloca(&bx, op.layout, "const");
611608
op.val.store(&bx, tmp);
612-
op.val = Ref(tmp.llval, tmp.align);
613-
}
614-
(&mir::Operand::Copy(_), UnsizedRef(..)) |
615-
(&mir::Operand::Constant(_), UnsizedRef(..)) => {
616-
bug!("tried to pass an unsized argument by copy or constant")
609+
op.val = Ref(tmp.llval, None, tmp.align);
617610
}
618611
_ => {}
619612
}
@@ -667,7 +660,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
667660
}
668661
} else if arg.is_unsized_indirect() {
669662
match op.val {
670-
UnsizedRef(a, b) => {
663+
Ref(a, Some(b), _) => {
671664
llargs.push(a);
672665
llargs.push(b);
673666
return;
@@ -690,7 +683,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
690683
}
691684
}
692685
}
693-
Ref(llval, align) => {
686+
Ref(llval, _, align) => {
694687
if arg.is_indirect() && align.abi() < arg.layout.align.abi() {
695688
// `foo(packed.large_field)`. We can't pass the (unaligned) field directly. I
696689
// think that ATM (Rust 1.16) we only pass temporaries, but we shouldn't
@@ -703,8 +696,6 @@ impl FunctionCx<'a, 'll, 'tcx> {
703696
(llval, align, true)
704697
}
705698
}
706-
UnsizedRef(..) =>
707-
bug!("codegen_argument: tried to pass unsized operand to sized argument"),
708699
};
709700

710701
if by_ref && !arg.is_indirect() {
@@ -740,13 +731,13 @@ impl FunctionCx<'a, 'll, 'tcx> {
740731
let tuple = self.codegen_operand(bx, operand);
741732

742733
// Handle both by-ref and immediate tuples.
743-
if let Ref(llval, align) = tuple.val {
734+
if let Ref(llval, None, align) = tuple.val {
744735
let tuple_ptr = PlaceRef::new_sized(llval, tuple.layout, align);
745736
for i in 0..tuple.layout.fields.count() {
746737
let field_ptr = tuple_ptr.project_field(bx, i);
747738
self.codegen_argument(bx, field_ptr.load(bx), llargs, &args[i]);
748739
}
749-
} else if let UnsizedRef(..) = tuple.val {
740+
} else if let Ref(_, Some(_), _) = tuple.val {
750741
bug!("closure arguments must be sized")
751742
} else {
752743
// If the tuple is immediate, the elements are as well.

src/librustc_codegen_llvm/mir/operand.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ use super::place::PlaceRef;
3737
pub enum OperandValue<'ll> {
3838
/// A reference to the actual operand. The data is guaranteed
3939
/// to be valid for the operand's lifetime.
40-
Ref(&'ll Value, Align),
41-
/// A reference to the unsized operand. The data is guaranteed
42-
/// to be valid for the operand's lifetime.
43-
/// The second field is the extra.
44-
UnsizedRef(&'ll Value, &'ll Value),
40+
/// The second value, if any, is the extra data (vtable or length)
41+
/// which indicates that it refers to an unsized rvalue.
42+
Ref(&'ll Value, Option<&'ll Value>, Align),
4543
/// A single LLVM value.
4644
Immediate(&'ll Value),
4745
/// A pair of immediate LLVM values. Used by fat pointers too.
@@ -154,8 +152,7 @@ impl OperandRef<'ll, 'tcx> {
154152
let (llptr, llextra) = match self.val {
155153
OperandValue::Immediate(llptr) => (llptr, None),
156154
OperandValue::Pair(llptr, llextra) => (llptr, Some(llextra)),
157-
OperandValue::Ref(..) |
158-
OperandValue::UnsizedRef(..) => bug!("Deref of by-Ref operand {:?}", self)
155+
OperandValue::Ref(..) => bug!("Deref of by-Ref operand {:?}", self)
159156
};
160157
let layout = cx.layout_of(projected_ty);
161158
PlaceRef {
@@ -250,8 +247,7 @@ impl OperandRef<'ll, 'tcx> {
250247
*a = bx.bitcast(*a, field.scalar_pair_element_llvm_type(bx.cx, 0, true));
251248
*b = bx.bitcast(*b, field.scalar_pair_element_llvm_type(bx.cx, 1, true));
252249
}
253-
OperandValue::Ref(..) |
254-
OperandValue::UnsizedRef(..) => bug!()
250+
OperandValue::Ref(..) => bug!()
255251
}
256252

257253
OperandRef {
@@ -291,11 +287,11 @@ impl OperandValue<'ll> {
291287
return;
292288
}
293289
match self {
294-
OperandValue::Ref(r, source_align) => {
290+
OperandValue::Ref(r, None, source_align) => {
295291
base::memcpy_ty(bx, dest.llval, r, dest.layout,
296292
source_align.min(dest.align), flags)
297293
}
298-
OperandValue::UnsizedRef(..) => {
294+
OperandValue::Ref(_, Some(_), _) => {
299295
bug!("cannot directly store unsized values");
300296
}
301297
OperandValue::Immediate(s) => {
@@ -321,7 +317,7 @@ impl OperandValue<'ll> {
321317
.unwrap_or_else(|| bug!("indirect_dest has non-pointer type: {:?}", indirect_dest)).ty;
322318

323319
let (llptr, llextra) =
324-
if let OperandValue::UnsizedRef(llptr, llextra) = self {
320+
if let OperandValue::Ref(llptr, Some(llextra), _) = self {
325321
(llptr, llextra)
326322
} else {
327323
bug!("store_unsized called with a sized value")

src/librustc_codegen_llvm/mir/place.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl PlaceRef<'ll, 'tcx> {
132132
};
133133

134134
let val = if let Some(llextra) = self.llextra {
135-
OperandValue::UnsizedRef(self.llval, llextra)
135+
OperandValue::Ref(self.llval, Some(llextra), self.align)
136136
} else if self.layout.is_llvm_immediate() {
137137
let mut const_llval = None;
138138
unsafe {
@@ -163,7 +163,7 @@ impl PlaceRef<'ll, 'tcx> {
163163
};
164164
OperandValue::Pair(load(0, a), load(1, b))
165165
} else {
166-
OperandValue::Ref(self.llval, self.align)
166+
OperandValue::Ref(self.llval, None, self.align)
167167
};
168168

169169
OperandRef { val, layout: self.layout }

src/librustc_codegen_llvm/mir/rvalue.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ impl FunctionCx<'a, 'll, 'tcx> {
8383
base::coerce_unsized_into(&bx, scratch, dest);
8484
scratch.storage_dead(&bx);
8585
}
86-
OperandValue::Ref(llref, align) => {
86+
OperandValue::Ref(llref, None, align) => {
8787
let source = PlaceRef::new_sized(llref, operand.layout, align);
8888
base::coerce_unsized_into(&bx, source, dest);
8989
}
90-
OperandValue::UnsizedRef(..) => {
90+
OperandValue::Ref(_, Some(_), _) => {
9191
bug!("unsized coercion on an unsized rvalue")
9292
}
9393
}
@@ -268,9 +268,6 @@ impl FunctionCx<'a, 'll, 'tcx> {
268268
bug!("by-ref operand {:?} in codegen_rvalue_operand",
269269
operand);
270270
}
271-
OperandValue::UnsizedRef(..) => {
272-
bug!("unsized coercion on an unsized rvalue")
273-
}
274271
}
275272
}
276273
mir::CastKind::Misc if operand.layout.is_llvm_scalar_pair() => {

0 commit comments

Comments
 (0)