Replace mk_foo
calls with infer_foo
where possible.
There are several `mk_foo`/`intern_foo` pairs, where the former takes an iterator and the latter takes a slice. (This naming convention is bad, but that's a fix for another PR.) This commit changes several `mk_foo` occurrences into `intern_foo`, avoiding the need for some `.iter()`/`.into_iter()` calls. Affected cases: - mk_type_list - mk_tup - mk_substs - mk_const_list
This commit is contained in:
parent
9556b56dbd
commit
bcf0ec0191
20 changed files with 37 additions and 42 deletions
|
@ -2589,7 +2589,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
DefKind::InlineConst => substs.as_inline_const().parent_substs(),
|
DefKind::InlineConst => substs.as_inline_const().parent_substs(),
|
||||||
other => bug!("unexpected item {:?}", other),
|
other => bug!("unexpected item {:?}", other),
|
||||||
};
|
};
|
||||||
let parent_substs = tcx.mk_substs(parent_substs.iter());
|
let parent_substs = tcx.intern_substs(parent_substs);
|
||||||
|
|
||||||
assert_eq!(typeck_root_substs.len(), parent_substs.len());
|
assert_eq!(typeck_root_substs.len(), parent_substs.len());
|
||||||
if let Err(_) = self.eq_substs(
|
if let Err(_) = self.eq_substs(
|
||||||
|
|
|
@ -56,7 +56,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
Some(fx.easy_call("__multi3", &[lhs, rhs], val_ty))
|
Some(fx.easy_call("__multi3", &[lhs, rhs], val_ty))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
|
let out_ty = fx.tcx.intern_tup(&[lhs.layout().ty, fx.tcx.types.bool]);
|
||||||
let oflow = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32));
|
let oflow = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32));
|
||||||
let lhs = lhs.load_scalar(fx);
|
let lhs = lhs.load_scalar(fx);
|
||||||
let rhs = rhs.load_scalar(fx);
|
let rhs = rhs.load_scalar(fx);
|
||||||
|
@ -78,7 +78,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||||
}
|
}
|
||||||
BinOp::Add | BinOp::Sub | BinOp::Mul => {
|
BinOp::Add | BinOp::Sub | BinOp::Mul => {
|
||||||
assert!(checked);
|
assert!(checked);
|
||||||
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
|
let out_ty = fx.tcx.intern_tup(&[lhs.layout().ty, fx.tcx.types.bool]);
|
||||||
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
|
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
|
||||||
let (param_types, args) = if fx.tcx.sess.target.is_like_windows {
|
let (param_types, args) = if fx.tcx.sess.target.is_like_windows {
|
||||||
let (lhs_ptr, lhs_extra) = lhs.force_stack(fx);
|
let (lhs_ptr, lhs_extra) = lhs.force_stack(fx);
|
||||||
|
|
|
@ -191,7 +191,7 @@ fn llvm_add_sub<'tcx>(
|
||||||
// carry0 | carry1 -> carry or borrow respectively
|
// carry0 | carry1 -> carry or borrow respectively
|
||||||
let cb_out = fx.bcx.ins().bor(cb0, cb1);
|
let cb_out = fx.bcx.ins().bor(cb0, cb1);
|
||||||
|
|
||||||
let layout = fx.layout_of(fx.tcx.mk_tup([fx.tcx.types.u8, fx.tcx.types.u64].iter()));
|
let layout = fx.layout_of(fx.tcx.intern_tup(&[fx.tcx.types.u8, fx.tcx.types.u64]));
|
||||||
let val = CValue::by_val_pair(cb_out, c, layout);
|
let val = CValue::by_val_pair(cb_out, c, layout);
|
||||||
ret.write_cvalue(fx, val);
|
ret.write_cvalue(fx, val);
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ pub(crate) fn maybe_create_entry_wrapper(
|
||||||
tcx,
|
tcx,
|
||||||
ParamEnv::reveal_all(),
|
ParamEnv::reveal_all(),
|
||||||
report.def_id,
|
report.def_id,
|
||||||
tcx.mk_substs([GenericArg::from(main_ret_ty)].iter()),
|
tcx.intern_substs(&[GenericArg::from(main_ret_ty)]),
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
@ -289,7 +289,7 @@ pub(crate) fn codegen_checked_int_binop<'tcx>(
|
||||||
_ => bug!("binop {:?} on checked int/uint lhs: {:?} rhs: {:?}", bin_op, in_lhs, in_rhs),
|
_ => bug!("binop {:?} on checked int/uint lhs: {:?} rhs: {:?}", bin_op, in_lhs, in_rhs),
|
||||||
};
|
};
|
||||||
|
|
||||||
let out_layout = fx.layout_of(fx.tcx.mk_tup([in_lhs.layout().ty, fx.tcx.types.bool].iter()));
|
let out_layout = fx.layout_of(fx.tcx.intern_tup(&[in_lhs.layout().ty, fx.tcx.types.bool]));
|
||||||
CValue::by_val_pair(res, has_overflow, out_layout)
|
CValue::by_val_pair(res, has_overflow, out_layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
let loc_ty = self
|
let loc_ty = self
|
||||||
.tcx
|
.tcx
|
||||||
.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
|
.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
|
||||||
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter()));
|
.subst(*self.tcx, self.tcx.intern_substs(&[self.tcx.lifetimes.re_erased.into()]));
|
||||||
let loc_layout = self.layout_of(loc_ty).unwrap();
|
let loc_layout = self.layout_of(loc_ty).unwrap();
|
||||||
let location = self.allocate(loc_layout, MemoryKind::CallerLocation).unwrap();
|
let location = self.allocate(loc_layout, MemoryKind::CallerLocation).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -378,7 +378,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
||||||
(
|
(
|
||||||
1,
|
1,
|
||||||
vec![tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0))],
|
vec![tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0))],
|
||||||
tcx.mk_projection(discriminant_def_id, tcx.mk_substs([param(0).into()].iter())),
|
tcx.mk_projection(discriminant_def_id, tcx.intern_substs(&[param(0).into()])),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -301,7 +301,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
// Build a tuple (U0..Un) of the final upvar types U0..Un
|
// Build a tuple (U0..Un) of the final upvar types U0..Un
|
||||||
// and unify the upvar tuple type in the closure with it:
|
// and unify the upvar tuple type in the closure with it:
|
||||||
let final_tupled_upvars_type = self.tcx.mk_tup(final_upvar_tys.iter());
|
let final_tupled_upvars_type = self.tcx.intern_tup(&final_upvar_tys);
|
||||||
self.demand_suptype(span, substs.tupled_upvars_ty(), final_tupled_upvars_type);
|
self.demand_suptype(span, substs.tupled_upvars_ty(), final_tupled_upvars_type);
|
||||||
|
|
||||||
let fake_reads = delegate
|
let fake_reads = delegate
|
||||||
|
@ -315,8 +315,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
self.typeck_results.borrow_mut().closure_size_eval.insert(
|
self.typeck_results.borrow_mut().closure_size_eval.insert(
|
||||||
closure_def_id,
|
closure_def_id,
|
||||||
ClosureSizeProfileData {
|
ClosureSizeProfileData {
|
||||||
before_feature_tys: self.tcx.mk_tup(before_feature_tys.into_iter()),
|
before_feature_tys: self.tcx.intern_tup(&before_feature_tys),
|
||||||
after_feature_tys: self.tcx.mk_tup(after_feature_tys.into_iter()),
|
after_feature_tys: self.tcx.intern_tup(&after_feature_tys),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -502,7 +502,7 @@ impl<'tcx> Collector<'tcx> {
|
||||||
.subst_identity()
|
.subst_identity()
|
||||||
.fn_sig(self.tcx)
|
.fn_sig(self.tcx)
|
||||||
.inputs()
|
.inputs()
|
||||||
.map_bound(|slice| self.tcx.mk_type_list(slice.iter())),
|
.map_bound(|slice| self.tcx.intern_type_list(slice)),
|
||||||
);
|
);
|
||||||
|
|
||||||
argument_types
|
argument_types
|
||||||
|
|
|
@ -2525,14 +2525,12 @@ impl<'tcx> ConstantKind<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
|
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
|
||||||
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id) {
|
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id)
|
||||||
if let Some(parent_did) = parent_hir_id.as_owner() {
|
&& let Some(parent_did) = parent_hir_id.as_owner()
|
||||||
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
|
{
|
||||||
} else {
|
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
|
||||||
tcx.mk_substs(Vec::<GenericArg<'tcx>>::new().into_iter())
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
tcx.mk_substs(Vec::<GenericArg<'tcx>>::new().into_iter())
|
tcx.intern_substs(&[])
|
||||||
};
|
};
|
||||||
debug!(?parent_substs);
|
debug!(?parent_substs);
|
||||||
|
|
||||||
|
|
|
@ -1190,7 +1190,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.mk_imm_ref(
|
self.mk_imm_ref(
|
||||||
self.lifetimes.re_static,
|
self.lifetimes.re_static,
|
||||||
self.type_of(self.require_lang_item(LangItem::PanicLocation, None))
|
self.type_of(self.require_lang_item(LangItem::PanicLocation, None))
|
||||||
.subst(self, self.mk_substs([self.lifetimes.re_static.into()].iter())),
|
.subst(self, self.intern_substs(&[self.lifetimes.re_static.into()])),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -686,7 +686,7 @@ where
|
||||||
Increase this counter if you tried to implement this but
|
Increase this counter if you tried to implement this but
|
||||||
failed to do it without duplicating a lot of code from
|
failed to do it without duplicating a lot of code from
|
||||||
other places in the compiler: 2
|
other places in the compiler: 2
|
||||||
tcx.mk_tup(&[
|
tcx.intern_tup(&[
|
||||||
tcx.mk_array(tcx.types.usize, 3),
|
tcx.mk_array(tcx.types.usize, 3),
|
||||||
tcx.mk_array(Option<fn()>),
|
tcx.mk_array(Option<fn()>),
|
||||||
])
|
])
|
||||||
|
|
|
@ -673,7 +673,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
|
||||||
for (a_arg, b_arg) in aa.iter().zip(ba.iter()) {
|
for (a_arg, b_arg) in aa.iter().zip(ba.iter()) {
|
||||||
related_args.push(r.consts(a_arg, b_arg)?);
|
related_args.push(r.consts(a_arg, b_arg)?);
|
||||||
}
|
}
|
||||||
let related_args = tcx.mk_const_list(related_args.iter());
|
let related_args = tcx.intern_const_list(&related_args);
|
||||||
Expr::FunctionCall(func, related_args)
|
Expr::FunctionCall(func, related_args)
|
||||||
}
|
}
|
||||||
_ => return Err(TypeError::ConstMismatch(expected_found(r, a, b))),
|
_ => return Err(TypeError::ConstMismatch(expected_found(r, a, b))),
|
||||||
|
|
|
@ -418,7 +418,7 @@ impl<'tcx> ir::TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<ty::PolyExistential
|
||||||
|
|
||||||
impl<'tcx> ir::TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<ty::Const<'tcx>> {
|
impl<'tcx> ir::TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<ty::Const<'tcx>> {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||||
ty::util::fold_list(self, folder, |tcx, v| tcx.mk_const_list(v.iter()))
|
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_const_list(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -597,7 +597,7 @@ fn build_call_shim<'tcx>(
|
||||||
let untuple_args = sig.inputs();
|
let untuple_args = sig.inputs();
|
||||||
|
|
||||||
// Create substitutions for the `Self` and `Args` generic parameters of the shim body.
|
// Create substitutions for the `Self` and `Args` generic parameters of the shim body.
|
||||||
let arg_tup = tcx.mk_tup(untuple_args.iter());
|
let arg_tup = tcx.intern_tup(untuple_args);
|
||||||
|
|
||||||
(Some([ty.into(), arg_tup.into()]), Some(untuple_args))
|
(Some([ty.into(), arg_tup.into()]), Some(untuple_args))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -813,21 +813,18 @@ fn transform_substs<'tcx>(
|
||||||
substs: SubstsRef<'tcx>,
|
substs: SubstsRef<'tcx>,
|
||||||
options: TransformTyOptions,
|
options: TransformTyOptions,
|
||||||
) -> SubstsRef<'tcx> {
|
) -> SubstsRef<'tcx> {
|
||||||
let substs: Vec<GenericArg<'tcx>> = substs
|
let substs = substs.iter().map(|subst| {
|
||||||
.iter()
|
if let GenericArgKind::Type(ty) = subst.unpack() {
|
||||||
.map(|subst| {
|
if is_c_void_ty(tcx, ty) {
|
||||||
if let GenericArgKind::Type(ty) = subst.unpack() {
|
tcx.mk_unit().into()
|
||||||
if is_c_void_ty(tcx, ty) {
|
|
||||||
tcx.mk_unit().into()
|
|
||||||
} else {
|
|
||||||
transform_ty(tcx, ty, options).into()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
subst
|
transform_ty(tcx, ty, options).into()
|
||||||
}
|
}
|
||||||
})
|
} else {
|
||||||
.collect();
|
subst
|
||||||
tcx.mk_substs(substs.iter())
|
}
|
||||||
|
});
|
||||||
|
tcx.mk_substs(substs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a type metadata identifier for the specified FnAbi using the Itanium C++ ABI with vendor
|
/// Returns a type metadata identifier for the specified FnAbi using the Itanium C++ ABI with vendor
|
||||||
|
|
|
@ -191,10 +191,10 @@ pub(crate) fn extract_tupled_inputs_and_output_from_callable<'tcx>(
|
||||||
ty::FnDef(def_id, substs) => Ok(Some(
|
ty::FnDef(def_id, substs) => Ok(Some(
|
||||||
tcx.fn_sig(def_id)
|
tcx.fn_sig(def_id)
|
||||||
.subst(tcx, substs)
|
.subst(tcx, substs)
|
||||||
.map_bound(|sig| (tcx.mk_tup(sig.inputs().iter()), sig.output())),
|
.map_bound(|sig| (tcx.intern_tup(sig.inputs()), sig.output())),
|
||||||
)),
|
)),
|
||||||
ty::FnPtr(sig) => {
|
ty::FnPtr(sig) => {
|
||||||
Ok(Some(sig.map_bound(|sig| (tcx.mk_tup(sig.inputs().iter()), sig.output()))))
|
Ok(Some(sig.map_bound(|sig| (tcx.intern_tup(sig.inputs()), sig.output()))))
|
||||||
}
|
}
|
||||||
ty::Closure(_, substs) => {
|
ty::Closure(_, substs) => {
|
||||||
let closure_substs = substs.as_closure();
|
let closure_substs = substs.as_closure();
|
||||||
|
|
|
@ -1923,7 +1923,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
||||||
) -> Progress<'tcx> {
|
) -> Progress<'tcx> {
|
||||||
let tcx = selcx.tcx();
|
let tcx = selcx.tcx();
|
||||||
let self_ty = obligation.predicate.self_ty();
|
let self_ty = obligation.predicate.self_ty();
|
||||||
let substs = tcx.mk_substs([self_ty.into()].iter());
|
let substs = tcx.intern_substs(&[self_ty.into()]);
|
||||||
let lang_items = tcx.lang_items();
|
let lang_items = tcx.lang_items();
|
||||||
let item_def_id = obligation.predicate.def_id;
|
let item_def_id = obligation.predicate.def_id;
|
||||||
let trait_def_id = tcx.trait_of_item(item_def_id).unwrap();
|
let trait_def_id = tcx.trait_of_item(item_def_id).unwrap();
|
||||||
|
|
|
@ -144,7 +144,7 @@ fn recurse_build<'tcx>(
|
||||||
for &id in args.iter() {
|
for &id in args.iter() {
|
||||||
new_args.push(recurse_build(tcx, body, id, root_span)?);
|
new_args.push(recurse_build(tcx, body, id, root_span)?);
|
||||||
}
|
}
|
||||||
let new_args = tcx.mk_const_list(new_args.iter());
|
let new_args = tcx.intern_const_list(&new_args);
|
||||||
tcx.mk_const(Expr::FunctionCall(fun, new_args), node.ty)
|
tcx.mk_const(Expr::FunctionCall(fun, new_args), node.ty)
|
||||||
}
|
}
|
||||||
&ExprKind::Binary { op, lhs, rhs } if check_binop(op) => {
|
&ExprKind::Binary { op, lhs, rhs } if check_binop(op) => {
|
||||||
|
|
|
@ -173,7 +173,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) -
|
||||||
&& let Some(iter_item) = cx.tcx
|
&& let Some(iter_item) = cx.tcx
|
||||||
.associated_items(iter_trait)
|
.associated_items(iter_trait)
|
||||||
.find_by_name_and_kind(cx.tcx, Ident::with_dummy_span(Symbol::intern("Item")), AssocKind::Type, iter_trait)
|
.find_by_name_and_kind(cx.tcx, Ident::with_dummy_span(Symbol::intern("Item")), AssocKind::Type, iter_trait)
|
||||||
&& let substs = cx.tcx.mk_substs([GenericArg::from(typeck.expr_ty_adjusted(iter_expr))].into_iter())
|
&& let substs = cx.tcx.intern_substs(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))])
|
||||||
&& let proj_ty = cx.tcx.mk_projection(iter_item.def_id, substs)
|
&& let proj_ty = cx.tcx.mk_projection(iter_item.def_id, substs)
|
||||||
&& let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty)
|
&& let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue