Binders::subst -> substitute

This commit is contained in:
Florian Diebold 2021-04-05 18:39:53 +02:00
parent ad20f00844
commit 05eba0db3d
14 changed files with 39 additions and 39 deletions

View File

@ -235,7 +235,7 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
write!(f, "{}", self.name(f.db))?;
let bounds = f.db.generic_predicates_for_param(self.id);
let substs = TyBuilder::type_params_subst(f.db, self.id.parent);
let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>();
let predicates = bounds.iter().cloned().map(|b| b.substitute(&substs)).collect::<Vec<_>>();
if !(predicates.is_empty() || f.omit_verbose_types()) {
write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?;
}

View File

@ -516,7 +516,7 @@ pub fn signature_ty(&self, db: &dyn HirDatabase) -> Type {
VariantDef::Variant(it) => it.parent.id.into(),
};
let substs = TyBuilder::type_params_subst(db, generic_def_id);
let ty = db.field_types(var_id)[self.id].clone().subst(&substs);
let ty = db.field_types(var_id)[self.id].clone().substitute(&substs);
Type::new(db, self.parent.module(db).id.krate(), var_id, ty)
}
@ -1503,7 +1503,7 @@ pub fn default(self, db: &dyn HirDatabase) -> Option<Type> {
let krate = self.id.parent.module(db.upcast()).krate();
let ty = params.get(local_idx)?.clone();
let subst = TyBuilder::type_params_subst(db, self.id.parent);
let ty = ty.subst(&subst.prefix(local_idx));
let ty = ty.substitute(&subst.prefix(local_idx));
Some(Type::new_with_resolver_inner(db, krate, &resolver, ty))
}
}
@ -1916,7 +1916,7 @@ pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
.iter()
.map(|(local_id, ty)| {
let def = Field { parent: variant_id.into(), id: local_id };
let ty = ty.clone().subst(substs);
let ty = ty.clone().substitute(substs);
(def, self.derived(ty))
})
.collect()

View File

@ -339,7 +339,7 @@ fn missing_fields(
.into_iter()
.map(|local_id| {
let field = FieldId { parent: variant, local_id };
let ty = field_types[local_id].clone().subst(substs);
let ty = field_types[local_id].clone().substitute(substs);
(field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty))
})
.collect()

View File

@ -139,7 +139,7 @@ pub fn fill_with_defaults(
} else {
// each default can depend on the previous parameters
let subst_so_far = Substitution::intern(self.vec.clone());
self.vec.push(default_ty.clone().subst(&subst_so_far).cast(&Interner));
self.vec.push(default_ty.clone().substitute(&subst_so_far).cast(&Interner));
}
}
self
@ -200,7 +200,7 @@ fn subst_binders(b: Binders<T>) -> Self {
pub fn build(self) -> T {
let (b, subst) = self.build_internal();
b.subst(&subst)
b.substitute(&subst)
}
}

View File

@ -352,7 +352,7 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
let data = (*datas)
.as_ref()
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
let bounds = data.subst(parameters);
let bounds = data.substitute(parameters);
bounds.into_value_and_skipped_binders().0
} else {
Vec::new()
@ -397,7 +397,7 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
}
TyKind::FnDef(def, parameters) => {
let def = from_chalk(f.db, *def);
let sig = f.db.callable_item_signature(def).subst(parameters);
let sig = f.db.callable_item_signature(def).substitute(parameters);
match def {
CallableDefId::FunctionId(ff) => {
write!(f, "fn {}", f.db.function_data(ff).name)?
@ -482,7 +482,7 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
(_, Some(default_parameter)) => {
let actual_default = default_parameter
.clone()
.subst(&parameters.prefix(i));
.substitute(&parameters.prefix(i));
if parameter.assert_ty_ref(&Interner) != &actual_default
{
default_from = i + 1;
@ -542,7 +542,7 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
let data = (*datas)
.as_ref()
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
let bounds = data.subst(&parameters);
let bounds = data.substitute(&parameters);
write_bounds_like_dyn_trait_with_prefix("impl", bounds.skip_binders(), f)?;
// FIXME: it would maybe be good to distinguish this from the alias type (when debug printing), and to show the substitution
}
@ -595,7 +595,7 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
let bounds =
f.db.generic_predicates(id.parent)
.into_iter()
.map(|pred| pred.clone().subst(&substs))
.map(|pred| pred.clone().substitute(&substs))
.filter(|wc| match &wc.skip_binders() {
WhereClause::Implemented(tr) => {
tr.self_type_parameter(&Interner) == self
@ -629,7 +629,7 @@ fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
let data = (*datas)
.as_ref()
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
let bounds = data.subst(&opaque_ty.substitution);
let bounds = data.substitute(&opaque_ty.substitution);
write_bounds_like_dyn_trait_with_prefix("impl", bounds.skip_binders(), f)?;
}
ImplTraitId::AsyncBlockTypeImplTrait(..) => {

View File

@ -470,25 +470,25 @@ fn resolve_variant(&mut self, path: Option<&Path>) -> (Ty, Option<VariantId>) {
TypeNs::AdtId(AdtId::StructId(strukt)) => {
let substs = ctx.substs_from_path(path, strukt.into(), true);
let ty = self.db.ty(strukt.into());
let ty = self.insert_type_vars(ty.subst(&substs));
let ty = self.insert_type_vars(ty.substitute(&substs));
forbid_unresolved_segments((ty, Some(strukt.into())), unresolved)
}
TypeNs::AdtId(AdtId::UnionId(u)) => {
let substs = ctx.substs_from_path(path, u.into(), true);
let ty = self.db.ty(u.into());
let ty = self.insert_type_vars(ty.subst(&substs));
let ty = self.insert_type_vars(ty.substitute(&substs));
forbid_unresolved_segments((ty, Some(u.into())), unresolved)
}
TypeNs::EnumVariantId(var) => {
let substs = ctx.substs_from_path(path, var.into(), true);
let ty = self.db.ty(var.parent.into());
let ty = self.insert_type_vars(ty.subst(&substs));
let ty = self.insert_type_vars(ty.substitute(&substs));
forbid_unresolved_segments((ty, Some(var.into())), unresolved)
}
TypeNs::SelfType(impl_id) => {
let generics = crate::utils::generics(self.db.upcast(), impl_id.into());
let substs = generics.type_params_subst(self.db);
let ty = self.db.impl_self_ty(impl_id).subst(&substs);
let ty = self.db.impl_self_ty(impl_id).substitute(&substs);
match unresolved {
None => {
let variant = ty_variant(&ty);

View File

@ -419,7 +419,7 @@ fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
self.result.record_field_resolutions.insert(field.expr, field_def);
}
let field_ty = field_def.map_or(self.err_ty(), |it| {
field_types[it.local_id].clone().subst(&substs)
field_types[it.local_id].clone().substitute(&substs)
});
self.infer_expr_coerce(field.expr, &Expectation::has_type(field_ty));
}
@ -462,7 +462,7 @@ fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
Some(
self.db.field_types((*s).into())[field.local_id]
.clone()
.subst(&parameters),
.substitute(&parameters),
)
} else {
None
@ -476,7 +476,7 @@ fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
Some(
self.db.field_types((*u).into())[field.local_id]
.clone()
.subst(&parameters),
.substitute(&parameters),
)
} else {
None
@ -852,7 +852,7 @@ fn infer_method_call(
None => (receiver_ty, Binders::empty(&Interner, self.err_ty()), None),
};
let substs = self.substs_for_method_call(def_generics, generic_args, &derefed_receiver_ty);
let method_ty = method_ty.subst(&substs);
let method_ty = method_ty.substitute(&substs);
let method_ty = self.insert_type_vars(method_ty);
self.register_obligations_for_call(&method_ty);
let (expected_receiver_ty, param_tys, ret_ty) = match method_ty.callable_sig(self.db) {
@ -950,7 +950,7 @@ fn register_obligations_for_call(&mut self, callable_ty: &Ty) {
let generic_predicates = self.db.generic_predicates(def.into());
for predicate in generic_predicates.iter() {
let (predicate, binders) =
predicate.clone().subst(parameters).into_value_and_skipped_binders();
predicate.clone().substitute(parameters).into_value_and_skipped_binders();
always!(binders.len(&Interner) == 0); // quantified where clauses not yet handled
self.push_obligation(predicate.cast(&Interner));
}

View File

@ -49,7 +49,7 @@ fn infer_tuple_struct_pat(
let expected_ty = var_data
.as_ref()
.and_then(|d| d.field(&Name::new_tuple_field(i)))
.map_or(self.err_ty(), |field| field_tys[field].clone().subst(&substs));
.map_or(self.err_ty(), |field| field_tys[field].clone().substitute(&substs));
let expected_ty = self.normalize_associated_types_in(expected_ty);
self.infer_pat(subpat, &expected_ty, default_bm);
}
@ -84,7 +84,7 @@ fn infer_record_pat(
}
let expected_ty = matching_field
.map_or(self.err_ty(), |field| field_tys[field].clone().subst(&substs));
.map_or(self.err_ty(), |field| field_tys[field].clone().substitute(&substs));
let expected_ty = self.normalize_associated_types_in(expected_ty);
self.infer_pat(subpat.pat, &expected_ty, default_bm);
}

View File

@ -81,9 +81,9 @@ fn resolve_value_path(
ValueNs::ImplSelf(impl_id) => {
let generics = crate::utils::generics(self.db.upcast(), impl_id.into());
let substs = generics.type_params_subst(self.db);
let ty = self.db.impl_self_ty(impl_id).subst(&substs);
let ty = self.db.impl_self_ty(impl_id).substitute(&substs);
if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() {
let ty = self.db.value_ty(struct_id.into()).subst(&substs);
let ty = self.db.value_ty(struct_id.into()).substitute(&substs);
return Some(ty);
} else {
// FIXME: diagnostic, invalid Self reference
@ -243,7 +243,7 @@ fn resolve_ty_assoc_item(
let impl_substs = TyBuilder::subst_for_def(self.db, impl_id)
.fill(iter::repeat_with(|| self.table.new_type_var()))
.build();
let impl_self_ty = self.db.impl_self_ty(impl_id).subst(&impl_substs);
let impl_self_ty = self.db.impl_self_ty(impl_id).substitute(&impl_substs);
self.unify(&impl_self_ty, &ty);
Some(impl_substs)
}

View File

@ -130,7 +130,7 @@ pub fn wrap_empty(value: T) -> Self
impl<T: TypeWalk> Binders<T> {
/// Substitutes all variables.
pub fn subst(self, subst: &Substitution) -> T {
pub fn substitute(self, subst: &Substitution) -> T {
let (value, binders) = self.into_value_and_skipped_binders();
assert_eq!(subst.len(&Interner), binders.len(&Interner));
value.subst_bound_vars(subst)
@ -362,7 +362,7 @@ pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<CallableSig> {
TyKind::FnDef(def, parameters) => {
let callable_def = db.lookup_intern_callable_def((*def).into());
let sig = db.callable_item_signature(callable_def);
Some(sig.subst(&parameters))
Some(sig.substitute(&parameters))
}
TyKind::Closure(.., substs) => {
let sig_param = substs.at(&Interner, 0).assert_ty_ref(&Interner);
@ -436,7 +436,7 @@ pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWh
let data = (*it)
.as_ref()
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
data.subst(&opaque_ty.substitution)
data.substitute(&opaque_ty.substitution)
})
}
// It always has an parameter for Future::Output type.
@ -455,7 +455,7 @@ pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWh
let predicates = db
.generic_predicates(id.parent)
.into_iter()
.map(|pred| pred.clone().subst(&substs))
.map(|pred| pred.clone().substitute(&substs))
.filter(|wc| match &wc.skip_binders() {
WhereClause::Implemented(tr) => {
tr.self_type_parameter(&Interner) == self

View File

@ -414,7 +414,7 @@ pub(crate) fn lower_partly_resolved_path(
TypeParamLoweringMode::Placeholder => generics.type_params_subst(self.db),
TypeParamLoweringMode::Variable => generics.bound_vars_subst(self.in_binders),
};
self.db.impl_self_ty(impl_id).subst(&substs)
self.db.impl_self_ty(impl_id).substitute(&substs)
}
TypeNs::AdtSelfType(adt) => {
let generics = generics(self.db.upcast(), adt.into());
@ -422,7 +422,7 @@ pub(crate) fn lower_partly_resolved_path(
TypeParamLoweringMode::Placeholder => generics.type_params_subst(self.db),
TypeParamLoweringMode::Variable => generics.bound_vars_subst(self.in_binders),
};
self.db.ty(adt.into()).subst(&substs)
self.db.ty(adt.into()).substitute(&substs)
}
TypeNs::AdtId(it) => self.lower_path_inner(resolved_segment, it.into(), infer_args),
@ -516,7 +516,7 @@ fn lower_path_inner(
TyDefId::TypeAliasId(it) => Some(it.into()),
};
let substs = self.substs_from_path_segment(segment, generic_def, infer_args, None);
self.db.ty(typeable).subst(&substs)
self.db.ty(typeable).substitute(&substs)
}
/// Collect generic arguments from a path into a `Substs`. See also
@ -620,7 +620,7 @@ fn substs_from_path_segment(
for default_ty in defaults.iter().skip(substs.len()) {
// each default can depend on the previous parameters
let substs_so_far = Substitution::from_iter(&Interner, substs.clone());
substs.push(default_ty.clone().subst(&substs_so_far));
substs.push(default_ty.clone().substitute(&substs_so_far));
}
}
}

View File

@ -712,7 +712,7 @@ pub(crate) fn inherent_impl_substs(
let vars = TyBuilder::subst_for_def(db, impl_id)
.fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty.binders.len(&Interner))
.build();
let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars);
let self_ty_with_vars = db.impl_self_ty(impl_id).substitute(&vars);
let mut kinds = self_ty.binders.interned().to_vec();
kinds.extend(
iter::repeat(chalk_ir::WithKind::new(
@ -774,7 +774,7 @@ fn transform_receiver_ty(
AssocContainerId::ModuleId(_) => unreachable!(),
};
let sig = db.callable_item_signature(function_id.into());
Some(sig.map(|s| s.params()[0].clone()).subst(&substs))
Some(sig.map(|s| s.params()[0].clone()).substitute(&substs))
}
pub fn implements_trait(

View File

@ -519,7 +519,7 @@ pub(super) fn convert_where_clauses(
let generic_predicates = db.generic_predicates(def);
let mut result = Vec::with_capacity(generic_predicates.len());
for pred in generic_predicates.iter() {
result.push(pred.clone().subst(substs).to_chalk(db));
result.push(pred.clone().substitute(substs).to_chalk(db));
}
result
}

View File

@ -72,7 +72,7 @@ fn direct_super_trait_refs(db: &dyn HirDatabase, trait_ref: &TraitRef) -> Vec<Tr
_ => None,
})
})
.map(|pred| pred.subst(&trait_ref.substitution))
.map(|pred| pred.substitute(&trait_ref.substitution))
.collect()
}