Skip to content

Commit dc0f24f

Browse files
Remove region_bound_pairs
1 parent c463791 commit dc0f24f

File tree

6 files changed

+47
-119
lines changed

6 files changed

+47
-119
lines changed

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_hir::def_id::DefId;
22
use rustc_infer::infer::canonical::QueryRegionConstraints;
3-
use rustc_infer::infer::outlives::env::RegionBoundPairs;
43
use rustc_infer::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelegate};
54
use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
65
use rustc_infer::infer::{self, InferCtxt, SubregionOrigin};
@@ -35,10 +34,9 @@ pub(crate) struct ConstraintConversion<'a, 'tcx> {
3534
/// `process_registered_region_obligations` has some special-cased
3635
/// logic expecting to see (e.g.) `ReStatic`, and if we supplied
3736
/// our special inference variable there, we would mess that up.
38-
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
3937
implicit_region_bound: ty::Region<'tcx>,
4038
param_env: ty::ParamEnv<'tcx>,
41-
known_type_outlives_obligations: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
39+
known_type_outlives: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
4240
locations: Locations,
4341
span: Span,
4442
category: ConstraintCategory<'tcx>,
@@ -50,10 +48,9 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
5048
pub(crate) fn new(
5149
infcx: &'a InferCtxt<'tcx>,
5250
universal_regions: &'a UniversalRegions<'tcx>,
53-
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
5451
implicit_region_bound: ty::Region<'tcx>,
5552
param_env: ty::ParamEnv<'tcx>,
56-
known_type_outlives_obligations: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
53+
known_type_outlives: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
5754
locations: Locations,
5855
span: Span,
5956
category: ConstraintCategory<'tcx>,
@@ -63,10 +60,9 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
6360
infcx,
6461
tcx: infcx.tcx,
6562
universal_regions,
66-
region_bound_pairs,
6763
implicit_region_bound,
6864
param_env,
69-
known_type_outlives_obligations,
65+
known_type_outlives,
7066
locations,
7167
span,
7268
category,
@@ -135,9 +131,8 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
135131
let ConstraintConversion {
136132
tcx,
137133
infcx,
138-
region_bound_pairs,
139134
implicit_region_bound,
140-
known_type_outlives_obligations,
135+
known_type_outlives: known_type_outlives_obligations,
141136
..
142137
} = *self;
143138

@@ -179,7 +174,6 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
179174
TypeOutlives::new(
180175
&mut *self,
181176
tcx,
182-
region_bound_pairs,
183177
Some(implicit_region_bound),
184178
known_type_outlives_obligations,
185179
)

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+18-26
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use rustc_data_structures::frozen::Frozen;
22
use rustc_data_structures::transitive_relation::{TransitiveRelation, TransitiveRelationBuilder};
33
use rustc_hir::def::DefKind;
44
use rustc_infer::infer::canonical::QueryRegionConstraints;
5-
use rustc_infer::infer::outlives::env::RegionBoundPairs;
6-
use rustc_infer::infer::region_constraints::GenericKind;
75
use rustc_infer::infer::{InferCtxt, outlives};
86
use rustc_infer::traits::ScrubbedTraitError;
97
use rustc_middle::mir::ConstraintCategory;
@@ -44,8 +42,7 @@ type NormalizedInputsAndOutput<'tcx> = Vec<Ty<'tcx>>;
4442

4543
pub(crate) struct CreateResult<'tcx> {
4644
pub(crate) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
47-
pub(crate) region_bound_pairs: RegionBoundPairs<'tcx>,
48-
pub(crate) known_type_outlives_obligations: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
45+
pub(crate) known_type_outlives: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
4946
pub(crate) normalized_inputs_and_output: NormalizedInputsAndOutput<'tcx>,
5047
}
5148

@@ -62,7 +59,7 @@ pub(crate) fn create<'tcx>(
6259
implicit_region_bound,
6360
constraints,
6461
universal_regions,
65-
region_bound_pairs: Default::default(),
62+
known_type_outlives: vec![],
6663
outlives: Default::default(),
6764
inverse_outlives: Default::default(),
6865
}
@@ -189,8 +186,8 @@ struct UniversalRegionRelationsBuilder<'a, 'tcx> {
189186

190187
// outputs:
191188
outlives: TransitiveRelationBuilder<RegionVid>,
189+
known_type_outlives: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
192190
inverse_outlives: TransitiveRelationBuilder<RegionVid>,
193-
region_bound_pairs: RegionBoundPairs<'tcx>,
194191
}
195192

196193
impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
@@ -228,15 +225,9 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
228225

229226
// Normalize the assumptions we use to borrowck the program.
230227
let mut constraints = vec![];
231-
let mut known_type_outlives_obligations = vec![];
232228
for bound in param_env.caller_bounds() {
233229
if let Some(outlives) = bound.as_type_outlives_clause() {
234-
self.normalize_and_push_type_outlives_obligation(
235-
outlives,
236-
span,
237-
&mut known_type_outlives_obligations,
238-
&mut constraints,
239-
);
230+
self.normalize_and_push_type_outlives_obligation(outlives, span, &mut constraints);
240231
};
241232
}
242233

