Skip to content

Rollup of 8 pull requests #142564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1e10dfc
Add all rustc_std_internal_symbol to symbols.o
bjorn3 May 8, 2025
2d2d70f
Remove dependency injection for the panic runtime
bjorn3 May 8, 2025
3a7ae67
Stop handling explicit dependencies on the panic runtime
bjorn3 May 8, 2025
f8d1bfa
Avoid exporting panic_unwind as stdlib cargo feature
bjorn3 May 8, 2025
6df5456
Make comment on activate_injected_dep a doc comment
bjorn3 May 9, 2025
c85760c
Fix Debug for Location.
m-ou-se Jun 11, 2025
5b50e0b
Add support for snapshot tests with insta
Kobzol Jun 12, 2025
efaf3eb
ignore `run-make` tests that need `std` on `no_std` targets
folkertdev Jun 12, 2025
40c2ca9
Move `shared_helpers` test to a dedicated module
Kobzol Jun 12, 2025
2591571
Stop using Config for `tempdir-as-a-service` in `build_stamp` tests
Kobzol Jun 12, 2025
8540188
Remove `RefCell` from `cc/cxx/ar/ranlib`
Kobzol Jun 12, 2025
dbe15e3
Remove environment variable modification in `test_default_compiler_wasi`
Kobzol Jun 12, 2025
a71b463
Move submodule path cache from `parse_gitmodules` to `Builder`
Kobzol Jun 12, 2025
983fe4f
Simplify `configure_with_args`
Kobzol Jun 12, 2025
6feb9b7
Add lightweight snapshot testing for bootstrap tests
Kobzol Jun 12, 2025
1ac89f1
Refactor `rustc_attr_data_structures` documentation
xizheyin Jun 5, 2025
a0db28f
clarify `rustc_do_not_const_check` comment
fee1-dead Jun 15, 2025
3871203
Stabilize "file_lock" feature
cberner May 29, 2025
5ac1cd9
Test Debug for Location.
m-ou-se Jun 11, 2025
ab25464
Rollup merge of #140809 - bjorn3:panic_runtime_cleanup, r=wesleywiser…
tgross35 Jun 16, 2025
a5db6b9
Rollup merge of #142082 - xizheyin:rustc_attr_data_structures, r=jdon…
tgross35 Jun 16, 2025
f89b2fa
Rollup merge of #142125 - cberner:file_lock_stable, r=ChrisDenton
tgross35 Jun 16, 2025
a5e9bfd
Rollup merge of #142373 - m-ou-se:debug-for-location, r=tgross35
tgross35 Jun 16, 2025
f6c4c33
Rollup merge of #142414 - folkertdev:ignore-nostd-tests, r=jieyouxu
tgross35 Jun 16, 2025
c62f7be
Rollup merge of #142416 - Kobzol:bootstrap-cleanup-2, r=jieyouxu
tgross35 Jun 16, 2025
75913ed
Rollup merge of #142431 - Kobzol:bootstrap-snapshot-tests, r=jieyouxu
tgross35 Jun 16, 2025
1b68bed
Rollup merge of #142528 - fee1-dead-contrib:push-rlxklunqkwmv, r=Ralf…
tgross35 Jun 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 44 additions & 14 deletions compiler/rustc_attr_data_structures/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,54 @@ impl Deprecation {
}
}

/// Represent parsed, *built in*, inert attributes.
/// Represents parsed *built-in* inert attributes.
///
/// That means attributes that are not actually ever expanded.
/// For more information on this, see the module docs on the [`rustc_attr_parsing`] crate.
/// They're instead used as markers, to guide the compilation process in various way in most every stage of the compiler.
/// These are kept around after the AST, into the HIR and further on.
/// ## Overview
/// These attributes are markers that guide the compilation process and are never expanded into other code.
/// They persist throughout the compilation phases, from AST to HIR and beyond.
///
/// The word "parsed" could be a little misleading here, because the parser already parses
/// attributes early on. However, the result, an [`ast::Attribute`]
/// is only parsed at a high level, still containing a token stream in many cases. That is
/// because the structure of the contents varies from attribute to attribute.
/// With a parsed attribute I mean that each attribute is processed individually into a
/// final structure, which on-site (the place where the attribute is useful for, think the
/// the place where `must_use` is checked) little to no extra parsing or validating needs to
/// happen.
/// ## Attribute Processing
/// While attributes are initially parsed by [`rustc_parse`] into [`ast::Attribute`], they still contain raw token streams
/// because different attributes have different internal structures. This enum represents the final,
/// fully parsed form of these attributes, where each variant contains contains all the information and
/// structure relevant for the specific attribute.
///
/// For more docs, look in [`rustc_attr_parsing`].
/// Some attributes can be applied multiple times to the same item, and they are "collapsed" into a single
/// semantic attribute. For example:
/// ```rust
/// #[repr(C)]
/// #[repr(packed)]
/// struct S { }
/// ```
/// This is equivalent to `#[repr(C, packed)]` and results in a single [`AttributeKind::Repr`] containing
/// both `C` and `packed` annotations. This collapsing happens during parsing and is reflected in the
/// data structures defined in this enum.
///
/// ## Usage
/// These parsed attributes are used throughout the compiler to:
/// - Control code generation (e.g., `#[repr]`)
/// - Mark API stability (`#[stable]`, `#[unstable]`)
/// - Provide documentation (`#[doc]`)
/// - Guide compiler behavior (e.g., `#[allow_internal_unstable]`)
///
/// ## Note on Attribute Organization
/// Some attributes like `InlineAttr`, `OptimizeAttr`, and `InstructionSetAttr` are defined separately
/// from this enum because they are used in specific compiler phases (like code generation) and don't
/// need to persist throughout the entire compilation process. They are typically processed and
/// converted into their final form earlier in the compilation pipeline.
///
/// For example:
/// - `InlineAttr` is used during code generation to control function inlining
/// - `OptimizeAttr` is used to control optimization levels
/// - `InstructionSetAttr` is used for target-specific code generation
///
/// These attributes are handled by their respective compiler passes in the [`rustc_codegen_ssa`] crate
/// and don't need to be preserved in the same way as the attributes in this enum.
///
/// For more details on attribute parsing, see the [`rustc_attr_parsing`] crate.
///
/// [`rustc_parse`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/index.html
/// [`rustc_codegen_ssa`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/index.html
/// [`rustc_attr_parsing`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
pub enum AttributeKind {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_attr_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! Data structures for representing parsed attributes in the Rust compiler.
//! For detailed documentation about attribute processing,
//! see [rustc_attr_parsing](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html).

// tidy-alphabetical-start
#![allow(internal_features)]
#![doc(rust_logo)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,7 @@ pub(crate) fn linked_symbols(
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
if info.level.is_below_threshold(export_threshold) && !tcx.is_compiler_builtins(cnum)
|| info.used
|| info.rustc_std_internal_symbol
{
symbols.push((
symbol_export::linking_symbol_name_for_instance_in_crate(tcx, symbol, cnum),
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
|| used,
rustc_std_internal_symbol: codegen_attrs
.flags
.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL),
};
(def_id.to_def_id(), info)
})
Expand All @@ -143,6 +146,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
level: SymbolExportLevel::C,
kind: SymbolExportKind::Data,
used: false,
rustc_std_internal_symbol: false,
},
);
}
Expand Down Expand Up @@ -191,6 +195,7 @@ fn exported_symbols_provider_local<'tcx>(
level: info.level,
kind: SymbolExportKind::Text,
used: info.used,
rustc_std_internal_symbol: info.rustc_std_internal_symbol,
},
)
})
Expand All @@ -207,6 +212,7 @@ fn exported_symbols_provider_local<'tcx>(
level: SymbolExportLevel::C,
kind: SymbolExportKind::Text,
used: false,
rustc_std_internal_symbol: false,
},
));
}
Expand All @@ -229,6 +235,7 @@ fn exported_symbols_provider_local<'tcx>(
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
used: false,
rustc_std_internal_symbol: true,
},
));
}
Expand All @@ -243,6 +250,7 @@ fn exported_symbols_provider_local<'tcx>(
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Data,
used: false,
rustc_std_internal_symbol: true,
},
))
}
Expand All @@ -262,6 +270,7 @@ fn exported_symbols_provider_local<'tcx>(
level: SymbolExportLevel::C,
kind: SymbolExportKind::Data,
used: false,
rustc_std_internal_symbol: false,
},
)
}));
Expand All @@ -287,6 +296,7 @@ fn exported_symbols_provider_local<'tcx>(
level: SymbolExportLevel::C,
kind: SymbolExportKind::Data,
used: false,
rustc_std_internal_symbol: false,
},
)
}));
Expand All @@ -304,6 +314,7 @@ fn exported_symbols_provider_local<'tcx>(
level: SymbolExportLevel::C,
kind: SymbolExportKind::Data,
used: true,
rustc_std_internal_symbol: false,
},
));
}
Expand Down Expand Up @@ -379,6 +390,8 @@ fn exported_symbols_provider_local<'tcx>(
}
}

