Skip to content

Commit

Permalink
Fix hotplug_codegen_backend test
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Oct 10, 2020
1 parent 12a2941 commit aa51449
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
extern crate rustc_codegen_ssa;
extern crate rustc_errors;
extern crate rustc_middle;
#[macro_use]
extern crate rustc_data_structures;
extern crate rustc_driver;
extern crate rustc_hir;
Expand All @@ -12,17 +11,19 @@ extern crate rustc_span;
extern crate rustc_symbol_mangling;
extern crate rustc_target;

use rustc_codegen_ssa::back::linker::LinkerInfo;
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::owning_ref::OwningRef;
use rustc_codegen_ssa::{CodegenResults, CrateInfo};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::MetadataRef;
use rustc_errors::ErrorReported;
use rustc_middle::dep_graph::DepGraph;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader, MetadataLoaderDyn};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt;
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;
Expand All @@ -31,14 +32,11 @@ 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()))
unreachable!("some_crate.rs shouldn't depend on any external crates");
}

fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> {
self.get_rlib_metadata(target, filename)
unreachable!("some_crate.rs shouldn't depend on any external crates");
}
}

Expand All @@ -49,53 +47,49 @@ impl CodegenBackend for TheBackend {
Box::new(NoLlvmMetadataLoader)
}

fn provide(&self, providers: &mut Providers) {
rustc_symbol_mangling::provide(providers);

providers.supported_target_features = |tcx, _cnum| {
Default::default() // Just a dummy
};
providers.is_reachable_non_generic = |_tcx, _defid| true;
providers.exported_symbols = |_tcx, _crate| &[];
}

fn provide_extern(&self, providers: &mut Providers) {
providers.is_reachable_non_generic = |_tcx, _defid| true;
}
fn provide(&self, providers: &mut Providers) {}
fn provide_extern(&self, providers: &mut Providers) {}

fn codegen_crate<'a, 'tcx>(
&self,
tcx: TyCtxt<'tcx>,
_metadata: EncodedMetadata,
metadata: EncodedMetadata,
_need_metadata_module: bool,
) -> Box<dyn Any> {
use rustc_hir::def_id::LOCAL_CRATE;

Box::new(tcx.crate_name(LOCAL_CRATE) as Symbol)
Box::new(CodegenResults {
crate_name: tcx.crate_name(LOCAL_CRATE),
modules: vec![],
allocator_module: None,
metadata_module: None,
metadata,
windows_subsystem: None,
linker_info: LinkerInfo::new(tcx),
crate_info: CrateInfo::new(tcx),
})
}

fn join_codegen(
&self,
ongoing_codegen: Box<dyn Any>,
_sess: &Session,
_dep_graph: &DepGraph,
) -> Result<Box<dyn Any>, ErrorReported> {
let crate_name = ongoing_codegen
.downcast::<Symbol>()
.expect("in join_codegen: ongoing_codegen is not a Symbol");
Ok(crate_name)
) -> Result<(CodegenResults, FxHashMap<WorkProductId, WorkProduct>), ErrorReported> {
let codegen_results = ongoing_codegen
.downcast::<CodegenResults>()
.expect("in join_codegen: ongoing_codegen is not a CodegenResults");
Ok((*codegen_results, FxHashMap::default()))
}

fn link(
&self,
sess: &Session,
codegen_results: Box<dyn Any>,
codegen_results: CodegenResults,
outputs: &OutputFilenames,
) -> Result<(), ErrorReported> {
use rustc_session::{config::CrateType, output::out_filename};
use std::io::Write;
let crate_name =
codegen_results.downcast::<Symbol>().expect("in link: codegen_results is not a Symbol");
let crate_name = codegen_results.crate_name;
for &crate_type in sess.opts.crate_types.iter() {
if crate_type != CrateType::Rlib {
sess.fatal(&format!("Crate type is {:?}", crate_type));
Expand Down

0 comments on commit aa51449

Please sign in to comment.