Skip to content

Swap Lru from std::sync::Arc to triomphe::Arc #131629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 46 additions & 23 deletions Cargo.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4

[[package]]
name = "addr2line"
Expand Down Expand Up @@ -3545,6 +3545,8 @@ dependencies = [
"tempfile",
"thin-vec",
"tracing",
"triomphe",
"unsize",
"windows",
]

Expand Down Expand Up @@ -3908,6 +3910,7 @@ dependencies = [
"rustc_traits",
"rustc_ty_utils",
"tracing",
"unsize",
]

[[package]]
Expand Down Expand Up @@ -4359,6 +4362,7 @@ dependencies = [
"smallvec",
"tempfile",
"thin-vec",
"triomphe",
]

[[package]]
Expand Down Expand Up @@ -5465,6 +5469,16 @@ dependencies = [
"tracing-subscriber",
]

[[package]]
name = "triomphe"
version = "0.1.14"
source = "git+https://github.com/GnomedDev/triomphe?branch=dropck-eyepatch#a9614f96c0eb04818cea5f98416b05ca34d9e383"
dependencies = [
"serde",
"stable_deref_trait",
"unsize",
]

[[package]]
name = "twox-hash"
version = "1.6.3"
Expand Down Expand Up @@ -5661,6 +5675,15 @@ dependencies = [
"diff",
]

[[package]]
name = "unsize"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fa7a7a734c1a5664a662ddcea0b6c9472a21da8888c957c7f1eaa09dba7a939"
dependencies = [
"autocfg",
]

