Skip to content

Commit 033c0a4

Browse files
committed
Auto merge of #146185 - Zalathar:rollup-n14lyv6, r=Zalathar
Rollup of 24 pull requests Successful merges: - #140459 (Add `read_buf` equivalents for positioned reads) - #143725 (core: add Peekable::next_if_map) - #145209 (Stabilize `path_add_extension`) - #145342 (fix drop scope for `super let` bindings within `if let`) - #145750 (raw_vec.rs: Remove superfluous fn alloc_guard) - #145827 (On unused binding or binding not present in all patterns, suggest potential typo of unit struct/variant or const) - #145932 (Allow `inline(always)` with a target feature behind a unstable feature `target_feature_inline_always`.) - #145962 (Ensure we emit an allocator shim when only some crate types need one) - #145963 (Add LSX accelerated implementation for source file analysis) - #146054 (add `#[must_use]` to `array::repeat`) - #146090 (Derive `PartialEq` for `InvisibleOrigin`) - #146112 (don't uppercase error messages) - #146120 (Correct typo in `rustc_errors` comment) - #146124 (Test `rustc-dev` in `distcheck`) - #146127 (Rename `ToolRustc` to `ToolRustcPrivate`) - #146131 (rustdoc-search: add test case for indexing every item type) - #146134 (llvm: nvptx: Layout update to match LLVM) - #146136 (docs(std): add missing closing code block fences in doc comments) - #146137 (Disallow frontmatter in `--cfg` and `--check-cfg` arguments) - #146140 (compiletest: cygwin follows windows in using PATH for dynamic libraries) - #146150 (fix(rustdoc): match rustc `--emit` precedence ) - #146155 (Make bootstrap self test parallel) - #146161 ([rustdoc] Uncomment code to add scraped rustdoc examples in loaded paths) - #146172 (triagebot: configure some pings when certain attributes are used) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9385c64 + 11ea573 commit 033c0a4

File tree

157 files changed

+2934
-707
lines changed

Some content is hidden

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

157 files changed

+2934
-707
lines changed

compiler/rustc_ast/src/token.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ pub enum CommentKind {
2222
Block,
2323
}
2424

25-
// This type must not implement `Hash` due to the unusual `PartialEq` impl below.
26-
#[derive(Copy, Clone, Debug, Encodable, Decodable, HashStable_Generic)]
25+
#[derive(Copy, Clone, PartialEq, Debug, Encodable, Decodable, HashStable_Generic)]
2726
pub enum InvisibleOrigin {
2827
// From the expansion of a metavariable in a declarative macro.
2928
MetaVar(MetaVarKind),
@@ -45,20 +44,6 @@ impl InvisibleOrigin {
4544
}
4645
}
4746

48-
impl PartialEq for InvisibleOrigin {
49-
#[inline]
50-
fn eq(&self, _other: &InvisibleOrigin) -> bool {
51-
// When we had AST-based nonterminals we couldn't compare them, and the
52-
// old `Nonterminal` type had an `eq` that always returned false,
53-
// resulting in this restriction:
54-
// https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment
55-
// This `eq` emulates that behaviour. We could consider lifting this
56-
// restriction now but there are still cases involving invisible
57-
// delimiters that make it harder than it first appears.
58-
false
59-
}
60-
}
61-
6247
/// Annoyingly similar to `NonterminalKind`, but the slight differences are important.
6348
#[derive(Debug, Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, HashStable_Generic)]
6449
pub enum MetaVarKind {
@@ -142,7 +127,8 @@ impl Delimiter {
142127
}
143128
}
144129

