Skip to content

Commit 0f88167

Browse files
committed
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.
2 parents cd45b19 + 0e0488f commit 0f88167

File tree

13 files changed

+44
-794
lines changed

13 files changed

+44
-794
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,6 @@ dependencies = [
26502650
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
26512651
"rustc 0.0.0",
26522652
"rustc_data_structures 0.0.0",
2653-
"rustc_incremental 0.0.0",
26542653
"rustc_metadata 0.0.0",
26552654
"rustc_mir 0.0.0",
26562655
"rustc_target 0.0.0",

config.toml.example

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
# =============================================================================
1515
[llvm]
1616

17-
# Indicates whether rustc will support compilation with LLVM
18-
# note: rustc does not compile without LLVM at the moment
19-
#enabled = true
20-
2117
# Indicates whether the LLVM build is a Release or Debug build
2218
#optimize = true
2319

src/bootstrap/builder.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -996,10 +996,7 @@ impl<'a> Builder<'a> {
996996
// For other crates, however, we know that we've already got a standard
997997
// library up and running, so we can use the normal compiler to compile
998998
// build scripts in that situation.
999-
//
1000-
// If LLVM support is disabled we need to use the snapshot compiler to compile
1001-
// build scripts, as the new compiler doesn't support executables.
1002-
if mode == Mode::Std || !self.config.llvm_enabled {
999+
if mode == Mode::Std {
10031000
cargo
10041001
.env("RUSTC_SNAPSHOT", &self.initial_rustc)
10051002
.env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir());

src/bootstrap/config.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ pub struct Config {
6464
pub backtrace_on_ice: bool,
6565

6666
// llvm codegen options
67-
pub llvm_enabled: bool,
6867
pub llvm_assertions: bool,
6968
pub llvm_optimize: bool,
7069
pub llvm_thin_lto: bool,
@@ -244,7 +243,6 @@ struct Install {
244243
#[derive(Deserialize, Default)]
245244
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
246245
struct Llvm {
247-
enabled: Option<bool>,
248246
ccache: Option<StringOrBool>,
249247
ninja: Option<bool>,
250248
assertions: Option<bool>,
@@ -360,7 +358,6 @@ impl Config {
360358

361359
pub fn default_opts() -> Config {
362360
let mut config = Config::default();
363-
config.llvm_enabled = true;
364361
config.llvm_optimize = true;
365362
config.llvm_version_check = true;
366363
config.backtrace = true;
@@ -512,7 +509,6 @@ impl Config {
512509
Some(StringOrBool::Bool(false)) | None => {}
513510
}
514511
set(&mut config.ninja, llvm.ninja);
515-
set(&mut config.llvm_enabled, llvm.enabled);
516512
llvm_assertions = llvm.assertions;
517513
set(&mut config.llvm_optimize, llvm.optimize);
518514
set(&mut config.llvm_thin_lto, llvm.thin_lto);
@@ -671,6 +667,11 @@ impl Config {
671667
pub fn very_verbose(&self) -> bool {
672668
self.verbose > 1
673669
}
670+
671+
pub fn llvm_enabled(&self) -> bool {
672+
self.rust_codegen_backends.contains(&INTERNER.intern_str("llvm"))
673+
|| self.rust_codegen_backends.contains(&INTERNER.intern_str("emscripten"))
674+
}
674675
}
675676

676677
fn set<T>(field: &mut T, val: Option<T>) {

src/bootstrap/test.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ impl Step for Compiletest {
11941194
cmd.arg("--quiet");
11951195
}
11961196

1197-
if builder.config.llvm_enabled {
1197+
if builder.config.llvm_enabled() {
11981198
let llvm_config = builder.ensure(native::Llvm {
11991199
target: builder.config.build,
12001200
emscripten: false,
@@ -1227,12 +1227,6 @@ impl Step for Compiletest {
12271227
}
12281228
}
12291229
}
1230-
if suite == "run-make-fulldeps" && !builder.config.llvm_enabled {
1231-
builder.info(
1232-
"Ignoring run-make test suite as they generally don't work without LLVM"
1233-
);
1234-
return;
1235-
}
12361230

12371231
if suite != "run-make-fulldeps" {
12381232
cmd.arg("--cc")

src/bootstrap/tool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ impl<'a> Builder<'a> {
700700
}
701701

702702
fn llvm_bin_path(&self) -> Option<PathBuf> {
703-
if self.config.llvm_enabled {
703+
if self.config.llvm_enabled() {
704704
let llvm_config = self.ensure(native::Llvm {
705705
target: self.config.build,
706706
emscripten: false,

src/librustc_codegen_utils/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ rustc_target = { path = "../librustc_target" }
2121
rustc_data_structures = { path = "../librustc_data_structures" }
2222
rustc_metadata = { path = "../librustc_metadata" }
2323
rustc_mir = { path = "../librustc_mir" }
24-
rustc_incremental = { path = "../librustc_incremental" }

src/librustc_codegen_utils/codegen_backend.rs

+2-144
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,16 @@
1010
#![feature(box_syntax)]
1111

1212
use std::any::Any;
13-
use std::io::Write;
14-
use std::fs;
15-
use std::path::Path;
16-
use std::sync::{mpsc, Arc};
17-
18-
use rustc_data_structures::owning_ref::OwningRef;
19-
use flate2::Compression;
20-
use flate2::write::DeflateEncoder;
13+
use std::sync::mpsc;
2114

2215
use syntax::symbol::Symbol;
23-
use rustc::hir::def_id::LOCAL_CRATE;
2416
use rustc::session::Session;
2517
use rustc::util::common::ErrorReported;
26-
use rustc::session::config::{CrateType, OutputFilenames, PrintRequest};
18+
use rustc::session::config::{OutputFilenames, PrintRequest};
2719
use rustc::ty::TyCtxt;
2820
use rustc::ty::query::Providers;
29-
use rustc::middle::cstore::EncodedMetadata;
3021
use rustc::middle::cstore::MetadataLoader;
3122
use rustc::dep_graph::DepGraph;
32-
use rustc_target::spec::Target;
33-
use crate::link::out_filename;
3423

3524
pub use rustc_data_structures::sync::MetadataRef;
3625

@@ -64,134 +53,3 @@ pub trait CodegenBackend {
6453
outputs: &OutputFilenames,
6554
) -> Result<(), ErrorReported>;
6655
}
67-
68-
pub struct NoLlvmMetadataLoader;
69-
70-
impl MetadataLoader for NoLlvmMetadataLoader {
71-
fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> {
72-
let buf = fs::read(filename).map_err(|e| format!("metadata file open err: {:?}", e))?;
73-
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf);
74-
Ok(rustc_erase_owner!(buf.map_owner_box()))
75-
}
76-
77-
fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> {
78-
self.get_rlib_metadata(target, filename)
79-
}
80-
}
81-
82-
pub struct MetadataOnlyCodegenBackend(());
83-
pub struct OngoingCodegen {
84-
metadata: EncodedMetadata,
85-
metadata_version: Vec<u8>,
86-
crate_name: Symbol,
87-
}
88-
89-
impl MetadataOnlyCodegenBackend {
90-
pub fn boxed() -> Box<dyn CodegenBackend> {
91-
box MetadataOnlyCodegenBackend(())
92-
}
93-
}
94-
95-
impl CodegenBackend for MetadataOnlyCodegenBackend {
96-
fn init(&self, sess: &Session) {
97-
for cty in sess.opts.crate_types.iter() {
98-
match *cty {
99-
CrateType::Rlib | CrateType::Dylib | CrateType::Executable => {},
100-
_ => {
101-
sess.diagnostic().warn(
102-
&format!("LLVM unsupported, so output type {} is not supported", cty)
103-
);
104-
},
105-
}
106-
}
107-
}
108-
109-
fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync> {
110-
box NoLlvmMetadataLoader
111-
}
112-
113-
fn provide(&self, providers: &mut Providers<'_>) {
114-
crate::symbol_names::provide(providers);
115-
116-
providers.target_features_whitelist = |_tcx, _cnum| {
117-
Default::default() // Just a dummy
118-
};
119-
providers.is_reachable_non_generic = |_tcx, _defid| true;
120-
providers.exported_symbols = |_tcx, _crate| Arc::new(Vec::new());
121-
}
122-
fn provide_extern(&self, providers: &mut Providers<'_>) {
123-
providers.is_reachable_non_generic = |_tcx, _defid| true;
124-
}
125-
126-
fn codegen_crate<'a, 'tcx>(
127-
&self,
128-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
129-
_rx: mpsc::Receiver<Box<dyn Any + Send>>
130-
) -> Box<dyn Any> {
131-
use rustc_mir::monomorphize::item::MonoItem;
132-
133-
crate::check_for_rustc_errors_attr(tcx);
134-
crate::symbol_names_test::report_symbol_names(tcx);
135-
rustc_incremental::assert_dep_graph(tcx);
136-
rustc_incremental::assert_module_sources::assert_module_sources(tcx);
137-
// FIXME: Fix this
138-
// rustc::middle::dependency_format::calculate(tcx);
139-
let _ = tcx.link_args(LOCAL_CRATE);
140-
let _ = tcx.native_libraries(LOCAL_CRATE);
141-
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
142-
for (mono_item, _) in cgus.iter().flat_map(|cgu| cgu.items().iter()) {
143-
if let MonoItem::Fn(inst) = mono_item {
144-
let def_id = inst.def_id();
145-
if def_id.is_local() {
146-
let _ = tcx.codegen_fn_attrs(def_id);
147-
}
148-
}
149-
}
150-
tcx.sess.abort_if_errors();
151-
152-
let metadata = tcx.encode_metadata();
153-
154-
box OngoingCodegen {
155-
metadata,
156-
metadata_version: tcx.metadata_encoding_version().to_vec(),
157-
crate_name: tcx.crate_name(LOCAL_CRATE),
158-
}
159-
}
160-
161-
fn join_codegen_and_link(
162-
&self,
163-
ongoing_codegen: Box<dyn Any>,
164-
sess: &Session,
165-
_dep_graph: &DepGraph,
166-
outputs: &OutputFilenames,
167-
) -> Result<(), ErrorReported> {
168-
let ongoing_codegen = ongoing_codegen.downcast::<OngoingCodegen>()
169-
.expect("Expected MetadataOnlyCodegenBackend's OngoingCodegen, found Box<dyn Any>");
170-
for &crate_type in sess.opts.crate_types.iter() {
171-
if crate_type != CrateType::Rlib &&
172-
crate_type != CrateType::Dylib {
173-
continue;
174-
}
175-
let output_name =
176-
out_filename(sess, crate_type, &outputs, &ongoing_codegen.crate_name.as_str());
177-
let mut compressed = ongoing_codegen.metadata_version.clone();
178-
let metadata = if crate_type == CrateType::Dylib {
179-
DeflateEncoder::new(&mut compressed, Compression::fast())
180-
.write_all(&ongoing_codegen.metadata.raw_data)
181-
.unwrap();
182-
&compressed
183-
} else {
184-
&ongoing_codegen.metadata.raw_data
185-
};
186-
fs::write(&output_name, metadata).unwrap();
187-
}
188-
189-
sess.abort_if_errors();
190-
if !sess.opts.crate_types.contains(&CrateType::Rlib)
191-
&& !sess.opts.crate_types.contains(&CrateType::Dylib)
192-
{
193-
sess.fatal("Executables are not supported by the metadata-only backend.");
194-
}
195-
Ok(())
196-
}
197-
}

src/librustc_codegen_utils/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#[macro_use]
2121
extern crate rustc;
22-
#[macro_use] extern crate rustc_data_structures;
2322

2423
use rustc::ty::TyCtxt;
2524
use rustc::hir::def_id::LOCAL_CRATE;

src/librustc_driver/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ use syntax::feature_gate::{GatedCfg, UnstableFeatures};
9191
use syntax::parse::{self, PResult};
9292
use syntax_pos::{DUMMY_SP, MultiSpan, FileName};
9393

94-
#[cfg(test)]
95-
mod test;
96-
9794
pub mod pretty;
9895

9996
/// Exit status code used for successful compilation and help output.

0 commit comments

Comments
 (0)