From 3842da5d69f59e418d4c6f031df2f126c311367a Mon Sep 17 00:00:00 2001 From: Alejandra Gonzalez Date: Tue, 30 Jun 2026 13:39:34 +0200 Subject: [PATCH] Remove dependency from rustc_codegen_ssa on rustc_incremental This allows us to depend on `rustc_resolve` from `rustc_incremental`. Important for https://github.com/rust-lang/rust-project-goals/issues/641 --- Cargo.lock | 1 - compiler/rustc_codegen_ssa/src/back/write.rs | 18 ++++++++++-------- compiler/rustc_incremental/src/lib.rs | 4 ++-- compiler/rustc_incremental/src/persist/fs.rs | 10 +--------- compiler/rustc_incremental/src/persist/mod.rs | 2 +- compiler/rustc_metadata/Cargo.toml | 1 - compiler/rustc_metadata/src/rmeta/encoder.rs | 8 ++++---- 7 files changed, 18 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8dfdd7cae290..a3e77a97e04c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4392,7 +4392,6 @@ dependencies = [ "rustc_fs_util", "rustc_hir", "rustc_hir_pretty", - "rustc_incremental", "rustc_index", "rustc_macros", "rustc_middle", diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 112cf45ebbf2e..de1adf02a049d 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -15,9 +15,7 @@ use rustc_errors::{ }; use rustc_fs_util::link_or_copy; use rustc_hir::find_attr; -use rustc_incremental::{ - copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess, -}; +use rustc_incremental::{copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir_sess}; use rustc_macros::{Decodable, Encodable}; use rustc_metadata::fs::copy_to_stdout; use rustc_middle::bug; @@ -884,20 +882,24 @@ fn execute_copy_from_cache_work_item( let mut links_from_incr_cache = Vec::new(); let mut load_from_incr_comp_dir = |output_path: PathBuf, saved_path: &str| { - let source_file = in_incr_comp_dir(incr_comp_session_dir, saved_path); + let source_file_in_incr_comp_dir = incr_comp_session_dir.join(saved_path); debug!( "copying preexisting module `{}` from {:?} to {}", module.name, - source_file, + source_file_in_incr_comp_dir, output_path.display() ); - match link_or_copy(&source_file, &output_path) { + match link_or_copy(&source_file_in_incr_comp_dir, &output_path) { Ok(_) => { - links_from_incr_cache.push(source_file); + links_from_incr_cache.push(source_file_in_incr_comp_dir); Some(output_path) } Err(error) => { - dcx.emit_err(errors::CopyPathBuf { source_file, output_path, error }); + dcx.emit_err(errors::CopyPathBuf { + source_file: source_file_in_incr_comp_dir, + output_path, + error, + }); None } } diff --git a/compiler/rustc_incremental/src/lib.rs b/compiler/rustc_incremental/src/lib.rs index 0f5d9c5389667..83646cb086d8d 100644 --- a/compiler/rustc_incremental/src/lib.rs +++ b/compiler/rustc_incremental/src/lib.rs @@ -10,8 +10,8 @@ mod diagnostics; mod persist; pub use persist::{ - copy_cgu_workproduct_to_incr_comp_cache_dir, finalize_session_directory, in_incr_comp_dir, - in_incr_comp_dir_sess, load_query_result_cache, save_work_product_index, setup_dep_graph, + copy_cgu_workproduct_to_incr_comp_cache_dir, finalize_session_directory, in_incr_comp_dir_sess, + load_query_result_cache, save_work_product_index, setup_dep_graph, }; use rustc_middle::util::Providers; diff --git a/compiler/rustc_incremental/src/persist/fs.rs b/compiler/rustc_incremental/src/persist/fs.rs index 80134d5ff2202..562481e51188b 100644 --- a/compiler/rustc_incremental/src/persist/fs.rs +++ b/compiler/rustc_incremental/src/persist/fs.rs @@ -184,15 +184,7 @@ fn lock_file_path(session_dir: &Path) -> PathBuf { /// Returns the path for a given filename within the incremental compilation directory /// in the current session. pub fn in_incr_comp_dir_sess(sess: &Session, file_name: &str) -> PathBuf { - in_incr_comp_dir(&sess.incr_comp_session_dir(), file_name) -} - -/// Returns the path for a given filename within the incremental compilation directory, -/// not necessarily from the current session. -/// -/// To ensure the file is part of the current session, use [`in_incr_comp_dir_sess`]. -pub fn in_incr_comp_dir(incr_comp_session_dir: &Path, file_name: &str) -> PathBuf { - incr_comp_session_dir.join(file_name) + sess.incr_comp_session_dir().join(file_name) } /// Allocates the private session directory. diff --git a/compiler/rustc_incremental/src/persist/mod.rs b/compiler/rustc_incremental/src/persist/mod.rs index c25c5f1ea47fb..7d486cc394b80 100644 --- a/compiler/rustc_incremental/src/persist/mod.rs +++ b/compiler/rustc_incremental/src/persist/mod.rs @@ -10,7 +10,7 @@ mod load; mod save; mod work_product; -pub use fs::{finalize_session_directory, in_incr_comp_dir, in_incr_comp_dir_sess}; +pub use fs::{finalize_session_directory, in_incr_comp_dir_sess}; pub use load::{load_query_result_cache, setup_dep_graph}; pub(crate) use save::save_dep_graph; pub use save::save_work_product_index; diff --git a/compiler/rustc_metadata/Cargo.toml b/compiler/rustc_metadata/Cargo.toml index 3a70ee130c27b..2fce131e08b6a 100644 --- a/compiler/rustc_metadata/Cargo.toml +++ b/compiler/rustc_metadata/Cargo.toml @@ -18,7 +18,6 @@ rustc_feature = { path = "../rustc_feature" } rustc_fs_util = { path = "../rustc_fs_util" } rustc_hir = { path = "../rustc_hir" } rustc_hir_pretty = { path = "../rustc_hir_pretty" } -rustc_incremental = { path = "../rustc_incremental" } rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 0f63c8469953d..16a5a6c8877a5 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2472,10 +2472,10 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: Option<&Path>) { && tcx.dep_graph.try_mark_green(tcx, &dep_node).is_some() { let saved_path = &work_product.saved_files["rmeta"]; - let incr_comp_session_dir = tcx.sess.incr_comp_session_dir_opt().unwrap(); - let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, saved_path); - debug!("copying preexisting metadata from {source_file:?} to {path:?}"); - match rustc_fs_util::link_or_copy(&source_file, path) { + let incr_comp_session_dir = tcx.sess.incr_comp_session_dir(); + let source_file_in_incr_dir = &incr_comp_session_dir.join(saved_path); + debug!("copying preexisting metadata from {source_file_in_incr_dir:?} to {path:?}"); + match rustc_fs_util::link_or_copy(&source_file_in_incr_dir, path) { Ok(_) => {} Err(err) => tcx.dcx().emit_fatal(FailCreateFileEncoder { err }), };