145-
// This exists because `InvisibleOrigin`s should be compared. It is only used for assertions.
130+
// This exists because `InvisibleOrigin`s should not be compared. It is only used for
131+
// assertions.
146132
pub fn eq_ignoring_invisible_origin(&self, other: &Delimiter) -> bool {
147133
match (self, other) {
148134
(Delimiter::Parenthesis, Delimiter::Parenthesis) => true,

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ attr_parsing_unrecognized_repr_hint =
151151
attr_parsing_unstable_cfg_target_compact =
152152
compact `cfg(target(..))` is experimental and subject to change
153153
154-
attr_parsing_unstable_feature_bound_incompatible_stability = Item annotated with `#[unstable_feature_bound]` should not be stable
154+
attr_parsing_unstable_feature_bound_incompatible_stability = item annotated with `#[unstable_feature_bound]` should not be stable
155155
.help = If this item is meant to be stable, do not use any functions annotated with `#[unstable_feature_bound]`. Otherwise, mark this item as unstable with `#[unstable]`
156156
157157
attr_parsing_unsupported_literal_cfg_boolean =

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,18 @@ pub(crate) fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[
2929
}
3030

3131
/// Get LLVM attribute for the provided inline heuristic.
32-
#[inline]
33-
fn inline_attr<'ll>(cx: &CodegenCx<'ll, '_>, inline: InlineAttr) -> Option<&'ll Attribute> {
32+
pub(crate) fn inline_attr<'ll, 'tcx>(
33+
cx: &CodegenCx<'ll, 'tcx>,
34+
instance: ty::Instance<'tcx>,
35+
) -> Option<&'ll Attribute> {
36+
// `optnone` requires `noinline`
37+
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
38+
let inline = match (codegen_fn_attrs.inline, &codegen_fn_attrs.optimize) {
39+
(_, OptimizeAttr::DoNotOptimize) => InlineAttr::Never,
40+
(InlineAttr::None, _) if instance.def.requires_inline(cx.tcx) => InlineAttr::Hint,
41+
(inline, _) => inline,
42+
};
43+
3444
if !cx.tcx.sess.opts.unstable_opts.inline_llvm {
3545
// disable LLVM inlining
3646
return Some(AttributeKind::NoInline.create_attr(cx.llcx));
@@ -346,14 +356,6 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
346356
OptimizeAttr::Speed => {}
347357
}
348358

349-
// `optnone` requires `noinline`
350-
let inline = match (codegen_fn_attrs.inline, &codegen_fn_attrs.optimize) {
351-
(_, OptimizeAttr::DoNotOptimize) => InlineAttr::Never,
352-
(InlineAttr::None, _) if instance.def.requires_inline(cx.tcx) => InlineAttr::Hint,
353-
(inline, _) => inline,
354-
};
355-
to_add.extend(inline_attr(cx, inline));
356-
357359
if cx.sess().must_emit_unwind_tables() {
358360
to_add.push(uwtable_attr(cx.llcx, cx.sess().opts.unstable_opts.use_sync_unwind));
359361
}
@@ -488,6 +490,14 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
488490
let function_features =
489491
codegen_fn_attrs.target_features.iter().map(|f| f.name.as_str()).collect::<Vec<&str>>();
490492

493+
// Apply function attributes as per usual if there are no user defined
494+
// target features otherwise this will get applied at the callsite.
495+
if function_features.is_empty() {
496+
if let Some(inline_attr) = inline_attr(cx, instance) {
497+
to_add.push(inline_attr);
498+
}
499+
}
500+
491501
let function_features = function_features
492502
.iter()
493503
// Convert to LLVMFeatures and filter out unavailable ones
@@ -517,6 +527,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
517527
let function_features = function_features.iter().map(|s| s.as_str());
518528
let target_features: String =
519529
global_features.chain(function_features).intersperse(",").collect();
530+
520531
if !target_features.is_empty() {
521532
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "target-features", &target_features));
522533
}

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13921392
fn call(
13931393
&mut self,
13941394
llty: &'ll Type,
1395-
fn_attrs: Option<&CodegenFnAttrs>,
1395+
fn_call_attrs: Option<&CodegenFnAttrs>,
13961396
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
13971397
llfn: &'ll Value,
13981398
args: &[&'ll Value],
@@ -1409,10 +1409,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14091409
}
14101410

14111411
// Emit CFI pointer type membership test
1412-
self.cfi_type_test(fn_attrs, fn_abi, instance, llfn);
1412+
self.cfi_type_test(fn_call_attrs, fn_abi, instance, llfn);
14131413

14141414
// Emit KCFI operand bundle
1415-
let kcfi_bundle = self.kcfi_operand_bundle(fn_attrs, fn_abi, instance, llfn);
1415+
let kcfi_bundle = self.kcfi_operand_bundle(fn_call_attrs, fn_abi, instance, llfn);
14161416
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.as_ref()) {
14171417
bundles.push(kcfi_bundle);
14181418
}
@@ -1429,6 +1429,29 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14291429
c"".as_ptr(),
14301430
)
14311431
};
1432+
1433+
if let Some(instance) = instance {
1434+
// Attributes on the function definition being called
1435+
let fn_defn_attrs = self.cx.tcx.codegen_fn_attrs(instance.def_id());
1436+
if let Some(fn_call_attrs) = fn_call_attrs
1437+
&& !fn_call_attrs.target_features.is_empty()
1438+
// If there is an inline attribute and a target feature that matches
1439+
// we will add the attribute to the callsite otherwise we'll omit
1440+
// this and not add the attribute to prevent soundness issues.
1441+
&& let Some(inlining_rule) = attributes::inline_attr(&self.cx, instance)
1442+
&& self.cx.tcx.is_target_feature_call_safe(
1443+
&fn_call_attrs.target_features,
1444+
&fn_defn_attrs.target_features,
1445+
)
1446+
{
1447+
attributes::apply_to_callsite(
1448+
call,
1449+
llvm::AttributePlace::Function,
1450+
&[inlining_rule],
1451+
);
1452+
}
1453+
}
1454+
14321455
if let Some(fn_abi) = fn_abi {
14331456
fn_abi.apply_attrs_callsite(self, call);
14341457
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ pub(crate) unsafe fn create_module<'ll>(
217217
// LLVM 22.0 updated the default layout on avr: https://github.com/llvm/llvm-project/pull/153010
218218
target_data_layout = target_data_layout.replace("n8:16", "n8")
219219
}
220+
if sess.target.arch == "nvptx64" {
221+
// LLVM 22 updated the NVPTX layout to indicate 256-bit vector load/store: https://github.com/llvm/llvm-project/pull/155198
222+
target_data_layout = target_data_layout.replace("-i256:256", "");
223+
}
220224
}
221225

