Skip to content

Commit 9ef2c30

Browse files
committed
Preserve visibility scopes in stored generator locals
Unfortunately, this didn't have quite the effect I was hoping for. Locals still appear visible at every point in the function, regardless of scopes. I suspect all the rewriting of the MIR we do for the generator transform makes these scopes less useful. I didn't observe any regressions in behavior, but it's possible that this change is wrong without additional changes to the MIR.
1 parent b8f6de4 commit 9ef2c30

File tree

1 file changed

+17
-9
lines changed
  • src/librustc_codegen_ssa/mir

1 file changed

+17
-9
lines changed

src/librustc_codegen_ssa/mir/mod.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -649,14 +649,15 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
649649
.iter()
650650
.zip(upvar_tys)
651651
.enumerate()
652-
.map(|(i, (upvar, ty))| (None, i, upvar.debug_name, upvar.by_ref, ty));
652+
.map(|(i, (upvar, ty))| {
653+
(None, i, upvar.debug_name, upvar.by_ref, ty, scope, DUMMY_SP)
654+
});
653655

654656
let generator_fields = mir.generator_layout.as_ref().map(|generator_layout| {
655657
let (def_id, gen_substs) = match closure_layout.ty.sty {
656658
ty::Generator(def_id, substs, _) => (def_id, substs),
657659
_ => bug!("generator layout without generator substs"),
658660
};
659-
// TODO handle variant scopes here
660661
let state_tys = gen_substs.state_tys(def_id, tcx);
661662

662663
generator_layout.variant_fields.iter()
@@ -668,18 +669,25 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
668669
.zip(tys)
669670
.enumerate()
670671
.filter_map(move |(i, (decl, ty))| {
671-
let ty = fx.monomorphize(&ty);
672-
decl.name.map(|name| {
673-
(variant_idx, i, name, false, ty)
674-
})
672+
if let Some(name) = decl.name {
673+
let ty = fx.monomorphize(&ty);
674+
let (var_scope, var_span) = fx.debug_loc(mir::SourceInfo {
675+
span: decl.source_info.span,
676+
scope: decl.visibility_scope,
677+
});
678+
let var_scope = var_scope.unwrap_or(scope);
679+
Some((variant_idx, i, name, false, ty, var_scope, var_span))
680+
} else {
681+
None
682+
}
675683
})
676684
})
677685
}).into_iter().flatten();
678686

679687
upvars.chain(generator_fields)
680688
};
681689

682-
for (variant_idx, field, name, by_ref, ty) in extra_locals {
690+
for (variant_idx, field, name, by_ref, ty, var_scope, var_span) in extra_locals {
683691
let fields = match variant_idx {
684692
Some(variant_idx) => {
685693
match &closure_layout.variants {
@@ -713,10 +721,10 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
713721
&fx.debug_context,
714722
name,
715723
ty,
716-
scope,
724+
var_scope,
717725
variable_access,
718726
VariableKind::LocalVariable,
719-
DUMMY_SP
727+
var_span
720728
);
721729
}
722730
});

0 commit comments

Comments
 (0)