Skip to content

Commit 86f73a0

Browse files
committed
Auto merge of rust-lang#14017 - lowr:patch/remove-type-walk, r=Veykril
internal: remove `TypeWalk` Because less code is better! `hir_ty::TypeWalk` is only used in analysis-stats and its usage can be replaced by checking `TypeFlags` (which is precomputed upon `TyKind` interning so it should make analysis-stats a bit faster, though it was really negligible in my local environment). We should just use chalk's `TypeVisitor` or `TypeFolder` instead even if we come to need it again.
2 parents e46c242 + e9f14c5 commit 86f73a0

File tree

4 files changed

+8
-159
lines changed

4 files changed

+8
-159
lines changed

crates/hir-ty/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mod lower;
2020
mod mapping;
2121
mod tls;
2222
mod utils;
23-
mod walk;
2423
pub mod db;
2524
pub mod diagnostics;
2625
pub mod display;
@@ -71,7 +70,6 @@ pub use mapping::{
7170
};
7271
pub use traits::TraitEnvironment;
7372
pub use utils::{all_super_traits, is_fn_unsafe_to_call};
74-
pub use walk::TypeWalk;
7573

7674
pub use chalk_ir::{
7775
cast::Cast, AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind,
@@ -107,6 +105,7 @@ pub type GenericArgData = chalk_ir::GenericArgData<Interner>;
107105

108106
pub type Ty = chalk_ir::Ty<Interner>;
109107
pub type TyKind = chalk_ir::TyKind<Interner>;
108+
pub type TypeFlags = chalk_ir::TypeFlags;
110109
pub type DynTy = chalk_ir::DynTy<Interner>;
111110
pub type FnPointer = chalk_ir::FnPointer<Interner>;
112111
// pub type FnSubst = chalk_ir::FnSubst<Interner>;

crates/hir-ty/src/walk.rs

-147
This file was deleted.

crates/hir/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3168,6 +3168,8 @@ impl Type {
31683168
}
31693169

31703170
pub fn contains_unknown(&self) -> bool {
3171+
// FIXME: When we get rid of `ConstScalar::Unknown`, we can just look at precomputed
3172+
// `TypeFlags` in `TyData`.
31713173
return go(&self.ty);
31723174

31733175
fn go(ty: &Ty) -> bool {
@@ -3482,10 +3484,9 @@ impl Type {
34823484
Type { env: self.env.clone(), ty }
34833485
}
34843486

3487+
/// Visits every type, including generic arguments, in this type. `cb` is called with type
3488+
/// itself first, and then with its generic arguments.
34853489
pub fn walk(&self, db: &dyn HirDatabase, mut cb: impl FnMut(Type)) {
3486-
// TypeWalk::walk for a Ty at first visits parameters and only after that the Ty itself.
3487-
// We need a different order here.
3488-
34893490
fn walk_substs(
34903491
db: &dyn HirDatabase,
34913492
type_: &Type,

crates/rust-analyzer/src/cli/analysis_stats.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use hir_def::{
1515
expr::ExprId,
1616
FunctionId,
1717
};
18-
use hir_ty::{TyExt, TypeWalk};
18+
use hir_ty::{Interner, TyExt, TypeFlags};
1919
use ide::{Analysis, AnalysisHost, LineCol, RootDatabase};
2020
use ide_db::base_db::{
2121
salsa::{self, debug::DebugQueryTable, ParallelDatabase},
@@ -280,12 +280,8 @@ impl flags::AnalysisStats {
280280
}
281281
true
282282
} else {
283-
let mut is_partially_unknown = false;
284-
ty.walk(&mut |ty| {
285-
if ty.is_unknown() {
286-
is_partially_unknown = true;
287-
}
288-
});
283+
let is_partially_unknown =
284+
ty.data(Interner).flags.contains(TypeFlags::HAS_ERROR);
289285
if is_partially_unknown {
290286
num_exprs_partially_unknown += 1;
291287
}

0 commit comments

Comments
 (0)