Skip to content

Commit 494ce37

Browse files
committed
Reduced the Lvalue constructors to a kernel of three constructors.
Updated all call sites that used the other contructors to uniformly call `Lvalue::new_with_hint`, passing along the appropriate kind of hint for each context. Placated tidy in a few other places in datum.rs.
1 parent ff14eaf commit 494ce37

File tree

3 files changed

+65
-95
lines changed

3 files changed

+65
-95
lines changed

src/librustc_trans/trans/_match.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,15 @@ fn insert_lllocals<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
950950
let lvalue = match binding_info.trmode {
951951
TrByCopy(..) =>
952952
Lvalue::new("_match::insert_lllocals"),
953-
TrByMoveIntoCopy(..) =>
954-
Lvalue::match_input("_match::insert_lllocals", bcx, binding_info.id),
953+
TrByMoveIntoCopy(..) => {
954+
// match_input moves from the input into a
955+
// separate stack slot; it must zero (at least
956+
// until we track drop flags for a fragmented
957+
// parent match input expression).
958+
let hint_kind = HintKind::ZeroAndMaintain;
959+
Lvalue::new_with_hint("_match::insert_lllocals (match_input)",
960+
bcx, binding_info.id, hint_kind)
961+
}
955962
_ => unreachable!(),
956963
};
957964
let datum = Datum::new(llval, binding_info.ty, lvalue);
@@ -971,10 +978,22 @@ fn insert_lllocals<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
971978
TrByRef => (binding_info.llmatch, true),
972979
};
973980

974-
let lvalue = Lvalue::local("_match::insert_lllocals",
975-
bcx,
976-
binding_info.id,
977-
aliases_other_state);
981+
982+
// A local that aliases some other state must be zeroed, since
983+
// the other state (e.g. some parent data that we matched
984+
// into) will still have its subcomponents (such as this
985+
// local) destructed at the end of the parent's scope. Longer
986+
// term, we will properly map such parents to the set of
987+
// unique drop flags for its fragments.
988+
let hint_kind = if aliases_other_state {
989+
HintKind::ZeroAndMaintain
990+
} else {
991+
HintKind::DontZeroJustUse
992+
};
993+
let lvalue = Lvalue::new_with_hint("_match::insert_lllocals (local)",
994+
bcx,
995+
binding_info.id,
996+
hint_kind);
978997
let datum = Datum::new(llval, binding_info.ty, lvalue);
979998
if let Some(cs) = cs {
980999
let opt_datum = lvalue.dropflag_hint(bcx);
@@ -1709,7 +1728,7 @@ fn mk_binding_alloca<'blk, 'tcx, A, F>(bcx: Block<'blk, 'tcx>,
17091728

17101729
// Allocate memory on stack for the binding.
17111730
let llval = alloc_ty(bcx, var_ty, &bcx.name(name));
1712-
let lvalue = Lvalue::binding(caller_name, bcx, p_id, name);
1731+
let lvalue = Lvalue::new_with_hint(caller_name, bcx, p_id, HintKind::DontZeroJustUse);
17131732
let datum = Datum::new(llval, var_ty, lvalue);
17141733

17151734
// Subtle: be sure that we *populate* the memory *before*

src/librustc_trans/trans/datum.rs

Lines changed: 37 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -189,96 +189,42 @@ pub struct Rvalue {
189189
pub mode: RvalueMode
190190
}
191191

192-
// XXX: reduce this to a smaller kernel of constructors.
193-
impl Lvalue { // These are all constructors for various Lvalues.
194-
pub fn new(source: &'static str) -> Lvalue {
195-
Lvalue { source: source, drop_flag_info: DropFlagInfo::None }
196-
}
197-
198-
pub fn upvar<'blk, 'tcx>(source: &'static str,
199-
bcx: Block<'blk, 'tcx>,
200-
id: ast::NodeId) -> Lvalue {
201-
let info = if Lvalue::has_dropflag_hint(bcx, id) {
202-
DropFlagInfo::ZeroAndMaintain(id)
203-
} else {
204-
DropFlagInfo::None
205-
};
206-
let info = if bcx.tcx().sess.nonzeroing_move_hints() { info } else { DropFlagInfo::None };
207-
debug!("upvar Lvalue at {}, id: {} info: {:?}", source, id, info);
208-
Lvalue { source: source, drop_flag_info: info }
209-
}
210-
211-
pub fn match_input<'blk, 'tcx>(source: &'static str,
212-
bcx: Block<'blk, 'tcx>,
213-
id: ast::NodeId) -> Lvalue
214-
{
215-
let info = if Lvalue::has_dropflag_hint(bcx, id) {
216-
// match_input is used to move from the input into a
217-
// separate stack slot; it must zero (at least until we
218-
// improve things to track drop flags for the fragmented
219-
// parent match input expression).
220-
DropFlagInfo::ZeroAndMaintain(id)
221-
} else {
222-
DropFlagInfo::None
223-
};
224-
let info = if bcx.tcx().sess.nonzeroing_move_hints() { info } else { DropFlagInfo::None };
225-
debug!("match_input Lvalue at {}, id: {} info: {:?}", source, id, info);
226-
Lvalue { source: source, drop_flag_info: info }
227-
}
192+
#[derive(Copy, Clone, Debug)]
193+
pub enum HintKind {
194+
ZeroAndMaintain,
195+
DontZeroJustUse,
196+
}
228197

229-
pub fn local<'blk, 'tcx>(source: &'static str,
230-
bcx: Block<'blk, 'tcx>,
231-
id: ast::NodeId,
232-
aliases_other_state: bool)
233-
-> Lvalue
234-
{
235-
let info = if Lvalue::has_dropflag_hint(bcx, id) {
236-
if aliases_other_state {
237-
DropFlagInfo::ZeroAndMaintain(id)
238-
} else {
239-
DropFlagInfo::DontZeroJustUse(id)
240-
}
241-
} else {
242-
DropFlagInfo::None
243-
};
244-
let info = if bcx.tcx().sess.nonzeroing_move_hints() { info } else { DropFlagInfo::None };
245-
debug!("local Lvalue at {}, id: {} info: {:?}", source, id, info);
246-
Lvalue { source: source, drop_flag_info: info }
198+
impl Lvalue { // Constructors for various Lvalues.
199+
pub fn new<'blk, 'tcx>(source: &'static str) -> Lvalue {
200+
debug!("Lvalue at {} no drop flag info", source);
201+
Lvalue { source: source, drop_flag_info: DropFlagInfo::None }
247202
}
248203

249-
pub fn store_arg<'blk, 'tcx>(source: &'static str,
250-
bcx: Block<'blk, 'tcx>,
251-
id: ast::NodeId) -> Lvalue
252-
{
253-
let info = if Lvalue::has_dropflag_hint(bcx, id) {
254-
DropFlagInfo::ZeroAndMaintain(id)
255-
} else {
256-
DropFlagInfo::None
257-
};
258-
let info = if bcx.tcx().sess.nonzeroing_move_hints() { info } else { DropFlagInfo::None };
259-
debug!("store_arg Lvalue at {}, id: {} info: {:?}", source, id, info);
260-
Lvalue { source: source, drop_flag_info: info }
204+
pub fn new_dropflag_hint(source: &'static str) -> Lvalue {
205+
debug!("Lvalue at {} is drop flag hint", source);
206+
Lvalue { source: source, drop_flag_info: DropFlagInfo::None }
261207
}
262208

263-
pub fn binding<'blk, 'tcx>(source: &'static str,
264-
bcx: Block<'blk, 'tcx>,
265-
id: ast::NodeId,
266-
name: ast::Name) -> Lvalue {
267-
let info = if Lvalue::has_dropflag_hint(bcx, id) {
268-
DropFlagInfo::DontZeroJustUse(id)
269-
} else {
270-
DropFlagInfo::None
209+
pub fn new_with_hint<'blk, 'tcx>(source: &'static str,
210+
bcx: Block<'blk, 'tcx>,
211+
id: ast::NodeId,
212+
k: HintKind) -> Lvalue {
213+
let (opt_id, info) = {
214+
let hint_available = Lvalue::has_dropflag_hint(bcx, id) &&
215+
bcx.tcx().sess.nonzeroing_move_hints();
216+
let info = match k {
217+
HintKind::ZeroAndMaintain if hint_available =>
218+
DropFlagInfo::ZeroAndMaintain(id),
219+
HintKind::DontZeroJustUse if hint_available =>
220+
DropFlagInfo::DontZeroJustUse(id),
221+
_ => DropFlagInfo::None,
222+
};
223+
(Some(id), info)
271224
};
272-
let info = if bcx.tcx().sess.nonzeroing_move_hints() { info } else { DropFlagInfo::None };
273-
debug!("binding Lvalue at {}, id: {} name: {} info: {:?}",
274-
source, id, name, info);
225+
debug!("Lvalue at {}, id: {:?} info: {:?}", source, opt_id, info);
275226
Lvalue { source: source, drop_flag_info: info }
276227
}
277-
278-
pub fn new_dropflag_hint(source: &'static str) -> Lvalue {
279-
debug!("dropflag hint Lvalue at {}", source);
280-
Lvalue { source: source, drop_flag_info: DropFlagInfo::None }
281-
}
282228
} // end Lvalue constructor methods.
283229

284230
impl Lvalue {
@@ -454,11 +400,15 @@ impl KindOps for Lvalue {
454400
}
455401
bcx
456402
} else {
457-
// XXX would be nice to assert this, but we currently are
458-
// adding e.g. DontZeroJustUse flags. (The dropflag hint
459-
// construction should be taking !type_needs_drop into
460-
// account; earlier analysis phases may not have all the
461-
// info they need to do it properly, I think...)
403+
// FIXME (#5016) would be nice to assert this, but we have
404+
// to allow for e.g. DontZeroJustUse flags, for now.
405+
//
406+
// (The dropflag hint construction should be taking
407+
// !type_needs_drop into account; earlier analysis phases
408+
// may not have all the info they need to include such
409+
// information properly, I think; in particular the
410+
// fragments analysis works on a non-monomorphized view of
411+
// the code.)
462412
//
463413
// assert_eq!(self.drop_flag_info, DropFlagInfo::None);
464414
bcx

src/librustc_trans/trans/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,8 @@ pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
13211321
def::DefUpvar(nid, _) => {
13221322
// Can't move upvars, so this is never a ZeroMemLastUse.
13231323
let local_ty = node_id_type(bcx, nid);
1324-
let lval = Lvalue::upvar("expr::trans_local_var", bcx, nid);
1324+
let lval = Lvalue::new_with_hint("expr::trans_local_var (upvar)",
1325+
bcx, nid, HintKind::ZeroAndMaintain);
13251326
match bcx.fcx.llupvars.borrow().get(&nid) {
13261327
Some(&val) => Datum::new(val, local_ty, lval),
13271328
None => {

0 commit comments

Comments
 (0)