Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #103777

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4c05e3a
Use `raw-dylib` in the std
ChrisDenton Sep 10, 2022
ba847ca
Enable varargs support for calling conventions other than C or cdecl
Soveu Aug 8, 2022
65ef625
Apply suggestions from code review
jackh726 Aug 16, 2022
de78c32
Cleanup message and bless tests
jackh726 Oct 23, 2022
ac732b6
rustdoc: clean up `#toggle-all-docs`
notriddle Sep 17, 2022
bdbc977
rustdoc: fix weird toggle-all-docs style in iOS
notriddle Sep 17, 2022
0c4a01a
check lld version to choose correct flag for tests
belovdv Sep 21, 2022
c4c4c56
Replace `mir_map.0` dump with `built` phase change dump
JakobDegen Sep 5, 2022
51b0363
Move mir building mir-opt tests to own directory
JakobDegen Oct 27, 2022
3195388
rustdoc: add support for incoherent impls on structs and traits
notriddle Oct 29, 2022
eb2dd95
Add regression test for reexports in search results
GuillaumeGomez Oct 30, 2022
8609364
All verbosity checks in `PrettyPrinter` now go through `PrettyPrinter…
SarthakSingh31 Oct 30, 2022
a227543
Rollup merge of #97971 - Soveu:varargs, r=jackh726
notriddle Oct 30, 2022
5965158
Rollup merge of #101428 - JakobDegen:build-tests, r=oli-obk
notriddle Oct 30, 2022
a0e9c70
Rollup merge of #101944 - notriddle:notriddle/toggle-all-docs, r=jsha…
notriddle Oct 30, 2022
c0ee7a1
Rollup merge of #102101 - BelovDV:new-check-lld-version, r=petrochenkov
notriddle Oct 30, 2022
d70f59d
Rollup merge of #102327 - ChrisDenton:std-raw-dylib, r=thomcc
notriddle Oct 30, 2022
b544523
Rollup merge of #103746 - notriddle:notriddle/incoherent-dyn-trait, r…
notriddle Oct 30, 2022
7080630
Rollup merge of #103758 - GuillaumeGomez:reexports-search-result-test…
notriddle Oct 30, 2022
b46dd7c
Rollup merge of #103764 - SarthakSingh31:issue-94187-2, r=compiler-er…
notriddle Oct 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading