Skip to content

Commit c051f69

Browse files
committed
rarw
1 parent d03518e commit c051f69

File tree

3 files changed

+29
-37
lines changed

3 files changed

+29
-37
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,6 @@ pub struct RegionInferenceContext<'tcx> {
164164
/// compute the values of each region.
165165
constraint_sccs: ConstraintSccs,
166166

167-
/// Reverse of the SCC constraint graph -- i.e., an edge `A -> B` exists if
168-
/// `B: A`. This is used to compute the universal regions that are required
169-
/// to outlive a given SCC. Computed lazily.
170-
///
171-
/// TODO: this sohuld be removeable.
172-
rev_scc_graph: Option<ReverseSccGraph>,
173-
174167
/// Map universe indexes to information on why we created it.
175168
universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
176169

@@ -425,7 +418,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
425418
constraints,
426419
constraint_graph,
427420
constraint_sccs,
428-
rev_scc_graph: None,
429421
universe_causes,
430422
scc_values,
431423
type_tests,

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::constraints::{ConstraintSccIndex, OutlivesConstraintSet};
2626
use crate::consumers::OutlivesConstraint;
2727
use crate::type_check::free_region_relations::UniversalRegionRelations;
2828
use crate::type_check::{Locations, MirTypeckRegionConstraints};
29-
use crate::universal_regions::UniversalRegions;
29+
use crate::universal_regions::{self, RegionClassification, UniversalRegions};
3030
use crate::{BorrowCheckRootCtxt, BorrowckInferCtxt};
3131

3232
pub(crate) fn handle_opaque_type_uses<'tcx>(
@@ -77,11 +77,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
7777
'entry: for (&key, &hidden_type) in &opaque_types {
7878
let (key, hidden_type) =
7979
fold_regions(tcx, infcx.resolve_vars_if_possible((key, hidden_type)), |r, _| {
80-
if let ty::RePlaceholder(placeholder) = r.kind() {
81-
constraints.get_placeholder_region(placeholder)
82-
} else {
83-
ty::Region::new_var(tcx, universal_regions.to_region_vid(r))
84-
}
80+
Region::new_var(tcx, to_region_vid(&constraints, universal_regions, r))
8581
});
8682
// Check whether the arguments are fully universal.
8783
//
@@ -93,7 +89,12 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
9389
if let Some(region) = captured_arg.as_region() {
9490
let scc = constraint_sccs.scc(region.as_var());
9591
let vid = constraint_sccs.annotation(scc).representative;
96-
if matches!(definitions[vid].origin, NllRegionVariableOrigin::FreeRegion) {
92+
if matches!(definitions[vid].origin, NllRegionVariableOrigin::FreeRegion)
93+
&& !matches!(
94+
universal_regions.region_classification(vid),
95+
Some(RegionClassification::External)
96+
)
97+
{
9798
arg_regions.push((vid, definitions[vid].external_name.unwrap()));
9899
} else {
99100
continue 'entry;
@@ -152,7 +153,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
152153
infcx,
153154
span: hidden_type.span,
154155
universal_regions,
155-
outlives_constraints: &mut constraints.outlives_constraints,
156+
constraints: &mut constraints,
156157
};
157158
TypeRelation::relate(&mut relation, hidden_type.ty, expected).unwrap();
158159

@@ -171,6 +172,18 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
171172
constraints
172173
}
173174

175+
fn to_region_vid<'tcx>(
176+
constraints: &MirTypeckRegionConstraints<'tcx>,
177+
universal_regions: &UniversalRegions<'tcx>,
178+
r: Region<'tcx>,
179+
) -> RegionVid {
180+
if let ty::RePlaceholder(placeholder) = r.kind() {
181+
constraints.get_placeholder_region(placeholder).as_var()
182+
} else {
183+
universal_regions.to_region_vid(r)
184+
}
185+
}
186+
174187
struct OpaqueHiddenTypeFolder<'a, 'tcx> {
175188
infcx: &'a BorrowckInferCtxt<'tcx>,
176189
arg_regions: &'a [(RegionVid, Region<'tcx>)],
@@ -334,7 +347,7 @@ struct EquateRegions<'a, 'tcx> {
334347
infcx: &'a BorrowckInferCtxt<'tcx>,
335348
span: Span,
336349
universal_regions: &'a UniversalRegions<'tcx>,
337-
outlives_constraints: &'a mut OutlivesConstraintSet<'tcx>,
350+
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
338351
}
339352

340353
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for EquateRegions<'_, 'tcx> {
@@ -366,10 +379,10 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for EquateRegions<'_, 'tcx> {
366379
return Ok(a);
367380
}
368381

369-
let a_vid = self.universal_regions.to_region_vid(a);
370-
let b_vid = self.universal_regions.to_region_vid(b);
382+
let a_vid = to_region_vid(self.constraints, self.universal_regions, a);
383+
let b_vid = to_region_vid(self.constraints, self.universal_regions, b);
371384
let locations = Locations::All(self.span);
372-
self.outlives_constraints.push(OutlivesConstraint {
385+
self.constraints.outlives_constraints.push(OutlivesConstraint {
373386
sup: a_vid,
374387
sub: b_vid,
375388
locations,
@@ -378,7 +391,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for EquateRegions<'_, 'tcx> {
378391
variance_info: ty::VarianceDiagInfo::None,
379392
from_closure: false,
380393
});
381-
self.outlives_constraints.push(OutlivesConstraint {
394+
self.constraints.outlives_constraints.push(OutlivesConstraint {
382395
sup: b_vid,
383396
sub: a_vid,
384397
locations,
@@ -457,10 +470,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
457470
// region which cannot be mapped back to a universal.
458471
// FIXME: We could probably compute the LUB if there is one.
459472
let scc = self.constraint_sccs.scc(vid);
460-
let upper_bounds: Vec<_> = self
461-
.rev_scc_graph
462-
.as_ref()
463-
.unwrap()
473+
let rev_scc_graph =
474+
&ReverseSccGraph::compute(&self.constraint_sccs, self.universal_regions());
475+
let upper_bounds: Vec<_> = rev_scc_graph
464476
.upper_bounds(scc)
465477
.filter_map(|vid| self.definitions[vid].external_name)
466478
.filter(|r| !r.is_static())

compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,3 @@ impl ReverseSccGraph {
5656
.filter(move |r| duplicates.insert(*r))
5757
}
5858
}
59-
60-
impl RegionInferenceContext<'_> {
61-
/// Compute the reverse SCC-based constraint graph (lazily).
62-
pub(super) fn compute_reverse_scc_graph(&mut self) {
63-
if self.rev_scc_graph.is_some() {
64-
return;
65-
} else {
66-
self.rev_scc_graph =
67-
Some(ReverseSccGraph::compute(&self.constraint_sccs, self.universal_regions()))
68-
}
69-
}
70-
}

0 commit comments

Comments
 (0)