Skip to content

Commit 2570023

Browse files
committed
Create definitions for promoted constants.
1 parent fdd0301 commit 2570023

File tree

101 files changed

+531
-605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+531
-605
lines changed

compiler/rustc_borrowck/src/consumers.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! This file provides API for compiler consumers.
44
55
use rustc_hir::def_id::LocalDefId;
6-
use rustc_index::IndexSlice;
76
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
87
use rustc_middle::mir::Body;
98
use rustc_middle::ty::TyCtxt;
@@ -29,9 +28,8 @@ pub use super::{
2928
///
3029
/// * Polonius is highly unstable, so expect regular changes in its signature or other details.
3130
pub fn get_body_with_borrowck_facts(tcx: TyCtxt<'_>, def: LocalDefId) -> BodyWithBorrowckFacts<'_> {
32-
let (input_body, promoted) = tcx.mir_promoted(def);
31+
let (input_body, _) = tcx.mir_promoted(def);
3332
let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(def)).build();
3433
let input_body: &Body<'_> = &input_body.borrow();
35-
let promoted: &IndexSlice<_, _> = &promoted.borrow();
36-
*super::do_mir_borrowck(&infcx, input_body, promoted, true).1.unwrap()
34+
*super::do_mir_borrowck(&infcx, input_body, true).1.unwrap()
3735
}

compiler/rustc_borrowck/src/lib.rs

+8-57
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,11 @@ use rustc_fluent_macro::fluent_messages;
2424
use rustc_hir as hir;
2525
use rustc_hir::def_id::LocalDefId;
2626
use rustc_index::bit_set::ChunkedBitSet;
27-
use rustc_index::{IndexSlice, IndexVec};
27+
use rustc_index::IndexVec;
2828
use rustc_infer::infer::{
2929
DefiningAnchor, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
3030
};
31-
use rustc_middle::mir::{
32-
traversal, Body, ClearCrossCrate, Local, Location, Mutability, NonDivergingIntrinsic, Operand,
33-
Place, PlaceElem, PlaceRef, VarDebugInfoContents,
34-
};
35-
use rustc_middle::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind};
36-
use rustc_middle::mir::{InlineAsmOperand, Terminator, TerminatorKind};
37-
use rustc_middle::mir::{ProjectionElem, Promoted, Rvalue, Statement, StatementKind};
31+
use rustc_middle::mir::*;
3832
use rustc_middle::query::Providers;
3933
use rustc_middle::ty::{self, CapturedPlace, ParamEnv, RegionVid, TyCtxt};
4034
use rustc_session::lint::builtin::UNUSED_MUT;
@@ -123,7 +117,7 @@ pub fn provide(providers: &mut Providers) {
123117
}
124118

125119
fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
126-
let (input_body, promoted) = tcx.mir_promoted(def);
120+
let (input_body, _) = tcx.mir_promoted(def);
127121
debug!("run query mir_borrowck: {}", tcx.def_path_str(def));
128122

129123
if input_body.borrow().should_skip() {
@@ -138,13 +132,11 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
138132
return tcx.arena.alloc(result);
139133
}
140134

141-
let hir_owner = tcx.hir().local_def_id_to_hir_id(def).owner;
142-
135+
let typeck_root = tcx.typeck_root_def_id(def.to_def_id()).expect_local();
143136
let infcx =
144-
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)).build();
137+
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(typeck_root)).build();
145138
let input_body: &Body<'_> = &input_body.borrow();
146-
let promoted: &IndexSlice<_, _> = &promoted.borrow();
147-
let opt_closure_req = do_mir_borrowck(&infcx, input_body, promoted, false).0;
139+
let opt_closure_req = do_mir_borrowck(&infcx, input_body, false).0;
148140
debug!("mir_borrowck done");
149141

