Unnamed repository; edit this file 'description' to name the repository.
Use slices for `Interner::FnInputTys` and `Interner::GenericArgsSlice`, not `Tys` and `GenericArgs` respectively
This allows us to avoid interning them.
| -rw-r--r-- | crates/hir-ty/src/display.rs | 4 | ||||
| -rw-r--r-- | crates/hir-ty/src/dyn_compatibility.rs | 14 | ||||
| -rw-r--r-- | crates/hir-ty/src/infer/closure.rs | 29 | ||||
| -rw-r--r-- | crates/hir-ty/src/infer/expr.rs | 2 | ||||
| -rw-r--r-- | crates/hir-ty/src/method_resolution/confirm.rs | 2 | ||||
| -rw-r--r-- | crates/hir-ty/src/method_resolution/probe.rs | 2 | ||||
| -rw-r--r-- | crates/hir-ty/src/mir/eval.rs | 2 | ||||
| -rw-r--r-- | crates/hir-ty/src/mir/lower.rs | 4 | ||||
| -rw-r--r-- | crates/hir-ty/src/next_solver/generic_arg.rs | 15 | ||||
| -rw-r--r-- | crates/hir-ty/src/next_solver/interner.rs | 7 | ||||
| -rw-r--r-- | crates/hir-ty/src/next_solver/ty.rs | 5 | ||||
| -rw-r--r-- | crates/hir/src/lib.rs | 6 |
12 files changed, 39 insertions, 53 deletions
diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs index 8e44c14abe..b9e23464e9 100644 --- a/crates/hir-ty/src/display.rs +++ b/crates/hir-ty/src/display.rs @@ -1459,7 +1459,7 @@ impl<'db> HirDisplay<'db> for Ty<'db> { }; let coroutine_sig = coroutine_sig.skip_binder(); let coroutine_inputs = coroutine_sig.inputs(); - let TyKind::Tuple(coroutine_inputs) = coroutine_inputs.as_slice()[1].kind() else { + let TyKind::Tuple(coroutine_inputs) = coroutine_inputs[1].kind() else { unreachable!("invalid coroutine closure signature"); }; let TyKind::Tuple(coroutine_output) = coroutine_sig.output().kind() else { @@ -1942,7 +1942,7 @@ fn write_bounds_like_dyn_trait<'db>( let own_args = projection.projection_term.own_args(f.interner); if !own_args.is_empty() { write!(f, "<")?; - hir_fmt_generic_arguments(f, own_args.as_slice(), None)?; + hir_fmt_generic_arguments(f, own_args, None)?; write!(f, ">")?; } write!(f, " = ")?; diff --git a/crates/hir-ty/src/dyn_compatibility.rs b/crates/hir-ty/src/dyn_compatibility.rs index ffdc9ca0f8..59cfd3fdc9 100644 --- a/crates/hir-ty/src/dyn_compatibility.rs +++ b/crates/hir-ty/src/dyn_compatibility.rs @@ -328,13 +328,9 @@ where } let sig = db.callable_item_signature(func.into()); - if sig - .skip_binder() - .inputs() - .iter() - .skip(1) - .any(|ty| contains_illegal_self_type_reference(db, trait_, &ty, AllowSelfProjection::Yes)) - { + if sig.skip_binder().inputs().iter().skip(1).any(|ty| { + contains_illegal_self_type_reference(db, trait_, ty.skip_binder(), AllowSelfProjection::Yes) + }) { cb(MethodViolationCode::ReferencesSelfInput)?; } @@ -411,11 +407,11 @@ fn receiver_is_dispatchable<'db>( // `self: Self` can't be dispatched on, but this is already considered dyn-compatible // See rustc's comment on https://github.com/rust-lang/rust/blob/3f121b9461cce02a703a0e7e450568849dfaa074/compiler/rustc_trait_selection/src/traits/object_safety.rs#L433-L437 - if sig.inputs().iter().next().is_some_and(|p| p.skip_binder() == self_param_ty) { + if sig.inputs().iter().next().is_some_and(|p| *p.skip_binder() == self_param_ty) { return true; } - let Some(&receiver_ty) = sig.inputs().skip_binder().as_slice().first() else { + let Some(&receiver_ty) = sig.inputs().skip_binder().first() else { return false; }; diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs index 14b0c9076c..82912017c3 100644 --- a/crates/hir-ty/src/infer/closure.rs +++ b/crates/hir-ty/src/infer/closure.rs @@ -13,7 +13,7 @@ use rustc_type_ir::{ ClosureArgs, ClosureArgsParts, CoroutineArgs, CoroutineArgsParts, CoroutineClosureArgs, CoroutineClosureArgsParts, Interner, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, - inherent::{BoundExistentialPredicates, GenericArgs as _, IntoKind, SliceLike, Ty as _}, + inherent::{BoundExistentialPredicates, GenericArgs as _, IntoKind, Ty as _}, }; use tracing::debug; @@ -77,11 +77,11 @@ impl<'db> InferenceContext<'_, 'db> { let (id, ty, resume_yield_tys) = match closure_kind { ClosureKind::Coroutine(_) => { let yield_ty = self.table.next_ty_var(); - let resume_ty = liberated_sig.inputs().get(0).unwrap_or(self.types.unit); + let resume_ty = liberated_sig.inputs().first().copied().unwrap_or(self.types.unit); // FIXME: Infer the upvars later. let parts = CoroutineArgsParts { - parent_args, + parent_args: parent_args.as_slice(), kind_ty: self.types.unit, resume_ty, yield_ty, @@ -119,7 +119,7 @@ impl<'db> InferenceContext<'_, 'db> { }; // FIXME: Infer the kind later if needed. let parts = ClosureArgsParts { - parent_args, + parent_args: parent_args.as_slice(), closure_kind_ty: Ty::from_closure_kind( interner, expected_kind.unwrap_or(rustc_type_ir::ClosureKind::Fn), @@ -165,16 +165,13 @@ impl<'db> InferenceContext<'_, 'db> { let closure_args = CoroutineClosureArgs::new( interner, CoroutineClosureArgsParts { - parent_args, + parent_args: parent_args.as_slice(), closure_kind_ty, signature_parts_ty: Ty::new_fn_ptr( interner, bound_sig.map_bound(|sig| { interner.mk_fn_sig( - [ - resume_ty, - Ty::new_tup_from_iter(interner, sig.inputs().iter()), - ], + [resume_ty, Ty::new_tup(interner, sig.inputs())], Ty::new_tup(interner, &[bound_yield_ty, bound_return_ty]), sig.c_variadic, sig.safety, @@ -195,7 +192,7 @@ impl<'db> InferenceContext<'_, 'db> { // Now go through the argument patterns for (arg_pat, arg_ty) in args.iter().zip(bound_sig.skip_binder().inputs()) { - self.infer_top_pat(*arg_pat, arg_ty, None); + self.infer_top_pat(*arg_pat, *arg_ty, None); } // FIXME: lift these out into a struct @@ -668,7 +665,7 @@ impl<'db> InferenceContext<'_, 'db> { assert!(!expected_sig.skip_binder().has_vars_bound_above(rustc_type_ir::INNERMOST)); let bound_sig = expected_sig.map_bound(|sig| { self.interner().mk_fn_sig( - sig.inputs(), + sig.inputs().iter().copied(), sig.output(), sig.c_variadic, Safety::Safe, @@ -744,9 +741,10 @@ impl<'db> InferenceContext<'_, 'db> { // The liberated version of this signature should be a subtype // of the liberated form of the expectation. - for (supplied_ty, expected_ty) in - iter::zip(supplied_sig.inputs(), expected_sigs.liberated_sig.inputs()) - { + for (supplied_ty, expected_ty) in iter::zip( + supplied_sig.inputs().iter().copied(), + expected_sigs.liberated_sig.inputs().iter().copied(), + ) { // Check that E' = S'. let cause = ObligationCause::new(); let InferOk { value: (), obligations } = @@ -765,7 +763,8 @@ impl<'db> InferenceContext<'_, 'db> { let inputs = supplied_sig .inputs() - .into_iter() + .iter() + .copied() .map(|ty| table.infer_ctxt.resolve_vars_if_possible(ty)); expected_sigs.liberated_sig = table.interner().mk_fn_sig( diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs index 5eeaeef9d9..4d3ca94b22 100644 --- a/crates/hir-ty/src/infer/expr.rs +++ b/crates/hir-ty/src/infer/expr.rs @@ -1219,7 +1219,7 @@ impl<'db> InferenceContext<'_, 'db> { CoroutineArgs::new( self.interner(), CoroutineArgsParts { - parent_args, + parent_args: parent_args.as_slice(), kind_ty: self.types.unit, // rustc uses a special lang item type for the resume ty. I don't believe this can cause us problems. resume_ty: self.types.unit, diff --git a/crates/hir-ty/src/method_resolution/confirm.rs b/crates/hir-ty/src/method_resolution/confirm.rs index 9292928f99..0024ca16a5 100644 --- a/crates/hir-ty/src/method_resolution/confirm.rs +++ b/crates/hir-ty/src/method_resolution/confirm.rs @@ -145,7 +145,7 @@ impl<'a, 'b, 'db> ConfirmContext<'a, 'b, 'db> { // traits, no trait system method can be called before this point because they // could alter our Self-type, except for normalizing the receiver from the // signature (which is also done during probing). - let method_sig_rcvr = method_sig.inputs().as_slice()[0]; + let method_sig_rcvr = method_sig.inputs()[0]; debug!( "confirm: self_ty={:?} method_sig_rcvr={:?} method_sig={:?}", self_ty, method_sig_rcvr, method_sig diff --git a/crates/hir-ty/src/method_resolution/probe.rs b/crates/hir-ty/src/method_resolution/probe.rs index cdffcd9383..cb9b810686 100644 --- a/crates/hir-ty/src/method_resolution/probe.rs +++ b/crates/hir-ty/src/method_resolution/probe.rs @@ -1977,7 +1977,7 @@ impl<'a, 'db, Choice: ProbeChoice<'db>> ProbeContext<'a, 'db, Choice> { && self.mode == Mode::MethodCall { let sig = self.xform_method_sig(item, args); - (sig.inputs().as_slice()[0], Some(sig.output())) + (sig.inputs()[0], Some(sig.output())) } else { (impl_ty, None) } diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs index b78e610b49..c7156bb11e 100644 --- a/crates/hir-ty/src/mir/eval.rs +++ b/crates/hir-ty/src/mir/eval.rs @@ -2771,7 +2771,7 @@ impl<'db> Evaluator<'db> { TyKind::Closure(closure, subst) => self.exec_closure( closure.0, func_data, - subst.split_closure_args_untupled().parent_args, + GenericArgs::new_from_slice(subst.split_closure_args_untupled().parent_args), destination, &args[1..], locals, diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs index ef2a13848c..ca198aa71b 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -2147,7 +2147,7 @@ pub fn mir_body_for_closure_query<'db>( }; let resolver_guard = ctx.resolver.update_to_inner_scope(db, owner, expr); let current = ctx.lower_params_and_bindings( - args.iter().zip(sig.skip_binder().inputs().iter()).map(|(it, y)| (*it, y)), + args.iter().zip(sig.skip_binder().inputs().iter()).map(|(it, y)| (*it, *y)), None, |_| true, )?; @@ -2289,7 +2289,7 @@ pub fn lower_to_mir<'db>( if let DefWithBodyId::FunctionId(fid) = owner { let callable_sig = db.callable_item_signature(fid.into()).instantiate_identity().skip_binder(); - let mut params = callable_sig.inputs().iter(); + let mut params = callable_sig.inputs().iter().copied(); let self_param = body.self_param.and_then(|id| Some((id, params.next()?))); break 'b ctx.lower_params_and_bindings( body.params.iter().zip(params).map(|(it, y)| (*it, y)), diff --git a/crates/hir-ty/src/next_solver/generic_arg.rs b/crates/hir-ty/src/next_solver/generic_arg.rs index b600f6000d..785d3ef652 100644 --- a/crates/hir-ty/src/next_solver/generic_arg.rs +++ b/crates/hir-ty/src/next_solver/generic_arg.rs @@ -574,9 +574,8 @@ impl<'db> GenericArgs<'db> { // FIXME: should use `ClosureSubst` when possible match self.as_slice() { [parent_args @ .., closure_kind_ty, sig_ty, tupled_upvars_ty] => { - let interner = DbInterner::conjure(); rustc_type_ir::ClosureArgsParts { - parent_args: GenericArgs::new_from_iter(interner, parent_args.iter().cloned()), + parent_args, closure_sig_as_fn_ptr_ty: sig_ty.expect_ty(), closure_kind_ty: closure_kind_ty.expect_ty(), tupled_upvars_ty: tupled_upvars_ty.expect_ty(), @@ -690,7 +689,7 @@ impl<'db> rustc_type_ir::inherent::GenericArgs<DbInterner<'db>> for GenericArgs< interner, TyKind::FnPtr( sig_tys.map_bound(|s| { - let inputs = Ty::new_tup_from_iter(interner, s.inputs().iter()); + let inputs = Ty::new_tup(interner, s.inputs()); let output = s.output(); FnSigTys { inputs_and_output: Tys::new_from_iter( @@ -705,7 +704,7 @@ impl<'db> rustc_type_ir::inherent::GenericArgs<DbInterner<'db>> for GenericArgs< _ => unreachable!("sig_ty should be last"), }; rustc_type_ir::ClosureArgsParts { - parent_args: GenericArgs::new_from_iter(interner, parent_args.iter().cloned()), + parent_args, closure_sig_as_fn_ptr_ty: sig_ty, closure_kind_ty: closure_kind_ty.expect_ty(), tupled_upvars_ty: tupled_upvars_ty.expect_ty(), @@ -728,10 +727,7 @@ impl<'db> rustc_type_ir::inherent::GenericArgs<DbInterner<'db>> for GenericArgs< tupled_upvars_ty, coroutine_captures_by_ref_ty, ] => rustc_type_ir::CoroutineClosureArgsParts { - parent_args: GenericArgs::new_from_iter( - DbInterner::conjure(), - parent_args.iter().cloned(), - ), + parent_args, closure_kind_ty: closure_kind_ty.expect_ty(), signature_parts_ty: signature_parts_ty.expect_ty(), tupled_upvars_ty: tupled_upvars_ty.expect_ty(), @@ -742,11 +738,10 @@ impl<'db> rustc_type_ir::inherent::GenericArgs<DbInterner<'db>> for GenericArgs< } fn split_coroutine_args(self) -> rustc_type_ir::CoroutineArgsParts<DbInterner<'db>> { - let interner = DbInterner::conjure(); match self.as_slice() { [parent_args @ .., kind_ty, resume_ty, yield_ty, return_ty, tupled_upvars_ty] => { rustc_type_ir::CoroutineArgsParts { - parent_args: GenericArgs::new_from_iter(interner, parent_args.iter().cloned()), + parent_args, kind_ty: kind_ty.expect_ty(), resume_ty: resume_ty.expect_ty(), yield_ty: yield_ty.expect_ty(), diff --git a/crates/hir-ty/src/next_solver/interner.rs b/crates/hir-ty/src/next_solver/interner.rs index 6b97d110ee..0102c2ef6e 100644 --- a/crates/hir-ty/src/next_solver/interner.rs +++ b/crates/hir-ty/src/next_solver/interner.rs @@ -1012,7 +1012,7 @@ impl<'db> Interner for DbInterner<'db> { type Span = Span; type GenericArgs = GenericArgs<'db>; - type GenericArgsSlice = GenericArgs<'db>; + type GenericArgsSlice = &'db [GenericArg<'db>]; type GenericArg = GenericArg<'db>; type Term = Term<'db>; @@ -1053,7 +1053,7 @@ impl<'db> Interner for DbInterner<'db> { type Ty = Ty<'db>; type Tys = Tys<'db>; - type FnInputTys = Tys<'db>; + type FnInputTys = &'db [Ty<'db>]; type ParamTy = ParamTy; type BoundTy = BoundTy; type PlaceholderTy = PlaceholderTy; @@ -1261,8 +1261,7 @@ impl<'db> Interner for DbInterner<'db> { self, args.as_slice()[0..trait_generics.own_params.len()].iter().cloned(), ); - let alias_args = - GenericArgs::new_from_iter(self, args.iter().skip(trait_generics.own_params.len())); + let alias_args = &args.as_slice()[trait_generics.own_params.len()..]; (TraitRef::new_from_args(self, trait_def_id.try_into().unwrap(), trait_args), alias_args) } diff --git a/crates/hir-ty/src/next_solver/ty.rs b/crates/hir-ty/src/next_solver/ty.rs index 85534e42a8..87cba7aca8 100644 --- a/crates/hir-ty/src/next_solver/ty.rs +++ b/crates/hir-ty/src/next_solver/ty.rs @@ -1280,10 +1280,7 @@ impl<'db> Tys<'db> { impl<'db> rustc_type_ir::inherent::Tys<DbInterner<'db>> for Tys<'db> { fn inputs(self) -> <DbInterner<'db> as Interner>::FnInputTys { - Tys::new_from_iter( - DbInterner::conjure(), - self.as_slice().split_last().unwrap().1.iter().copied(), - ) + self.as_slice().split_last().unwrap().1 } fn output(self) -> <DbInterner<'db> as Interner>::Ty { diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 933dd6af1d..883f1aa26e 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -2290,7 +2290,7 @@ impl Function { .inputs() .iter() .enumerate() - .map(|(idx, ty)| { + .map(|(idx, &ty)| { let ty = Type { env: environment, ty }; Param { func: Callee::Def(CallableDefId::FunctionId(self.id)), ty, idx } }) @@ -2317,7 +2317,7 @@ impl Function { .iter() .enumerate() .skip(skip) - .map(|(idx, ty)| { + .map(|(idx, &ty)| { let ty = Type { env: environment, ty }; Param { func: Callee::Def(CallableDefId::FunctionId(self.id)), ty, idx } }) @@ -2341,7 +2341,7 @@ impl Function { .iter() .enumerate() .skip(skip) - .map(|(idx, ty)| { + .map(|(idx, &ty)| { let ty = Type { env: environment, ty }; Param { func: Callee::Def(CallableDefId::FunctionId(self.id)), ty, idx } }) |