222226
// Ensure the data-layout values hardcoded remain the defaults.

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ codegen_ssa_dynamic_linking_with_lto =
4040
.note = only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO
4141
4242
codegen_ssa_error_calling_dlltool =
43-
Error calling dlltool '{$dlltool_path}': {$error}
43+
error calling dlltool '{$dlltool_path}': {$error}
4444
4545
codegen_ssa_error_creating_import_library =
46-
Error creating import library for {$lib_name}: {$error}
46+
error creating import library for {$lib_name}: {$error}
4747
4848
codegen_ssa_error_creating_remark_dir = failed to create remark directory: {$error}
4949
5050
codegen_ssa_error_writing_def_file =
51-
Error writing .DEF file: {$error}
51+
error writing .DEF file: {$error}
5252
5353
codegen_ssa_expected_name_value_pair = expected name value pair
5454
@@ -264,9 +264,9 @@ codegen_ssa_shuffle_indices_evaluation = could not evaluate shuffle_indices at c
264264
265265
codegen_ssa_specify_libraries_to_link = use the `-l` flag to specify native libraries to link
266266
267-
codegen_ssa_static_library_native_artifacts = Link against the following native artifacts when linking against this static library. The order and any duplication can be significant on some platforms.
267+
codegen_ssa_static_library_native_artifacts = link against the following native artifacts when linking against this static library. The order and any duplication can be significant on some platforms.
268268
269-
codegen_ssa_static_library_native_artifacts_to_file = Native artifacts to link against have been written to {$path}. The order and any duplication can be significant on some platforms.
269+
codegen_ssa_static_library_native_artifacts_to_file = native artifacts to link against have been written to {$path}. The order and any duplication can be significant on some platforms.
270270
271271
codegen_ssa_stripping_debug_info_failed = stripping debug info with `{$util}` failed: {$status}
272272
.note = {$output}
@@ -364,13 +364,13 @@ codegen_ssa_unable_to_run = unable to run `{$util}`: {$error}
364364
365365
codegen_ssa_unable_to_run_dsymutil = unable to run `dsymutil`: {$error}
366366
367-
codegen_ssa_unable_to_write_debugger_visualizer = Unable to write debugger visualizer file `{$path}`: {$error}
367+
codegen_ssa_unable_to_write_debugger_visualizer = unable to write debugger visualizer file `{$path}`: {$error}
368368
369369
codegen_ssa_unexpected_parameter_name = unexpected parameter name
370370
.label = expected `{$prefix_nops}` or `{$entry_nops}`
371371
372372
codegen_ssa_unknown_archive_kind =
373-
Don't know how to build archive of type: {$kind}
373+
don't know how to build archive of type: {$kind}
374374
375375
codegen_ssa_unknown_ctarget_feature =
376376
unknown and unstable feature specified for `-Ctarget-feature`: `{$feature}`

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use super::linker::{self, Linker};
5858
use super::metadata::{MetadataPosition, create_wrapper_file};
5959
use super::rpath::{self, RPathConfig};
6060
use super::{apple, versioned_llvm_target};
61+
use crate::base::needs_allocator_shim_for_linking;
6162
use crate::{
6263
CodegenResults, CompiledModule, CrateInfo, NativeLib, errors, looks_like_rust_object_file,
6364
};
@@ -2080,9 +2081,17 @@ fn add_local_crate_regular_objects(cmd: &mut dyn Linker, codegen_results: &Codeg
20802081
}
20812082

