Skip to content

Commit 239e8b1

Browse files
committed
Auto merge of #145551 - Zalathar:rollup-eo75r94, r=Zalathar
Rollup of 10 pull requests Successful merges: - #144838 (Fix outdated doc comment) - #145206 (Port `#[custom_mir(..)]` to the new attribute system) - #145208 (Implement declarative (`macro_rules!`) derive macros (RFC 3698)) - #145309 (Fix `-Zregparm` for LLVM builtins) - #145355 (Add codegen test for issue 122734) - #145420 (cg_llvm: Use LLVM-C bindings for `LLVMSetTailCallKind`, `LLVMGetTypeKind`) - #145451 (Add static glibc to the nix dev shell) - #145460 (Speedup `copy_src_dirs` in bootstrap) - #145476 (Fix typo in doc for library/std/src/fs.rs#set_permissions) - #145485 (Fix deprecation attributes on foreign statics) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 425a9c0 + ab57f43 commit 239e8b1

52 files changed

Lines changed: 1150 additions & 257 deletions

Some content is hidden

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

‎compiler/rustc_attr_parsing/src/attributes/deprecation.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
5454
Allow(Target::TyAlias),
5555
Allow(Target::Use),
5656
Allow(Target::ForeignFn),
57+
Allow(Target::ForeignStatic),
58+
Allow(Target::ForeignTy),
5759
Allow(Target::Field),
5860
Allow(Target::Trait),
5961
Allow(Target::AssocTy),

