Skip to content

Commit

Permalink
Preserve visibility scopes in stored generator locals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tmandry committed Apr 22, 2019
1 parent 1c7ace8 commit b054710
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/librustc_codegen_ssa/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,15 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
.iter()
.zip(upvar_tys)
.enumerate()
.map(|(i, (decl, ty))| (None, i, decl.debug_name, decl.by_ref, ty));
.map(|(i, (decl, ty))| {
(None, i, decl.debug_name, decl.by_ref, ty, scope, DUMMY_SP)
});

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

generator_layout.variant_fields.iter()
Expand All @@ -667,18 +668,25 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
.zip(tys)
.enumerate()
.filter_map(move |(i, (decl, ty))| {
let ty = fx.monomorphize(&ty);
decl.name.map(|name| {
(variant_idx, i, name, false, ty)
})
if let Some(name) = decl.name {
let ty = fx.monomorphize(&ty);
let (var_scope, var_span) = fx.debug_loc(mir::SourceInfo {
span: decl.source_info.span,
scope: decl.visibility_scope,
});
let var_scope = var_scope.unwrap_or(scope);
Some((variant_idx, i, name, false, ty, var_scope, var_span))
} else {
None
}
})
})
}).into_iter().flatten();

upvars.chain(generator_fields)
};

for (variant_idx, field, name, by_ref, ty) in extra_locals {
for (variant_idx, field, name, by_ref, ty, var_scope, var_span) in extra_locals {
let fields = match variant_idx {
Some(variant_idx) => {
match &closure_layout.variants {
Expand Down Expand Up @@ -712,10 +720,10 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
&fx.debug_context,
name,
ty,
scope,
var_scope,
variable_access,
VariableKind::LocalVariable,
DUMMY_SP
var_span
);
}
});
Expand Down

0 comments on commit b054710

Please sign in to comment.