Skip to content

Commit 5a1c148

Browse files
committed
Remove feature gate and fix performance nit
1 parent cfa372b commit 5a1c148

File tree

2 files changed

+18
-88
lines changed
  • compiler/rustc_borrowck/src

2 files changed

+18
-88
lines changed

compiler/rustc_borrowck/src/constraints/mod.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,10 @@ impl<'tcx> OutlivesConstraintSet<'tcx> {
6767
&self.outlives
6868
}
6969
pub(crate) fn placeholders_to_static(
70-
&self,
70+
&mut self,
7171
universal_regions: &UniversalRegions<'tcx>,
7272
definitions: &IndexVec<RegionVid, RegionDefinition<'tcx>>,
73-
) -> Self {
74-
let mut copy = self.clone();
75-
73+
) {
7674
let universe = |rvid: RegionVid| definitions[rvid].universe;
7775

7876
let is_placeholder = |rvid: RegionVid| {
@@ -95,7 +93,8 @@ impl<'tcx> OutlivesConstraintSet<'tcx> {
9593
})
9694
};
9795

98-
let should_be_static = definitions.indices().filter_map(|rvid| {
96+
// Start a search to find reachable regions from here that have incompatible universes
97+
let should_be_static:Vec<_> = definitions.indices().filter_map(|rvid| {
9998
let mut queue: Vec<RegionVid> = outlived_regions(rvid).map(|&r| r).collect();
10099
let mut seen: FxHashSet<_> = queue.iter().map(|&r| r).collect();
101100
seen.insert(rvid);
@@ -120,13 +119,11 @@ impl<'tcx> OutlivesConstraintSet<'tcx> {
120119
}
121120
}
122121
None
123-
});
122+
}).collect();
124123

125124
for rvid in should_be_static {
126-
copy.push(outlives_static(rvid));
125+
self.push(outlives_static(rvid));
127126
}
128-
129-
copy
130127
}
131128
}
132129

compiler/rustc_borrowck/src/region_infer/mod.rs

+12-79
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub struct RegionInferenceContext<'tcx> {
7171
/// The SCC computed from `constraints` and the constraint
7272
/// graph. We have an edge from SCC A to SCC B if `A: B`. Used to
7373
/// compute the values of each region.
74-
constraint_sccs: Rc<Sccs<RegionVid, ConstraintSccIndex>>,
74+
constraint_sccs: Sccs<RegionVid, ConstraintSccIndex>,
7575

7676
/// Reverse of the SCC constraint graph -- i.e., an edge `A -> B` exists if
7777
/// `B: A`. This is used to compute the universal regions that are required
@@ -121,11 +121,6 @@ pub struct RegionInferenceContext<'tcx> {
121121
/// Information about how the universally quantified regions in
122122
/// scope on this function relate to one another.
123123
universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
124-
125-
/// Whether we are operating with polonius=next or not. False
126-
/// means the regular NLL machinery is in use, true means use the
127-
/// new Polonius constraint propagation.
128-
polonius_next_enabled: bool,
129124
}
130125

131126
/// Each time that `apply_member_constraint` is successful, it appends
@@ -256,7 +251,7 @@ pub enum ExtraConstraintInfo {
256251
#[instrument(skip(infcx, sccs), level = "debug")]
257252
fn sccs_info<'cx, 'tcx>(
258253
infcx: &'cx BorrowckInferCtxt<'cx, 'tcx>,
259-
sccs: Rc<Sccs<RegionVid, ConstraintSccIndex>>,
254+
sccs: &Sccs<RegionVid, ConstraintSccIndex>,
260255
) {
261256
use crate::renumber::RegionCtxt;
262257

@@ -332,7 +327,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
332327
universal_regions: Rc<UniversalRegions<'tcx>>,
333328
placeholder_indices: Rc<PlaceholderIndices>,
334329
universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
335-
outlives_constraints: OutlivesConstraintSet<'tcx>,
330+
mut outlives_constraints: OutlivesConstraintSet<'tcx>,
336331
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
337332
universe_causes: FxIndexMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
338333
type_tests: Vec<TypeTest<'tcx>>,
@@ -350,21 +345,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
350345
.map(|info| RegionDefinition::new(info.universe, info.origin))
351346
.collect();
352347

353-
let polonius_next_enabled = infcx.tcx.sess.opts.unstable_opts.polonius.is_next_enabled();
348+
outlives_constraints.placeholders_to_static(&universal_regions, &definitions);
354349

355-
let constraints = if polonius_next_enabled {
356-
Frozen::freeze(
357-
outlives_constraints.placeholders_to_static(&universal_regions, &definitions),
358-
)
359-
} else {
360-
Frozen::freeze(outlives_constraints)
361-
};
350+
let constraints = Frozen::freeze(outlives_constraints);
362351
let constraint_graph = Frozen::freeze(constraints.graph(definitions.len()));
363352
let fr_static = universal_regions.fr_static;
364-
let constraint_sccs = Rc::new(constraints.compute_sccs(&constraint_graph, fr_static));
353+
let constraint_sccs = constraints.compute_sccs(&constraint_graph, fr_static);
365354

366355
if cfg!(debug_assertions) {
367-
sccs_info(infcx, constraint_sccs.clone());
356+
sccs_info(infcx, &constraint_sccs);
368357
}
369358

370359
let mut scc_values =
@@ -399,7 +388,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
399388
type_tests,
400389
universal_regions,
401390
universal_region_relations,
402-
polonius_next_enabled,
403391
};
404392

405393
result.init_free_and_bound_regions();
@@ -571,23 +559,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
571559
}
572560

