Skip to content
Open
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
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_codegen_ssa::{CompiledModules, CrateInfo, TargetConfig, back};
use rustc_log::tracing::info;
use rustc_middle::dep_graph::WorkProductMap;
use rustc_session::Session;
use rustc_session::config::{NATIVE_CPU, OutputFilenames};
use rustc_session::{IncrCompSession, Session};
use rustc_span::{Symbol, sym};
use rustc_target::spec::{Arch, CfgAbi, Env, Os};

Expand Down Expand Up @@ -233,13 +233,14 @@ impl CodegenBackend for CraneliftCodegenBackend {
&self,
ongoing_codegen: Box<dyn Any>,
sess: &Session,
incr_comp_session: Option<&IncrCompSession>,
_outputs: &OutputFilenames,
crate_info: &CrateInfo,
) -> (CompiledModules, WorkProductMap) {
ongoing_codegen
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<driver::aot::AotDriver>>()
.unwrap()
.join(sess, crate_info)
.join(sess, incr_comp_session, crate_info)
}

fn fallback_intrinsics(&self) -> Vec<Symbol> {
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ use rustc_errors::{DiagCtxt, DiagCtxtHandle};
use rustc_middle::dep_graph::{WorkProduct, WorkProductMap};
use rustc_middle::ty::TyCtxt;
use rustc_middle::util::Providers;
use rustc_session::Session;
use rustc_session::config::{OptLevel, OutputFilenames};
use rustc_session::{IncrCompSession, Session};
use rustc_span::{Symbol, sym};
use rustc_target::spec::{Arch, RelocModel};
use tempfile::TempDir;
Expand Down Expand Up @@ -297,13 +297,14 @@ impl CodegenBackend for GccCodegenBackend {
&self,
ongoing_codegen: Box<dyn Any>,
sess: &Session,
incr_comp_session: Option<&IncrCompSession>,
_outputs: &OutputFilenames,
crate_info: &CrateInfo,
) -> (CompiledModules, WorkProductMap) {
ongoing_codegen
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<GccCodegenBackend>>()
.expect("Expected GccCodegenBackend's OngoingCodegen, found Box<Any>")
.join(sess, crate_info)
.join(sess, incr_comp_session, crate_info)
}

fn target_config(&self, sess: &Session) -> TargetConfig {
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductMap};
use rustc_middle::ty::TyCtxt;
use rustc_middle::util::Providers;
use rustc_session::Session;
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
use rustc_session::{IncrCompSession, Session};
use rustc_span::{Symbol, sym};
use rustc_target::spec::{RelocModel, TlsModel};

Expand Down Expand Up @@ -379,13 +379,14 @@ impl CodegenBackend for LlvmCodegenBackend {
&self,
ongoing_codegen: Box<dyn Any>,
sess: &Session,
incr_comp_session: Option<&IncrCompSession>,
outputs: &OutputFilenames,
crate_info: &CrateInfo,
) -> (CompiledModules, WorkProductMap) {
let (compiled_modules, work_products) = ongoing_codegen
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<LlvmCodegenBackend>>()
.expect("Expected LlvmCodegenBackend's OngoingCodegen, found Box<Any>")
.join(sess, crate_info);
.join(sess, incr_comp_session, crate_info);

if sess.opts.unstable_opts.llvm_time_trace {
sess.time("llvm_dump_timing_file", || {
Expand Down
25 changes: 19 additions & 6 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use rustc_metadata::fs::copy_to_stdout;
use rustc_middle::bug;
use rustc_middle::dep_graph::{WorkProduct, WorkProductMap};
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_session::config::{
self, CrateType, Lto, OptLevel, OutFileName, OutputFilenames, OutputType, Passes,
SwitchWithOptPath,
};
use rustc_session::{IncrCompSession, Session};
use rustc_span::source_map::SourceMap;
use rustc_span::{FileName, InnerSpan, Span, SpanData};
use rustc_target::spec::{MergeFunctions, SanitizerSet};
Expand Down Expand Up @@ -461,6 +461,7 @@ pub(crate) fn start_async_codegen<B: WriteBackendMethods>(

fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
sess: &Session,
incr_comp_session: Option<&IncrCompSession>,
compiled_modules: &CompiledModules,
) -> WorkProductMap {
let mut work_products = WorkProductMap::default();
Expand Down Expand Up @@ -494,6 +495,7 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
}
let (id, product) = copy_cgu_workproduct_to_incr_comp_cache_dir(
sess,
incr_comp_session.unwrap(),
&module.name,
files.as_slice(),
&module.links_from_incr_cache,
Expand Down Expand Up @@ -1286,7 +1288,10 @@ fn start_executing_work<B: WriteBackendMethods>(
time_trace: sess.opts.unstable_opts.llvm_time_trace,
remark: sess.opts.cg.remark.clone(),
remark_dir,
incr_comp_session_dir: sess.incr_comp_session_dir_opt().map(|r| r.clone()),
incr_comp_session_dir: tcx
.incr_comp_session
.as_ref()
.map(|incr_comp_session| incr_comp_session.session_directory.clone()),
output_filenames: Arc::clone(tcx.output_filenames(())),
module_config: regular_config,
opt_level,
Expand Down Expand Up @@ -2118,7 +2123,12 @@ pub struct OngoingCodegen<B: WriteBackendMethods> {
}

impl<B: WriteBackendMethods> OngoingCodegen<B> {
pub fn join(self, sess: &Session, crate_info: &CrateInfo) -> (CompiledModules, WorkProductMap) {
pub fn join(
self,
sess: &Session,
incr_comp_session: Option<&IncrCompSession>,
crate_info: &CrateInfo,
) -> (CompiledModules, WorkProductMap) {
self.shared_emitter_main.check(sess, true);

let maybe_lto_modules = sess.time("join_worker_thread", || match self.coordinator.join() {
Expand Down Expand Up @@ -2196,8 +2206,11 @@ impl<B: WriteBackendMethods> OngoingCodegen<B> {
// out deterministic results.
compiled_modules.modules.sort_by(|a, b| a.name.cmp(&b.name));

let work_products =
copy_all_cgu_workproducts_to_incr_comp_cache_dir(sess, &compiled_modules);
let work_products = copy_all_cgu_workproducts_to_incr_comp_cache_dir(
sess,
incr_comp_session,
&compiled_modules,
);
produce_final_output_artifacts(sess, &compiled_modules, &self.output_filenames);

(compiled_modules, work_products)
Expand Down Expand Up @@ -2249,7 +2262,7 @@ pub(crate) fn submit_pre_lto_module_to_llvm<B: WriteBackendMethods>(
module: CachedModuleCodegen,
) {
let filename = pre_lto_bitcode_filename(&module.name);
let bitcode_path = in_incr_comp_dir_sess(tcx.sess, &filename);
let bitcode_path = in_incr_comp_dir_sess(tcx.incr_comp_session.unwrap(), &filename);
// Schedule the module to be loaded
drop(
coordinator
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/traits/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use rustc_metadata::creader::MetadataLoaderDyn;
use rustc_middle::dep_graph::WorkProductMap;
use rustc_middle::ty::TyCtxt;
use rustc_middle::util::Providers;
use rustc_session::Session;
use rustc_session::config::{CrateType, OutputFilenames, PrintRequest};
use rustc_session::{IncrCompSession, Session};
use rustc_span::Symbol;

use super::CodegenObject;
Expand Down Expand Up @@ -127,6 +127,7 @@ pub trait CodegenBackend {
&self,
ongoing_codegen: Box<dyn Any>,
sess: &Session,
incr_comp_session: Option<&IncrCompSession>,
outputs: &OutputFilenames,
crate_info: &CrateInfo,
) -> (CompiledModules, WorkProductMap);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))

// Linking is done outside the `compiler.enter()` so that the
// `GlobalCtxt` within `Queries` can be freed as early as possible.
if let Some(linker) = linker {
linker.link(sess, codegen_backend);
if let (Some(linker), incr_comp_session) = linker {
linker.link(sess, incr_comp_session, codegen_backend);
}
})
}
Expand Down
48 changes: 26 additions & 22 deletions compiler/rustc_incremental/src/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_data_structures::{base_n, flock};
use rustc_fs_util::{LinkOrCopy, link_or_copy, try_canonicalize};
use rustc_middle::bug;
use rustc_session::{Session, StableCrateId};
use rustc_session::{IncrCompSession, Session, StableCrateId};
use rustc_span::Symbol;
use tracing::debug;

Expand All @@ -138,25 +138,25 @@ const QUERY_CACHE_FILENAME: &str = "query-cache.bin";
const INT_ENCODE_BASE: usize = base_n::CASE_INSENSITIVE;

/// Returns the path to a session's dependency graph.
pub(crate) fn dep_graph_path(sess: &Session) -> PathBuf {
in_incr_comp_dir_sess(sess, DEP_GRAPH_FILENAME)
pub(crate) fn dep_graph_path(incr_comp_session: &IncrCompSession) -> PathBuf {
in_incr_comp_dir_sess(incr_comp_session, DEP_GRAPH_FILENAME)
}

/// Returns the path to a session's staging dependency graph.
///
/// On the difference between dep-graph and staging dep-graph,
/// see `build_dep_graph`.
pub(crate) fn staging_dep_graph_path(sess: &Session) -> PathBuf {
in_incr_comp_dir_sess(sess, STAGING_DEP_GRAPH_FILENAME)
pub(crate) fn staging_dep_graph_path(incr_comp_session: &IncrCompSession) -> PathBuf {
in_incr_comp_dir_sess(incr_comp_session, STAGING_DEP_GRAPH_FILENAME)
}

pub(crate) fn work_products_path(sess: &Session) -> PathBuf {
in_incr_comp_dir_sess(sess, WORK_PRODUCTS_FILENAME)
pub(crate) fn work_products_path(incr_comp_session: &IncrCompSession) -> PathBuf {
in_incr_comp_dir_sess(incr_comp_session, WORK_PRODUCTS_FILENAME)
}

/// Returns the path to a session's query cache.
pub(crate) fn query_cache_path(sess: &Session) -> PathBuf {
in_incr_comp_dir_sess(sess, QUERY_CACHE_FILENAME)
pub(crate) fn query_cache_path(incr_comp_session: &IncrCompSession) -> PathBuf {
in_incr_comp_dir_sess(incr_comp_session, QUERY_CACHE_FILENAME)
}

/// Locks a given session directory.
Expand All @@ -183,8 +183,8 @@ 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 {
sess.incr_comp_session_dir().join(file_name)
pub fn in_incr_comp_dir_sess(incr_comp_session: &IncrCompSession, file_name: &str) -> PathBuf {
incr_comp_session.session_directory.join(file_name)
}

/// Allocates the private session directory.
Expand All @@ -206,7 +206,7 @@ pub(crate) fn prepare_session_directory(
sess: &Session,
crate_name: Symbol,
stable_crate_id: StableCrateId,
) {
) -> IncrCompSession {
assert!(sess.opts.incremental.is_some());

let _timer = sess.timer("incr_comp_prepare_session_directory");
Expand Down Expand Up @@ -257,8 +257,7 @@ pub(crate) fn prepare_session_directory(
directory."
);

sess.init_incr_comp_session(session_dir, directory_lock);
return;
return IncrCompSession { session_directory: session_dir, _lock_file: directory_lock };
};

debug!("attempting to copy data from source: {}", source_directory.display());
Expand All @@ -271,8 +270,7 @@ pub(crate) fn prepare_session_directory(
sess.dcx().emit_warn(diagnostics::HardLinkFailed { path: &session_dir });
}

sess.init_incr_comp_session(session_dir, directory_lock);
return;
return IncrCompSession { session_directory: session_dir, _lock_file: directory_lock };
} else {
debug!("copying failed - trying next directory");

Expand All @@ -295,18 +293,23 @@ pub(crate) fn prepare_session_directory(
/// This function finalizes and thus 'publishes' the session directory by
/// renaming it to `s-{timestamp}-{svh}` and releasing the file lock.
/// This must not be called if there have been any compilation errors.
pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
pub fn finalize_session_directory(
sess: &Session,
incr_comp_session: Option<IncrCompSession>,
svh: Option<Svh>,
) {
assert!(sess.dcx().has_errors_or_delayed_bugs().is_none());

if sess.opts.incremental.is_none() {
return;
}
let incr_comp_session = incr_comp_session.unwrap();
// The svh is always produced when incr. comp. is enabled.
let svh = svh.unwrap();

let _timer = sess.timer("incr_comp_finalize_session_directory");

let incr_comp_session_dir: PathBuf = sess.incr_comp_session_dir().clone();
let incr_comp_session_dir = incr_comp_session.session_directory.clone();

debug!("finalize_session_directory() - session directory: {}", incr_comp_session_dir.display());

Expand Down Expand Up @@ -342,14 +345,15 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
}
}

// This unlocks the directory
sess.finalize_incr_comp_session();
drop(incr_comp_session); // Unlock incr comp session dir

let _ = garbage_collect_session_directories(sess, &new_path);
}

pub(crate) fn delete_all_session_dir_contents(sess: &Session) -> io::Result<()> {
let sess_dir_iterator = sess.incr_comp_session_dir().read_dir()?;
pub(crate) fn delete_all_session_dir_contents(
incr_comp_session: &IncrCompSession,
) -> io::Result<()> {
let sess_dir_iterator = incr_comp_session.session_directory.read_dir()?;
for entry in sess_dir_iterator {
let entry = entry?;
safe_remove_file(&entry.path())?
Expand Down
Loading
Loading