Skip to content

Rollup of 5 pull requests #143006

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 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ fn thin_lto(
}

fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
for &val in ad {
for val in ad {
// We intentionally don't use a wildcard, to not forget handling anything new.
match val {
config::AutoDiff::PrintPerf => {
Expand All @@ -599,6 +599,10 @@ fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
config::AutoDiff::PrintTA => {
llvm::set_print_type(true);
}
config::AutoDiff::PrintTAFn(fun) => {
llvm::set_print_type(true); // Enable general type printing
llvm::set_print_type_fun(&fun); // Set specific function to analyze
}
config::AutoDiff::Inline => {
llvm::set_inline(true);
}
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,19 @@ pub(crate) use self::Enzyme_AD::*;

#[cfg(llvm_enzyme)]
pub(crate) mod Enzyme_AD {
use std::ffi::{CString, c_char};

use libc::c_void;

unsafe extern "C" {
pub(crate) fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8);
pub(crate) fn EnzymeSetCLString(arg1: *mut ::std::os::raw::c_void, arg2: *const c_char);
}
unsafe extern "C" {
static mut EnzymePrintPerf: c_void;
static mut EnzymePrintActivity: c_void;
static mut EnzymePrintType: c_void;
static mut EnzymeFunctionToAnalyze: c_void;
static mut EnzymePrint: c_void;
static mut EnzymeStrictAliasing: c_void;
static mut looseTypeAnalysis: c_void;
Expand All @@ -86,6 +91,15 @@ pub(crate) mod Enzyme_AD {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintType), print as u8);
}
}
pub(crate) fn set_print_type_fun(fun_name: &str) {
let c_fun_name = CString::new(fun_name).unwrap();
unsafe {
EnzymeSetCLString(
std::ptr::addr_of_mut!(EnzymeFunctionToAnalyze),
c_fun_name.as_ptr() as *const c_char,
);
}
}
pub(crate) fn set_print(print: bool) {
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrint), print as u8);
Expand Down Expand Up @@ -132,6 +146,9 @@ pub(crate) mod Fallback_AD {
pub(crate) fn set_print_type(print: bool) {
unimplemented!()
}
pub(crate) fn set_print_type_fun(fun_name: &str) {
unimplemented!()
}
pub(crate) fn set_print(print: bool) {
unimplemented!()
}
Expand Down
15 changes: 14 additions & 1 deletion compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
use rustc_infer::infer::relate::RelateResult;
use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult};
use rustc_infer::traits::{
IfExpressionCause, MatchExpressionArmCause, Obligation, PredicateObligation,
IfExpressionCause, ImplSource, MatchExpressionArmCause, Obligation, PredicateObligation,
PredicateObligations, SelectionError,
};
use rustc_middle::span_bug;
Expand Down Expand Up @@ -704,6 +704,19 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// be silent, as it causes a type mismatch later.
}

Ok(Some(ImplSource::UserDefined(impl_source))) => {
queue.extend(impl_source.nested);
// Certain incoherent `CoerceUnsized` implementations may cause ICEs,
// so check the impl's validity. Taint the body so that we don't try
// to evaluate these invalid coercions in CTFE. We only need to do this
// for local impls, since upstream impls should be valid.
if impl_source.impl_def_id.is_local()
&& let Err(guar) =
self.tcx.ensure_ok().coerce_unsized_info(impl_source.impl_def_id)
{
self.fcx.set_tainted_by_errors(guar);
}
}
Ok(Some(impl_source)) => queue.extend(impl_source.nested_obligations()),
}
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,15 @@ pub enum CoverageLevel {
}