// Note: These all set rustc_std_internal_symbol to false as generic functions must not
// be marked with this attribute and we are only handling generic functions here.
match *mono_item {
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
let has_generics = args.non_erasable_generics().next().is_some();
Expand All @@ -394,6 +407,7 @@ fn exported_symbols_provider_local<'tcx>(
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
used: false,
rustc_std_internal_symbol: false,
},
));
}
Expand All @@ -416,6 +430,7 @@ fn exported_symbols_provider_local<'tcx>(
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
used: false,
rustc_std_internal_symbol: false,
},
));
}
Expand All @@ -432,6 +447,7 @@ fn exported_symbols_provider_local<'tcx>(
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
used: false,
rustc_std_internal_symbol: false,
},
));
}
Expand All @@ -442,6 +458,7 @@ fn exported_symbols_provider_local<'tcx>(
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
used: false,
rustc_std_internal_symbol: false,
},
));
}
Expand Down
22 changes: 1 addition & 21 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::time::{Duration, Instant};
use itertools::Itertools;
use rustc_abi::FIRST_VARIANT;
use rustc_ast as ast;
use rustc_ast::expand::allocator::{ALLOCATOR_METHODS, AllocatorKind, global_fn_name};
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_attr_data_structures::OptimizeAttr;
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
Expand Down Expand Up @@ -1039,26 +1039,6 @@ impl CrateInfo {
.collect::<Vec<_>>();
symbols.sort_unstable_by(|a, b| a.0.cmp(&b.0));
linked_symbols.extend(symbols);
if tcx.allocator_kind(()).is_some() {
// At least one crate needs a global allocator. This crate may be placed
// after the crate that defines it in the linker order, in which case some
// linkers return an error. By adding the global allocator shim methods to
// the linked_symbols list, linking the generated symbols.o will ensure that
// circular dependencies involving the global allocator don't lead to linker
// errors.
linked_symbols.extend(ALLOCATOR_METHODS.iter().map(|method| {
(
format!(
"{prefix}{}",
mangle_internal_symbol(
tcx,
global_fn_name(method.name).as_str()
)
),
SymbolExportKind::Text,
)
}));
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
rustc_legacy_const_generics, Normal, template!(List: "N"), ErrorFollowing,
EncodeCrossCrate::Yes,
),
// Do not const-check this function's body. It will always get replaced during CTFE.
// Do not const-check this function's body. It will always get replaced during CTFE via `hook_special_const_fn`.
rustc_attr!(
rustc_do_not_const_check, Normal, template!(Word), WarnFollowing,
EncodeCrossCrate::Yes, "`#[rustc_do_not_const_check]` skips const-check for this function's body",
Expand Down
92 changes: 9 additions & 83 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Validates all used crates and extern libraries and loads their metadata

use std::error::Error;
use std::ops::Fn;
use std::path::Path;
use std::str::FromStr;
use std::time::Duration;
Expand Down Expand Up @@ -276,12 +275,6 @@ impl CStore {
.filter_map(|(cnum, data)| data.as_deref().map(|data| (cnum, data)))
}

fn iter_crate_data_mut(&mut self) -> impl Iterator<Item = (CrateNum, &mut CrateMetadata)> {
self.metas
.iter_enumerated_mut()
.filter_map(|(cnum, data)| data.as_deref_mut().map(|data| (cnum, data)))
}

fn push_dependencies_in_postorder(&self, deps: &mut IndexSet<CrateNum>, cnum: CrateNum) {
if !deps.contains(&cnum) {
let data = self.get_crate_data(cnum);
Expand All @@ -307,13 +300,6 @@ impl CStore {
deps
}

fn crate_dependencies_in_reverse_postorder(
&self,
cnum: CrateNum,
) -> impl Iterator<Item = CrateNum> {
self.crate_dependencies_in_postorder(cnum).into_iter().rev()
}

pub(crate) fn injected_panic_runtime(&self) -> Option<CrateNum> {
self.injected_panic_runtime
}
Expand Down Expand Up @@ -966,47 +952,27 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
// If we need a panic runtime, we try to find an existing one here. At
// the same time we perform some general validation of the DAG we've got
// going such as ensuring everything has a compatible panic strategy.
//
// The logic for finding the panic runtime here is pretty much the same
// as the allocator case with the only addition that the panic strategy
// compilation mode also comes into play.
let desired_strategy = self.sess.panic_strategy();
let mut runtime_found = false;
let mut needs_panic_runtime = attr::contains_name(&krate.attrs, sym::needs_panic_runtime);

let mut panic_runtimes = Vec::new();
for (cnum, data) in self.cstore.iter_crate_data() {
needs_panic_runtime = needs_panic_runtime || data.needs_panic_runtime();
if data.is_panic_runtime() {
// Inject a dependency from all #![needs_panic_runtime] to this
// #![panic_runtime] crate.
panic_runtimes.push(cnum);
runtime_found = runtime_found || data.dep_kind() == CrateDepKind::Explicit;
}
}
for cnum in panic_runtimes {
self.inject_dependency_if(cnum, "a panic runtime", &|data| data.needs_panic_runtime());
for (_cnum, data) in self.cstore.iter_crate_data() {
needs_panic_runtime |= data.needs_panic_runtime();
}

// If an explicitly linked and matching panic runtime was found, or if
// we just don't need one at all, then we're done here and there's
// nothing else to do.
if !needs_panic_runtime || runtime_found {
// If we just don't need a panic runtime at all, then we're done here
// and there's nothing else to do.
if !needs_panic_runtime {
return;
}

// By this point we know that we (a) need a panic runtime and (b) no
// panic runtime was explicitly linked. Here we just load an appropriate
// default runtime for our panic strategy and then inject the
// dependencies.
// By this point we know that we need a panic runtime. Here we just load
// an appropriate default runtime for our panic strategy.
//
// We may resolve to an already loaded crate (as the crate may not have
// been explicitly linked prior to this) and we may re-inject
// dependencies again, but both of those situations are fine.
// been explicitly linked prior to this), but this is fine.
//
// Also note that we have yet to perform validation of the crate graph
// in terms of everyone has a compatible panic runtime format, that's
// performed later as part of the `dependency_format` module.
let desired_strategy = self.sess.panic_strategy();
let name = match desired_strategy {
PanicStrategy::Unwind => sym::panic_unwind,
PanicStrategy::Abort => sym::panic_abort,
Expand All @@ -1031,7 +997,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
}

self.cstore.injected_panic_runtime = Some(cnum);
self.inject_dependency_if(cnum, "a panic runtime", &|data| data.needs_panic_runtime());
}

fn inject_profiler_runtime(&mut self) {
Expand Down Expand Up @@ -1212,45 +1177,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
}
}

fn inject_dependency_if(
&mut self,
krate: CrateNum,
what: &str,
needs_dep: &dyn Fn(&CrateMetadata) -> bool,
) {
// Don't perform this validation if the session has errors, as one of
// those errors may indicate a circular dependency which could cause
// this to stack overflow.
if self.dcx().has_errors().is_some() {
return;
}

// Before we inject any dependencies, make sure we don't inject a
// circular dependency by validating that this crate doesn't
// transitively depend on any crates satisfying `needs_dep`.
for dep in self.cstore.crate_dependencies_in_reverse_postorder(krate) {
let data = self.cstore.get_crate_data(dep);
if needs_dep(&data) {
self.dcx().emit_err(errors::NoTransitiveNeedsDep {
crate_name: self.cstore.get_crate_data(krate).name(),
needs_crate_name: what,
deps_crate_name: data.name(),
});
}
}

// All crates satisfying `needs_dep` do not explicitly depend on the
// crate provided for this compile, but in order for this compilation to
// be successfully linked we need to inject a dependency (to order the
// crates on the command line correctly).
for (cnum, data) in self.cstore.iter_crate_data_mut() {
if needs_dep(data) {
info!("injecting a dep from {} to {}", cnum, krate);
data.add_dependency(krate);
}
}
}

fn report_unused_deps(&mut self, krate: &ast::Crate) {
// Make a point span rather than covering the whole file
let span = krate.spans.inner_span.shrink_to_lo();
Expand Down
Loading
Loading