Skip to content

Commit

Permalink
Auto merge of #103787 - notriddle:rollup-q1vmxsb, r=notriddle
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Oct 31, 2022
2 parents d726c84 + e6ffd96 commit 4596f4f
Show file tree
Hide file tree
Showing 83 changed files with 547 additions and 188 deletions.
11 changes: 7 additions & 4 deletions compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_hir::definitions::DisambiguatedDefPathData;
use rustc_middle::mir::interpret::{Allocation, ConstAllocation};
use rustc_middle::ty::{
self,
print::{with_no_verbose_constants, PrettyPrinter, Print, Printer},
print::{PrettyPrinter, Print, Printer},
subst::{GenericArg, GenericArgKind},
Ty, TyCtxt,
};
Expand Down Expand Up @@ -179,6 +179,11 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {

Ok(self)
}

fn should_print_verbose(&self) -> bool {
// `std::any::type_name` should never print verbose type names
false
}
}

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

/// Directly returns an `Allocation` containing an absolute path representation of the given type.
pub(crate) fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ConstAllocation<'tcx> {
let path = with_no_verbose_constants!(
AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path
);
let path = AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path;
let alloc = Allocation::from_bytes_byte_aligned_immutable(path.into_bytes());
tcx.intern_const_alloc(alloc)
}
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ declare_features! (
(active, exclusive_range_pattern, "1.11.0", Some(37854), None),
/// Allows exhaustive pattern matching on types that contain uninhabited types.
(active, exhaustive_patterns, "1.13.0", Some(51085), None),
/// Allows using `efiapi`, `sysv64` and `win64` as calling convention
/// for functions with varargs.
(active, extended_varargs_abi_support, "1.65.0", Some(100189), None),
/// Allows defining `extern type`s.
(active, extern_types, "1.23.0", Some(43467), None),
/// Allows the use of `#[ffi_const]` on foreign functions.
Expand Down
46 changes: 33 additions & 13 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ use rustc_middle::middle;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::util;
use rustc_session::config::EntryFnType;
use rustc_session::{config::EntryFnType, parse::feature_err};
use rustc_span::{symbol::sym, Span, DUMMY_SP};
use rustc_target::spec::abi::Abi;
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
Expand All @@ -118,20 +118,40 @@ use astconv::AstConv;
use bounds::Bounds;

fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi, span: Span) {
match (decl.c_variadic, abi) {
// The function has the correct calling convention, or isn't a "C-variadic" function.
(false, _) | (true, Abi::C { .. }) | (true, Abi::Cdecl { .. }) => {}
// The function is a "C-variadic" function with an incorrect calling convention.
(true, _) => {
let mut err = struct_span_err!(
tcx.sess,
const ERROR_HEAD: &str = "C-variadic function must have a compatible calling convention";
const CONVENTIONS_UNSTABLE: &str = "`C`, `cdecl`, `win64`, `sysv64` or `efiapi`";
const CONVENTIONS_STABLE: &str = "`C` or `cdecl`";
const UNSTABLE_EXPLAIN: &str =
"using calling conventions other than `C` or `cdecl` for varargs functions is unstable";

if !decl.c_variadic || matches!(abi, Abi::C { .. } | Abi::Cdecl { .. }) {
return;
}

let extended_abi_support = tcx.features().extended_varargs_abi_support;
let conventions = match (extended_abi_support, abi.supports_varargs()) {
// User enabled additional ABI support for varargs and function ABI matches those ones.
(true, true) => return,

// Using this ABI would be ok, if the feature for additional ABI support was enabled.
// Return CONVENTIONS_STABLE, because we want the other error to look the same.
(false, true) => {
feature_err(
&tcx.sess.parse_sess,
sym::extended_varargs_abi_support,
span,
E0045,
"C-variadic function must have C or cdecl calling convention"
);
err.span_label(span, "C-variadics require C or cdecl calling convention").emit();
UNSTABLE_EXPLAIN,
)
.emit();
CONVENTIONS_STABLE
}
}

(false, false) => CONVENTIONS_STABLE,
(true, false) => CONVENTIONS_UNSTABLE,
};

let mut err = struct_span_err!(tcx.sess, span, E0045, "{}, like {}", ERROR_HEAD, conventions);
err.span_label(span, ERROR_HEAD).emit();
}

fn require_same_types<'tcx>(
Expand Down
34 changes: 17 additions & 17 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ thread_local! {
static NO_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
static NO_QUERIES: Cell<bool> = const { Cell::new(false) };
static NO_VISIBLE_PATH: Cell<bool> = const { Cell::new(false) };
static NO_VERBOSE_CONSTANTS: Cell<bool> = const { Cell::new(false) };
}

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

/// The "region highlights" are used to control region printing during
Expand Down Expand Up @@ -600,7 +596,7 @@ pub trait PrettyPrinter<'tcx>:
}
ty::FnPtr(ref bare_fn) => p!(print(bare_fn)),
ty::Infer(infer_ty) => {
let verbose = self.tcx().sess.verbose();
let verbose = self.should_print_verbose();
if let ty::TyVar(ty_vid) = infer_ty {
if let Some(name) = self.ty_infer_name(ty_vid) {
p!(write("{}", name))
Expand Down Expand Up @@ -642,7 +638,7 @@ pub trait PrettyPrinter<'tcx>:
p!(print_def_path(def_id, &[]));
}
ty::Projection(ref data) => {
if !(self.tcx().sess.verbose() || NO_QUERIES.with(|q| q.get()))
if !(self.should_print_verbose() || NO_QUERIES.with(|q| q.get()))
&& self.tcx().def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder
{
return self.pretty_print_opaque_impl_type(data.item_def_id, data.substs);
Expand All @@ -658,7 +654,7 @@ pub trait PrettyPrinter<'tcx>:
// only affect certain debug messages (e.g. messages printed
// from `rustc_middle::ty` during the computation of `tcx.predicates_of`),
// and should have no effect on any compiler output.
if self.tcx().sess.verbose() || NO_QUERIES.with(|q| q.get()) {
if self.should_print_verbose() || NO_QUERIES.with(|q| q.get()) {
p!(write("Opaque({:?}, {:?})", def_id, substs));
return Ok(self);
}
Expand Down Expand Up @@ -689,7 +685,7 @@ pub trait PrettyPrinter<'tcx>:
hir::Movability::Static => p!("static "),
}

if !self.tcx().sess.verbose() {
if !self.should_print_verbose() {
p!("generator");
// FIXME(eddyb) should use `def_span`.
if let Some(did) = did.as_local() {
Expand Down Expand Up @@ -725,7 +721,7 @@ pub trait PrettyPrinter<'tcx>:
}
ty::Closure(did, substs) => {
p!(write("["));
if !self.tcx().sess.verbose() {
if !self.should_print_verbose() {
p!(write("closure"));
// FIXME(eddyb) should use `def_span`.
if let Some(did) = did.as_local() {
Expand Down Expand Up @@ -763,7 +759,7 @@ pub trait PrettyPrinter<'tcx>:
}
ty::Array(ty, sz) => {
p!("[", print(ty), "; ");
if !NO_VERBOSE_CONSTANTS.with(|flag| flag.get()) && self.tcx().sess.verbose() {
if self.should_print_verbose() {
p!(write("{:?}", sz));
} else if let ty::ConstKind::Unevaluated(..) = sz.kind() {
// Do not try to evaluate unevaluated constants. If we are const evaluating an
Expand Down Expand Up @@ -1077,7 +1073,7 @@ pub trait PrettyPrinter<'tcx>:

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

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

if !NO_VERBOSE_CONSTANTS.with(|flag| flag.get()) && self.tcx().sess.verbose() {
if self.should_print_verbose() {
p!(write("ValTree({:?}: ", valtree), print(ty), ")");
return Ok(self);
}
Expand Down Expand Up @@ -1564,6 +1560,10 @@ pub trait PrettyPrinter<'tcx>:
Ok(cx)
})
}

fn should_print_verbose(&self) -> bool {
self.tcx().sess.verbose()
}
}

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

let verbose = self.tcx.sess.verbose();
let verbose = self.should_print_verbose();
disambiguated_data.fmt_maybe_verbose(&mut self, verbose)?;

self.empty_path = false;
Expand Down Expand Up @@ -1940,7 +1940,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
return true;
}

if self.tcx.sess.verbose() {
if self.should_print_verbose() {
return true;
}

Expand Down Expand Up @@ -2012,7 +2012,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
return Ok(self);
}

if self.tcx.sess.verbose() {
if self.should_print_verbose() {
p!(write("{:?}", region));
return Ok(self);
}
Expand Down Expand Up @@ -2218,7 +2218,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
// aren't named. Eventually, we might just want this as the default, but
// this is not *quite* right and changes the ordering of some output
// anyways.
let (new_value, map) = if self.tcx().sess.verbose() {
let (new_value, map) = if self.should_print_verbose() {
let regions: Vec<_> = value
.bound_vars()
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn mir_const<'tcx>(

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

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

pm::run_passes(
tcx,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
span,
);

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

body
}
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ symbols! {
export_name,
expr,
extended_key_value_attributes,
extended_varargs_abi_support,
extern_absolute_paths,
extern_crate_item_prelude,
extern_crate_self,
Expand Down
22 changes: 22 additions & 0 deletions compiler/rustc_target/src/spec/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ pub enum Abi {
RustCold,
}

impl Abi {
pub fn supports_varargs(self) -> bool {
// * C and Cdecl obviously support varargs.
// * C can be based on SysV64 or Win64, so they must support varargs.
// * EfiApi is based on Win64 or C, so it also supports it.
//
// * Stdcall does not, because it would be impossible for the callee to clean
// up the arguments. (callee doesn't know how many arguments are there)
// * Same for Fastcall, Vectorcall and Thiscall.
// * System can become Stdcall, so is also a no-no.
// * Other calling conventions are related to hardware or the compiler itself.
match self {
Self::C { .. }
| Self::Cdecl { .. }
| Self::Win64 { .. }
| Self::SysV64 { .. }
| Self::EfiApi => true,
_ => false,
}
}
}

#[derive(Copy, Clone)]
pub struct AbiData {
abi: Abi,
Expand Down
37 changes: 37 additions & 0 deletions compiler/rustc_target/src/spec/mipsel_sony_psx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::spec::{cvs, Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, Target, TargetOptions};

pub fn target() -> Target {
Target {
llvm_target: "mipsel-sony-psx".into(),
pointer_width: 32,
data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(),
arch: "mips".into(),

options: TargetOptions {
os: "none".into(),
env: "psx".into(),
vendor: "sony".into(),
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
cpu: "mips1".into(),
executables: true,
linker: Some("rust-lld".into()),
relocation_model: RelocModel::Static,
exe_suffix: ".exe".into(),

// PSX doesn't natively support floats.
features: "+soft-float".into(),

// This should be 16 bits, but LLVM incorrectly tries emitting MIPS-II SYNC instructions
// for atomic loads and stores. This crashes rustc so we have to disable the Atomic* API
// until this is fixed upstream. See https://reviews.llvm.org/D122427#3420144 for more
// info.
max_atomic_width: Some(0),

// PSX does not support trap-on-condition instructions.
llvm_args: cvs!["-mno-check-zero-division"],
llvm_abiname: "o32".into(),
panic_strategy: PanicStrategy::Abort,
..Default::default()
},
}
}
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,7 @@ supported_targets! {
("armv7a-kmc-solid_asp3-eabihf", armv7a_kmc_solid_asp3_eabihf),

("mipsel-sony-psp", mipsel_sony_psp),
("mipsel-sony-psx", mipsel_sony_psx),
("mipsel-unknown-none", mipsel_unknown_none),
("thumbv4t-none-eabi", thumbv4t_none_eabi),
("armv4t-none-eabi", armv4t_none_eabi),
Expand Down
8 changes: 2 additions & 6 deletions src/bootstrap/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ fn main() {
arg.push(&linker);
cmd.arg(arg);
}
if env::var_os("RUSTDOC_FUSE_LD_LLD").is_some() {
if let Ok(no_threads) = env::var("RUSTDOC_LLD_NO_THREADS") {
cmd.arg("-Clink-arg=-fuse-ld=lld");
if cfg!(windows) {
cmd.arg("-Clink-arg=-Wl,/threads:1");
} else {
cmd.arg("-Clink-arg=-Wl,--threads=1");
}
cmd.arg(format!("-Clink-arg=-Wl,{}", no_threads));
}
// Cargo doesn't pass RUSTDOCFLAGS to proc_macros:
// https://github.com/rust-lang/cargo/issues/4423
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,8 +1152,8 @@ impl Build {
options[0] = Some("-Clink-arg=-fuse-ld=lld".to_string());
}

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

IntoIterator::into_iter(options).flatten()
Expand Down
5 changes: 4 additions & 1 deletion src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,10 @@ impl Step for RustdocTheme {
cmd.env("RUSTDOC_LINKER", linker);
}
if builder.is_fuse_ld_lld(self.compiler.host) {
cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
cmd.env(
"RUSTDOC_LLD_NO_THREADS",
util::lld_flag_no_threads(self.compiler.host.contains("windows")),
);
}
try_run(builder, &mut cmd);
}
Expand Down
Loading

0 comments on commit 4596f4f

Please sign in to comment.