@@ -251,8 +242,8 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
251242
// - Normalize the type. This will create some region
252243
// constraints, which we buffer up because we are
253244
// not ready to process them yet.
254-
// - Then compute the implied bounds. This will adjust
255-
// the `region_bound_pairs` and so forth.
245+
// - Then compute the implied bounds, updating the
246+
// known outlives types and free region regions.
256247
// - After this is done, we'll process the constraints, once
257248
// the `relations` is built.
258249
let mut normalized_inputs_and_output =
@@ -323,10 +314,9 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
323314
constraint_conversion::ConstraintConversion::new(
324315
self.infcx,
325316
&self.universal_regions,
326-
&self.region_bound_pairs,
327317
self.implicit_region_bound,
328318
param_env,
329-
&known_type_outlives_obligations,
319+
&self.known_type_outlives,
330320
Locations::All(span),
331321
span,
332322
ConstraintCategory::Internal,
@@ -341,17 +331,15 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
341331
outlives: self.outlives.freeze(),
342332
inverse_outlives: self.inverse_outlives.freeze(),
343333
}),
344-
known_type_outlives_obligations,
345-
region_bound_pairs: self.region_bound_pairs,
334+
known_type_outlives: self.known_type_outlives,
346335
normalized_inputs_and_output,
347336
}
348337
}
349338

350339
fn normalize_and_push_type_outlives_obligation(
351-
&self,
340+
&mut self,
352341
mut outlives: ty::PolyTypeOutlivesPredicate<'tcx>,
353342
span: Span,
354-
known_type_outlives_obligations: &mut Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
355343
constraints: &mut Vec<&QueryRegionConstraints<'tcx>>,
356344
) {
357345
// In the new solver, normalize the type-outlives obligation assumptions.
@@ -382,7 +370,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
382370
}
383371
}
384372

385-
known_type_outlives_obligations.push(outlives);
373+
self.known_type_outlives.push(outlives);
386374
}
387375

388376
/// Update the type of a single local, which should represent
@@ -428,13 +416,17 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
428416
}
429417

430418
OutlivesBound::RegionSubParam(r_a, param_b) => {
431-
self.region_bound_pairs
432-
.insert(ty::OutlivesPredicate(GenericKind::Param(param_b), r_a));
419+
self.known_type_outlives.push(ty::Binder::dummy(ty::OutlivesPredicate(
420+
Ty::new_param(self.infcx.tcx, param_b.index, param_b.name),
421+
r_a,
422+
)));
433423
}
434424

435425
OutlivesBound::RegionSubAlias(r_a, alias_b) => {
436-
self.region_bound_pairs
437-
.insert(ty::OutlivesPredicate(GenericKind::Alias(alias_b), r_a));
426+
self.known_type_outlives.push(ty::Binder::dummy(ty::OutlivesPredicate(
427+
Ty::new_alias(self.infcx.tcx, alias_b.kind(self.infcx.tcx), alias_b),
428+
r_a,
429+
)));
438430
}
439431
}
440432
}

