Skip to content

Commit 765b7bd

Browse files
Merge pull request #21307 from ChayimFriedman2/more-perf-work
perf: More perf improvements, made possible after non-Salsa interneds
2 parents fa4ea90 + 3ab0420 commit 765b7bd

34 files changed

+644
-441
lines changed

crates/hir-ty/src/display.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ impl<'db> HirDisplay<'db> for Ty<'db> {
14591459
};
14601460
let coroutine_sig = coroutine_sig.skip_binder();
14611461
let coroutine_inputs = coroutine_sig.inputs();
1462-
let TyKind::Tuple(coroutine_inputs) = coroutine_inputs.as_slice()[1].kind() else {
1462+
let TyKind::Tuple(coroutine_inputs) = coroutine_inputs[1].kind() else {
14631463
unreachable!("invalid coroutine closure signature");
14641464
};
14651465
let TyKind::Tuple(coroutine_output) = coroutine_sig.output().kind() else {
@@ -1942,7 +1942,7 @@ fn write_bounds_like_dyn_trait<'db>(
19421942
let own_args = projection.projection_term.own_args(f.interner);
19431943
if !own_args.is_empty() {
19441944
write!(f, "<")?;
1945-
hir_fmt_generic_arguments(f, own_args.as_slice(), None)?;
1945+
hir_fmt_generic_arguments(f, own_args, None)?;
19461946
write!(f, ">")?;
19471947
}
19481948
write!(f, " = ")?;

crates/hir-ty/src/dyn_compatibility.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,9 @@ where
328328
}
329329

330330
let sig = db.callable_item_signature(func.into());
331-
if sig
332-
.skip_binder()
333-
.inputs()
334-
.iter()
335-
.skip(1)
336-
.any(|ty| contains_illegal_self_type_reference(db, trait_, &ty, AllowSelfProjection::Yes))
337-
{
331+
if sig.skip_binder().inputs().iter().skip(1).any(|ty| {
332+
contains_illegal_self_type_reference(db, trait_, ty.skip_binder(), AllowSelfProjection::Yes)
333+
}) {
338334
cb(MethodViolationCode::ReferencesSelfInput)?;
339335
}
340336

@@ -411,11 +407,11 @@ fn receiver_is_dispatchable<'db>(
411407

412408
// `self: Self` can't be dispatched on, but this is already considered dyn-compatible
413409
// See rustc's comment on https://github.com/rust-lang/rust/blob/3f121b9461cce02a703a0e7e450568849dfaa074/compiler/rustc_trait_selection/src/traits/object_safety.rs#L433-L437
414-
if sig.inputs().iter().next().is_some_and(|p| p.skip_binder() == self_param_ty) {
410+
if sig.inputs().iter().next().is_some_and(|p| *p.skip_binder() == self_param_ty) {
415411
return true;
416412
}
417413

418-
let Some(&receiver_ty) = sig.inputs().skip_binder().as_slice().first() else {
414+
let Some(&receiver_ty) = sig.inputs().skip_binder().first() else {
419415
return false;
420416
};
421417

crates/hir-ty/src/infer.rs

Lines changed: 22 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use rustc_ast_ir::Mutability;
5151
use rustc_hash::{FxHashMap, FxHashSet};
5252
use rustc_type_ir::{
5353
AliasTyKind, TypeFoldable,
54-
inherent::{AdtDef, IntoKind, Region as _, Ty as _},
54+
inherent::{AdtDef, IntoKind, Ty as _},
5555
};
5656
use span::Edition;
5757
use stdx::never;
@@ -108,23 +108,23 @@ fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> InferenceResult {
108108
DefWithBodyId::VariantId(v) => {
109109
ctx.return_ty = match EnumSignature::variant_body_type(db, v.lookup(db).parent) {
110110
hir_def::layout::IntegerType::Pointer(signed) => match signed {
111-
true => ctx.types.isize,
112-
false => ctx.types.usize,
111+
true => ctx.types.types.isize,
112+
false => ctx.types.types.usize,
113113
},
114114
hir_def::layout::IntegerType::Fixed(size, signed) => match signed {
115115
true => match size {
116-
Integer::I8 => ctx.types.i8,
117-
Integer::I16 => ctx.types.i16,
118-
Integer::I32 => ctx.types.i32,
119-
Integer::I64 => ctx.types.i64,
120-
Integer::I128 => ctx.types.i128,
116+
Integer::I8 => ctx.types.types.i8,
117+
Integer::I16 => ctx.types.types.i16,
118+
Integer::I32 => ctx.types.types.i32,
119+
Integer::I64 => ctx.types.types.i64,
120+
Integer::I128 => ctx.types.types.i128,
121121
},
122122
false => match size {
123-
Integer::I8 => ctx.types.u8,
124-
Integer::I16 => ctx.types.u16,
125-
Integer::I32 => ctx.types.u32,
126-
Integer::I64 => ctx.types.u64,
127-
Integer::I128 => ctx.types.u128,
123+
Integer::I8 => ctx.types.types.u8,
124+
Integer::I16 => ctx.types.types.u16,
125+
Integer::I32 => ctx.types.types.u32,
126+
Integer::I64 => ctx.types.types.u64,
127+
Integer::I128 => ctx.types.types.u128,
128128
},
129129
},
130130
};
@@ -738,75 +738,6 @@ impl InferenceResult {
738738
}
739739
}
740740

741-
#[derive(Debug, Clone)]
742-
struct InternedStandardTypes<'db> {
743-
unit: Ty<'db>,
744-
never: Ty<'db>,
745-
char: Ty<'db>,
746-
bool: Ty<'db>,
747-
i8: Ty<'db>,
748-
i16: Ty<'db>,
749-
i32: Ty<'db>,
750-
i64: Ty<'db>,
751-
i128: Ty<'db>,
752-
isize: Ty<'db>,
753-
u8: Ty<'db>,
754-
u16: Ty<'db>,
755-
u32: Ty<'db>,
756-
u64: Ty<'db>,
757-
u128: Ty<'db>,
758-
usize: Ty<'db>,
759-
f16: Ty<'db>,
760-
f32: Ty<'db>,
761-
f64: Ty<'db>,
762-
f128: Ty<'db>,
763-
static_str_ref: Ty<'db>,
764-
error: Ty<'db>,
765-
766-
re_static: Region<'db>,
767-
re_error: Region<'db>,
768-
re_erased: Region<'db>,
769-
770-
empty_args: GenericArgs<'db>,
771-
}
772-
773-
impl<'db> InternedStandardTypes<'db> {
774-
fn new(interner: DbInterner<'db>) -> Self {
775-
let str = Ty::new(interner, rustc_type_ir::TyKind::Str);
776-
let re_static = Region::new_static(interner);
777-
Self {
778-
unit: Ty::new_unit(interner),
779-
never: Ty::new(interner, TyKind::Never),
780-
char: Ty::new(interner, TyKind::Char),
781-
bool: Ty::new(interner, TyKind::Bool),
782-
i8: Ty::new_int(interner, rustc_type_ir::IntTy::I8),
783-
i16: Ty::new_int(interner, rustc_type_ir::IntTy::I16),
784-
i32: Ty::new_int(interner, rustc_type_ir::IntTy::I32),
785-
i64: Ty::new_int(interner, rustc_type_ir::IntTy::I64),
786-
i128: Ty::new_int(interner, rustc_type_ir::IntTy::I128),
787-
isize: Ty::new_int(interner, rustc_type_ir::IntTy::Isize),
788-
u8: Ty::new_uint(interner, rustc_type_ir::UintTy::U8),
789-
u16: Ty::new_uint(interner, rustc_type_ir::UintTy::U16),
790-
u32: Ty::new_uint(interner, rustc_type_ir::UintTy::U32),
791-
u64: Ty::new_uint(interner, rustc_type_ir::UintTy::U64),
792-
u128: Ty::new_uint(interner, rustc_type_ir::UintTy::U128),
793-
usize: Ty::new_uint(interner, rustc_type_ir::UintTy::Usize),
794-
f16: Ty::new_float(interner, rustc_type_ir::FloatTy::F16),
795-
f32: Ty::new_float(interner, rustc_type_ir::FloatTy::F32),
796-
f64: Ty::new_float(interner, rustc_type_ir::FloatTy::F64),
797-
f128: Ty::new_float(interner, rustc_type_ir::FloatTy::F128),
798-
static_str_ref: Ty::new_ref(interner, re_static, str, Mutability::Not),
799-
error: Ty::new_error(interner, ErrorGuaranteed),
800-
801-
re_static,
802-
re_error: Region::error(interner),
803-
re_erased: Region::new_erased(interner),
804-
805-
empty_args: GenericArgs::empty(interner),
806-
}
807-
}
808-
}
809-
810741
/// The inference context contains all information needed during type inference.
811742
#[derive(Clone, Debug)]
812743
pub(crate) struct InferenceContext<'body, 'db> {
@@ -841,7 +772,7 @@ pub(crate) struct InferenceContext<'body, 'db> {
841772
resume_yield_tys: Option<(Ty<'db>, Ty<'db>)>,
842773
diverges: Diverges,
843774
breakables: Vec<BreakableContext<'db>>,
844-
types: InternedStandardTypes<'db>,
775+
types: &'db crate::next_solver::DefaultAny<'db>,
845776

846777
/// Whether we are inside the pattern of a destructuring assignment.
847778
inside_assignment: bool,
@@ -918,10 +849,10 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
918849
) -> Self {
919850
let trait_env = db.trait_environment_for_body(owner);
920851
let table = unify::InferenceTable::new(db, trait_env, resolver.krate(), Some(owner));
921-
let types = InternedStandardTypes::new(table.interner());
852+
let types = crate::next_solver::default_types(db);
922853
InferenceContext {
923-
result: InferenceResult::new(types.error),
924-
return_ty: types.error, // set in collect_* calls
854+
result: InferenceResult::new(types.types.error),
855+
return_ty: types.types.error, // set in collect_* calls
925856
types,
926857
target_features: OnceCell::new(),
927858
unstable_features: MethodResolutionUnstableFeatures::from_def_map(
@@ -1153,7 +1084,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
11531084
data.type_ref,
11541085
&data.store,
11551086
InferenceTyDiagnosticSource::Signature,
1156-
LifetimeElisionKind::Elided(self.types.re_static),
1087+
LifetimeElisionKind::Elided(self.types.regions.statik),
11571088
);
11581089

11591090
self.return_ty = return_ty;
@@ -1211,7 +1142,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
12111142
);
12121143
self.process_user_written_ty(return_ty)
12131144
}
1214-
None => self.types.unit,
1145+
None => self.types.types.unit,
12151146
};
12161147

12171148
self.return_coercion = Some(CoerceMany::new(self.return_ty));
@@ -1408,7 +1339,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
14081339
}
14091340

14101341
fn err_ty(&self) -> Ty<'db> {
1411-
self.types.error
1342+
self.types.types.error
14121343
}
14131344

14141345
pub(crate) fn make_body_lifetime(&mut self, lifetime_ref: LifetimeRefId) -> Region<'db> {
@@ -1573,7 +1504,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
15731504
if let Err(_err) = result {
15741505
// FIXME: Emit diagnostic.
15751506
}
1576-
result.unwrap_or(self.types.error)
1507+
result.unwrap_or(self.types.types.error)
15771508
}
15781509

15791510
fn expr_ty(&self, expr: ExprId) -> Ty<'db> {
@@ -1805,7 +1736,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
18051736
result
18061737
} else {
18071738
// FIXME diagnostic
1808-
(ctx.types.error, None)
1739+
(ctx.types.types.error, None)
18091740
}
18101741
}
18111742
}