573561
NllRegionVariableOrigin::Placeholder(placeholder) => {
574-
// Each placeholder region is only visible from
575-
// its universe `ui` and its extensions. So we
576-
// can't just add it into `scc` unless the
577-
// universe of the scc can name this region.
578-
// This case is handled separately when Polonius
579-
// is enabled.
580-
let scc_universe = self.scc_universes[scc];
581-
if self.polonius_next_enabled || scc_universe.can_name(placeholder.universe) {
582-
self.scc_values.add_element(scc, placeholder);
583-
} else {
584-
debug!(
585-
"init_free_and_bound_regions: placeholder {:?} is \
586-
not compatible with universe {:?} of its SCC {:?}",
587-
placeholder, scc_universe, scc,
588-
);
589-
self.add_incompatible_universe(scc);
590-
}
562+
self.scc_values.add_element(scc, placeholder);
591563
}
592564

593565
NllRegionVariableOrigin::Existential { .. } => {
@@ -755,8 +727,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
755727
// SCC. For each SCC, we visit its successors and compute
756728
// their values, then we union all those values to get our
757729
// own.
758-
let constraint_sccs = self.constraint_sccs.clone();
759-
for scc in constraint_sccs.all_sccs() {
730+
for scc in self.constraint_sccs.all_sccs() {
760731
self.compute_value_for_scc(scc);
761732
}
762733

@@ -771,22 +742,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
771742
/// (which is assured by iterating over SCCs in dependency order).
772743
#[instrument(skip(self), level = "debug")]
773744
fn compute_value_for_scc(&mut self, scc_a: ConstraintSccIndex) {
774-
let constraint_sccs = self.constraint_sccs.clone();
775-
776745
// Walk each SCC `B` such that `A: B`...
777-
for &scc_b in constraint_sccs.successors(scc_a) {
746+
for &scc_b in self.constraint_sccs.successors(scc_a) {
778747
debug!(?scc_b);
779-
// ...and add elements from `B` into `A`. One complication
780-
// arises because of universes: If `B` contains something
781-
// that `A` cannot name, then `A` can only contain `B` if
782-
// it outlives static.
783-
if self.polonius_next_enabled || self.universe_compatible(scc_b, scc_a) {
784-
// `A` can name everything that is in `B`, so just
785-
// merge the bits.
786-
self.scc_values.add_region(scc_a, scc_b);
787-
} else {
788-
self.add_incompatible_universe(scc_a);
789-
}
748+
self.scc_values.add_region(scc_a, scc_b);
790749
}
791750

792751
// Now take member constraints into account.
@@ -842,13 +801,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
842801
if self.scc_universes[scc] != ty::UniverseIndex::ROOT {
843802
return;
844803
}
845-
debug_assert!(
846-
self.polonius_next_enabled
847-
|| self.scc_values.placeholders_contained_in(scc).next().is_none(),
848-
"scc {:?} in a member constraint has placeholder value: {:?}",
849-
scc,
850-
self.scc_values.region_value_str(scc),
851-
);
852804

853805
// The existing value for `scc` is a lower-bound. This will
854806
// consist of some set `{P} + {LB}` of points `{P}` and
@@ -933,21 +885,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
933885
self.scc_values.placeholders_contained_in(scc_b).all(|p| universe_a.can_name(p.universe))
934886
}
935887

936-
/// Extend `scc` so that it can outlive some placeholder region
937-
/// from a universe it can't name; at present, the only way for
938-
/// this to be true is if `scc` outlives `'static`. This is
939-
/// actually stricter than necessary: ideally, we'd support bounds
940-
/// like `for<'a: 'b>` that might then allow us to approximate
941-
/// `'a` with `'b` and not `'static`. But it will have to do for
942-
/// now.
943-
fn add_incompatible_universe(&mut self, scc: ConstraintSccIndex) {
944-
debug!("add_incompatible_universe(scc={:?})", scc);
945-
946-
let fr_static = self.universal_regions.fr_static;
947-
self.scc_values.add_all_points(scc);
948-
self.scc_values.add_element(scc, fr_static);
949-
}
950-
951888
/// Once regions have been propagated, this method is used to see
952889
/// whether the "type tests" produced by typeck were satisfied;
953890
/// type tests encode type-outlives relationships like `T:
@@ -1579,10 +1516,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
15791516
// Because this free region must be in the ROOT universe, we
15801517
// know it cannot contain any bound universes.
15811518
assert!(self.scc_universes[longer_fr_scc] == ty::UniverseIndex::ROOT);
1582-
debug_assert!(
1583-
self.polonius_next_enabled
1584-
|| self.scc_values.placeholders_contained_in(longer_fr_scc).next().is_none()
1585-
);
15861519

15871520
// Only check all of the relations for the main representative of each
15881521
// SCC, otherwise just check that we outlive said representative. This
@@ -2267,7 +2200,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22672200

22682201
/// Access to the SCC constraint graph.
22692202
pub(crate) fn constraint_sccs(&self) -> &Sccs<RegionVid, ConstraintSccIndex> {
2270-
self.constraint_sccs.as_ref()
2203+
&self.constraint_sccs
22712204
}
22722205

22732206
/// Access to the region graph, built from the outlives constraints.

0 commit comments

Comments
 (0)