Skip to content

Commit b44d631

Browse files
committed
Rustup to rustc 1.42.0-nightly (3ebcfa145 2020-01-12)
1 parent c74b306 commit b44d631

File tree

5 files changed

+113
-111
lines changed

5 files changed

+113
-111
lines changed

src/analyze.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local, SsaKind
2323
match &stmt.kind {
2424
Assign(place_and_rval) => match &place_and_rval.1 {
2525
Rvalue::Ref(_, _, place) => {
26-
analyze_non_ssa_place(&mut flag_map, place);
26+
not_ssa(&mut flag_map, place.local)
2727
}
2828
_ => {}
2929
},
@@ -36,7 +36,7 @@ pub fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local, SsaKind
3636
if let Some((dest_place, _dest_bb)) = destination {
3737
let dest_layout = fx.layout_of(fx.monomorphize(&dest_place.ty(&fx.mir.local_decls, fx.tcx).ty));
3838
if !crate::abi::can_return_to_ssa_var(fx.tcx, dest_layout) {
39-
analyze_non_ssa_place(&mut flag_map, dest_place);
39+
not_ssa(&mut flag_map, dest_place.local)
4040
}
4141
}
4242
}
@@ -47,13 +47,6 @@ pub fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local, SsaKind
4747
flag_map
4848
}
4949

50-
fn analyze_non_ssa_place(flag_map: &mut IndexVec<Local, SsaKind>, place: &Place) {
51-
match place.base {
52-
PlaceBase::Local(local) => not_ssa(flag_map, local),
53-
_ => {}
54-
}
55-
}
56-
5750
fn not_ssa(flag_map: &mut IndexVec<Local, SsaKind>, local: Local) {
5851
flag_map[local] = SsaKind::NotSsa;
5952
}

src/base.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ fn trans_stmt<'tcx>(
292292

293293
fx.set_debug_loc(stmt.source_info);
294294

295-
#[cfg(debug_assertions)]
295+
#[cfg(false_debug_assertions)]
296296
match &stmt.kind {
297297
StatementKind::StorageLive(..) | StatementKind::StorageDead(..) => {} // Those are not very useful
298298
_ => {
@@ -646,20 +646,7 @@ pub fn trans_place<'tcx>(
646646
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
647647
place: &Place<'tcx>,
648648
) -> CPlace<'tcx> {
649-
let mut cplace = match &place.base {
650-
PlaceBase::Local(local) => fx.get_local_place(*local),
651-
PlaceBase::Static(static_) => match static_.kind {
652-
StaticKind::Static => {
653-
// Statics can't be generic, so `static_.ty` doesn't need to be monomorphized.
654-
crate::constant::codegen_static_ref(fx, static_.def_id, static_.ty)
655-
}
656-
StaticKind::Promoted(promoted, substs) => {
657-
let instance = Instance::new(static_.def_id, fx.monomorphize(&substs));
658-
let ty = fx.monomorphize(&static_.ty);
659-
crate::constant::trans_promoted(fx, instance, promoted, ty)
660-
}
661-
},
662-
};
649+
let mut cplace = fx.get_local_place(place.local);
663650

664651
for elem in &*place.projection {
665652
match *elem {

src/constant.rs

+107-69
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn codegen_static(constants_cx: &mut ConstantCx, def_id: DefId) {
4040
constants_cx.todo.insert(TodoItem::Static(def_id));
4141
}
4242

43-
pub fn codegen_static_ref<'tcx>(
43+
fn codegen_static_ref<'tcx>(
4444
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
4545
def_id: DefId,
4646
ty: Ty<'tcx>,
@@ -50,31 +50,37 @@ pub fn codegen_static_ref<'tcx>(
5050
cplace_for_dataid(fx, ty, data_id)
5151
}
5252

53-
pub fn trans_promoted<'tcx>(
54-
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
55-
instance: Instance<'tcx>,
56-
promoted: Promoted,
57-
dest_ty: Ty<'tcx>,
58-
) -> CPlace<'tcx> {
59-
match fx.tcx.const_eval_promoted(instance, promoted) {
60-
Ok(const_) => {
61-
let cplace = trans_const_place(fx, const_);
62-
debug_assert_eq!(cplace.layout(), fx.layout_of(dest_ty));
63-
cplace
64-
}
65-
Err(_) => crate::trap::trap_unreachable_ret_place(
66-
fx,
67-
fx.layout_of(dest_ty),
68-
"[panic] Tried to get value of promoted value with errored during const eval.",
69-
),
70-
}
71-
}
72-
7353
pub fn trans_constant<'tcx>(
7454
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
7555
constant: &Constant<'tcx>,
7656
) -> CValue<'tcx> {
77-
let const_ = force_eval_const(fx, &constant.literal);
57+
let const_ = match constant.literal.val {
58+
ConstKind::Unevaluated(def_id, ref substs, promoted) if fx.tcx.is_static(def_id) => {
59+
assert!(substs.is_empty());
60+
assert!(promoted.is_none());
61+
62+
return codegen_static_ref(
63+
fx,
64+
def_id,
65+
fx.monomorphize(&constant.literal.ty),
66+
).to_cvalue(fx);
67+
}
68+
ConstKind::Unevaluated(def_id, ref substs, promoted) => {
69+
let substs = fx.monomorphize(substs);
70+
fx.tcx.const_eval_resolve(
71+
ParamEnv::reveal_all(),
72+
def_id,
73+
substs,
74+
promoted,
75+
None, // FIXME use correct span
76+
).unwrap_or_else(|_| {
77+
fx.tcx.sess.abort_if_errors();
78+
unreachable!();
79+
})
80+
}
81+
_ => fx.monomorphize(&constant.literal),
82+
};
83+
7884
trans_const_value(fx, const_)
7985
}
8086