[[package]]
name = "unstable-book-gen"
version = "0.1.0"
Expand Down Expand Up @@ -5813,7 +5836,7 @@ dependencies = [
"lexopt",
"tempfile",
"wasi-preview1-component-adapter-provider",
"wasmparser 0.219.0",
"wasmparser 0.219.1",
"wat",
"wit-component",
"wit-parser",
Expand All @@ -5837,28 +5860,28 @@ dependencies = [

[[package]]
name = "wasm-encoder"
version = "0.219.0"
version = "0.219.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2b1b95711b3ad655656a341e301cc64e33cbee94de9a99a1c5a2ab88efab79d"
checksum = "29cbbd772edcb8e7d524a82ee8cef8dd046fc14033796a754c3ad246d019fa54"
dependencies = [
"leb128",
"wasmparser 0.219.0",
"wasmparser 0.219.1",
]

[[package]]
name = "wasm-metadata"
version = "0.219.0"
version = "0.219.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96132fe00dd17d092d2be289eeed5a0a68ad3cf30b68e8875bc953b96f55f0be"
checksum = "2af5a8e37a5e996861e1813f8de30911c47609c9ff51a7284f7dbd754dc3a9f3"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder 0.219.0",
"wasmparser 0.219.0",
"wasm-encoder 0.219.1",
"wasmparser 0.219.1",
]

[[package]]
Expand All @@ -5873,9 +5896,9 @@ dependencies = [

[[package]]
name = "wasmparser"
version = "0.219.0"
version = "0.219.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "324b4e56d24439495b88cd81439dad5e97f3c7b1eedc3c7e10455ed1e045e9a2"
checksum = "5c771866898879073c53b565a6c7b49953795159836714ac56a5befb581227c5"
dependencies = [
"ahash",
"bitflags 2.6.0",
Expand All @@ -5887,22 +5910,22 @@ dependencies = [

[[package]]
name = "wast"
version = "219.0.0"
version = "219.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06880ecb25662bc21db6a83f4fcc27c41f71fbcba4f1980b650c88ada92728e1"
checksum = "4f79a9d9df79986a68689a6b40bcc8d5d40d807487b235bebc2ac69a242b54a1"
dependencies = [
"bumpalo",
"leb128",
"memchr",
"unicode-width",
"wasm-encoder 0.219.0",
"wasm-encoder 0.219.1",
]

[[package]]
name = "wat"
version = "1.219.0"
version = "1.219.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11e56dbf9fc89111b0d97c91e683d7895b1a6e5633a729f2ccad2303724005b6"
checksum = "8bc3cf014fb336883a411cd662f987abf6a1d2a27f2f0008616a0070bbf6bd0d"
dependencies = [
"wast",
]
Expand Down Expand Up @@ -6179,9 +6202,9 @@ dependencies = [

[[package]]
name = "wit-component"
version = "0.219.0"
version = "0.219.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99a76111c20444a814019de20499d30940ecd219b9512ee296f034a5edb18a2d"
checksum = "ad1673163c0cb14a6a19ddbf44dd4efe6f015ec1ebb8156710ac32501f19fba2"
dependencies = [
"anyhow",
"bitflags 2.6.0",
Expand All @@ -6190,17 +6213,17 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
"wasm-encoder 0.219.0",
"wasm-encoder 0.219.1",
"wasm-metadata",
"wasmparser 0.219.0",
"wasmparser 0.219.1",
"wit-parser",
]

[[package]]
name = "wit-parser"
version = "0.219.0"
version = "0.219.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23102e180c0c464f36e293d31a27b524e3ece930d7b5527d2f33f9d2c963de64"
checksum = "4a86f669283257e8e424b9a4fc3518e3ade0b95deb9fbc0f93a1876be3eda598"
dependencies = [
"anyhow",
"id-arena",
Expand All @@ -6211,7 +6234,7 @@ dependencies = [
"serde_derive",
"serde_json",
"unicode-xid",
"wasmparser 0.219.0",
"wasmparser 0.219.1",
]

[[package]]
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
current_item: None,
impl_trait_defs: Vec::new(),
impl_trait_bounds: Vec::new(),
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].as_slice().into(),
allow_gen_future: if tcx.features().async_fn_track_caller {
[sym::gen_future, sym::closure_track_caller].into()
[sym::gen_future, sym::closure_track_caller].as_slice().into()
} else {
[sym::gen_future].into()
[sym::gen_future].as_slice().into()
},
allow_for_await: [sym::async_iterator].into(),
allow_async_fn_traits: [sym::async_fn_traits].into(),
allow_for_await: [sym::async_iterator].as_slice().into(),
allow_async_fn_traits: [sym::async_fn_traits].as_slice().into(),
// FIXME(gen_blocks): how does `closure_track_caller`/`async_fn_track_caller`
// interact with `gen`/`async gen` blocks
allow_async_iterator: [sym::gen_future, sym::async_iterator].into(),
allow_async_iterator: [sym::gen_future, sym::async_iterator].as_slice().into(),
generics_def_id_map: Default::default(),
host_param_id: None,
ast_index,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/src/global_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use std::io::Write;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::sync::Arc;

use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_data_structures::sync::Lrc;
use rustc_hir::{InlineAsmOperand, ItemId};
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_session::config::{OutputFilenames, OutputType};
Expand Down Expand Up @@ -110,7 +110,7 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
pub(crate) struct GlobalAsmConfig {
assembler: PathBuf,
target: String,
pub(crate) output_filenames: Arc<OutputFilenames>,
pub(crate) output_filenames: Lrc<OutputFilenames>,
}

impl GlobalAsmConfig {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use cranelift_codegen::settings::{self, Configurable};
use rustc_codegen_ssa::CodegenResults;
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sync::Lrc;
use rustc_errors::ErrorGuaranteed;
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
Expand Down Expand Up @@ -125,7 +126,7 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
/// inside a single codegen unit with the exception of the Cranelift [`Module`](cranelift_module::Module).
struct CodegenCx {
profiler: SelfProfilerRef,
output_filenames: Arc<OutputFilenames>,
output_filenames: Lrc<OutputFilenames>,
should_write_ir: bool,
global_asm: String,
inline_asm_index: Cell<usize>,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use super::symbol_export::symbol_name_for_instance_in_crate;
use crate::errors::ErrorCreatingRemarkDir;
use crate::traits::*;
use crate::{
CachedModuleCodegen, CodegenResults, CompiledModule, CrateInfo, ModuleCodegen, ModuleKind,
CachedModuleCodegen, CodegenResults, CompiledModule, CrateInfo, Lrc, ModuleCodegen, ModuleKind,
errors,
};

Expand Down Expand Up @@ -349,7 +349,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
pub opts: Arc<config::Options>,
pub crate_types: Vec<CrateType>,
pub each_linked_rlib_for_lto: Vec<(CrateNum, PathBuf)>,
pub output_filenames: Arc<OutputFilenames>,
pub output_filenames: Lrc<OutputFilenames>,
pub regular_module_config: Arc<ModuleConfig>,
pub metadata_module_config: Arc<ModuleConfig>,
pub allocator_module_config: Arc<ModuleConfig>,
Expand Down Expand Up @@ -2037,7 +2037,7 @@ pub struct OngoingCodegen<B: ExtraBackendMethods> {
pub crate_info: CrateInfo,
pub codegen_worker_receive: Receiver<CguMessage>,
pub shared_emitter_main: SharedEmitterMain,
pub output_filenames: Arc<OutputFilenames>,
pub output_filenames: Lrc<OutputFilenames>,
pub coordinator: Coordinator<B>,
}

Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ stacker = "0.1.17"
tempfile = "3.2"
thin-vec = "0.2.12"
tracing = "0.1"
unsize = { version = "1.1", optional = true }
# tidy-alphabetical-end

[dependencies.parking_lot]
version = "0.12"

[dependencies.triomphe]
version = "0.1"
optional = true
features = ["unsize", "unstable_dropck_eyepatch"]
git = "https://github.com/GnomedDev/triomphe"
branch = "dropck-eyepatch"

[target.'cfg(windows)'.dependencies.windows]
version = "0.57.0"
features = [
Expand All @@ -56,5 +64,5 @@ portable-atomic = "1.5.1"

[features]
# tidy-alphabetical-start
rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "dep:rustc-rayon"]
rustc_use_parallel_compiler = ["indexmap/rustc-rayon", "dep:rustc-rayon", "dep:triomphe", "dep:unsize"]
# tidy-alphabetical-end
4 changes: 2 additions & 2 deletions compiler/rustc_data_structures/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ cfg_match! {
[*mut T where T: ?Sized]
[std::ptr::NonNull<T> where T: ?Sized]
[std::rc::Rc<T> where T: ?Sized]
[std::rc::Weak<T> where T: ?Sized]
[std::sync::MutexGuard<'_, T> where T: ?Sized]
[std::sync::RwLockReadGuard<'_, T> where T: ?Sized]
[std::sync::RwLockWriteGuard<'_, T> where T: ?Sized]
Expand Down Expand Up @@ -92,6 +91,7 @@ cfg_match! {
[Box<T, A> where T: ?Sized + DynSend, A: std::alloc::Allocator + DynSend]
[crate::sync::RwLock<T> where T: DynSend]
[crate::tagged_ptr::CopyTaggedPtr<P, T, CP> where P: Send + crate::tagged_ptr::Pointer, T: Send + crate::tagged_ptr::Tag, const CP: bool]
[triomphe::Arc<T> where T: ?Sized + DynSync + DynSend]
[rustc_arena::TypedArena<T> where T: DynSend]
[indexmap::IndexSet<V, S> where V: DynSend, S: DynSend]
[indexmap::IndexMap<K, V, S> where K: DynSend, V: DynSend, S: DynSend]
Expand All @@ -116,7 +116,6 @@ cfg_match! {
[std::cell::UnsafeCell<T> where T: ?Sized]
[std::ptr::NonNull<T> where T: ?Sized]
[std::rc::Rc<T> where T: ?Sized]
[std::rc::Weak<T> where T: ?Sized]
[std::cell::OnceCell<T> where T]
[std::sync::mpsc::Receiver<T> where T]
[std::sync::mpsc::Sender<T> where T]
Expand Down Expand Up @@ -179,6 +178,7 @@ cfg_match! {
[crate::sync::WorkerLocal<T> where T: DynSend]
[crate::intern::Interned<'a, T> where 'a, T: DynSync]
[crate::tagged_ptr::CopyTaggedPtr<P, T, CP> where P: Sync + crate::tagged_ptr::Pointer, T: Sync + crate::tagged_ptr::Tag, const CP: bool]
[triomphe::Arc<T> where T: ?Sized + DynSync + DynSend]
[parking_lot::lock_api::Mutex<R, T> where R: DynSync, T: ?Sized + DynSend]
[parking_lot::lock_api::RwLock<R, T> where R: DynSync, T: ?Sized + DynSend + DynSync]
[indexmap::IndexSet<V, S> where V: DynSync, S: DynSync]
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_data_structures/src/owned_slice.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::borrow::Borrow;
use std::ops::Deref;

use unsize::{CoerceUnsize, Coercion};

// Use our fake Send/Sync traits when on not parallel compiler,
// so that `OwnedSlice` only implements/requires Send/Sync
// for parallel compiler builds.
Expand Down Expand Up @@ -89,7 +91,8 @@ where
let owner = Lrc::new(owner);
let bytes = slicer(&*owner)?;

Ok(OwnedSlice { bytes, owner })
let owner_unsized = owner.clone().unsize(Coercion!(to dyn sync::Send + sync::Sync));
Ok(OwnedSlice { bytes, owner: owner_unsized })
}

impl OwnedSlice {
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_data_structures/src/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,7 @@ impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for Box<T> {
}
}

impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for ::std::rc::Rc<T> {
#[inline]
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
(**self).hash_stable(ctx, hasher);
}
}

impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for ::std::sync::Arc<T> {
impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for crate::sync::Lrc<T> {
#[inline]
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
(**self).hash_stable(ctx, hasher);
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ cfg_match! {
pub type AtomicU64 = Atomic<u64>;

pub use std::rc::Rc as Lrc;
pub use std::rc::Weak as Weak;
#[doc(no_inline)]
pub use std::cell::Ref as ReadGuard;
#[doc(no_inline)]
Expand Down Expand Up @@ -277,8 +276,7 @@ cfg_match! {
#[cfg(not(target_has_atomic = "64"))]
pub use portable_atomic::AtomicU64;

pub use std::sync::Arc as Lrc;
pub use std::sync::Weak as Weak;
pub use triomphe::Arc as Lrc;

pub type LRef<'a, T> = &'a T;

Expand Down
Loading
Loading