Rollup merge of #137713 - vayunbiyani:fix-enzyme-build-errors, r=oli-obk
Fix enzyme build errors After [this PR](https://github.com/rust-lang/rust/pull/136428) was merged, I switched to master and attempted building `./x.py build --stage 1 library` with the config mentioned in the enzyme rustbook but it resulted in some errors tho the config.example.toml build succeeded The errors were re: ### 1. Use of ref in match patterns The errors were related to match ergonomics in Rust 2024, where ref is no longer needed when matching on references. Examples: ``` error: binding modifiers may only be written when the default binding mode is `move` --> compiler/rustc_builtin_macros/src/autodiff.rs:136:31 | 136 | Annotatable::Item(ref iitem) => { | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html> note: matching on a reference type with a non-reference pattern changes the default binding mode --> compiler/rustc_builtin_macros/src/autodiff.rs:136:13 | 136 | Annotatable::Item(ref iitem) => { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_` help: remove the unnecessary binding modifier | 136 - Annotatable::Item(ref iitem) => { 136 + Annotatable::Item(iitem) => { | error: binding modifiers may only be written when the default binding mode is `move` --> compiler/rustc_builtin_macros/src/autodiff.rs:146:36 | 146 | Annotatable::AssocItem(ref assoc_item, _) => { | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html> note: matching on a reference type with a non-reference pattern changes the default binding mode --> compiler/rustc_builtin_macros/src/autodiff.rs:146:13 | 146 | Annotatable::AssocItem(ref assoc_item, _) => { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_` help: remove the unnecessary binding modifier | 146 - Annotatable::AssocItem(ref assoc_item, _) => { 146 + Annotatable::AssocItem(assoc_item, _) => { | error: binding modifiers may only be written when the default binding mode is `move` --> compiler/rustc_builtin_macros/src/autodiff.rs:174:31 | 174 | ... Annotatable::Item(ref iitem) => (iitem.vis.clone(), iitem.ide... | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html> note: matching on a reference type with a non-reference pattern changes the default binding mode --> compiler/rustc_builtin_macros/src/autodiff.rs:174:13 | 174 | ... Annotatable::Item(ref iitem) => (iitem.vis.clone(), iitem.ident.c... | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_` help: remove the unnecessary binding modifier | 174 - Annotatable::Item(ref iitem) => (iitem.vis.clone(), iitem.ident.clone()), 174 + Annotatable::Item(iitem) => (iitem.vis.clone(), iitem.ident.clone()), | error: binding modifiers may only be written when the default binding mode is `move` --> compiler/rustc_builtin_macros/src/autodiff.rs:175:36 | 175 | Annotatable::AssocItem(ref assoc_item, _) => { | ^^^ binding modifier not allowed under `ref` default binding mode | = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html> note: matching on a reference type with a non-reference pattern changes the default binding mode --> compiler/rustc_builtin_macros/src/autodiff.rs:175:13 | 175 | Annotatable::AssocItem(ref assoc_item, _) => { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this matches on type `&_` help: remove the unnecessary binding modifier | 175 - Annotatable::AssocItem(ref assoc_item, _) => { 175 + Annotatable::AssocItem(assoc_item, _) => { | error: could not compile `rustc_builtin_macros` (lib) due to 4 previous errors warning: build failed, waiting for other jobs to finish... Build completed unsuccessfully in 0:19:39 ``` ### 2. the use of external C blocks without unsafe in compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs (I don't have the error message handy) The first commit fixes the errors above --- ## Additional Improvement: `@ZuseZ4` suggested we consolidate the variants under `#[cfg(llvm_enzyme)]` and `#[cfg(not(llvm_enzyme))]` by conditionally checking for `cfg!(llvm_enzyme)` instead. This way, the autodiff code is compiled but not executed avoiding such regressions r? `@ZuseZ4` cc: `@oli-obk`
This commit is contained in:
commit
d65f568302
3 changed files with 10 additions and 32 deletions
|
@ -3,7 +3,6 @@
|
||||||
//! configs (autodiff enabled or disabled), so we have to add cfg's to each import.
|
//! configs (autodiff enabled or disabled), so we have to add cfg's to each import.
|
||||||
//! FIXME(ZuseZ4): Remove this once we have a smarter linter.
|
//! FIXME(ZuseZ4): Remove this once we have a smarter linter.
|
||||||
|
|
||||||
#[cfg(llvm_enzyme)]
|
|
||||||
mod llvm_enzyme {
|
mod llvm_enzyme {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
|
@ -130,10 +129,14 @@ mod llvm_enzyme {
|
||||||
meta_item: &ast::MetaItem,
|
meta_item: &ast::MetaItem,
|
||||||
mut item: Annotatable,
|
mut item: Annotatable,
|
||||||
) -> Vec<Annotatable> {
|
) -> Vec<Annotatable> {
|
||||||
|
if cfg!(not(llvm_enzyme)) {
|
||||||
|
ecx.sess.dcx().emit_err(errors::AutoDiffSupportNotBuild { span: meta_item.span });
|
||||||
|
return vec![item];
|
||||||
|
}
|
||||||
let dcx = ecx.sess.dcx();
|
let dcx = ecx.sess.dcx();
|
||||||
// first get the annotable item:
|
// first get the annotable item:
|
||||||
let (sig, is_impl): (FnSig, bool) = match &item {
|
let (sig, is_impl): (FnSig, bool) = match &item {
|
||||||
Annotatable::Item(ref iitem) => {
|
Annotatable::Item(iitem) => {
|
||||||
let sig = match &iitem.kind {
|
let sig = match &iitem.kind {
|
||||||
ItemKind::Fn(box ast::Fn { sig, .. }) => sig,
|
ItemKind::Fn(box ast::Fn { sig, .. }) => sig,
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -143,7 +146,7 @@ mod llvm_enzyme {
|
||||||
};
|
};
|
||||||
(sig.clone(), false)
|
(sig.clone(), false)
|
||||||
}
|
}
|
||||||
Annotatable::AssocItem(ref assoc_item, _) => {
|
Annotatable::AssocItem(assoc_item, _) => {
|
||||||
let sig = match &assoc_item.kind {
|
let sig = match &assoc_item.kind {
|
||||||
ast::AssocItemKind::Fn(box ast::Fn { sig, .. }) => sig,
|
ast::AssocItemKind::Fn(box ast::Fn { sig, .. }) => sig,
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -171,8 +174,8 @@ mod llvm_enzyme {
|
||||||
let sig_span = ecx.with_call_site_ctxt(sig.span);
|
let sig_span = ecx.with_call_site_ctxt(sig.span);
|
||||||
|
|
||||||
let (vis, primal) = match &item {
|
let (vis, primal) = match &item {
|
||||||
Annotatable::Item(ref iitem) => (iitem.vis.clone(), iitem.ident.clone()),
|
Annotatable::Item(iitem) => (iitem.vis.clone(), iitem.ident.clone()),
|
||||||
Annotatable::AssocItem(ref assoc_item, _) => {
|
Annotatable::AssocItem(assoc_item, _) => {
|
||||||
(assoc_item.vis.clone(), assoc_item.ident.clone())
|
(assoc_item.vis.clone(), assoc_item.ident.clone())
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -801,25 +804,4 @@ mod llvm_enzyme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(llvm_enzyme))]
|
|
||||||
mod ad_fallback {
|
|
||||||
use rustc_ast::ast;
|
|
||||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
|
||||||
use rustc_span::Span;
|
|
||||||
|
|
||||||
use crate::errors;
|
|
||||||
pub(crate) fn expand(
|
|
||||||
ecx: &mut ExtCtxt<'_>,
|
|
||||||
_expand_span: Span,
|
|
||||||
meta_item: &ast::MetaItem,
|
|
||||||
item: Annotatable,
|
|
||||||
) -> Vec<Annotatable> {
|
|
||||||
ecx.sess.dcx().emit_err(errors::AutoDiffSupportNotBuild { span: meta_item.span });
|
|
||||||
return vec![item];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(llvm_enzyme))]
|
|
||||||
pub(crate) use ad_fallback::expand;
|
|
||||||
#[cfg(llvm_enzyme)]
|
|
||||||
pub(crate) use llvm_enzyme::expand;
|
pub(crate) use llvm_enzyme::expand;
|
||||||
|
|
|
@ -144,10 +144,8 @@ pub(crate) struct AllocMustStatics {
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(llvm_enzyme)]
|
|
||||||
pub(crate) use autodiff::*;
|
pub(crate) use autodiff::*;
|
||||||
|
|
||||||
#[cfg(llvm_enzyme)]
|
|
||||||
mod autodiff {
|
mod autodiff {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -203,9 +201,7 @@ mod autodiff {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(llvm_enzyme))]
|
|
||||||
pub(crate) use ad_fallback::*;
|
pub(crate) use ad_fallback::*;
|
||||||
#[cfg(not(llvm_enzyme))]
|
|
||||||
mod ad_fallback {
|
mod ad_fallback {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
|
|
@ -42,10 +42,10 @@ pub use self::Enzyme_AD::*;
|
||||||
#[cfg(llvm_enzyme)]
|
#[cfg(llvm_enzyme)]
|
||||||
pub mod Enzyme_AD {
|
pub mod Enzyme_AD {
|
||||||
use libc::c_void;
|
use libc::c_void;
|
||||||
extern "C" {
|
unsafe extern "C" {
|
||||||
pub fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8);
|
pub fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8);
|
||||||
}
|
}
|
||||||
extern "C" {
|
unsafe extern "C" {
|
||||||
static mut EnzymePrintPerf: c_void;
|
static mut EnzymePrintPerf: c_void;
|
||||||
static mut EnzymePrintActivity: c_void;
|
static mut EnzymePrintActivity: c_void;
|
||||||
static mut EnzymePrintType: c_void;
|
static mut EnzymePrintType: c_void;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue