Skip to content

Commit 82bd719

Browse files
committed
rustc: don't track var_hir_id or mutability in mir::UpvarDecl.
1 parent 61fcbfc commit 82bd719

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/librustc/mir/mod.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use crate::hir::def::{CtorKind, Namespace};
66
use crate::hir::def_id::DefId;
7-
use crate::hir::{self, HirId, InlineAsm as HirInlineAsm};
7+
use crate::hir::{self, InlineAsm as HirInlineAsm};
88
use crate::mir::interpret::{ConstValue, InterpError, Scalar};
99
use crate::mir::visit::MirVisitable;
1010
use rustc_apfloat::ieee::{Double, Single};
@@ -138,16 +138,16 @@ pub struct Mir<'tcx> {
138138
/// If this MIR was built for a constant, this will be 0.
139139
pub arg_count: usize,
140140

141-
/// Names and capture modes of all the closure upvars, assuming
142-
/// the first argument is either the closure or a reference to it.
143-
pub upvar_decls: Vec<UpvarDecl>,
144-
145141
/// Mark an argument local (which must be a tuple) as getting passed as
146142
/// its individual components at the LLVM level.
147143
///
148144
/// This is used for the "rust-call" ABI.
149145
pub spread_arg: Option<Local>,
150146

147+
/// Names and capture modes of all the closure upvars, assuming
148+
/// the first argument is either the closure or a reference to it.
149+
pub upvar_decls: Vec<UpvarDecl>,
150+
151151
/// Mark this MIR of a const context other than const functions as having converted a `&&` or
152152
/// `||` expression into `&` or `|` respectively. This is problematic because if we ever stop
153153
/// this conversion from happening and use short circuiting, we will cause the following code
@@ -986,13 +986,8 @@ impl<'tcx> LocalDecl<'tcx> {
986986
pub struct UpvarDecl {
987987
pub debug_name: Name,
988988

989-
/// `HirId` of the captured variable
990-
pub var_hir_id: ClearCrossCrate<HirId>,
991-
992989
/// If true, the capture is behind a reference.
993990
pub by_ref: bool,
994-
995-
pub mutability: Mutability,
996991
}
997992

998993
///////////////////////////////////////////////////////////////////////////

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
556556
);
557557
// Not in a closure
558558
debug_assert!(
559-
this.upvar_decls.len() > upvar_index.index(),
559+
this.upvar_mutbls.len() > upvar_index.index(),
560560
"Unexpected capture place"
561561
);
562-
this.upvar_decls[upvar_index.index()].mutability
562+
this.upvar_mutbls[upvar_index.index()]
563563
}
564564
_ => bug!("Unexpected capture place"),
565565
};

src/librustc_mir/build/mod.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
376376
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
377377
canonical_user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>,
378378
upvar_decls: Vec<UpvarDecl>,
379+
upvar_mutbls: Vec<Mutability>,
379380
unit_temp: Option<Place<'tcx>>,
380381

381382
/// Cached block with the `RESUME` terminator; this is created
@@ -625,6 +626,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
625626
let fn_def_id = tcx_hir.local_def_id_from_hir_id(fn_id);
626627

627628
// Gather the upvars of a closure, if any.
629+
let mut upvar_mutbls = vec![];
628630
// In analyze_closure() in upvar.rs we gathered a list of upvars used by a
629631
// closure and we stored in a map called upvar_list in TypeckTables indexed
630632
// with the closure's DefId. Here, we run through that vec of UpvarIds for
@@ -644,24 +646,24 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
644646
};
645647
let mut decl = UpvarDecl {
646648
debug_name: keywords::Invalid.name(),
647-
var_hir_id: ClearCrossCrate::Set(var_hir_id),
648649
by_ref,
649-
mutability: Mutability::Not,
650650
};
651+
let mut mutability = Mutability::Not;
651652
if let Some(Node::Binding(pat)) = tcx_hir.find(var_node_id) {
652653
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
653654
decl.debug_name = ident.name;
654655
if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) {
655656
if bm == ty::BindByValue(hir::MutMutable) {
656-
decl.mutability = Mutability::Mut;
657+
mutability = Mutability::Mut;
657658
} else {
658-
decl.mutability = Mutability::Not;
659+
mutability = Mutability::Not;
659660
}
660661
} else {
661662
tcx.sess.delay_span_bug(pat.span, "missing binding mode");
662663
}
663664
}
664665
}
666+
upvar_mutbls.push(mutability);
665667
decl
666668
})
667669
.collect();
@@ -672,7 +674,8 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
672674
safety,
673675
return_ty,
674676
return_ty_span,
675-
upvar_decls);
677+
upvar_decls,
678+
upvar_mutbls);
676679

677680
let call_site_scope = region::Scope {
678681
id: body.value.hir_id.local_id,
@@ -734,7 +737,7 @@ fn construct_const<'a, 'gcx, 'tcx>(
734737
let ty = hir.tables().expr_ty_adjusted(ast_expr);
735738
let owner_id = tcx.hir().body_owner(body_id);
736739
let span = tcx.hir().span(owner_id);
737-
let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, ty_span,vec![]);
740+
let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, ty_span, vec![], vec![]);
738741

739742
let mut block = START_BLOCK;
740743
let expr = builder.hir.mirror(ast_expr);
@@ -762,7 +765,7 @@ fn construct_error<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>,
762765
let owner_id = hir.tcx().hir().body_owner(body_id);
763766
let span = hir.tcx().hir().span(owner_id);
764767
let ty = hir.tcx().types.err;
765-
let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, span, vec![]);
768+
let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, span, vec![], vec![]);
766769
let source_info = builder.source_info(span);
767770
builder.cfg.terminate(START_BLOCK, source_info, TerminatorKind::Unreachable);
768771
builder.finish(None)
@@ -775,7 +778,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
775778
safety: Safety,
776779
return_ty: Ty<'tcx>,
777780
return_span: Span,
778-
upvar_decls: Vec<UpvarDecl>)
781+
upvar_decls: Vec<UpvarDecl>,
782+
upvar_mutbls: Vec<Mutability>)
779783
-> Builder<'a, 'gcx, 'tcx> {
780784
let lint_level = LintLevel::Explicit(hir.root_lint_level);
781785
let mut builder = Builder {
@@ -798,6 +802,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
798802
),
799803
canonical_user_type_annotations: IndexVec::new(),
800804
upvar_decls,
805+
upvar_mutbls,
801806
var_indices: Default::default(),
802807
unit_temp: None,
803808
cached_resume_block: None,

0 commit comments

Comments
 (0)