Skip to content

Commit

Permalink
Remove region_bound_pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jan 25, 2025
1 parent 8f63b79 commit 485c6f4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 119 deletions.
14 changes: 4 additions & 10 deletions compiler/rustc_borrowck/src/type_check/constraint_conversion.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use rustc_hir::def_id::DefId;
use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_infer::infer::outlives::env::RegionBoundPairs;
use rustc_infer::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelegate};
use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
use rustc_infer::infer::{self, InferCtxt, SubregionOrigin};
Expand Down Expand Up @@ -35,10 +34,9 @@ pub(crate) struct ConstraintConversion<'a, 'tcx> {
/// `process_registered_region_obligations` has some special-cased
/// logic expecting to see (e.g.) `ReStatic`, and if we supplied
/// our special inference variable there, we would mess that up.
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
implicit_region_bound: ty::Region<'tcx>,
param_env: ty::ParamEnv<'tcx>,
known_type_outlives_obligations: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
known_type_outlives: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
locations: Locations,
span: Span,
category: ConstraintCategory<'tcx>,
Expand All @@ -50,10 +48,9 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
pub(crate) fn new(
infcx: &'a InferCtxt<'tcx>,
universal_regions: &'a UniversalRegions<'tcx>,
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
implicit_region_bound: ty::Region<'tcx>,
param_env: ty::ParamEnv<'tcx>,
known_type_outlives_obligations: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
known_type_outlives: &'a [ty::PolyTypeOutlivesPredicate<'tcx>],
locations: Locations,
span: Span,
category: ConstraintCategory<'tcx>,
Expand All @@ -63,10 +60,9 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
infcx,
tcx: infcx.tcx,
universal_regions,
region_bound_pairs,
implicit_region_bound,
param_env,
known_type_outlives_obligations,
known_type_outlives,
locations,
span,
category,
Expand Down Expand Up @@ -135,9 +131,8 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
let ConstraintConversion {
tcx,
infcx,
region_bound_pairs,
implicit_region_bound,
known_type_outlives_obligations,
known_type_outlives: known_type_outlives_obligations,
..
} = *self;

Expand Down Expand Up @@ -179,7 +174,6 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
TypeOutlives::new(
&mut *self,
tcx,
region_bound_pairs,
Some(implicit_region_bound),
known_type_outlives_obligations,
)
Expand Down
44 changes: 18 additions & 26 deletions compiler/rustc_borrowck/src/type_check/free_region_relations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use rustc_data_structures::frozen::Frozen;
use rustc_data_structures::transitive_relation::{TransitiveRelation, TransitiveRelationBuilder};
use rustc_hir::def::DefKind;
use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_infer::infer::outlives::env::RegionBoundPairs;
use rustc_infer::infer::region_constraints::GenericKind;
use rustc_infer::infer::{InferCtxt, outlives};
use rustc_infer::traits::ScrubbedTraitError;
use rustc_middle::mir::ConstraintCategory;
Expand Down Expand Up @@ -44,8 +42,7 @@ type NormalizedInputsAndOutput<'tcx> = Vec<Ty<'tcx>>;

pub(crate) struct CreateResult<'tcx> {
pub(crate) universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
pub(crate) region_bound_pairs: RegionBoundPairs<'tcx>,
pub(crate) known_type_outlives_obligations: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
pub(crate) known_type_outlives: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
pub(crate) normalized_inputs_and_output: NormalizedInputsAndOutput<'tcx>,
}

Expand All @@ -62,7 +59,7 @@ pub(crate) fn create<'tcx>(
implicit_region_bound,
constraints,
universal_regions,
region_bound_pairs: Default::default(),
known_type_outlives: vec![],
outlives: Default::default(),
inverse_outlives: Default::default(),
}
Expand Down Expand Up @@ -189,8 +186,8 @@ struct UniversalRegionRelationsBuilder<'a, 'tcx> {

// outputs:
outlives: TransitiveRelationBuilder<RegionVid>,
known_type_outlives: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
inverse_outlives: TransitiveRelationBuilder<RegionVid>,
region_bound_pairs: RegionBoundPairs<'tcx>,
}

impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
Expand Down Expand Up @@ -228,15 +225,9 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {

// Normalize the assumptions we use to borrowck the program.
let mut constraints = vec![];
let mut known_type_outlives_obligations = vec![];
for bound in param_env.caller_bounds() {
if let Some(outlives) = bound.as_type_outlives_clause() {
self.normalize_and_push_type_outlives_obligation(
outlives,
span,
&mut known_type_outlives_obligations,
&mut constraints,
);
self.normalize_and_push_type_outlives_obligation(outlives, span, &mut constraints);
};
}

Expand All @@ -251,8 +242,8 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
// - Normalize the type. This will create some region
// constraints, which we buffer up because we are
// not ready to process them yet.
// - Then compute the implied bounds. This will adjust
// the `region_bound_pairs` and so forth.
// - Then compute the implied bounds, updating the
// known outlives types and free region regions.
// - After this is done, we'll process the constraints, once
// the `relations` is built.
let mut normalized_inputs_and_output =
Expand Down Expand Up @@ -323,10 +314,9 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
constraint_conversion::ConstraintConversion::new(
self.infcx,
&self.universal_regions,
&self.region_bound_pairs,
self.implicit_region_bound,
param_env,
&known_type_outlives_obligations,
&self.known_type_outlives,
Locations::All(span),
span,
ConstraintCategory::Internal,
Expand All @@ -341,17 +331,15 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
outlives: self.outlives.freeze(),
inverse_outlives: self.inverse_outlives.freeze(),
}),
known_type_outlives_obligations,
region_bound_pairs: self.region_bound_pairs,
known_type_outlives: self.known_type_outlives,
normalized_inputs_and_output,
}
}

fn normalize_and_push_type_outlives_obligation(
&self,
&mut self,
mut outlives: ty::PolyTypeOutlivesPredicate<'tcx>,
span: Span,
known_type_outlives_obligations: &mut Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
constraints: &mut Vec<&QueryRegionConstraints<'tcx>>,
) {
// In the new solver, normalize the type-outlives obligation assumptions.
Expand Down Expand Up @@ -382,7 +370,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
}
}

known_type_outlives_obligations.push(outlives);
self.known_type_outlives.push(outlives);
}

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

OutlivesBound::RegionSubParam(r_a, param_b) => {
self.region_bound_pairs
.insert(ty::OutlivesPredicate(GenericKind::Param(param_b), r_a));
self.known_type_outlives.push(ty::Binder::dummy(ty::OutlivesPredicate(
Ty::new_param(self.infcx.tcx, param_b.index, param_b.name),
r_a,
)));
}

