1
Fork 0

Auto merge of #136471 - safinaskar:parallel, r=SparrowLii

tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`

tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`

This is continuation of https://github.com/rust-lang/rust/pull/132282 .

I'm pretty sure I did everything right. In particular, I searched all occurrences of `Lrc` in submodules and made sure that they don't need replacement.

There are other possibilities, through.

We can define `enum Lrc<T> { Rc(Rc<T>), Arc(Arc<T>) }`. Or we can make `Lrc` a union and on every clone we can read from special thread-local variable. Or we can add a generic parameter to `Lrc` and, yes, this parameter will be everywhere across all codebase.

So, if you think we should take some alternative approach, then don't merge this PR. But if it is decided to stick with `Arc`, then, please, merge.

cc "Parallel Rustc Front-end" ( https://github.com/rust-lang/rust/issues/113349 )

r? SparrowLii

`@rustbot` label WG-compiler-parallel
This commit is contained in:
bors 2025-02-06 10:50:05 +00:00
commit 2f92f050e8
77 changed files with 405 additions and 395 deletions

View file

@ -2,6 +2,7 @@
use std::iter::TrustedLen;
use std::path::Path;
use std::sync::Arc;
use std::{io, iter, mem};
pub(super) use cstore_impl::provide;
@ -11,7 +12,7 @@ use rustc_data_structures::captures::Captures;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::owned_slice::OwnedSlice;
use rustc_data_structures::sync::{Lock, Lrc, OnceLock};
use rustc_data_structures::sync::{Lock, OnceLock};
use rustc_data_structures::unhash::UnhashMap;
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, DeriveProcMacro};
@ -117,7 +118,7 @@ pub(crate) struct CrateMetadata {
/// How to link (or not link) this crate to the currently compiled crate.
dep_kind: CrateDepKind,
/// Filesystem location of this crate.
source: Lrc<CrateSource>,
source: Arc<CrateSource>,
/// Whether or not this crate should be consider a private dependency.
/// Used by the 'exported_private_dependencies' lint, and for determining
/// whether to emit suggestions that reference this crate.
@ -149,7 +150,7 @@ struct ImportedSourceFile {
/// The end of this SourceFile within the source_map of its original crate
original_end_pos: rustc_span::BytePos,
/// The imported SourceFile's representation within the local source_map
translated_source_file: Lrc<rustc_span::SourceFile>,
translated_source_file: Arc<rustc_span::SourceFile>,
}
pub(super) struct DecodeContext<'a, 'tcx> {
@ -1866,7 +1867,7 @@ impl CrateMetadata {
cnum_map,
dependencies,
dep_kind,
source: Lrc::new(source),
source: Arc::new(source),
private_dep,
host_hash,
used: false,

View file

@ -1,8 +1,8 @@
use std::any::Any;
use std::mem;
use std::sync::Arc;
use rustc_attr_parsing::Deprecation;
use rustc_data_structures::sync::Lrc;
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
@ -409,7 +409,7 @@ provide! { tcx, def_id, other, cdata,
matches!(cdata.extern_crate, Some(extern_crate) if !extern_crate.is_direct())
}
used_crate_source => { Lrc::clone(&cdata.source) }
used_crate_source => { Arc::clone(&cdata.source) }
debugger_visualizers => { cdata.get_debugger_visualizers() }
exported_symbols => {
@ -548,7 +548,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
visible_parent_map
},
dependency_formats: |tcx, ()| Lrc::new(crate::dependency_format::calculate(tcx)),
dependency_formats: |tcx, ()| Arc::new(crate::dependency_format::calculate(tcx)),
has_global_allocator: |tcx, LocalCrate| CStore::from_tcx(tcx).has_global_allocator(),
has_alloc_error_handler: |tcx, LocalCrate| CStore::from_tcx(tcx).has_alloc_error_handler(),
postorder_cnums: |tcx, ()| {

View file

@ -3,11 +3,12 @@ use std::collections::hash_map::Entry;
use std::fs::File;
use std::io::{Read, Seek, Write};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use rustc_ast::attr::AttributeExt;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::memmap::{Mmap, MmapMut};
use rustc_data_structures::sync::{Lrc, join, par_for_each_in};
use rustc_data_structures::sync::{join, par_for_each_in};
use rustc_data_structures::temp_dir::MaybeTempDir;
use rustc_data_structures::thousands::format_with_underscores;
use rustc_feature::Features;
@ -52,7 +53,7 @@ pub(super) struct EncodeContext<'a, 'tcx> {
// This is used to speed up Span encoding.
// The `usize` is an index into the `MonotonicVec`
// that stores the `SourceFile`
source_file_cache: (Lrc<SourceFile>, usize),
source_file_cache: (Arc<SourceFile>, usize),
// The indices (into the `SourceMap`'s `MonotonicVec`)
// of all of the `SourceFiles` that we need to serialize.
// When we serialize a `Span`, we insert the index of its
@ -278,7 +279,7 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for SpanData {
let source_map = s.tcx.sess.source_map();
let source_file_index = source_map.lookup_source_file_idx(self.lo);
s.source_file_cache =
(Lrc::clone(&source_map.files()[source_file_index]), source_file_index);
(Arc::clone(&source_map.files()[source_file_index]), source_file_index);
}
let (ref source_file, source_file_index) = s.source_file_cache;
debug_assert!(source_file.contains(self.lo));
@ -2306,7 +2307,7 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path) {
encoder.emit_raw_bytes(&0u64.to_le_bytes());
let source_map_files = tcx.sess.source_map().files();
let source_file_cache = (Lrc::clone(&source_map_files[0]), 0);
let source_file_cache = (Arc::clone(&source_map_files[0]), 0);
let required_source_files = Some(FxIndexSet::default());
drop(source_map_files);