Skip to content

Commit befb020

Browse files
committed
Auto merge of #142558 - tgross35:rollup-ld8nn4w, r=tgross35
Rollup of 7 pull requests Successful merges: - #138237 (Get rid of `EscapeDebugInner`.) - #140809 (Reduce special casing for the panic runtime) - #141990 (Implement send_signal for unix child processes) - #142082 (Refactor `rustc_attr_data_structures` documentation) - #142125 (Stabilize "file_lock" feature) - #142528 (clarify `rustc_do_not_const_check` comment) - #142530 (use `if let` guards where possible) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 68ac5ab + f145a46 commit befb020

File tree

31 files changed

+377
-292
lines changed

31 files changed

+377
-292
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,54 @@ impl Deprecation {
130130
}
131131
}
132132

133-
/// Represent parsed, *built in*, inert attributes.
133+
/// Represents parsed *built-in* inert attributes.
134134
///
135-
/// That means attributes that are not actually ever expanded.
136-
/// For more information on this, see the module docs on the [`rustc_attr_parsing`] crate.
137-
/// They're instead used as markers, to guide the compilation process in various way in most every stage of the compiler.
138-
/// These are kept around after the AST, into the HIR and further on.
135+
/// ## Overview
136+
/// These attributes are markers that guide the compilation process and are never expanded into other code.
137+
/// They persist throughout the compilation phases, from AST to HIR and beyond.
139138
///
140-
/// The word "parsed" could be a little misleading here, because the parser already parses
141-
/// attributes early on. However, the result, an [`ast::Attribute`]
142-
/// is only parsed at a high level, still containing a token stream in many cases. That is
143-
/// because the structure of the contents varies from attribute to attribute.
144-
/// With a parsed attribute I mean that each attribute is processed individually into a
145-
/// final structure, which on-site (the place where the attribute is useful for, think the
146-
/// the place where `must_use` is checked) little to no extra parsing or validating needs to
147-
/// happen.
139+
/// ## Attribute Processing
140+
/// While attributes are initially parsed by [`rustc_parse`] into [`ast::Attribute`], they still contain raw token streams
141+
/// because different attributes have different internal structures. This enum represents the final,
142+
/// fully parsed form of these attributes, where each variant contains contains all the information and
143+
/// structure relevant for the specific attribute.
148144
///
149-
/// For more docs, look in [`rustc_attr_parsing`].
145+
/// Some attributes can be applied multiple times to the same item, and they are "collapsed" into a single
146+
/// semantic attribute. For example:
147+
/// ```rust
148+
/// #[repr(C)]
149+
/// #[repr(packed)]
150+
/// struct S { }
151+
/// ```
152+
/// This is equivalent to `#[repr(C, packed)]` and results in a single [`AttributeKind::Repr`] containing
153+
/// both `C` and `packed` annotations. This collapsing happens during parsing and is reflected in the
154+
/// data structures defined in this enum.
150155
///
156+
/// ## Usage
157+
/// These parsed attributes are used throughout the compiler to:
158+
/// - Control code generation (e.g., `#[repr]`)
159+
/// - Mark API stability (`#[stable]`, `#[unstable]`)
160+
/// - Provide documentation (`#[doc]`)
161+
/// - Guide compiler behavior (e.g., `#[allow_internal_unstable]`)
162+
///
163+
/// ## Note on Attribute Organization
164+
/// Some attributes like `InlineAttr`, `OptimizeAttr`, and `InstructionSetAttr` are defined separately
165+
/// from this enum because they are used in specific compiler phases (like code generation) and don't
166+
/// need to persist throughout the entire compilation process. They are typically processed and
167+
/// converted into their final form earlier in the compilation pipeline.
168+
///
169+
/// For example:
170+
/// - `InlineAttr` is used during code generation to control function inlining
171+
/// - `OptimizeAttr` is used to control optimization levels
172+
/// - `InstructionSetAttr` is used for target-specific code generation
173+
///
174+
/// These attributes are handled by their respective compiler passes in the [`rustc_codegen_ssa`] crate
175+
/// and don't need to be preserved in the same way as the attributes in this enum.
176+
///
177+
/// For more details on attribute parsing, see the [`rustc_attr_parsing`] crate.
178+
///
179+
/// [`rustc_parse`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/index.html
180+
/// [`rustc_codegen_ssa`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/index.html
151181
/// [`rustc_attr_parsing`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html
152182
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
153183
pub enum AttributeKind {

compiler/rustc_attr_data_structures/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Data structures for representing parsed attributes in the Rust compiler.
2+
//! For detailed documentation about attribute processing,
3+
//! see [rustc_attr_parsing](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html).
4+
15
// tidy-alphabetical-start
26
#![allow(internal_features)]
37
#![doc(rust_logo)]

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ pub(crate) fn expand_test_or_bench(
118118

119119
let (item, is_stmt) = match item {
120120
Annotatable::Item(i) => (i, false),
121-
Annotatable::Stmt(stmt) if matches!(stmt.kind, ast::StmtKind::Item(_)) => {
122-
// FIXME: Use an 'if let' guard once they are implemented
123-
if let ast::StmtKind::Item(i) = stmt.kind { (i, true) } else { unreachable!() }
124-
}
121+
Annotatable::Stmt(box ast::Stmt { kind: ast::StmtKind::Item(i), .. }) => (i, true),
125122
other => {
126123
not_testable_error(cx, attr_sp, None);
127124
return vec![other];

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,7 @@ pub(crate) fn linked_symbols(
18291829
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
18301830
if info.level.is_below_threshold(export_threshold) && !tcx.is_compiler_builtins(cnum)
18311831
|| info.used
1832+
|| info.rustc_std_internal_symbol
18321833
{
18331834
symbols.push((
18341835
symbol_export::linking_symbol_name_for_instance_in_crate(tcx, symbol, cnum),

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
131131
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
132132
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
133133
|| used,
134+
rustc_std_internal_symbol: codegen_attrs
135+
.flags
136+
.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL),
134137
};
135138
(def_id.to_def_id(), info)
136139
})
@@ -143,6 +146,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
143146
level: SymbolExportLevel::C,
144147
kind: SymbolExportKind::Data,
145148
used: false,
149+
rustc_std_internal_symbol: false,
146150
},
147151
);
148152
}
@@ -191,6 +195,7 @@ fn exported_symbols_provider_local<'tcx>(
191195
level: info.level,
192196
kind: SymbolExportKind::Text,
193197
used: info.used,
198+
rustc_std_internal_symbol: info.rustc_std_internal_symbol,
194199
},
195200
)
196201
})
@@ -207,6 +212,7 @@ fn exported_symbols_provider_local<'tcx>(
207212
level: SymbolExportLevel::C,
208213
kind: SymbolExportKind::Text,
209214
used: false,
215+
rustc_std_internal_symbol: false,
210216
},
211217
));
212218
}
@@ -229,6 +235,7 @@ fn exported_symbols_provider_local<'tcx>(
229235
level: SymbolExportLevel::Rust,
230236
kind: SymbolExportKind::Text,
231237
used: false,
238+
rustc_std_internal_symbol: true,
232239
},
233240
));
234241
}
@@ -243,6 +250,7 @@ fn exported_symbols_provider_local<'tcx>(
243250
level: SymbolExportLevel::Rust,
244251
kind: SymbolExportKind::Data,
245252
used: false,
253+
rustc_std_internal_symbol: true,
246254
},
247255
))
248256
}
@@ -262,6 +270,7 @@ fn exported_symbols_provider_local<'tcx>(
262270
level: SymbolExportLevel::C,
263271
kind: SymbolExportKind::Data,
264272
used: false,
273+
rustc_std_internal_symbol: false,
265274
},
266275
)
267276
}));
@@ -287,6 +296,7 @@ fn exported_symbols_provider_local<'tcx>(
287296
level: SymbolExportLevel::C,
288297
kind: SymbolExportKind::Data,
289298
used: false,
299+
rustc_std_internal_symbol: false,
290300
},
291301
)
292302
}));
@@ -304,6 +314,7 @@ fn exported_symbols_provider_local<'tcx>(
304314
level: SymbolExportLevel::C,
305315
kind: SymbolExportKind::Data,
306316
used: true,
317+
rustc_std_internal_symbol: false,
307318
},
308319
));
309320
}
@@ -379,6 +390,8 @@ fn exported_symbols_provider_local<'tcx>(
379390
}
380391
}
381392

