Skip to content

Commit

Permalink
remove non-borrowck member constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Dec 20, 2024
1 parent 674c657 commit 9792cf0
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 436 deletions.
22 changes: 7 additions & 15 deletions compiler/rustc_borrowck/src/member_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ where
/// Stores the data about each `R0 member of [R1..Rn]` constraint.
/// These are organized into a linked list, so each constraint
/// contains the index of the next constraint with the same `R0`.
constraints: IndexVec<NllMemberConstraintIndex, NllMemberConstraint<'tcx>>,
constraints: IndexVec<NllMemberConstraintIndex, MemberConstraint<'tcx>>,

/// Stores the `R1..Rn` regions for *all* sets. For any given
/// constraint, we keep two indices so that we can pull out a
Expand All @@ -32,7 +32,7 @@ where

/// Represents a `R0 member of [R1..Rn]` constraint
#[derive(Debug)]
pub(crate) struct NllMemberConstraint<'tcx> {
pub(crate) struct MemberConstraint<'tcx> {
next_constraint: Option<NllMemberConstraintIndex>,

/// The span where the hidden type was instantiated.
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<'tcx> MemberConstraintSet<'tcx, ty::RegionVid> {
let start_index = self.choice_regions.len();
self.choice_regions.extend(choice_regions);
let end_index = self.choice_regions.len();
let constraint_index = self.constraints.push(NllMemberConstraint {
let constraint_index = self.constraints.push(MemberConstraint {
next_constraint,
member_region_vid,
definition_span,
Expand All @@ -98,14 +98,6 @@ impl<'tcx> MemberConstraintSet<'tcx, ty::RegionVid> {
});
self.first_constraints.insert(member_region_vid, constraint_index);
}

// TODO: removed in the next commit
pub(crate) fn push_constraint(
&mut self,
_: &rustc_middle::infer::MemberConstraint<'tcx>,
_: impl FnMut(ty::Region<'tcx>) -> ty::RegionVid,
) {
}
}

impl<'tcx, R1> MemberConstraintSet<'tcx, R1>
Expand Down Expand Up @@ -186,7 +178,7 @@ where
/// R0 member of [R1..Rn]
/// ```
pub(crate) fn choice_regions(&self, pci: NllMemberConstraintIndex) -> &[ty::RegionVid] {
let NllMemberConstraint { start_index, end_index, .. } = &self.constraints[pci];
let MemberConstraint { start_index, end_index, .. } = &self.constraints[pci];
&self.choice_regions[*start_index..*end_index]
}
}
Expand All @@ -195,9 +187,9 @@ impl<'tcx, R> Index<NllMemberConstraintIndex> for MemberConstraintSet<'tcx, R>
where
R: Copy + Eq,
{
type Output = NllMemberConstraint<'tcx>;
type Output = MemberConstraint<'tcx>;

fn index(&self, i: NllMemberConstraintIndex) -> &NllMemberConstraint<'tcx> {
fn index(&self, i: NllMemberConstraintIndex) -> &MemberConstraint<'tcx> {
&self.constraints[i]
}
}
Expand All @@ -219,7 +211,7 @@ where
/// target_list: A -> B -> C -> D -> E -> F -> (None)
/// ```
fn append_list(
constraints: &mut IndexSlice<NllMemberConstraintIndex, NllMemberConstraint<'_>>,
constraints: &mut IndexSlice<NllMemberConstraintIndex, MemberConstraint<'_>>,
target_list: NllMemberConstraintIndex,
source_list: NllMemberConstraintIndex,
) {
Expand Down
21 changes: 3 additions & 18 deletions compiler/rustc_borrowck/src/type_check/constraint_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {

#[instrument(skip(self), level = "debug")]
pub(super) fn convert_all(&mut self, query_constraints: &QueryRegionConstraints<'tcx>) {
let QueryRegionConstraints { outlives, member_constraints } = query_constraints;

// Annoying: to invoke `self.to_region_vid`, we need access to
// `self.constraints`, but we also want to be mutating
// `self.member_constraints`. For now, just swap out the value
// we want and replace at the end.
let mut tmp = std::mem::take(&mut self.constraints.member_constraints);
for member_constraint in member_constraints {
tmp.push_constraint(member_constraint, |r| self.to_region_vid(r));
}
self.constraints.member_constraints = tmp;
let QueryRegionConstraints { outlives } = query_constraints;

for &(predicate, constraint_category) in outlives {
self.convert(predicate, constraint_category);
Expand Down Expand Up @@ -295,13 +285,8 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {

match result {
Ok(TypeOpOutput { output: ty, constraints, .. }) => {
if let Some(constraints) = constraints {
assert!(
constraints.member_constraints.is_empty(),
"no member constraints expected from normalizing: {:#?}",
constraints.member_constraints
);
next_outlives_predicates.extend(constraints.outlives.iter().copied());
if let Some(QueryRegionConstraints { outlives }) = constraints {
next_outlives_predicates.extend(outlives.iter().copied());
}
ty
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,10 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
/// reference those regions from the `ParamEnv`. It is also used
/// during initialization. Relies on the `indices` map having been
/// fully initialized.
///
/// Panics if `r` is not a registered universal region, most notably
/// if it is a placeholder. Handling placeholders requires access to the
/// `MirTypeckRegionConstraints`.
fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
if let ty::ReVar(..) = *r {
r.as_var()
Expand Down
14 changes: 2 additions & 12 deletions compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,6 @@ impl<'tcx> InferCtxt<'tcx> {
}),
);

// ...also include the query member constraints.
output_query_region_constraints.member_constraints.extend(
query_response
.value
.region_constraints
.member_constraints
.iter()
.map(|p_c| instantiate_value(self.tcx, &result_args, p_c.clone())),
);

let user_result: R =
query_response.instantiate_projected(self.tcx, &result_args, |q_r| q_r.value.clone());

Expand Down Expand Up @@ -643,7 +633,7 @@ pub fn make_query_region_constraints<'tcx>(
outlives_obligations: impl Iterator<Item = (Ty<'tcx>, ty::Region<'tcx>, ConstraintCategory<'tcx>)>,
region_constraints: &RegionConstraintData<'tcx>,
) -> QueryRegionConstraints<'tcx> {
let RegionConstraintData { constraints, verifys, member_constraints } = region_constraints;
let RegionConstraintData { constraints, verifys } = region_constraints;

assert!(verifys.is_empty());

Expand Down Expand Up @@ -674,5 +664,5 @@ pub fn make_query_region_constraints<'tcx>(
}))
.collect();

QueryRegionConstraints { outlives, member_constraints: member_constraints.clone() }
QueryRegionConstraints { outlives }
}
21 changes: 0 additions & 21 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub use relate::StructurallyRelateAliases;
pub use relate::combine::PredicateEmittingRelation;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
use rustc_data_structures::unify as ut;
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
Expand Down Expand Up @@ -685,26 +684,6 @@ impl<'tcx> InferCtxt<'tcx> {
self.inner.borrow_mut().unwrap_region_constraints().make_subregion(origin, a, b);
}

/// Require that the region `r` be equal to one of the regions in
/// the set `regions`.
#[instrument(skip(self), level = "debug")]
pub fn add_member_constraint(
&self,
key: ty::OpaqueTypeKey<'tcx>,
definition_span: Span,
hidden_ty: Ty<'tcx>,
region: ty::Region<'tcx>,
in_regions: Lrc<Vec<ty::Region<'tcx>>>,
) {
self.inner.borrow_mut().unwrap_region_constraints().add_member_constraint(
key,
definition_span,
hidden_ty,
region,
in_regions,
);
}

/// Processes a `Coerce` predicate from the fulfillment context.
/// This is NOT the preferred way to handle coercion, which is to
/// invoke `FnCtxt::coerce` or a similar method (see `coercion.rs`).
Expand Down
Loading

0 comments on commit 9792cf0

Please sign in to comment.