Skip to content

Commit f82fd06

Browse files
committed
Auto merge of #150028 - matthiaskrgr:rollup-6mq2ms9, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #148756 (Warn on codegen attributes on required trait methods) - #148790 (Add new Tier-3 target: riscv64im-unknown-none-elf) - #149271 (feat: dlopen Enzyme) - #149354 (Bootstrap config: libgccjit libs dir) - #149459 (std: sys: fs: uefi: Implement set_times and set_perm) - #149950 (Simplify how inline asm handles `MaybeUninit`) - #150000 (Port `#[rustc_legacy_const_generics]` to use attribute parser ) - #150014 (Metadata loader cleanups) - #150021 (document that mpmc channels deliver an item to (at most) one receiver) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0160933 + aec3e2e commit f82fd06

File tree

62 files changed

+1483
-700
lines changed

Some content is hidden

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

62 files changed

+1483
-700
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,7 @@ dependencies = [
36133613
"gimli 0.31.1",
36143614
"itertools",
36153615
"libc",
3616+
"libloading 0.9.0",
36163617
"measureme",
36173618
"object 0.37.3",
36183619
"rustc-demangle",

bootstrap.example.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,31 @@
191191
# Currently, this is only supported for the `x86_64-unknown-linux-gnu` target.
192192
#gcc.download-ci-gcc = false
193193

194+
# Provide a directory of prebuilt libgccjit.so dylibs for given (host, target) compilation pairs.
195+
# This is useful when you want to cross-compile `rustc` to another target since GCC is not a
196+
# multi-target compiler.
197+
# You have to use a directory structure that looks like this:
198+
# `<libgccjit-libs-dir>/<host>/<target>/libgccjit.so`.
199+
# For example:
200+
#
201+
# ```
202+
# <libgccjit-libs-dir>
203+
# ├── m68k-unknown-linux-gnu
204+
# │ └── m68k-unknown-linux-gnu
205+
# │ └── libgccjit.so
206+
# └── x86_64-unknown-linux-gnu
207+
# ├── m68k-unknown-linux-gnu
208+
# │ └── libgccjit.so
209+
# └── x86_64-unknown-linux-gnu
210+
# └── libgccjit.so
211+
# ```
212+
# The directory above would allow you to cross-compile rustc from x64 to m68k
213+
#
214+
# Note that this option has priority over `gcc.download-ci-gcc`.
215+
# If you set both, bootstrap will first try to load libgccjit.so from this directory.
216+
# Only if it isn't found, it will try to download it from CI or build it locally.
217+
#gcc.libgccjit-libs-dir = "/path/to/libgccjit-libs-dir"
218+
194219
# =============================================================================
195220
# General build configuration options
196221
# =============================================================================

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,25 +237,27 @@ impl SpanLowerer {
237237
#[extension(trait ResolverAstLoweringExt)]
238238
impl ResolverAstLowering {
239239
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>> {
240-
if let ExprKind::Path(None, path) = &expr.kind {
241-
// Don't perform legacy const generics rewriting if the path already
242-
// has generic arguments.
243-
if path.segments.last().unwrap().args.is_some() {
244-
return None;
245-
}
240+
let ExprKind::Path(None, path) = &expr.kind else {
241+
return None;
242+
};
246243

247-
if let Res::Def(DefKind::Fn, def_id) = self.partial_res_map.get(&expr.id)?.full_res()? {
248-
// We only support cross-crate argument rewriting. Uses
249-
// within the same crate should be updated to use the new
250-
// const generics style.
251-
if def_id.is_local() {
252-
return None;
253-
}
244+
// Don't perform legacy const generics rewriting if the path already
245+
// has generic arguments.
246+
if path.segments.last().unwrap().args.is_some() {
247+
return None;
248+
}
254249

255-
if let Some(v) = self.legacy_const_generic_args.get(&def_id) {
256-
return v.clone();
257-
}
258-
}
250+
let def_id = self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
251+
252+
// We only support cross-crate argument rewriting. Uses
253+
// within the same crate should be updated to use the new
254+
// const generics style.
255+
if def_id.is_local() {
256+
return None;
257+
}
258+
259+
if let Some(v) = self.legacy_const_generic_args.get(&def_id) {
260+
return v.clone();
259261
}
260262

261263
None

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser {
6161
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
6262
Allow(Target::Fn),
6363
Allow(Target::Method(MethodKind::Inherent)),
64-
Allow(Target::Method(MethodKind::Trait { body: false })),
6564
Allow(Target::Method(MethodKind::Trait { body: true })),
6665
Allow(Target::Method(MethodKind::TraitImpl)),
6766
]);

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
5757
Allow(Target::Fn),
5858
Allow(Target::Method(MethodKind::Trait { body: true })),
5959
Allow(Target::Method(MethodKind::TraitImpl)),
60-
Allow(Target::Method(MethodKind::Trait { body: false })),
6160
Allow(Target::Method(MethodKind::Inherent)),
6261
Allow(Target::ForeignFn),
6362
Allow(Target::Closure),
@@ -343,7 +342,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for TrackCallerParser {
343342
Allow(Target::Method(MethodKind::Inherent)),
344343
Allow(Target::Method(MethodKind::Trait { body: true })),
345344
Allow(Target::Method(MethodKind::TraitImpl)),
346-
Allow(Target::Method(MethodKind::Trait { body: false })),
345+
Allow(Target::Method(MethodKind::Trait { body: false })), // `#[track_caller]` is inherited from trait methods
347346
Allow(Target::ForeignFn),
348347
Allow(Target::Closure),
349348
Warn(Target::MacroDef),

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
469469
Allow(Target::Static),
470470
Allow(Target::Fn),
471471
Allow(Target::Method(MethodKind::Inherent)),
472-
Allow(Target::Method(MethodKind::Trait { body: false })),
473472
Allow(Target::Method(MethodKind::Trait { body: true })),
474473
Allow(Target::Method(MethodKind::TraitImpl)),
475474
]);
@@ -587,12 +586,12 @@ impl<S: Stage> SingleAttributeParser<S> for LinkageParser {
587586
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
588587
Allow(Target::Fn),
589588
Allow(Target::Method(MethodKind::Inherent)),
590-
Allow(Target::Method(MethodKind::Trait { body: false })),
591589
Allow(Target::Method(MethodKind::Trait { body: true })),
592590
Allow(Target::Method(MethodKind::TraitImpl)),
593591
Allow(Target::Static),
594592
Allow(Target::ForeignStatic),
595593
Allow(Target::ForeignFn),
594+
Warn(Target::Method(MethodKind::Trait { body: false })), // Not inherited
596595
]);
597596

598597
const TEMPLATE: AttributeTemplate = template!(NameValueStr: [

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<S: Stage> AttributeParser<S> for AlignParser {
315315
Allow(Target::Method(MethodKind::Inherent)),
316316
Allow(Target::Method(MethodKind::Trait { body: true })),
317317
Allow(Target::Method(MethodKind::TraitImpl)),
318-
Allow(Target::Method(MethodKind::Trait { body: false })),
318+
Allow(Target::Method(MethodKind::Trait { body: false })), // `#[align]` is inherited from trait methods
319319
Allow(Target::ForeignFn),
320320
]);
321321

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use rustc_ast::{LitIntType, LitKind, MetaItemLit};
2+
13
use super::prelude::*;
24
use super::util::parse_single_integer;
35

@@ -76,3 +78,47 @@ impl<S: Stage> SingleAttributeParser<S> for RustcSimdMonomorphizeLaneLimitParser
7678
Some(AttributeKind::RustcSimdMonomorphizeLaneLimit(cx.parse_limit_int(nv)?))
7779
}
7880
}
81+
82+
pub(crate) struct RustcLegacyConstGenericsParser;
83+
84+
impl<S: Stage> SingleAttributeParser<S> for RustcLegacyConstGenericsParser {
85+
const PATH: &[Symbol] = &[sym::rustc_legacy_const_generics];
86+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
87+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
88+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
89+
const TEMPLATE: AttributeTemplate = template!(List: &["N"]);
90+
91+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
92+
let ArgParser::List(meta_items) = args else {
93+
cx.expected_list(cx.attr_span, args);
94+
return None;
95+
};
96+
97+
let mut parsed_indexes = ThinVec::new();
98+
let mut errored = false;
99+
100+
for possible_index in meta_items.mixed() {
101+
if let MetaItemOrLitParser::Lit(MetaItemLit {
102+
kind: LitKind::Int(index, LitIntType::Unsuffixed),
103+
..
104+
}) = possible_index
105+
{
106+
parsed_indexes.push((index.0 as usize, possible_index.span()));
107+
} else {
108+
cx.expected_integer_literal(possible_index.span());
109+
errored = true;
110+
}
111+
}
112+
if errored {
113+
return None;
114+
} else if parsed_indexes.is_empty() {
115+
cx.expected_at_least_one_argument(args.span()?);
116+
return None;
117+
}
118+
119+
Some(AttributeKind::RustcLegacyConstGenerics {
120+
fn_indexes: parsed_indexes,
121+
attr_span: cx.attr_span,
122+
})
123+
}
124+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ use crate::attributes::proc_macro_attrs::{
5959
use crate::attributes::prototype::CustomMirParser;
6060
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
6161
use crate::attributes::rustc_internal::{
62-
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser, RustcMainParser,
63-
RustcObjectLifetimeDefaultParser, RustcSimdMonomorphizeLaneLimitParser,
62+
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser,
63+
RustcLegacyConstGenericsParser, RustcMainParser, RustcObjectLifetimeDefaultParser,
64+
RustcSimdMonomorphizeLaneLimitParser,
6465
};
6566
use crate::attributes::semantics::MayDangleParser;
6667
use crate::attributes::stability::{
@@ -208,6 +209,7 @@ attribute_parsers!(
208209
Single<RustcForceInlineParser>,
209210
Single<RustcLayoutScalarValidRangeEndParser>,
210211
Single<RustcLayoutScalarValidRangeStartParser>,
212+
Single<RustcLegacyConstGenericsParser>,
211213
Single<RustcObjectLifetimeDefaultParser>,
212214
Single<RustcSimdMonomorphizeLaneLimitParser>,
213215
Single<SanitizeParser>,

compiler/rustc_codegen_cranelift/src/inline_asm.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -857,19 +857,9 @@ fn call_inline_asm<'tcx>(
857857

858858
fn asm_clif_type<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option<types::Type> {
859859
match ty.kind() {
860-
// Adapted from https://github.com/rust-lang/rust/blob/f3c66088610c1b80110297c2d9a8b5f9265b013f/compiler/rustc_hir_analysis/src/check/intrinsicck.rs#L136-L151
860+
// Adapted from https://github.com/rust-lang/rust/blob/df44a57fd29fca899ce473f85ed64efd0708dd7c/compiler/rustc_hir_typeck/src/inline_asm.rs#L180-L183
861861
ty::Adt(adt, args) if fx.tcx.is_lang_item(adt.did(), LangItem::MaybeUninit) => {
862-
let fields = &adt.non_enum_variant().fields;
863-
let ty = fields[FieldIdx::ONE].ty(fx.tcx, args);
864-
let ty::Adt(ty, args) = ty.kind() else {
865-
unreachable!("expected first field of `MaybeUninit` to be an ADT")
866-
};
867-
assert!(
868-
ty.is_manually_drop(),
869-
"expected first field of `MaybeUninit` to be `ManuallyDrop`"
870-
);
871-
let fields = &ty.non_enum_variant().fields;
872-
let ty = fields[FieldIdx::ZERO].ty(fx.tcx, args);
862+
let ty = args.type_at(0);
873863
fx.clif_type(ty)
874864
}
875865
_ => fx.clif_type(ty),

0 commit comments

Comments
 (0)