PR feedback

This commit is contained in:
khyperia 2020-09-17 12:14:18 +02:00
parent c946c40d9d
commit 48655c2d2c
3 changed files with 7 additions and 10 deletions

View File

@ -32,7 +32,6 @@ use rustc_serialize::json;
use rustc_session::config::{self, OptLevel, OutputFilenames, PrintRequest};
use rustc_session::Session;
use rustc_span::symbol::Symbol;
use rustc_target::spec::Target;
use std::any::Any;
use std::ffi::CStr;
@ -245,10 +244,6 @@ impl CodegenBackend for LlvmCodegenBackend {
target_features(sess)
}
fn target_override(&self, _opts: &config::Options) -> Option<Target> {
None
}
fn metadata_loader(&self) -> Box<MetadataLoaderDyn> {
Box::new(metadata::LlvmMetadataLoader)
}

View File

@ -55,9 +55,11 @@ pub trait CodegenBackend {
fn print_passes(&self) {}
fn print_version(&self) {}
/// If this plugin provides additional builtin targets, provide them here.
/// If this plugin provides additional builtin targets, provide the one enabled by the options here.
/// Be careful: this is called *before* init() is called.
fn target_override(&self, opts: &config::Options) -> Option<Target>;
fn target_override(&self, _opts: &config::Options) -> Option<Target> {
None
}
fn metadata_loader(&self) -> Box<MetadataLoaderDyn>;
fn provide(&self, _providers: &mut Providers);

View File

@ -65,7 +65,7 @@ pub fn create_session(
lint_caps: FxHashMap<lint::LintId, lint::Level>,
descriptions: Registry,
) -> (Lrc<Session>, Lrc<Box<dyn CodegenBackend>>) {
let codegen_backend = get_codegen_backend(sopts.debugging_opts.codegen_backend.as_deref());
let codegen_backend = get_codegen_backend(&sopts);
// target_override is documented to be called before init(), so this is okay
let target_override = codegen_backend.target_override(&sopts);
@ -224,13 +224,13 @@ fn load_backend_from_dylib(path: &Path) -> fn() -> Box<dyn CodegenBackend> {
}
}
pub fn get_codegen_backend(codegen_name: Option<&str>) -> Box<dyn CodegenBackend> {
pub fn get_codegen_backend(sopts: &config::Options) -> Box<dyn CodegenBackend> {
static INIT: Once = Once::new();
static mut LOAD: fn() -> Box<dyn CodegenBackend> = || unreachable!();
INIT.call_once(|| {
let codegen_name = codegen_name.unwrap_or("llvm");
let codegen_name = sopts.debugging_opts.codegen_backend.as_deref().unwrap_or("llvm");
let backend = match codegen_name {
filename if filename.contains('.') => load_backend_from_dylib(filename.as_ref()),
codegen_name => get_builtin_codegen_backend(codegen_name),