Skip to content

Commit

Permalink
Rename upvar_list to closure_captures
Browse files Browse the repository at this point in the history
As part of supporting RFC 2229, we will be capturing all the places that
are mentioned in a closure. Currently the upvar_list field gives access
to a FxIndexMap<HirId, Upvar> map. Eventually this will change, with the
upvar_list having a more general structure that expresses captured
paths, not just the mentioned upvars. We will make those changes in
subsequent PRs.

This commit modifies the name of the upvar_list map to closure_captures
in TypeckTables.

Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
Co-authored-by: Aman Arora <me@aman-arora.com>
  • Loading branch information
3 people committed May 25, 2020
1 parent a0f06d1 commit c3dc8c4
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ pub struct TypeckTables<'tcx> {
/// The upvarID contains the HIR node ID and it also contains the full path
/// leading to the member of the struct or tuple that is used instead of the
/// entire variable.
pub upvar_list: ty::UpvarListMap,
pub closure_captures: ty::UpvarListMap,

/// Stores the type, expression, span and optional scope span of all types
/// that are live across the yield of this generator (if a generator).
Expand Down Expand Up @@ -447,7 +447,7 @@ impl<'tcx> TypeckTables<'tcx> {
used_trait_imports: Lrc::new(Default::default()),
tainted_by_errors: None,
concrete_opaque_types: Default::default(),
upvar_list: Default::default(),
closure_captures: Default::default(),
generator_interior_types: Default::default(),
}
}
Expand Down Expand Up @@ -688,7 +688,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
ref used_trait_imports,
tainted_by_errors,
ref concrete_opaque_types,
ref upvar_list,
ref closure_captures,
ref generator_interior_types,
} = *self;

Expand Down Expand Up @@ -721,7 +721,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
used_trait_imports.hash_stable(hcx, hasher);
tainted_by_errors.hash_stable(hcx, hasher);
concrete_opaque_types.hash_stable(hcx, hasher);
upvar_list.hash_stable(hcx, hasher);
closure_captures.hash_stable(hcx, hasher);
generator_interior_types.hash_stable(hcx, hasher);
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn do_mir_borrowck<'a, 'tcx>(
infcx.set_tainted_by_errors();
}
let upvars: Vec<_> = tables
.upvar_list
.closure_captures
.get(&def_id.to_def_id())
.into_iter()
.flat_map(|v| v.values())
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
let mut name = None;
if let Some(def_id) = def_id.as_local() {
let tables = self.ecx.tcx.typeck_tables_of(def_id);
if let Some(upvars) = tables.upvar_list.get(&def_id.to_def_id()) {
if let Some(upvars) = tables.closure_captures.get(&def_id.to_def_id()) {
// Sometimes the index is beyond the number of upvars (seen
// for a generator).
if let Some((&var_hir_id, _)) = upvars.get_index(field) {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir_build/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let hir_tables = self.hir.tables();

// In analyze_closure() in upvar.rs we gathered a list of upvars used by a
// closure and we stored in a map called upvar_list in TypeckTables indexed
// indexed closure and we stored in a map called closure_captures in TypeckTables
// with the closure's DefId. Here, we run through that vec of UpvarIds for
// the given closure and use the necessary information to create upvar
// debuginfo and to fill `self.upvar_mutbls`.
if let Some(upvars) = hir_tables.upvar_list.get(&fn_def_id) {
if let Some(upvars) = hir_tables.closure_captures.get(&fn_def_id) {
let closure_env_arg = Local::new(1);
let mut closure_env_projs = vec![];
let mut closure_ty = self.local_decls[closure_env_arg].ty;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ fn convert_var<'tcx>(
) -> ExprKind<'tcx> {
let upvar_index = cx
.tables()
.upvar_list
.closure_captures
.get(&cx.body_owner)
.and_then(|upvars| upvars.get_full(&var_hir_id).map(|(i, _, _)| i));

Expand Down
8 changes: 4 additions & 4 deletions src/librustc_typeck/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
let mut upvar_list: FxIndexMap<hir::HirId, ty::UpvarId> =
let mut closure_captures: FxIndexMap<hir::HirId, ty::UpvarId> =
FxIndexMap::with_capacity_and_hasher(upvars.len(), Default::default());
for (&var_hir_id, _) in upvars.iter() {
let upvar_id = ty::UpvarId {
Expand All @@ -122,7 +122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("seed upvar_id {:?}", upvar_id);
// Adding the upvar Id to the list of Upvars, which will be added
// to the map for the closure at the end of the for loop.
upvar_list.insert(var_hir_id, upvar_id);
closure_captures.insert(var_hir_id, upvar_id);

let capture_kind = match capture_clause {
hir::CaptureBy::Value => ty::UpvarCapture::ByValue,
Expand All @@ -140,8 +140,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Add the vector of upvars to the map keyed with the closure id.
// This gives us an easier access to them without having to call
// tcx.upvars again..
if !upvar_list.is_empty() {
self.tables.borrow_mut().upvar_list.insert(closure_def_id, upvar_list);
if !closure_captures.is_empty() {
self.tables.borrow_mut().closure_captures.insert(closure_def_id, closure_captures);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports);
wbcx.tables.used_trait_imports = used_trait_imports;

wbcx.tables.upvar_list =
mem::replace(&mut self.tables.borrow_mut().upvar_list, Default::default());
wbcx.tables.closure_captures =
mem::replace(&mut self.tables.borrow_mut().closure_captures, Default::default());

if self.is_tainted_by_errors() {
// FIXME(eddyb) keep track of `ErrorReported` from where the error was emitted.
Expand Down

0 comments on commit c3dc8c4

Please sign in to comment.