diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-05-02 18:27:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-02 18:27:39 +0200 |
| commit | 590d201e0b563b33804a78059e243f51f5060190 (patch) | |
| tree | 477c66fee096f2880cbdae4fbc612aed544f2a2c /src/librustc_codegen_ssa | |
| parent | 78dc7e15c98afa9acbba9be5a36e167c711044e2 (diff) | |
| parent | ff86a4582021fe0f5be19b54c64693ec8ff1e82f (diff) | |
| download | rust-590d201e0b563b33804a78059e243f51f5060190.tar.gz rust-590d201e0b563b33804a78059e243f51f5060190.zip | |
Rollup merge of #71777 - petrochenkov:crtype, r=Mark-Simulacrum
cleanup: `config::CrateType` -> `CrateType`
Diffstat (limited to 'src/librustc_codegen_ssa')
| -rw-r--r-- | src/librustc_codegen_ssa/back/link.rs | 71 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/back/symbol_export.rs | 17 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/back/write.rs | 13 |
3 files changed, 49 insertions, 52 deletions
diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 12cd58924ae..7a0e1e2c638 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -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 @@ -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; } @@ -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, @@ -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); } _ => { @@ -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; } @@ -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, @@ -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; } @@ -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; } @@ -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 @@ -1142,7 +1141,7 @@ 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)); } @@ -1150,7 +1149,7 @@ fn add_pre_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: config } /// 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)); } @@ -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); @@ -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) }); @@ -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); @@ -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, ) { @@ -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; } @@ -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, @@ -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); } @@ -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); } @@ -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(); } @@ -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 @@ -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]; @@ -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)); @@ -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)); @@ -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, diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 338211ca11f..c0272e1cd2d 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -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) @@ -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)); diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index 31bf064ad91..c53fc5551fd 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -28,9 +28,8 @@ use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::middle::exported_symbols::SymbolExportLevel; use rustc_middle::ty::TyCtxt; use rustc_session::cgu_reuse_tracker::CguReuseTracker; -use rustc_session::config::{ - self, Lto, OutputFilenames, OutputType, Passes, Sanitizer, SwitchWithOptPath, -}; +use rustc_session::config::{self, CrateType, Lto, OutputFilenames, OutputType}; +use rustc_session::config::{Passes, Sanitizer, SwitchWithOptPath}; use rustc_session::Session; use rustc_span::hygiene::ExpnId; use rustc_span::source_map::SourceMap; @@ -288,7 +287,7 @@ pub struct CodegenContext<B: WriteBackendMethods> { pub fewer_names: bool, pub exported_symbols: Option<Arc<ExportedSymbols>>, pub opts: Arc<config::Options>, - pub crate_types: Vec<config::CrateType>, + pub crate_types: Vec<CrateType>, pub each_linked_rlib_for_lto: Vec<(CrateNum, PathBuf)>, pub output_filenames: Arc<OutputFilenames>, pub regular_module_config: Arc<ModuleConfig>, @@ -375,7 +374,7 @@ pub struct CompiledModules { fn need_crate_bitcode_for_rlib(sess: &Session) -> bool { sess.opts.cg.embed_bitcode - && sess.crate_types.borrow().contains(&config::CrateType::Rlib) + && sess.crate_types.borrow().contains(&CrateType::Rlib) && sess.opts.output_types.contains_key(&OutputType::Exe) } @@ -760,7 +759,7 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>( // require LTO so the request for LTO is always unconditionally // passed down to the backend, but we don't actually want to do // anything about it yet until we've got a final product. - let is_rlib = cgcx.crate_types.len() == 1 && cgcx.crate_types[0] == config::CrateType::Rlib; + let is_rlib = cgcx.crate_types.len() == 1 && cgcx.crate_types[0] == CrateType::Rlib; // Metadata modules never participate in LTO regardless of the lto // settings. @@ -1813,7 +1812,7 @@ fn msvc_imps_needed(tcx: TyCtxt<'_>) -> bool { ); tcx.sess.target.target.options.is_like_msvc && - tcx.sess.crate_types.borrow().iter().any(|ct| *ct == config::CrateType::Rlib) && + tcx.sess.crate_types.borrow().iter().any(|ct| *ct == CrateType::Rlib) && // ThinLTO can't handle this workaround in all cases, so we don't // emit the `__imp_` symbols. Instead we make them unnecessary by disallowing // dynamic linking when linker plugin LTO is enabled. |