20822083
/// Add object files for allocator code linked once for the whole crate tree.
2083-
fn add_local_crate_allocator_objects(cmd: &mut dyn Linker, codegen_results: &CodegenResults) {
2084-
if let Some(obj) = codegen_results.allocator_module.as_ref().and_then(|m| m.object.as_ref()) {
2085-
cmd.add_object(obj);
2084+
fn add_local_crate_allocator_objects(
2085+
cmd: &mut dyn Linker,
2086+
codegen_results: &CodegenResults,
2087+
crate_type: CrateType,
2088+
) {
2089+
if needs_allocator_shim_for_linking(&codegen_results.crate_info.dependency_formats, crate_type)
2090+
{
2091+
if let Some(obj) = codegen_results.allocator_module.as_ref().and_then(|m| m.object.as_ref())
2092+
{
2093+
cmd.add_object(obj);
2094+
}
20862095
}
20872096
}
20882097

@@ -2281,7 +2290,7 @@ fn linker_with_args(
22812290
codegen_results,
22822291
metadata,
22832292
);
2284-
add_local_crate_allocator_objects(cmd, codegen_results);
2293+
add_local_crate_allocator_objects(cmd, codegen_results, crate_type);
22852294

22862295
// Avoid linking to dynamic libraries unless they satisfy some undefined symbols
22872296
// at the point at which they are specified on the command line.

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use rustc_metadata::{
1111
};
1212
use rustc_middle::bug;
1313
use rustc_middle::middle::dependency_format::Linkage;
14-
use rustc_middle::middle::exported_symbols;
15-
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportKind};
14+
use rustc_middle::middle::exported_symbols::{
15+
self, ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
16+
};
1617
use rustc_middle::ty::TyCtxt;
1718
use rustc_session::Session;
1819
use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
@@ -22,6 +23,8 @@ use tracing::{debug, warn};
2223

2324
use super::command::Command;
2425
use super::symbol_export;
26+
use crate::back::symbol_export::allocator_shim_symbols;
27+
use crate::base::needs_allocator_shim_for_linking;
2528
use crate::errors;
2629

2730
#[cfg(test)]
@@ -1827,7 +1830,7 @@ fn exported_symbols_for_non_proc_macro(
18271830
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
18281831
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
18291832
// Do not export mangled symbols from cdylibs and don't attempt to export compiler-builtins
1830-
// from any cdylib. The latter doesn't work anyway as we use hidden visibility for
1833+
// from any dylib. The latter doesn't work anyway as we use hidden visibility for
18311834
// compiler-builtins. Most linkers silently ignore it, but ld64 gives a warning.
18321835
if info.level.is_below_threshold(export_threshold) && !tcx.is_compiler_builtins(cnum) {
18331836
symbols.push((
@@ -1838,6 +1841,14 @@ fn exported_symbols_for_non_proc_macro(
18381841
}
18391842
});
18401843

1844+
// Mark allocator shim symbols as exported only if they were generated.
1845+
if export_threshold == SymbolExportLevel::Rust
1846+
&& needs_allocator_shim_for_linking(tcx.dependency_formats(()), crate_type)
1847+
&& tcx.allocator_kind(()).is_some()
1848+
{
1849+
symbols.extend(allocator_shim_symbols(tcx));
1850+
}
1851+
18411852
symbols
18421853
}
18431854

compiler/rustc_codegen_ssa/src/back/lto.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use rustc_middle::ty::TyCtxt;
88
use rustc_session::config::{CrateType, Lto};
99
use tracing::info;
1010

11-
use crate::back::symbol_export::{self, symbol_name_for_instance_in_crate};
11+
use crate::back::symbol_export::{self, allocator_shim_symbols, symbol_name_for_instance_in_crate};
1212
use crate::back::write::CodegenContext;
13+
use crate::base::allocator_kind_for_codegen;
1314
use crate::errors::{DynamicLinkingWithLTO, LtoDisallowed, LtoDylib, LtoProcMacro};
1415
use crate::traits::*;
1516

@@ -115,6 +116,11 @@ pub(super) fn exported_symbols_for_lto(
115116
}
116117
}
117118

119+
// Mark allocator shim symbols as exported only if they were generated.
120+
if export_threshold == SymbolExportLevel::Rust && allocator_kind_for_codegen(tcx).is_some() {
121+
symbols_below_threshold.extend(allocator_shim_symbols(tcx).map(|(name, _kind)| name));
122+
}
123+
118124
symbols_below_threshold
119125
}
120126

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_symbol_mangling::mangle_internal_symbol;
1818
use rustc_target::spec::TlsModel;
1919
use tracing::debug;
2020

