Skip to content

Commit

Permalink
Auto merge of #135789 - matthiaskrgr:rollup-4cvw8s4, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #133695 (Reexport likely/unlikely in std::hint)
 - #135330 (Respect --sysroot for rustc -vV and -Cpasses=list)
 - #135333 (Partial progress on #132735: Replace extern "rust-intrinsic" with #[rustc_intrinsic] across the codebase)
 - #135741 (Recognise new IPv6 documentation range from IETF RFC 9637)
 - #135770 (Update contributing docs for submodule/subtree changes)
 - #135775 (Subtree update of `rust-analyzer`)
 - #135776 (Subtree sync for rustc_codegen_cranelift)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 20, 2025
2 parents 9f4d9dc + 67b609a commit f3d1d47
Show file tree
Hide file tree
Showing 331 changed files with 9,572 additions and 3,037 deletions.
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ Documentation for contributing to the compiler or tooling is located in the [Gui
Development][rustc-dev-guide], commonly known as the [rustc-dev-guide]. Documentation for the
standard library in the [Standard library developers Guide][std-dev-guide], commonly known as the [std-dev-guide].

## Making changes to subtrees and submodules

For submodules, changes need to be made against the repository corresponding the
submodule, and not the main `rust-lang/rust` repository.

For subtrees, prefer sending a PR against the subtree's repository if it does
not need to be made against the main `rust-lang/rust` repostory (e.g. a
rustc-dev-guide change that does not accompany a compiler change).

## About the [rustc-dev-guide]

The [rustc-dev-guide] is meant to help document how rustc –the Rust compiler– works,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2025-01-10"
channel = "nightly-2025-01-20"
components = ["rust-src", "rustc-dev", "llvm-tools"]
profile = "minimal"
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,11 @@ diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-supp
index 9607ff02f96..b7d97caf9a2 100644
--- a/src/tools/run-make-support/src/external_deps/rustdoc.rs
+++ b/src/tools/run-make-support/src/external_deps/rustdoc.rs
@@ -34,8 +34,6 @@ pub fn bare() -> Self {
@@ -34,7 +34,6 @@ pub fn bare() -> Self {
#[track_caller]
pub fn new() -> Self {
let mut cmd = setup_common();
- let target_rpath_dir = env_var_os("TARGET_RPATH_DIR");
- cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy()));
- cmd.arg("-L").arg(env_var_os("TARGET_RPATH_DIR"));
Self { cmd }
}
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_codegen_cranelift/src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,17 @@ fn make_module(sess: &Session, name: String) -> UnwindModule<ObjectModule> {

let mut builder =
ObjectBuilder::new(isa, name + ".o", cranelift_module::default_libcall_names()).unwrap();

// Disable function sections by default on MSVC as it causes significant slowdowns with link.exe.
// Maybe link.exe has exponential behavior when there are many sections with the same name? Also
// explicitly disable it on MinGW as rustc already disables it by default on MinGW and as such
// isn't tested. If rustc enables it in the future on MinGW, we can re-enable it too once it has
// been on MinGW.
let default_function_sections = sess.target.function_sections && !sess.target.is_like_windows;
builder.per_function_section(
sess.opts.unstable_opts.function_sections.unwrap_or(sess.target.function_sections),
sess.opts.unstable_opts.function_sections.unwrap_or(default_function_sections),
);

UnwindModule::new(ObjectModule::new(builder), true)
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Codegen of intrinsics. This includes `extern "rust-intrinsic"`,
//! functions marked with the `#[rustc_intrinsic]` attribute
//! and LLVM intrinsics that have symbol names starting with `llvm.`.
macro_rules! intrinsic_args {
Expand Down
37 changes: 22 additions & 15 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
use rustc_session::config::{
CG_OPTIONS, ErrorOutputType, Input, OptionDesc, OutFileName, OutputType, UnstableOptions,
Z_OPTIONS, nightly_options,
Z_OPTIONS, nightly_options, parse_target_triple,
};
use rustc_session::getopts::{self, Matches};
use rustc_session::lint::{Lint, LintId};
Expand Down Expand Up @@ -916,13 +916,7 @@ pub fn version_at_macro_invocation(
safe_println!("host: {}", config::host_tuple());
safe_println!("release: {release}");

let debug_flags = matches.opt_strs("Z");
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
let opts = config::Options::default();
let sysroot = filesearch::materialize_sysroot(opts.maybe_sysroot.clone());
let target = config::build_target_config(early_dcx, &opts, &sysroot);

get_codegen_backend(early_dcx, &sysroot, backend_name, &target).print_version();
get_backend_from_raw_matches(early_dcx, matches).print_version();
}
}

Expand Down Expand Up @@ -1125,19 +1119,32 @@ pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) ->
}

if cg_flags.iter().any(|x| *x == "passes=list") {
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));

let opts = config::Options::default();
let sysroot = filesearch::materialize_sysroot(opts.maybe_sysroot.clone());
let target = config::build_target_config(early_dcx, &opts, &sysroot);

get_codegen_backend(early_dcx, &sysroot, backend_name, &target).print_passes();
get_backend_from_raw_matches(early_dcx, matches).print_passes();
return true;
}

false
}

/// Get the codegen backend based on the raw [`Matches`].
///
/// `rustc -vV` and `rustc -Cpasses=list` need to get the codegen backend before we have parsed all
/// arguments and created a [`Session`]. This function reads `-Zcodegen-backend`, `--target` and
/// `--sysroot` without validating any other arguments and loads the codegen backend based on these
/// arguments.
fn get_backend_from_raw_matches(
early_dcx: &EarlyDiagCtxt,
matches: &Matches,
) -> Box<dyn CodegenBackend> {
let debug_flags = matches.opt_strs("Z");
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
let target = parse_target_triple(early_dcx, matches);
let sysroot = filesearch::materialize_sysroot(matches.opt_str("sysroot").map(PathBuf::from));
let target = config::build_target_config(early_dcx, &target, &sysroot);

get_codegen_backend(early_dcx, &sysroot, backend_name, &target)
}

fn describe_debug_flags() {
safe_println!("\nAvailable options:\n");
print_flag_list("-Z", config::Z_OPTIONS);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
crate::callbacks::setup_callbacks();

let sysroot = filesearch::materialize_sysroot(config.opts.maybe_sysroot.clone());
let target = config::build_target_config(&early_dcx, &config.opts, &sysroot);
let target = config::build_target_config(&early_dcx, &config.opts.target_triple, &sysroot);
let file_loader = config.file_loader.unwrap_or_else(|| Box::new(RealFileLoader));
let path_mapping = config.opts.file_path_mapping();
let hash_kind = config.opts.unstable_opts.src_hash_algorithm(&target);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ where
let matches = optgroups().parse(args).unwrap();
let sessopts = build_session_options(&mut early_dcx, &matches);
let sysroot = filesearch::materialize_sysroot(sessopts.maybe_sysroot.clone());
let target = rustc_session::config::build_target_config(&early_dcx, &sessopts, &sysroot);
let target =
rustc_session::config::build_target_config(&early_dcx, &sessopts.target_triple, &sysroot);
let hash_kind = sessopts.unstable_opts.src_hash_algorithm(&target);
let checksum_hash_kind = sessopts.unstable_opts.checksum_hash_algorithm();
let sm_inputs = Some(SourceMapInputs {
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,12 @@ pub fn build_configuration(sess: &Session, mut user_cfg: Cfg) -> Cfg {
user_cfg
}

pub fn build_target_config(early_dcx: &EarlyDiagCtxt, opts: &Options, sysroot: &Path) -> Target {
match Target::search(&opts.target_triple, sysroot) {
pub fn build_target_config(
early_dcx: &EarlyDiagCtxt,
target: &TargetTuple,
sysroot: &Path,
) -> Target {
match Target::search(target, sysroot) {
Ok((target, warnings)) => {
for warning in warnings.warning_messages() {
early_dcx.early_warn(warning)
Expand Down
135 changes: 135 additions & 0 deletions library/core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,138 @@ pub const fn black_box<T>(dummy: T) -> T {
pub const fn must_use<T>(value: T) -> T {
value
}

/// Hints to the compiler that a branch condition is likely to be true.
/// Returns the value passed to it.
///
/// It can be used with `if` or boolean `match` expressions.
///
/// When used outside of a branch condition, it may still influence a nearby branch, but
/// probably will not have any effect.
///
/// It can also be applied to parts of expressions, such as `likely(a) && unlikely(b)`, or to
/// compound expressions, such as `likely(a && b)`. When applied to compound expressions, it has
/// the following effect:
/// ```text
/// likely(!a) => !unlikely(a)
/// likely(a && b) => likely(a) && likely(b)
/// likely(a || b) => a || likely(b)
/// ```
///
/// See also the function [`cold_path()`] which may be more appropriate for idiomatic Rust code.
///
/// # Examples
///
/// ```
/// #![feature(likely_unlikely)]
/// use core::hint::likely;
///
/// fn foo(x: i32) {
/// if likely(x > 0) {
/// println!("this branch is likely to be taken");
/// } else {
/// println!("this branch is unlikely to be taken");
/// }
///
/// match likely(x > 0) {
/// true => println!("this branch is likely to be taken"),
/// false => println!("this branch is unlikely to be taken"),
/// }
///
/// // Use outside of a branch condition may still influence a nearby branch
/// let cond = likely(x != 0);
/// if cond {
/// println!("this branch is likely to be taken");
/// }
/// }
/// ```
///
///
#[unstable(feature = "likely_unlikely", issue = "26179")]
#[inline(always)]
pub const fn likely(b: bool) -> bool {
crate::intrinsics::likely(b)
}

/// Hints to the compiler that a branch condition is unlikely to be true.
/// Returns the value passed to it.
///
/// It can be used with `if` or boolean `match` expressions.
///
/// When used outside of a branch condition, it may still influence a nearby branch, but
/// probably will not have any effect.
///
/// It can also be applied to parts of expressions, such as `likely(a) && unlikely(b)`, or to
/// compound expressions, such as `unlikely(a && b)`. When applied to compound expressions, it has
/// the following effect:
/// ```text
/// unlikely(!a) => !likely(a)
/// unlikely(a && b) => a && unlikely(b)
/// unlikely(a || b) => unlikely(a) || unlikely(b)
/// ```
///
/// See also the function [`cold_path()`] which may be more appropriate for idiomatic Rust code.
///
/// # Examples
///
/// ```
/// #![feature(likely_unlikely)]
/// use core::hint::unlikely;
///
/// fn foo(x: i32) {
/// if unlikely(x > 0) {
/// println!("this branch is unlikely to be taken");
/// } else {
/// println!("this branch is likely to be taken");
/// }
///
/// match unlikely(x > 0) {
/// true => println!("this branch is unlikely to be taken"),
/// false => println!("this branch is likely to be taken"),
/// }
///
/// // Use outside of a branch condition may still influence a nearby branch
/// let cond = unlikely(x != 0);
/// if cond {
/// println!("this branch is likely to be taken");
/// }
/// }
/// ```
#[unstable(feature = "likely_unlikely", issue = "26179")]
#[inline(always)]
pub const fn unlikely(b: bool) -> bool {
crate::intrinsics::unlikely(b)
}

/// Hints to the compiler that given path is cold, i.e., unlikely to be taken. The compiler may
/// choose to optimize paths that are not cold at the expense of paths that are cold.
///
/// # Examples
///
/// ```
/// #![feature(cold_path)]
/// use core::hint::cold_path;
///
/// fn foo(x: &[i32]) {
/// if let Some(first) = x.get(0) {
/// // this is the fast path
/// } else {
/// // this path is unlikely
/// cold_path();
/// }
/// }
///
/// fn bar(x: i32) -> i32 {
/// match x {
/// 1 => 10,
/// 2 => 100,
/// 3 => { cold_path(); 1000 }, // this branch is unlikely
/// _ => { cold_path(); 10000 }, // this is also unlikely
/// }
/// }
/// ```
#[unstable(feature = "cold_path", issue = "26179")]
#[inline(always)]
pub const fn cold_path() {
crate::intrinsics::cold_path()
}
11 changes: 7 additions & 4 deletions library/core/src/net/ip_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1539,8 +1539,9 @@ impl Ipv6Addr {
/// // Addresses reserved for benchmarking (`2001:2::/48`)
/// assert_eq!(Ipv6Addr::new(0x2001, 2, 0, 0, 0, 0, 0, 1,).is_global(), false);
///
/// // Addresses reserved for documentation (`2001:db8::/32`)
/// // Addresses reserved for documentation (`2001:db8::/32` and `3fff::/20`)
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1).is_global(), false);
/// assert_eq!(Ipv6Addr::new(0x3fff, 0, 0, 0, 0, 0, 0, 0).is_global(), false);
///
/// // Unique local addresses (`fc00::/7`)
/// assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 1).is_global(), false);
Expand Down Expand Up @@ -1686,11 +1687,12 @@ impl Ipv6Addr {
}

/// Returns [`true`] if this is an address reserved for documentation
/// (`2001:db8::/32`).
/// (`2001:db8::/32` and `3fff::/20`).
///
/// This property is defined in [IETF RFC 3849].
/// This property is defined by [IETF RFC 3849] and [IETF RFC 9637].
///
/// [IETF RFC 3849]: https://tools.ietf.org/html/rfc3849
/// [IETF RFC 9637]: https://tools.ietf.org/html/rfc9637
///
/// # Examples
///
Expand All @@ -1701,12 +1703,13 @@ impl Ipv6Addr {
///
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_documentation(), false);
/// assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_documentation(), true);
/// assert_eq!(Ipv6Addr::new(0x3fff, 0, 0, 0, 0, 0, 0, 0).is_documentation(), true);
/// ```
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_documentation(&self) -> bool {
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8)
matches!(self.segments(), [0x2001, 0xdb8, ..] | [0x3fff, 0..=0x0fff, ..])
}

/// Returns [`true`] if this is an address reserved for benchmarking (`2001:2::/48`).
Expand Down
10 changes: 10 additions & 0 deletions library/core/tests/net/ip_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ fn ip_properties() {
check!("ff08::", global | multicast);
check!("ff0e::", global | multicast);
check!("2001:db8:85a3::8a2e:370:7334", doc);
check!("3fff:fff:ffff:ffff:ffff:ffff:ffff:ffff", doc);
check!("2001:2::ac32:23ff:21", benchmarking);
check!("102:304:506:708:90a:b0c:d0e:f10", global);
}
Expand Down Expand Up @@ -790,6 +791,15 @@ fn ipv6_properties() {
documentation
);

check!(
"3fff:fff:ffff:ffff:ffff:ffff:ffff:ffff",
&[
0x3f, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff
],
documentation
);

check!(
"2001:2::ac32:23ff:21",
&[0x20, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0xac, 0x32, 0x23, 0xff, 0, 0x21],
Expand Down
5 changes: 2 additions & 3 deletions src/tools/miri/tests/fail/intrinsics/copy_overlapping.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![feature(intrinsics)]

// Directly call intrinsic to avoid debug assertions in libstd
extern "rust-intrinsic" {
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
}
#[rustc_intrinsic]
unsafe fn copy_nonoverlapping<T>(_src: *const T, _dst: *mut T, _count: usize);

fn main() {
let mut data = [0u8; 16];
Expand Down
5 changes: 2 additions & 3 deletions src/tools/miri/tests/fail/intrinsics/copy_unaligned.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![feature(intrinsics)]

// Directly call intrinsic to avoid debug assertions in libstd
extern "rust-intrinsic" {
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
}
#[rustc_intrinsic]
unsafe fn copy_nonoverlapping<T>(_src: *const T, _dst: *mut T, _count: usize);

fn main() {
let mut data = [0u16; 8];
Expand Down
5 changes: 2 additions & 3 deletions src/tools/miri/tests/fail/intrinsics/ctlz_nonzero.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![feature(intrinsics)]

mod rusti {
extern "rust-intrinsic" {
pub fn ctlz_nonzero<T>(x: T) -> u32;
}
#[rustc_intrinsic]
pub unsafe fn ctlz_nonzero<T>(_x: T) -> u32;
}

pub fn main() {
Expand Down
Loading

0 comments on commit f3d1d47

Please sign in to comment.