From 3c7c38ad9335b043315addc1fcabf3631bbe1125 Mon Sep 17 00:00:00 2001 From: real-eren Date: Sun, 2 Feb 2025 17:59:43 -0500 Subject: [PATCH 01/12] Simplify SSE2 implementation --- .../rustc_span/src/analyze_source_file.rs | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_span/src/analyze_source_file.rs b/compiler/rustc_span/src/analyze_source_file.rs index fba205665803c..87c8e3fce072d 100644 --- a/compiler/rustc_span/src/analyze_source_file.rs +++ b/compiler/rustc_span/src/analyze_source_file.rs @@ -110,25 +110,19 @@ cfg_match! { if control_char_mask != 0 { // Check for newlines in the chunk let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) }; - let newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) }; + let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) }; if control_char_mask == newlines_mask { // All control characters are newlines, record them - let mut newlines_mask = 0xFFFF0000 | newlines_mask as u32; let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1); - loop { + while newlines_mask != 0 { let index = newlines_mask.trailing_zeros(); - if index >= CHUNK_SIZE as u32 { - // We have arrived at the end of the chunk. - break; - } - lines.push(RelativeBytePos(index) + output_offset); // Clear the bit, so we can find the next one. - newlines_mask &= (!1) << index; + newlines_mask &= newlines_mask - 1; } // We are done for this chunk. All control characters were @@ -268,25 +262,19 @@ cfg_match! { if control_char_mask != 0 { // Check for newlines in the chunk let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) }; - let newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) }; + let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) }; if control_char_mask == newlines_mask { // All control characters are newlines, record them - let mut newlines_mask = 0xFFFF0000 | newlines_mask as u32; let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1); - loop { + while newlines_mask != 0 { let index = newlines_mask.trailing_zeros(); - if index >= CHUNK_SIZE as u32 { - // We have arrived at the end of the chunk. - break; - } - lines.push(RelativeBytePos(index) + output_offset); // Clear the bit, so we can find the next one. - newlines_mask &= (!1) << index; + newlines_mask &= newlines_mask - 1; } // We are done for this chunk. All control characters were From d6ca7ad0d7a7e8acd14f6da3bad4e7b5a25c3d17 Mon Sep 17 00:00:00 2001 From: real-eren Date: Sun, 2 Feb 2025 19:39:07 -0500 Subject: [PATCH 02/12] Remove dead control char logic Only newlines and multibyte characters are actually relevant --- .../rustc_span/src/analyze_source_file.rs | 175 ++++++------------ 1 file changed, 55 insertions(+), 120 deletions(-) diff --git a/compiler/rustc_span/src/analyze_source_file.rs b/compiler/rustc_span/src/analyze_source_file.rs index 87c8e3fce072d..47cc16b623d10 100644 --- a/compiler/rustc_span/src/analyze_source_file.rs +++ b/compiler/rustc_span/src/analyze_source_file.rs @@ -95,59 +95,32 @@ cfg_match! { if multibyte_mask == 0 { assert!(intra_chunk_offset == 0); - // Check if there are any control characters in the chunk. All - // control characters that we can encounter at this point have a - // byte value less than 32 or ... - let control_char_test0 = unsafe { _mm_cmplt_epi8(chunk, _mm_set1_epi8(32)) }; - let control_char_mask0 = unsafe { _mm_movemask_epi8(control_char_test0) }; - - // ... it's the ASCII 'DEL' character with a value of 127. - let control_char_test1 = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(127)) }; - let control_char_mask1 = unsafe { _mm_movemask_epi8(control_char_test1) }; - - let control_char_mask = control_char_mask0 | control_char_mask1; - - if control_char_mask != 0 { - // Check for newlines in the chunk - let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) }; - let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) }; - - if control_char_mask == newlines_mask { - // All control characters are newlines, record them - let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1); - - while newlines_mask != 0 { - let index = newlines_mask.trailing_zeros(); - - lines.push(RelativeBytePos(index) + output_offset); - - // Clear the bit, so we can find the next one. - newlines_mask &= newlines_mask - 1; - } - - // We are done for this chunk. All control characters were - // newlines and we took care of those. - continue; - } else { - // Some of the control characters are not newlines, - // fall through to the slow path below. - } - } else { - // No control characters, nothing to record for this chunk - continue; + // Check for newlines in the chunk + let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) }; + let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) }; + + let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1); + + while newlines_mask != 0 { + let index = newlines_mask.trailing_zeros(); + + lines.push(RelativeBytePos(index) + output_offset); + + // Clear the bit, so we can find the next one. + newlines_mask &= newlines_mask - 1; } + } else { + // The slow path. + // There are multibyte chars in here, fallback to generic decoding. + let scan_start = chunk_index * CHUNK_SIZE + intra_chunk_offset; + intra_chunk_offset = analyze_source_file_generic( + &src[scan_start..], + CHUNK_SIZE - intra_chunk_offset, + RelativeBytePos::from_usize(scan_start), + lines, + multi_byte_chars, + ); } - - // The slow path. - // There are control chars in here, fallback to generic decoding. - let scan_start = chunk_index * CHUNK_SIZE + intra_chunk_offset; - intra_chunk_offset = analyze_source_file_generic( - &src[scan_start..], - CHUNK_SIZE - intra_chunk_offset, - RelativeBytePos::from_usize(scan_start), - lines, - multi_byte_chars, - ); } // There might still be a tail left to analyze @@ -247,59 +220,32 @@ cfg_match! { if multibyte_mask == 0 { assert!(intra_chunk_offset == 0); - // Check if there are any control characters in the chunk. All - // control characters that we can encounter at this point have a - // byte value less than 32 or ... - let control_char_test0 = unsafe { _mm_cmplt_epi8(chunk, _mm_set1_epi8(32)) }; - let control_char_mask0 = unsafe { _mm_movemask_epi8(control_char_test0) }; - - // ... it's the ASCII 'DEL' character with a value of 127. - let control_char_test1 = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(127)) }; - let control_char_mask1 = unsafe { _mm_movemask_epi8(control_char_test1) }; - - let control_char_mask = control_char_mask0 | control_char_mask1; - - if control_char_mask != 0 { - // Check for newlines in the chunk - let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) }; - let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) }; - - if control_char_mask == newlines_mask { - // All control characters are newlines, record them - let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1); - - while newlines_mask != 0 { - let index = newlines_mask.trailing_zeros(); - - lines.push(RelativeBytePos(index) + output_offset); - - // Clear the bit, so we can find the next one. - newlines_mask &= newlines_mask - 1; - } - - // We are done for this chunk. All control characters were - // newlines and we took care of those. - continue; - } else { - // Some of the control characters are not newlines, - // fall through to the slow path below. - } - } else { - // No control characters, nothing to record for this chunk - continue; + // Check for newlines in the chunk + let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) }; + let mut newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) }; + + let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1); + + while newlines_mask != 0 { + let index = newlines_mask.trailing_zeros(); + + lines.push(RelativeBytePos(index) + output_offset); + + // Clear the bit, so we can find the next one. + newlines_mask &= newlines_mask - 1; } + } else { + // The slow path. + // There are multibyte chars in here, fallback to generic decoding. + let scan_start = chunk_index * CHUNK_SIZE + intra_chunk_offset; + intra_chunk_offset = analyze_source_file_generic( + &src[scan_start..], + CHUNK_SIZE - intra_chunk_offset, + RelativeBytePos::from_usize(scan_start), + lines, + multi_byte_chars, + ); } - - // The slow path. - // There are control chars in here, fallback to generic decoding. - let scan_start = chunk_index * CHUNK_SIZE + intra_chunk_offset; - intra_chunk_offset = analyze_source_file_generic( - &src[scan_start..], - CHUNK_SIZE - intra_chunk_offset, - RelativeBytePos::from_usize(scan_start), - lines, - multi_byte_chars, - ); } // There might still be a tail left to analyze @@ -357,29 +303,18 @@ fn analyze_source_file_generic( // string. let mut char_len = 1; - if byte < 32 { - // This is an ASCII control character, it could be one of the cases - // that are interesting to us. - + if byte == b'\n' { let pos = RelativeBytePos::from_usize(i) + output_offset; - - if let b'\n' = byte { - lines.push(pos + RelativeBytePos(1)); - } - } else if byte >= 127 { - // The slow path: - // This is either ASCII control character "DEL" or the beginning of - // a multibyte char. Just decode to `char`. + lines.push(pos + RelativeBytePos(1)); + } else if byte >= 128 { + // This is the beginning of a multibyte char. Just decode to `char`. let c = src[i..].chars().next().unwrap(); char_len = c.len_utf8(); let pos = RelativeBytePos::from_usize(i) + output_offset; - - if char_len > 1 { - assert!((2..=4).contains(&char_len)); - let mbc = MultiByteChar { pos, bytes: char_len as u8 }; - multi_byte_chars.push(mbc); - } + assert!((2..=4).contains(&char_len)); + let mbc = MultiByteChar { pos, bytes: char_len as u8 }; + multi_byte_chars.push(mbc); } i += char_len; From 4b086d47118668bff5f04b511e673fa3c84369d3 Mon Sep 17 00:00:00 2001 From: Henry Jiang Date: Wed, 12 Feb 2025 00:54:00 -0500 Subject: [PATCH 03/12] expect EINVAL for pthread_mutex_destroy for aix --- library/std/src/sys/pal/unix/sync/mutex.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/pal/unix/sync/mutex.rs b/library/std/src/sys/pal/unix/sync/mutex.rs index 8ff6c3d3d15da..557e70af94ba7 100644 --- a/library/std/src/sys/pal/unix/sync/mutex.rs +++ b/library/std/src/sys/pal/unix/sync/mutex.rs @@ -111,9 +111,9 @@ impl Drop for Mutex { // `PTHREAD_MUTEX_INITIALIZER`, which is valid at all locations. Thus, // this call always destroys a valid mutex. let r = unsafe { libc::pthread_mutex_destroy(self.raw()) }; - if cfg!(target_os = "dragonfly") { - // On DragonFly pthread_mutex_destroy() returns EINVAL if called on a - // mutex that was just initialized with libc::PTHREAD_MUTEX_INITIALIZER. + if cfg!(any(target_os = "aix", target_os = "dragonfly")) { + // On AIX and DragonFly pthread_mutex_destroy() returns EINVAL if called + // on a mutex that was just initialized with libc::PTHREAD_MUTEX_INITIALIZER. // Once it is used (locked/unlocked) or pthread_mutex_init() is called, // this behaviour no longer occurs. debug_assert!(r == 0 || r == libc::EINVAL); From 88193aad724279c938efd2d17332e08a751de106 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 12 Feb 2025 23:52:53 +0000 Subject: [PATCH 04/12] Use the right binder for rebinding PolyTraitRef --- .../rustc_trait_selection/src/traits/util.rs | 4 ++-- .../traits/alias/expand-higher-ranked-alias.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/ui/traits/alias/expand-higher-ranked-alias.rs diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index d30363ec1589a..15f5cf916a48b 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -47,11 +47,11 @@ pub fn expand_trait_aliases<'tcx>( queue.extend( tcx.explicit_super_predicates_of(trait_pred.def_id()) .iter_identity_copied() - .map(|(clause, span)| { + .map(|(super_clause, span)| { let mut spans = spans.clone(); spans.push(span); ( - clause.instantiate_supertrait( + super_clause.instantiate_supertrait( tcx, clause.kind().rebind(trait_pred.trait_ref), ), diff --git a/tests/ui/traits/alias/expand-higher-ranked-alias.rs b/tests/ui/traits/alias/expand-higher-ranked-alias.rs new file mode 100644 index 0000000000000..8a301d39f4c46 --- /dev/null +++ b/tests/ui/traits/alias/expand-higher-ranked-alias.rs @@ -0,0 +1,18 @@ +// Make sure we are using the right binder vars when expanding +// `for<'a> Foo<'a>` to `for<'a> Bar<'a>`. + +//@ check-pass + +#![feature(trait_alias)] + +trait Bar<'a> {} + +trait Foo<'a> = Bar<'a>; + +fn test2(_: &(impl for<'a> Foo<'a> + ?Sized)) {} + +fn test(x: &dyn for<'a> Foo<'a>) { + test2(x); +} + +fn main() {} From 9c03369c17c6eed8b6471cb7e176f7da99f6cdfb Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Tue, 11 Feb 2025 21:58:54 -0700 Subject: [PATCH 05/12] add `IntoBounds` trait for `range_into_bounds` feature, #136903 --- library/core/src/ops/mod.rs | 2 + library/core/src/ops/range.rs | 82 +++++++++++++++++++++++++++++++++++ library/core/src/range.rs | 28 +++++++++++- 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs index 7b2ced2cc4bdc..627a875d9f724 100644 --- a/library/core/src/ops/mod.rs +++ b/library/core/src/ops/mod.rs @@ -182,6 +182,8 @@ pub use self::function::{Fn, FnMut, FnOnce}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::index::{Index, IndexMut}; pub(crate) use self::index_range::IndexRange; +#[unstable(feature = "range_into_bounds", issue = "136903")] +pub use self::range::IntoBounds; #[stable(feature = "inclusive_range", since = "1.26.0")] pub use self::range::{Bound, RangeBounds, RangeInclusive, RangeToInclusive}; #[unstable(feature = "one_sided_range", issue = "69780")] diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index 42e07a0e51da4..5580faefacc0d 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -831,6 +831,30 @@ pub trait RangeBounds { } } +/// Used to convert a range into start and end bounds, consuming the +/// range by value. +/// +/// `IntoBounds` is implemented by Rust’s built-in range types, produced +/// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`. +#[unstable(feature = "range_into_bounds", issue = "136903")] +pub trait IntoBounds: RangeBounds { + /// Convert this range into the start and end bounds. + /// Returns `(start_bound, end_bound)`. + /// + /// # Examples + /// + /// ``` + /// #![feature(range_into_bounds)] + /// + /// use std::ops::Bound::*; + /// use std::ops::IntoBounds; + /// + /// assert_eq!((0..5).into_bounds(), (Included(0), Excluded(5))); + /// assert_eq!((..=7).into_bounds(), (Unbounded, Included(7))); + /// ``` + fn into_bounds(self) -> (Bound, Bound); +} + use self::Bound::{Excluded, Included, Unbounded}; #[stable(feature = "collections_range", since = "1.28.0")] @@ -843,6 +867,13 @@ impl RangeBounds for RangeFull { } } +#[unstable(feature = "range_into_bounds", issue = "136903")] +impl IntoBounds for RangeFull { + fn into_bounds(self) -> (Bound, Bound) { + (Unbounded, Unbounded) + } +} + #[stable(feature = "collections_range", since = "1.28.0")] impl RangeBounds for RangeFrom { fn start_bound(&self) -> Bound<&T> { @@ -853,6 +884,13 @@ impl RangeBounds for RangeFrom { } } +#[unstable(feature = "range_into_bounds", issue = "136903")] +impl IntoBounds for RangeFrom { + fn into_bounds(self) -> (Bound, Bound) { + (Included(self.start), Unbounded) + } +} + #[stable(feature = "collections_range", since = "1.28.0")] impl RangeBounds for RangeTo { fn start_bound(&self) -> Bound<&T> { @@ -863,6 +901,13 @@ impl RangeBounds for RangeTo { } } +#[unstable(feature = "range_into_bounds", issue = "136903")] +impl IntoBounds for RangeTo { + fn into_bounds(self) -> (Bound, Bound) { + (Unbounded, Excluded(self.end)) + } +} + #[stable(feature = "collections_range", since = "1.28.0")] impl RangeBounds for Range { fn start_bound(&self) -> Bound<&T> { @@ -873,6 +918,13 @@ impl RangeBounds for Range { } } +#[unstable(feature = "range_into_bounds", issue = "136903")] +impl IntoBounds for Range { + fn into_bounds(self) -> (Bound, Bound) { + (Included(self.start), Excluded(self.end)) + } +} + #[stable(feature = "collections_range", since = "1.28.0")] impl RangeBounds for RangeInclusive { fn start_bound(&self) -> Bound<&T> { @@ -889,6 +941,22 @@ impl RangeBounds for RangeInclusive { } } +#[unstable(feature = "range_into_bounds", issue = "136903")] +impl IntoBounds for RangeInclusive { + fn into_bounds(self) -> (Bound, Bound) { + ( + Included(self.start), + if self.exhausted { + // When the iterator is exhausted, we usually have start == end, + // but we want the range to appear empty, containing nothing. + Excluded(self.end) + } else { + Included(self.end) + }, + ) + } +} + #[stable(feature = "collections_range", since = "1.28.0")] impl RangeBounds for RangeToInclusive { fn start_bound(&self) -> Bound<&T> { @@ -899,6 +967,13 @@ impl RangeBounds for RangeToInclusive { } } +#[unstable(feature = "range_into_bounds", issue = "136903")] +impl IntoBounds for RangeToInclusive { + fn into_bounds(self) -> (Bound, Bound) { + (Unbounded, Included(self.end)) + } +} + #[stable(feature = "collections_range", since = "1.28.0")] impl RangeBounds for (Bound, Bound) { fn start_bound(&self) -> Bound<&T> { @@ -918,6 +993,13 @@ impl RangeBounds for (Bound, Bound) { } } +#[unstable(feature = "range_into_bounds", issue = "136903")] +impl IntoBounds for (Bound, Bound) { + fn into_bounds(self) -> (Bound, Bound) { + self + } +} + #[stable(feature = "collections_range", since = "1.28.0")] impl<'a, T: ?Sized + 'a> RangeBounds for (Bound<&'a T>, Bound<&'a T>) { fn start_bound(&self) -> Bound<&T> { diff --git a/library/core/src/range.rs b/library/core/src/range.rs index 6a62928873fe8..e94499065ac9a 100644 --- a/library/core/src/range.rs +++ b/library/core/src/range.rs @@ -31,7 +31,9 @@ pub use iter::{IterRange, IterRangeFrom, IterRangeInclusive}; #[doc(inline)] pub use crate::iter::Step; #[doc(inline)] -pub use crate::ops::{Bound, OneSidedRange, RangeBounds, RangeFull, RangeTo, RangeToInclusive}; +pub use crate::ops::{ + Bound, IntoBounds, OneSidedRange, RangeBounds, RangeFull, RangeTo, RangeToInclusive, +}; /// A (half-open) range bounded inclusively below and exclusively above /// (`start..end` in a future edition). @@ -175,6 +177,14 @@ impl RangeBounds for Range<&T> { } } +// #[unstable(feature = "range_into_bounds", issue = "136903")] +#[unstable(feature = "new_range_api", issue = "125687")] +impl IntoBounds for Range { + fn into_bounds(self) -> (Bound, Bound) { + (Included(self.start), Excluded(self.end)) + } +} + #[unstable(feature = "new_range_api", issue = "125687")] impl From> for legacy::Range { #[inline] @@ -343,6 +353,14 @@ impl RangeBounds for RangeInclusive<&T> { } } +// #[unstable(feature = "range_into_bounds", issue = "136903")] +#[unstable(feature = "new_range_api", issue = "125687")] +impl IntoBounds for RangeInclusive { + fn into_bounds(self) -> (Bound, Bound) { + (Included(self.start), Included(self.end)) + } +} + #[unstable(feature = "new_range_api", issue = "125687")] impl From> for legacy::RangeInclusive { #[inline] @@ -479,6 +497,14 @@ impl RangeBounds for RangeFrom<&T> { } } +// #[unstable(feature = "range_into_bounds", issue = "136903")] +#[unstable(feature = "new_range_api", issue = "125687")] +impl IntoBounds for RangeFrom { + fn into_bounds(self) -> (Bound, Bound) { + (Included(self.start), Unbounded) + } +} + #[unstable(feature = "new_range_api", issue = "125687")] impl From> for legacy::RangeFrom { #[inline] From d7eca8ac1524fea59f37f5bf02b072ca822532e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 12 Feb 2025 12:12:37 +0100 Subject: [PATCH 06/12] Trace execution of bootstrap commands --- src/bootstrap/src/core/build_steps/compile.rs | 5 ++++- src/bootstrap/src/lib.rs | 2 ++ src/bootstrap/src/utils/exec.rs | 22 +++++++++++++++++++ src/bootstrap/src/utils/helpers.rs | 4 +++- src/bootstrap/src/utils/tracing.rs | 19 ++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index a2375842bddef..9442d80841f0e 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -30,7 +30,7 @@ use crate::utils::exec::command; use crate::utils::helpers::{ exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date, }; -use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode}; +use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode, trace_cmd}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Std { @@ -2234,6 +2234,9 @@ pub fn stream_cargo( cb: &mut dyn FnMut(CargoMessage<'_>), ) -> bool { let mut cmd = cargo.into_cmd(); + + let _run_span = trace_cmd!(cmd); + let cargo = cmd.as_command_mut(); // Instruct Cargo to give us json messages on stdout, critically leaving // stderr as piped so we can get those pretty colors. diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 665ab117002e0..90b10a95c0eb9 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -905,6 +905,8 @@ impl Build { return CommandOutput::default(); } + let _run_span = trace_cmd!(command); + let created_at = command.get_created_location(); let executed_at = std::panic::Location::caller(); diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index 1902dcd396283..f486ab3fe7547 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -329,3 +329,25 @@ impl Default for CommandOutput { } } } + +/// Helper trait to format both Command and BootstrapCommand as a short execution line, +/// without all the other details (e.g. environment variables). +#[allow(unused)] +pub trait FormatShortCmd { + fn format_short_cmd(&self) -> String; +} + +impl FormatShortCmd for BootstrapCommand { + fn format_short_cmd(&self) -> String { + self.command.format_short_cmd() + } +} + +impl FormatShortCmd for Command { + fn format_short_cmd(&self) -> String { + let program = Path::new(self.get_program()); + let mut line = vec![program.file_name().unwrap().to_str().unwrap()]; + line.extend(self.get_args().into_iter().map(|arg| arg.to_str().unwrap())); + line.join(" ") + } +} diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index a1b1748c85b53..244c4cc3c8576 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -13,11 +13,11 @@ use std::{env, fs, io, str}; use build_helper::util::fail; use object::read::archive::ArchiveFile; -use crate::LldMode; use crate::core::builder::Builder; use crate::core::config::{Config, TargetSelection}; use crate::utils::exec::{BootstrapCommand, command}; pub use crate::utils::shared_helpers::{dylib_path, dylib_path_var}; +use crate::{LldMode, trace_cmd}; #[cfg(test)] mod tests; @@ -265,6 +265,8 @@ pub fn make(host: &str) -> PathBuf { #[track_caller] pub fn output(cmd: &mut Command) -> String { + let _run_span = trace_cmd!(cmd); + let output = match cmd.stderr(Stdio::inherit()).output() { Ok(status) => status, Err(e) => fail(&format!("failed to execute command: {cmd:?}\nERROR: {e}")), diff --git a/src/bootstrap/src/utils/tracing.rs b/src/bootstrap/src/utils/tracing.rs index e89decf9e5586..55531019f0332 100644 --- a/src/bootstrap/src/utils/tracing.rs +++ b/src/bootstrap/src/utils/tracing.rs @@ -47,3 +47,22 @@ macro_rules! error { ::tracing::error!($($tokens)*) } } + +#[macro_export] +macro_rules! trace_cmd { + ($cmd:expr) => { + { + #[allow(unused)] + use $crate::utils::exec::FormatShortCmd; + + #[cfg(feature = "tracing")] + ::tracing::span!( + target: "COMMAND", + ::tracing::Level::TRACE, + "executing command", + cmd = $cmd.format_short_cmd(), + full_cmd = ?$cmd + ).entered() + } + }; +} From 447a6a0322b887ebc8fc734b0582db8bc754967b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 12 Feb 2025 13:35:36 +0100 Subject: [PATCH 07/12] Add export of bootstrap tracing to Chrome events --- src/bootstrap/Cargo.lock | 12 ++++++++++++ src/bootstrap/Cargo.toml | 3 ++- src/bootstrap/src/bin/main.rs | 16 +++++++++++++--- src/bootstrap/src/core/build_steps/compile.rs | 5 +++-- src/bootstrap/src/lib.rs | 1 + src/bootstrap/src/utils/exec.rs | 2 +- src/bootstrap/src/utils/helpers.rs | 5 +++-- src/bootstrap/src/utils/tracing.rs | 2 -- 8 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock index d2f3c7f36ca86..a47f3af60cbd5 100644 --- a/src/bootstrap/Cargo.lock +++ b/src/bootstrap/Cargo.lock @@ -59,6 +59,7 @@ dependencies = [ "termcolor", "toml", "tracing", + "tracing-chrome", "tracing-subscriber", "tracing-tree", "walkdir", @@ -727,6 +728,17 @@ dependencies = [ "syn", ] +[[package]] +name = "tracing-chrome" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf0a738ed5d6450a9fb96e86a23ad808de2b727fd1394585da5cdd6788ffe724" +dependencies = [ + "serde_json", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "tracing-core" version = "0.1.33" diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index d7afcc7f27d2e..ed51862390d40 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -7,7 +7,7 @@ default-run = "bootstrap" [features] build-metrics = ["sysinfo"] -tracing = ["dep:tracing", "dep:tracing-subscriber", "dep:tracing-tree"] +tracing = ["dep:tracing", "dep:tracing-chrome", "dep:tracing-subscriber", "dep:tracing-tree"] [lib] path = "src/lib.rs" @@ -67,6 +67,7 @@ sysinfo = { version = "0.33.0", default-features = false, optional = true, featu # Dependencies needed by the `tracing` feature tracing = { version = "0.1", optional = true, features = ["attributes"] } +tracing-chrome = { version = "0.7", optional = true } tracing-subscriber = { version = "0.3", optional = true, features = ["env-filter", "fmt", "registry", "std"] } tracing-tree = { version = "0.4.0", optional = true } diff --git a/src/bootstrap/src/bin/main.rs b/src/bootstrap/src/bin/main.rs index 441674936c666..38b380e3db824 100644 --- a/src/bootstrap/src/bin/main.rs +++ b/src/bootstrap/src/bin/main.rs @@ -21,7 +21,7 @@ use tracing::instrument; #[cfg_attr(feature = "tracing", instrument(level = "trace", name = "main"))] fn main() { #[cfg(feature = "tracing")] - setup_tracing(); + let _guard = setup_tracing(); let args = env::args().skip(1).collect::>(); @@ -210,7 +210,7 @@ fn check_version(config: &Config) -> Option { // - `tracing`'s `#[instrument(..)]` macro will need to be gated like `#![cfg_attr(feature = // "tracing", instrument(..))]`. #[cfg(feature = "tracing")] -fn setup_tracing() { +fn setup_tracing() -> impl Drop { use tracing_subscriber::EnvFilter; use tracing_subscriber::layer::SubscriberExt; @@ -218,7 +218,17 @@ fn setup_tracing() { // cf. . let layer = tracing_tree::HierarchicalLayer::default().with_targets(true).with_indent_amount(2); - let registry = tracing_subscriber::registry().with(filter).with(layer); + let mut chrome_layer = tracing_chrome::ChromeLayerBuilder::new().include_args(true); + + // Writes the Chrome profile to trace-.json if enabled + if !env::var("BOOTSTRAP_PROFILE").is_ok_and(|v| v == "1") { + chrome_layer = chrome_layer.writer(io::sink()); + } + + let (chrome_layer, _guard) = chrome_layer.build(); + + let registry = tracing_subscriber::registry().with(filter).with(layer).with(chrome_layer); tracing::subscriber::set_global_default(registry).unwrap(); + _guard } diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 9442d80841f0e..8e5a8b7e2541c 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -30,7 +30,7 @@ use crate::utils::exec::command; use crate::utils::helpers::{ exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date, }; -use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode, trace_cmd}; +use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Std { @@ -2235,7 +2235,8 @@ pub fn stream_cargo( ) -> bool { let mut cmd = cargo.into_cmd(); - let _run_span = trace_cmd!(cmd); + #[cfg(feature = "tracing")] + let _run_span = crate::trace_cmd!(cmd); let cargo = cmd.as_command_mut(); // Instruct Cargo to give us json messages on stdout, critically leaving diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 90b10a95c0eb9..7cd8aacf0d6c8 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -905,6 +905,7 @@ impl Build { return CommandOutput::default(); } + #[cfg(feature = "tracing")] let _run_span = trace_cmd!(command); let created_at = command.get_created_location(); diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index f486ab3fe7547..7eb9ab96c8a4a 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -347,7 +347,7 @@ impl FormatShortCmd for Command { fn format_short_cmd(&self) -> String { let program = Path::new(self.get_program()); let mut line = vec![program.file_name().unwrap().to_str().unwrap()]; - line.extend(self.get_args().into_iter().map(|arg| arg.to_str().unwrap())); + line.extend(self.get_args().map(|arg| arg.to_str().unwrap())); line.join(" ") } } diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index 244c4cc3c8576..3fee397da091d 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -13,11 +13,11 @@ use std::{env, fs, io, str}; use build_helper::util::fail; use object::read::archive::ArchiveFile; +use crate::LldMode; use crate::core::builder::Builder; use crate::core::config::{Config, TargetSelection}; use crate::utils::exec::{BootstrapCommand, command}; pub use crate::utils::shared_helpers::{dylib_path, dylib_path_var}; -use crate::{LldMode, trace_cmd}; #[cfg(test)] mod tests; @@ -265,7 +265,8 @@ pub fn make(host: &str) -> PathBuf { #[track_caller] pub fn output(cmd: &mut Command) -> String { - let _run_span = trace_cmd!(cmd); + #[cfg(feature = "tracing")] + let _run_span = crate::trace_cmd!(cmd); let output = match cmd.stderr(Stdio::inherit()).output() { Ok(status) => status, diff --git a/src/bootstrap/src/utils/tracing.rs b/src/bootstrap/src/utils/tracing.rs index 55531019f0332..99849341dc3b9 100644 --- a/src/bootstrap/src/utils/tracing.rs +++ b/src/bootstrap/src/utils/tracing.rs @@ -52,10 +52,8 @@ macro_rules! error { macro_rules! trace_cmd { ($cmd:expr) => { { - #[allow(unused)] use $crate::utils::exec::FormatShortCmd; - #[cfg(feature = "tracing")] ::tracing::span!( target: "COMMAND", ::tracing::Level::TRACE, From 521cbd36fa1cc645a3682fe429b4d636b16b6fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 12 Feb 2025 13:48:48 +0100 Subject: [PATCH 08/12] Document bootstrap profiling --- .../src/building/bootstrapping/debugging-bootstrap.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/doc/rustc-dev-guide/src/building/bootstrapping/debugging-bootstrap.md b/src/doc/rustc-dev-guide/src/building/bootstrapping/debugging-bootstrap.md index 3f907e85dd6cc..04fa5b204dd4e 100644 --- a/src/doc/rustc-dev-guide/src/building/bootstrapping/debugging-bootstrap.md +++ b/src/doc/rustc-dev-guide/src/building/bootstrapping/debugging-bootstrap.md @@ -121,6 +121,14 @@ For `#[instrument]`, it's recommended to: - Explicitly pick an instrumentation name via `name = ".."` to distinguish between e.g. `run` of different steps. - Take care to not cause diverging behavior via tracing, e.g. building extra things only when tracing infra is enabled. +### Profiling bootstrap + +You can use the `COMMAND` tracing target to trace execution of most commands spawned by bootstrap. If you also use the `BOOTSTRAP_PROFILE=1` environment variable, bootstrap will generate a Chrome JSON trace file, which can be visualized in Chrome's `chrome://tracing` page or on https://ui.perfetto.dev. + +```bash +$ BOOTSTRAP_TRACING=COMMAND=trace BOOTSTRAP_PROFILE=1 ./x build library +``` + ### rust-analyzer integration? Unfortunately, because bootstrap is a `rust-analyzer.linkedProjects`, you can't ask r-a to check/build bootstrap itself with `tracing` feature enabled to get relevant completions, due to lack of support as described in . From fc5ff7f3f9a088b4f2882c51c845593f42a2faee Mon Sep 17 00:00:00 2001 From: MarcoIeni <11428655+MarcoIeni@users.noreply.github.com> Date: Thu, 13 Feb 2025 18:10:22 +0100 Subject: [PATCH 09/12] ci: switch loongarch jobs to free runners --- src/ci/github-actions/jobs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index c08104e796b93..5c6a4d84e3eb2 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -168,10 +168,10 @@ auto: <<: *job-linux-4c - name: dist-loongarch64-linux - <<: *job-linux-4c-largedisk + <<: *job-linux-4c - name: dist-loongarch64-musl - <<: *job-linux-4c-largedisk + <<: *job-linux-4c - name: dist-ohos <<: *job-linux-4c From 296625613386532e8a6963f821716db119c2ab62 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Mon, 13 Jan 2025 15:52:08 +0000 Subject: [PATCH 10/12] Make `-O` mean `-C opt-level=3` --- compiler/rustc_codegen_cranelift/src/lib.rs | 2 +- compiler/rustc_codegen_gcc/src/lib.rs | 2 +- compiler/rustc_codegen_llvm/src/back/write.rs | 4 +-- compiler/rustc_codegen_ssa/src/back/linker.rs | 16 ++++++------ compiler/rustc_codegen_ssa/src/back/write.rs | 4 +-- compiler/rustc_codegen_ssa/src/base.rs | 6 ++--- compiler/rustc_mir_transform/src/inline.rs | 3 +-- compiler/rustc_session/src/config.rs | 26 ++++++++++++------- src/doc/rustc/src/codegen-options/index.md | 2 +- src/doc/rustc/src/command-line-arguments.md | 2 +- .../src/external_deps/rustc.rs | 2 +- tests/run-make/rustc-help/help-v.stdout | 2 +- tests/run-make/rustc-help/help.stdout | 2 +- 13 files changed, 39 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/lib.rs b/compiler/rustc_codegen_cranelift/src/lib.rs index b015341990306..a3f4374487578 100644 --- a/compiler/rustc_codegen_cranelift/src/lib.rs +++ b/compiler/rustc_codegen_cranelift/src/lib.rs @@ -289,7 +289,7 @@ fn build_isa(sess: &Session) -> Arc { flags_builder.set("opt_level", "none").unwrap(); } OptLevel::Less - | OptLevel::Default + | OptLevel::More | OptLevel::Size | OptLevel::SizeMin | OptLevel::Aggressive => { diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index ce88ac390216a..6455bcec6851b 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -476,7 +476,7 @@ fn to_gcc_opt_level(optlevel: Option) -> OptimizationLevel { Some(level) => match level { OptLevel::No => OptimizationLevel::None, OptLevel::Less => OptimizationLevel::Limited, - OptLevel::Default => OptimizationLevel::Standard, + OptLevel::More => OptimizationLevel::Standard, OptLevel::Aggressive => OptimizationLevel::Aggressive, OptLevel::Size | OptLevel::SizeMin => OptimizationLevel::Limited, }, diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 58933a77e53d1..9fa10e960680b 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -141,7 +141,7 @@ fn to_llvm_opt_settings(cfg: config::OptLevel) -> (llvm::CodeGenOptLevel, llvm:: match cfg { No => (llvm::CodeGenOptLevel::None, llvm::CodeGenOptSizeNone), Less => (llvm::CodeGenOptLevel::Less, llvm::CodeGenOptSizeNone), - Default => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeNone), + More => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeNone), Aggressive => (llvm::CodeGenOptLevel::Aggressive, llvm::CodeGenOptSizeNone), Size => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeDefault), SizeMin => (llvm::CodeGenOptLevel::Default, llvm::CodeGenOptSizeAggressive), @@ -153,7 +153,7 @@ fn to_pass_builder_opt_level(cfg: config::OptLevel) -> llvm::PassBuilderOptLevel match cfg { No => llvm::PassBuilderOptLevel::O0, Less => llvm::PassBuilderOptLevel::O1, - Default => llvm::PassBuilderOptLevel::O2, + More => llvm::PassBuilderOptLevel::O2, Aggressive => llvm::PassBuilderOptLevel::O3, Size => llvm::PassBuilderOptLevel::Os, SizeMin => llvm::PassBuilderOptLevel::Oz, diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 8fb831471a9ba..05d6ff357514d 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -410,7 +410,7 @@ impl<'a> GccLinker<'a> { let opt_level = match self.sess.opts.optimize { config::OptLevel::No => "O0", config::OptLevel::Less => "O1", - config::OptLevel::Default | config::OptLevel::Size | config::OptLevel::SizeMin => "O2", + config::OptLevel::More | config::OptLevel::Size | config::OptLevel::SizeMin => "O2", config::OptLevel::Aggressive => "O3", }; @@ -685,7 +685,7 @@ impl<'a> Linker for GccLinker<'a> { // GNU-style linkers support optimization with -O. GNU ld doesn't // need a numeric argument, but other linkers do. - if self.sess.opts.optimize == config::OptLevel::Default + if self.sess.opts.optimize == config::OptLevel::More || self.sess.opts.optimize == config::OptLevel::Aggressive { self.link_arg("-O1"); @@ -1213,7 +1213,7 @@ impl<'a> Linker for EmLinker<'a> { self.cc_arg(match self.sess.opts.optimize { OptLevel::No => "-O0", OptLevel::Less => "-O1", - OptLevel::Default => "-O2", + OptLevel::More => "-O2", OptLevel::Aggressive => "-O3", OptLevel::Size => "-Os", OptLevel::SizeMin => "-Oz", @@ -1384,7 +1384,7 @@ impl<'a> Linker for WasmLd<'a> { self.link_arg(match self.sess.opts.optimize { OptLevel::No => "-O0", OptLevel::Less => "-O1", - OptLevel::Default => "-O2", + OptLevel::More => "-O2", OptLevel::Aggressive => "-O3", // Currently LLD doesn't support `Os` and `Oz`, so pass through `O2` // instead. @@ -1451,7 +1451,7 @@ impl<'a> WasmLd<'a> { let opt_level = match self.sess.opts.optimize { config::OptLevel::No => "O0", config::OptLevel::Less => "O1", - config::OptLevel::Default => "O2", + config::OptLevel::More => "O2", config::OptLevel::Aggressive => "O3", // wasm-ld only handles integer LTO opt levels. Use O2 config::OptLevel::Size | config::OptLevel::SizeMin => "O2", @@ -1525,7 +1525,7 @@ impl<'a> Linker for L4Bender<'a> { fn optimize(&mut self) { // GNU-style linkers support optimization with -O. GNU ld doesn't // need a numeric argument, but other linkers do. - if self.sess.opts.optimize == config::OptLevel::Default + if self.sess.opts.optimize == config::OptLevel::More || self.sess.opts.optimize == config::OptLevel::Aggressive { self.link_arg("-O1"); @@ -1929,7 +1929,7 @@ impl<'a> Linker for LlbcLinker<'a> { match self.sess.opts.optimize { OptLevel::No => "-O0", OptLevel::Less => "-O1", - OptLevel::Default => "-O2", + OptLevel::More => "-O2", OptLevel::Aggressive => "-O3", OptLevel::Size => "-Os", OptLevel::SizeMin => "-Oz", @@ -2006,7 +2006,7 @@ impl<'a> Linker for BpfLinker<'a> { self.link_arg(match self.sess.opts.optimize { OptLevel::No => "-O0", OptLevel::Less => "-O1", - OptLevel::Default => "-O2", + OptLevel::More => "-O2", OptLevel::Aggressive => "-O3", OptLevel::Size => "-Os", OptLevel::SizeMin => "-Oz", diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index ce2161a07ebf6..f029c08a80821 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -236,7 +236,7 @@ impl ModuleConfig { // Copy what clang does by turning on loop vectorization at O2 and // slp vectorization at O3. vectorize_loop: !sess.opts.cg.no_vectorize_loops - && (sess.opts.optimize == config::OptLevel::Default + && (sess.opts.optimize == config::OptLevel::More || sess.opts.optimize == config::OptLevel::Aggressive), vectorize_slp: !sess.opts.cg.no_vectorize_slp && sess.opts.optimize == config::OptLevel::Aggressive, @@ -260,7 +260,7 @@ impl ModuleConfig { MergeFunctions::Trampolines | MergeFunctions::Aliases => { use config::OptLevel::*; match sess.opts.optimize { - Aggressive | Default | SizeMin | Size => true, + Aggressive | More | SizeMin | Size => true, Less | No => false, } } diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index d9fbf539fd3d5..e800492dad02f 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -1054,12 +1054,12 @@ pub(crate) fn provide(providers: &mut Providers) { config::OptLevel::No => return config::OptLevel::No, // If globally optimise-speed is already specified, just use that level. config::OptLevel::Less => return config::OptLevel::Less, - config::OptLevel::Default => return config::OptLevel::Default, + config::OptLevel::More => return config::OptLevel::More, config::OptLevel::Aggressive => return config::OptLevel::Aggressive, // If globally optimize-for-size has been requested, use -O2 instead (if optimize(size) // are present). - config::OptLevel::Size => config::OptLevel::Default, - config::OptLevel::SizeMin => config::OptLevel::Default, + config::OptLevel::Size => config::OptLevel::More, + config::OptLevel::SizeMin => config::OptLevel::More, }; let defids = tcx.collect_and_partition_mono_items(cratenum).all_mono_items; diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index ab617e2ce6fd6..1f8392b211870 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -49,8 +49,7 @@ impl<'tcx> crate::MirPass<'tcx> for Inline { match sess.mir_opt_level() { 0 | 1 => false, 2 => { - (sess.opts.optimize == OptLevel::Default - || sess.opts.optimize == OptLevel::Aggressive) + (sess.opts.optimize == OptLevel::More || sess.opts.optimize == OptLevel::Aggressive) && sess.opts.incremental == None } _ => true, diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 2fb4b27b88905..7d473b86ff58a 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -86,12 +86,18 @@ pub enum CFProtection { #[derive(Clone, Copy, Debug, PartialEq, Hash, HashStable_Generic)] pub enum OptLevel { - No, // -O0 - Less, // -O1 - Default, // -O2 - Aggressive, // -O3 - Size, // -Os - SizeMin, // -Oz + /// `-Copt-level=0` + No, + /// `-Copt-level=1` + Less, + /// `-Copt-level=2` + More, + /// `-Copt-level=3` / `-O` + Aggressive, + /// `-Copt-level=s` + Size, + /// `-Copt-level=z` + SizeMin, } /// This is what the `LtoCli` values get mapped to after resolving defaults and @@ -1253,7 +1259,7 @@ impl Options { Some(setting) => setting, None => match self.optimize { OptLevel::No | OptLevel::Less | OptLevel::Size | OptLevel::SizeMin => true, - OptLevel::Default | OptLevel::Aggressive => false, + OptLevel::More | OptLevel::Aggressive => false, }, } } @@ -1572,7 +1578,7 @@ pub fn rustc_optgroups() -> Vec { stack-protector-strategies|link-args|deployment-target]", ), opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""), - opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=2", ""), + opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=3", ""), opt(Stable, Opt, "o", "", "Write output to ", "FILENAME"), opt(Stable, Opt, "", "out-dir", "Write output to compiler-chosen filename in ", "DIR"), opt( @@ -2127,12 +2133,12 @@ fn parse_opt_level( }) .max(); if max_o > max_c { - OptLevel::Default + OptLevel::Aggressive } else { match cg.opt_level.as_ref() { "0" => OptLevel::No, "1" => OptLevel::Less, - "2" => OptLevel::Default, + "2" => OptLevel::More, "3" => OptLevel::Aggressive, "s" => OptLevel::Size, "z" => OptLevel::SizeMin, diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index f45217c69ff0f..8c1769a8c7722 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -368,7 +368,7 @@ This flag controls the optimization level. * `s`: optimize for binary size. * `z`: optimize for binary size, but also turn off loop vectorization. -Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=2`. +Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=3`. The default is `0`. diff --git a/src/doc/rustc/src/command-line-arguments.md b/src/doc/rustc/src/command-line-arguments.md index 0942b5ebfee37..9dd2e7de1b330 100644 --- a/src/doc/rustc/src/command-line-arguments.md +++ b/src/doc/rustc/src/command-line-arguments.md @@ -308,7 +308,7 @@ A synonym for [`-C debuginfo=2`](codegen-options/index.md#debuginfo). ## `-O`: optimize your code -A synonym for [`-C opt-level=2`](codegen-options/index.md#opt-level). +A synonym for [`-C opt-level=3`](codegen-options/index.md#opt-level). ## `-o`: filename of the output diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs index 33dc57cbc0776..fd4a20278addd 100644 --- a/src/tools/run-make-support/src/external_deps/rustc.rs +++ b/src/tools/run-make-support/src/external_deps/rustc.rs @@ -84,7 +84,7 @@ impl Rustc { self } - /// Specify default optimization level `-O` (alias for `-C opt-level=2`). + /// Specify default optimization level `-O` (alias for `-C opt-level=3`). pub fn opt(&mut self) -> &mut Self { self.cmd.arg("-O"); self diff --git a/tests/run-make/rustc-help/help-v.stdout b/tests/run-make/rustc-help/help-v.stdout index 8f6fde69c29b1..382b1c96682cb 100644 --- a/tests/run-make/rustc-help/help-v.stdout +++ b/tests/run-make/rustc-help/help-v.stdout @@ -32,7 +32,7 @@ Options: --print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target] Compiler information to print on stdout -g Equivalent to -C debuginfo=2 - -O Equivalent to -C opt-level=2 + -O Equivalent to -C opt-level=3 -o FILENAME Write output to --out-dir DIR Write output to compiler-chosen filename in --explain OPT Provide a detailed explanation of an error message diff --git a/tests/run-make/rustc-help/help.stdout b/tests/run-make/rustc-help/help.stdout index 131efa93282fd..08bb7f85098d2 100644 --- a/tests/run-make/rustc-help/help.stdout +++ b/tests/run-make/rustc-help/help.stdout @@ -32,7 +32,7 @@ Options: --print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target] Compiler information to print on stdout -g Equivalent to -C debuginfo=2 - -O Equivalent to -C opt-level=2 + -O Equivalent to -C opt-level=3 -o FILENAME Write output to --out-dir DIR Write output to compiler-chosen filename in --explain OPT Provide a detailed explanation of an error message From 06524b56bdfc7019154798659e2a72d6cc2c9c83 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 13 Feb 2025 14:32:50 -0800 Subject: [PATCH 11/12] Update backtrace --- library/backtrace | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/backtrace b/library/backtrace index f8cc6ac9acc4e..9d2c34e7e63af 160000 --- a/library/backtrace +++ b/library/backtrace @@ -1 +1 @@ -Subproject commit f8cc6ac9acc4e663ecd96f9bcf1ff4542636d1b9 +Subproject commit 9d2c34e7e63afe1e71c333b247065e3b7ba4d883 From bfdc96114c4b591025dd6ec18b4282f0b21e641c Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Thu, 13 Feb 2025 15:04:39 -0800 Subject: [PATCH 12/12] [cg_llvm] Remove dead error message --- compiler/rustc_codegen_llvm/messages.ftl | 3 --- compiler/rustc_codegen_llvm/src/errors.rs | 5 ----- 2 files changed, 8 deletions(-) diff --git a/compiler/rustc_codegen_llvm/messages.ftl b/compiler/rustc_codegen_llvm/messages.ftl index 9585848cbf033..399d7ffea8e6d 100644 --- a/compiler/rustc_codegen_llvm/messages.ftl +++ b/compiler/rustc_codegen_llvm/messages.ftl @@ -38,9 +38,6 @@ codegen_llvm_lto_proc_macro = lto cannot be used for `proc-macro` crate type wit codegen_llvm_mismatch_data_layout = data-layout for target `{$rustc_target}`, `{$rustc_layout}`, differs from LLVM target's `{$llvm_target}` default layout, `{$llvm_layout}` -codegen_llvm_multiple_source_dicompileunit = multiple source DICompileUnits found -codegen_llvm_multiple_source_dicompileunit_with_llvm_err = multiple source DICompileUnits found: {$llvm_err} - codegen_llvm_parse_bitcode = failed to parse bitcode for LTO module codegen_llvm_parse_bitcode_with_llvm_err = failed to parse bitcode for LTO module: {$llvm_err} diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs index f4c9491f75844..97f4925616595 100644 --- a/compiler/rustc_codegen_llvm/src/errors.rs +++ b/compiler/rustc_codegen_llvm/src/errors.rs @@ -131,8 +131,6 @@ pub enum LlvmError<'a> { LoadBitcode { name: CString }, #[diag(codegen_llvm_write_thinlto_key)] WriteThinLtoKey { err: std::io::Error }, - #[diag(codegen_llvm_multiple_source_dicompileunit)] - MultipleSourceDiCompileUnit, #[diag(codegen_llvm_prepare_thin_lto_module)] PrepareThinLtoModule, #[diag(codegen_llvm_parse_bitcode)] @@ -155,9 +153,6 @@ impl Diagnostic<'_, G> for WithLlvmError<'_> { PrepareThinLtoContext => fluent::codegen_llvm_prepare_thin_lto_context_with_llvm_err, LoadBitcode { .. } => fluent::codegen_llvm_load_bitcode_with_llvm_err, WriteThinLtoKey { .. } => fluent::codegen_llvm_write_thinlto_key_with_llvm_err, - MultipleSourceDiCompileUnit => { - fluent::codegen_llvm_multiple_source_dicompileunit_with_llvm_err - } PrepareThinLtoModule => fluent::codegen_llvm_prepare_thin_lto_module_with_llvm_err, ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err, PrepareAutoDiff { .. } => fluent::codegen_llvm_prepare_autodiff_with_llvm_err,