1
Fork 0

Move some code from Compiler::enter to GlobalCtxt::finish

This commit is contained in:
bjorn3 2024-10-31 14:23:38 +00:00
parent bec24a25cd
commit 8e9bbc899c
11 changed files with 64 additions and 32 deletions

View file

@ -73,6 +73,9 @@ middle_drop_check_overflow =
middle_erroneous_constant = erroneous constant encountered
middle_failed_writing_file =
failed to write file {$path}: {$error}"
middle_layout_references_error =
the type has an unknown layout

View file

@ -1,5 +1,5 @@
use std::fmt;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::{fmt, io};
use rustc_errors::codes::*;
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage};
@ -18,6 +18,13 @@ pub struct DropCheckOverflow<'tcx> {
pub overflow_ty: Ty<'tcx>,
}
#[derive(Diagnostic)]
#[diag(middle_failed_writing_file)]
pub struct FailedWritingFile<'a> {
pub path: &'a Path,
pub error: io::Error,
}
#[derive(Diagnostic)]
#[diag(middle_opaque_hidden_type_mismatch)]
pub struct OpaqueHiddenTypeMismatch<'tcx> {

View file

@ -108,6 +108,19 @@ declare_hooks! {
/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
/// can just link to the upstream crate and therefore don't need a mono item.
hook should_codegen_locally(instance: crate::ty::Instance<'tcx>) -> bool;
hook alloc_self_profile_query_strings() -> ();
/// Saves and writes the DepGraph to the file system.
///
/// This function saves both the dep-graph and the query result cache,
/// and drops the result cache.
///
/// This function should only run after all queries have completed.
/// Trying to execute a query afterwards would attempt to read the result cache we just dropped.
hook save_dep_graph() -> ();
hook query_key_hash_verify_all() -> ();
}
#[cold]

View file

@ -1365,8 +1365,17 @@ impl<'tcx> GlobalCtxt<'tcx> {
tls::enter_context(&icx, || f(icx.tcx))
}
pub fn finish(&self) -> FileEncodeResult {
self.dep_graph.finish_encoding()
pub fn finish(&'tcx self) {
// We assume that no queries are run past here. If there are new queries
// after this point, they'll show up as "<unknown>" in self-profiling data.
self.enter(|tcx| tcx.alloc_self_profile_query_strings());
self.enter(|tcx| tcx.save_dep_graph());
self.enter(|tcx| tcx.query_key_hash_verify_all());
if let Err((path, error)) = self.dep_graph.finish_encoding() {
self.sess.dcx().emit_fatal(crate::error::FailedWritingFile { path: &path, error });
}
}
}