Skip to content

Commit b4dd765

Browse files
committed
comments and code-cleanup in response to reviews.
1 parent 22796c8 commit b4dd765

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/librustc_trans/trans/_match.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,24 @@ fn insert_lllocals<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
952952
Lvalue::new("_match::insert_lllocals"),
953953
TrByMoveIntoCopy(..) => {
954954
// 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).
955+
// separate stack slot.
956+
//
957+
// E.g. consider moving the value `D(A)` out
958+
// of the tuple `(D(A), D(B))` and into the
959+
// local variable `x` via the pattern `(x,_)`,
960+
// leaving the remainder of the tuple `(_,
961+
// D(B))` still to be dropped in the future.
962+
//
963+
// Thus, here we must must zero the place that
964+
// we are moving *from*, because we do not yet
965+
// track drop flags for a fragmented parent
966+
// match input expression.
967+
//
968+
// Longer term we will be able to map the move
969+
// into `(x, _)` up to the parent path that
970+
// owns the whole tuple, and mark the
971+
// corresponding stack-local drop-flag
972+
// tracking the first component of the tuple.
958973
let hint_kind = HintKind::ZeroAndMaintain;
959974
Lvalue::new_with_hint("_match::insert_lllocals (match_input)",
960975
bcx, binding_info.id, hint_kind)

src/librustc_trans/trans/datum.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,27 @@ pub struct Rvalue {
189189
pub mode: RvalueMode
190190
}
191191

192+
/// Classifies what action we should take when a value is moved away
193+
/// with respect to its drop-flag.
194+
///
195+
/// Long term there will be no need for this classification: all flags
196+
/// (which will be stored on the stack frame) will have the same
197+
/// interpretation and maintenance code associated with them.
192198
#[derive(Copy, Clone, Debug)]
193199
pub enum HintKind {
200+
/// When the value is moved, set the drop-flag to "dropped"
201+
/// (i.e. "zero the flag", even when the specific representation
202+
/// is not literally 0) and when it is reinitialized, set the
203+
/// drop-flag back to "initialized".
194204
ZeroAndMaintain,
205+
206+
/// When the value is moved, do not set the drop-flag to "dropped"
207+
/// However, continue to read the drop-flag in deciding whether to
208+
/// drop. (In essence, the path/fragment in question will never
209+
/// need to be dropped at the points where it is moved away by
210+
/// this code, but we are defending against the scenario where
211+
/// some *other* code could move away (or drop) the value and thus
212+
/// zero-the-flag, which is why we will still read from it.
195213
DontZeroJustUse,
196214
}
197215

@@ -218,7 +236,8 @@ impl Lvalue { // Constructors for various Lvalues.
218236
DropFlagInfo::ZeroAndMaintain(id),
219237
HintKind::DontZeroJustUse if hint_available =>
220238
DropFlagInfo::DontZeroJustUse(id),
221-
_ => DropFlagInfo::None,
239+
_ =>
240+
DropFlagInfo::None,
222241
};
223242
(Some(id), info)
224243
};

0 commit comments

Comments
 (0)