Skip to content
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

A bunch of cleanups #133567

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
2 changes: 0 additions & 2 deletions compiler/rustc_codegen_cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ impl CodegenBackend for CraneliftCodegenBackend {
sess: &Session,
outputs: &OutputFilenames,
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
let _timer = sess.timer("finish_ongoing_codegen");

ongoing_codegen.downcast::<driver::aot::OngoingCodegen>().unwrap().join(
sess,
outputs,
Expand Down
11 changes: 3 additions & 8 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use rustc_codegen_ssa::back::write::{
use rustc_codegen_ssa::traits::*;
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, FatalError};
use rustc_errors::{DiagCtxtHandle, FatalError};
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::ty::TyCtxt;
Expand Down Expand Up @@ -371,19 +371,14 @@ impl CodegenBackend for LlvmCodegenBackend {
(codegen_results, work_products)
}

fn link(
&self,
sess: &Session,
codegen_results: CodegenResults,
outputs: &OutputFilenames,
) -> Result<(), ErrorGuaranteed> {
fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames) {
use rustc_codegen_ssa::back::link::link_binary;

use crate::back::archive::LlvmArchiveBuilderBuilder;

// Run the linker on any artifacts that resulted from the LLVM run.
// This should produce either a finished executable or library.
link_binary(sess, &LlvmArchiveBuilderBuilder, codegen_results, outputs)
link_binary(sess, &LlvmArchiveBuilderBuilder, codegen_results, outputs);
}
}

Expand Down
56 changes: 24 additions & 32 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_ast::CRATE_NODE_ID;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::memmap::Mmap;
use rustc_data_structures::temp_dir::MaybeTempDir;
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, FatalError};
use rustc_errors::{DiagCtxtHandle, FatalError};
use rustc_fs_util::{fix_windows_verbatim_for_gcc, try_canonicalize};
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_metadata::fs::{METADATA_FILENAME, copy_to_stdout, emit_wrapper_file};
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn link_binary(
archive_builder_builder: &dyn ArchiveBuilderBuilder,
codegen_results: CodegenResults,
outputs: &OutputFilenames,
) -> Result<(), ErrorGuaranteed> {
) {
let _timer = sess.timer("link_binary");
let output_metadata = sess.opts.output_types.contains_key(&OutputType::Metadata);
let mut tempfiles_for_stdout_output: Vec<PathBuf> = Vec::new();
Expand Down Expand Up @@ -119,7 +119,7 @@ pub fn link_binary(
&codegen_results,
RlibFlavor::Normal,
&path,
)?
)
.build(&out_filename);
}
CrateType::Staticlib => {
Expand All @@ -129,7 +129,7 @@ pub fn link_binary(
&codegen_results,
&out_filename,
&path,
)?;
);
}
_ => {
link_natively(
Expand All @@ -139,7 +139,7 @@ pub fn link_binary(
&out_filename,
&codegen_results,
path.as_ref(),
)?;
);
}
}
if sess.opts.json_artifact_notifications {
Expand Down Expand Up @@ -225,8 +225,6 @@ pub fn link_binary(
maybe_remove_temps_from_module(preserve_objects, preserve_dwarf_objects, module);
}
});

Ok(())
}

// Crate type is not passed when calculating the dylibs to include for LTO. In that case all
Expand Down Expand Up @@ -298,7 +296,7 @@ fn link_rlib<'a>(
codegen_results: &CodegenResults,
flavor: RlibFlavor,
tmpdir: &MaybeTempDir,
) -> Result<Box<dyn ArchiveBuilder + 'a>, ErrorGuaranteed> {
) -> Box<dyn ArchiveBuilder + 'a> {
let mut ab = archive_builder_builder.new_archive_builder(sess);

let trailing_metadata = match flavor {
Expand Down Expand Up @@ -374,7 +372,7 @@ fn link_rlib<'a>(
{
let path = find_native_static_library(filename.as_str(), true, sess);
let src = read(path)
.map_err(|e| sess.dcx().emit_fatal(errors::ReadFileError { message: e }))?;
.unwrap_or_else(|e| sess.dcx().emit_fatal(errors::ReadFileError { message: e }));
let (data, _) = create_wrapper_file(sess, ".bundled_lib".to_string(), &src);
let wrapper_file = emit_wrapper_file(sess, &data, tmpdir, filename.as_str());
packed_bundled_libs.push(wrapper_file);
Expand All @@ -392,7 +390,7 @@ fn link_rlib<'a>(
codegen_results.crate_info.used_libraries.iter(),
tmpdir.as_ref(),
true,
)? {
) {
ab.add_archive(&output_path, Box::new(|_| false)).unwrap_or_else(|error| {
sess.dcx().emit_fatal(errors::AddNativeLibrary { library_path: output_path, error });
});
Expand Down Expand Up @@ -433,7 +431,7 @@ fn link_rlib<'a>(
ab.add_file(&lib)
}

Ok(ab)
ab
}

/// Extract all symbols defined in raw-dylib libraries, collated by library name.
Expand All @@ -445,7 +443,7 @@ fn link_rlib<'a>(
fn collate_raw_dylibs<'a>(
sess: &Session,
used_libraries: impl IntoIterator<Item = &'a NativeLib>,
) -> Result<Vec<(String, Vec<DllImport>)>, ErrorGuaranteed> {
) -> Vec<(String, Vec<DllImport>)> {
// Use index maps to preserve original order of imports and libraries.
let mut dylib_table = FxIndexMap::<String, FxIndexMap<Symbol, &DllImport>>::default();

Expand All @@ -469,15 +467,13 @@ fn collate_raw_dylibs<'a>(
}
}
}
if let Some(guar) = sess.dcx().has_errors() {
return Err(guar);
}
Ok(dylib_table
sess.dcx().abort_if_errors();
dylib_table
.into_iter()
.map(|(name, imports)| {
(name, imports.into_iter().map(|(_, import)| import.clone()).collect())
})
.collect())
.collect()
}

fn create_dll_import_libs<'a>(
Expand All @@ -486,8 +482,8 @@ fn create_dll_import_libs<'a>(
used_libraries: impl IntoIterator<Item = &'a NativeLib>,
tmpdir: &Path,
is_direct_dependency: bool,
) -> Result<Vec<PathBuf>, ErrorGuaranteed> {
Ok(collate_raw_dylibs(sess, used_libraries)?
) -> Vec<PathBuf> {
collate_raw_dylibs(sess, used_libraries)
.into_iter()
.map(|(raw_dylib_name, raw_dylib_imports)| {
let name_suffix = if is_direct_dependency { "_imports" } else { "_imports_indirect" };
Expand Down Expand Up @@ -537,7 +533,7 @@ fn create_dll_import_libs<'a>(

output_path
})
.collect())
.collect()
}

/// Create a static archive.
Expand All @@ -557,15 +553,15 @@ fn link_staticlib(
codegen_results: &CodegenResults,
out_filename: &Path,
tempdir: &MaybeTempDir,
) -> Result<(), ErrorGuaranteed> {
) {
info!("preparing staticlib to {:?}", out_filename);
let mut ab = link_rlib(
sess,
archive_builder_builder,
codegen_results,
RlibFlavor::StaticlibBase,
tempdir,
)?;
);
let mut all_native_libs = vec![];

let res = each_linked_rlib(
Expand Down Expand Up @@ -656,8 +652,6 @@ fn link_staticlib(
print_native_static_libs(sess, &print.out, &all_native_libs, &all_rust_dylibs);
}
}

Ok(())
}

/// Use `thorin` (rust implementation of a dwarf packaging utility) to link DWARF objects into a
Expand Down Expand Up @@ -773,7 +767,7 @@ fn link_natively(
out_filename: &Path,
codegen_results: &CodegenResults,
tmpdir: &Path,
) -> Result<(), ErrorGuaranteed> {
) {
info!("preparing {:?} to {:?}", crate_type, out_filename);
let (linker_path, flavor) = linker_and_flavor(sess);
let self_contained_components = self_contained_components(sess, crate_type);
Expand All @@ -797,7 +791,7 @@ fn link_natively(
temp_filename,
codegen_results,
self_contained_components,
)?;
);

linker::disable_localization(&mut cmd);

Expand Down Expand Up @@ -1177,8 +1171,6 @@ fn link_natively(
ab.add_file(temp_filename);
ab.build(out_filename);
}

Ok(())
}

fn strip_symbols_with_external_utility(
Expand Down Expand Up @@ -2232,7 +2224,7 @@ fn linker_with_args(
out_filename: &Path,
codegen_results: &CodegenResults,
self_contained_components: LinkSelfContainedComponents,
) -> Result<Command, ErrorGuaranteed> {
) -> Command {
let self_contained_crt_objects = self_contained_components.is_crt_objects_enabled();
let cmd = &mut *super::linker::get_linker(
sess,
Expand Down Expand Up @@ -2356,7 +2348,7 @@ fn linker_with_args(
codegen_results.crate_info.used_libraries.iter(),
tmpdir,
true,
)? {
) {
cmd.add_object(&output_path);
}
// As with add_upstream_native_libraries, we need to add the upstream raw-dylib symbols in case
Expand Down Expand Up @@ -2388,7 +2380,7 @@ fn linker_with_args(
native_libraries_from_nonstatics,
tmpdir,
false,
)? {
) {
cmd.add_object(&output_path);
}

Expand Down Expand Up @@ -2435,7 +2427,7 @@ fn linker_with_args(
// to it and remove the option. Currently the last holdout is wasm32-unknown-emscripten.
add_post_link_args(cmd, sess, flavor);

Ok(cmd.take_cmd())
cmd.take_cmd()
}

fn add_order_independent_options(
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,11 @@ impl Translate for SharedEmitter {
}

impl Emitter for SharedEmitter {
fn emit_diagnostic(&mut self, mut diag: rustc_errors::DiagInner) {
fn emit_diagnostic(
&mut self,
mut diag: rustc_errors::DiagInner,
_registry: &rustc_errors::registry::Registry,
) {
// Check that we aren't missing anything interesting when converting to
// the cut-down local `DiagInner`.
assert_eq!(diag.span, MultiSpan::new());
Expand Down Expand Up @@ -2028,8 +2032,6 @@ pub struct OngoingCodegen<B: ExtraBackendMethods> {

impl<B: ExtraBackendMethods> OngoingCodegen<B> {
pub fn join(self, sess: &Session) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
let _timer = sess.timer("finish_ongoing_codegen");

self.shared_emitter_main.check(sess, true);
let compiled_modules = sess.time("join_worker_thread", || match self.coordinator.join() {
Ok(Ok(compiled_modules)) => compiled_modules,
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_codegen_ssa/src/traits/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::hash::Hash;
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_errors::ErrorGuaranteed;
use rustc_metadata::EncodedMetadata;
use rustc_metadata::creader::MetadataLoaderDyn;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
Expand Down Expand Up @@ -84,13 +83,8 @@ pub trait CodegenBackend {
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>);

/// This is called on the returned [`CodegenResults`] from [`join_codegen`](Self::join_codegen).
fn link(
&self,
sess: &Session,
codegen_results: CodegenResults,
outputs: &OutputFilenames,
) -> Result<(), ErrorGuaranteed> {
link_binary(sess, &ArArchiveBuilderBuilder, codegen_results, outputs)
fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames) {
link_binary(sess, &ArArchiveBuilderBuilder, codegen_results, outputs);
}

/// Returns `true` if this backend can be safely called from multiple threads.
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_driver_impl/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ impl Expander {
/// If this function is intended to be used with command line arguments,
/// `argv[0]` must be removed prior to calling it manually.
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
pub fn arg_expand_all(
early_dcx: &EarlyDiagCtxt,
at_args: &[String],
) -> Result<Vec<String>, ErrorGuaranteed> {
pub fn arg_expand_all(early_dcx: &EarlyDiagCtxt, at_args: &[String]) -> Vec<String> {
let mut expander = Expander::default();
let mut result = Ok(());
for arg in at_args {
if let Err(err) = expander.arg(arg) {
result = Err(early_dcx.early_err(format!("failed to load argument file: {err}")));
}
}
result.map(|()| expander.finish())
if let Err(guar) = result {
guar.raise_fatal();
}
expander.finish()
}

/// Gets the raw unprocessed command-line arguments as Unicode strings, without doing any further
Expand Down
Loading
Loading