Skip to content

Commit

Permalink
Auto merge of rust-lang#71807 - Dylan-DPC:rollup-jvb8sd9, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - rust-lang#69274 (Implement RFC 2396: `#[target_feature]` 1.1)
 - rust-lang#71767 (doc: make Stack and StackElement a little pretty)
 - rust-lang#71772 (Mark query function as must_use.)
 - rust-lang#71777 (cleanup: `config::CrateType` -> `CrateType`)
 - rust-lang#71784 (Remove recommendation for unmaintained dirs crate)
 - rust-lang#71785 (Update comment regarding SO_REUSEADDR on Windows)
 - rust-lang#71787 (fix rustdoc warnings)

Failed merges:

r? @ghost
  • Loading branch information
bors committed May 2, 2020
2 parents f05a524 + 97cf378 commit c1e0552
Show file tree
Hide file tree
Showing 57 changed files with 271 additions and 273 deletions.
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/deriving/generic/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub enum Ty<'a> {
Self_,
/// &/Box/ Ty
Ptr(Box<Ty<'a>>, PtrTy),
/// mod::mod::Type<[lifetime], [Params...]>, including a plain type
/// `mod::mod::Type<[lifetime], [Params...]>`, including a plain type
/// parameter, and things like `i32`
Literal(Path<'a>),
/// includes unit
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_builtin_macros/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ fn generate_test_harness(
///
/// By default this expands to
///
/// ```
/// #[main]
/// pub fn main() {
/// extern crate test;
Expand All @@ -242,6 +243,7 @@ fn generate_test_harness(
/// &test_const3,
/// ]);
/// }
/// ```
///
/// Most of the Ident have the usual def-site hygiene for the AST pass. The
/// exception is the `test_const`s. These have a syntax context that has two
Expand Down
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
16 changes: 9 additions & 7 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 @@ -49,12 +49,13 @@ pub struct CodegenCx<'ll, 'tcx> {
pub const_cstr_cache: RefCell<FxHashMap<Symbol, &'ll Value>>,

/// Reverse-direction for const ptrs cast from globals.
/// Key is a Value holding a *T,
/// Val is a Value holding a *[T].
///
/// Key is a Value holding a `*T`,
/// Val is a Value holding a `*[T]`.
///
/// Needed because LLVM loses pointer->pointee association
/// when we ptrcast, and we have to ptrcast during codegen
/// of a [T] const because we form a slice, a (*T,usize) pair, not
/// of a `[T]` const because we form a slice, a `(*T,usize)` pair, not
/// a pointer to an LLVM array type. Similar for trait objects.
pub const_unsized: RefCell<FxHashMap<&'ll Value, &'ll Value>>,

Expand Down Expand Up @@ -101,9 +102,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

0 comments on commit c1e0552

Please sign in to comment.