Skip to content

Commit 8e2ed71

Browse files
committed
Auto merge of #146328 - zetanumbers:fix-141951, r=lcnr
Skip typeck for items w/o their own typeck context Skip items which forward typeck to their ancestor. Should remove some potential but unnecessary typeck query waits, hence might improve performance for the parallel frontend. Thanks to `@ywxt` for a fix suggestion Fixes #141951
2 parents 2a9bacf + 7e826fb commit 8e2ed71

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

compiler/rustc_hir/src/def.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,43 @@ impl DefKind {
440440
| DefKind::ExternCrate => false,
441441
}
442442
}
443+
444+
/// Returns `true` if `self` is a kind of definition that does not have its own
445+
/// type-checking context, i.e. closure, coroutine or inline const.
446+
#[inline]
447+
pub fn is_typeck_child(self) -> bool {
448+
match self {
449+
DefKind::Closure | DefKind::InlineConst | DefKind::SyntheticCoroutineBody => true,
450+
DefKind::Mod
451+
| DefKind::Struct
452+
| DefKind::Union
453+
| DefKind::Enum
454+
| DefKind::Variant
455+
| DefKind::Trait
456+
| DefKind::TyAlias
457+
| DefKind::ForeignTy
458+
| DefKind::TraitAlias
459+
| DefKind::AssocTy
460+
| DefKind::TyParam
461+
| DefKind::Fn
462+
| DefKind::Const
463+
| DefKind::ConstParam
464+
| DefKind::Static { .. }
465+
| DefKind::Ctor(_, _)
466+
| DefKind::AssocFn
467+
| DefKind::AssocConst
468+
| DefKind::Macro(_)
469+
| DefKind::ExternCrate
470+
| DefKind::Use
471+
| DefKind::ForeignMod
472+
| DefKind::AnonConst
473+
| DefKind::OpaqueTy
474+
| DefKind::Field
475+
| DefKind::LifetimeParam
476+
| DefKind::GlobalAsm
477+
| DefKind::Impl { .. } => false,
478+
}
479+
}
443480
}
444481

445482
/// The resolution of a path or export.

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
238238
_ => (),
239239
}
240240
// Skip `AnonConst`s because we feed their `type_of`.
241-
if !matches!(def_kind, DefKind::AnonConst) {
241+
// Also skip items for which typeck forwards to parent typeck.
242+
if !(matches!(def_kind, DefKind::AnonConst) || def_kind.is_typeck_child()) {
242243
tcx.ensure_ok().typeck(item_def_id);
243244
}
244245
// Ensure we generate the new `DefId` before finishing `check_crate`.

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,7 @@ impl<'tcx> TyCtxt<'tcx> {
608608
/// Returns `true` if `def_id` refers to a definition that does not have its own
609609
/// type-checking context, i.e. closure, coroutine or inline const.
610610
pub fn is_typeck_child(self, def_id: DefId) -> bool {
611-
matches!(
612-
self.def_kind(def_id),
613-
DefKind::Closure | DefKind::InlineConst | DefKind::SyntheticCoroutineBody
614-
)
611+
self.def_kind(def_id).is_typeck_child()
615612
}
616613

617614
/// Returns `true` if `def_id` refers to a trait (i.e., `trait Foo { ... }`).

0 commit comments

Comments
 (0)