Make BoundRegion have a kind of BoungRegionKind
This commit is contained in:
parent
6340607aca
commit
328fcee4af
47 changed files with 183 additions and 181 deletions
|
@ -648,7 +648,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
|||
|
||||
/// Creates a `InternalSubsts` that maps each generic parameter to a higher-ranked
|
||||
/// var bound at index `0`. For types, we use a `BoundVar` index equal to
|
||||
/// the type parameter index. For regions, we use the `BoundRegion::BrNamed`
|
||||
/// the type parameter index. For regions, we use the `BoundRegionKind::BrNamed`
|
||||
/// variant (which has a `DefId`).
|
||||
fn bound_vars_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
|
||||
InternalSubsts::for_item(tcx, def_id, |param, substs| match param.kind {
|
||||
|
@ -662,12 +662,10 @@ fn bound_vars_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
|
|||
))
|
||||
.into(),
|
||||
|
||||
ty::GenericParamDefKind::Lifetime => tcx
|
||||
.mk_region(ty::RegionKind::ReLateBound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundRegion::BrAnon(substs.len() as u32),
|
||||
))
|
||||
.into(),
|
||||
ty::GenericParamDefKind::Lifetime => {
|
||||
let br = ty::BoundRegion { kind: ty::BrAnon(substs.len() as u32) };
|
||||
tcx.mk_region(ty::RegionKind::ReLateBound(ty::INNERMOST, br)).into()
|
||||
}
|
||||
|
||||
ty::GenericParamDefKind::Const => tcx
|
||||
.mk_const(ty::Const {
|
||||
|
|
|
@ -35,9 +35,7 @@ use rustc_ast::ast;
|
|||
use rustc_middle::traits::{ChalkEnvironmentAndGoal, ChalkRustInterner as RustInterner};
|
||||
use rustc_middle::ty::fold::TypeFolder;
|
||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
|
||||
use rustc_middle::ty::{
|
||||
self, Binder, BoundRegion, Region, RegionKind, Ty, TyCtxt, TypeFoldable, TypeVisitor,
|
||||
};
|
||||
use rustc_middle::ty::{self, Binder, Region, RegionKind, Ty, TyCtxt, TypeFoldable, TypeVisitor};
|
||||
use rustc_span::def_id::DefId;
|
||||
|
||||
use chalk_ir::{FnSig, ForeignDefId};
|
||||
|
@ -444,15 +442,15 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
|
|||
ReEarlyBound(_) => {
|
||||
panic!("Should have already been substituted.");
|
||||
}
|
||||
ReLateBound(db, br) => match br {
|
||||
ty::BoundRegion::BrAnon(var) => {
|
||||
ReLateBound(db, br) => match br.kind {
|
||||
ty::BoundRegionKind::BrAnon(var) => {
|
||||
chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(
|
||||
chalk_ir::DebruijnIndex::new(db.as_u32()),
|
||||
*var as usize,
|
||||
var as usize,
|
||||
))
|
||||
.intern(interner)
|
||||
}
|
||||
ty::BoundRegion::BrNamed(_def_id, _name) => unimplemented!(),
|
||||
ty::BoundRegionKind::BrNamed(_def_id, _name) => unimplemented!(),
|
||||
ty::BrEnv => unimplemented!(),
|
||||
},
|
||||
ReFree(_) => unimplemented!(),
|
||||
|
@ -477,13 +475,13 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
|
|||
let kind = match self.data(interner) {
|
||||
chalk_ir::LifetimeData::BoundVar(var) => ty::RegionKind::ReLateBound(
|
||||
ty::DebruijnIndex::from_u32(var.debruijn.depth()),
|
||||
ty::BoundRegion::BrAnon(var.index as u32),
|
||||
ty::BoundRegion { kind: ty::BrAnon(var.index as u32) },
|
||||
),
|
||||
chalk_ir::LifetimeData::InferenceVar(_var) => unimplemented!(),
|
||||
chalk_ir::LifetimeData::Placeholder(p) => {
|
||||
ty::RegionKind::RePlaceholder(ty::Placeholder {
|
||||
universe: ty::UniverseIndex::from_usize(p.ui.counter),
|
||||
name: ty::BoundRegion::BrAnon(p.idx as u32),
|
||||
name: ty::BoundRegionKind::BrAnon(p.idx as u32),
|
||||
})
|
||||
}
|
||||
chalk_ir::LifetimeData::Static => ty::RegionKind::ReStatic,
|
||||
|
@ -805,7 +803,7 @@ impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::AliasEqBound<RustInterner<'tcx>
|
|||
}
|
||||
|
||||
/// To collect bound vars, we have to do two passes. In the first pass, we
|
||||
/// collect all `BoundRegion`s and `ty::Bound`s. In the second pass, we then
|
||||
/// collect all `BoundRegionKind`s and `ty::Bound`s. In the second pass, we then
|
||||
/// replace `BrNamed` into `BrAnon`. The two separate passes are important,
|
||||
/// since we can only replace `BrNamed` with `BrAnon`s with indices *after* all
|
||||
/// "real" `BrAnon`s.
|
||||
|
@ -893,14 +891,14 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
|
|||
|
||||
fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
match r {
|
||||
ty::ReLateBound(index, br) if *index == self.binder_index => match br {
|
||||
ty::BoundRegion::BrNamed(def_id, _name) => {
|
||||
if self.named_parameters.iter().find(|d| *d == def_id).is_none() {
|
||||
self.named_parameters.push(*def_id);
|
||||
ty::ReLateBound(index, br) if *index == self.binder_index => match br.kind {
|
||||
ty::BoundRegionKind::BrNamed(def_id, _name) => {
|
||||
if self.named_parameters.iter().find(|d| **d == def_id).is_none() {
|
||||
self.named_parameters.push(def_id);
|
||||
}
|
||||
}
|
||||
|
||||
ty::BoundRegion::BrAnon(var) => match self.parameters.entry(*var) {
|
||||
ty::BoundRegionKind::BrAnon(var) => match self.parameters.entry(var) {
|
||||
Entry::Vacant(entry) => {
|
||||
entry.insert(chalk_ir::VariableKind::Lifetime);
|
||||
}
|
||||
|
@ -926,7 +924,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
/// This is used to replace `BoundRegion::BrNamed` with `BoundRegion::BrAnon`.
|
||||
/// This is used to replace `BoundRegionKind::BrNamed` with `BoundRegionKind::BrAnon`.
|
||||
/// Note: we assume that we will always have room for more bound vars. (i.e. we
|
||||
/// won't ever hit the `u32` limit in `BrAnon`s).
|
||||
struct NamedBoundVarSubstitutor<'a, 'tcx> {
|
||||
|
@ -955,20 +953,16 @@ impl<'a, 'tcx> TypeFolder<'tcx> for NamedBoundVarSubstitutor<'a, 'tcx> {
|
|||
|
||||
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
|
||||
match r {
|
||||
ty::ReLateBound(index, br) if *index == self.binder_index => match br {
|
||||
ty::BoundRegion::BrNamed(def_id, _name) => {
|
||||
match self.named_parameters.get(def_id) {
|
||||
Some(idx) => {
|
||||
return self.tcx.mk_region(RegionKind::ReLateBound(
|
||||
*index,
|
||||
BoundRegion::BrAnon(*idx),
|
||||
));
|
||||
}
|
||||
None => panic!("Missing `BrNamed`."),
|
||||
ty::ReLateBound(index, br) if *index == self.binder_index => match br.kind {
|
||||
ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
|
||||
Some(idx) => {
|
||||
let new_br = ty::BoundRegion { kind: ty::BrAnon(*idx) };
|
||||
return self.tcx.mk_region(RegionKind::ReLateBound(*index, new_br));
|
||||
}
|
||||
}
|
||||
None => panic!("Missing `BrNamed`."),
|
||||
},
|
||||
ty::BrEnv => unimplemented!(),
|
||||
ty::BoundRegion::BrAnon(_) => {}
|
||||
ty::BrAnon(_) => {}
|
||||
},
|
||||
_ => (),
|
||||
};
|
||||
|
@ -1044,17 +1038,15 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
|
|||
// FIXME(chalk) - jackh726 - this currently isn't hit in any tests.
|
||||
// This covers any region variables in a goal, right?
|
||||
ty::ReEarlyBound(_re) => match self.named_regions.get(&_re.def_id) {
|
||||
Some(idx) => self.tcx.mk_region(RegionKind::ReLateBound(
|
||||
self.binder_index,
|
||||
BoundRegion::BrAnon(*idx),
|
||||
)),
|
||||
Some(idx) => {
|
||||
let br = ty::BoundRegion { kind: ty::BrAnon(*idx) };
|
||||
self.tcx.mk_region(RegionKind::ReLateBound(self.binder_index, br))
|
||||
}
|
||||
None => {
|
||||
let idx = self.named_regions.len() as u32;
|
||||
let br = ty::BoundRegion { kind: ty::BrAnon(idx) };
|
||||
self.named_regions.insert(_re.def_id, idx);
|
||||
self.tcx.mk_region(RegionKind::ReLateBound(
|
||||
self.binder_index,
|
||||
BoundRegion::BrAnon(idx),
|
||||
))
|
||||
self.tcx.mk_region(RegionKind::ReLateBound(self.binder_index, br))
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1096,7 +1088,7 @@ impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
|
|||
fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
match r {
|
||||
ty::RePlaceholder(p) if p.universe == self.universe_index => {
|
||||
if let ty::BoundRegion::BrAnon(anon) = p.name {
|
||||
if let ty::BoundRegionKind::BrAnon(anon) = p.name {
|
||||
self.next_anon_region_placeholder = self.next_anon_region_placeholder.max(anon);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ crate fn evaluate_goal<'tcx>(
|
|||
|
||||
let reempty_placeholder = tcx.mk_region(ty::RegionKind::RePlaceholder(ty::Placeholder {
|
||||
universe: ty::UniverseIndex::ROOT,
|
||||
name: ty::BoundRegion::BrAnon(placeholders_collector.next_anon_region_placeholder + 1),
|
||||
name: ty::BoundRegionKind::BrAnon(placeholders_collector.next_anon_region_placeholder + 1),
|
||||
}));
|
||||
|
||||
let mut params_substitutor =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue