Skip to content

Commit 4a603e4

Browse files
committed
Auto merge of #159579 - JonathanBrouwer:rollup-TlvztYP, r=JonathanBrouwer
Rollup of 5 pull requests Successful merges: - #159188 (Always generate private and hidden items in JSON docs of the stdlib) - #159567 (Update rustc crate crossbeam-epoch to 0.9.20) - #150732 (Convert `-Ctarget-cpu` into a target-modifier for AVR, AMDGCN and NVPTX ) - #159549 (restrict const-eval-related 'content' triggers to library/ folder) - #159570 (fix ICE in opsem inhabitedness check)
2 parents 9f36de7 + 1271efe commit 4a603e4

49 files changed

Lines changed: 574 additions & 62 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,9 +1001,9 @@ dependencies = [
10011001

10021002
[[package]]
10031003
name = "crossbeam-epoch"
1004-
version = "0.9.18"
1004+
version = "0.9.20"
10051005
source = "registry+https://github.com/rust-lang/crates.io-index"
1006-
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
1006+
checksum = "2d6914041f254d6e9176c01941b21115dcfb7089e55135a35411081bd106ef3f"
10071007
dependencies = [
10081008
"crossbeam-utils",
10091009
]

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use rustc_codegen_ssa::{CompiledModules, CrateInfo, TargetConfig, back};
4242
use rustc_log::tracing::info;
4343
use rustc_middle::dep_graph::WorkProductMap;
4444
use rustc_session::Session;
45-
use rustc_session::config::OutputFilenames;
45+
use rustc_session::config::{NATIVE_CPU, OutputFilenames};
4646
use rustc_span::{Symbol, sym};
4747
use rustc_target::spec::{Arch, CfgAbi, Env, Os};
4848

@@ -341,7 +341,7 @@ fn build_isa(sess: &Session, jit: bool) -> Arc<dyn TargetIsa + 'static> {
341341
let flags = settings::Flags::new(flags_builder);
342342

343343
let isa_builder = match sess.opts.cg.target_cpu.as_deref() {
344-
Some("native") => cranelift_native::builder_with_options(true).unwrap(),
344+
Some(NATIVE_CPU) => cranelift_native::builder_with_options(true).unwrap(),
345345
Some(value) => {
346346
let mut builder =
347347
cranelift_codegen::isa::lookup(target_triple.clone()).unwrap_or_else(|err| {

compiler/rustc_codegen_gcc/src/gcc_util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use gccjit::Context;
33
use rustc_codegen_ssa::target_features;
44
use rustc_data_structures::smallvec::{SmallVec, smallvec};
55
use rustc_session::Session;
6+
use rustc_session::config::NATIVE_CPU;
67
use rustc_target::spec::Arch;
78

89
fn gcc_features_by_flags(sess: &Session, features: &mut Vec<String>) {
@@ -115,7 +116,7 @@ fn arch_to_gcc(name: &str) -> &str {
115116
}
116117

117118
fn handle_native(name: &str) -> &str {
118-
if name != "native" {
119+
if name != NATIVE_CPU {
119120
return arch_to_gcc(name);
120121
}
121122

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
1414
use rustc_fs_util::path_to_c_string;
1515
use rustc_middle::bug;
1616
use rustc_session::Session;
17-
use rustc_session::config::{PrintKind, PrintRequest};
17+
use rustc_session::config::{NATIVE_CPU, PrintKind, PrintRequest};
1818
use rustc_target::spec::{
1919
Arch, CfgAbi, Env, MergeFunctions, Os, PanicStrategy, SmallDataThresholdSupport,
2020
};
@@ -514,10 +514,12 @@ fn print_target_cpus(sess: &Session, tm: &llvm::TargetMachine, out: &mut String)
514514

515515
// Only print the "native" entry when host and target are the same arch,
516516
// since otherwise it could be wrong or misleading.
517-
if sess.host.arch == sess.target.arch {
517+
// Also do not print it if `requires_consistent_cpu` is set, because in this case
518+
// "native" would be rejected.
519+
if sess.host.arch == sess.target.arch && !sess.target.requires_consistent_cpu {
518520
let host = get_host_cpu_name();
519521
cpus.push_front(Cpu {
520-
cpu_name: "native",
522+
cpu_name: NATIVE_CPU,
521523
remark: format!(" - Select the CPU of the current host (currently {host})."),
522524
});
523525
}
@@ -612,7 +614,7 @@ fn get_host_cpu_name() -> &'static str {
612614
/// LLVM. Otherwise, the string is returned as-is.
613615
fn handle_native(cpu_name: &str) -> &str {
614616
match cpu_name {
615-
"native" => get_host_cpu_name(),
617+
NATIVE_CPU => get_host_cpu_name(),
616618
_ => cpu_name,
617619
}
618620
}
@@ -666,7 +668,7 @@ pub(crate) fn global_llvm_features(sess: &Session, only_base_features: bool) ->
666668

667669
// -Ctarget-cpu=native
668670
match sess.opts.cg.target_cpu {
669-
Some(ref s) if s == "native" => {
671+
Some(ref s) if s == NATIVE_CPU => {
670672
// We have already figured out the actual CPU name with `LLVMRustGetHostCPUName` and set
671673
// that for LLVM, so the features implied by that CPU name will be available everywhere.
672674
// However, that is not sufficient: e.g. `skylake` alone is not sufficient to tell if

compiler/rustc_metadata/src/creader.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ impl CStore {
380380
flag_name,
381381
flag_name_prefixed,
382382
extern_value: extern_value.to_string(),
383+
has_extern_value: !extern_value.is_empty(),
383384
})
384385
}
385386
(Some(local_value), None) => {
@@ -390,6 +391,7 @@ impl CStore {
390391
flag_name,
391392
flag_name_prefixed,
392393
local_value: local_value.to_string(),
394+
has_local_value: !local_value.is_empty(),
393395
})
394396
}
395397
(None, None) => panic!("Incorrect target modifiers report_diff(None, None)"),

compiler/rustc_metadata/src/diagnostics.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,16 @@ pub(crate) struct IncompatibleTargetModifiers {
606606
"the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely"
607607
)]
608608
#[note(
609-
"unset `{$flag_name_prefixed}` in this crate is incompatible with `{$flag_name_prefixed}={$extern_value}` in dependency `{$extern_crate}`"
609+
"`{$flag_name_prefixed}` is unset in this crate which is incompatible with {$has_extern_value ->
610+
[false] `{$flag_name_prefixed}` being set
611+
*[other] `{$flag_name_prefixed}={$extern_value}`
612+
} in dependency `{$extern_crate}`"
610613
)]
611614
#[help(
612-
"set `{$flag_name_prefixed}={$extern_value}` in this crate or unset `{$flag_name_prefixed}` in `{$extern_crate}`"
615+
"set {$has_extern_value ->
616+
[false] `{$flag_name_prefixed}`
617+
*[other] `{$flag_name_prefixed}={$extern_value}`
618+
} in this crate or unset `{$flag_name_prefixed}` in `{$extern_crate}`"
613619
)]
614620
#[help(
615621
"if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error"
@@ -622,6 +628,7 @@ pub(crate) struct IncompatibleTargetModifiersLMissed {
622628
pub flag_name: String,
623629
pub flag_name_prefixed: String,
624630
pub extern_value: String,
631+
pub has_extern_value: bool,
625632
}
626633

627634
#[derive(Diagnostic)]
@@ -630,10 +637,16 @@ pub(crate) struct IncompatibleTargetModifiersLMissed {
630637
"the `{$flag_name_prefixed}` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely"
631638
)]
632639
#[note(
633-
"`{$flag_name_prefixed}={$local_value}` in this crate is incompatible with unset `{$flag_name_prefixed}` in dependency `{$extern_crate}`"
640+
"{$has_local_value ->
641+
[false] `{$flag_name_prefixed}` being set
642+
*[other] `{$flag_name_prefixed}={$local_value}`
643+
} in this crate is incompatible with `{$flag_name_prefixed}` being unset in dependency `{$extern_crate}`"
634644
)]
635645
#[help(
636-
"unset `{$flag_name_prefixed}` in this crate or set `{$flag_name_prefixed}={$local_value}` in `{$extern_crate}`"
646+
"unset `{$flag_name_prefixed}` in this crate or set {$has_local_value ->
647+
[false] `{$flag_name_prefixed}`
648+
*[other] `{$flag_name_prefixed}={$local_value}`
649+
} in `{$extern_crate}`"
637650
)]
638651
#[help(
639652
"if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch={$flag_name}` to silence this error"
@@ -646,6 +659,7 @@ pub(crate) struct IncompatibleTargetModifiersRMissed {
646659
pub flag_name: String,
647660
pub flag_name_prefixed: String,
648661
pub local_value: String,
662+
pub has_local_value: bool,
649663
}
650664

651665
#[derive(Diagnostic)]

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ impl MetadataBlob {
750750
"lang_items".to_owned(),
751751
"features".to_owned(),
752752
"items".to_owned(),
753+
"target_modifiers".to_owned(),
753754
];
754755
let ls_kinds = if ls_kinds.contains(&"all".to_owned()) { &all_ls_kinds } else { ls_kinds };
755756

@@ -919,11 +920,28 @@ impl MetadataBlob {
919920

920921
write!(out, "\n")?;
921922
}
923+
"target_modifiers" => {
924+
writeln!(out, "=Target modifiers=")?;
925+
926+
for modifier in root.decode_target_modifiers(self) {
927+
let extended = modifier.extend();
928+
929+
writeln!(
930+
out,
931+
"-{}{}={} [{}]",
932+
extended.prefix,
933+
extended.name,
934+
modifier.value_name,
935+
extended.tech_value,
936+
)?;
937+
}
938+
}
922939

923940
_ => {
924941
writeln!(
925942
out,
926-
"unknown -Zls kind. allowed values are: all, root, lang_items, features, items"
943+
"unknown -Zls kind. allowed values are: all, root, lang_items, features, items, \
944+
target_modifiers"
927945
)?;
928946
}
929947
}

compiler/rustc_middle/src/ty/inhabitedness/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,12 @@ fn is_opsem_inhabited_recursor<'tcx, SEEN>(
339339
})
340340
}
341341

