diff options
| author | bors <bors@rust-lang.org> | 2024-03-14 02:54:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-14 02:54:10 +0000 |
| commit | 5ac0b2d0219de2fd6fef86c69ef0cfa1e6c36f3b (patch) | |
| tree | 093ee4994478e32a433204b49a338b5b289de445 /compiler | |
| parent | c7fed9f85422696f67fcf76abc846827fd4dde72 (diff) | |
| parent | 96d24f2dd13e8e9d0c6f9912781ffe1fc79864d3 (diff) | |
| download | rust-5ac0b2d0219de2fd6fef86c69ef0cfa1e6c36f3b.tar.gz rust-5ac0b2d0219de2fd6fef86c69ef0cfa1e6c36f3b.zip | |
Auto merge of #122347 - oli-obk:track_errors13, r=compiler-errors
Revert "Auto merge of #122140 - oli-obk:track_errors13, r=davidtwco" This reverts commit 65cd843ae06ad00123c131a431ed5304e4cd577a, reversing changes made to d255c6a57c393db6221b1ff700daea478436f1cd. reverts https://github.com/rust-lang/rust/pull/122140 It was a large regression in wall time due to trashing CPU caches
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_driver_impl/src/pretty.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/lib.rs | 30 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/outlives/test.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/variance/test.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/passes.rs | 33 |
6 files changed, 61 insertions, 37 deletions
diff --git a/compiler/rustc_driver_impl/src/pretty.rs b/compiler/rustc_driver_impl/src/pretty.rs index c0c6201f73d..c9bbe45b212 100644 --- a/compiler/rustc_driver_impl/src/pretty.rs +++ b/compiler/rustc_driver_impl/src/pretty.rs @@ -336,8 +336,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { ThirTree => { let tcx = ex.tcx(); let mut out = String::new(); - rustc_hir_analysis::check_crate(tcx); - if tcx.dcx().has_errors().is_some() { + if rustc_hir_analysis::check_crate(tcx).is_err() { FatalError.raise(); } debug!("pretty printing THIR tree"); @@ -349,8 +348,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { ThirFlat => { let tcx = ex.tcx(); let mut out = String::new(); - rustc_hir_analysis::check_crate(tcx); - if tcx.dcx().has_errors().is_some() { + if rustc_hir_analysis::check_crate(tcx).is_err() { FatalError.raise(); } debug!("pretty printing THIR flat"); diff --git a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs index d370efc9d0e..dcb01a117b0 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs @@ -5,20 +5,22 @@ use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{self as hir, def, Expr, ImplItem, Item, Node, TraitItem}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt}; -use rustc_span::{sym, DUMMY_SP}; +use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP}; use crate::errors::{TaitForwardCompat, TypeOf, UnconstrainedOpaqueType}; -pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) { +pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { + let mut res = Ok(()); if tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) { for id in tcx.hir().items() { if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) { let type_of = tcx.type_of(id.owner_id).instantiate_identity(); - tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of }); + res = Err(tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of })); } } } + res } /// Checks "defining uses" of opaque `impl Trait` in associated types. diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index b1b36ade508..8cf70fe46aa 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -98,6 +98,7 @@ mod outlives; pub mod structured_errors; mod variance; +use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_middle::middle; use rustc_middle::query::Providers; @@ -155,13 +156,11 @@ pub fn provide(providers: &mut Providers) { hir_wf_check::provide(providers); } -pub fn check_crate(tcx: TyCtxt<'_>) { +pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { let _prof_timer = tcx.sess.timer("type_check_crate"); if tcx.features().rustc_attrs { - tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx)); - tcx.sess.time("variance_testing", || variance::test::test_variance(tcx)); - collect::test_opaque_hidden_types(tcx); + tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx))?; } tcx.sess.time("coherence_checking", || { @@ -177,6 +176,14 @@ pub fn check_crate(tcx: TyCtxt<'_>) { let _ = tcx.ensure().crate_inherent_impls_overlap_check(()); }); + if tcx.features().rustc_attrs { + tcx.sess.time("variance_testing", || variance::test::test_variance(tcx))?; + } + + if tcx.features().rustc_attrs { + collect::test_opaque_hidden_types(tcx)?; + } + // Make sure we evaluate all static and (non-associated) const items, even if unused. // If any of these fail to evaluate, we do not want this crate to pass compilation. tcx.hir().par_body_owners(|item_def_id| { @@ -191,6 +198,21 @@ pub fn check_crate(tcx: TyCtxt<'_>) { // Freeze definitions as we don't add new ones at this point. This improves performance by // allowing lock-free access to them. tcx.untracked().definitions.freeze(); + + // FIXME: Remove this when we implement creating `DefId`s + // for anon constants during their parents' typeck. + // Typeck all body owners in parallel will produce queries + // cycle errors because it may typeck on anon constants directly. + tcx.hir().par_body_owners(|item_def_id| { + let def_kind = tcx.def_kind(item_def_id); + if !matches!(def_kind, DefKind::AnonConst) { + tcx.ensure().typeck(item_def_id); + } + }); + + tcx.ensure().check_unused_traits(()); + + Ok(()) } /// A quasi-deprecated helper used in rustdoc and clippy to get diff --git a/compiler/rustc_hir_analysis/src/outlives/test.rs b/compiler/rustc_hir_analysis/src/outlives/test.rs index dea3f1a9930..60cd8c39fa0 100644 --- a/compiler/rustc_hir_analysis/src/outlives/test.rs +++ b/compiler/rustc_hir_analysis/src/outlives/test.rs @@ -1,7 +1,8 @@ use rustc_middle::ty::{self, TyCtxt}; -use rustc_span::symbol::sym; +use rustc_span::{symbol::sym, ErrorGuaranteed}; -pub fn test_inferred_outlives(tcx: TyCtxt<'_>) { +pub fn test_inferred_outlives(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { + let mut res = Ok(()); for id in tcx.hir().items() { // For unit testing: check for a special "rustc_outlives" // attribute and report an error with various results if found. @@ -22,7 +23,8 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) { for p in pred { err.note(p); } - err.emit(); + res = Err(err.emit()); } } + res } diff --git a/compiler/rustc_hir_analysis/src/variance/test.rs b/compiler/rustc_hir_analysis/src/variance/test.rs index 5264d5aa26f..c211e1af046 100644 --- a/compiler/rustc_hir_analysis/src/variance/test.rs +++ b/compiler/rustc_hir_analysis/src/variance/test.rs @@ -2,19 +2,21 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::CRATE_DEF_ID; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::sym; +use rustc_span::ErrorGuaranteed; use crate::errors; -pub fn test_variance(tcx: TyCtxt<'_>) { +pub fn test_variance(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { + let mut res = Ok(()); if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) { for id in tcx.hir().items() { if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) { let variances_of = tcx.variances_of(id.owner_id); - tcx.dcx().emit_err(errors::VariancesOf { + res = Err(tcx.dcx().emit_err(errors::VariancesOf { span: tcx.def_span(id.owner_id), variances_of: format!("{variances_of:?}"), - }); + })); } } } @@ -25,10 +27,11 @@ pub fn test_variance(tcx: TyCtxt<'_>) { if tcx.has_attr(id.owner_id, sym::rustc_variance) { let variances_of = tcx.variances_of(id.owner_id); - tcx.dcx().emit_err(errors::VariancesOf { + res = Err(tcx.dcx().emit_err(errors::VariancesOf { span: tcx.def_span(id.owner_id), variances_of: format!("{variances_of:?}"), - }); + })); } } + res } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 4cc9ffdbb2f..4b4c1d6cf67 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -734,22 +734,19 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> { }); // passes are timed inside typeck - rustc_hir_analysis::check_crate(tcx); + rustc_hir_analysis::check_crate(tcx)?; - sess.time("typeck_and_mir_analyses", || { + sess.time("MIR_borrow_checking", || { tcx.hir().par_body_owners(|def_id| { - let def_kind = tcx.def_kind(def_id); - // FIXME: Remove this when we implement creating `DefId`s - // for anon constants during their parents' typeck. - // Typeck all body owners in parallel will produce queries - // cycle errors because it may typeck on anon constants directly. - if !matches!(def_kind, rustc_hir::def::DefKind::AnonConst) { - tcx.ensure().typeck(def_id); - } // Run unsafety check because it's responsible for stealing and // deallocating THIR. tcx.ensure().check_unsafety(def_id); - tcx.ensure().mir_borrowck(def_id); + tcx.ensure().mir_borrowck(def_id) + }); + }); + + sess.time("MIR_effect_checking", || { + for def_id in tcx.hir().body_owners() { if !tcx.sess.opts.unstable_opts.thir_unsafeck { rustc_mir_transform::check_unsafety::check_unsafety(tcx, def_id); } @@ -764,15 +761,15 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> { tcx.ensure().mir_drops_elaborated_and_const_checked(def_id); tcx.ensure().unused_generic_params(ty::InstanceDef::Item(def_id.to_def_id())); } - - if tcx.is_coroutine(def_id.to_def_id()) { - tcx.ensure().mir_coroutine_witnesses(def_id); - tcx.ensure().check_coroutine_obligations(def_id); - } - }) + } }); - tcx.ensure().check_unused_traits(()); + tcx.hir().par_body_owners(|def_id| { + if tcx.is_coroutine(def_id.to_def_id()) { + tcx.ensure().mir_coroutine_witnesses(def_id); + tcx.ensure().check_coroutine_obligations(def_id); + } + }); sess.time("layout_testing", || layout_test::test_layout(tcx)); sess.time("abi_testing", || abi_test::test_abi(tcx)); |
