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 #138185

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
917d2eb
add verbatim linker to AIXLinker
Feb 20, 2025
1a5a453
atomic: clarify that failing conditional RMW operations are not 'writes'
RalfJung Mar 4, 2025
e0b7577
linux x64: default to `-znostart-stop-gc`
lqd Feb 26, 2025
9d8ce72
compiler: factor Windows x86-32 ABI impl into its own file
workingjubilee Feb 21, 2025
4e4bed8
setTargetTriple now accepts Triple rather than string
ZequanWu Mar 7, 2025
8814679
rename Triple to Target
ZequanWu Mar 7, 2025
bbc80a8
Delay bug for negative auto trait rather than ICEing
compiler-errors Mar 7, 2025
bae4682
Rename print_something to should_render
compiler-errors Mar 5, 2025
9ae9453
Fix pretty printing of parsed attrs in hir_pretty
compiler-errors Mar 5, 2025
fb04372
Move all alloc integration tests to a new alloctests crate
bjorn3 Feb 6, 2025
be1e0b7
Move most Rc tests to alloctests
bjorn3 Feb 6, 2025
701bedc
Move last remaining Rc test to alloctests
bjorn3 Feb 6, 2025
ae5687e
Fully test the alloc crate through alloctests
bjorn3 Feb 6, 2025
22d0440
Add comments
bjorn3 Feb 13, 2025
1d586b5
Rollup merge of #136642 - bjorn3:separate_alloctest_crate, r=cuviper
compiler-errors Mar 7, 2025
0270489
Rollup merge of #137337 - dalvescb:master, r=petrochenkov
compiler-errors Mar 7, 2025
f47df77
Rollup merge of #137363 - workingjubilee:untangle-x86-abi-impl, r=jie…
compiler-errors Mar 7, 2025
ae1699f
Rollup merge of #137685 - lqd:nostart-stop-gc, r=petrochenkov
compiler-errors Mar 7, 2025
541029d
Rollup merge of #138000 - RalfJung:atomic-rmw, r=Amanieu
compiler-errors Mar 7, 2025
dee3c9c
Rollup merge of #138063 - compiler-errors:improve-attr-unpretty, r=jd…
compiler-errors Mar 7, 2025
3dafc37
Rollup merge of #138137 - ZequanWu:fix-triple, r=cuviper
compiler-errors Mar 7, 2025
92e7038
Rollup merge of #138173 - compiler-errors:incoherent-negative-impl, r…
compiler-errors Mar 7, 2025
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
52 changes: 30 additions & 22 deletions compiler/rustc_attr_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,39 @@ pub trait HashStableContext: rustc_ast::HashStableContext + rustc_abi::HashStabl
/// like [`Span`]s and empty tuples, are gracefully skipped so they don't clutter the
/// representation much.
pub trait PrintAttribute {
fn print_something(&self) -> bool;
/// Whether or not this will render as something meaningful, or if it's skipped
/// (which will force the containing struct to also skip printing a comma
/// and the field name).
fn should_render(&self) -> bool;

fn print_attribute(&self, p: &mut Printer);
}

impl<T: PrintAttribute> PrintAttribute for &T {
fn print_something(&self) -> bool {
T::print_something(self)
fn should_render(&self) -> bool {
T::should_render(self)
}

fn print_attribute(&self, p: &mut Printer) {
T::print_attribute(self, p)
}
}
impl<T: PrintAttribute> PrintAttribute for Option<T> {
fn print_something(&self) -> bool {
self.as_ref().is_some_and(|x| x.print_something())
fn should_render(&self) -> bool {
self.as_ref().is_some_and(|x| x.should_render())
}

fn print_attribute(&self, p: &mut Printer) {
if let Some(i) = self {
T::print_attribute(i, p)
}
}
}
impl<T: PrintAttribute> PrintAttribute for ThinVec<T> {
fn print_something(&self) -> bool {
self.is_empty() || self[0].print_something()
fn should_render(&self) -> bool {
self.is_empty() || self[0].should_render()
}

fn print_attribute(&self, p: &mut Printer) {
let mut last_printed = false;
p.word("[");
Expand All @@ -70,15 +76,15 @@ impl<T: PrintAttribute> PrintAttribute for ThinVec<T> {
p.word_space(",");
}
i.print_attribute(p);
last_printed = i.print_something();
last_printed = i.should_render();
}
p.word("]");
}
}
macro_rules! print_skip {
($($t: ty),* $(,)?) => {$(
impl PrintAttribute for $t {
fn print_something(&self) -> bool { false }
fn should_render(&self) -> bool { false }
fn print_attribute(&self, _: &mut Printer) { }
})*
};
Expand All @@ -87,7 +93,7 @@ macro_rules! print_skip {
macro_rules! print_disp {
($($t: ty),* $(,)?) => {$(
impl PrintAttribute for $t {
fn print_something(&self) -> bool { true }
fn should_render(&self) -> bool { true }
fn print_attribute(&self, p: &mut Printer) {
p.word(format!("{}", self));
}
Expand All @@ -97,7 +103,7 @@ macro_rules! print_disp {
macro_rules! print_debug {
($($t: ty),* $(,)?) => {$(
impl PrintAttribute for $t {
fn print_something(&self) -> bool { true }
fn should_render(&self) -> bool { true }
fn print_attribute(&self, p: &mut Printer) {
p.word(format!("{:?}", self));
}
Expand All @@ -106,37 +112,39 @@ macro_rules! print_debug {
}

macro_rules! print_tup {
(num_print_something $($ts: ident)*) => { 0 $(+ $ts.print_something() as usize)* };
(num_should_render $($ts: ident)*) => { 0 $(+ $ts.should_render() as usize)* };
() => {};
($t: ident $($ts: ident)*) => {
#[allow(non_snake_case, unused)]
impl<$t: PrintAttribute, $($ts: PrintAttribute),*> PrintAttribute for ($t, $($ts),*) {
fn print_something(&self) -> bool {
fn should_render(&self) -> bool {
let ($t, $($ts),*) = self;
print_tup!(num_print_something $t $($ts)*) != 0
print_tup!(num_should_render $t $($ts)*) != 0
}

fn print_attribute(&self, p: &mut Printer) {
let ($t, $($ts),*) = self;
let parens = print_tup!(num_print_something $t $($ts)*) > 1;
let parens = print_tup!(num_should_render $t $($ts)*) > 1;
if parens {
p.word("(");
p.popen();
}

let mut printed_anything = $t.print_something();
let mut printed_anything = $t.should_render();

$t.print_attribute(p);

$(
if printed_anything && $ts.print_something() {
p.word_space(",");
if $ts.should_render() {
if printed_anything {
p.word_space(",");
}
printed_anything = true;
}
$ts.print_attribute(p);
)*

if parens {
p.word(")");
p.pclose();
}
}
}
Expand All @@ -147,5 +155,5 @@ macro_rules! print_tup {

print_tup!(A B C D E F G H);
print_skip!(Span, ());
print_disp!(Symbol, u16, bool, NonZero<u32>);
print_debug!(UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency);
print_disp!(u16, bool, NonZero<u32>);
print_debug!(Symbol, UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency);
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ index 7165c3e48af..968552ad435 100644
--- a/library/alloc/Cargo.toml
+++ b/library/alloc/Cargo.toml
@@ -11,7 +11,7 @@ test = { path = "../test" }
edition = "2021"
bench = false

[dependencies]
core = { path = "../core", public = true }
-compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std'] }
+compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std', 'no-f16-f128'] }

[dev-dependencies]
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
[features]
compiler-builtins-mem = ['compiler_builtins/mem']
--
2.34.1

29 changes: 29 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3382,6 +3382,35 @@ fn add_lld_args(
// this, `wasm-component-ld`, which is overridden if this option is passed.
if !sess.target.is_like_wasm {
cmd.cc_arg("-fuse-ld=lld");

// On ELF platforms like at least x64 linux, GNU ld and LLD have opposite defaults on some
// section garbage-collection features. For example, the somewhat popular `linkme` crate and
// its dependents rely in practice on this difference: when using lld, they need `-z
// nostart-stop-gc` to prevent encapsulation symbols and sections from being
// garbage-collected.
//
// More information about all this can be found in:
// - https://maskray.me/blog/2021-01-31-metadata-sections-comdat-and-shf-link-order
// - https://lld.llvm.org/ELF/start-stop-gc
//
// So when using lld, we restore, for now, the traditional behavior to help migration, but
// will remove it in the future.
// Since this only disables an optimization, it shouldn't create issues, but is in theory
// slightly suboptimal. However, it:
// - doesn't have any visible impact on our benchmarks
// - reduces the need to disable lld for the crates that depend on this
//
// Note that lld can detect some cases where this difference is relied on, and emits a
// dedicated error to add this link arg. We could make use of this error to emit an FCW. As
// of writing this, we don't do it, because lld is already enabled by default on nightly
// without this mitigation: no working project would see the FCW, so we do this to help
// stabilization.
//
// FIXME: emit an FCW if linking fails due its absence, and then remove this link-arg in the
// future.
if sess.target.llvm_target == "x86_64-unknown-linux-gnu" {
cmd.link_arg("-znostart-stop-gc");
}
}

if !flavor.is_gnu() {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1655,9 +1655,9 @@ impl<'a> Linker for AixLinker<'a> {
}
}

fn link_dylib_by_name(&mut self, name: &str, _verbatim: bool, _as_needed: bool) {
fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, _as_needed: bool) {
self.hint_dynamic();
self.link_or_cc_arg(format!("-l{name}"));
self.link_or_cc_arg(if verbatim { String::from(name) } else { format!("-l{name}") });
}

fn link_dylib_by_path(&mut self, path: &Path, _as_needed: bool) {
Expand All @@ -1668,7 +1668,7 @@ impl<'a> Linker for AixLinker<'a> {
fn link_staticlib_by_name(&mut self, name: &str, verbatim: bool, whole_archive: bool) {
self.hint_static();
if !whole_archive {
self.link_or_cc_arg(format!("-l{name}"));
self.link_or_cc_arg(if verbatim { String::from(name) } else { format!("-l{name}") });
} else {
let mut arg = OsString::from("-bkeepfile:");
arg.push(find_native_static_library(name, verbatim, self.sess));
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_hir_analysis/src/check/always_applicable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ pub(crate) fn check_negative_auto_trait_impl<'tcx>(
// be implemented here to handle non-ADT rigid types.
Ok(())
} else {
span_bug!(tcx.def_span(impl_def_id), "incoherent impl of negative auto trait");
Err(tcx.dcx().span_delayed_bug(
tcx.def_span(impl_def_id),
"incoherent impl of negative auto trait",
))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ impl<'a> State<'a> {
self.hardbreak()
}
hir::Attribute::Parsed(pa) => {
self.word("#[attr=\"");
self.word("#[attr = ");
pa.print_attribute(self);
self.word("\")]");
self.word("]");
self.hardbreak()
}
}
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ extern "C" LLVMContextRef LLVMRustContextCreate(bool shouldDiscardNames) {
}

extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M,
const char *Triple) {
unwrap(M)->setTargetTriple(Triple::normalize(Triple));
const char *Target) {
#if LLVM_VERSION_GE(21, 0)
unwrap(M)->setTargetTriple(Triple(Triple::normalize(Target)));
#else
unwrap(M)->setTargetTriple(Triple::normalize(Target));
#endif
}

extern "C" void LLVMRustPrintPassTimings(RustStringRef OutBuf) {
Expand Down
27 changes: 16 additions & 11 deletions compiler/rustc_macros/src/print_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
let name = field.ident.as_ref().unwrap();
let string_name = name.to_string();
disps.push(quote! {
if __printed_anything && #name.print_something() {
__p.word_space(",");
if #name.should_render() {
if __printed_anything {
__p.word_space(",");
}
__p.word(#string_name);
__p.word_space(":");
__printed_anything = true;
}
__p.word(#string_name);
__p.word_space(":");
#name.print_attribute(__p);
});
field_names.push(name);
Expand All @@ -31,10 +33,11 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
quote! { {#(#field_names),*} },
quote! {
__p.word(#string_name);
if true #(&& !#field_names.print_something())* {
if true #(&& !#field_names.should_render())* {
return;
}

__p.nbsp();
__p.word("{");
#(#disps)*
__p.word("}");
Expand All @@ -48,8 +51,10 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
for idx in 0..fields_unnamed.unnamed.len() {
let name = format_ident!("f{idx}");
disps.push(quote! {
if __printed_anything && #name.print_something() {
__p.word_space(",");
if #name.should_render() {
if __printed_anything {
__p.word_space(",");
}
__printed_anything = true;
}
#name.print_attribute(__p);
Expand All @@ -62,13 +67,13 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
quote! {
__p.word(#string_name);

if true #(&& !#field_names.print_something())* {
if true #(&& !#field_names.should_render())* {
return;
}

__p.word("(");
__p.popen();
#(#disps)*
__p.word(")");
__p.pclose();
},
quote! { true },
)
Expand Down Expand Up @@ -138,7 +143,7 @@ pub(crate) fn print_attribute(input: Structure<'_>) -> TokenStream {
input.gen_impl(quote! {
#[allow(unused)]
gen impl PrintAttribute for @Self {
fn print_something(&self) -> bool { #printed }
fn should_render(&self) -> bool { #printed }
fn print_attribute(&self, __p: &mut rustc_ast_pretty::pp::Printer) { #code }
}
})
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_target/src/callconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mod sparc64;
mod wasm;
mod x86;
mod x86_64;
mod x86_win32;
mod x86_win64;
mod xtensa;

Expand Down Expand Up @@ -649,7 +650,11 @@ impl<'a, Ty> FnAbi<'a, Ty> {
};
let reg_struct_return = cx.x86_abi_opt().reg_struct_return;
let opts = x86::X86Options { flavor, regparm, reg_struct_return };
x86::compute_abi_info(cx, self, opts);
if spec.is_like_msvc {
x86_win32::compute_abi_info(cx, self, opts);
} else {
x86::compute_abi_info(cx, self, opts);
}
}
"x86_64" => match abi {
ExternAbi::SysV64 { .. } => x86_64::compute_abi_info(cx, self),
Expand Down
24 changes: 2 additions & 22 deletions compiler/rustc_target/src/callconv/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
if t.abi_return_struct_as_int || opts.reg_struct_return {
// According to Clang, everyone but MSVC returns single-element
// float aggregates directly in a floating-point register.
if !t.is_like_msvc && fn_abi.ret.layout.is_single_fp_element(cx) {
if fn_abi.ret.layout.is_single_fp_element(cx) {
match fn_abi.ret.layout.size.bytes() {
4 => fn_abi.ret.cast_to(Reg::f32()),
8 => fn_abi.ret.cast_to(Reg::f64()),
Expand Down Expand Up @@ -64,31 +64,11 @@ where
continue;
}

// FIXME: MSVC 2015+ will pass the first 3 vector arguments in [XYZ]MM0-2
// See https://reviews.llvm.org/D72114 for Clang behavior

let t = cx.target_spec();
let align_4 = Align::from_bytes(4).unwrap();
let align_16 = Align::from_bytes(16).unwrap();

if t.is_like_msvc
&& arg.layout.is_adt()
&& let Some(max_repr_align) = arg.layout.max_repr_align
&& max_repr_align > align_4
{
// MSVC has special rules for overaligned arguments: https://reviews.llvm.org/D72114.
// Summarized here:
// - Arguments with _requested_ alignment > 4 are passed indirectly.
// - For backwards compatibility, arguments with natural alignment > 4 are still passed
// on stack (via `byval`). For example, this includes `double`, `int64_t`,
// and structs containing them, provided they lack an explicit alignment attribute.
assert!(
arg.layout.align.abi >= max_repr_align,
"abi alignment {:?} less than requested alignment {max_repr_align:?}",
arg.layout.align.abi,
);
arg.make_indirect();
} else if arg.layout.is_aggregate() {
if arg.layout.is_aggregate() {
// We need to compute the alignment of the `byval` argument. The rules can be found in
// `X86_32ABIInfo::getTypeStackAlignInBytes` in Clang's `TargetInfo.cpp`. Summarized
// here, they are:
Expand Down
Loading
Loading