compute liveness later
This commit is contained in:
parent
ccb550fb45
commit
fb1702f301
@ -11,7 +11,7 @@
|
||||
use borrow_check::borrow_set::BorrowSet;
|
||||
use borrow_check::location::{LocationIndex, LocationTable};
|
||||
use borrow_check::nll::facts::AllFactsExt;
|
||||
use borrow_check::nll::type_check::MirTypeckRegionConstraints;
|
||||
use borrow_check::nll::type_check::{MirTypeckResults, MirTypeckRegionConstraints};
|
||||
use borrow_check::nll::region_infer::values::RegionValueElements;
|
||||
use borrow_check::nll::liveness_map::{NllLivenessMap, LocalWithRegion};
|
||||
use dataflow::indexes::BorrowIndex;
|
||||
@ -109,9 +109,12 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
|
||||
let elements = &Rc::new(RegionValueElements::new(mir));
|
||||
|
||||
// Run the MIR type-checker.
|
||||
let liveness_map = NllLivenessMap::compute(&mir);
|
||||
let liveness = LivenessResults::compute(mir, &liveness_map);
|
||||
let (constraint_sets, universal_region_relations) = type_check::type_check(
|
||||
let MirTypeckResults {
|
||||
constraints,
|
||||
universal_region_relations,
|
||||
liveness,
|
||||
liveness_map,
|
||||
} = type_check::type_check(
|
||||
infcx,
|
||||
param_env,
|
||||
mir,
|
||||
@ -119,7 +122,6 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
|
||||
&universal_regions,
|
||||
location_table,
|
||||
borrow_set,
|
||||
&liveness,
|
||||
&mut all_facts,
|
||||
flow_inits,
|
||||
move_data,
|
||||
@ -141,7 +143,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
|
||||
mut liveness_constraints,
|
||||
outlives_constraints,
|
||||
type_tests,
|
||||
} = constraint_sets;
|
||||
} = constraints;
|
||||
|
||||
constraint_generation::generate_constraints(
|
||||
infcx,
|
||||
@ -205,6 +207,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
|
||||
dump_mir_results(
|
||||
infcx,
|
||||
&liveness,
|
||||
&liveness_map,
|
||||
MirSource::item(def_id),
|
||||
&mir,
|
||||
®ioncx,
|
||||
@ -221,6 +224,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
|
||||
fn dump_mir_results<'a, 'gcx, 'tcx>(
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
liveness: &LivenessResults<LocalWithRegion>,
|
||||
liveness_map: &NllLivenessMap,
|
||||
source: MirSource,
|
||||
mir: &Mir<'tcx>,
|
||||
regioncx: &RegionInferenceContext,
|
||||
@ -230,8 +234,6 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
|
||||
return;
|
||||
}
|
||||
|
||||
let map = &NllLivenessMap::compute(mir);
|
||||
|
||||
let regular_liveness_per_location: FxHashMap<_, _> = mir
|
||||
.basic_blocks()
|
||||
.indices()
|
||||
@ -239,7 +241,7 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
|
||||
let mut results = vec![];
|
||||
liveness
|
||||
.regular
|
||||
.simulate_block(&mir, bb, map, |location, local_set| {
|
||||
.simulate_block(&mir, bb, liveness_map, |location, local_set| {
|
||||
results.push((location, local_set.clone()));
|
||||
});
|
||||
results
|
||||
@ -253,7 +255,7 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
|
||||
let mut results = vec![];
|
||||
liveness
|
||||
.drop
|
||||
.simulate_block(&mir, bb, map, |location, local_set| {
|
||||
.simulate_block(&mir, bb, liveness_map, |location, local_set| {
|
||||
results.push((location, local_set.clone()));
|
||||
});
|
||||
results
|
||||
|
@ -36,23 +36,29 @@ use super::TypeChecker;
|
||||
pub(super) fn generate<'gcx, 'tcx>(
|
||||
cx: &mut TypeChecker<'_, 'gcx, 'tcx>,
|
||||
mir: &Mir<'tcx>,
|
||||
liveness: &LivenessResults<LocalWithRegion>,
|
||||
flow_inits: &mut FlowAtLocation<MaybeInitializedPlaces<'_, 'gcx, 'tcx>>,
|
||||
move_data: &MoveData<'tcx>,
|
||||
) {
|
||||
let mut generator = TypeLivenessGenerator {
|
||||
cx,
|
||||
mir,
|
||||
liveness,
|
||||
flow_inits,
|
||||
move_data,
|
||||
drop_data: FxHashMap(),
|
||||
map: &NllLivenessMap::compute(mir),
|
||||
};
|
||||
) -> (LivenessResults<LocalWithRegion>, NllLivenessMap) {
|
||||
let liveness_map = NllLivenessMap::compute(&mir);
|
||||
let liveness = LivenessResults::compute(mir, &liveness_map);
|
||||
|
||||
for bb in mir.basic_blocks().indices() {
|
||||
generator.add_liveness_constraints(bb);
|
||||
{
|
||||
let mut generator = TypeLivenessGenerator {
|
||||
cx,
|
||||
mir,
|
||||
liveness: &liveness,
|
||||
flow_inits,
|
||||
move_data,
|
||||
drop_data: FxHashMap(),
|
||||
map: &liveness_map,
|
||||
};
|
||||
|
||||
for bb in mir.basic_blocks().indices() {
|
||||
generator.add_liveness_constraints(bb);
|
||||
}
|
||||
}
|
||||
|
||||
(liveness, liveness_map)
|
||||
}
|
||||
|
||||
struct TypeLivenessGenerator<'gen, 'typeck, 'flow, 'gcx, 'tcx>
|
||||
|
@ -15,6 +15,7 @@ use borrow_check::borrow_set::BorrowSet;
|
||||
use borrow_check::location::LocationTable;
|
||||
use borrow_check::nll::constraints::{ConstraintSet, OutlivesConstraint};
|
||||
use borrow_check::nll::facts::AllFacts;
|
||||
use borrow_check::nll::liveness_map::NllLivenessMap;
|
||||
use borrow_check::nll::region_infer::values::{RegionValueElements, LivenessValues};
|
||||
use borrow_check::nll::region_infer::{ClosureRegionRequirementsExt, TypeTest};
|
||||
use borrow_check::nll::type_check::free_region_relations::{CreateResult, UniversalRegionRelations};
|
||||
@ -115,16 +116,12 @@ pub(crate) fn type_check<'gcx, 'tcx>(
|
||||
universal_regions: &Rc<UniversalRegions<'tcx>>,
|
||||
location_table: &LocationTable,
|
||||
borrow_set: &BorrowSet<'tcx>,
|
||||
liveness: &LivenessResults<LocalWithRegion>,
|
||||
all_facts: &mut Option<AllFacts>,
|
||||
flow_inits: &mut FlowAtLocation<MaybeInitializedPlaces<'_, 'gcx, 'tcx>>,
|
||||
move_data: &MoveData<'tcx>,
|
||||
elements: &Rc<RegionValueElements>,
|
||||
errors_buffer: &mut Vec<Diagnostic>,
|
||||
) -> (
|
||||
MirTypeckRegionConstraints<'tcx>,
|
||||
Rc<UniversalRegionRelations<'tcx>>,
|
||||
) {
|
||||
) -> MirTypeckResults<'tcx> {
|
||||
let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body));
|
||||
let mut constraints = MirTypeckRegionConstraints {
|
||||
liveness_constraints: LivenessValues::new(elements),
|
||||
@ -147,7 +144,7 @@ pub(crate) fn type_check<'gcx, 'tcx>(
|
||||
all_facts,
|
||||
);
|
||||
|
||||
{
|
||||
let (liveness, liveness_map) = {
|
||||
let mut borrowck_context = BorrowCheckContext {
|
||||
universal_regions,
|
||||
location_table,
|
||||
@ -166,7 +163,6 @@ pub(crate) fn type_check<'gcx, 'tcx>(
|
||||
Some(&mut borrowck_context),
|
||||
Some(errors_buffer),
|
||||
|cx| {
|
||||
liveness::generate(cx, mir, liveness, flow_inits, move_data);
|
||||
cx.equate_inputs_and_outputs(
|
||||
mir,
|
||||
mir_def_id,
|
||||
@ -174,14 +170,20 @@ pub(crate) fn type_check<'gcx, 'tcx>(
|
||||
&universal_region_relations,
|
||||
&normalized_inputs_and_output,
|
||||
);
|
||||
liveness::generate(cx, mir, flow_inits, move_data)
|
||||
},
|
||||
);
|
||||
}
|
||||
)
|
||||
};
|
||||
|
||||
(constraints, universal_region_relations)
|
||||
MirTypeckResults {
|
||||
constraints,
|
||||
universal_region_relations,
|
||||
liveness,
|
||||
liveness_map,
|
||||
}
|
||||
}
|
||||
|
||||
fn type_check_internal<'a, 'gcx, 'tcx, F>(
|
||||
fn type_check_internal<'a, 'gcx, 'tcx, R>(
|
||||
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
|
||||
mir_def_id: DefId,
|
||||
param_env: ty::ParamEnv<'gcx>,
|
||||
@ -190,10 +192,8 @@ fn type_check_internal<'a, 'gcx, 'tcx, F>(
|
||||
implicit_region_bound: Option<ty::Region<'tcx>>,
|
||||
borrowck_context: Option<&'a mut BorrowCheckContext<'a, 'tcx>>,
|
||||
errors_buffer: Option<&mut Vec<Diagnostic>>,
|
||||
mut extra: F,
|
||||
) where
|
||||
F: FnMut(&mut TypeChecker<'a, 'gcx, 'tcx>),
|
||||
{
|
||||
mut extra: impl FnMut(&mut TypeChecker<'a, 'gcx, 'tcx>) -> R,
|
||||
) -> R where {
|
||||
let mut checker = TypeChecker::new(
|
||||
infcx,
|
||||
mir,
|
||||
@ -214,7 +214,7 @@ fn type_check_internal<'a, 'gcx, 'tcx, F>(
|
||||
checker.typeck_mir(mir, errors_buffer);
|
||||
}
|
||||
|
||||
extra(&mut checker);
|
||||
extra(&mut checker)
|
||||
}
|
||||
|
||||
fn mirbug(tcx: TyCtxt, span: Span, msg: &str) {
|
||||
@ -655,6 +655,13 @@ struct BorrowCheckContext<'a, 'tcx: 'a> {
|
||||
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
|
||||
}
|
||||
|
||||
crate struct MirTypeckResults<'tcx> {
|
||||
crate constraints: MirTypeckRegionConstraints<'tcx>,
|
||||
crate universal_region_relations: Rc<UniversalRegionRelations<'tcx>>,
|
||||
crate liveness: LivenessResults<LocalWithRegion>,
|
||||
crate liveness_map: NllLivenessMap,
|
||||
}
|
||||
|
||||
/// A collection of region constraints that must be satisfied for the
|
||||
/// program to be considered well-typed.
|
||||
crate struct MirTypeckRegionConstraints<'tcx> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user