Skip to content

Commit 40a8662

Browse files
committed
fix incremental build regressions
1 parent 56db0a0 commit 40a8662

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

compiler/rustc_middle/src/query/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,6 +2698,11 @@ rustc_queries! {
26982698
cache_on_disk_if { true }
26992699
}
27002700

2701+
query has_normalization_error_in_mono(key: ty::Instance<'tcx>) -> bool {
2702+
desc { "checking whether {}'s body has post-analysis normalization error", key }
2703+
cache_on_disk_if { true }
2704+
}
2705+
27012706
query size_estimate(key: ty::Instance<'tcx>) -> usize {
27022707
desc { "estimating codegen size of `{}`", key }
27032708
cache_on_disk_if { true }

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -473,22 +473,12 @@ fn collect_items_rec<'tcx>(
473473
recursion_limit,
474474
));
475475

476-
// Check whether the MIR body is malformed. Usually it's due to normalization overflow.
477-
// FIXME: I assume that there are few type errors at post-analysis stage, but not
478-
// entirely sure.
479476
// Plenty of code paths later assume that everything can be normalized.
480477
// Check normalization here to provide better diagnostics.
481-
let body = tcx.instance_mir(instance.def);
482-
let normalization_failed = body.local_decls.iter().any(|local| {
483-
instance
484-
.try_instantiate_mir_and_normalize_erasing_regions(
485-
tcx,
486-
ty::TypingEnv::fully_monomorphized(),
487-
ty::EarlyBinder::bind(local.ty),
488-
)
489-
.is_err()
490-
});
491-
if normalization_failed {
478+
// Normalization errors here are usually due to trait solving overflow.
479+
// FIXME: I assume that there are few type errors at post-analysis stage, but not
480+
// entirely sure.
481+
if tcx.has_normalization_error_in_mono(instance) {
492482
let def_id = instance.def_id();
493483
let def_span = tcx.def_span(def_id);
494484
let def_path_str = tcx.def_path_str(def_id);
@@ -630,6 +620,21 @@ fn collect_items_rec<'tcx>(
630620
}
631621
}
632622

623+
// Check whether we can normalize the MIR body. Make it a query since decoding MIR from disk cache
624+
// may be expensive.
625+
fn has_normalization_error_in_mono<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool {
626+
let body = tcx.instance_mir(instance.def);
627+
body.local_decls.iter().any(|local| {
628+
instance
629+
.try_instantiate_mir_and_normalize_erasing_regions(
630+
tcx,
631+
ty::TypingEnv::fully_monomorphized(),
632+
ty::EarlyBinder::bind(local.ty),
633+
)
634+
.is_err()
635+
})
636+
}
637+
633638
fn check_recursion_limit<'tcx>(
634639
tcx: TyCtxt<'tcx>,
635640
instance: Instance<'tcx>,
@@ -1784,4 +1789,5 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
17841789
pub(crate) fn provide(providers: &mut Providers) {
17851790
providers.hooks.should_codegen_locally = should_codegen_locally;
17861791
providers.items_of_instance = items_of_instance;
1792+
providers.has_normalization_error_in_mono = has_normalization_error_in_mono;
17871793
}

0 commit comments

Comments
 (0)