393+
// Note: These all set rustc_std_internal_symbol to false as generic functions must not
394+
// be marked with this attribute and we are only handling generic functions here.
382395
match *mono_item {
383396
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
384397
let has_generics = args.non_erasable_generics().next().is_some();
@@ -394,6 +407,7 @@ fn exported_symbols_provider_local<'tcx>(
394407
level: SymbolExportLevel::Rust,
395408
kind: SymbolExportKind::Text,
396409
used: false,
410+
rustc_std_internal_symbol: false,
397411
},
398412
));
399413
}
@@ -416,6 +430,7 @@ fn exported_symbols_provider_local<'tcx>(
416430
level: SymbolExportLevel::Rust,
417431
kind: SymbolExportKind::Text,
418432
used: false,
433+
rustc_std_internal_symbol: false,
419434
},
420435
));
421436
}
@@ -432,6 +447,7 @@ fn exported_symbols_provider_local<'tcx>(
432447
level: SymbolExportLevel::Rust,
433448
kind: SymbolExportKind::Text,
434449
used: false,
450+
rustc_std_internal_symbol: false,
435451
},
436452
));
437453
}
@@ -442,6 +458,7 @@ fn exported_symbols_provider_local<'tcx>(
442458
level: SymbolExportLevel::Rust,
443459
kind: SymbolExportKind::Text,
444460
used: false,
461+
rustc_std_internal_symbol: false,
445462
},
446463
));
447464
}

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::time::{Duration, Instant};
66
use itertools::Itertools;
77
use rustc_abi::FIRST_VARIANT;
88
use rustc_ast as ast;
9-
use rustc_ast::expand::allocator::{ALLOCATOR_METHODS, AllocatorKind, global_fn_name};
9+
use rustc_ast::expand::allocator::AllocatorKind;
1010
use rustc_attr_data_structures::OptimizeAttr;
1111
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1212
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
@@ -1039,26 +1039,6 @@ impl CrateInfo {
10391039
.collect::<Vec<_>>();
10401040
symbols.sort_unstable_by(|a, b| a.0.cmp(&b.0));
10411041
linked_symbols.extend(symbols);
1042-
if tcx.allocator_kind(()).is_some() {
1043-
// At least one crate needs a global allocator. This crate may be placed
1044-
// after the crate that defines it in the linker order, in which case some
1045-
// linkers return an error. By adding the global allocator shim methods to
1046-
// the linked_symbols list, linking the generated symbols.o will ensure that
1047-
// circular dependencies involving the global allocator don't lead to linker
1048-
// errors.
1049-
linked_symbols.extend(ALLOCATOR_METHODS.iter().map(|method| {
1050-
(
1051-
format!(
1052-
"{prefix}{}",
1053-
mangle_internal_symbol(
1054-
tcx,
1055-
global_fn_name(method.name).as_str()
1056-
)
1057-
),
1058-
SymbolExportKind::Text,
1059-
)
1060-
}));
1061-
}
10621042
});
10631043
}
10641044

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
887887
rustc_legacy_const_generics, Normal, template!(List: "N"), ErrorFollowing,
888888
EncodeCrossCrate::Yes,
889889
),
890-
// Do not const-check this function's body. It will always get replaced during CTFE.
890+
// Do not const-check this function's body. It will always get replaced during CTFE via `hook_special_const_fn`.
891891
rustc_attr!(
892892
rustc_do_not_const_check, Normal, template!(Word), WarnFollowing,
893893
EncodeCrossCrate::Yes, "`#[rustc_do_not_const_check]` skips const-check for this function's body",

0 commit comments

Comments
 (0)