Store LocalDefId in hir::Closure.
This commit is contained in:
parent
dba1503ed3
commit
290f0781b4
10 changed files with 24 additions and 23 deletions
|
@ -635,6 +635,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
// `static |_task_context| -> <ret_ty> { body }`:
|
// `static |_task_context| -> <ret_ty> { body }`:
|
||||||
let generator_kind = {
|
let generator_kind = {
|
||||||
let c = self.arena.alloc(hir::Closure {
|
let c = self.arena.alloc(hir::Closure {
|
||||||
|
def_id: self.local_def_id(closure_node_id),
|
||||||
binder: hir::ClosureBinder::Default,
|
binder: hir::ClosureBinder::Default,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
bound_generic_params: &[],
|
bound_generic_params: &[],
|
||||||
|
@ -887,6 +888,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
let fn_decl = self.lower_fn_decl(decl, None, fn_decl_span, FnDeclKind::Closure, None);
|
let fn_decl = self.lower_fn_decl(decl, None, fn_decl_span, FnDeclKind::Closure, None);
|
||||||
|
|
||||||
let c = self.arena.alloc(hir::Closure {
|
let c = self.arena.alloc(hir::Closure {
|
||||||
|
def_id: self.local_def_id(closure_id),
|
||||||
binder: binder_clause,
|
binder: binder_clause,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
bound_generic_params,
|
bound_generic_params,
|
||||||
|
@ -991,6 +993,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
self.lower_fn_decl(&outer_decl, None, fn_decl_span, FnDeclKind::Closure, None);
|
self.lower_fn_decl(&outer_decl, None, fn_decl_span, FnDeclKind::Closure, None);
|
||||||
|
|
||||||
let c = self.arena.alloc(hir::Closure {
|
let c = self.arena.alloc(hir::Closure {
|
||||||
|
def_id: self.local_def_id(closure_id),
|
||||||
binder: binder_clause,
|
binder: binder_clause,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
bound_generic_params,
|
bound_generic_params,
|
||||||
|
|
|
@ -921,6 +921,7 @@ pub struct Crate<'hir> {
|
||||||
|
|
||||||
#[derive(Debug, HashStable_Generic)]
|
#[derive(Debug, HashStable_Generic)]
|
||||||
pub struct Closure<'hir> {
|
pub struct Closure<'hir> {
|
||||||
|
pub def_id: LocalDefId,
|
||||||
pub binder: ClosureBinder,
|
pub binder: ClosureBinder,
|
||||||
pub capture_clause: CaptureBy,
|
pub capture_clause: CaptureBy,
|
||||||
pub bound_generic_params: &'hir [GenericParam<'hir>],
|
pub bound_generic_params: &'hir [GenericParam<'hir>],
|
||||||
|
|
|
@ -733,6 +733,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
|
||||||
walk_list!(visitor, visit_arm, arms);
|
walk_list!(visitor, visit_arm, arms);
|
||||||
}
|
}
|
||||||
ExprKind::Closure(&Closure {
|
ExprKind::Closure(&Closure {
|
||||||
|
def_id: _,
|
||||||
binder: _,
|
binder: _,
|
||||||
bound_generic_params,
|
bound_generic_params,
|
||||||
fn_decl,
|
fn_decl,
|
||||||
|
|
|
@ -311,10 +311,9 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
||||||
if let hir::ExprKind::Closure { .. } = expr.kind {
|
if let hir::ExprKind::Closure(closure) = expr.kind {
|
||||||
let def_id = self.tcx.hir().local_def_id(expr.hir_id);
|
self.tcx.ensure().generics_of(closure.def_id);
|
||||||
self.tcx.ensure().generics_of(def_id);
|
self.tcx.ensure().codegen_fn_attrs(closure.def_id);
|
||||||
self.tcx.ensure().codegen_fn_attrs(def_id);
|
|
||||||
// We do not call `type_of` for closures here as that
|
// We do not call `type_of` for closures here as that
|
||||||
// depends on typecheck and would therefore hide
|
// depends on typecheck and would therefore hide
|
||||||
// any further errors in case one typeck fails.
|
// any further errors in case one typeck fails.
|
||||||
|
|
|
@ -636,9 +636,8 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
|
||||||
self.tcx.hir()
|
self.tcx.hir()
|
||||||
}
|
}
|
||||||
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
|
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
|
||||||
if let hir::ExprKind::Closure { .. } = ex.kind {
|
if let hir::ExprKind::Closure(closure) = ex.kind {
|
||||||
let def_id = self.tcx.hir().local_def_id(ex.hir_id);
|
self.check(closure.def_id);
|
||||||
self.check(def_id);
|
|
||||||
}
|
}
|
||||||
intravisit::walk_expr(self, ex);
|
intravisit::walk_expr(self, ex);
|
||||||
}
|
}
|
||||||
|
@ -771,9 +770,8 @@ fn find_opaque_ty_constraints_for_rpit(
|
||||||
self.tcx.hir()
|
self.tcx.hir()
|
||||||
}
|
}
|
||||||
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
|
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
|
||||||
if let hir::ExprKind::Closure { .. } = ex.kind {
|
if let hir::ExprKind::Closure(closure) = ex.kind {
|
||||||
let def_id = self.tcx.hir().local_def_id(ex.hir_id);
|
self.check(closure.def_id);
|
||||||
self.check(def_id);
|
|
||||||
}
|
}
|
||||||
intravisit::walk_expr(self, ex);
|
intravisit::walk_expr(self, ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1481,6 +1481,7 @@ impl<'a> State<'a> {
|
||||||
body,
|
body,
|
||||||
fn_decl_span: _,
|
fn_decl_span: _,
|
||||||
movability: _,
|
movability: _,
|
||||||
|
def_id: _,
|
||||||
}) => {
|
}) => {
|
||||||
self.print_closure_binder(binder, bound_generic_params);
|
self.print_closure_binder(binder, bound_generic_params);
|
||||||
self.print_capture_clause(capture_clause);
|
self.print_capture_clause(capture_clause);
|
||||||
|
|
|
@ -1708,12 +1708,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_info_for_closure(&mut self, hir_id: hir::HirId) {
|
#[instrument(level = "debug", skip(self))]
|
||||||
let def_id = self.tcx.hir().local_def_id(hir_id);
|
fn encode_info_for_closure(&mut self, def_id: LocalDefId) {
|
||||||
debug!("EncodeContext::encode_info_for_closure({:?})", def_id);
|
|
||||||
// NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
|
// NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
|
||||||
// including on the signature, which is inferred in `typeck.
|
// including on the signature, which is inferred in `typeck.
|
||||||
let typeck_result: &'tcx ty::TypeckResults<'tcx> = self.tcx.typeck(def_id);
|
let typeck_result: &'tcx ty::TypeckResults<'tcx> = self.tcx.typeck(def_id);
|
||||||
|
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
|
||||||
let ty = typeck_result.node_type(hir_id);
|
let ty = typeck_result.node_type(hir_id);
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Generator(..) => {
|
ty::Generator(..) => {
|
||||||
|
@ -2115,8 +2115,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_info_for_expr(&mut self, expr: &hir::Expr<'_>) {
|
fn encode_info_for_expr(&mut self, expr: &hir::Expr<'_>) {
|
||||||
if let hir::ExprKind::Closure { .. } = expr.kind {
|
if let hir::ExprKind::Closure(closure) = expr.kind {
|
||||||
self.encode_info_for_closure(expr.hir_id);
|
self.encode_info_for_closure(closure.def_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1412,8 +1412,8 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, ex: &'hir Expr<'hir>) {
|
fn visit_expr(&mut self, ex: &'hir Expr<'hir>) {
|
||||||
if matches!(ex.kind, ExprKind::Closure { .. }) {
|
if let ExprKind::Closure(closure) = ex.kind {
|
||||||
self.body_owners.push(self.tcx.hir().local_def_id(ex.hir_id));
|
self.body_owners.push(closure.def_id);
|
||||||
}
|
}
|
||||||
intravisit::walk_expr(self, ex)
|
intravisit::walk_expr(self, ex)
|
||||||
}
|
}
|
||||||
|
|
|
@ -413,7 +413,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
|
||||||
}
|
}
|
||||||
intravisit::walk_expr(self, expr);
|
intravisit::walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
hir::ExprKind::Closure { .. } => {
|
hir::ExprKind::Closure(closure) => {
|
||||||
// Interesting control flow (for loops can contain labeled
|
// Interesting control flow (for loops can contain labeled
|
||||||
// breaks or continues)
|
// breaks or continues)
|
||||||
self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id));
|
self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id));
|
||||||
|
@ -423,8 +423,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
|
||||||
// in better error messages than just pointing at the closure
|
// in better error messages than just pointing at the closure
|
||||||
// construction site.
|
// construction site.
|
||||||
let mut call_caps = Vec::new();
|
let mut call_caps = Vec::new();
|
||||||
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id);
|
if let Some(upvars) = self.tcx.upvars_mentioned(closure.def_id) {
|
||||||
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
|
|
||||||
call_caps.extend(upvars.keys().map(|var_id| {
|
call_caps.extend(upvars.keys().map(|var_id| {
|
||||||
let upvar = upvars[var_id];
|
let upvar = upvars[var_id];
|
||||||
let upvar_ln = self.add_live_node(UpvarNode(upvar.span));
|
let upvar_ln = self.add_live_node(UpvarNode(upvar.span));
|
||||||
|
|
|
@ -75,9 +75,8 @@ impl<'tcx> Visitor<'tcx> for CaptureCollector<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
||||||
if let hir::ExprKind::Closure { .. } = expr.kind {
|
if let hir::ExprKind::Closure(closure) = expr.kind {
|
||||||
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id);
|
if let Some(upvars) = self.tcx.upvars_mentioned(closure.def_id) {
|
||||||
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
|
|
||||||
// Every capture of a closure expression is a local in scope,
|
// Every capture of a closure expression is a local in scope,
|
||||||
// that is moved/copied/borrowed into the closure value, and
|
// that is moved/copied/borrowed into the closure value, and
|
||||||
// for this analysis they are like any other access to a local.
|
// for this analysis they are like any other access to a local.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue