Skip to content

Commit 2805aed

Browse files
committed
Auto merge of rust-lang#123631 - oli-obk:fail_slow, r=jieyouxu
Ensure we do not accidentally insert new early aborts in the analysis passes pulling the infallible part out into a separate function makes sure that someone needs to change the signature in order to regress this. We only want to stop compilation in the presence of errors after all analyses are done, but before we start running lints. per-item we can still stop doing work if previous queries returned errors, but that's a separate story.
2 parents bb78dba + 3b16ee2 commit 2805aed

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

compiler/rustc_driver_impl/src/pretty.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
336336
ThirTree => {
337337
let tcx = ex.tcx();
338338
let mut out = String::new();
339-
if rustc_hir_analysis::check_crate(tcx).is_err() {
339+
rustc_hir_analysis::check_crate(tcx);
340+
if tcx.dcx().has_errors().is_some() {
340341
FatalError.raise();
341342
}
342343
debug!("pretty printing THIR tree");
@@ -348,7 +349,8 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
348349
ThirFlat => {
349350
let tcx = ex.tcx();
350351
let mut out = String::new();
351-
if rustc_hir_analysis::check_crate(tcx).is_err() {
352+
rustc_hir_analysis::check_crate(tcx);
353+
if tcx.dcx().has_errors().is_some() {
352354
FatalError.raise();
353355
}
354356
debug!("pretty printing THIR flat");

compiler/rustc_hir_analysis/src/lib.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ mod outlives;
9797
pub mod structured_errors;
9898
mod variance;
9999

100-
use rustc_errors::ErrorGuaranteed;
101100
use rustc_hir as hir;
102101
use rustc_hir::def::DefKind;
103102
use rustc_middle::middle;
@@ -153,11 +152,11 @@ pub fn provide(providers: &mut Providers) {
153152
hir_wf_check::provide(providers);
154153
}
155154

156-
pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
155+
pub fn check_crate(tcx: TyCtxt<'_>) {
157156
let _prof_timer = tcx.sess.timer("type_check_crate");
158157

159158
if tcx.features().rustc_attrs {
160-
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx))?;
159+
let _ = tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx));
161160
}
162161

163162
tcx.sess.time("coherence_checking", || {
@@ -174,11 +173,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
174173
});
175174

176175
if tcx.features().rustc_attrs {
177-
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx))?;
176+
let _ = tcx.sess.time("variance_testing", || variance::test::test_variance(tcx));
178177
}
179178

180179
if tcx.features().rustc_attrs {
181-
collect::test_opaque_hidden_types(tcx)?;
180+
let _ = collect::test_opaque_hidden_types(tcx);
182181
}
183182

184183
// Make sure we evaluate all static and (non-associated) const items, even if unused.
@@ -213,8 +212,6 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
213212
});
214213

215214
tcx.ensure().check_unused_traits(());
216-
217-
Ok(())
218215
}
219216

220217
/// Lower a [`hir::Ty`] to a [`Ty`].

compiler/rustc_interface/src/passes.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -686,18 +686,15 @@ pub fn create_global_ctxt<'tcx>(
686686
})
687687
}
688688

689-
/// Runs the type-checking, region checking and other miscellaneous analysis
690-
/// passes on the crate.
691-
fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
689+
/// Runs all analyses that we guarantee to run, even if errors were reported in earlier analyses.
690+
/// This function never fails.
691+
fn run_required_analyses(tcx: TyCtxt<'_>) {
692692
if tcx.sess.opts.unstable_opts.hir_stats {
693693
rustc_passes::hir_stats::print_hir_stats(tcx);
694694
}
695-
696695
#[cfg(debug_assertions)]
697696
rustc_passes::hir_id_validator::check_crate(tcx);
698-
699697
let sess = tcx.sess;
700-
701698
sess.time("misc_checking_1", || {
702699
parallel!(
703700
{
@@ -733,10 +730,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
733730
}
734731
);
735732
});
736-
737-
// passes are timed inside typeck
738-
rustc_hir_analysis::check_crate(tcx)?;
739-
733+
rustc_hir_analysis::check_crate(tcx);
740734
sess.time("MIR_borrow_checking", || {
741735
tcx.hir().par_body_owners(|def_id| {
742736
// Run unsafety check because it's responsible for stealing and
@@ -745,7 +739,6 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
745739
tcx.ensure().mir_borrowck(def_id)
746740
});
747741
});
748-
749742
sess.time("MIR_effect_checking", || {
750743
for def_id in tcx.hir().body_owners() {
751744
tcx.ensure().has_ffi_unwind_calls(def_id);
@@ -761,16 +754,22 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
761754
}
762755
}
763756
});
764-
765757
tcx.hir().par_body_owners(|def_id| {
766758
if tcx.is_coroutine(def_id.to_def_id()) {
767759
tcx.ensure().mir_coroutine_witnesses(def_id);
768760
tcx.ensure().check_coroutine_obligations(def_id);
769761
}
770762
});
771-
772763
sess.time("layout_testing", || layout_test::test_layout(tcx));
773764
sess.time("abi_testing", || abi_test::test_abi(tcx));
765+
}
766+
767+
/// Runs the type-checking, region checking and other miscellaneous analysis
768+
/// passes on the crate.
769+
fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
770+
run_required_analyses(tcx);
771+
772+
let sess = tcx.sess;
774773

775774
// Avoid overwhelming user with errors if borrow checking failed.
776775
// I'm not sure how helpful this is, to be honest, but it avoids a

0 commit comments

Comments
 (0)