Review comments

This commit is contained in:
Jack Huey 2020-08-15 18:04:11 -04:00
parent 76c728901e
commit f690569465
4 changed files with 130 additions and 131 deletions

View File

@ -112,30 +112,25 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
match application_ty.name { match application_ty.name {
chalk_ir::TypeName::Ref(mutbl) => { chalk_ir::TypeName::Ref(mutbl) => {
let data = application_ty.substitution.interned(); let data = application_ty.substitution.interned();
let lifetime = match &**data[0].interned() { match (&**data[0].interned(), &**data[1].interned()) {
chalk_ir::GenericArgData::Lifetime(t) => t, (
chalk_ir::GenericArgData::Lifetime(lifetime),
chalk_ir::GenericArgData::Ty(ty),
) => Some(match mutbl {
chalk_ir::Mutability::Not => write!(fmt, "(&{:?} {:?})", lifetime, ty),
chalk_ir::Mutability::Mut => write!(fmt, "(&{:?} mut {:?})", lifetime, ty),
}),
_ => unreachable!(), _ => unreachable!(),
}; }
let ty = match &**data[1].interned() {
chalk_ir::GenericArgData::Ty(t) => t,
_ => unreachable!(),
};
return Some(match mutbl {
chalk_ir::Mutability::Not => write!(fmt, "(&{:?} {:?})", lifetime, ty),
chalk_ir::Mutability::Mut => write!(fmt, "(&{:?} mut {:?})", lifetime, ty),
});
} }
chalk_ir::TypeName::Array => { chalk_ir::TypeName::Array => {
let data = application_ty.substitution.interned(); let data = application_ty.substitution.interned();
let ty = match &**data[0].interned() { match (&**data[0].interned(), &**data[1].interned()) {
chalk_ir::GenericArgData::Ty(t) => t, (chalk_ir::GenericArgData::Ty(ty), chalk_ir::GenericArgData::Const(len)) => {
Some(write!(fmt, "[{:?}; {:?}]", ty, len))
}
_ => unreachable!(), _ => unreachable!(),
}; }
let len = match &**data[1].interned() {
chalk_ir::GenericArgData::Const(t) => t,
_ => unreachable!(),
};
return Some(write!(fmt, "[{:?}; {:?}]", ty, len));
} }
chalk_ir::TypeName::Slice => { chalk_ir::TypeName::Slice => {
let data = application_ty.substitution.interned(); let data = application_ty.substitution.interned();
@ -143,12 +138,13 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
chalk_ir::GenericArgData::Ty(t) => t, chalk_ir::GenericArgData::Ty(t) => t,
_ => unreachable!(), _ => unreachable!(),
}; };
return Some(write!(fmt, "[{:?}]", ty)); Some(write!(fmt, "[{:?}]", ty))
}
_ => {
let chalk_ir::ApplicationTy { name, substitution } = application_ty;
Some(write!(fmt, "{:?}{:?}", name, chalk_ir::debug::Angle(substitution.interned())))
} }
_ => {}
} }
let chalk_ir::ApplicationTy { name, substitution } = application_ty;
Some(write!(fmt, "{:?}{:?}", name, chalk_ir::debug::Angle(substitution.interned())))
} }
fn debug_substitution( fn debug_substitution(

View File

@ -21,10 +21,9 @@ use std::sync::Arc;
use crate::chalk::lowering::{self, LowerInto}; use crate::chalk::lowering::{self, LowerInto};
pub struct RustIrDatabase<'tcx> { pub struct RustIrDatabase<'tcx> {
pub tcx: TyCtxt<'tcx>, pub(crate) interner: RustInterner<'tcx>,
pub interner: RustInterner<'tcx>, pub(crate) restatic_placeholder: ty::Region<'tcx>,
pub restatic_placeholder: ty::Region<'tcx>, pub(crate) reempty_placeholder: ty::Region<'tcx>,
pub reempty_placeholder: ty::Region<'tcx>,
} }
impl fmt::Debug for RustIrDatabase<'_> { impl fmt::Debug for RustIrDatabase<'_> {
@ -39,15 +38,15 @@ impl<'tcx> RustIrDatabase<'tcx> {
def_id: DefId, def_id: DefId,
bound_vars: SubstsRef<'tcx>, bound_vars: SubstsRef<'tcx>,
) -> Vec<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> { ) -> Vec<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
let predicates = self.tcx.predicates_of(def_id).predicates; let predicates = self.interner.tcx.predicates_of(def_id).predicates;
let mut regions_substitutor = lowering::RegionsSubstitutor::new( let mut regions_substitutor = lowering::RegionsSubstitutor::new(
self.tcx, self.interner.tcx,
self.restatic_placeholder, self.restatic_placeholder,
self.reempty_placeholder, self.reempty_placeholder,
); );
predicates predicates
.iter() .iter()
.map(|(wc, _)| wc.subst(self.tcx, bound_vars)) .map(|(wc, _)| wc.subst(self.interner.tcx, bound_vars))
.map(|wc| wc.fold_with(&mut regions_substitutor)) .map(|wc| wc.fold_with(&mut regions_substitutor))
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect() .filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect()
} }
@ -63,7 +62,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
assoc_type_id: chalk_ir::AssocTypeId<RustInterner<'tcx>>, assoc_type_id: chalk_ir::AssocTypeId<RustInterner<'tcx>>,
) -> Arc<chalk_solve::rust_ir::AssociatedTyDatum<RustInterner<'tcx>>> { ) -> Arc<chalk_solve::rust_ir::AssociatedTyDatum<RustInterner<'tcx>>> {
let def_id = assoc_type_id.0; let def_id = assoc_type_id.0;
let assoc_item = self.tcx.associated_item(def_id); let assoc_item = self.interner.tcx.associated_item(def_id);
let trait_def_id = match assoc_item.container { let trait_def_id = match assoc_item.container {
AssocItemContainer::TraitContainer(def_id) => def_id, AssocItemContainer::TraitContainer(def_id) => def_id,
_ => unimplemented!("Not possible??"), _ => unimplemented!("Not possible??"),
@ -72,7 +71,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
AssocKind::Type => {} AssocKind::Type => {}
_ => unimplemented!("Not possible??"), _ => unimplemented!("Not possible??"),
} }
let bound_vars = bound_vars_for_item(self.tcx, def_id); let bound_vars = bound_vars_for_item(self.interner.tcx, def_id);
let binders = binders_for(&self.interner, bound_vars); let binders = binders_for(&self.interner, bound_vars);
// FIXME(chalk): this really isn't right I don't think. The functions // FIXME(chalk): this really isn't right I don't think. The functions
// for GATs are a bit hard to figure out. Are these supposed to be where // for GATs are a bit hard to figure out. Are these supposed to be where
@ -95,14 +94,15 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
trait_id: chalk_ir::TraitId<RustInterner<'tcx>>, trait_id: chalk_ir::TraitId<RustInterner<'tcx>>,
) -> Arc<chalk_solve::rust_ir::TraitDatum<RustInterner<'tcx>>> { ) -> Arc<chalk_solve::rust_ir::TraitDatum<RustInterner<'tcx>>> {
let def_id = trait_id.0; let def_id = trait_id.0;
let trait_def = self.tcx.trait_def(def_id); let trait_def = self.interner.tcx.trait_def(def_id);
let bound_vars = bound_vars_for_item(self.tcx, def_id); let bound_vars = bound_vars_for_item(self.interner.tcx, def_id);
let binders = binders_for(&self.interner, bound_vars); let binders = binders_for(&self.interner, bound_vars);
let where_clauses = self.where_clauses_for(def_id, bound_vars); let where_clauses = self.where_clauses_for(def_id, bound_vars);
let associated_ty_ids: Vec<_> = self let associated_ty_ids: Vec<_> = self
.interner
.tcx .tcx
.associated_items(def_id) .associated_items(def_id)
.in_definition_order() .in_definition_order()
@ -110,24 +110,47 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
.map(|i| chalk_ir::AssocTypeId(i.def_id)) .map(|i| chalk_ir::AssocTypeId(i.def_id))
.collect(); .collect();
let well_known = let well_known = if self
if self.tcx.lang_items().sized_trait().map(|t| def_id == t).unwrap_or(false) { .interner
Some(chalk_solve::rust_ir::WellKnownTrait::Sized) .tcx
} else if self.tcx.lang_items().copy_trait().map(|t| def_id == t).unwrap_or(false) { .lang_items()
Some(chalk_solve::rust_ir::WellKnownTrait::Copy) .sized_trait()
} else if self.tcx.lang_items().clone_trait().map(|t| def_id == t).unwrap_or(false) { .map(|t| def_id == t)
Some(chalk_solve::rust_ir::WellKnownTrait::Clone) .unwrap_or(false)
} else if self.tcx.lang_items().drop_trait().map(|t| def_id == t).unwrap_or(false) { {
Some(chalk_solve::rust_ir::WellKnownTrait::Drop) Some(chalk_solve::rust_ir::WellKnownTrait::Sized)
} else if self.tcx.lang_items().fn_trait().map(|t| def_id == t).unwrap_or(false) { } else if self.interner.tcx.lang_items().copy_trait().map(|t| def_id == t).unwrap_or(false)
Some(chalk_solve::rust_ir::WellKnownTrait::Fn) {
} else if self.tcx.lang_items().fn_once_trait().map(|t| def_id == t).unwrap_or(false) { Some(chalk_solve::rust_ir::WellKnownTrait::Copy)
Some(chalk_solve::rust_ir::WellKnownTrait::FnOnce) } else if self.interner.tcx.lang_items().clone_trait().map(|t| def_id == t).unwrap_or(false)
} else if self.tcx.lang_items().fn_mut_trait().map(|t| def_id == t).unwrap_or(false) { {
Some(chalk_solve::rust_ir::WellKnownTrait::FnMut) Some(chalk_solve::rust_ir::WellKnownTrait::Clone)
} else { } else if self.interner.tcx.lang_items().drop_trait().map(|t| def_id == t).unwrap_or(false)
None {
}; Some(chalk_solve::rust_ir::WellKnownTrait::Drop)
} else if self.interner.tcx.lang_items().fn_trait().map(|t| def_id == t).unwrap_or(false) {
Some(chalk_solve::rust_ir::WellKnownTrait::Fn)
} else if self
.interner
.tcx
.lang_items()
.fn_once_trait()
.map(|t| def_id == t)
.unwrap_or(false)
{
Some(chalk_solve::rust_ir::WellKnownTrait::FnOnce)
} else if self
.interner
.tcx
.lang_items()
.fn_mut_trait()
.map(|t| def_id == t)
.unwrap_or(false)
{
Some(chalk_solve::rust_ir::WellKnownTrait::FnMut)
} else {
None
};
Arc::new(chalk_solve::rust_ir::TraitDatum { Arc::new(chalk_solve::rust_ir::TraitDatum {
id: trait_id, id: trait_id,
binders: chalk_ir::Binders::new( binders: chalk_ir::Binders::new(
@ -138,7 +161,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
auto: trait_def.has_auto_impl, auto: trait_def.has_auto_impl,
marker: trait_def.is_marker, marker: trait_def.is_marker,
upstream: !def_id.is_local(), upstream: !def_id.is_local(),
fundamental: self.tcx.has_attr(def_id, sym::fundamental), fundamental: self.interner.tcx.has_attr(def_id, sym::fundamental),
non_enumerable: true, non_enumerable: true,
coinductive: false, coinductive: false,
}, },
@ -153,7 +176,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
) -> Arc<chalk_solve::rust_ir::AdtDatum<RustInterner<'tcx>>> { ) -> Arc<chalk_solve::rust_ir::AdtDatum<RustInterner<'tcx>>> {
let adt_def = adt_id.0; let adt_def = adt_id.0;
let bound_vars = bound_vars_for_item(self.tcx, adt_def.did); let bound_vars = bound_vars_for_item(self.interner.tcx, adt_def.did);
let binders = binders_for(&self.interner, bound_vars); let binders = binders_for(&self.interner, bound_vars);
let where_clauses = self.where_clauses_for(adt_def.did, bound_vars); let where_clauses = self.where_clauses_for(adt_def.did, bound_vars);
@ -165,16 +188,11 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fields: variant fields: variant
.fields .fields
.iter() .iter()
.map(|field| { .map(|field| field.ty(self.interner.tcx, bound_vars).lower_into(&self.interner))
self.tcx
.type_of(field.did)
.subst(self.tcx, bound_vars)
.lower_into(&self.interner)
})
.collect(), .collect(),
}) })
.collect(); .collect();
let struct_datum = Arc::new(chalk_solve::rust_ir::AdtDatum { Arc::new(chalk_solve::rust_ir::AdtDatum {
id: adt_id, id: adt_id,
binders: chalk_ir::Binders::new( binders: chalk_ir::Binders::new(
binders, binders,
@ -190,8 +208,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
ty::AdtKind::Union => chalk_solve::rust_ir::AdtKind::Union, ty::AdtKind::Union => chalk_solve::rust_ir::AdtKind::Union,
ty::AdtKind::Enum => chalk_solve::rust_ir::AdtKind::Enum, ty::AdtKind::Enum => chalk_solve::rust_ir::AdtKind::Enum,
}, },
}); })
struct_datum
} }
fn adt_repr( fn adt_repr(
@ -210,27 +227,25 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn_def_id: chalk_ir::FnDefId<RustInterner<'tcx>>, fn_def_id: chalk_ir::FnDefId<RustInterner<'tcx>>,
) -> Arc<chalk_solve::rust_ir::FnDefDatum<RustInterner<'tcx>>> { ) -> Arc<chalk_solve::rust_ir::FnDefDatum<RustInterner<'tcx>>> {
let def_id = fn_def_id.0; let def_id = fn_def_id.0;
let bound_vars = bound_vars_for_item(self.tcx, def_id); let bound_vars = bound_vars_for_item(self.interner.tcx, def_id);
let binders = binders_for(&self.interner, bound_vars); let binders = binders_for(&self.interner, bound_vars);
let where_clauses = self.where_clauses_for(def_id, bound_vars); let where_clauses = self.where_clauses_for(def_id, bound_vars);
let sig = self.tcx.fn_sig(def_id); let sig = self.interner.tcx.fn_sig(def_id);
let inputs_and_output = sig.inputs_and_output();
let inputs_and_output = inputs_and_output.subst(self.tcx, bound_vars);
let (inputs_and_output, iobinders, _) = crate::chalk::lowering::collect_bound_vars( let (inputs_and_output, iobinders, _) = crate::chalk::lowering::collect_bound_vars(
&self.interner, &self.interner,
self.tcx, self.interner.tcx,
&inputs_and_output, &sig.inputs_and_output().subst(self.interner.tcx, bound_vars),
); );
let argument_types = inputs_and_output[..inputs_and_output.len() - 1] let argument_types = inputs_and_output[..inputs_and_output.len() - 1]
.iter() .iter()
.map(|t| t.subst(self.tcx, &bound_vars).lower_into(&self.interner)) .map(|t| t.subst(self.interner.tcx, &bound_vars).lower_into(&self.interner))
.collect(); .collect();
let return_type = inputs_and_output[inputs_and_output.len() - 1] let return_type = inputs_and_output[inputs_and_output.len() - 1]
.subst(self.tcx, &bound_vars) .subst(self.interner.tcx, &bound_vars)
.lower_into(&self.interner); .lower_into(&self.interner);
let bound = chalk_solve::rust_ir::FnDefDatumBound { let bound = chalk_solve::rust_ir::FnDefDatumBound {
@ -257,13 +272,13 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
impl_id: chalk_ir::ImplId<RustInterner<'tcx>>, impl_id: chalk_ir::ImplId<RustInterner<'tcx>>,
) -> Arc<chalk_solve::rust_ir::ImplDatum<RustInterner<'tcx>>> { ) -> Arc<chalk_solve::rust_ir::ImplDatum<RustInterner<'tcx>>> {
let def_id = impl_id.0; let def_id = impl_id.0;
let bound_vars = bound_vars_for_item(self.tcx, def_id); let bound_vars = bound_vars_for_item(self.interner.tcx, def_id);
let binders = binders_for(&self.interner, bound_vars); let binders = binders_for(&self.interner, bound_vars);
let trait_ref = self.tcx.impl_trait_ref(def_id).expect("not an impl"); let trait_ref = self.interner.tcx.impl_trait_ref(def_id).expect("not an impl");
let trait_ref = trait_ref.subst(self.tcx, bound_vars); let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars);
let mut regions_substitutor = lowering::RegionsSubstitutor::new( let mut regions_substitutor = lowering::RegionsSubstitutor::new(
self.tcx, self.interner.tcx,
self.restatic_placeholder, self.restatic_placeholder,
self.reempty_placeholder, self.reempty_placeholder,
); );
@ -296,16 +311,16 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
// require us to be able to interconvert `Ty<'tcx>`, and we're // require us to be able to interconvert `Ty<'tcx>`, and we're
// not there yet. // not there yet.
let all_impls = self.tcx.all_impls(def_id); let all_impls = self.interner.tcx.all_impls(def_id);
let matched_impls = all_impls.filter(|impl_def_id| { let matched_impls = all_impls.filter(|impl_def_id| {
use chalk_ir::could_match::CouldMatch; use chalk_ir::could_match::CouldMatch;
let trait_ref = self.tcx.impl_trait_ref(*impl_def_id).unwrap(); let trait_ref = self.interner.tcx.impl_trait_ref(*impl_def_id).unwrap();
let bound_vars = bound_vars_for_item(self.tcx, *impl_def_id); let bound_vars = bound_vars_for_item(self.interner.tcx, *impl_def_id);
let self_ty = trait_ref.self_ty(); let self_ty = trait_ref.self_ty();
let self_ty = self_ty.subst(self.tcx, bound_vars); let self_ty = self_ty.subst(self.interner.tcx, bound_vars);
let mut regions_substitutor = lowering::RegionsSubstitutor::new( let mut regions_substitutor = lowering::RegionsSubstitutor::new(
self.tcx, self.interner.tcx,
self.restatic_placeholder, self.restatic_placeholder,
self.reempty_placeholder, self.reempty_placeholder,
); );
@ -326,9 +341,9 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
) -> bool { ) -> bool {
let trait_def_id = auto_trait_id.0; let trait_def_id = auto_trait_id.0;
let adt_def = adt_id.0; let adt_def = adt_id.0;
let all_impls = self.tcx.all_impls(trait_def_id); let all_impls = self.interner.tcx.all_impls(trait_def_id);
for impl_def_id in all_impls { for impl_def_id in all_impls {
let trait_ref = self.tcx.impl_trait_ref(impl_def_id).unwrap(); let trait_ref = self.interner.tcx.impl_trait_ref(impl_def_id).unwrap();
let self_ty = trait_ref.self_ty(); let self_ty = trait_ref.self_ty();
match *self_ty.kind() { match *self_ty.kind() {
ty::Adt(impl_adt_def, _) => { ty::Adt(impl_adt_def, _) => {
@ -347,7 +362,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
associated_ty_id: chalk_solve::rust_ir::AssociatedTyValueId<RustInterner<'tcx>>, associated_ty_id: chalk_solve::rust_ir::AssociatedTyValueId<RustInterner<'tcx>>,
) -> Arc<chalk_solve::rust_ir::AssociatedTyValue<RustInterner<'tcx>>> { ) -> Arc<chalk_solve::rust_ir::AssociatedTyValue<RustInterner<'tcx>>> {
let def_id = associated_ty_id.0; let def_id = associated_ty_id.0;
let assoc_item = self.tcx.associated_item(def_id); let assoc_item = self.interner.tcx.associated_item(def_id);
let impl_id = match assoc_item.container { let impl_id = match assoc_item.container {
AssocItemContainer::TraitContainer(def_id) => def_id, AssocItemContainer::TraitContainer(def_id) => def_id,
_ => unimplemented!("Not possible??"), _ => unimplemented!("Not possible??"),
@ -356,9 +371,9 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
AssocKind::Type => {} AssocKind::Type => {}
_ => unimplemented!("Not possible??"), _ => unimplemented!("Not possible??"),
} }
let bound_vars = bound_vars_for_item(self.tcx, def_id); let bound_vars = bound_vars_for_item(self.interner.tcx, def_id);
let binders = binders_for(&self.interner, bound_vars); let binders = binders_for(&self.interner, bound_vars);
let ty = self.tcx.type_of(def_id); let ty = self.interner.tcx.type_of(def_id);
Arc::new(chalk_solve::rust_ir::AssociatedTyValue { Arc::new(chalk_solve::rust_ir::AssociatedTyValue {
impl_id: chalk_ir::ImplId(impl_id), impl_id: chalk_ir::ImplId(impl_id),
@ -385,7 +400,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
&self, &self,
opaque_ty_id: chalk_ir::OpaqueTyId<RustInterner<'tcx>>, opaque_ty_id: chalk_ir::OpaqueTyId<RustInterner<'tcx>>,
) -> Arc<chalk_solve::rust_ir::OpaqueTyDatum<RustInterner<'tcx>>> { ) -> Arc<chalk_solve::rust_ir::OpaqueTyDatum<RustInterner<'tcx>>> {
let bound_vars = bound_vars_for_item(self.tcx, opaque_ty_id.0); let bound_vars = bound_vars_for_item(self.interner.tcx, opaque_ty_id.0);
let binders = binders_for(&self.interner, bound_vars); let binders = binders_for(&self.interner, bound_vars);
let where_clauses = self.where_clauses_for(opaque_ty_id.0, bound_vars); let where_clauses = self.where_clauses_for(opaque_ty_id.0, bound_vars);
@ -395,7 +410,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
}; };
Arc::new(chalk_solve::rust_ir::OpaqueTyDatum { Arc::new(chalk_solve::rust_ir::OpaqueTyDatum {
opaque_ty_id, opaque_ty_id,
bound: chalk_ir::Binders::new(chalk_ir::VariableKinds::empty(&self.interner), value), bound: chalk_ir::Binders::empty(&self.interner, value),
}) })
} }
@ -412,20 +427,20 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
) -> Option<chalk_ir::TraitId<RustInterner<'tcx>>> { ) -> Option<chalk_ir::TraitId<RustInterner<'tcx>>> {
use chalk_solve::rust_ir::WellKnownTrait::*; use chalk_solve::rust_ir::WellKnownTrait::*;
let def_id = match well_known_trait { let def_id = match well_known_trait {
Sized => self.tcx.lang_items().sized_trait(), Sized => self.interner.tcx.lang_items().sized_trait(),
Copy => self.tcx.lang_items().copy_trait(), Copy => self.interner.tcx.lang_items().copy_trait(),
Clone => self.tcx.lang_items().clone_trait(), Clone => self.interner.tcx.lang_items().clone_trait(),
Drop => self.tcx.lang_items().drop_trait(), Drop => self.interner.tcx.lang_items().drop_trait(),
Fn => self.tcx.lang_items().fn_trait(), Fn => self.interner.tcx.lang_items().fn_trait(),
FnMut => self.tcx.lang_items().fn_mut_trait(), FnMut => self.interner.tcx.lang_items().fn_mut_trait(),
FnOnce => self.tcx.lang_items().fn_once_trait(), FnOnce => self.interner.tcx.lang_items().fn_once_trait(),
Unsize => self.tcx.lang_items().unsize_trait(), Unsize => self.interner.tcx.lang_items().unsize_trait(),
}; };
def_id.map(chalk_ir::TraitId) def_id.map(chalk_ir::TraitId)
} }
fn is_object_safe(&self, trait_id: chalk_ir::TraitId<RustInterner<'tcx>>) -> bool { fn is_object_safe(&self, trait_id: chalk_ir::TraitId<RustInterner<'tcx>>) -> bool {
self.tcx.is_object_safe(trait_id.0) self.interner.tcx.is_object_safe(trait_id.0)
} }
fn hidden_opaque_type( fn hidden_opaque_type(
@ -433,7 +448,10 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
_id: chalk_ir::OpaqueTyId<RustInterner<'tcx>>, _id: chalk_ir::OpaqueTyId<RustInterner<'tcx>>,
) -> chalk_ir::Ty<RustInterner<'tcx>> { ) -> chalk_ir::Ty<RustInterner<'tcx>> {
// FIXME(chalk): actually get hidden ty // FIXME(chalk): actually get hidden ty
self.tcx.mk_ty(ty::Tuple(self.tcx.intern_substs(&[]))).lower_into(&self.interner) self.interner
.tcx
.mk_ty(ty::Tuple(self.interner.tcx.intern_substs(&[])))
.lower_into(&self.interner)
} }
fn closure_kind( fn closure_kind(

View File

@ -880,10 +880,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for NamedBoundVarSubstitutor<'a, 'tcx> {
result result
} }
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
t.super_fold_with(self)
}
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> { fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
match r { match r {
ty::ReLateBound(index, br) if *index == self.binder_index => match br { ty::ReLateBound(index, br) if *index == self.binder_index => match br {
@ -914,18 +910,18 @@ crate struct ParamsSubstitutor<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
binder_index: ty::DebruijnIndex, binder_index: ty::DebruijnIndex,
list: Vec<rustc_middle::ty::ParamTy>, list: Vec<rustc_middle::ty::ParamTy>,
next_ty_placehoder: usize, next_ty_placeholder: usize,
crate params: rustc_data_structures::fx::FxHashMap<usize, rustc_middle::ty::ParamTy>, crate params: rustc_data_structures::fx::FxHashMap<usize, rustc_middle::ty::ParamTy>,
crate named_regions: BTreeMap<DefId, u32>, crate named_regions: BTreeMap<DefId, u32>,
} }
impl<'tcx> ParamsSubstitutor<'tcx> { impl<'tcx> ParamsSubstitutor<'tcx> {
crate fn new(tcx: TyCtxt<'tcx>, next_ty_placehoder: usize) -> Self { crate fn new(tcx: TyCtxt<'tcx>, next_ty_placeholder: usize) -> Self {
ParamsSubstitutor { ParamsSubstitutor {
tcx, tcx,
binder_index: ty::INNERMOST, binder_index: ty::INNERMOST,
list: vec![], list: vec![],
next_ty_placehoder, next_ty_placeholder,
params: rustc_data_structures::fx::FxHashMap::default(), params: rustc_data_structures::fx::FxHashMap::default(),
named_regions: BTreeMap::default(), named_regions: BTreeMap::default(),
} }
@ -957,7 +953,7 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
})), })),
None => { None => {
self.list.push(param); self.list.push(param);
let idx = self.list.len() - 1 + self.next_ty_placehoder; let idx = self.list.len() - 1 + self.next_ty_placeholder;
self.params.insert(idx, param); self.params.insert(idx, param);
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType { self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
universe: ty::UniverseIndex::from_usize(0), universe: ty::UniverseIndex::from_usize(0),
@ -997,7 +993,7 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
/// Used to collect `Placeholder`s. /// Used to collect `Placeholder`s.
crate struct PlaceholdersCollector { crate struct PlaceholdersCollector {
universe_index: ty::UniverseIndex, universe_index: ty::UniverseIndex,
crate next_ty_placehoder: usize, crate next_ty_placeholder: usize,
crate next_anon_region_placeholder: u32, crate next_anon_region_placeholder: u32,
} }
@ -1005,21 +1001,17 @@ impl PlaceholdersCollector {
crate fn new() -> Self { crate fn new() -> Self {
PlaceholdersCollector { PlaceholdersCollector {
universe_index: ty::UniverseIndex::ROOT, universe_index: ty::UniverseIndex::ROOT,
next_ty_placehoder: 0, next_ty_placeholder: 0,
next_anon_region_placeholder: 0, next_anon_region_placeholder: 0,
} }
} }
} }
impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector { impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
t.super_visit_with(self)
}
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool { fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
match t.kind { match t.kind {
ty::Placeholder(p) if p.universe == self.universe_index => { ty::Placeholder(p) if p.universe == self.universe_index => {
self.next_ty_placehoder = self.next_ty_placehoder.max(p.name.as_usize() + 1); self.next_ty_placeholder = self.next_ty_placeholder.max(p.name.as_usize() + 1);
} }
_ => (), _ => (),
@ -1065,14 +1057,6 @@ impl<'tcx> TypeFolder<'tcx> for RegionsSubstitutor<'tcx> {
self.tcx self.tcx
} }
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> Binder<T> {
t.super_fold_with(self)
}
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
t.super_fold_with(self)
}
fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> { fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
match r { match r {
ty::ReStatic => self.restatic_placeholder, ty::ReStatic => self.restatic_placeholder,

View File

@ -53,8 +53,9 @@ crate fn evaluate_goal<'tcx>(
})); }));
let mut params_substitutor = let mut params_substitutor =
ParamsSubstitutor::new(tcx, placeholders_collector.next_ty_placehoder); ParamsSubstitutor::new(tcx, placeholders_collector.next_ty_placeholder);
let obligation = obligation.fold_with(&mut params_substitutor); let obligation = obligation.fold_with(&mut params_substitutor);
// FIXME(chalk): we really should be substituting these back in the solution
let _params: FxHashMap<usize, ParamTy> = params_substitutor.params; let _params: FxHashMap<usize, ParamTy> = params_substitutor.params;
let mut regions_substitutor = let mut regions_substitutor =
@ -63,7 +64,7 @@ crate fn evaluate_goal<'tcx>(
let max_universe = obligation.max_universe.index(); let max_universe = obligation.max_universe.index();
let _lowered_goal: chalk_ir::UCanonical< let lowered_goal: chalk_ir::UCanonical<
chalk_ir::InEnvironment<chalk_ir::Goal<ChalkRustInterner<'tcx>>>, chalk_ir::InEnvironment<chalk_ir::Goal<ChalkRustInterner<'tcx>>>,
> = chalk_ir::UCanonical { > = chalk_ir::UCanonical {
canonical: chalk_ir::Canonical { canonical: chalk_ir::Canonical {
@ -101,17 +102,17 @@ crate fn evaluate_goal<'tcx>(
use chalk_solve::Solver; use chalk_solve::Solver;
let mut solver = chalk_engine::solve::SLGSolver::new(32, None); let mut solver = chalk_engine::solve::SLGSolver::new(32, None);
let db = ChalkRustIrDatabase { tcx, interner, restatic_placeholder, reempty_placeholder }; let db = ChalkRustIrDatabase { interner, restatic_placeholder, reempty_placeholder };
let solution = chalk_solve::logging::with_tracing_logs(|| solver.solve(&db, &_lowered_goal)); let solution = chalk_solve::logging::with_tracing_logs(|| solver.solve(&db, &lowered_goal));
// Ideally, the code to convert *back* to rustc types would live close to // Ideally, the code to convert *back* to rustc types would live close to
// the code to convert *from* rustc types. Right now though, we don't // the code to convert *from* rustc types. Right now though, we don't
// really need this and so it's really minimal. // really need this and so it's really minimal.
// Right now, we also treat a `Unique` solution the same as // Right now, we also treat a `Unique` solution the same as
// `Ambig(Definite)`. This really isn't right. // `Ambig(Definite)`. This really isn't right.
let make_solution = |_subst: chalk_ir::Substitution<_>| { let make_solution = |subst: chalk_ir::Substitution<_>| {
let mut var_values: IndexVec<BoundVar, GenericArg<'tcx>> = IndexVec::new(); let mut var_values: IndexVec<BoundVar, GenericArg<'tcx>> = IndexVec::new();
_subst.as_slice(&interner).iter().for_each(|p| { subst.as_slice(&interner).iter().for_each(|p| {
var_values.push(p.lower_into(&interner)); var_values.push(p.lower_into(&interner));
}); });
let sol = Canonical { let sol = Canonical {
@ -128,13 +129,13 @@ crate fn evaluate_goal<'tcx>(
}; };
solution solution
.map(|s| match s { .map(|s| match s {
Solution::Unique(_subst) => { Solution::Unique(subst) => {
// FIXME(chalk): handle constraints // FIXME(chalk): handle constraints
make_solution(_subst.value.subst) make_solution(subst.value.subst)
} }
Solution::Ambig(_guidance) => { Solution::Ambig(guidance) => {
match _guidance { match guidance {
chalk_solve::Guidance::Definite(_subst) => make_solution(_subst.value), chalk_solve::Guidance::Definite(subst) => make_solution(subst.value),
chalk_solve::Guidance::Suggested(_) => unimplemented!(), chalk_solve::Guidance::Suggested(_) => unimplemented!(),
chalk_solve::Guidance::Unknown => { chalk_solve::Guidance::Unknown => {
// chalk_fulfill doesn't use the var_values here, so // chalk_fulfill doesn't use the var_values here, so