Skip to content

Commit 04afbcf

Browse files
authored
Unrolled build for rust-lang#137713
Rollup merge of rust-lang#137713 - vayunbiyani:fix-enzyme-build-errors, r=oli-obk Fix enzyme build errors After [this PR](rust-lang#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`
2 parents 2f58193 + c85f038 commit 04afbcf

File tree

3 files changed

+10
-32
lines changed

3 files changed

+10
-32
lines changed

compiler/rustc_builtin_macros/src/autodiff.rs

+8-26
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! configs (autodiff enabled or disabled), so we have to add cfg's to each import.
44
//! FIXME(ZuseZ4): Remove this once we have a smarter linter.
55
6-
#[cfg(llvm_enzyme)]
76
mod llvm_enzyme {
87
use std::str::FromStr;
98
use std::string::String;
@@ -130,10 +129,14 @@ mod llvm_enzyme {
130129
meta_item: &ast::MetaItem,
131130
mut item: Annotatable,
132131
) -> Vec<Annotatable> {
132+
if cfg!(not(llvm_enzyme)) {
133+
ecx.sess.dcx().emit_err(errors::AutoDiffSupportNotBuild { span: meta_item.span });
134+
return vec![item];
135+
}
133136
let dcx = ecx.sess.dcx();
134137
// first get the annotable item:
135138
let (sig, is_impl): (FnSig, bool) = match &item {
136-
Annotatable::Item(ref iitem) => {
139+
Annotatable::Item(iitem) => {
137140
let sig = match &iitem.kind {
138141
ItemKind::Fn(box ast::Fn { sig, .. }) => sig,
139142
_ => {
@@ -143,7 +146,7 @@ mod llvm_enzyme {
143146
};
144147
(sig.clone(), false)
145148
}
146-
Annotatable::AssocItem(ref assoc_item, _) => {
149+
Annotatable::AssocItem(assoc_item, _) => {
147150
let sig = match &assoc_item.kind {
148151
ast::AssocItemKind::Fn(box ast::Fn { sig, .. }) => sig,
149152
_ => {
@@ -171,8 +174,8 @@ mod llvm_enzyme {
171174
let sig_span = ecx.with_call_site_ctxt(sig.span);
172175

173176
let (vis, primal) = match &item {
174-
Annotatable::Item(ref iitem) => (iitem.vis.clone(), iitem.ident.clone()),
175-
Annotatable::AssocItem(ref assoc_item, _) => {
177+
Annotatable::Item(iitem) => (iitem.vis.clone(), iitem.ident.clone()),
178+
Annotatable::AssocItem(assoc_item, _) => {
176179
(assoc_item.vis.clone(), assoc_item.ident.clone())
177180
}
178181
_ => {
@@ -801,25 +804,4 @@ mod llvm_enzyme {
801804
}
802805
}
803806

804-
#[cfg(not(llvm_enzyme))]
805-
mod ad_fallback {
806-
use rustc_ast::ast;
807-
use rustc_expand::base::{Annotatable, ExtCtxt};
808-
use rustc_span::Span;
809-
810-
use crate::errors;
811-
pub(crate) fn expand(
812-
ecx: &mut ExtCtxt<'_>,
813-
_expand_span: Span,
814-
meta_item: &ast::MetaItem,
815-
item: Annotatable,
816-
) -> Vec<Annotatable> {
817-
ecx.sess.dcx().emit_err(errors::AutoDiffSupportNotBuild { span: meta_item.span });
818-
return vec![item];
819-
}
820-
}
821-
822-
#[cfg(not(llvm_enzyme))]
823-
pub(crate) use ad_fallback::expand;
824-
#[cfg(llvm_enzyme)]
825807
pub(crate) use llvm_enzyme::expand;

compiler/rustc_builtin_macros/src/errors.rs

-4
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,8 @@ pub(crate) struct AllocMustStatics {
144144
pub(crate) span: Span,
145145
}
146146

147-
#[cfg(llvm_enzyme)]
148147
pub(crate) use autodiff::*;
149148

150-
#[cfg(llvm_enzyme)]
151149
mod autodiff {
152150
use super::*;
153151
#[derive(Diagnostic)]
@@ -203,9 +201,7 @@ mod autodiff {
203201
}
204202
}
205203

206-
#[cfg(not(llvm_enzyme))]
207204
pub(crate) use ad_fallback::*;
208-
#[cfg(not(llvm_enzyme))]
209205
mod ad_fallback {
210206
use super::*;
211207
#[derive(Diagnostic)]

compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ pub use self::Enzyme_AD::*;
4242
#[cfg(llvm_enzyme)]
4343
pub mod Enzyme_AD {
4444
use libc::c_void;
45-
extern "C" {
45+
unsafe extern "C" {
4646
pub fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8);
4747
}
48-
extern "C" {
48+
unsafe extern "C" {
4949
static mut EnzymePrintPerf: c_void;
5050
static mut EnzymePrintActivity: c_void;
5151
static mut EnzymePrintType: c_void;

0 commit comments

Comments
 (0)