Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
if encode_opt {
record!(self.tables.optimized_mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id));

if let DefKind::Generator = self.tcx.def_kind(def_id) {
if let DefKind::Generator = self.tcx.def_kind(def_id) && tcx.sess.opts.unstable_opts.drop_tracking_mir {
record!(self.tables.mir_generator_witnesses[def_id.to_def_id()] <- tcx.mir_generator_witnesses(def_id));
}
}
Expand Down
33 changes: 17 additions & 16 deletions compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
) -> GeneratorLayout<'tcx> {
assert!(tcx.sess.opts.unstable_opts.drop_tracking_mir);
let def_id = def_id.expect_local();

let (body, _) = tcx.mir_promoted(ty::WithOptConstParam::unknown(def_id));
Expand All @@ -1400,15 +1401,8 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
let gen_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;

// Get the interior types and substs which typeck computed
let (upvars, interior, movable) = match *gen_ty.kind() {
ty::Generator(_, substs, movability) => {
let substs = substs.as_generator();
(
substs.upvar_tys().collect::<Vec<_>>(),
substs.witness(),
movability == hir::Movability::Movable,
)
}
let movable = match *gen_ty.kind() {
ty::Generator(_, _, movability) => movability == hir::Movability::Movable,
_ => span_bug!(body.span, "unexpected generator type {}", gen_ty),
};

Expand All @@ -1422,11 +1416,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
// `storage_liveness` tells us which locals have live storage at suspension points
let (_, generator_layout, _) = compute_layout(tcx, liveness_info, body);

if tcx.sess.opts.unstable_opts.drop_tracking_mir {
check_suspend_tys(tcx, &generator_layout, &body);
} else {
sanitize_witness(tcx, body, interior, upvars, &generator_layout);
}
check_suspend_tys(tcx, &generator_layout, &body);

generator_layout
}
Expand All @@ -1444,10 +1434,15 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
let gen_ty = body.local_decls.raw[1].ty;

// Get the discriminant type and substs which typeck computed
let (discr_ty, movable) = match *gen_ty.kind() {
let (discr_ty, upvars, interior, movable) = match *gen_ty.kind() {
ty::Generator(_, substs, movability) => {
let substs = substs.as_generator();
(substs.discr_ty(tcx), movability == hir::Movability::Movable)
(
substs.discr_ty(tcx),
substs.upvar_tys().collect::<Vec<_>>(),
substs.witness(),
movability == hir::Movability::Movable,
)
}
_ => {
tcx.sess
Expand Down Expand Up @@ -1524,6 +1519,12 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
// `storage_liveness` tells us which locals have live storage at suspension points
let (remap, layout, storage_liveness) = compute_layout(tcx, liveness_info, body);

if tcx.sess.opts.unstable_opts.validate_mir
&& !tcx.sess.opts.unstable_opts.drop_tracking_mir
{
sanitize_witness(tcx, body, interior, upvars, &layout);
}

let can_return = can_return(tcx, body, tcx.param_env(body.source.def_id()));

// Run the transformation which converts Places from Local to generator struct
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ fn mir_drops_elaborated_and_const_checked(
return tcx.mir_drops_elaborated_and_const_checked(def);
}

if tcx.generator_kind(def.did).is_some() {
if tcx.generator_kind(def.did).is_some() && tcx.sess.opts.unstable_opts.drop_tracking_mir {
tcx.ensure().mir_generator_witnesses(def.did);
}
let mir_borrowck = tcx.mir_borrowck_opt_const_arg(def);
Expand Down