Rename upvar_list to closure_captures
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>
This commit is contained in:
parent
a0f06d11ae
commit
c3dc8c455c
7 changed files with 15 additions and 15 deletions
|
|
@ -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).
|
||||
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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);
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -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,
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue