Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/next_solver/infer/region_constraints/mod.rs')
-rw-r--r--crates/hir-ty/src/next_solver/infer/region_constraints/mod.rs53
1 files changed, 51 insertions, 2 deletions
diff --git a/crates/hir-ty/src/next_solver/infer/region_constraints/mod.rs b/crates/hir-ty/src/next_solver/infer/region_constraints/mod.rs
index 50549694c3..7f15a467b3 100644
--- a/crates/hir-ty/src/next_solver/infer/region_constraints/mod.rs
+++ b/crates/hir-ty/src/next_solver/infer/region_constraints/mod.rs
@@ -22,7 +22,7 @@ use crate::next_solver::{
AliasTy, Binder, DbInterner, OpaqueTypeKey, ParamTy, PlaceholderTy, Region, Ty,
};
-#[derive(Clone, Default)]
+#[derive(Debug, Clone, Default)]
pub struct RegionConstraintStorage<'db> {
/// For each `RegionVid`, the corresponding `RegionVariableOrigin`.
pub(super) var_infos: IndexVec<RegionVid, RegionVariableInfo>,
@@ -239,7 +239,7 @@ pub struct VerifyIfEq<'db> {
pub bound: Region<'db>,
}
-#[derive(Clone, PartialEq, Eq, Hash)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct TwoRegions<'db> {
a: Region<'db>,
b: Region<'db>,
@@ -458,6 +458,44 @@ impl<'db> RegionConstraintCollector<'db, '_> {
}
}
+ pub(super) fn lub_regions(
+ &mut self,
+ db: DbInterner<'db>,
+ a: Region<'db>,
+ b: Region<'db>,
+ ) -> Region<'db> {
+ // cannot add constraints once regions are resolved
+ debug!("RegionConstraintCollector: lub_regions({:?}, {:?})", a, b);
+ #[expect(clippy::if_same_then_else)]
+ if a.is_static() || b.is_static() {
+ a // nothing lives longer than static
+ } else if a == b {
+ a // LUB(a,a) = a
+ } else {
+ self.combine_vars(db, Lub, a, b)
+ }
+ }
+
+ pub(super) fn glb_regions(
+ &mut self,
+ db: DbInterner<'db>,
+ a: Region<'db>,
+ b: Region<'db>,
+ ) -> Region<'db> {
+ // cannot add constraints once regions are resolved
+ debug!("RegionConstraintCollector: glb_regions({:?}, {:?})", a, b);
+ #[expect(clippy::if_same_then_else)]
+ if a.is_static() {
+ b // static lives longer than everything else
+ } else if b.is_static() {
+ a // static lives longer than everything else
+ } else if a == b {
+ a // GLB(a,a) = a
+ } else {
+ self.combine_vars(db, Glb, a, b)
+ }
+ }
+
/// Resolves a region var to its value in the unification table, if it exists.
/// Otherwise, it is resolved to the root `ReVar` in the table.
pub fn opportunistic_resolve_var(
@@ -531,6 +569,17 @@ impl<'db> RegionConstraintCollector<'db, '_> {
}
}
+ pub fn vars_since_snapshot(&self, value_count: usize) -> Range<RegionVid> {
+ RegionVid::from(value_count)..RegionVid::from(self.storage.unification_table.len())
+ }
+
+ /// See `InferCtxt::region_constraints_added_in_snapshot`.
+ pub fn region_constraints_added_in_snapshot(&self, mark: &Snapshot) -> bool {
+ self.undo_log
+ .region_constraints_in_snapshot(mark)
+ .any(|elt| matches!(elt, AddConstraint(_)))
+ }
+
#[inline]
fn unification_table_mut(&mut self) -> super::UnificationTable<'_, 'db, RegionVidKey<'db>> {
ut::UnificationTable::with_log(&mut self.storage.unification_table, self.undo_log)