Skip to content

Commit ffba430

Browse files
committed
Auto merge of #90282 - matthiaskrgr:rollup-c6trbff, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #89581 (Add -Z no-unique-section-names to reduce ELF header bloat.) - #90196 (Fix and extent ControlFlow `traverse_inorder` example) - #90255 (:arrow_up: rust-analyzer) - #90266 (Prevent duplicate caller bounds candidates by exposing default substs in Unevaluated) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 29b1248 + 26e9a71 commit ffba430

File tree

11 files changed

+84
-5
lines changed

11 files changed

+84
-5
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub fn target_machine_factory(
161161
let ffunction_sections =
162162
sess.opts.debugging_opts.function_sections.unwrap_or(sess.target.function_sections);
163163
let fdata_sections = ffunction_sections;
164+
let funique_section_names = !sess.opts.debugging_opts.no_unique_section_names;
164165

165166
let code_model = to_llvm_code_model(sess.code_model());
166167

@@ -205,6 +206,7 @@ pub fn target_machine_factory(
205206
use_softfp,
206207
ffunction_sections,
207208
fdata_sections,
209+
funique_section_names,
208210
trap_unreachable,
209211
singlethread,
210212
asm_comments,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2187,6 +2187,7 @@ extern "C" {
21872187
UseSoftFP: bool,
21882188
FunctionSections: bool,
21892189
DataSections: bool,
2190+
UniqueSectionNames: bool,
21902191
TrapUnreachable: bool,
21912192
Singlethread: bool,
21922193
AsmComments: bool,

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ fn test_debugging_options_tracking_hash() {
744744
tracked!(new_llvm_pass_manager, Some(true));
745745
tracked!(no_generate_arange_section, true);
746746
tracked!(no_link, true);
747+
tracked!(no_unique_section_names, true);
747748
tracked!(no_profiler_runtime, true);
748749
tracked!(osx_rpath_install_name, true);
749750
tracked!(panic_abort_tests, true);

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
462462
LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
463463
bool FunctionSections,
464464
bool DataSections,
465+
bool UniqueSectionNames,
465466
bool TrapUnreachable,
466467
bool Singlethread,
467468
bool AsmComments,
@@ -491,6 +492,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
491492
}
492493
Options.DataSections = DataSections;
493494
Options.FunctionSections = FunctionSections;
495+
Options.UniqueSectionNames = UniqueSectionNames;
494496
Options.MCOptions.AsmVerbose = AsmComments;
495497
Options.MCOptions.PreserveAsmComments = AsmComments;
496498
Options.MCOptions.ABIName = ABIStr;

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,8 @@ options! {
12141214
"compile without linking"),
12151215
no_parallel_llvm: bool = (false, parse_no_flag, [UNTRACKED],
12161216
"run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
1217+
no_unique_section_names: bool = (false, parse_bool, [TRACKED],
1218+
"do not use unique names for text and data sections when -Z function-sections is used"),
12171219
no_profiler_runtime: bool = (false, parse_no_flag, [TRACKED],
12181220
"prevent automatic injection of the profiler_builtins crate"),
12191221
normalize_docs: bool = (false, parse_bool, [TRACKED],

compiler/rustc_ty_utils/src/ty.rs

+12
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
247247
}
248248

249249
/// See `ParamEnv` struct definition for details.
250+
#[instrument(level = "debug", skip(tcx))]
250251
fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
251252
// The param_env of an impl Trait type is its defining function's param_env
252253
if let Some(parent) = ty::is_impl_trait_defn(tcx, def_id) {
@@ -274,9 +275,20 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
274275
predicates.extend(environment);
275276
}
276277

278+
// It's important that we include the default substs in unevaluated
279+
// constants, since `Unevaluated` instances in predicates whose substs are None
280+
// can lead to "duplicate" caller bounds candidates during trait selection,
281+
// duplicate in the sense that both have their default substs, but the
282+
// candidate that resulted from a superpredicate still uses `None` in its
283+
// `substs_` field of `Unevaluated` to indicate that it has its default substs,
284+
// whereas the other candidate has `substs_: Some(default_substs)`, see
285+
// issue #89334
286+
predicates = tcx.expose_default_const_substs(predicates);
287+
277288
let unnormalized_env =
278289
ty::ParamEnv::new(tcx.intern_predicates(&predicates), traits::Reveal::UserFacing);
279290

291+
debug!("unnormalized_env caller bounds: {:?}", unnormalized_env.caller_bounds());
280292
let body_id = def_id
281293
.as_local()
282294
.map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))

library/core/src/ops/control_flow.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{convert, ops};
2424
/// ```
2525
///
2626
/// A basic tree traversal:
27-
/// ```no_run
27+
/// ```
2828
/// use std::ops::ControlFlow;
2929
///
3030
/// pub struct TreeNode<T> {
@@ -34,17 +34,42 @@ use crate::{convert, ops};
3434
/// }
3535
///
3636
/// impl<T> TreeNode<T> {
37-
/// pub fn traverse_inorder<B>(&self, mut f: impl FnMut(&T) -> ControlFlow<B>) -> ControlFlow<B> {
37+
/// pub fn traverse_inorder<B>(&self, f: &mut impl FnMut(&T) -> ControlFlow<B>) -> ControlFlow<B> {
3838
/// if let Some(left) = &self.left {
39-
/// left.traverse_inorder(&mut f)?;
39+
/// left.traverse_inorder(f)?;
4040
/// }
4141
/// f(&self.value)?;
4242
/// if let Some(right) = &self.right {
43-
/// right.traverse_inorder(&mut f)?;
43+
/// right.traverse_inorder(f)?;
4444
/// }
4545
/// ControlFlow::Continue(())
4646
/// }
47+
/// fn leaf(value: T) -> Option<Box<TreeNode<T>>> {
48+
/// Some(Box::new(Self { value, left: None, right: None }))
49+
/// }
4750
/// }
51+
///
52+
/// let node = TreeNode {
53+
/// value: 0,
54+
/// left: TreeNode::leaf(1),
55+
/// right: Some(Box::new(TreeNode {
56+
/// value: -1,
57+
/// left: TreeNode::leaf(5),
58+
/// right: TreeNode::leaf(2),
59+
/// }))
60+
/// };
61+
/// let mut sum = 0;
62+
///
63+
/// let res = node.traverse_inorder(&mut |val| {
64+
/// if *val < 0 {
65+
/// ControlFlow::Break(*val)
66+
/// } else {
67+
/// sum += *val;
68+
/// ControlFlow::Continue(())
69+
/// }
70+
/// });
71+
/// assert_eq!(res, ControlFlow::Break(-1));
72+
/// assert_eq!(sum, 6);
4873
/// ```
4974
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
5075
#[derive(Debug, Clone, Copy, PartialEq)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# `no-unique-section-names`
2+
3+
------------------------
4+
5+
This flag currently applies only to ELF-based targets using the LLVM codegen backend. It prevents the generation of unique ELF section names for each separate code and data item when `-Z function-sections` is also in use, which is the default for most targets. This option can reduce the size of object files, and depending on the linker, the final ELF binary as well.
6+
7+
For example, a function `func` will by default generate a code section called `.text.func`. Normally this is fine because the linker will merge all those `.text.*` sections into a single one in the binary. However, starting with [LLVM 12](https://github.com/llvm/llvm-project/commit/ee5d1a04), the backend will also generate unique section names for exception handling, so you would see a section name of `.gcc_except_table.func` in the object file and potentially in the final ELF binary, which could add significant bloat to programs that contain many functions.
8+
9+
This flag instructs LLVM to use the same `.text` and `.gcc_except_table` section name for each function, and it is analogous to Clang's `-fno-unique-section-names` option.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// build-pass
2+
3+
#![feature(generic_const_exprs)]
4+
#![allow(unused_braces, incomplete_features)]
5+
6+
pub trait Foo<const N: usize> {}
7+
pub trait Bar: Foo<{ 1 }> { }
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// build-pass
2+
3+
#![feature(generic_const_exprs)]
4+
#![allow(unused_braces, incomplete_features)]
5+
6+
pub trait AnotherTrait{
7+
const ARRAY_SIZE: usize;
8+
}
9+
pub trait Shard<T: AnotherTrait>:
10+
AsMut<[[u8; T::ARRAY_SIZE]]>
11+
where
12+
[(); T::ARRAY_SIZE]: Sized
13+
{
14+
}
15+
16+
fn main() {}

src/tools/rust-analyzer

0 commit comments

Comments
 (0)