Rollup merge of #99186 - camsteffen:closure-localdefid, r=cjgillot
Use LocalDefId for closures more
This commit is contained in:
commit
403c1b3802
29 changed files with 164 additions and 171 deletions
|
@ -1983,53 +1983,45 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
|||
}
|
||||
|
||||
AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| {
|
||||
if let Some(def_id) = def_id.as_local() {
|
||||
let name = if tcx.sess.opts.unstable_opts.span_free_formats {
|
||||
let substs = tcx.lift(substs).unwrap();
|
||||
format!(
|
||||
"[closure@{}]",
|
||||
tcx.def_path_str_with_substs(def_id.to_def_id(), substs),
|
||||
)
|
||||
} else {
|
||||
let span = tcx.def_span(def_id);
|
||||
format!(
|
||||
"[closure@{}]",
|
||||
tcx.sess.source_map().span_to_diagnostic_string(span)
|
||||
)
|
||||
};
|
||||
let mut struct_fmt = fmt.debug_struct(&name);
|
||||
|
||||
// FIXME(project-rfc-2229#48): This should be a list of capture names/places
|
||||
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
|
||||
for (&var_id, place) in iter::zip(upvars.keys(), places) {
|
||||
let var_name = tcx.hir().name(var_id);
|
||||
struct_fmt.field(var_name.as_str(), place);
|
||||
}
|
||||
}
|
||||
|
||||
struct_fmt.finish()
|
||||
let name = if tcx.sess.opts.unstable_opts.span_free_formats {
|
||||
let substs = tcx.lift(substs).unwrap();
|
||||
format!(
|
||||
"[closure@{}]",
|
||||
tcx.def_path_str_with_substs(def_id.to_def_id(), substs),
|
||||
)
|
||||
} else {
|
||||
write!(fmt, "[closure]")
|
||||
let span = tcx.def_span(def_id);
|
||||
format!(
|
||||
"[closure@{}]",
|
||||
tcx.sess.source_map().span_to_diagnostic_string(span)
|
||||
)
|
||||
};
|
||||
let mut struct_fmt = fmt.debug_struct(&name);
|
||||
|
||||
// FIXME(project-rfc-2229#48): This should be a list of capture names/places
|
||||
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
|
||||
for (&var_id, place) in iter::zip(upvars.keys(), places) {
|
||||
let var_name = tcx.hir().name(var_id);
|
||||
struct_fmt.field(var_name.as_str(), place);
|
||||
}
|
||||
}
|
||||
|
||||
struct_fmt.finish()
|
||||
}),
|
||||
|
||||
AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
|
||||
if let Some(def_id) = def_id.as_local() {
|
||||
let name = format!("[generator@{:?}]", tcx.def_span(def_id));
|
||||
let mut struct_fmt = fmt.debug_struct(&name);
|
||||
let name = format!("[generator@{:?}]", tcx.def_span(def_id));
|
||||
let mut struct_fmt = fmt.debug_struct(&name);
|
||||
|
||||
// FIXME(project-rfc-2229#48): This should be a list of capture names/places
|
||||
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
|
||||
for (&var_id, place) in iter::zip(upvars.keys(), places) {
|
||||
let var_name = tcx.hir().name(var_id);
|
||||
struct_fmt.field(var_name.as_str(), place);
|
||||
}
|
||||
// FIXME(project-rfc-2229#48): This should be a list of capture names/places
|
||||
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
|
||||
for (&var_id, place) in iter::zip(upvars.keys(), places) {
|
||||
let var_name = tcx.hir().name(var_id);
|
||||
struct_fmt.field(var_name.as_str(), place);
|
||||
}
|
||||
|
||||
struct_fmt.finish()
|
||||
} else {
|
||||
write!(fmt, "[generator]")
|
||||
}
|
||||
|
||||
struct_fmt.finish()
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ use rustc_hir::{self, GeneratorKind};
|
|||
use rustc_target::abi::VariantIdx;
|
||||
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::Span;
|
||||
use rustc_target::asm::InlineAsmRegOrRegClass;
|
||||
|
@ -340,8 +341,11 @@ pub enum FakeReadCause {
|
|||
/// If a closure pattern matches a Place starting with an Upvar, then we introduce a
|
||||
/// FakeRead for that Place outside the closure, in such a case this option would be
|
||||
/// Some(closure_def_id).
|
||||
/// Otherwise, the value of the optional DefId will be None.
|
||||
ForMatchedPlace(Option<DefId>),
|
||||
/// Otherwise, the value of the optional LocalDefId will be None.
|
||||
//
|
||||
// We can use LocaDefId here since fake read statements are removed
|
||||
// before codegen in the `CleanupNonCodegenStatements` pass.
|
||||
ForMatchedPlace(Option<LocalDefId>),
|
||||
|
||||
/// A fake read of the RefWithinGuard version of a bind-by-value variable
|
||||
/// in a match guard to ensure that its value hasn't change by the time
|
||||
|
@ -365,7 +369,7 @@ pub enum FakeReadCause {
|
|||
/// FakeRead for that Place outside the closure, in such a case this option would be
|
||||
/// Some(closure_def_id).
|
||||
/// Otherwise, the value of the optional DefId will be None.
|
||||
ForLet(Option<DefId>),
|
||||
ForLet(Option<LocalDefId>),
|
||||
|
||||
/// If we have an index expression like
|
||||
///
|
||||
|
@ -1095,8 +1099,10 @@ pub enum AggregateKind<'tcx> {
|
|||
/// active field index would identity the field `c`
|
||||
Adt(DefId, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
|
||||
|
||||
Closure(DefId, SubstsRef<'tcx>),
|
||||
Generator(DefId, SubstsRef<'tcx>, hir::Movability),
|
||||
// Note: We can use LocalDefId since closures and generators a deaggregated
|
||||
// before codegen.
|
||||
Closure(LocalDefId, SubstsRef<'tcx>),
|
||||
Generator(LocalDefId, SubstsRef<'tcx>, hir::Movability),
|
||||
}
|
||||
|
||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||
|
|
|
@ -205,9 +205,9 @@ impl<'tcx> Rvalue<'tcx> {
|
|||
AggregateKind::Adt(did, _, substs, _, _) => {
|
||||
tcx.bound_type_of(did).subst(tcx, substs)
|
||||
}
|
||||
AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs),
|
||||
AggregateKind::Closure(did, substs) => tcx.mk_closure(did.to_def_id(), substs),
|
||||
AggregateKind::Generator(did, substs, movability) => {
|
||||
tcx.mk_generator(did, substs, movability)
|
||||
tcx.mk_generator(did.to_def_id(), substs, movability)
|
||||
}
|
||||
},
|
||||
Rvalue::ShallowInitBox(_, ty) => tcx.mk_box(ty),
|
||||
|
|
|
@ -413,12 +413,12 @@ rustc_queries! {
|
|||
}
|
||||
|
||||
query symbols_for_closure_captures(
|
||||
key: (LocalDefId, DefId)
|
||||
key: (LocalDefId, LocalDefId)
|
||||
) -> Vec<rustc_span::Symbol> {
|
||||
storage(ArenaCacheSelector<'tcx>)
|
||||
desc {
|
||||
|tcx| "symbols for captures of closure `{}` in `{}`",
|
||||
tcx.def_path_str(key.1),
|
||||
tcx.def_path_str(key.1.to_def_id()),
|
||||
tcx.def_path_str(key.0.to_def_id())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ use rustc_span::{Span, Symbol, DUMMY_SP};
|
|||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::asm::InlineAsmRegOrRegClass;
|
||||
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use std::fmt;
|
||||
use std::ops::Index;
|
||||
|
||||
|
@ -405,7 +406,7 @@ pub enum ExprKind<'tcx> {
|
|||
},
|
||||
/// A closure definition.
|
||||
Closure {
|
||||
closure_id: DefId,
|
||||
closure_id: LocalDefId,
|
||||
substs: UpvarSubsts<'tcx>,
|
||||
upvars: Box<[ExprId]>,
|
||||
movability: Option<hir::Movability>,
|
||||
|
|
|
@ -59,7 +59,7 @@ pub type UpvarCaptureMap = FxHashMap<UpvarId, UpvarCapture>;
|
|||
|
||||
/// Given the closure DefId this map provides a map of root variables to minimum
|
||||
/// set of `CapturedPlace`s that need to be tracked to support all captures of that closure.
|
||||
pub type MinCaptureInformationMap<'tcx> = FxHashMap<DefId, RootVariableMinCaptureList<'tcx>>;
|
||||
pub type MinCaptureInformationMap<'tcx> = FxHashMap<LocalDefId, RootVariableMinCaptureList<'tcx>>;
|
||||
|
||||
/// Part of `MinCaptureInformationMap`; Maps a root variable to the list of `CapturedPlace`.
|
||||
/// Used to track the minimum set of `Place`s that need to be captured to support all
|
||||
|
@ -253,7 +253,7 @@ impl<'tcx> CapturedPlace<'tcx> {
|
|||
|
||||
fn symbols_for_closure_captures<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: (LocalDefId, DefId),
|
||||
def_id: (LocalDefId, LocalDefId),
|
||||
) -> Vec<Symbol> {
|
||||
let typeck_results = tcx.typeck(def_id.0);
|
||||
let captures = typeck_results.closure_min_captures_flattened(def_id.1);
|
||||
|
|
|
@ -570,7 +570,7 @@ pub struct TypeckResults<'tcx> {
|
|||
/// we never capture `t`. This becomes an issue when we build MIR as we require
|
||||
/// information on `t` in order to create place `t.0` and `t.1`. We can solve this
|
||||
/// issue by fake reading `t`.
|
||||
pub closure_fake_reads: FxHashMap<DefId, Vec<(HirPlace<'tcx>, FakeReadCause, hir::HirId)>>,
|
||||
pub closure_fake_reads: FxHashMap<LocalDefId, Vec<(HirPlace<'tcx>, FakeReadCause, hir::HirId)>>,
|
||||
|
||||
/// Tracks the rvalue scoping rules which defines finer scoping for rvalue expressions
|
||||
/// by applying extended parameter rules.
|
||||
|
@ -589,7 +589,7 @@ pub struct TypeckResults<'tcx> {
|
|||
|
||||
/// Contains the data for evaluating the effect of feature `capture_disjoint_fields`
|
||||
/// on closure size.
|
||||
pub closure_size_eval: FxHashMap<DefId, ClosureSizeProfileData<'tcx>>,
|
||||
pub closure_size_eval: FxHashMap<LocalDefId, ClosureSizeProfileData<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'tcx> TypeckResults<'tcx> {
|
||||
|
@ -811,7 +811,7 @@ impl<'tcx> TypeckResults<'tcx> {
|
|||
/// by the closure.
|
||||
pub fn closure_min_captures_flattened(
|
||||
&self,
|
||||
closure_def_id: DefId,
|
||||
closure_def_id: LocalDefId,
|
||||
) -> impl Iterator<Item = &ty::CapturedPlace<'tcx>> {
|
||||
self.closure_min_captures
|
||||
.get(&closure_def_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue