Skip to content

Commit 4596f4f

Browse files
committed
Auto merge of #103787 - notriddle:rollup-q1vmxsb, r=notriddle
Rollup of 8 pull requests Successful merges: - #97971 (Enable varargs support for calling conventions other than C or cdecl ) - #101428 (Add mir building test directory) - #101944 (rustdoc: clean up `#toggle-all-docs`) - #102101 (check lld version to choose correct option to disable multi-threading in tests) - #102689 (Add a tier 3 target for the Sony PlayStation 1) - #103746 (rustdoc: add support for incoherent impls on structs and traits) - #103758 (Add regression test for reexports in search results) - #103764 (All verbosity checks in `PrettyPrinter` now go through `PrettyPrinter::should_print_verbose`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d726c84 + e6ffd96 commit 4596f4f

File tree

83 files changed

+547
-188
lines changed

Some content is hidden

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

83 files changed

+547
-188
lines changed

compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::definitions::DisambiguatedDefPathData;
44
use rustc_middle::mir::interpret::{Allocation, ConstAllocation};
55
use rustc_middle::ty::{
66
self,
7-
print::{with_no_verbose_constants, PrettyPrinter, Print, Printer},
7+
print::{PrettyPrinter, Print, Printer},
88
subst::{GenericArg, GenericArgKind},
99
Ty, TyCtxt,
1010
};
@@ -179,6 +179,11 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
179179

180180
Ok(self)
181181
}
182+
183+
fn should_print_verbose(&self) -> bool {
184+
// `std::any::type_name` should never print verbose type names
185+
false
186+
}
182187
}
183188

184189
impl Write for AbsolutePathPrinter<'_> {
@@ -190,9 +195,7 @@ impl Write for AbsolutePathPrinter<'_> {
190195

191196
/// Directly returns an `Allocation` containing an absolute path representation of the given type.
192197
pub(crate) fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ConstAllocation<'tcx> {
193-
let path = with_no_verbose_constants!(
194-
AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path
195-
);
198+
let path = AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path;
196199
let alloc = Allocation::from_bytes_byte_aligned_immutable(path.into_bytes());
197200
tcx.intern_const_alloc(alloc)
198201
}

compiler/rustc_feature/src/active.rs

+3
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ declare_features! (
388388
(active, exclusive_range_pattern, "1.11.0", Some(37854), None),
389389
/// Allows exhaustive pattern matching on types that contain uninhabited types.
390390
(active, exhaustive_patterns, "1.13.0", Some(51085), None),
391+
/// Allows using `efiapi`, `sysv64` and `win64` as calling convention
392+
/// for functions with varargs.
393+
(active, extended_varargs_abi_support, "1.65.0", Some(100189), None),
391394
/// Allows defining `extern type`s.
392395
(active, extern_types, "1.23.0", Some(43467), None),
393396
/// Allows the use of `#[ffi_const]` on foreign functions.

compiler/rustc_hir_analysis/src/lib.rs

+33-13
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ use rustc_middle::middle;
106106
use rustc_middle::ty::query::Providers;
107107
use rustc_middle::ty::{self, Ty, TyCtxt};
108108
use rustc_middle::util;
109-
use rustc_session::config::EntryFnType;
109+
use rustc_session::{config::EntryFnType, parse::feature_err};
110110
use rustc_span::{symbol::sym, Span, DUMMY_SP};
111111
use rustc_target::spec::abi::Abi;
112112
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
@@ -118,20 +118,40 @@ use astconv::AstConv;
118118
use bounds::Bounds;
119119

120120
fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi, span: Span) {
121-
match (decl.c_variadic, abi) {
122-
// The function has the correct calling convention, or isn't a "C-variadic" function.
123-
(false, _) | (true, Abi::C { .. }) | (true, Abi::Cdecl { .. }) => {}
124-
// The function is a "C-variadic" function with an incorrect calling convention.
125-
(true, _) => {
126-
let mut err = struct_span_err!(
127-
tcx.sess,
121+
const ERROR_HEAD: &str = "C-variadic function must have a compatible calling convention";
122+
const CONVENTIONS_UNSTABLE: &str = "`C`, `cdecl`, `win64`, `sysv64` or `efiapi`";
123+
const CONVENTIONS_STABLE: &str = "`C` or `cdecl`";
124+
const UNSTABLE_EXPLAIN: &str =
125+
"using calling conventions other than `C` or `cdecl` for varargs functions is unstable";
126+
127+
if !decl.c_variadic || matches!(abi, Abi::C { .. } | Abi::Cdecl { .. }) {
128+
return;
129+
}
130+
131+
let extended_abi_support = tcx.features().extended_varargs_abi_support;
132+
let conventions = match (extended_abi_support, abi.supports_varargs()) {
133+
// User enabled additional ABI support for varargs and function ABI matches those ones.
134+
(true, true) => return,
135+
136+
// Using this ABI would be ok, if the feature for additional ABI support was enabled.
137+
// Return CONVENTIONS_STABLE, because we want the other error to look the same.
138+
(false, true) => {
139+
feature_err(
140+
&tcx.sess.parse_sess,
141+
sym::extended_varargs_abi_support,
128142
span,
129-
E0045,
130-
"C-variadic function must have C or cdecl calling convention"
131-
);
132-
err.span_label(span, "C-variadics require C or cdecl calling convention").emit();
143+
UNSTABLE_EXPLAIN,
144+
)
145+
.emit();
146+
CONVENTIONS_STABLE
133147
}
134-
}
148+
149+
(false, false) => CONVENTIONS_STABLE,
150+
(true, false) => CONVENTIONS_UNSTABLE,
151+
};
152+
153+
let mut err = struct_span_err!(tcx.sess, span, E0045, "{}, like {}", ERROR_HEAD, conventions);
154+
err.span_label(span, ERROR_HEAD).emit();
135155
}
136156

137157
fn require_same_types<'tcx>(

compiler/rustc_middle/src/ty/print/pretty.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ thread_local! {
6363
static NO_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
6464
static NO_QUERIES: Cell<bool> = const { Cell::new(false) };
6565
static NO_VISIBLE_PATH: Cell<bool> = const { Cell::new(false) };
66-
static NO_VERBOSE_CONSTANTS: Cell<bool> = const { Cell::new(false) };
6766
}
6867

6968
macro_rules! define_helper {
@@ -118,9 +117,6 @@ define_helper!(
118117
/// Prevent selection of visible paths. `Display` impl of DefId will prefer
119118
/// visible (public) reexports of types as paths.
120119
fn with_no_visible_paths(NoVisibleGuard, NO_VISIBLE_PATH);
121-
/// Prevent verbose printing of constants. Verbose printing of constants is
122-
/// never desirable in some contexts like `std::any::type_name`.
123-
fn with_no_verbose_constants(NoVerboseConstantsGuard, NO_VERBOSE_CONSTANTS);
124120
);
125121

126122
/// The "region highlights" are used to control region printing during
@@ -600,7 +596,7 @@ pub trait PrettyPrinter<'tcx>:
600596
}
601597
ty::FnPtr(ref bare_fn) => p!(print(bare_fn)),
602598
ty::Infer(infer_ty) => {
603-
let verbose = self.tcx().sess.verbose();
599+
let verbose = self.should_print_verbose();
604600
if let ty::TyVar(ty_vid) = infer_ty {
605601
if let Some(name) = self.ty_infer_name(ty_vid) {
606602
p!(write("{}", name))
@@ -642,7 +638,7 @@ pub trait PrettyPrinter<'tcx>:
642638
p!(print_def_path(def_id, &[]));
643639
}
644640
ty::Projection(ref data) => {
645-
if !(self.tcx().sess.verbose() || NO_QUERIES.with(|q| q.get()))
641+
if !(self.should_print_verbose() || NO_QUERIES.with(|q| q.get()))
646642
&& self.tcx().def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder
647643
{
648644
return self.pretty_print_opaque_impl_type(data.item_def_id, data.substs);
@@ -658,7 +654,7 @@ pub trait PrettyPrinter<'tcx>:
658654
// only affect certain debug messages (e.g. messages printed
659655
// from `rustc_middle::ty` during the computation of `tcx.predicates_of`),
660656
// and should have no effect on any compiler output.
661-
if self.tcx().sess.verbose() || NO_QUERIES.with(|q| q.get()) {
657+
if self.should_print_verbose() || NO_QUERIES.with(|q| q.get()) {
662658
p!(write("Opaque({:?}, {:?})", def_id, substs));
663659
return Ok(self);
664660
}
@@ -689,7 +685,7 @@ pub trait PrettyPrinter<'tcx>:
689685
hir::Movability::Static => p!("static "),
690686
}
691687

692-
if !self.tcx().sess.verbose() {
688+
if !self.should_print_verbose() {
693689
p!("generator");
694690
// FIXME(eddyb) should use `def_span`.
695691
if let Some(did) = did.as_local() {
@@ -725,7 +721,7 @@ pub trait PrettyPrinter<'tcx>:
725721
}
726722
ty::Closure(did, substs) => {
727723
p!(write("["));
728-
if !self.tcx().sess.verbose() {
724+
if !self.should_print_verbose() {
729725
p!(write("closure"));
730726
// FIXME(eddyb) should use `def_span`.
731727
if let Some(did) = did.as_local() {
@@ -763,7 +759,7 @@ pub trait PrettyPrinter<'tcx>:
763759
}
764760
ty::Array(ty, sz) => {
765761
p!("[", print(ty), "; ");
766-
if !NO_VERBOSE_CONSTANTS.with(|flag| flag.get()) && self.tcx().sess.verbose() {
762+
if self.should_print_verbose() {
767763
p!(write("{:?}", sz));
768764
} else if let ty::ConstKind::Unevaluated(..) = sz.kind() {
769765
// Do not try to evaluate unevaluated constants. If we are const evaluating an
@@ -1077,7 +1073,7 @@ pub trait PrettyPrinter<'tcx>:
10771073

10781074
// Special-case `Fn(...) -> ...` and re-sugar it.
10791075
let fn_trait_kind = cx.tcx().fn_trait_kind_from_lang_item(principal.def_id);
1080-
if !cx.tcx().sess.verbose() && fn_trait_kind.is_some() {
1076+
if !cx.should_print_verbose() && fn_trait_kind.is_some() {
10811077
if let ty::Tuple(tys) = principal.substs.type_at(0).kind() {
10821078
let mut projections = predicates.projection_bounds();
10831079
if let (Some(proj), None) = (projections.next(), projections.next()) {
@@ -1185,7 +1181,7 @@ pub trait PrettyPrinter<'tcx>:
11851181
) -> Result<Self::Const, Self::Error> {
11861182
define_scoped_cx!(self);
11871183

1188-
if !NO_VERBOSE_CONSTANTS.with(|flag| flag.get()) && self.tcx().sess.verbose() {
1184+
if self.should_print_verbose() {
11891185
p!(write("Const({:?}: {:?})", ct.kind(), ct.ty()));
11901186
return Ok(self);
11911187
}
@@ -1420,7 +1416,7 @@ pub trait PrettyPrinter<'tcx>:
14201416
) -> Result<Self::Const, Self::Error> {
14211417
define_scoped_cx!(self);
14221418

1423-
if !NO_VERBOSE_CONSTANTS.with(|flag| flag.get()) && self.tcx().sess.verbose() {
1419+
if self.should_print_verbose() {
14241420
p!(write("ValTree({:?}: ", valtree), print(ty), ")");
14251421
return Ok(self);
14261422
}
@@ -1564,6 +1560,10 @@ pub trait PrettyPrinter<'tcx>:
15641560
Ok(cx)
15651561
})
15661562
}
1563+
1564+
fn should_print_verbose(&self) -> bool {
1565+
self.tcx().sess.verbose()
1566+
}
15671567
}
15681568

15691569
// HACK(eddyb) boxed to avoid moving around a large struct by-value.
@@ -1839,7 +1839,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
18391839
}
18401840
}
18411841

1842-
let verbose = self.tcx.sess.verbose();
1842+
let verbose = self.should_print_verbose();
18431843
disambiguated_data.fmt_maybe_verbose(&mut self, verbose)?;
18441844

18451845
self.empty_path = false;
@@ -1940,7 +1940,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
19401940
return true;
19411941
}
19421942

1943-
if self.tcx.sess.verbose() {
1943+
if self.should_print_verbose() {
19441944
return true;
19451945
}
19461946

@@ -2012,7 +2012,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
20122012
return Ok(self);
20132013
}
20142014

2015-
if self.tcx.sess.verbose() {
2015+
if self.should_print_verbose() {
20162016
p!(write("{:?}", region));
20172017
return Ok(self);
20182018
}
@@ -2218,7 +2218,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
22182218
// aren't named. Eventually, we might just want this as the default, but
22192219
// this is not *quite* right and changes the ordering of some output
22202220
// anyways.
2221-
let (new_value, map) = if self.tcx().sess.verbose() {
2221+
let (new_value, map) = if self.should_print_verbose() {
22222222
let regions: Vec<_> = value
22232223
.bound_vars()
22242224
.into_iter()

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn mir_const<'tcx>(
288288

289289
let mut body = tcx.mir_built(def).steal();
290290

291-
rustc_middle::mir::dump_mir(tcx, None, "mir_map", &0, &body, |_, _| Ok(()));
291+
pass_manager::dump_mir_for_phase_change(tcx, &body);
292292

293293
pm::run_passes(
294294
tcx,

compiler/rustc_mir_transform/src/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
845845
span,
846846
);
847847

848-
rustc_middle::mir::dump_mir(tcx, None, "mir_map", &0, &body, |_, _| Ok(()));
848+
crate::pass_manager::dump_mir_for_phase_change(tcx, &body);
849849

850850
body
851851
}

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ symbols! {
694694
export_name,
695695
expr,
696696
extended_key_value_attributes,
697+
extended_varargs_abi_support,
697698
extern_absolute_paths,
698699
extern_crate_item_prelude,
699700
extern_crate_self,

compiler/rustc_target/src/spec/abi.rs

+22
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ pub enum Abi {
4040
RustCold,
4141
}
4242

43+
impl Abi {
44+
pub fn supports_varargs(self) -> bool {
45+
// * C and Cdecl obviously support varargs.
46+
// * C can be based on SysV64 or Win64, so they must support varargs.
47+
// * EfiApi is based on Win64 or C, so it also supports it.
48+
//
49+
// * Stdcall does not, because it would be impossible for the callee to clean
50+
// up the arguments. (callee doesn't know how many arguments are there)
51+
// * Same for Fastcall, Vectorcall and Thiscall.
52+
// * System can become Stdcall, so is also a no-no.
53+
// * Other calling conventions are related to hardware or the compiler itself.
54+
match self {
55+
Self::C { .. }
56+
| Self::Cdecl { .. }
57+
| Self::Win64 { .. }
58+
| Self::SysV64 { .. }
59+
| Self::EfiApi => true,
60+
_ => false,
61+
}
62+
}
63+
}
64+
4365
#[derive(Copy, Clone)]
4466
pub struct AbiData {
4567
abi: Abi,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use crate::spec::{cvs, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
llvm_target: "mipsel-sony-psx".into(),
6+
pointer_width: 32,
7+
data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(),
8+
arch: "mips".into(),
9+
10+
options: TargetOptions {
11+
os: "none".into(),
12+
env: "psx".into(),
13+
vendor: "sony".into(),
14+
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
15+
cpu: "mips1".into(),
16+
executables: true,
17+
linker: Some("rust-lld".into()),
18+
relocation_model: RelocModel::Static,
19+
exe_suffix: ".exe".into(),
20+
21+
// PSX doesn't natively support floats.
22+
features: "+soft-float".into(),
23+
24+
// This should be 16 bits, but LLVM incorrectly tries emitting MIPS-II SYNC instructions
25+
// for atomic loads and stores. This crashes rustc so we have to disable the Atomic* API
26+
// until this is fixed upstream. See https://reviews.llvm.org/D122427#3420144 for more
27+
// info.
28+
max_atomic_width: Some(0),
29+
30+
// PSX does not support trap-on-condition instructions.
31+
llvm_args: cvs!["-mno-check-zero-division"],
32+
llvm_abiname: "o32".into(),
33+
panic_strategy: PanicStrategy::Abort,
34+
..Default::default()
35+
},
36+
}
37+
}

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ supported_targets! {
12221222
("armv7a-kmc-solid_asp3-eabihf", armv7a_kmc_solid_asp3_eabihf),
12231223

12241224
("mipsel-sony-psp", mipsel_sony_psp),
1225+
("mipsel-sony-psx", mipsel_sony_psx),
12251226
("mipsel-unknown-none", mipsel_unknown_none),
12261227
("thumbv4t-none-eabi", thumbv4t_none_eabi),
12271228
("armv4t-none-eabi", armv4t_none_eabi),

src/bootstrap/bin/rustdoc.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,9 @@ fn main() {
5555
arg.push(&linker);
5656
cmd.arg(arg);
5757
}
58-
if env::var_os("RUSTDOC_FUSE_LD_LLD").is_some() {
58+
if let Ok(no_threads) = env::var("RUSTDOC_LLD_NO_THREADS") {
5959
cmd.arg("-Clink-arg=-fuse-ld=lld");
60-
if cfg!(windows) {
61-
cmd.arg("-Clink-arg=-Wl,/threads:1");
62-
} else {
63-
cmd.arg("-Clink-arg=-Wl,--threads=1");
64-
}
60+
cmd.arg(format!("-Clink-arg=-Wl,{}", no_threads));
6561
}
6662
// Cargo doesn't pass RUSTDOCFLAGS to proc_macros:
6763
// https://github.com/rust-lang/cargo/issues/4423

src/bootstrap/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1152,8 +1152,8 @@ impl Build {
11521152
options[0] = Some("-Clink-arg=-fuse-ld=lld".to_string());
11531153
}
11541154

1155-
let threads = if target.contains("windows") { "/threads:1" } else { "--threads=1" };
1156-
options[1] = Some(format!("-Clink-arg=-Wl,{}", threads));
1155+
let no_threads = util::lld_flag_no_threads(target.contains("windows"));
1156+
options[1] = Some(format!("-Clink-arg=-Wl,{}", no_threads));
11571157
}
11581158

11591159
IntoIterator::into_iter(options).flatten()

src/bootstrap/test.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,10 @@ impl Step for RustdocTheme {
771771
cmd.env("RUSTDOC_LINKER", linker);
772772
}
773773
if builder.is_fuse_ld_lld(self.compiler.host) {
774-
cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
774+
cmd.env(
775+
"RUSTDOC_LLD_NO_THREADS",
776+
util::lld_flag_no_threads(self.compiler.host.contains("windows")),
777+
);
775778
}
776779
try_run(builder, &mut cmd);
777780
}

0 commit comments

Comments
 (0)