Rollup merge of #69965 - mark-i-m:codegen-utils, r=eddyb

Refactorings to get rid of rustc_codegen_utils

r? @eddyb

cc #45276

After this, the only modules left in `rustc_codegen_utils` are
- `link`: a bunch of linking-related functions (many dealing with file names). These are mostly consumed by save analysis, rustc_driver, rustc_interface, and of course codegen. I assume they live here because we don't want a dependency of save analysis on codegen... Perhaps they can be moved to librustc?
- ~`symbol_names` and `symbol_names_test`: honestly it seems odd that `symbol_names_test` is not a submodule of `symbol_names`. It seems like these could honestly live in their own crate or move to librustc. Already name mangling is exported as the `symbol_name` query.~ (move it to its own crate)

I don't mind doing either of the above as part of this PR or a followup if you want.
This commit is contained in:
Mazdak Farrokhzad 2020-03-21 08:51:14 +01:00 committed by GitHub
commit 0b99489a89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 265 additions and 290 deletions

View file

@ -1,36 +1,38 @@
#![feature(rustc_private)]
extern crate rustc;
extern crate rustc_codegen_utils;
extern crate rustc_codegen_ssa;
#[macro_use]
extern crate rustc_data_structures;
extern crate rustc_hir;
extern crate rustc_target;
extern crate rustc_driver;
extern crate rustc_hir;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_symbol_mangling;
extern crate rustc_target;
use std::any::Any;
use std::sync::Arc;
use std::path::Path;
use rustc::ty::TyCtxt;
use rustc::ty::query::Providers;
use rustc::middle::cstore::{EncodedMetadata, MetadataLoader, MetadataLoaderDyn};
use rustc::dep_graph::DepGraph;
use rustc::middle::cstore::{EncodedMetadata, MetadataLoader, MetadataLoaderDyn};
use rustc::ty::query::Providers;
use rustc::ty::TyCtxt;
use rustc::util::common::ErrorReported;
use rustc_codegen_utils::codegen_backend::CodegenBackend;
use rustc_data_structures::sync::MetadataRef;
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::owning_ref::OwningRef;
use rustc_session::Session;
use rustc_data_structures::sync::MetadataRef;
use rustc_session::config::OutputFilenames;
use rustc_session::Session;
use rustc_span::symbol::Symbol;
use rustc_target::spec::Target;
use std::any::Any;
use std::path::Path;
use std::sync::Arc;
pub struct NoLlvmMetadataLoader;
impl MetadataLoader for NoLlvmMetadataLoader {
fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> {
let buf = std::fs::read(filename).map_err(|e| format!("metadata file open err: {:?}", e))?;
let buf =
std::fs::read(filename).map_err(|e| format!("metadata file open err: {:?}", e))?;
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf);
Ok(rustc_erase_owner!(buf.map_owner_box()))
}
@ -48,7 +50,7 @@ impl CodegenBackend for TheBackend {
}
fn provide(&self, providers: &mut Providers) {
rustc_codegen_utils::symbol_names::provide(providers);
rustc_symbol_mangling::provide(providers);
providers.target_features_whitelist = |tcx, _cnum| {
tcx.arena.alloc(Default::default()) // Just a dummy
@ -78,7 +80,8 @@ impl CodegenBackend for TheBackend {
_sess: &Session,
_dep_graph: &DepGraph,
) -> Result<Box<dyn Any>, ErrorReported> {
let crate_name = ongoing_codegen.downcast::<Symbol>()
let crate_name = ongoing_codegen
.downcast::<Symbol>()
.expect("in join_codegen: ongoing_codegen is not a Symbol");
Ok(crate_name)
}
@ -89,17 +92,15 @@ impl CodegenBackend for TheBackend {
codegen_results: Box<dyn Any>,
outputs: &OutputFilenames,
) -> Result<(), ErrorReported> {
use rustc_session::{config::CrateType, output::out_filename};
use std::io::Write;
use rustc_session::config::CrateType;
use rustc_codegen_utils::link::out_filename;
let crate_name = codegen_results.downcast::<Symbol>()
.expect("in link: codegen_results is not a Symbol");
let crate_name =
codegen_results.downcast::<Symbol>().expect("in link: codegen_results is not a Symbol");
for &crate_type in sess.opts.crate_types.iter() {
if crate_type != CrateType::Rlib {
sess.fatal(&format!("Crate type is {:?}", crate_type));
}
let output_name =
out_filename(sess, crate_type, &outputs, &*crate_name.as_str());
let output_name = out_filename(sess, crate_type, &outputs, &*crate_name.as_str());
let mut out_file = ::std::fs::File::create(output_name).unwrap();
write!(out_file, "This has been \"compiled\" successfully.").unwrap();
}