‎compiler/rustc_attr_parsing/src/attributes/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub(crate) mod no_implicit_prelude;
4343
pub(crate)mod non_exhaustive;
4444
pub(crate)mod path;
4545
pub(crate)mod proc_macro_attrs;
46+
pub(crate)mod prototype;
4647
pub(crate)mod repr;
4748
pub(crate)mod rustc_internal;
4849
pub(crate)mod semantics;
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
//! Attributes that are only used on function prototypes.
2+
3+
use rustc_feature::{AttributeTemplate, template};
4+
use rustc_hir::Target;
5+
use rustc_hir::attrs::{AttributeKind,MirDialect,MirPhase};
6+
use rustc_span::{Span,Symbol, sym};
7+
8+
usesuper::{AttributeOrder,OnDuplicate};
9+
usecrate::attributes::SingleAttributeParser;
10+
usecrate::context::{AcceptContext,AllowedTargets,MaybeWarn,Stage};
11+
usecrate::parser::ArgParser;
12+
13+
pub(crate)structCustomMirParser;
14+
15+
impl<S:Stage>SingleAttributeParser<S>forCustomMirParser{
16+
constPATH:&[rustc_span::Symbol] = &[sym::custom_mir];
17+
18+
constATTRIBUTE_ORDER:AttributeOrder = AttributeOrder::KeepOutermost;
19+
20+
constON_DUPLICATE:OnDuplicate<S> = OnDuplicate::Error;
21+
22+
constALLOWED_TARGETS:AllowedTargets =
23+
AllowedTargets::AllowList(&[MaybeWarn::Allow(Target::Fn)]);
24+
25+
constTEMPLATE:AttributeTemplate = template!(List:&[r#"dialect = "...", phase = "...""#]);
26+
27+
fnconvert(cx:&mutAcceptContext<'_,'_,S>,args:&ArgParser<'_>) -> Option<AttributeKind>{
28+
letSome(list) = args.list()else{
29+
cx.expected_list(cx.attr_span);
30+
returnNone;
31+
};
32+
33+
letmut dialect = None;
34+
letmut phase = None;
35+
letmut failed = false;
36+
37+
for item in list.mixed(){
38+
letSome(meta_item) = item.meta_item()else{
39+
cx.expected_name_value(item.span(),None);
40+
failed = true;
41+
break;
42+
};
43+
44+
ifletSome(arg) = meta_item.word_is(sym::dialect){
45+
extract_value(cx, sym::dialect, arg, meta_item.span(),&mut dialect,&mut failed);
46+
}elseifletSome(arg) = meta_item.word_is(sym::phase){
47+
extract_value(cx, sym::phase, arg, meta_item.span(),&mut phase,&mut failed);
48+
}elseifletSome(word) = meta_item.path().word(){
49+
let word = word.to_string();
50+
cx.unknown_key(meta_item.span(), word,&["dialect","phase"]);
51+
failed = true;
52+
}else{
53+
cx.expected_name_value(meta_item.span(),None);
54+
failed = true;
55+
};
56+
}
57+
58+
let dialect = parse_dialect(cx, dialect,&mut failed);
59+
let phase = parse_phase(cx, phase,&mut failed);
60+
61+
if failed {
62+
returnNone;
63+
}
64+
65+
Some(AttributeKind::CustomMir(dialect, phase, cx.attr_span))
66+
}
67+
}
68+
69+
fnextract_value<S:Stage>(
70+
cx:&mutAcceptContext<'_,'_,S>,
71+
key:Symbol,
72+
arg:&ArgParser<'_>,
73+
span:Span,
74+
out_val:&mutOption<(Symbol,Span)>,
75+
failed:&mutbool,
76+
){
77+
if out_val.is_some(){
78+
cx.duplicate_key(span, key);
79+
*failed = true;
80+
return;
81+
}
82+
83+
letSome(val) = arg.name_value()else{
84+
cx.expected_single_argument(arg.span().unwrap_or(span));
85+
*failed = true;
86+
return;
87+
};
88+
89+
letSome(value_sym) = val.value_as_str()else{
90+
cx.expected_string_literal(val.value_span,Some(val.value_as_lit()));
91+
*failed = true;
92+
return;
93+
};
94+
95+
*out_val = Some((value_sym, val.value_span));
96+
}
97+
98+
fnparse_dialect<S:Stage>(
99+
cx:&mutAcceptContext<'_,'_,S>,
100+
dialect:Option<(Symbol,Span)>,
101+
failed:&mutbool,
102+
) -> Option<(MirDialect,Span)>{
103+
let(dialect, span) = dialect?;
104+
105+
let dialect = match dialect {
106+
sym::analysis => MirDialect::Analysis,
107+
sym::built => MirDialect::Built,
108+
sym::runtime => MirDialect::Runtime,
109+
110+
_ => {
111+
cx.expected_specific_argument(span,vec!["analysis","built","runtime"]);
112+
*failed = true;
113+
returnNone;
114+
}
115+
};
116+
117+
Some((dialect, span))
118+
}
119+
120+
fnparse_phase<S:Stage>(
121+
cx:&mutAcceptContext<'_,'_,S>,
122+
phase:Option<(Symbol,Span)>,
123+
failed:&mutbool,
124+
) -> Option<(MirPhase,Span)>{
125+
let(phase, span) = phase?;
126+
127+
let phase = match phase {
128+
sym::initial => MirPhase::Initial,
129+
sym::post_cleanup => MirPhase::PostCleanup,
130+
sym::optimized => MirPhase::Optimized,
131+
132+
_ => {
133+
cx.expected_specific_argument(span,vec!["initial","post-cleanup","optimized"]);
134+
*failed = true;
135+
returnNone;
136+
}
137+
};
138+
139+
Some((phase, span))
140+
}

‎compiler/rustc_attr_parsing/src/context.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use crate::attributes::path::PathParser as PathAttributeParser;
4646
usecrate::attributes::proc_macro_attrs::{
4747
ProcMacroAttributeParser,ProcMacroDeriveParser,ProcMacroParser,RustcBuiltinMacroParser,
4848
};
49+
usecrate::attributes::prototype::CustomMirParser;
4950
usecrate::attributes::repr::{AlignParser,ReprParser};
5051
usecrate::attributes::rustc_internal::{
5152
RustcLayoutScalarValidRangeEnd,RustcLayoutScalarValidRangeStart,
@@ -167,6 +168,7 @@ attribute_parsers!(
167168

168169
// tidy-alphabetical-start
169170
Single<CoverageParser>,
171+
Single<CustomMirParser>,
170172
Single<DeprecationParser>,
171173
Single<DummyParser>,
172174
Single<ExportNameParser>,
@@ -1060,6 +1062,9 @@ pub(crate) fn allowed_targets_applied(
10601062
if !features.stmt_expr_attributes(){
10611063
allowed_targets.retain(|t| !matches!(t,Target::Expression | Target::Statement));
10621064
}
1065+
if !features.extern_types(){
1066+
allowed_targets.retain(|t| !matches!(t,Target::ForeignTy));
1067+
}
10631068
}
10641069

10651070
// We define groups of "similar" targets.

‎compiler/rustc_codegen_llvm/src/builder.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14531453
instance:Option<Instance<'tcx>>,
14541454
){
14551455
let call = self.call(llty, fn_attrs,Some(fn_abi), llfn, args, funclet, instance);
1456-
llvm::LLVMRustSetTailCallKind(call, llvm::TailCallKind::MustTail);
1456+
llvm::LLVMSetTailCallKind(call, llvm::TailCallKind::MustTail);
14571457

14581458
match&fn_abi.ret.mode{
14591459
PassMode::Ignore | PassMode::Indirect{ .. } => self.ret_void(),

‎compiler/rustc_codegen_llvm/src/context.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,15 @@ pub(crate) unsafe fn create_module<'ll>(
377377
}
378378
}
379379

380+
ifletSome(regparm_count) = sess.opts.unstable_opts.regparm{
381+
llvm::add_module_flag_u32(
382+
llmod,
383+
llvm::ModuleFlagMergeBehavior::Error,
384+
"NumRegisterParameters",
385+
regparm_count,
386+
);
387+
}
388+
380389
ifletSome(BranchProtection{ bti, pac_ret }) = sess.opts.unstable_opts.branch_protection{
381390
if sess.target.arch == "aarch64"{
382391
llvm::add_module_flag_u32(

‎compiler/rustc_codegen_llvm/src/llvm/ffi.rs‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub(crate) enum ModuleFlagMergeBehavior {
9797

9898
// Consts for the LLVM CallConv type, pre-cast to usize.
9999

100+
/// Must match the layout of `LLVMTailCallKind`.
100101
#[derive(Copy,Clone,PartialEq,Debug)]
101102
#[repr(C)]
102103
#[allow(dead_code)]
@@ -332,10 +333,15 @@ impl RealPredicate {
332333
}
333334
}
334335

335-
/// LLVMTypeKind
336-
#[derive(Copy,Clone,PartialEq,Debug)]
336+
/// Must match the layout of `LLVMTypeKind`.
337+
///
338+
/// Use [`RawEnum<TypeKind>`] for values of `LLVMTypeKind` returned from LLVM,
339+
/// to avoid risk of UB if LLVM adds new enum values.
340+
///
341+
/// All of LLVM's variants should be declared here, even if no Rust-side code refers
342+
/// to them, because unknown variants will cause [`RawEnum::to_rust`] to panic.
343+
#[derive(Copy,Clone,PartialEq,Debug,TryFromU32)]
337344
#[repr(C)]
338-
#[expect(dead_code, reason = "Some variants are unused, but are kept to match LLVM-C")]
339345
pub(crate)enumTypeKind{
340346
Void = 0,
341347
Half = 1,
@@ -1046,6 +1052,8 @@ unsafe extern "C" {
10461052
CanThrow: llvm::Bool,
10471053
) -> &'llValue;
10481054

1055+
pub(crate) safe fnLLVMGetTypeKind(Ty:&Type) -> RawEnum<TypeKind>;
1056+
10491057
// Operations on integer types
10501058
pub(crate)fnLLVMInt1TypeInContext(C:&Context) -> &Type;
10511059
pub(crate)fnLLVMInt8TypeInContext(C:&Context) -> &Type;
@@ -1197,7 +1205,7 @@ unsafe extern "C" {
11971205
pub(crate) safe fnLLVMIsGlobalConstant(GlobalVar:&Value) -> Bool;
11981206
pub(crate) safe fnLLVMSetGlobalConstant(GlobalVar:&Value,IsConstant:Bool);
11991207
pub(crate) safe fnLLVMSetTailCall(CallInst:&Value,IsTailCall:Bool);
1200-
pub(crate) safe fnLLVMRustSetTailCallKind(CallInst:&Value,Kind:TailCallKind);
1208+
pub(crate) safe fnLLVMSetTailCallKind(CallInst:&Value,kind:TailCallKind);
12011209

12021210
// Operations on attributes
12031211
pub(crate)fnLLVMCreateStringAttribute(
@@ -1841,9 +1849,6 @@ unsafe extern "C" {
18411849
// Create and destroy contexts.
18421850
pub(crate)fnLLVMRustContextCreate(shouldDiscardNames:bool) -> &'staticmutContext;
18431851

1844-
/// See llvm::LLVMTypeKind::getTypeID.
1845-
pub(crate)fnLLVMRustGetTypeKind(Ty:&Type) -> TypeKind;
1846-
18471852
// Operations on all values
18481853
pub(crate)fnLLVMRustGlobalAddMetadata<'a>(
18491854
Val:&'aValue,

‎compiler/rustc_codegen_llvm/src/type_.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> BaseTypeCodegenMethods for GenericCx<'ll, CX> {
204204
}
205205

206206
fntype_kind(&self,ty:&'llType) -> TypeKind{
207-
unsafe{llvm::LLVMRustGetTypeKind(ty).to_generic()}
207+
llvm::LLVMGetTypeKind(ty).to_rust().to_generic()
208208
}
209209

210210
fntype_ptr(&self) -> &'llType{

‎compiler/rustc_errors/src/diagnostic_impls.rs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_abi::TargetDataLayoutErrors;
99
use rustc_ast::util::parser::ExprPrecedence;
1010
use rustc_ast_pretty::pprust;
1111
use rustc_hir::RustcVersion;
12+
use rustc_hir::attrs::{MirDialect,MirPhase};
1213
use rustc_macros::Subdiagnostic;
1314
use rustc_span::edition::Edition;
1415
use rustc_span::{Ident,MacroRulesNormalizedIdent,Span,Symbol};
@@ -312,6 +313,28 @@ impl IntoDiagArg for ExprPrecedence {
312313
}
313314
}
314315

316+
implIntoDiagArgforMirDialect{
317+
fninto_diag_arg(self,_path:&mutOption<PathBuf>) -> DiagArgValue{
318+
let arg = matchself{
319+
MirDialect::Analysis => "analysis",
320+
MirDialect::Built => "built",
321+
MirDialect::Runtime => "runtime",
322+
};
323+
DiagArgValue::Str(Cow::Borrowed(arg))
324+
}
325+
}
326+
327+
implIntoDiagArgforMirPhase{
328+
fninto_diag_arg(self,_path:&mutOption<PathBuf>) -> DiagArgValue{
329+
let arg = matchself{
330+
MirPhase::Initial => "initial",
331+
MirPhase::PostCleanup => "post-cleanup",
332+
MirPhase::Optimized => "optimized",
333+
};
334+
DiagArgValue::Str(Cow::Borrowed(arg))
335+
}
336+
}
337+
315338
#[derive(Clone)]
316339
pubstructDiagSymbolList<S = Symbol>(Vec<S>);
317340

‎compiler/rustc_expand/messages.ftl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ expand_invalid_fragment_specifier =
7070
invalid fragment specifier `{$fragment}`
7171
.help = {$help}
7272
73-
expand_macro_args_bad_delim = macro attribute argument matchers require parentheses
73+
expand_macro_args_bad_delim = `{$rule_kw}` rule argument matchers require parentheses
7474
expand_macro_args_bad_delim_sugg = the delimiters should be `(` and `)`
7575
7676
expand_macro_body_stability =

0 commit comments

Comments
 (0)