Skip to content

Commit b054710

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 1c7ace8 commit b054710

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
@@ -648,14 +648,15 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
648648
.iter()
649649
.zip(upvar_tys)
650650
.enumerate()
651-
.map(|(i, (decl, ty))| (None, i, decl.debug_name, decl.by_ref, ty));
651+
.map(|(i, (decl, ty))| {
652+
(None, i, decl.debug_name, decl.by_ref, ty, scope, DUMMY_SP)
653+
});
652654

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

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

678686
upvars.chain(generator_fields)
679687
};
680688

681-
for (variant_idx, field, name, by_ref, ty) in extra_locals {
689+
for (variant_idx, field, name, by_ref, ty, var_scope, var_span) in extra_locals {
682690
let fields = match variant_idx {
683691
Some(variant_idx) => {
684692
match &closure_layout.variants {
@@ -712,10 +720,10 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
712720
&fx.debug_context,
713721
name,
714722
ty,
715-
scope,
723+
var_scope,
716724
variable_access,
717725
VariableKind::LocalVariable,
718-
DUMMY_SP
726+
var_span
719727
);
720728
}
721729
});

0 commit comments

Comments
 (0)