crates/hir-ty/src/infer/closure.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_type_ir::{
1313
ClosureArgs, ClosureArgsParts, CoroutineArgs, CoroutineArgsParts, CoroutineClosureArgs,
1414
CoroutineClosureArgsParts, Interner, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
1515
TypeVisitor,
16-
inherent::{BoundExistentialPredicates, GenericArgs as _, IntoKind, SliceLike, Ty as _},
16+
inherent::{BoundExistentialPredicates, GenericArgs as _, IntoKind, Ty as _},
1717
};
1818
use tracing::debug;
1919

@@ -22,9 +22,8 @@ use crate::{
2222
db::{InternedClosure, InternedCoroutine},
2323
infer::{BreakableKind, Diverges, coerce::CoerceMany},
2424
next_solver::{
25-
AliasTy, Binder, BoundRegionKind, BoundVarKind, BoundVarKinds, ClauseKind, DbInterner,
26-
ErrorGuaranteed, FnSig, GenericArgs, PolyFnSig, PolyProjectionPredicate, Predicate,
27-
PredicateKind, SolverDefId, Ty, TyKind,
25+
AliasTy, Binder, ClauseKind, DbInterner, ErrorGuaranteed, FnSig, GenericArgs, PolyFnSig,
26+
PolyProjectionPredicate, Predicate, PredicateKind, SolverDefId, Ty, TyKind,
2827
abi::Safety,
2928
infer::{
3029
BoundRegionConversionTime, InferOk, InferResult,
@@ -73,16 +72,17 @@ impl<'db> InferenceContext<'_, 'db> {
7372

7473
let parent_args = GenericArgs::identity_for_item(interner, self.generic_def.into());
7574
// FIXME: Make this an infer var and infer it later.
76-
let tupled_upvars_ty = self.types.unit;
75+
let tupled_upvars_ty = self.types.types.unit;
7776
let (id, ty, resume_yield_tys) = match closure_kind {
7877
ClosureKind::Coroutine(_) => {
7978
let yield_ty = self.table.next_ty_var();
80-
let resume_ty = liberated_sig.inputs().get(0).unwrap_or(self.types.unit);
79+
let resume_ty =
80+
liberated_sig.inputs().first().copied().unwrap_or(self.types.types.unit);
8181

8282
// FIXME: Infer the upvars later.
8383
let parts = CoroutineArgsParts {
84-
parent_args,
85-
kind_ty: self.types.unit,
84+
parent_args: parent_args.as_slice(),
85+
kind_ty: self.types.types.unit,
8686
resume_ty,
8787
yield_ty,
8888
return_ty: body_ret_ty,
@@ -119,7 +119,7 @@ impl<'db> InferenceContext<'_, 'db> {
119119
};
120120
// FIXME: Infer the kind later if needed.
121121
let parts = ClosureArgsParts {
122-
parent_args,
122+
parent_args: parent_args.as_slice(),
123123
closure_kind_ty: Ty::from_closure_kind(
124124
interner,
125125
expected_kind.unwrap_or(rustc_type_ir::ClosureKind::Fn),
@@ -140,9 +140,9 @@ impl<'db> InferenceContext<'_, 'db> {
140140
// async closures always return the type ascribed after the `->` (if present),
141141
// and yield `()`.
142142
let bound_return_ty = bound_sig.skip_binder().output();
143-
let bound_yield_ty = self.types.unit;
143+
let bound_yield_ty = self.types.types.unit;
144144
// rustc uses a special lang item type for the resume ty. I don't believe this can cause us problems.
145-
let resume_ty = self.types.unit;
145+
let resume_ty = self.types.types.unit;
146146

147147
// FIXME: Infer the kind later if needed.
148148
let closure_kind_ty = Ty::from_closure_kind(
@@ -155,26 +155,26 @@ impl<'db> InferenceContext<'_, 'db> {
155155
let coroutine_captures_by_ref_ty = Ty::new_fn_ptr(
156156
interner,
157157
Binder::bind_with_vars(
158-
interner.mk_fn_sig([], self.types.unit, false, Safety::Safe, FnAbi::Rust),
159-
BoundVarKinds::new_from_iter(
160-
interner,
161-
[BoundVarKind::Region(BoundRegionKind::ClosureEnv)],
158+
interner.mk_fn_sig(
159+
[],
160+
self.types.types.unit,
161+
false,
162+
Safety::Safe,
163+
FnAbi::Rust,
162164
),
165+
self.types.coroutine_captures_by_ref_bound_var_kinds,
163166
),
164167
);
165168
let closure_args = CoroutineClosureArgs::new(
166169
interner,
167170
CoroutineClosureArgsParts {
168-
parent_args,
171+
parent_args: parent_args.as_slice(),
169172
closure_kind_ty,
170173
signature_parts_ty: Ty::new_fn_ptr(
171174
interner,
172175
bound_sig.map_bound(|sig| {
173176
interner.mk_fn_sig(
174-
[
175-
resume_ty,
176-
Ty::new_tup_from_iter(interner, sig.inputs().iter()),
177-
],
177+
[resume_ty, Ty::new_tup(interner, sig.inputs())],
178178
Ty::new_tup(interner, &[bound_yield_ty, bound_return_ty]),
179179
sig.c_variadic,
180180
sig.safety,
@@ -195,7 +195,7 @@ impl<'db> InferenceContext<'_, 'db> {
195195

196196
// Now go through the argument patterns
197197
for (arg_pat, arg_ty) in args.iter().zip(bound_sig.skip_binder().inputs()) {
198-
self.infer_top_pat(*arg_pat, arg_ty, None);
198+
self.infer_top_pat(*arg_pat, *arg_ty, None);
199199
}
200200

201201
// FIXME: lift these out into a struct
@@ -668,7 +668,7 @@ impl<'db> InferenceContext<'_, 'db> {
668668
assert!(!expected_sig.skip_binder().has_vars_bound_above(rustc_type_ir::INNERMOST));
669669
let bound_sig = expected_sig.map_bound(|sig| {
670670
self.interner().mk_fn_sig(
671-
sig.inputs(),
671+
sig.inputs().iter().copied(),
672672
sig.output(),
673673
sig.c_variadic,
674674
Safety::Safe,
@@ -744,9 +744,10 @@ impl<'db> InferenceContext<'_, 'db> {
744744

745745
// The liberated version of this signature should be a subtype
746746
// of the liberated form of the expectation.
747-
for (supplied_ty, expected_ty) in
748-
iter::zip(supplied_sig.inputs(), expected_sigs.liberated_sig.inputs())
749-
{
747+
for (supplied_ty, expected_ty) in iter::zip(
748+
supplied_sig.inputs().iter().copied(),
749+
expected_sigs.liberated_sig.inputs().iter().copied(),
750+
) {
750751
// Check that E' = S'.
751752
let cause = ObligationCause::new();
752753
let InferOk { value: (), obligations } =
@@ -765,7 +766,8 @@ impl<'db> InferenceContext<'_, 'db> {
765766

766767
let inputs = supplied_sig
767768
.inputs()
768-
.into_iter()
769+
.iter()
770+
.copied()
769771
.map(|ty| table.infer_ctxt.resolve_vars_if_possible(ty));
770772

771773
expected_sigs.liberated_sig = table.interner().mk_fn_sig(

crates/hir-ty/src/infer/closure/analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl CapturedItemWithoutTy {
289289
BorrowKind::Mut { .. } => Mutability::Mut,
290290
_ => Mutability::Not,
291291
};
292-
Ty::new_ref(ctx.interner(), ctx.types.re_error, ty, m)
292+
Ty::new_ref(ctx.interner(), ctx.types.regions.error, ty, m)
293293
}
294294
};
295295
CapturedItem {

0 commit comments

Comments
 (0)