Commit 0f88167f authored by bors's avatar bors

Auto merge of #58847 - bjorn3:remove_metadata_only_cg, r=alexcrichton

Remove metadata only codegen backend

It is unused and probably broken at the moment.
parents cd45b19b 0e0488fa
......@@ -2650,7 +2650,6 @@ dependencies = [
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc 0.0.0",
"rustc_data_structures 0.0.0",
"rustc_incremental 0.0.0",
"rustc_metadata 0.0.0",
"rustc_mir 0.0.0",
"rustc_target 0.0.0",
......
......@@ -14,10 +14,6 @@
# =============================================================================
[llvm]
# Indicates whether rustc will support compilation with LLVM
# note: rustc does not compile without LLVM at the moment
#enabled = true
# Indicates whether the LLVM build is a Release or Debug build
#optimize = true
......
......@@ -996,10 +996,7 @@ impl<'a> Builder<'a> {
// For other crates, however, we know that we've already got a standard
// library up and running, so we can use the normal compiler to compile
// build scripts in that situation.
//
// If LLVM support is disabled we need to use the snapshot compiler to compile
// build scripts, as the new compiler doesn't support executables.
if mode == Mode::Std || !self.config.llvm_enabled {
if mode == Mode::Std {
cargo
.env("RUSTC_SNAPSHOT", &self.initial_rustc)
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir());
......
......@@ -64,7 +64,6 @@ pub struct Config {
pub backtrace_on_ice: bool,
// llvm codegen options
pub llvm_enabled: bool,
pub llvm_assertions: bool,
pub llvm_optimize: bool,
pub llvm_thin_lto: bool,
......@@ -244,7 +243,6 @@ struct Install {
#[derive(Deserialize, Default)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct Llvm {
enabled: Option<bool>,
ccache: Option<StringOrBool>,
ninja: Option<bool>,
assertions: Option<bool>,
......@@ -360,7 +358,6 @@ impl Config {
pub fn default_opts() -> Config {
let mut config = Config::default();
config.llvm_enabled = true;
config.llvm_optimize = true;
config.llvm_version_check = true;
config.backtrace = true;
......@@ -512,7 +509,6 @@ impl Config {
Some(StringOrBool::Bool(false)) | None => {}
}
set(&mut config.ninja, llvm.ninja);
set(&mut config.llvm_enabled, llvm.enabled);
llvm_assertions = llvm.assertions;
set(&mut config.llvm_optimize, llvm.optimize);
set(&mut config.llvm_thin_lto, llvm.thin_lto);
......@@ -671,6 +667,11 @@ impl Config {
pub fn very_verbose(&self) -> bool {
self.verbose > 1
}
pub fn llvm_enabled(&self) -> bool {
self.rust_codegen_backends.contains(&INTERNER.intern_str("llvm"))
|| self.rust_codegen_backends.contains(&INTERNER.intern_str("emscripten"))
}
}
fn set<T>(field: &mut T, val: Option<T>) {
......
......@@ -1194,7 +1194,7 @@ impl Step for Compiletest {
cmd.arg("--quiet");
}
if builder.config.llvm_enabled {
if builder.config.llvm_enabled() {
let llvm_config = builder.ensure(native::Llvm {
target: builder.config.build,
emscripten: false,
......@@ -1227,12 +1227,6 @@ impl Step for Compiletest {
}
}
}
if suite == "run-make-fulldeps" && !builder.config.llvm_enabled {
builder.info(
"Ignoring run-make test suite as they generally don't work without LLVM"
);
return;
}
if suite != "run-make-fulldeps" {
cmd.arg("--cc")
......
......@@ -700,7 +700,7 @@ impl<'a> Builder<'a> {
}
fn llvm_bin_path(&self) -> Option<PathBuf> {
if self.config.llvm_enabled {
if self.config.llvm_enabled() {
let llvm_config = self.ensure(native::Llvm {
target: self.config.build,
emscripten: false,
......
......@@ -21,4 +21,3 @@ rustc_target = { path = "../librustc_target" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_metadata = { path = "../librustc_metadata" }
rustc_mir = { path = "../librustc_mir" }
rustc_incremental = { path = "../librustc_incremental" }
......@@ -10,27 +10,16 @@
#![feature(box_syntax)]
use std::any::Any;
use std::io::Write;
use std::fs;
use std::path::Path;
use std::sync::{mpsc, Arc};
use rustc_data_structures::owning_ref::OwningRef;
use flate2::Compression;
use flate2::write::DeflateEncoder;
use std::sync::mpsc;
use syntax::symbol::Symbol;
use rustc::hir::def_id::LOCAL_CRATE;
use rustc::session::Session;
use rustc::util::common::ErrorReported;
use rustc::session::config::{CrateType, OutputFilenames, PrintRequest};
use rustc::session::config::{OutputFilenames, PrintRequest};
use rustc::ty::TyCtxt;
use rustc::ty::query::Providers;
use rustc::middle::cstore::EncodedMetadata;
use rustc::middle::cstore::MetadataLoader;
use rustc::dep_graph::DepGraph;
use rustc_target::spec::Target;
use crate::link::out_filename;
pub use rustc_data_structures::sync::MetadataRef;
......@@ -64,134 +53,3 @@ pub trait CodegenBackend {
outputs: &OutputFilenames,
) -> Result<(), ErrorReported>;
}
pub struct NoLlvmMetadataLoader;
impl MetadataLoader for NoLlvmMetadataLoader {
fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> {
let buf = 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()))
}
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> {
self.get_rlib_metadata(target, filename)
}
}
pub struct MetadataOnlyCodegenBackend(());
pub struct OngoingCodegen {
metadata: EncodedMetadata,
metadata_version: Vec<u8>,
crate_name: Symbol,
}
impl MetadataOnlyCodegenBackend {
pub fn boxed() -> Box<dyn CodegenBackend> {
box MetadataOnlyCodegenBackend(())
}
}
impl CodegenBackend for MetadataOnlyCodegenBackend {
fn init(&self, sess: &Session) {
for cty in sess.opts.crate_types.iter() {
match *cty {
CrateType::Rlib | CrateType::Dylib | CrateType::Executable => {},
_ => {
sess.diagnostic().warn(
&format!("LLVM unsupported, so output type {} is not supported", cty)
);
},
}
}
}
fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync> {
box NoLlvmMetadataLoader
}
fn provide(&self, providers: &mut Providers<'_>) {
crate::symbol_names::provide(providers);
providers.target_features_whitelist = |_tcx, _cnum| {
Default::default() // Just a dummy
};
providers.is_reachable_non_generic = |_tcx, _defid| true;
providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new());
}
fn provide_extern(&self, providers: &mut Providers<'_>) {
providers.is_reachable_non_generic = |_tcx, _defid| true;
}
fn codegen_crate<'a, 'tcx>(
&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
_rx: mpsc::Receiver<Box<dyn Any + Send>>
) -> Box<dyn Any> {
use rustc_mir::monomorphize::item::MonoItem;
crate::check_for_rustc_errors_attr(tcx);
crate::symbol_names_test::report_symbol_names(tcx);
rustc_incremental::assert_dep_graph(tcx);
rustc_incremental::assert_module_sources::assert_module_sources(tcx);
// FIXME: Fix this
// rustc::middle::dependency_format::calculate(tcx);
let _ = tcx.link_args(LOCAL_CRATE);
let _ = tcx.native_libraries(LOCAL_CRATE);
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
for (mono_item, _) in cgus.iter().flat_map(|cgu| cgu.items().iter()) {
if let MonoItem::Fn(inst) = mono_item {
let def_id = inst.def_id();
if def_id.is_local() {
let _ = tcx.codegen_fn_attrs(def_id);
}
}
}
tcx.sess.abort_if_errors();
let metadata = tcx.encode_metadata();
box OngoingCodegen {
metadata,
metadata_version: tcx.metadata_encoding_version().to_vec(),
crate_name: tcx.crate_name(LOCAL_CRATE),
}
}
fn join_codegen_and_link(
&self,
ongoing_codegen: Box<dyn Any>,
sess: &Session,
_dep_graph: &DepGraph,
outputs: &OutputFilenames,
) -> Result<(), ErrorReported> {
let ongoing_codegen = ongoing_codegen.downcast::<OngoingCodegen>()
.expect("Expected MetadataOnlyCodegenBackend's OngoingCodegen, found Box<dyn Any>");
for &crate_type in sess.opts.crate_types.iter() {
if crate_type != CrateType::Rlib &&
crate_type != CrateType::Dylib {
continue;
}
let output_name =
out_filename(sess, crate_type, &outputs, &ongoing_codegen.crate_name.as_str());
let mut compressed = ongoing_codegen.metadata_version.clone();
let metadata = if crate_type == CrateType::Dylib {
DeflateEncoder::new(&mut compressed, Compression::fast())
.write_all(&ongoing_codegen.metadata.raw_data)
.unwrap();
&compressed
} else {
&ongoing_codegen.metadata.raw_data
};
fs::write(&output_name, metadata).unwrap();
}
sess.abort_if_errors();
if !sess.opts.crate_types.contains(&CrateType::Rlib)
&& !sess.opts.crate_types.contains(&CrateType::Dylib)
{
sess.fatal("Executables are not supported by the metadata-only backend.");
}
Ok(())
}
}
......@@ -19,7 +19,6 @@
#[macro_use]
extern crate rustc;
#[macro_use] extern crate rustc_data_structures;
use rustc::ty::TyCtxt;
use rustc::hir::def_id::LOCAL_CRATE;
......
......@@ -91,9 +91,6 @@ use syntax::feature_gate::{GatedCfg, UnstableFeatures};
use syntax::parse::{self, PResult};
use syntax_pos::{DUMMY_SP, MultiSpan, FileName};
#[cfg(test)]
mod test;
pub mod pretty;
/// Exit status code used for successful compilation and help output.
......
This diff is collapsed.
......@@ -266,9 +266,6 @@ pub fn get_codegen_backend(sess: &Session) -> Box<dyn CodegenBackend> {
let codegen_name = sess.opts.debugging_opts.codegen_backend.as_ref()
.unwrap_or(&sess.target.target.options.codegen_backend);
let backend = match &codegen_name[..] {
"metadata_only" => {
rustc_codegen_utils::codegen_backend::MetadataOnlyCodegenBackend::boxed
}
filename if filename.contains(".") => {
load_backend_from_dylib(filename.as_ref())
}
......
......@@ -3,9 +3,13 @@
extern crate syntax;
extern crate rustc;
extern crate rustc_codegen_utils;
#[macro_use]
extern crate rustc_data_structures;
extern crate rustc_target;
use std::any::Any;
use std::sync::mpsc;
use std::sync::{Arc, mpsc};
use std::path::Path;
use syntax::symbol::Symbol;
use rustc::session::Session;
use rustc::session::config::OutputFilenames;
......@@ -14,21 +18,44 @@ use rustc::ty::query::Providers;
use rustc::middle::cstore::MetadataLoader;
use rustc::dep_graph::DepGraph;
use rustc::util::common::ErrorReported;
use rustc_codegen_utils::codegen_backend::{CodegenBackend, MetadataOnlyCodegenBackend};
use rustc_codegen_utils::codegen_backend::CodegenBackend;
use rustc_data_structures::sync::MetadataRef;
use rustc_data_structures::owning_ref::OwningRef;
use rustc_target::spec::Target;
struct TheBackend(Box<CodegenBackend>);
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: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf);
Ok(rustc_erase_owner!(buf.map_owner_box()))
}
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> {
self.get_rlib_metadata(target, filename)
}
}
struct TheBackend;
impl CodegenBackend for TheBackend {
fn metadata_loader(&self) -> Box<MetadataLoader + Sync> {
self.0.metadata_loader()
Box::new(NoLlvmMetadataLoader)
}
fn provide(&self, providers: &mut Providers) {
self.0.provide(providers);
rustc_codegen_utils::symbol_names::provide(providers);
providers.target_features_whitelist = |_tcx, _cnum| {
Default::default() // Just a dummy
};
providers.is_reachable_non_generic = |_tcx, _defid| true;
providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new());
}
fn provide_extern(&self, providers: &mut Providers) {
self.0.provide_extern(providers);
providers.is_reachable_non_generic = |_tcx, _defid| true;
}
fn codegen_crate<'a, 'tcx>(
......@@ -69,5 +96,5 @@ impl CodegenBackend for TheBackend {
/// This is the entrypoint for a hot plugged rustc_codegen_llvm
#[no_mangle]
pub fn __rustc_codegen_backend() -> Box<CodegenBackend> {
Box::new(TheBackend(MetadataOnlyCodegenBackend::boxed()))
Box::new(TheBackend)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment