Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: config::CrateType -> CrateType #71777

Merged
merged 1 commit into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_middle::bug;
use rustc_middle::dep_graph::WorkProduct;
use rustc_middle::middle::exported_symbols::SymbolExportLevel;
use rustc_session::cgu_reuse_tracker::CguReuse;
use rustc_session::config::{self, Lto};
use rustc_session::config::{self, CrateType, Lto};

use std::ffi::{CStr, CString};
use std::fs::File;
Expand All @@ -33,13 +33,10 @@ use std::sync::Arc;
/// compilation session.
pub const THIN_LTO_IMPORTS_INCR_COMP_FILE_NAME: &str = "thin-lto-past-imports.bin";

pub fn crate_type_allows_lto(crate_type: config::CrateType) -> bool {
pub fn crate_type_allows_lto(crate_type: CrateType) -> bool {
match crate_type {
config::CrateType::Executable
| config::CrateType::Staticlib
| config::CrateType::Cdylib => true,

config::CrateType::Dylib | config::CrateType::Rlib | config::CrateType::ProcMacro => false,
CrateType::Executable | CrateType::Staticlib | CrateType::Cdylib => true,
CrateType::Dylib | CrateType::Rlib | CrateType::ProcMacro => false,
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_middle::bug;
use rustc_middle::mir::mono::CodegenUnit;
use rustc_middle::ty::layout::{HasParamEnv, LayoutError, TyAndLayout};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::config::{self, CFGuard, DebugInfo};
use rustc_session::config::{CFGuard, CrateType, DebugInfo};
use rustc_session::Session;
use rustc_span::source_map::{Span, DUMMY_SP};
use rustc_span::symbol::Symbol;
Expand Down Expand Up @@ -101,9 +101,10 @@ fn to_llvm_tls_model(tls_model: TlsModel) -> llvm::ThreadLocalMode {
/// If the list of crate types is not yet known we conservatively return `false`.
pub fn all_outputs_are_pic_executables(sess: &Session) -> bool {
sess.relocation_model() == RelocModel::Pic
&& sess.crate_types.try_get().map_or(false, |crate_types| {
crate_types.iter().all(|ty| *ty == config::CrateType::Executable)
})
&& sess
.crate_types
.try_get()
.map_or(false, |crate_types| crate_types.iter().all(|ty| *ty == CrateType::Executable))
}

fn strip_function_ptr_alignment(data_layout: String) -> String {
Expand Down
71 changes: 35 additions & 36 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use rustc_fs_util::fix_windows_verbatim_for_gcc;
use rustc_hir::def_id::CrateNum;
use rustc_middle::middle::cstore::{EncodedMetadata, LibSource, NativeLibrary, NativeLibraryKind};
use rustc_middle::middle::dependency_format::Linkage;
use rustc_session::config::{
self, CFGuard, DebugInfo, OutputFilenames, OutputType, PrintRequest, Sanitizer,
};
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo};
use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, Sanitizer};
use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename};
use rustc_session::search_paths::PathKind;
/// For all the linkers we support, and information they might
Expand Down Expand Up @@ -55,7 +54,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
// Ignore executable crates if we have -Z no-codegen, as they will error.
if (sess.opts.debugging_opts.no_codegen || !sess.opts.output_types.should_codegen())
&& !output_metadata
&& crate_type == config::CrateType::Executable
&& crate_type == CrateType::Executable
{
continue;
}
Expand All @@ -82,7 +81,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
if outputs.outputs.should_codegen() {
let out_filename = out_filename(sess, crate_type, outputs, crate_name);
match crate_type {
config::CrateType::Rlib => {
CrateType::Rlib => {
let _timer = sess.timer("link_rlib");
link_rlib::<B>(
sess,
Expand All @@ -93,7 +92,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
)
.build();
}
config::CrateType::Staticlib => {
CrateType::Staticlib => {
link_staticlib::<B>(sess, codegen_results, &out_filename, &tmpdir);
}
_ => {
Expand Down Expand Up @@ -236,10 +235,10 @@ pub fn each_linked_rlib(
let mut fmts = None;
for (ty, list) in info.dependency_formats.iter() {
match ty {
config::CrateType::Executable
| config::CrateType::Staticlib
| config::CrateType::Cdylib
| config::CrateType::ProcMacro => {
CrateType::Executable
| CrateType::Staticlib
| CrateType::Cdylib
| CrateType::ProcMacro => {
fmts = Some(list);
break;
}
Expand Down Expand Up @@ -461,7 +460,7 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>(
// links to all upstream files as well.
fn link_natively<'a, B: ArchiveBuilder<'a>>(
sess: &'a Session,
crate_type: config::CrateType,
crate_type: CrateType,
out_filename: &Path,
codegen_results: &CodegenResults,
tmpdir: &Path,
Expand Down Expand Up @@ -664,13 +663,13 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
}
}

fn link_sanitizer_runtime(sess: &Session, crate_type: config::CrateType, linker: &mut dyn Linker) {
fn link_sanitizer_runtime(sess: &Session, crate_type: CrateType, linker: &mut dyn Linker) {
let sanitizer = match &sess.opts.debugging_opts.sanitizer {
Some(s) => s,
None => return,
};

if crate_type != config::CrateType::Executable {
if crate_type != CrateType::Executable {
return;
}

Expand Down Expand Up @@ -826,7 +825,7 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
.crate_types
.borrow()
.iter()
.any(|&x| x != config::CrateType::Rlib && x != config::CrateType::Staticlib);
.any(|&x| x != CrateType::Rlib && x != CrateType::Staticlib);
if !output_linked {
return false;
}
Expand Down Expand Up @@ -1132,8 +1131,8 @@ fn exec_linker(
}

/// Add begin object files defined by the target spec.
fn add_pre_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: config::CrateType) {
let pre_link_objects = if crate_type == config::CrateType::Executable {
fn add_pre_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: CrateType) {
let pre_link_objects = if crate_type == CrateType::Executable {
&sess.target.target.options.pre_link_objects_exe
} else {
&sess.target.target.options.pre_link_objects_dll
Expand All @@ -1142,15 +1141,15 @@ fn add_pre_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: config
cmd.add_object(&get_object_file_path(sess, obj));
}

if crate_type == config::CrateType::Executable && sess.crt_static(Some(crate_type)) {
if crate_type == CrateType::Executable && sess.crt_static(Some(crate_type)) {
for obj in &sess.target.target.options.pre_link_objects_exe_crt {
cmd.add_object(&get_object_file_path(sess, obj));
}
}
}

/// Add end object files defined by the target spec.
fn add_post_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: config::CrateType) {
fn add_post_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: CrateType) {
for obj in &sess.target.target.options.post_link_objects {
cmd.add_object(&get_object_file_path(sess, obj));
}
Expand All @@ -1167,7 +1166,7 @@ fn add_pre_link_args(
cmd: &mut dyn Linker,
sess: &Session,
flavor: LinkerFlavor,
crate_type: config::CrateType,
crate_type: CrateType,
) {
if let Some(args) = sess.target.target.options.pre_link_args.get(&flavor) {
cmd.args(args);
Expand Down Expand Up @@ -1197,13 +1196,13 @@ fn add_late_link_args(
cmd: &mut dyn Linker,
sess: &Session,
flavor: LinkerFlavor,
crate_type: config::CrateType,
crate_type: CrateType,
codegen_results: &CodegenResults,
) {
if let Some(args) = sess.target.target.options.late_link_args.get(&flavor) {
cmd.args(args);
}
let any_dynamic_crate = crate_type == config::CrateType::Dylib
let any_dynamic_crate = crate_type == CrateType::Dylib
|| codegen_results.crate_info.dependency_formats.iter().any(|(ty, list)| {
*ty == crate_type && list.iter().any(|&linkage| linkage == Linkage::Dynamic)
});
Expand Down Expand Up @@ -1243,13 +1242,13 @@ fn add_local_crate_allocator_objects(cmd: &mut dyn Linker, codegen_results: &Cod
/// Add object files containing metadata for the current crate.
fn add_local_crate_metadata_objects(
cmd: &mut dyn Linker,
crate_type: config::CrateType,
crate_type: CrateType,
codegen_results: &CodegenResults,
) {
// When linking a dynamic library, we put the metadata into a section of the
// executable. This metadata is in a separate object file from the main
// object file, so we link that in here.
if crate_type == config::CrateType::Dylib || crate_type == config::CrateType::ProcMacro {
if crate_type == CrateType::Dylib || crate_type == CrateType::ProcMacro {
if let Some(obj) = codegen_results.metadata_module.as_ref().and_then(|m| m.object.as_ref())
{
cmd.add_object(obj);
Expand All @@ -1263,7 +1262,7 @@ fn add_local_crate_metadata_objects(
fn link_local_crate_native_libs_and_dependent_crate_libs<'a, B: ArchiveBuilder<'a>>(
cmd: &mut dyn Linker,
sess: &'a Session,
crate_type: config::CrateType,
crate_type: CrateType,
codegen_results: &CodegenResults,
tmpdir: &Path,
) {
Expand Down Expand Up @@ -1326,10 +1325,10 @@ fn add_position_independent_executable_args(
cmd: &mut dyn Linker,
sess: &Session,
flavor: LinkerFlavor,
crate_type: config::CrateType,
crate_type: CrateType,
codegen_results: &CodegenResults,
) {
if crate_type != config::CrateType::Executable {
if crate_type != CrateType::Executable {
return;
}

Expand Down Expand Up @@ -1407,7 +1406,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
path: &Path,
flavor: LinkerFlavor,
sess: &'a Session,
crate_type: config::CrateType,
crate_type: CrateType,
tmpdir: &Path,
out_filename: &Path,
codegen_results: &CodegenResults,
Expand Down Expand Up @@ -1463,7 +1462,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
cmd.output_filename(out_filename);

// OBJECT-FILES-NO, AUDIT-ORDER
if crate_type == config::CrateType::Executable && sess.target.target.options.is_like_windows {
if crate_type == CrateType::Executable && sess.target.target.options.is_like_windows {
if let Some(ref s) = codegen_results.windows_subsystem {
cmd.subsystem(s);
}
Expand All @@ -1486,7 +1485,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
// Try to strip as much out of the generated object by removing unused
// sections if possible. See more comments in linker.rs
if !sess.opts.cg.link_dead_code {
let keep_metadata = crate_type == config::CrateType::Dylib;
let keep_metadata = crate_type == CrateType::Dylib;
cmd.gc_sections(keep_metadata);
}

Expand Down Expand Up @@ -1522,10 +1521,10 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(

// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
// Tell the linker what we're doing.
if crate_type != config::CrateType::Executable {
if crate_type != CrateType::Executable {
cmd.build_dylib(out_filename);
}
if crate_type == config::CrateType::Executable && sess.crt_static(Some(crate_type)) {
if crate_type == CrateType::Executable && sess.crt_static(Some(crate_type)) {
cmd.build_static_executable();
}

Expand Down Expand Up @@ -1619,7 +1618,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
cmd: &mut dyn Linker,
sess: &'a Session,
codegen_results: &CodegenResults,
crate_type: config::CrateType,
crate_type: CrateType,
tmpdir: &Path,
) {
// All of the heavy lifting has previously been accomplished by the
Expand Down Expand Up @@ -1780,7 +1779,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
sess: &'a Session,
codegen_results: &CodegenResults,
tmpdir: &Path,
crate_type: config::CrateType,
crate_type: CrateType,
cnum: CrateNum,
) {
let src = &codegen_results.crate_info.used_crate_source[&cnum];
Expand All @@ -1796,7 +1795,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(

if (!are_upstream_rust_objects_already_included(sess)
|| ignored_for_lto(sess, &codegen_results.crate_info, cnum))
&& crate_type != config::CrateType::Dylib
&& crate_type != CrateType::Dylib
&& !skip_native
{
cmd.link_rlib(&fix_windows_verbatim_for_gcc(cratepath));
Expand Down Expand Up @@ -1857,7 +1856,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
// Note, though, that we don't want to include the whole of a
// compiler-builtins crate (e.g., compiler-rt) because it'll get
// repeatedly linked anyway.
if crate_type == config::CrateType::Dylib
if crate_type == CrateType::Dylib
&& codegen_results.crate_info.compiler_builtins != Some(cnum)
{
cmd.link_whole_rlib(&fix_windows_verbatim_for_gcc(&dst));
Expand Down Expand Up @@ -1905,7 +1904,7 @@ fn add_upstream_native_libraries(
cmd: &mut dyn Linker,
sess: &Session,
codegen_results: &CodegenResults,
crate_type: config::CrateType,
crate_type: CrateType,
) {
// Be sure to use a topological sorting of crates because there may be
// interdependencies between native libraries. When passing -nodefaultlibs,
Expand Down
17 changes: 8 additions & 9 deletions src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@ use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
use rustc_middle::ty::Instance;
use rustc_middle::ty::{SymbolName, TyCtxt};
use rustc_session::config::{self, Sanitizer};
use rustc_session::config::{CrateType, Sanitizer};

pub fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
crates_export_threshold(&tcx.sess.crate_types.borrow())
}

fn crate_export_threshold(crate_type: config::CrateType) -> SymbolExportLevel {
fn crate_export_threshold(crate_type: CrateType) -> SymbolExportLevel {
match crate_type {
config::CrateType::Executable
| config::CrateType::Staticlib
| config::CrateType::ProcMacro
| config::CrateType::Cdylib => SymbolExportLevel::C,
config::CrateType::Rlib | config::CrateType::Dylib => SymbolExportLevel::Rust,
CrateType::Executable | CrateType::Staticlib | CrateType::ProcMacro | CrateType::Cdylib => {
SymbolExportLevel::C
}
CrateType::Rlib | CrateType::Dylib => SymbolExportLevel::Rust,
}
}

pub fn crates_export_threshold(crate_types: &[config::CrateType]) -> SymbolExportLevel {
pub fn crates_export_threshold(crate_types: &[CrateType]) -> SymbolExportLevel {
if crate_types
.iter()
.any(|&crate_type| crate_export_threshold(crate_type) == SymbolExportLevel::Rust)
Expand Down Expand Up @@ -213,7 +212,7 @@ fn exported_symbols_provider_local(
}));
}

if tcx.sess.crate_types.borrow().contains(&config::CrateType::Dylib) {
if tcx.sess.crate_types.borrow().contains(&CrateType::Dylib) {
let symbol_name = metadata_symbol_name(tcx);
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name));

Expand Down
Loading