Add a query for CapturedPlace::to_symbol
This commit is contained in:
parent
0cb6f07ef2
commit
cf5eda1b4d
@ -285,7 +285,7 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;
|
||||
// required that their size stay the same, but we don't want to change
|
||||
// it inadvertently. This assert just ensures we're aware of any change.
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
static_assert_size!(DepNode, 17);
|
||||
static_assert_size!(DepNode, 18);
|
||||
|
||||
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
||||
static_assert_size!(DepNode, 24);
|
||||
|
@ -329,6 +329,16 @@ rustc_queries! {
|
||||
}
|
||||
}
|
||||
|
||||
query symbols_for_closure_captures(
|
||||
key: (LocalDefId, DefId)
|
||||
) -> Vec<rustc_span::Symbol> {
|
||||
desc {
|
||||
|tcx| "symbols for captures of closure `{}` in `{}`",
|
||||
tcx.def_path_str(key.1),
|
||||
tcx.def_path_str(key.0.to_def_id())
|
||||
}
|
||||
}
|
||||
|
||||
/// MIR after our optimization passes have run. This is MIR that is ready
|
||||
/// for codegen. This is also the only query that can fetch non-local MIR, at present.
|
||||
query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
|
||||
|
@ -162,7 +162,7 @@ impl CapturedPlace<'tcx> {
|
||||
}
|
||||
|
||||
/// Returns a symbol of the captured upvar, which looks like `name__field1__field2`.
|
||||
pub fn to_symbol(&self, tcx: TyCtxt<'tcx>) -> Symbol {
|
||||
fn to_symbol(&self, tcx: TyCtxt<'tcx>) -> Symbol {
|
||||
let hir_id = match self.place.base {
|
||||
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
|
||||
base => bug!("Expected an upvar, found {:?}", base),
|
||||
@ -248,6 +248,15 @@ impl CapturedPlace<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn symbols_for_closure_captures<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: (LocalDefId, DefId),
|
||||
) -> Vec<Symbol> {
|
||||
let typeck_results = tcx.typeck(def_id.0);
|
||||
let captures = typeck_results.closure_min_captures_flattened(def_id.1);
|
||||
captures.into_iter().map(|captured_place| captured_place.to_symbol(tcx)).collect()
|
||||
}
|
||||
|
||||
/// Return true if the `proj_possible_ancestor` represents an ancestor path
|
||||
/// to `proj_capture` or `proj_possible_ancestor` is same as `proj_capture`,
|
||||
/// assuming they both start off of the same root variable.
|
||||
@ -432,3 +441,7 @@ impl BorrowKind {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut ty::query::Providers) {
|
||||
*providers = ty::query::Providers { symbols_for_closure_captures, ..*providers }
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ pub use self::IntVarValue::*;
|
||||
pub use self::Variance::*;
|
||||
pub use adt::*;
|
||||
pub use assoc::*;
|
||||
pub use closure::*;
|
||||
pub use generics::*;
|
||||
pub use vtable::*;
|
||||
|
||||
@ -55,6 +54,12 @@ pub use rustc_type_ir::*;
|
||||
|
||||
pub use self::binding::BindingMode;
|
||||
pub use self::binding::BindingMode::*;
|
||||
pub use self::closure::{
|
||||
is_ancestor_or_same_capture, place_to_string_for_capture, BorrowKind, CaptureInfo,
|
||||
CapturedPlace, ClosureKind, MinCaptureInformationMap, MinCaptureList,
|
||||
RootVariableMinCaptureList, UpvarBorrow, UpvarCapture, UpvarCaptureMap, UpvarId, UpvarListMap,
|
||||
UpvarPath, CAPTURE_STRUCT_LOCAL,
|
||||
};
|
||||
pub use self::consts::{Const, ConstInt, ConstKind, InferConst, ScalarInt, Unevaluated, ValTree};
|
||||
pub use self::context::{
|
||||
tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
|
||||
@ -1979,6 +1984,7 @@ pub fn ast_uint_ty(uty: UintTy) -> ast::UintTy {
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut ty::query::Providers) {
|
||||
closure::provide(providers);
|
||||
context::provide(providers);
|
||||
erase_regions::provide(providers);
|
||||
layout::provide(providers);
|
||||
|
@ -959,13 +959,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
ty::Generator(_, substs, _) => ty::UpvarSubsts::Generator(substs),
|
||||
_ => span_bug!(self.fn_span, "upvars with non-closure env ty {:?}", closure_ty),
|
||||
};
|
||||
let def_id = self.def_id.as_local().unwrap();
|
||||
let capture_syms = tcx.symbols_for_closure_captures((def_id, fn_def_id));
|
||||
let capture_tys = upvar_substs.upvar_tys();
|
||||
let captures_with_tys =
|
||||
hir_typeck_results.closure_min_captures_flattened(fn_def_id).zip(capture_tys);
|
||||
let captures_with_tys = hir_typeck_results
|
||||
.closure_min_captures_flattened(fn_def_id)
|
||||
.zip(capture_tys.zip(capture_syms));
|
||||
|
||||
self.upvar_mutbls = captures_with_tys
|
||||
.enumerate()
|
||||
.map(|(i, (captured_place, ty))| {
|
||||
.map(|(i, (captured_place, (ty, sym)))| {
|
||||
let capture = captured_place.info.capture_kind;
|
||||
let var_id = match captured_place.place.base {
|
||||
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
|
||||
@ -974,8 +977,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
|
||||
let mutability = captured_place.mutability;
|
||||
|
||||
let name = captured_place.to_symbol(tcx);
|
||||
|
||||
let mut projs = closure_env_projs.clone();
|
||||
projs.push(ProjectionElem::Field(Field::new(i), ty));
|
||||
match capture {
|
||||
@ -986,7 +987,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
};
|
||||
|
||||
self.var_debug_info.push(VarDebugInfo {
|
||||
name,
|
||||
name: sym,
|
||||
source_info: SourceInfo::outermost(tcx_hir.span(var_id)),
|
||||
value: VarDebugInfoContents::Place(Place {
|
||||
local: ty::CAPTURE_STRUCT_LOCAL,
|
||||
|
Loading…
x
Reference in New Issue
Block a user