Skip to content

Commit cb3cff3

Browse files
committed
Stop using a placeholder for empty regions in Chalk
1 parent 6499c5e commit cb3cff3

File tree

3 files changed

+14
-60
lines changed

3 files changed

+14
-60
lines changed

compiler/rustc_traits/src/chalk/db.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ use rustc_span::symbol::sym;
2020
use std::fmt;
2121
use std::sync::Arc;
2222

23-
use crate::chalk::lowering::{self, LowerInto};
23+
use crate::chalk::lowering::LowerInto;
2424

2525
pub struct RustIrDatabase<'tcx> {
2626
pub(crate) interner: RustInterner<'tcx>,
27-
pub(crate) reempty_placeholder: ty::Region<'tcx>,
2827
}
2928

3029
impl fmt::Debug for RustIrDatabase<'_> {
@@ -40,12 +39,9 @@ impl<'tcx> RustIrDatabase<'tcx> {
4039
bound_vars: SubstsRef<'tcx>,
4140
) -> Vec<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
4241
let predicates = self.interner.tcx.predicates_defined_on(def_id).predicates;
43-
let mut regions_substitutor =
44-
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
4542
predicates
4643
.iter()
4744
.map(|(wc, _)| wc.subst(self.interner.tcx, bound_vars))
48-
.map(|wc| wc.fold_with(&mut regions_substitutor))
4945
.filter_map(|wc| LowerInto::<
5046
Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>
5147
>::lower_into(wc, self.interner)).collect()
@@ -287,9 +283,6 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
287283

288284
let trait_ref = self.interner.tcx.impl_trait_ref(def_id).expect("not an impl");
289285
let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars);
290-
let mut regions_substitutor =
291-
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
292-
let trait_ref = trait_ref.fold_with(&mut regions_substitutor);
293286

294287
let where_clauses = self.where_clauses_for(def_id, bound_vars);
295288

@@ -335,9 +328,6 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
335328

336329
let self_ty = trait_ref.self_ty();
337330
let self_ty = self_ty.subst(self.interner.tcx, bound_vars);
338-
let mut regions_substitutor =
339-
lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder);
340-
let self_ty = self_ty.fold_with(&mut regions_substitutor);
341331
let lowered_ty = self_ty.lower_into(self.interner);
342332

343333
parameters[0].assert_ty_ref(self.interner).could_match(

compiler/rustc_traits/src/chalk/lowering.rs

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,11 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
464464
})
465465
.intern(interner)
466466
}
467-
ReEmpty(_) => unimplemented!(),
468-
// FIXME(chalk): need to handle ReErased
469-
ReErased => unimplemented!(),
467+
ReEmpty(ui) => {
468+
chalk_ir::LifetimeData::Empty(chalk_ir::UniverseIndex { counter: ui.index() })
469+
.intern(interner)
470+
}
471+
ReErased => chalk_ir::LifetimeData::Erased.intern(interner),
470472
}
471473
}
472474
}
@@ -488,12 +490,12 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
488490
name: ty::BoundRegionKind::BrAnon(p.idx as u32),
489491
})
490492
}
491-
chalk_ir::LifetimeData::Static => ty::RegionKind::ReStatic,
492-
chalk_ir::LifetimeData::Phantom(_, _) => unimplemented!(),
493+
chalk_ir::LifetimeData::Static => return interner.tcx.lifetimes.re_static,
493494
chalk_ir::LifetimeData::Empty(ui) => {
494-
ty::RegionKind::ReEmpty(ty::UniverseIndex::from_usize(ui.counter))
495+
ty::ReEmpty(ty::UniverseIndex::from_usize(ui.counter))
495496
}
496-
chalk_ir::LifetimeData::Erased => ty::RegionKind::ReErased,
497+
chalk_ir::LifetimeData::Erased => return interner.tcx.lifetimes.re_erased,
498+
chalk_ir::LifetimeData::Phantom(void, _) => match *void {},
497499
};
498500
interner.tcx.mk_region(kind)
499501
}
@@ -1110,32 +1112,3 @@ impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
11101112
r.super_visit_with(self)
11111113
}
11121114
}
1113-
1114-
/// Used to substitute specific `Regions`s with placeholders.
1115-
crate struct RegionsSubstitutor<'tcx> {
1116-
tcx: TyCtxt<'tcx>,
1117-
reempty_placeholder: ty::Region<'tcx>,
1118-
}
1119-
1120-
impl<'tcx> RegionsSubstitutor<'tcx> {
1121-
crate fn new(tcx: TyCtxt<'tcx>, reempty_placeholder: ty::Region<'tcx>) -> Self {
1122-
RegionsSubstitutor { tcx, reempty_placeholder }
1123-
}
1124-
}
1125-
1126-
impl<'tcx> TypeFolder<'tcx> for RegionsSubstitutor<'tcx> {
1127-
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
1128-
self.tcx
1129-
}
1130-
1131-
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
1132-
match r {
1133-
ty::ReEmpty(ui) => {
1134-
assert_eq!(ui.as_usize(), 0);
1135-
self.reempty_placeholder
1136-
}
1137-
1138-
_ => r.super_fold_with(self),
1139-
}
1140-
}
1141-
}

compiler/rustc_traits/src/chalk/mod.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ use rustc_infer::infer::canonical::{
2222
use rustc_infer::traits::{self, CanonicalChalkEnvironmentAndGoal};
2323

2424
use crate::chalk::db::RustIrDatabase as ChalkRustIrDatabase;
25-
use crate::chalk::lowering::{
26-
LowerInto, ParamsSubstitutor, PlaceholdersCollector, RegionsSubstitutor,
27-
};
25+
use crate::chalk::lowering::LowerInto;
26+
use crate::chalk::lowering::{ParamsSubstitutor, PlaceholdersCollector};
2827

2928
use chalk_solve::Solution;
3029

@@ -42,20 +41,11 @@ crate fn evaluate_goal<'tcx>(
4241
let mut placeholders_collector = PlaceholdersCollector::new();
4342
obligation.visit_with(&mut placeholders_collector);
4443

45-
let reempty_placeholder = tcx.mk_region(ty::RegionKind::RePlaceholder(ty::Placeholder {
46-
universe: ty::UniverseIndex::ROOT,
47-
name: ty::BoundRegionKind::BrAnon(placeholders_collector.next_anon_region_placeholder + 1),
48-
}));
49-
5044
let mut params_substitutor =
5145
ParamsSubstitutor::new(tcx, placeholders_collector.next_ty_placeholder);
5246
let obligation = obligation.fold_with(&mut params_substitutor);
53-
// FIXME(chalk): we really should be substituting these back in the solution
5447
let _params: FxHashMap<usize, ParamTy> = params_substitutor.params;
5548

56-
let mut regions_substitutor = RegionsSubstitutor::new(tcx, reempty_placeholder);
57-
let obligation = obligation.fold_with(&mut regions_substitutor);
58-
5949
let max_universe = obligation.max_universe.index();
6050

6151
let lowered_goal: chalk_ir::UCanonical<
@@ -96,7 +86,8 @@ crate fn evaluate_goal<'tcx>(
9686

9787
use chalk_solve::Solver;
9888
let mut solver = chalk_engine::solve::SLGSolver::new(32, None);
99-
let db = ChalkRustIrDatabase { interner, reempty_placeholder };
89+
let db = ChalkRustIrDatabase { interner };
90+
debug!(?lowered_goal);
10091
let solution = solver.solve(&db, &lowered_goal);
10192
debug!(?obligation, ?solution, "evaluate goal");
10293

0 commit comments

Comments
 (0)