From 8ae77a2a55a0e4354701a37a147187256dd3f19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sat, 2 Mar 2024 18:56:28 +0100 Subject: [PATCH] Revert "Change prefetch to avoid deadlock" This reverts commit 887076855212f14f35900ada1979761e458c4920. --- compiler/rustc_metadata/src/rmeta/encoder.rs | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index fdb2b4f202415..25eb16d4a3d0b 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -665,7 +665,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let debugger_visualizers = stat!("debugger-visualizers", || self.encode_debugger_visualizers()); - // Encode exported symbols info. This is prefetched in `encode_metadata`. + // Encode exported symbols info. This is prefetched in `encode_metadata` so we encode + // this as late as possible to give the prefetching as much time as possible to complete. let exported_symbols = stat!("exported-symbols", || { self.encode_exported_symbols(tcx.exported_symbols(LOCAL_CRATE)) }); @@ -2203,13 +2204,21 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path) { // there's no need to do dep-graph tracking for any of it. tcx.dep_graph.assert_ignored(); - if tcx.sess.threads() != 1 { - // Prefetch some queries used by metadata encoding. - // This is not necessary for correctness, but is only done for performance reasons. - // It can be removed if it turns out to cause trouble or be detrimental to performance. - join(|| prefetch_mir(tcx), || tcx.exported_symbols(LOCAL_CRATE)); - } + join( + || encode_metadata_impl(tcx, path), + || { + if tcx.sess.threads() == 1 { + return; + } + // Prefetch some queries used by metadata encoding. + // This is not necessary for correctness, but is only done for performance reasons. + // It can be removed if it turns out to cause trouble or be detrimental to performance. + join(|| prefetch_mir(tcx), || tcx.exported_symbols(LOCAL_CRATE)); + }, + ); +} +fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) { let mut encoder = opaque::FileEncoder::new(path) .unwrap_or_else(|err| tcx.dcx().emit_fatal(FailCreateFileEncoder { err })); encoder.emit_raw_bytes(METADATA_HEADER);