150142
tcx.arena.alloc(opt_closure_req)
@@ -155,11 +147,10 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
155147
/// If `return_body_with_facts` is true, then return the body with non-erased
156148
/// region ids on which the borrow checking was performed together with Polonius
157149
/// facts.
158-
#[instrument(skip(infcx, input_body, input_promoted), fields(id=?input_body.source.def_id()), level = "debug")]
150+
#[instrument(skip(infcx, input_body), fields(id=?input_body.source.def_id()), level = "debug")]
159151
fn do_mir_borrowck<'tcx>(
160152
infcx: &InferCtxt<'tcx>,
161153
input_body: &Body<'tcx>,
162-
input_promoted: &IndexSlice<Promoted, Body<'tcx>>,
163154
return_body_with_facts: bool,
164155
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
165156
let def = input_body.source.def_id().expect_local();
@@ -212,9 +203,7 @@ fn do_mir_borrowck<'tcx>(
212203
// be modified (in place) to contain non-lexical lifetimes. It
213204
// will have a lifetime tied to the inference context.
214205
let mut body_owned = input_body.clone();
215-
let mut promoted = input_promoted.to_owned();
216-
let free_regions =
217-
nll::replace_regions_in_mir(&infcx, param_env, &mut body_owned, &mut promoted);
206+
let free_regions = nll::replace_regions_in_mir(&infcx, param_env, &mut body_owned);
218207
let body = &body_owned; // no further changes
219208

220209
let location_table_owned = LocationTable::new(body);
@@ -225,9 +214,6 @@ fn do_mir_borrowck<'tcx>(
225214
Ok((_, move_data)) => (move_data, Vec::new()),
226215
Err((move_data, move_errors)) => (move_data, move_errors),
227216
};
228-
let promoted_errors = promoted
229-
.iter_enumerated()
230-
.map(|(idx, body)| (idx, MoveData::gather_moves(&body, tcx, param_env)));
231217

232218
let mdpe = MoveDataParamEnv { move_data, param_env };
233219

@@ -255,7 +241,6 @@ fn do_mir_borrowck<'tcx>(
255241
&infcx,
256242
free_regions,
257243
body,
258-
&promoted,
259244
location_table,
260245
param_env,
261246
&mut flow_inits,
@@ -311,39 +296,6 @@ fn do_mir_borrowck<'tcx>(
311296
true
312297
};
313298

314-
for (idx, move_data_results) in promoted_errors {
315-
let promoted_body = &promoted[idx];
316-
317-
if let Err((move_data, move_errors)) = move_data_results {
318-
let mut promoted_mbcx = MirBorrowckCtxt {
319-
infcx: &infcx,
320-
param_env,
321-
body: promoted_body,
322-
move_data: &move_data,
323-
location_table, // no need to create a real one for the promoted, it is not used
324-
movable_generator,
325-
fn_self_span_reported: Default::default(),
326-
locals_are_invalidated_at_exit,
327-
access_place_error_reported: Default::default(),
328-
reservation_error_reported: Default::default(),
329-
uninitialized_error_reported: Default::default(),
330-
regioncx: regioncx.clone(),
331-
used_mut: Default::default(),
332-
used_mut_upvars: SmallVec::new(),
333-
borrow_set: Rc::clone(&borrow_set),
334-
dominators: Default::default(),
335-
upvars: Vec::new(),
336-
local_names: IndexVec::from_elem(None, &promoted_body.local_decls),
337-
region_names: RefCell::default(),
338-
next_region_name: RefCell::new(1),
339-
polonius_output: None,
340-
errors,
341-
};
342-
promoted_mbcx.report_move_errors(move_errors);
343-
errors = promoted_mbcx.errors;
344-
};
345-
}
346-
347299
let mut mbcx = MirBorrowckCtxt {
348300
infcx: &infcx,
349301
param_env,
@@ -737,7 +689,6 @@ impl<'cx, 'tcx> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtx
737689
}
738690
TerminatorKind::Assert { cond, expected: _, msg, target: _, unwind: _ } => {
739691
self.consume_operand(loc, (cond, span), flow_state);
740-
use rustc_middle::mir::AssertKind;
741692
if let AssertKind::BoundsCheck { len, index } = &**msg {
742693
self.consume_operand(loc, (len, span), flow_state);
743694
self.consume_operand(loc, (index, span), flow_state);

compiler/rustc_borrowck/src/nll.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
55
use rustc_data_structures::fx::FxIndexMap;
66
use rustc_hir::def_id::LocalDefId;
7-
use rustc_index::IndexSlice;
87
use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere};
98
use rustc_middle::mir::{
10-
Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, Promoted,
11-
START_BLOCK,
9+
Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, START_BLOCK,
1210
};
1311
use rustc_middle::ty::{self, OpaqueHiddenType, TyCtxt};
1412
use rustc_span::symbol::sym;
@@ -54,12 +52,11 @@ pub(crate) struct NllOutput<'tcx> {
5452
/// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal
5553
/// regions (e.g., region parameters) declared on the function. That set will need to be given to
5654
/// `compute_regions`.
57-
#[instrument(skip(infcx, param_env, body, promoted), level = "debug")]
55+
#[instrument(skip(infcx, param_env, body), level = "debug")]
5856
pub(crate) fn replace_regions_in_mir<'tcx>(
5957
infcx: &BorrowckInferCtxt<'_, 'tcx>,
6058
param_env: ty::ParamEnv<'tcx>,
6159
body: &mut Body<'tcx>,
62-
promoted: &mut IndexSlice<Promoted, Body<'tcx>>,
6360
) -> UniversalRegions<'tcx> {
6461
let def = body.source.def_id().expect_local();
6562

@@ -69,7 +66,7 @@ pub(crate) fn replace_regions_in_mir<'tcx>(
6966
let universal_regions = UniversalRegions::new(infcx, def, param_env);
7067

7168
// Replace all remaining regions with fresh inference variables.
72-
renumber::renumber_mir(infcx, body, promoted);
69+
renumber::renumber_mir(infcx, body);
7370

7471
dump_mir(infcx.tcx, false, "renumber", &0, body, |_, _| Ok(()));
7572

@@ -158,7 +155,6 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
158155
infcx: &BorrowckInferCtxt<'_, 'tcx>,
159156
universal_regions: UniversalRegions<'tcx>,
160157
body: &Body<'tcx>,
161-
promoted: &IndexSlice<Promoted, Body<'tcx>>,
162158
location_table: &LocationTable,
163159
param_env: ty::ParamEnv<'tcx>,
164160
flow_inits: &mut ResultsCursor<'cx, 'tcx, MaybeInitializedPlaces<'cx, 'tcx>>,
@@ -180,7 +176,6 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
180176
infcx,
181177
param_env,
182178
body,
183-
promoted,
184179
&universal_regions,
185180
location_table,
186181
borrow_set,

compiler/rustc_borrowck/src/renumber.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
#![deny(rustc::untranslatable_diagnostic)]
22
#![deny(rustc::diagnostic_outside_of_impl)]
3+
34
use crate::BorrowckInferCtxt;
4-
use rustc_index::IndexSlice;
55
use rustc_infer::infer::NllRegionVariableOrigin;
66
use rustc_middle::mir::visit::{MutVisitor, TyContext};
77
use rustc_middle::mir::Constant;
8-
use rustc_middle::mir::{Body, Location, Promoted};
8+
use rustc_middle::mir::{Body, Location};
99
use rustc_middle::ty::subst::SubstsRef;
1010
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
1111
use rustc_span::{Span, Symbol};
1212

1313
/// Replaces all free regions appearing in the MIR with fresh
1414
/// inference variables, returning the number of variables created.
15-
#[instrument(skip(infcx, body, promoted), level = "debug")]
16-
pub fn renumber_mir<'tcx>(
17-
infcx: &BorrowckInferCtxt<'_, 'tcx>,
18-
body: &mut Body<'tcx>,
19-
promoted: &mut IndexSlice<Promoted, Body<'tcx>>,
20-
) {
15+
#[instrument(skip(infcx, body), level = "debug")]
16+
pub fn renumber_mir<'tcx>(infcx: &BorrowckInferCtxt<'_, 'tcx>, body: &mut Body<'tcx>) {
2117
debug!(?body.arg_count);
22-
23-
let mut renumberer = RegionRenumberer { infcx };
24-
25-
for body in promoted.iter_mut() {
26-
renumberer.visit_body(body);
27-
}
28-
29-
renumberer.visit_body(body);
18+
RegionRenumberer { infcx }.visit_body(body);
3019
}
3120

3221
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]

0 commit comments

Comments
 (0)