/// The different settings that the `-Z autodiff` flag can have.
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
#[derive(Clone, PartialEq, Hash, Debug)]
pub enum AutoDiff {
/// Enable the autodiff opt pipeline
Enable,

/// Print TypeAnalysis information
PrintTA,
/// Print TypeAnalysis information for a specific function
PrintTAFn(String),
/// Print ActivityAnalysis Information
PrintAA,
/// Print Performance Warnings from Enzyme
Expand Down
17 changes: 15 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ mod desc {
pub(crate) const parse_list: &str = "a space-separated list of strings";
pub(crate) const parse_list_with_polarity: &str =
"a comma-separated list of strings, with elements beginning with + or -";
pub(crate) const parse_autodiff: &str = "a comma separated list of settings: `Enable`, `PrintSteps`, `PrintTA`, `PrintAA`, `PrintPerf`, `PrintModBefore`, `PrintModAfter`, `PrintModFinal`, `PrintPasses`, `NoPostopt`, `LooseTypes`, `Inline`";
pub(crate) const parse_autodiff: &str = "a comma separated list of settings: `Enable`, `PrintSteps`, `PrintTA`, `PrintTAFn`, `PrintAA`, `PrintPerf`, `PrintModBefore`, `PrintModAfter`, `PrintModFinal`, `PrintPasses`, `NoPostopt`, `LooseTypes`, `Inline`";
pub(crate) const parse_comma_list: &str = "a comma-separated list of strings";
pub(crate) const parse_opt_comma_list: &str = parse_comma_list;
pub(crate) const parse_number: &str = "a number";
Expand Down Expand Up @@ -1365,9 +1365,22 @@ pub mod parse {
let mut v: Vec<&str> = v.split(",").collect();
v.sort_unstable();
for &val in v.iter() {
let variant = match val {
// Split each entry on '=' if it has an argument
let (key, arg) = match val.split_once('=') {
Some((k, a)) => (k, Some(a)),
None => (val, None),
};

let variant = match key {
"Enable" => AutoDiff::Enable,
"PrintTA" => AutoDiff::PrintTA,
"PrintTAFn" => {
if let Some(fun) = arg {
AutoDiff::PrintTAFn(fun.to_string())
} else {
return false;
}
}
"PrintAA" => AutoDiff::PrintAA,
"PrintPerf" => AutoDiff::PrintPerf,
"PrintSteps" => AutoDiff::PrintSteps,
Expand Down
24 changes: 19 additions & 5 deletions library/core/src/ops/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,14 @@ add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128
/// ```
#[lang = "sub"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
#[rustc_on_unimplemented(
message = "cannot subtract `{Rhs}` from `{Self}`",
label = "no implementation for `{Self} - {Rhs}`",
append_const_msg
)]
#[doc(alias = "-")]
#[const_trait]
pub trait Sub<Rhs = Self> {
/// The resulting type after applying the `-` operator.
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -206,7 +208,8 @@ pub trait Sub<Rhs = Self> {
macro_rules! sub_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
impl Sub for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Sub for $t {
type Output = $t;

#[inline]
Expand Down Expand Up @@ -310,11 +313,13 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128
/// ```
#[lang = "mul"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
#[diagnostic::on_unimplemented(
message = "cannot multiply `{Self}` by `{Rhs}`",
label = "no implementation for `{Self} * {Rhs}`"
)]
#[doc(alias = "*")]
#[const_trait]
pub trait Mul<Rhs = Self> {
/// The resulting type after applying the `*` operator.
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -336,7 +341,8 @@ pub trait Mul<Rhs = Self> {
macro_rules! mul_impl {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
impl Mul for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Mul for $t {
type Output = $t;

#[inline]
Expand Down Expand Up @@ -444,11 +450,13 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128
/// ```
#[lang = "div"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
#[diagnostic::on_unimplemented(
message = "cannot divide `{Self}` by `{Rhs}`",
label = "no implementation for `{Self} / {Rhs}`"
)]
#[doc(alias = "/")]
#[const_trait]
pub trait Div<Rhs = Self> {
/// The resulting type after applying the `/` operator.
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -476,7 +484,8 @@ macro_rules! div_impl_integer {
///
#[doc = $panic]
#[stable(feature = "rust1", since = "1.0.0")]
impl Div for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Div for $t {
type Output = $t;

#[inline]
Expand All @@ -496,7 +505,8 @@ div_impl_integer! {
macro_rules! div_impl_float {
($($t:ty)*) => ($(
#[stable(feature = "rust1", since = "1.0.0")]
impl Div for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Div for $t {
type Output = $t;

#[inline]
Expand Down Expand Up @@ -546,11 +556,13 @@ div_impl_float! { f16 f32 f64 f128 }
/// ```
#[lang = "rem"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
#[diagnostic::on_unimplemented(
message = "cannot calculate the remainder of `{Self}` divided by `{Rhs}`",
label = "no implementation for `{Self} % {Rhs}`"
)]
#[doc(alias = "%")]
#[const_trait]
pub trait Rem<Rhs = Self> {
/// The resulting type after applying the `%` operator.
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -578,7 +590,8 @@ macro_rules! rem_impl_integer {
///
#[doc = $panic]
#[stable(feature = "rust1", since = "1.0.0")]
impl Rem for $t {
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Rem for $t {
type Output = $t;

#[inline]
Expand Down Expand Up @@ -613,6 +626,7 @@ macro_rules! rem_impl_float {
/// assert_eq!(x % y, remainder);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl Rem for $t {
type Output = $t;

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn rustup_installed(builder: &Builder<'_>) -> bool {
let mut rustup = command("rustup");
rustup.arg("--version");

rustup.allow_failure().run_always().run_capture_stdout(builder).is_success()
rustup.allow_failure().run_in_dry_run().run_capture_stdout(builder).is_success()
}

fn stage_dir_exists(stage_path: &str) -> bool {
Expand Down
14 changes: 7 additions & 7 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ impl Config {
config.initial_sysroot = t!(PathBuf::from_str(
command(&config.initial_rustc)
.args(["--print", "sysroot"])
.run_always()
.run_in_dry_run()
.run_capture_stdout(&config)
.stdout()
.trim()
Expand Down Expand Up @@ -1385,11 +1385,11 @@ impl Config {
// all the git commands below are actually executed, because some follow-up code
// in bootstrap might depend on the submodules being checked out. Furthermore, not all
// the command executions below work with an empty output (produced during dry run).
// Therefore, all commands below are marked with `run_always()`, so that they also run in
// Therefore, all commands below are marked with `run_in_dry_run()`, so that they also run in
// dry run mode.
let submodule_git = || {
let mut cmd = helpers::git(Some(&absolute_path));
cmd.run_always();
cmd.run_in_dry_run();
cmd
};

Expand All @@ -1399,7 +1399,7 @@ impl Config {
let checked_out_hash = checked_out_hash.trim_end();
// Determine commit that the submodule *should* have.
let recorded = helpers::git(Some(&self.src))
.run_always()
.run_in_dry_run()
.args(["ls-tree", "HEAD"])
.arg(relative_path)
.run_capture_stdout(self)
Expand All @@ -1419,7 +1419,7 @@ impl Config {

helpers::git(Some(&self.src))
.allow_failure()
.run_always()
.run_in_dry_run()
.args(["submodule", "-q", "sync"])
.arg(relative_path)
.run(self);
Expand All @@ -1430,12 +1430,12 @@ impl Config {
// even though that has no relation to the upstream for the submodule.
let current_branch = helpers::git(Some(&self.src))
.allow_failure()
.run_always()
.run_in_dry_run()
.args(["symbolic-ref", "--short", "HEAD"])
.run_capture(self);

let mut git = helpers::git(Some(&self.src)).allow_failure();
git.run_always();
git.run_in_dry_run();
if current_branch.is_success() {
// If there is a tag named after the current branch, git will try to disambiguate by prepending `heads/` to the branch name.
// This syntax isn't accepted by `branch.{branch}`. Strip it.
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn workspace_members(build: &Build) -> Vec<Package> {
.arg("--no-deps")
.arg("--manifest-path")
.arg(build.src.join(manifest_path));
let metadata_output = cargo.run_always().run_capture_stdout(build).stdout();
let metadata_output = cargo.run_in_dry_run().run_capture_stdout(build).stdout();
let Output { packages, .. } = t!(serde_json::from_str(&metadata_output));
packages
};
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ than building it.

let stage0_supported_target_list: HashSet<String> = command(&build.config.initial_rustc)
.args(["--print", "target-list"])
.run_always()
.run_in_dry_run()
.run_capture_stdout(&build)
.stdout()
.lines()
Expand Down Expand Up @@ -366,7 +366,7 @@ than building it.
// Cygwin. The Cygwin build does not have generators for Visual
// Studio, so detect that here and error.
let out =
command("cmake").arg("--help").run_always().run_capture_stdout(&build).stdout();
command("cmake").arg("--help").run_in_dry_run().run_capture_stdout(&build).stdout();
if !out.contains("Visual Studio") {
panic!(
"
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl Build {
let in_tree_gcc_info = config.in_tree_gcc_info.clone();

let initial_target_libdir = command(&config.initial_rustc)
.run_always()
.run_in_dry_run()
.args(["--print", "target-libdir"])
.run_capture_stdout(&config)
.stdout()
Expand Down Expand Up @@ -490,7 +490,7 @@ impl Build {
// If local-rust is the same major.minor as the current version, then force a
// local-rebuild
let local_version_verbose = command(&build.initial_rustc)
.run_always()
.run_in_dry_run()
.args(["--version", "--verbose"])
.run_capture_stdout(&build)
.stdout();
Expand Down Expand Up @@ -949,7 +949,7 @@ impl Build {
static SYSROOT_CACHE: OnceLock<PathBuf> = OnceLock::new();
SYSROOT_CACHE.get_or_init(|| {
command(&self.initial_rustc)
.run_always()
.run_in_dry_run()
.args(["--print", "sysroot"])
.run_capture_stdout(self)
.stdout()
Expand Down Expand Up @@ -1512,7 +1512,7 @@ impl Build {
"refs/remotes/origin/{}..HEAD",
self.config.stage0_metadata.config.nightly_branch
))
.run_always()
.run_in_dry_run()
.run_capture(self)
.stdout()
});
Expand Down
Loading
Loading