Rollup merge of #130294 - nnethercote:more-lifetimes, r=lcnr
Lifetime cleanups The last commit is very opinionated, let's see how we go. r? `@oli-obk`
This commit is contained in:
commit
03e8b6bbfa
49 changed files with 224 additions and 231 deletions
|
@ -97,11 +97,11 @@ impl<D: ConstraintGraphDirection> ConstraintGraph<D> {
|
|||
/// Given the constraint set from which this graph was built
|
||||
/// creates a region graph so that you can iterate over *regions*
|
||||
/// and not constraints.
|
||||
pub(crate) fn region_graph<'rg, 'tcx>(
|
||||
&'rg self,
|
||||
set: &'rg OutlivesConstraintSet<'tcx>,
|
||||
pub(crate) fn region_graph<'a, 'tcx>(
|
||||
&'a self,
|
||||
set: &'a OutlivesConstraintSet<'tcx>,
|
||||
static_region: RegionVid,
|
||||
) -> RegionGraph<'rg, 'tcx, D> {
|
||||
) -> RegionGraph<'a, 'tcx, D> {
|
||||
RegionGraph::new(set, self, static_region)
|
||||
}
|
||||
|
||||
|
@ -130,15 +130,15 @@ impl<D: ConstraintGraphDirection> ConstraintGraph<D> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Edges<'s, 'tcx, D: ConstraintGraphDirection> {
|
||||
graph: &'s ConstraintGraph<D>,
|
||||
constraints: &'s OutlivesConstraintSet<'tcx>,
|
||||
pub(crate) struct Edges<'a, 'tcx, D: ConstraintGraphDirection> {
|
||||
graph: &'a ConstraintGraph<D>,
|
||||
constraints: &'a OutlivesConstraintSet<'tcx>,
|
||||
pointer: Option<OutlivesConstraintIndex>,
|
||||
next_static_idx: Option<usize>,
|
||||
static_region: RegionVid,
|
||||
}
|
||||
|
||||
impl<'s, 'tcx, D: ConstraintGraphDirection> Iterator for Edges<'s, 'tcx, D> {
|
||||
impl<'a, 'tcx, D: ConstraintGraphDirection> Iterator for Edges<'a, 'tcx, D> {
|
||||
type Item = OutlivesConstraint<'tcx>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -171,20 +171,20 @@ impl<'s, 'tcx, D: ConstraintGraphDirection> Iterator for Edges<'s, 'tcx, D> {
|
|||
/// This struct brings together a constraint set and a (normal, not
|
||||
/// reverse) constraint graph. It implements the graph traits and is
|
||||
/// usd for doing the SCC computation.
|
||||
pub(crate) struct RegionGraph<'s, 'tcx, D: ConstraintGraphDirection> {
|
||||
set: &'s OutlivesConstraintSet<'tcx>,
|
||||
constraint_graph: &'s ConstraintGraph<D>,
|
||||
pub(crate) struct RegionGraph<'a, 'tcx, D: ConstraintGraphDirection> {
|
||||
set: &'a OutlivesConstraintSet<'tcx>,
|
||||
constraint_graph: &'a ConstraintGraph<D>,
|
||||
static_region: RegionVid,
|
||||
}
|
||||
|
||||
impl<'s, 'tcx, D: ConstraintGraphDirection> RegionGraph<'s, 'tcx, D> {
|
||||
impl<'a, 'tcx, D: ConstraintGraphDirection> RegionGraph<'a, 'tcx, D> {
|
||||
/// Creates a "dependency graph" where each region constraint `R1:
|
||||
/// R2` is treated as an edge `R1 -> R2`. We use this graph to
|
||||
/// construct SCCs for region inference but also for error
|
||||
/// reporting.
|
||||
pub(crate) fn new(
|
||||
set: &'s OutlivesConstraintSet<'tcx>,
|
||||
constraint_graph: &'s ConstraintGraph<D>,
|
||||
set: &'a OutlivesConstraintSet<'tcx>,
|
||||
constraint_graph: &'a ConstraintGraph<D>,
|
||||
static_region: RegionVid,
|
||||
) -> Self {
|
||||
Self { set, constraint_graph, static_region }
|
||||
|
@ -192,18 +192,18 @@ impl<'s, 'tcx, D: ConstraintGraphDirection> RegionGraph<'s, 'tcx, D> {
|
|||
|
||||
/// Given a region `R`, iterate over all regions `R1` such that
|
||||
/// there exists a constraint `R: R1`.
|
||||
pub(crate) fn outgoing_regions(&self, region_sup: RegionVid) -> Successors<'s, 'tcx, D> {
|
||||
pub(crate) fn outgoing_regions(&self, region_sup: RegionVid) -> Successors<'a, 'tcx, D> {
|
||||
Successors {
|
||||
edges: self.constraint_graph.outgoing_edges(region_sup, self.set, self.static_region),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Successors<'s, 'tcx, D: ConstraintGraphDirection> {
|
||||
edges: Edges<'s, 'tcx, D>,
|
||||
pub(crate) struct Successors<'a, 'tcx, D: ConstraintGraphDirection> {
|
||||
edges: Edges<'a, 'tcx, D>,
|
||||
}
|
||||
|
||||
impl<'s, 'tcx, D: ConstraintGraphDirection> Iterator for Successors<'s, 'tcx, D> {
|
||||
impl<'a, 'tcx, D: ConstraintGraphDirection> Iterator for Successors<'a, 'tcx, D> {
|
||||
type Item = RegionVid;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -211,7 +211,7 @@ impl<'s, 'tcx, D: ConstraintGraphDirection> Iterator for Successors<'s, 'tcx, D>
|
|||
}
|
||||
}
|
||||
|
||||
impl<'s, 'tcx, D: ConstraintGraphDirection> graph::DirectedGraph for RegionGraph<'s, 'tcx, D> {
|
||||
impl<'a, 'tcx, D: ConstraintGraphDirection> graph::DirectedGraph for RegionGraph<'a, 'tcx, D> {
|
||||
type Node = RegionVid;
|
||||
|
||||
fn num_nodes(&self) -> usize {
|
||||
|
@ -219,7 +219,7 @@ impl<'s, 'tcx, D: ConstraintGraphDirection> graph::DirectedGraph for RegionGraph
|
|||
}
|
||||
}
|
||||
|
||||
impl<'s, 'tcx, D: ConstraintGraphDirection> graph::Successors for RegionGraph<'s, 'tcx, D> {
|
||||
impl<'a, 'tcx, D: ConstraintGraphDirection> graph::Successors for RegionGraph<'a, 'tcx, D> {
|
||||
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
|
||||
self.outgoing_regions(node)
|
||||
}
|
||||
|
|
|
@ -112,16 +112,16 @@ pub struct Borrows<'a, 'tcx> {
|
|||
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
|
||||
}
|
||||
|
||||
struct OutOfScopePrecomputer<'mir, 'tcx> {
|
||||
struct OutOfScopePrecomputer<'a, 'tcx> {
|
||||
visited: BitSet<mir::BasicBlock>,
|
||||
visit_stack: Vec<mir::BasicBlock>,
|
||||
body: &'mir Body<'tcx>,
|
||||
regioncx: &'mir RegionInferenceContext<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
regioncx: &'a RegionInferenceContext<'tcx>,
|
||||
borrows_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
|
||||
}
|
||||
|
||||
impl<'mir, 'tcx> OutOfScopePrecomputer<'mir, 'tcx> {
|
||||
fn new(body: &'mir Body<'tcx>, regioncx: &'mir RegionInferenceContext<'tcx>) -> Self {
|
||||
impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
|
||||
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
|
||||
OutOfScopePrecomputer {
|
||||
visited: BitSet::new_empty(body.basic_blocks.len()),
|
||||
visit_stack: vec![],
|
||||
|
@ -224,17 +224,17 @@ pub fn calculate_borrows_out_of_scope_at_location<'tcx>(
|
|||
prec.borrows_out_of_scope_at_location
|
||||
}
|
||||
|
||||
struct PoloniusOutOfScopePrecomputer<'mir, 'tcx> {
|
||||
struct PoloniusOutOfScopePrecomputer<'a, 'tcx> {
|
||||
visited: BitSet<mir::BasicBlock>,
|
||||
visit_stack: Vec<mir::BasicBlock>,
|
||||
body: &'mir Body<'tcx>,
|
||||
regioncx: &'mir RegionInferenceContext<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
regioncx: &'a RegionInferenceContext<'tcx>,
|
||||
|
||||
loans_out_of_scope_at_location: FxIndexMap<Location, Vec<BorrowIndex>>,
|
||||
}
|
||||
|
||||
impl<'mir, 'tcx> PoloniusOutOfScopePrecomputer<'mir, 'tcx> {
|
||||
fn new(body: &'mir Body<'tcx>, regioncx: &'mir RegionInferenceContext<'tcx>) -> Self {
|
||||
impl<'a, 'tcx> PoloniusOutOfScopePrecomputer<'a, 'tcx> {
|
||||
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
|
||||
Self {
|
||||
visited: BitSet::new_empty(body.basic_blocks.len()),
|
||||
visit_stack: vec![],
|
||||
|
|
|
@ -3553,7 +3553,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
location: Location,
|
||||
mpi: MovePathIndex,
|
||||
) -> (Vec<MoveSite>, Vec<Location>) {
|
||||
fn predecessor_locations<'tcx, 'a>(
|
||||
fn predecessor_locations<'a, 'tcx>(
|
||||
body: &'a mir::Body<'tcx>,
|
||||
location: Location,
|
||||
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
|
||||
|
|
|
@ -21,15 +21,15 @@ pub(crate) fn find<'tcx>(
|
|||
uf.find()
|
||||
}
|
||||
|
||||
struct UseFinder<'cx, 'tcx> {
|
||||
body: &'cx Body<'tcx>,
|
||||
regioncx: &'cx Rc<RegionInferenceContext<'tcx>>,
|
||||
struct UseFinder<'a, 'tcx> {
|
||||
body: &'a Body<'tcx>,
|
||||
regioncx: &'a Rc<RegionInferenceContext<'tcx>>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
region_vid: RegionVid,
|
||||
start_point: Location,
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> UseFinder<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> UseFinder<'a, 'tcx> {
|
||||
fn find(&mut self) -> Option<Cause> {
|
||||
let mut queue = VecDeque::new();
|
||||
let mut visited = FxIndexSet::default();
|
||||
|
@ -93,8 +93,8 @@ impl<'cx, 'tcx> UseFinder<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
struct DefUseVisitor<'cx, 'tcx> {
|
||||
body: &'cx Body<'tcx>,
|
||||
struct DefUseVisitor<'a, 'tcx> {
|
||||
body: &'a Body<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
region_vid: RegionVid,
|
||||
def_use_result: Option<DefUseResult>,
|
||||
|
@ -106,7 +106,7 @@ enum DefUseResult {
|
|||
UseDrop { local: Local },
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> Visitor<'tcx> for DefUseVisitor<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for DefUseVisitor<'a, 'tcx> {
|
||||
fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
|
||||
let local_ty = self.body.local_decls[local].ty;
|
||||
|
||||
|
|
|
@ -558,7 +558,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
suggested: bool,
|
||||
}
|
||||
impl<'a, 'cx, 'tcx> Visitor<'tcx> for SuggestIndexOperatorAlternativeVisitor<'a, 'cx, 'tcx> {
|
||||
impl<'a, 'infcx, 'tcx> Visitor<'tcx> for SuggestIndexOperatorAlternativeVisitor<'a, 'infcx, 'tcx> {
|
||||
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
|
||||
hir::intravisit::walk_stmt(self, stmt);
|
||||
let expr = match stmt.kind {
|
||||
|
|
|
@ -32,18 +32,18 @@ pub(super) fn emit_loan_invalidations<'tcx>(
|
|||
visitor.visit_body(body);
|
||||
}
|
||||
|
||||
struct LoanInvalidationsGenerator<'cx, 'tcx> {
|
||||
struct LoanInvalidationsGenerator<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
all_facts: &'cx mut AllFacts,
|
||||
location_table: &'cx LocationTable,
|
||||
body: &'cx Body<'tcx>,
|
||||
dominators: &'cx Dominators<BasicBlock>,
|
||||
borrow_set: &'cx BorrowSet<'tcx>,
|
||||
all_facts: &'a mut AllFacts,
|
||||
location_table: &'a LocationTable,
|
||||
body: &'a Body<'tcx>,
|
||||
dominators: &'a Dominators<BasicBlock>,
|
||||
borrow_set: &'a BorrowSet<'tcx>,
|
||||
}
|
||||
|
||||
/// Visits the whole MIR and generates `invalidates()` facts.
|
||||
/// Most of the code implementing this was stolen from `borrow_check/mod.rs`.
|
||||
impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> {
|
||||
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
|
||||
self.check_activations(location);
|
||||
|
||||
|
@ -212,7 +212,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> LoanInvalidationsGenerator<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
|
||||
/// Simulates mutation of a place.
|
||||
fn mutate_place(&mut self, location: Location, place: Place<'tcx>, kind: AccessDepth) {
|
||||
self.access_place(
|
||||
|
|
|
@ -25,15 +25,15 @@ pub(super) fn emit_loan_kills<'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
struct LoanKillsGenerator<'cx, 'tcx> {
|
||||
struct LoanKillsGenerator<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
all_facts: &'cx mut AllFacts,
|
||||
location_table: &'cx LocationTable,
|
||||
borrow_set: &'cx BorrowSet<'tcx>,
|
||||
body: &'cx Body<'tcx>,
|
||||
all_facts: &'a mut AllFacts,
|
||||
location_table: &'a LocationTable,
|
||||
borrow_set: &'a BorrowSet<'tcx>,
|
||||
body: &'a Body<'tcx>,
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> Visitor<'tcx> for LoanKillsGenerator<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for LoanKillsGenerator<'a, 'tcx> {
|
||||
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
|
||||
// Also record CFG facts here.
|
||||
self.all_facts.cfg_edge.push((
|
||||
|
|
|
@ -181,12 +181,12 @@ impl UniversalRegionRelations<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
struct UniversalRegionRelationsBuilder<'this, 'tcx> {
|
||||
infcx: &'this InferCtxt<'tcx>,
|
||||
struct UniversalRegionRelationsBuilder<'a, 'tcx> {
|
||||
infcx: &'a InferCtxt<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
universal_regions: Rc<UniversalRegions<'tcx>>,
|
||||
implicit_region_bound: ty::Region<'tcx>,
|
||||
constraints: &'this mut MirTypeckRegionConstraints<'tcx>,
|
||||
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
|
||||
|
||||
// outputs:
|
||||
outlives: TransitiveRelationBuilder<RegionVid>,
|
||||
|
|
|
@ -148,12 +148,12 @@ fn record_regular_live_regions<'tcx>(
|
|||
}
|
||||
|
||||
/// Visitor looking for regions that should be live within rvalues or calls.
|
||||
struct LiveVariablesVisitor<'cx, 'tcx> {
|
||||
struct LiveVariablesVisitor<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
liveness_constraints: &'cx mut LivenessValues,
|
||||
liveness_constraints: &'a mut LivenessValues,
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> Visitor<'tcx> for LiveVariablesVisitor<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for LiveVariablesVisitor<'a, 'tcx> {
|
||||
/// We sometimes have `args` within an rvalue, or within a
|
||||
/// call. Make them live at the location where they appear.
|
||||
fn visit_args(&mut self, args: &GenericArgsRef<'tcx>, location: Location) {
|
||||
|
@ -188,7 +188,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for LiveVariablesVisitor<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'cx, 'tcx> LiveVariablesVisitor<'cx, 'tcx> {
|
||||
impl<'a, 'tcx> LiveVariablesVisitor<'a, 'tcx> {
|
||||
/// Some variable is "regular live" at `location` -- i.e., it may be used later. This means that
|
||||
/// all regions appearing in the type of `value` must be live at `location`.
|
||||
fn record_regions_live_at<T>(&mut self, value: T, location: Location)
|
||||
|
|
|
@ -11,13 +11,13 @@ use crate::location::{LocationIndex, LocationTable};
|
|||
type VarPointRelation = Vec<(Local, LocationIndex)>;
|
||||
type PathPointRelation = Vec<(MovePathIndex, LocationIndex)>;
|
||||
|
||||
struct UseFactsExtractor<'me, 'tcx> {
|
||||
var_defined_at: &'me mut VarPointRelation,
|
||||
var_used_at: &'me mut VarPointRelation,
|
||||
location_table: &'me LocationTable,
|
||||
var_dropped_at: &'me mut VarPointRelation,
|
||||
move_data: &'me MoveData<'tcx>,
|
||||
path_accessed_at_base: &'me mut PathPointRelation,
|
||||
struct UseFactsExtractor<'a, 'tcx> {
|
||||
var_defined_at: &'a mut VarPointRelation,
|
||||
var_used_at: &'a mut VarPointRelation,
|
||||
location_table: &'a LocationTable,
|
||||
var_dropped_at: &'a mut VarPointRelation,
|
||||
move_data: &'a MoveData<'tcx>,
|
||||
path_accessed_at_base: &'a mut PathPointRelation,
|
||||
}
|
||||
|
||||
// A Visitor to walk through the MIR and extract point-wise facts
|
||||
|
|
|
@ -58,8 +58,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
struct NllTypeRelating<'me, 'bccx, 'tcx> {
|
||||
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,
|
||||
struct NllTypeRelating<'a, 'b, 'tcx> {
|
||||
type_checker: &'a mut TypeChecker<'b, 'tcx>,
|
||||
|
||||
/// Where (and why) is this relation taking place?
|
||||
locations: Locations,
|
||||
|
@ -82,9 +82,9 @@ struct NllTypeRelating<'me, 'bccx, 'tcx> {
|
|||
ambient_variance_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
|
||||
impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
|
||||
fn new(
|
||||
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,
|
||||
type_checker: &'a mut TypeChecker<'b, 'tcx>,
|
||||
locations: Locations,
|
||||
category: ConstraintCategory<'tcx>,
|
||||
universe_info: UniverseInfo<'tcx>,
|
||||
|
@ -309,7 +309,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx> {
|
||||
impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
|
||||
fn cx(&self) -> TyCtxt<'tcx> {
|
||||
self.type_checker.infcx.tcx
|
||||
}
|
||||
|
@ -520,7 +520,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
|
|||
}
|
||||
}
|
||||
|
||||
impl<'bccx, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx> {
|
||||
impl<'b, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
|
||||
fn span(&self) -> Span {
|
||||
self.locations.span(self.type_checker.body)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue