Rename some fields to their Chalk names

This commit is contained in:
Florian Diebold 2021-03-14 16:26:12 +01:00
parent f57e2f5598
commit 3411fe3e84
11 changed files with 47 additions and 47 deletions

View file

@ -1686,8 +1686,8 @@ impl Type {
.build(); .build();
let predicate = ProjectionPredicate { let predicate = ProjectionPredicate {
projection_ty: ProjectionTy { projection_ty: ProjectionTy {
associated_ty: to_assoc_type_id(alias.id), associated_ty_id: to_assoc_type_id(alias.id),
parameters: subst, substitution: subst,
}, },
ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(&Interner), ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(&Interner),
}; };

View file

@ -84,7 +84,7 @@ fn deref_by_trait(
let projection = super::traits::ProjectionPredicate { let projection = super::traits::ProjectionPredicate {
ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len())) ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len()))
.intern(&Interner), .intern(&Interner),
projection_ty: super::ProjectionTy { associated_ty: to_assoc_type_id(target), parameters }, projection_ty: super::ProjectionTy { associated_ty_id: to_assoc_type_id(target), substitution: parameters },
}; };
let obligation = super::Obligation::Projection(projection); let obligation = super::Obligation::Projection(projection);

View file

@ -245,19 +245,19 @@ impl HirDisplay for ProjectionTy {
} }
let trait_ = f.db.trait_data(self.trait_(f.db)); let trait_ = f.db.trait_data(self.trait_(f.db));
let first_parameter = self.parameters[0].into_displayable( let first_parameter = self.substitution[0].into_displayable(
f.db, f.db,
f.max_size, f.max_size,
f.omit_verbose_types, f.omit_verbose_types,
f.display_target, f.display_target,
); );
write!(f, "<{} as {}", first_parameter, trait_.name)?; write!(f, "<{} as {}", first_parameter, trait_.name)?;
if self.parameters.len() > 1 { if self.substitution.len() > 1 {
write!(f, "<")?; write!(f, "<")?;
f.write_joined(&self.parameters[1..], ", ")?; f.write_joined(&self.substitution[1..], ", ")?;
write!(f, ">")?; write!(f, ">")?;
} }
write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty)).name)?; write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty_id)).name)?;
Ok(()) Ok(())
} }
} }
@ -491,8 +491,8 @@ impl HirDisplay for Ty {
} }
} else { } else {
let projection_ty = ProjectionTy { let projection_ty = ProjectionTy {
associated_ty: to_assoc_type_id(type_alias), associated_ty_id: to_assoc_type_id(type_alias),
parameters: parameters.clone(), substitution: parameters.clone(),
}; };
projection_ty.hir_fmt(f)?; projection_ty.hir_fmt(f)?;
@ -709,7 +709,7 @@ fn write_bounds_like_dyn_trait(
angle_open = true; angle_open = true;
} }
let type_alias = f.db.type_alias_data(from_assoc_type_id( let type_alias = f.db.type_alias_data(from_assoc_type_id(
projection_pred.projection_ty.associated_ty, projection_pred.projection_ty.associated_ty_id,
)); ));
write!(f, "{} = ", type_alias.name)?; write!(f, "{} = ", type_alias.name)?;
projection_pred.ty.hir_fmt(f)?; projection_pred.ty.hir_fmt(f)?;
@ -782,7 +782,7 @@ impl HirDisplay for GenericPredicate {
f, f,
">::{} = ", ">::{} = ",
f.db.type_alias_data(from_assoc_type_id( f.db.type_alias_data(from_assoc_type_id(
projection_pred.projection_ty.associated_ty projection_pred.projection_ty.associated_ty_id
)) ))
.name, .name,
)?; )?;

View file

@ -385,8 +385,8 @@ impl<'a> InferenceContext<'a> {
let projection = ProjectionPredicate { let projection = ProjectionPredicate {
ty: ty.clone(), ty: ty.clone(),
projection_ty: ProjectionTy { projection_ty: ProjectionTy {
associated_ty: to_assoc_type_id(res_assoc_ty), associated_ty_id: to_assoc_type_id(res_assoc_ty),
parameters: substs, substitution: substs,
}, },
}; };
self.obligations.push(Obligation::Trait(trait_ref)); self.obligations.push(Obligation::Trait(trait_ref));

View file

@ -99,8 +99,8 @@ impl<'a> InferenceContext<'a> {
if self.db.trait_solve(krate, goal.value).is_some() { if self.db.trait_solve(krate, goal.value).is_some() {
self.obligations.push(implements_fn_trait); self.obligations.push(implements_fn_trait);
let output_proj_ty = crate::ProjectionTy { let output_proj_ty = crate::ProjectionTy {
associated_ty: to_assoc_type_id(output_assoc_type), associated_ty_id: to_assoc_type_id(output_assoc_type),
parameters: substs, substitution: substs,
}; };
let return_ty = self.normalize_projection_ty(output_proj_ty); let return_ty = self.normalize_projection_ty(output_proj_ty);
Some((arg_tys, return_ty)) Some((arg_tys, return_ty))

View file

@ -381,11 +381,11 @@ impl InferenceTable {
self.unify_substs(&tr1.substs, &tr2.substs, depth + 1) self.unify_substs(&tr1.substs, &tr2.substs, depth + 1)
} }
(GenericPredicate::Projection(proj1), GenericPredicate::Projection(proj2)) (GenericPredicate::Projection(proj1), GenericPredicate::Projection(proj2))
if proj1.projection_ty.associated_ty == proj2.projection_ty.associated_ty => if proj1.projection_ty.associated_ty_id == proj2.projection_ty.associated_ty_id =>
{ {
self.unify_substs( self.unify_substs(
&proj1.projection_ty.parameters, &proj1.projection_ty.substitution,
&proj2.projection_ty.parameters, &proj2.projection_ty.substitution,
depth + 1, depth + 1,
) && self.unify_inner(&proj1.ty, &proj2.ty, depth + 1) ) && self.unify_inner(&proj1.ty, &proj2.ty, depth + 1)
} }

View file

@ -74,17 +74,17 @@ pub struct OpaqueTy {
/// trait and all its parameters are fully known. /// trait and all its parameters are fully known.
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub struct ProjectionTy { pub struct ProjectionTy {
pub associated_ty: AssocTypeId, pub associated_ty_id: AssocTypeId,
pub parameters: Substs, pub substitution: Substs,
} }
impl ProjectionTy { impl ProjectionTy {
pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef { pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef {
TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } TraitRef { trait_: self.trait_(db), substs: self.substitution.clone() }
} }
fn trait_(&self, db: &dyn HirDatabase) -> TraitId { fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
match from_assoc_type_id(self.associated_ty).lookup(db.upcast()).container { match from_assoc_type_id(self.associated_ty_id).lookup(db.upcast()).container {
AssocContainerId::TraitId(it) => it, AssocContainerId::TraitId(it) => it,
_ => panic!("projection ty without parent trait"), _ => panic!("projection ty without parent trait"),
} }
@ -93,7 +93,7 @@ impl ProjectionTy {
impl TypeWalk for ProjectionTy { impl TypeWalk for ProjectionTy {
fn walk(&self, f: &mut impl FnMut(&Ty)) { fn walk(&self, f: &mut impl FnMut(&Ty)) {
self.parameters.walk(f); self.substitution.walk(f);
} }
fn walk_mut_binders( fn walk_mut_binders(
@ -101,7 +101,7 @@ impl TypeWalk for ProjectionTy {
f: &mut impl FnMut(&mut Ty, DebruijnIndex), f: &mut impl FnMut(&mut Ty, DebruijnIndex),
binders: DebruijnIndex, binders: DebruijnIndex,
) { ) {
self.parameters.walk_mut_binders(f, binders); self.substitution.walk_mut_binders(f, binders);
} }
} }
@ -945,7 +945,7 @@ impl Ty {
} }
} }
TyKind::Alias(AliasTy::Projection(projection_ty)) => { TyKind::Alias(AliasTy::Projection(projection_ty)) => {
match from_assoc_type_id(projection_ty.associated_ty).lookup(db.upcast()).container match from_assoc_type_id(projection_ty.associated_ty_id).lookup(db.upcast()).container
{ {
AssocContainerId::TraitId(trait_id) => Some(trait_id), AssocContainerId::TraitId(trait_id) => Some(trait_id),
_ => None, _ => None,
@ -1055,7 +1055,7 @@ impl TypeWalk for Ty {
fn walk(&self, f: &mut impl FnMut(&Ty)) { fn walk(&self, f: &mut impl FnMut(&Ty)) {
match self.interned(&Interner) { match self.interned(&Interner) {
TyKind::Alias(AliasTy::Projection(p_ty)) => { TyKind::Alias(AliasTy::Projection(p_ty)) => {
for t in p_ty.parameters.iter() { for t in p_ty.substitution.iter() {
t.walk(f); t.walk(f);
} }
} }
@ -1087,7 +1087,7 @@ impl TypeWalk for Ty {
) { ) {
match &mut self.0 { match &mut self.0 {
TyKind::Alias(AliasTy::Projection(p_ty)) => { TyKind::Alias(AliasTy::Projection(p_ty)) => {
p_ty.parameters.walk_mut_binders(f, binders); p_ty.substitution.walk_mut_binders(f, binders);
} }
TyKind::Dyn(predicates) => { TyKind::Dyn(predicates) => {
for p in make_mut_slice(predicates) { for p in make_mut_slice(predicates) {

View file

@ -357,8 +357,8 @@ impl<'a> TyLoweringContext<'a> {
Some((super_trait_ref, associated_ty)) => { Some((super_trait_ref, associated_ty)) => {
// FIXME handle type parameters on the segment // FIXME handle type parameters on the segment
TyKind::Alias(AliasTy::Projection(ProjectionTy { TyKind::Alias(AliasTy::Projection(ProjectionTy {
associated_ty: to_assoc_type_id(associated_ty), associated_ty_id: to_assoc_type_id(associated_ty),
parameters: super_trait_ref.substs, substitution: super_trait_ref.substs,
})) }))
.intern(&Interner) .intern(&Interner)
} }
@ -478,8 +478,8 @@ impl<'a> TyLoweringContext<'a> {
// FIXME handle type parameters on the segment // FIXME handle type parameters on the segment
return Some( return Some(
TyKind::Alias(AliasTy::Projection(ProjectionTy { TyKind::Alias(AliasTy::Projection(ProjectionTy {
associated_ty: to_assoc_type_id(associated_ty), associated_ty_id: to_assoc_type_id(associated_ty),
parameters: substs, substitution: substs,
})) }))
.intern(&Interner), .intern(&Interner),
); );
@ -736,8 +736,8 @@ impl<'a> TyLoweringContext<'a> {
Some(t) => t, Some(t) => t,
}; };
let projection_ty = ProjectionTy { let projection_ty = ProjectionTy {
associated_ty: to_assoc_type_id(associated_ty), associated_ty_id: to_assoc_type_id(associated_ty),
parameters: super_trait_ref.substs, substitution: super_trait_ref.substs,
}; };
let mut preds = SmallVec::with_capacity( let mut preds = SmallVec::with_capacity(
binding.type_ref.as_ref().map_or(0, |_| 1) + binding.bounds.len(), binding.type_ref.as_ref().map_or(0, |_| 1) + binding.bounds.len(),

View file

@ -143,7 +143,7 @@ pub(crate) fn trait_solve_query(
log::info!("trait_solve_query({})", goal.value.value.display(db)); log::info!("trait_solve_query({})", goal.value.value.display(db));
if let Obligation::Projection(pred) = &goal.value.value { if let Obligation::Projection(pred) = &goal.value.value {
if let TyKind::BoundVar(_) = &pred.projection_ty.parameters[0].interned(&Interner) { if let TyKind::BoundVar(_) = &pred.projection_ty.substitution[0].interned(&Interner) {
// Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible
return Some(Solution::Ambig(Guidance::Unknown)); return Some(Solution::Ambig(Guidance::Unknown));
} }

View file

@ -234,9 +234,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
ty: TyKind::BoundVar(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 }) ty: TyKind::BoundVar(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 })
.intern(&Interner), .intern(&Interner),
projection_ty: ProjectionTy { projection_ty: ProjectionTy {
associated_ty: to_assoc_type_id(future_output), associated_ty_id: to_assoc_type_id(future_output),
// Self type as the first parameter. // Self type as the first parameter.
parameters: Substs::single( substitution: Substs::single(
TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
.intern(&Interner), .intern(&Interner),
), ),

View file

@ -78,8 +78,8 @@ impl ToChalk for Ty {
chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner) chalk_ir::TyKind::Adt(adt_id, substitution).intern(&Interner)
} }
TyKind::Alias(AliasTy::Projection(proj_ty)) => { TyKind::Alias(AliasTy::Projection(proj_ty)) => {
let associated_ty_id = proj_ty.associated_ty; let associated_ty_id = proj_ty.associated_ty_id;
let substitution = proj_ty.parameters.to_chalk(db); let substitution = proj_ty.substitution.to_chalk(db);
chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
associated_ty_id, associated_ty_id,
substitution, substitution,
@ -121,7 +121,7 @@ impl ToChalk for Ty {
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => {
let associated_ty = proj.associated_ty_id; let associated_ty = proj.associated_ty_id;
let parameters = from_chalk(db, proj.substitution); let parameters = from_chalk(db, proj.substitution);
TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty_id: associated_ty, substitution: parameters }))
} }
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => {
let opaque_ty_id = opaque_ty.opaque_ty_id; let opaque_ty_id = opaque_ty.opaque_ty_id;
@ -372,8 +372,8 @@ impl ToChalk for ProjectionTy {
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> { fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::ProjectionTy<Interner> {
chalk_ir::ProjectionTy { chalk_ir::ProjectionTy {
associated_ty_id: self.associated_ty, associated_ty_id: self.associated_ty_id,
substitution: self.parameters.to_chalk(db), substitution: self.substitution.to_chalk(db),
} }
} }
@ -382,8 +382,8 @@ impl ToChalk for ProjectionTy {
projection_ty: chalk_ir::ProjectionTy<Interner>, projection_ty: chalk_ir::ProjectionTy<Interner>,
) -> ProjectionTy { ) -> ProjectionTy {
ProjectionTy { ProjectionTy {
associated_ty: projection_ty.associated_ty_id, associated_ty_id: projection_ty.associated_ty_id,
parameters: from_chalk(db, projection_ty.substitution), substitution: from_chalk(db, projection_ty.substitution),
} }
} }
} }
@ -533,24 +533,24 @@ pub(super) fn generic_predicate_to_inline_bound(
Some(rust_ir::InlineBound::TraitBound(trait_bound)) Some(rust_ir::InlineBound::TraitBound(trait_bound))
} }
GenericPredicate::Projection(proj) => { GenericPredicate::Projection(proj) => {
if &proj.projection_ty.parameters[0] != self_ty { if &proj.projection_ty.substitution[0] != self_ty {
return None; return None;
} }
let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty) let trait_ = match from_assoc_type_id(proj.projection_ty.associated_ty_id)
.lookup(db.upcast()) .lookup(db.upcast())
.container .container
{ {
AssocContainerId::TraitId(t) => t, AssocContainerId::TraitId(t) => t,
_ => panic!("associated type not in trait"), _ => panic!("associated type not in trait"),
}; };
let args_no_self = proj.projection_ty.parameters[1..] let args_no_self = proj.projection_ty.substitution[1..]
.iter() .iter()
.map(|ty| ty.clone().to_chalk(db).cast(&Interner)) .map(|ty| ty.clone().to_chalk(db).cast(&Interner))
.collect(); .collect();
let alias_eq_bound = rust_ir::AliasEqBound { let alias_eq_bound = rust_ir::AliasEqBound {
value: proj.ty.clone().to_chalk(db), value: proj.ty.clone().to_chalk(db),
trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self }, trait_bound: rust_ir::TraitBound { trait_id: trait_.to_chalk(db), args_no_self },
associated_ty_id: proj.projection_ty.associated_ty, associated_ty_id: proj.projection_ty.associated_ty_id,
parameters: Vec::new(), // FIXME we don't support generic associated types yet parameters: Vec::new(), // FIXME we don't support generic associated types yet
}; };
Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound)) Some(rust_ir::InlineBound::AliasEqBound(alias_eq_bound))