Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

File tree

52 files changed

+1150
-257
lines changed

Some content is hidden

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

52 files changed

+1150
-257
lines changed

‎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+
use super::{AttributeOrder, OnDuplicate};
9+
use crate::attributes::SingleAttributeParser;
10+
use crate::context::{AcceptContext, AllowedTargets, MaybeWarn, Stage};
11+
use crate::parser::ArgParser;
12+
13+
pub(crate) struct CustomMirParser;
14+
15+
impl<S: Stage> SingleAttributeParser<S> for CustomMirParser {
16+
const PATH: &[rustc_span::Symbol] = &[sym::custom_mir];
17+
18+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
19+
20+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
21+
22+
const ALLOWED_TARGETS: AllowedTargets =
23+
AllowedTargets::AllowList(&[MaybeWarn::Allow(Target::Fn)]);
24+
25+
const TEMPLATE: AttributeTemplate = template!(List: &[r#"dialect = "...", phase = "...""#]);
26+
27+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
28+
let Some(list) = args.list() else {
29+
cx.expected_list(cx.attr_span);
30+
return None;
31+
};
32+
33+
let mut dialect = None;
34+
let mut phase = None;
35+
let mut failed = false;
36+
37+
for item in list.mixed() {
38+
let Some(meta_item) = item.meta_item() else {
39+
cx.expected_name_value(item.span(), None);
40+
failed = true;
41+
break;
42+
};
43+
44+
if let Some(arg) = meta_item.word_is(sym::dialect) {
45+
extract_value(cx, sym::dialect, arg, meta_item.span(), &mut dialect, &mut failed);
46+
} else if let Some(arg) = meta_item.word_is(sym::phase) {
47+
extract_value(cx, sym::phase, arg, meta_item.span(), &mut phase, &mut failed);
48+
} else if let Some(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+
return None;
63+
}
64+
65+
Some(AttributeKind::CustomMir(dialect, phase, cx.attr_span))
66+
}
67+
}
68+
69+
fn extract_value<S: Stage>(
70+
cx: &mut AcceptContext<'_, '_, S>,
71+
key: Symbol,
72+
arg: &ArgParser<'_>,
73+
span: Span,
74+
out_val: &mut Option<(Symbol, Span)>,
75+
failed: &mut bool,
76+
) {
77+
if out_val.is_some() {
78+
cx.duplicate_key(span, key);
79+
*failed = true;
80+
return;
81+
}
82+
83+
let Some(val) = arg.name_value() else {
84+
cx.expected_single_argument(arg.span().unwrap_or(span));
85+
*failed = true;
86+
return;
87+
};
88+
89+
let Some(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+
fn parse_dialect<S: Stage>(
99+
cx: &mut AcceptContext<'_, '_, S>,
100+
dialect: Option<(Symbol, Span)>,
101+
failed: &mut bool,
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+
return None;
114+
}
115+
};
116+
117+
Some((dialect, span))
118+
}
119+
120+
fn parse_phase<S: Stage>(
121+
cx: &mut AcceptContext<'_, '_, S>,
122+
phase: Option<(Symbol, Span)>,
123+
failed: &mut bool,
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+
return None;
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
use crate::attributes::proc_macro_attrs::{
4747
ProcMacroAttributeParser, ProcMacroDeriveParser, ProcMacroParser, RustcBuiltinMacroParser,
4848
};
49+
use crate::attributes::prototype::CustomMirParser;
4950
use crate::attributes::repr::{AlignParser, ReprParser};
5051
use crate::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+
if let Some(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
if let Some(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) enum TypeKind {
340346
Void = 0,
341347
Half = 1,
@@ -1046,6 +1052,8 @@ unsafe extern "C" {
10461052
CanThrow: llvm::Bool,
10471053
) -> &'ll Value;
10481054

1055+
pub(crate) safe fn LLVMGetTypeKind(Ty: &Type) -> RawEnum<TypeKind>;
1056+
10491057
// Operations on integer types
10501058
pub(crate) fn LLVMInt1TypeInContext(C: &Context) -> &Type;
10511059
pub(crate) fn LLVMInt8TypeInContext(C: &Context) -> &Type;
@@ -1197,7 +1205,7 @@ unsafe extern "C" {
11971205
pub(crate) safe fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
11981206
pub(crate) safe fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
11991207
pub(crate) safe fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
1200-
pub(crate) safe fn LLVMRustSetTailCallKind(CallInst: &Value, Kind: TailCallKind);
1208+
pub(crate) safe fn LLVMSetTailCallKind(CallInst: &Value, kind: TailCallKind);
12011209

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

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

‎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
fn type_kind(&self, ty: &'ll Type) -> TypeKind {
207-
unsafe{llvm::LLVMRustGetTypeKind(ty).to_generic()}
207+
llvm::LLVMGetTypeKind(ty).to_rust().to_generic()
208208
}
209209

210210
fn type_ptr(&self) -> &'ll Type {

‎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+
impl IntoDiagArg for MirDialect {
317+
fn into_diag_arg(self, _path: &mut Option<PathBuf>) -> DiagArgValue {
318+
let arg = match self {
319+
MirDialect::Analysis => "analysis",
320+
MirDialect::Built => "built",
321+
MirDialect::Runtime => "runtime",
322+
};
323+
DiagArgValue::Str(Cow::Borrowed(arg))
324+
}
325+
}
326+
327+
impl IntoDiagArg for MirPhase {
328+
fn into_diag_arg(self, _path: &mut Option<PathBuf>) -> DiagArgValue {
329+
let arg = match self {
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
pub struct DiagSymbolList<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)

AltStyle によって変換されたページ (->オリジナル) /