342-
ty::Error(_)
343-
| ty::Infer(..)
342+
ty::Error(_error_guaranteed) => {
343+
// We have a token proving there was an error, so we can return a dummy value.
344+
true
345+
}
346+
347+
ty::Infer(..)
344348
| ty::Placeholder(..)
345349
| ty::Bound(..)
346350
| ty::Param(..)

compiler/rustc_session/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ mod native_libs;
4646
mod print_request;
4747
pub mod sigpipe;
4848

49+
/// Special CPU name requesting the CPU of the current host.
50+
pub const NATIVE_CPU: &str = "native";
51+
4952
/// The different settings that the `-C strip` flag can have.
5053
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
5154
pub enum Strip {

compiler/rustc_session/src/diagnostics.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,3 +716,17 @@ pub(crate) struct ThinLtoNotSupportedByBackend;
716716
#[derive(Diagnostic)]
717717
#[diag("`-Zpacked-stack` is only supported on s390x")]
718718
pub(crate) struct UnsupportedPackedStack;
719+
720+
#[derive(Diagnostic)]
721+
#[diag("`-Ctarget-cpu=native` is not allowed for target `{$target_triple}`")]
722+
#[note("this target requires consistent `-Ctarget-cpu` values across all crates")]
723+
#[help(
724+
"specify the target CPU explicitly {$need_explicit_cpu ->
725+
[false] or leave it blank to use the default
726+
*[other] {\"\"}
727+
}"
728+
)]
729+
pub(crate) struct NativeTargetCpuNotAllowed<'a> {
730+
pub(crate) target_triple: &'a TargetTuple,
731+
pub(crate) need_explicit_cpu: bool,
732+
}

0 commit comments

Comments
 (0)