OutlivesBound::RegionSubAlias(r_a, alias_b) => {
self.region_bound_pairs
.insert(ty::OutlivesPredicate(GenericKind::Alias(alias_b), r_a));
self.known_type_outlives.push(ty::Binder::dummy(ty::OutlivesPredicate(
Ty::new_alias(self.infcx.tcx, alias_b.kind(self.infcx.tcx), alias_b),
r_a,
)));
}
}
}
Expand Down
16 changes: 5 additions & 11 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use rustc_hir::def_id::LocalDefId;
use rustc_hir::lang_items::LangItem;
use rustc_index::{IndexSlice, IndexVec};
use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_infer::infer::outlives::env::RegionBoundPairs;
use rustc_infer::infer::region_constraints::RegionConstraintData;
use rustc_infer::infer::{
BoundRegion, BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin,
Expand Down Expand Up @@ -129,9 +128,8 @@ pub(crate) fn type_check<'a, 'tcx>(

let CreateResult {
universal_region_relations,
region_bound_pairs,
normalized_inputs_and_output,
known_type_outlives_obligations,
known_type_outlives,
} = free_region_relations::create(
infcx,
infcx.param_env,
Expand Down Expand Up @@ -159,8 +157,7 @@ pub(crate) fn type_check<'a, 'tcx>(
last_span: body.span,
body,
user_type_annotations: &body.user_type_annotations,
region_bound_pairs,
known_type_outlives_obligations,
known_type_outlives,
implicit_region_bound,
reported_errors: Default::default(),
universal_regions: &universal_region_relations.universal_regions,
Expand Down Expand Up @@ -555,8 +552,7 @@ struct TypeChecker<'a, 'tcx> {
/// User type annotations are shared between the main MIR and the MIR of
/// all of the promoted items.
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
region_bound_pairs: RegionBoundPairs<'tcx>,
known_type_outlives_obligations: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
known_type_outlives: Vec<ty::PolyTypeOutlivesPredicate<'tcx>>,
implicit_region_bound: ty::Region<'tcx>,
reported_errors: FxIndexSet<(Ty<'tcx>, Span)>,
universal_regions: &'a UniversalRegions<'tcx>,
Expand Down Expand Up @@ -748,10 +744,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
constraint_conversion::ConstraintConversion::new(
self.infcx,
self.universal_regions,
&self.region_bound_pairs,
self.implicit_region_bound,
self.infcx.param_env,
&self.known_type_outlives_obligations,
&self.known_type_outlives,
locations,
locations.span(self.body),
category,
Expand Down Expand Up @@ -2531,10 +2526,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
constraint_conversion::ConstraintConversion::new(
self.infcx,
self.universal_regions,
&self.region_bound_pairs,
self.implicit_region_bound,
self.infcx.param_env,
&self.known_type_outlives_obligations,
&self.known_type_outlives,
locations,
self.body.span, // irrelevant; will be overridden.
ConstraintCategory::Boring, // same as above.
Expand Down
14 changes: 3 additions & 11 deletions compiler/rustc_infer/src/infer/outlives/env.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use rustc_data_structures::fx::FxIndexSet;
use rustc_data_structures::transitive_relation::TransitiveRelationBuilder;
use rustc_middle::{bug, ty};

use crate::infer::GenericKind;
use crate::infer::free_regions::FreeRegionMap;

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

/// "Region-bound pairs" tracks outlives relations that are known to
/// be true, either because of explicit where-clauses like `T: 'a` or
/// because of implied bounds.
pub type RegionBoundPairs<'tcx> = FxIndexSet<ty::OutlivesPredicate<'tcx, GenericKind<'tcx>>>;

impl<'tcx> OutlivesEnvironment<'tcx> {
/// Create a new `OutlivesEnvironment` from normalized outlives bounds.
pub fn from_normalized_bounds(
Expand Down Expand Up @@ -93,7 +85,7 @@ impl<'tcx> OutlivesEnvironment<'tcx> {
&self.free_region_map
}

/// Borrows current `region_bound_pairs`.
/// Borrows current `known_type_outlives`.
pub fn known_type_outlives(&self) -> &[ty::PolyTypeOutlivesPredicate<'tcx>] {
&self.known_type_outlives
}
Expand Down
14 changes: 2 additions & 12 deletions compiler/rustc_infer/src/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ use smallvec::smallvec;
use tracing::{debug, instrument};

use super::env::OutlivesEnvironment;
use crate::infer::outlives::env::RegionBoundPairs;
use crate::infer::outlives::verify::VerifyBoundCx;
use crate::infer::resolve::OpportunisticRegionResolver;
use crate::infer::snapshot::undo_log::UndoLog;
Expand Down Expand Up @@ -169,12 +168,9 @@ impl<'tcx> InferCtxt<'tcx> {

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

let region_bound_pairs = &Default::default();
let outlives = &mut TypeOutlives::new(
self,
self.tcx,
// TODO:
region_bound_pairs,
None,
outlives_env.known_type_outlives(),
);
Expand Down Expand Up @@ -229,19 +225,13 @@ where
pub fn new(
delegate: D,
tcx: TyCtxt<'tcx>,
region_bound_pairs: &'cx RegionBoundPairs<'tcx>,
implicit_region_bound: Option<ty::Region<'tcx>>,
caller_bounds: &'cx [ty::PolyTypeOutlivesPredicate<'tcx>],
known_type_outlives: &'cx [ty::PolyTypeOutlivesPredicate<'tcx>],
) -> Self {
Self {
delegate,
tcx,
verify_bound: VerifyBoundCx::new(
tcx,
region_bound_pairs,
implicit_region_bound,
caller_bounds,
),
verify_bound: VerifyBoundCx::new(tcx, implicit_region_bound, known_type_outlives),
}
}

Expand Down
Loading

0 comments on commit 485c6f4

Please sign in to comment.