@@ -83,9 +89,15 @@ pub fn force_eval_const<'tcx>(
8389
const_: &'tcx Const,
8490
) -> &'tcx Const<'tcx> {
8591
match const_.val {
86-
ConstKind::Unevaluated(def_id, ref substs) => {
92+
ConstKind::Unevaluated(def_id, ref substs, promoted) => {
8793
let substs = fx.monomorphize(substs);
88-
fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def_id, substs, None).unwrap_or_else(|_| {
94+
fx.tcx.const_eval_resolve(
95+
ParamEnv::reveal_all(),
96+
def_id,
97+
substs,
98+
promoted,
99+
None, // FIXME pass correct span
100+
).unwrap_or_else(|_| {
89101
fx.tcx.sess.abort_if_errors();
90102
unreachable!();
91103
})
@@ -100,38 +112,78 @@ pub fn trans_const_value<'tcx>(
100112
) -> CValue<'tcx> {
101113
let ty = fx.monomorphize(&const_.ty);
102114
let layout = fx.layout_of(ty);
103-
match ty.kind {
104-
ty::Bool | ty::Uint(_) => {
105-
let bits = const_.val.try_to_bits(layout.size).unwrap();
106-
CValue::const_val(fx, ty, bits)
115+
116+
if layout.is_zst() {
117+
return CValue::by_ref(
118+
crate::Pointer::const_addr(fx, i64::try_from(layout.align.pref.bytes()).unwrap()),
119+
layout,
120+
);
121+
}
122+
123+
let const_val = match const_.val {
124+
ConstKind::Value(const_val) => const_val,
125+
_ => unreachable!("Const {:?} should have been evaluated", const_),
126+
};
127+
128+
match const_val {
129+
ConstValue::Scalar(x) => {
130+
let scalar = match layout.abi {
131+
layout::Abi::Scalar(ref x) => x,
132+
_ => bug!("from_const: invalid ByVal layout: {:#?}", layout),
133+
};
134+
135+
match ty.kind {
136+
ty::Bool | ty::Uint(_) => {
137+
let bits = const_.val.try_to_bits(layout.size).unwrap_or_else(|| {
138+
panic!("{:?}\n{:?}", const_, layout);
139+
});
140+
CValue::const_val(fx, ty, bits)
141+
}
142+
ty::Int(_) => {
143+
let bits = const_.val.try_to_bits(layout.size).unwrap();
144+
CValue::const_val(
145+
fx,
146+
ty,
147+
rustc::mir::interpret::sign_extend(bits, layout.size),
148+
)
149+
}
150+
ty::Float(fty) => {
151+
let bits = const_.val.try_to_bits(layout.size).unwrap();
152+
let val = match fty {
153+
FloatTy::F32 => fx
154+
.bcx
155+
.ins()
156+
.f32const(Ieee32::with_bits(u32::try_from(bits).unwrap())),
157+
FloatTy::F64 => fx
158+
.bcx
159+
.ins()
160+
.f64const(Ieee64::with_bits(u64::try_from(bits).unwrap())),
161+
};
162+
CValue::by_val(val, layout)
163+
}
164+
ty::FnDef(_def_id, _substs) => CValue::by_ref(
165+
crate::pointer::Pointer::const_addr(fx, fx.pointer_type.bytes() as i64),
166+
layout,
167+
),
168+
_ => trans_const_place(fx, const_).to_cvalue(fx),
169+
}
107170
}
108-
ty::Int(_) => {
109-
let bits = const_.val.try_to_bits(layout.size).unwrap();
110-
CValue::const_val(
111-
fx,
112-
ty,
113-
rustc::mir::interpret::sign_extend(bits, layout.size),
171+
ConstValue::ByRef { alloc, offset } => {
172+
let alloc_id = fx.tcx.alloc_map.lock().create_memory_alloc(alloc);
173+
fx.constants_cx.todo.insert(TodoItem::Alloc(alloc_id));
174+
let data_id = data_id_for_alloc_id(fx.module, alloc_id, alloc.align);
175+
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
176+
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
177+
assert!(!layout.is_unsized(), "unsized ConstValue::ByRef not supported");
178+
CValue::by_ref(
179+
crate::pointer::Pointer::new(global_ptr)
180+
.offset_i64(fx, i64::try_from(offset.bytes()).unwrap()),
181+
layout,
114182
)
115183
}
116-
ty::Float(fty) => {
117-
let bits = const_.val.try_to_bits(layout.size).unwrap();
118-
let val = match fty {
119-
FloatTy::F32 => fx
120-
.bcx
121-
.ins()
122-
.f32const(Ieee32::with_bits(u32::try_from(bits).unwrap())),
123-
FloatTy::F64 => fx
124-
.bcx
125-
.ins()
126-
.f64const(Ieee64::with_bits(u64::try_from(bits).unwrap())),
127-
};
128-
CValue::by_val(val, layout)
184+
ConstValue::Slice { data: _, start: _, end: _ } => {
185+
trans_const_place(fx, const_).to_cvalue(fx)
129186
}
130-
ty::FnDef(_def_id, _substs) => CValue::by_ref(
131-
crate::pointer::Pointer::const_addr(fx, fx.pointer_type.bytes() as i64),
132-
layout,
133-
),
134-
_ => trans_const_place(fx, const_).to_cvalue(fx),
135187
}
136188
}
137189

@@ -480,22 +532,8 @@ pub fn mir_operand_get_const_val<'tcx>(
480532
fx: &FunctionCx<'_, 'tcx, impl Backend>,
481533
operand: &Operand<'tcx>,
482534
) -> Option<&'tcx Const<'tcx>> {
483-
let place = match operand {
484-
Operand::Copy(place) | Operand::Move(place) => place,
535+
match operand {
536+
Operand::Copy(_) | Operand::Move(_) => return None,
485537
Operand::Constant(const_) => return Some(force_eval_const(fx, const_.literal)),
486-
};
487-
488-
assert!(place.projection.is_empty());
489-
let static_ = match &place.base {
490-
PlaceBase::Static(static_) => static_,
491-
PlaceBase::Local(_) => return None,
492-
};
493-
494-
Some(match &static_.kind {
495-
StaticKind::Static => unimplemented!(),
496-
StaticKind::Promoted(promoted, substs) => {
497-
let instance = Instance::new(static_.def_id, fx.monomorphize(substs));
498-
fx.tcx.const_eval_promoted(instance, *promoted).unwrap()
499-
}
500-
})
538+
}
501539
}

src/debuginfo/mod.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> {
283283
&local_map,
284284
&value_labels_ranges,
285285
Place {
286-
base: PlaceBase::Local(local),
286+
local,
287287
projection: ty::List::empty(),
288288
},
289289
);
@@ -305,12 +305,8 @@ fn place_location<'a, 'tcx>(
305305
place: Place<'tcx>,
306306
) -> AttributeValue {
307307
assert!(place.projection.is_empty()); // FIXME implement them
308-
let cplace = match place.base {
309-
PlaceBase::Local(local) => local_map[&local],
310-
PlaceBase::Static(_) => bug!("Unenforced invariant that the place is based on a Local violated: {:?}", place),
311-
};
312308

313-
match cplace.inner() {
309+
match local_map[&place.local].inner() {
314310
CPlaceInner::Var(local) => {
315311
let value_label = cranelift_codegen::ir::ValueLabel::from_u32(local.as_u32());
316312
if let Some(value_loc_ranges) = value_labels_ranges.get(&value_label) {

src/trap.rs

-12
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,3 @@ pub fn trap_unreachable_ret_value<'tcx>(
9393
trap_unimplemented(fx, msg);
9494
CValue::by_ref(Pointer::const_addr(fx, 0), dest_layout)
9595
}
96-
97-
/// Like `trap_unreachable` but returns a fake place for the specified type.
98-
///
99-
/// Trap code: user65535
100-
pub fn trap_unreachable_ret_place<'tcx>(
101-
fx: &mut FunctionCx<'_, 'tcx, impl cranelift_module::Backend>,
102-
dest_layout: TyLayout<'tcx>,
103-
msg: impl AsRef<str>,
104-
) -> CPlace<'tcx> {
105-
trap_unimplemented(fx, msg);
106-
CPlace::for_ptr(Pointer::const_addr(fx, 0), dest_layout)
107-
}

0 commit comments

Comments
 (0)