Skip to content

Commit

Permalink
Auto merge of rust-lang#127438 - compiler-errors:compute-outlives-vis…
Browse files Browse the repository at this point in the history
…itor, r=lcnr

Make `push_outlives_components` into a `TypeVisitor`

This involves removing the `visited: &mut SsoHashSet<GenericArg<'tcx>>` that is being passed around the `VerifyBoundCx`. The fact that we were using it when decomposing different type tests seems sketchy, so I don't think, though it may technically result in us registering more redundant outlives components 🤷

I did end up deleting some of the comments that referred back to RFC 1214 during this refactor. I can add them back if you think they were useful.

r? lcnr
  • Loading branch information
bors committed Jul 8, 2024
2 parents 7fdefb8 + c895985 commit 59a4f02
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 247 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ where
// projection outlive; in some cases, this may add insufficient
// edges into the inference graph, leading to inference failures
// even though a satisfactory solution exists.
let verify_bound = self.verify_bound.alias_bound(alias_ty, &mut Default::default());
let verify_bound = self.verify_bound.alias_bound(alias_ty);
debug!("alias_must_outlive: pushing {:?}", verify_bound);
self.delegate.push_verify(origin, GenericKind::Alias(alias_ty), region, verify_bound);
}
Expand Down
29 changes: 8 additions & 21 deletions compiler/rustc_infer/src/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::infer::outlives::env::RegionBoundPairs;
use crate::infer::region_constraints::VerifyIfEq;
use crate::infer::{GenericKind, VerifyBound};
use rustc_data_structures::sso::SsoHashSet;
use rustc_middle::ty::GenericArg;
use rustc_middle::ty::{self, OutlivesPredicate, Ty, TyCtxt};
use rustc_type_ir::outlives::{compute_alias_components_recursive, Component};

Expand Down Expand Up @@ -99,12 +97,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
self.declared_generic_bounds_from_env_for_erased_ty(erased_alias_ty)
}

#[instrument(level = "debug", skip(self, visited))]
pub fn alias_bound(
&self,
alias_ty: ty::AliasTy<'tcx>,
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> VerifyBound<'tcx> {
#[instrument(level = "debug", skip(self))]
pub fn alias_bound(&self, alias_ty: ty::AliasTy<'tcx>) -> VerifyBound<'tcx> {
let alias_ty_as_ty = alias_ty.to_ty(self.tcx);

// Search the env for where clauses like `P: 'a`.
Expand All @@ -130,21 +124,17 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
// see the extensive comment in projection_must_outlive
let recursive_bound = {
let mut components = smallvec![];
compute_alias_components_recursive(self.tcx, alias_ty_as_ty, &mut components, visited);
self.bound_from_components(&components, visited)
compute_alias_components_recursive(self.tcx, alias_ty_as_ty, &mut components);
self.bound_from_components(&components)
};

VerifyBound::AnyBound(env_bounds.chain(definition_bounds).collect()).or(recursive_bound)
}

fn bound_from_components(
&self,
components: &[Component<TyCtxt<'tcx>>],
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> VerifyBound<'tcx> {
fn bound_from_components(&self, components: &[Component<TyCtxt<'tcx>>]) -> VerifyBound<'tcx> {
let mut bounds = components
.iter()
.map(|component| self.bound_from_single_component(component, visited))
.map(|component| self.bound_from_single_component(component))
// Remove bounds that must hold, since they are not interesting.
.filter(|bound| !bound.must_hold());

Expand All @@ -159,18 +149,15 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
fn bound_from_single_component(
&self,
component: &Component<TyCtxt<'tcx>>,
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> VerifyBound<'tcx> {
match *component {
Component::Region(lt) => VerifyBound::OutlivedBy(lt),
Component::Param(param_ty) => self.param_or_placeholder_bound(param_ty.to_ty(self.tcx)),
Component::Placeholder(placeholder_ty) => {
self.param_or_placeholder_bound(Ty::new_placeholder(self.tcx, placeholder_ty))
}
Component::Alias(alias_ty) => self.alias_bound(alias_ty, visited),
Component::EscapingAlias(ref components) => {
self.bound_from_components(components, visited)
}
Component::Alias(alias_ty) => self.alias_bound(alias_ty),
Component::EscapingAlias(ref components) => self.bound_from_components(components),
Component::UnresolvedInferenceVariable(v) => {
// Ignore this, we presume it will yield an error later, since
// if a type variable is not resolved by this point it never
Expand Down
Loading

0 comments on commit 59a4f02

Please sign in to comment.