21-
use crate::base::allocator_kind_for_codegen;
21+
use crate::back::symbol_export;
2222

2323
fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
2424
crates_export_threshold(tcx.crate_types())
@@ -217,31 +217,6 @@ fn exported_non_generic_symbols_provider_local<'tcx>(
217217
));
218218
}
219219

220-
// Mark allocator shim symbols as exported only if they were generated.
221-
if allocator_kind_for_codegen(tcx).is_some() {
222-
for symbol_name in ALLOCATOR_METHODS
223-
.iter()
224-
.map(|method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()))
225-
.chain([
226-
mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
227-
mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
228-
mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
229-
])
230-
{
231-
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
232-
233-
symbols.push((
234-
exported_symbol,
235-
SymbolExportInfo {
236-
level: SymbolExportLevel::Rust,
237-
kind: SymbolExportKind::Text,
238-
used: false,
239-
rustc_std_internal_symbol: true,
240-
},
241-
));
242-
}
243-
}
244-
245220
// Sort so we get a stable incr. comp. hash.
246221
symbols.sort_by_cached_key(|s| s.0.symbol_name_for_local_instance(tcx));
247222

@@ -516,6 +491,31 @@ pub(crate) fn provide(providers: &mut Providers) {
516491
upstream_monomorphizations_for_provider;
517492
}
518493

494+
pub(crate) fn allocator_shim_symbols(
495+
tcx: TyCtxt<'_>,
496+
) -> impl Iterator<Item = (String, SymbolExportKind)> {
497+
ALLOCATOR_METHODS
498+
.iter()
499+
.map(move |method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()))
500+
.chain([
501+
mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
502+
mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
503+
mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
504+
])
505+
.map(move |symbol_name| {
506+
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
507+
508+
(
509+
symbol_export::exporting_symbol_name_for_instance_in_crate(
510+
tcx,
511+
exported_symbol,
512+
LOCAL_CRATE,
513+
),
514+
SymbolExportKind::Text,
515+
)
516+
})
517+
}
518+
519519
fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel {
520520
// We export anything that's not mangled at the "C" layer as it probably has
521521
// to do with ABI concerns. We do not, however, apply such treatment to

0 commit comments

Comments
 (0)