compiler/rustc_borrowck/src/type_check/mod.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_hir::def_id::LocalDefId;
1313
use rustc_hir::lang_items::LangItem;
1414
use rustc_index::{IndexSlice, IndexVec};
1515
use rustc_infer::infer::canonical::QueryRegionConstraints;
16-
use rustc_infer::infer::outlives::env::RegionBoundPairs;
1716
use rustc_infer::infer::region_constraints::RegionConstraintData;
1817
use rustc_infer::infer::{
1918
BoundRegion, BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin,
@@ -129,9 +128,8 @@ pub(crate) fn type_check<'a, 'tcx>(
129128

130129
let CreateResult {
131130
universal_region_relations,
132-
region_bound_pairs,
133131
normalized_inputs_and_output,
134-
known_type_outlives_obligations,
132+
known_type_outlives,
135133
} = free_region_relations::create(
136134
infcx,
137135
infcx.param_env,
@@ -159,8 +157,7 @@ pub(crate) fn type_check<'a, 'tcx>(
159157
last_span: body.span,
160158
body,
161159
user_type_annotations: &body.user_type_annotations,
162-
region_bound_pairs,
163-
known_type_outlives_obligations,
160+
known_type_outlives,
164161
implicit_region_bound,
165162
reported_errors: Default::default(),
166163
universal_regions: &universal_region_relations.universal_regions,
@@ -555,8 +552,7 @@ struct TypeChecker<'a, 'tcx> {
555552
/// User type annotations are shared between the main MIR and the MIR of
556553
/// all of the promoted items.
557554
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
558-
region_bound_pairs: RegionBoundPairs<'tcx>,
559-
known_type_outlives_obligations: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
555+
known_type_outlives: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
560556
implicit_region_bound: ty::Region<'tcx>,
561557
reported_errors: FxIndexSet<(Ty<'tcx>, Span)>,
562558
universal_regions: &'a UniversalRegions<'tcx>,
@@ -748,10 +744,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
748744
constraint_conversion::ConstraintConversion::new(
749745
self.infcx,
750746
self.universal_regions,
751-
&self.region_bound_pairs,
752747
self.implicit_region_bound,
753748
self.infcx.param_env,
754-
&self.known_type_outlives_obligations,
749+
&self.known_type_outlives,
755750
locations,
756751
locations.span(self.body),
757752
category,
@@ -2531,10 +2526,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25312526
constraint_conversion::ConstraintConversion::new(
25322527
self.infcx,
25332528
self.universal_regions,
2534-
&self.region_bound_pairs,
25352529
self.implicit_region_bound,
25362530
self.infcx.param_env,
2537-
&self.known_type_outlives_obligations,
2531+
&self.known_type_outlives,
25382532
locations,
25392533
self.body.span, // irrelevant; will be overridden.
25402534
ConstraintCategory::Boring, // same as above.

compiler/rustc_infer/src/infer/outlives/env.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
use rustc_data_structures::fx::FxIndexSet;
21
use rustc_data_structures::transitive_relation::TransitiveRelationBuilder;
32
use rustc_middle::{bug, ty};
43

5-
use crate::infer::GenericKind;
64
use crate::infer::free_regions::FreeRegionMap;
75

86
/// The `OutlivesEnvironment` collects information about what outlives
97
/// what in a given type-checking setting. For example, if we have a
108
/// where-clause like `where T: 'a` in scope, then the
11-
/// `OutlivesEnvironment` would record that (in its
12-
/// `region_bound_pairs` field). Similarly, it contains methods for
13-
/// processing and adding implied bounds into the outlives
9+
/// `OutlivesEnvironment` would record that. Similarly, it contains
10+
/// methods for processing and adding implied bounds into the outlives
1411
/// environment.
1512
///
1613
/// Other code at present does not typically take a
@@ -31,11 +28,6 @@ pub struct OutlivesEnvironment<'tcx> {
3128
known_type_outlives: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
3229
}
3330

34-
/// "Region-bound pairs" tracks outlives relations that are known to
35-
/// be true, either because of explicit where-clauses like `T: 'a` or
36-
/// because of implied bounds.
37-
pub type RegionBoundPairs<'tcx> = FxIndexSet<ty::OutlivesPredicate<'tcx, GenericKind<'tcx>>>;
38-
3931
impl<'tcx> OutlivesEnvironment<'tcx> {
4032
/// Create a new `OutlivesEnvironment` from normalized outlives bounds.
4133
pub fn from_normalized_bounds(
@@ -93,7 +85,7 @@ impl<'tcx> OutlivesEnvironment<'tcx> {
9385
&self.free_region_map
9486
}
9587

96-
/// Borrows current `region_bound_pairs`.
88+
/// Borrows current `known_type_outlives`.
9789
pub fn known_type_outlives(&self) -> &[ty::PolyTypeOutlivesPredicate<'tcx>] {
9890
&self.known_type_outlives
9991
}

compiler/rustc_infer/src/infer/outlives/obligations.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ use smallvec::smallvec;
7272
use tracing::{debug, instrument};
7373

7474
use super::env::OutlivesEnvironment;
75-
use crate::infer::outlives::env::RegionBoundPairs;
7675
use crate::infer::outlives::verify::VerifyBoundCx;
7776
use crate::infer::resolve::OpportunisticRegionResolver;
7877
use crate::infer::snapshot::undo_log::UndoLog;
@@ -169,12 +168,9 @@ impl<'tcx> InferCtxt<'tcx> {
169168

170169
debug!(?sup_type, ?sub_region, ?origin);
171170

172-
let region_bound_pairs = &Default::default();
173171
let outlives = &mut TypeOutlives::new(
174172
self,
175173
self.tcx,
176-
// TODO:
177-
region_bound_pairs,
178174
None,
179175
outlives_env.known_type_outlives(),
180176
);
@@ -229,19 +225,13 @@ where
229225
pub fn new(
230226
delegate: D,
231227
tcx: TyCtxt<'tcx>,
232-
region_bound_pairs: &'cx RegionBoundPairs<'tcx>,
233228
implicit_region_bound: Option<ty::Region<'tcx>>,
234-
caller_bounds: &'cx [ty::PolyTypeOutlivesPredicate<'tcx>],
229+
known_type_outlives: &'cx [ty::PolyTypeOutlivesPredicate<'tcx>],
235230
) -> Self {
236231
Self {
237232
delegate,
238233
tcx,
239-
verify_bound: VerifyBoundCx::new(
240-
tcx,
241-
region_bound_pairs,
242-
implicit_region_bound,
243-
caller_bounds,
244-
),
234+
verify_bound: VerifyBoundCx::new(tcx, implicit_region_bound, known_type_outlives),
245235
}
246236
}
247237

0 commit comments

Comments
 (0)