Skip to content

Commit dcb11c4

Browse files
authored
Rollup merge of rust-lang#140697 - Sa4dUs:split-autodiff, r=ZuseZ4
Split `autodiff` into `autodiff_forward` and `autodiff_reverse` This PR splits `#[autodiff]` macro so `#[autodiff(df, Reverse, args)]` would become `#[autodiff_reverse(df, args)]` and `#[autodiff(df, Forward, args)]` would become `#[autodiff_forwad(df, args)]`.
2 parents 0f9ab19 + 556facc commit dcb11c4

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

core/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,11 @@ pub mod assert_matches {
225225

226226
// We don't export this through #[macro_export] for now, to avoid breakage.
227227
#[unstable(feature = "autodiff", issue = "124509")]
228+
#[cfg(not(bootstrap))]
228229
/// Unstable module containing the unstable `autodiff` macro.
229230
pub mod autodiff {
230231
#[unstable(feature = "autodiff", issue = "124509")]
231-
pub use crate::macros::builtin::autodiff;
232+
pub use crate::macros::builtin::{autodiff_forward, autodiff_reverse};
232233
}
233234

234235
#[unstable(feature = "contracts", issue = "128044")]

core/src/macros/mod.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,20 +1519,41 @@ pub(crate) mod builtin {
15191519
($file:expr $(,)?) => {{ /* compiler built-in */ }};
15201520
}
15211521

1522-
/// Automatic Differentiation macro which allows generating a new function to compute
1523-
/// the derivative of a given function. It may only be applied to a function.
1524-
/// The expected usage syntax is
1525-
/// `#[autodiff(NAME, MODE, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
1526-
/// where:
1527-
/// NAME is a string that represents a valid function name.
1528-
/// MODE is any of Forward, Reverse, ForwardFirst, ReverseFirst.
1529-
/// INPUT_ACTIVITIES consists of one valid activity for each input parameter.
1530-
/// OUTPUT_ACTIVITY must not be set if we implicitly return nothing (or explicitly return
1531-
/// `-> ()`). Otherwise it must be set to one of the allowed activities.
1522+
/// This macro uses forward-mode automatic differentiation to generate a new function.
1523+
/// It may only be applied to a function. The new function will compute the derivative
1524+
/// of the function to which the macro was applied.
1525+
///
1526+
/// The expected usage syntax is:
1527+
/// `#[autodiff_forward(NAME, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
1528+
///
1529+
/// - `NAME`: A string that represents a valid function name.
1530+
/// - `INPUT_ACTIVITIES`: Specifies one valid activity for each input parameter.
1531+
/// - `OUTPUT_ACTIVITY`: Must not be set if the function implicitly returns nothing
1532+
/// (or explicitly returns `-> ()`). Otherwise, it must be set to one of the allowed activities.
1533+
#[unstable(feature = "autodiff", issue = "124509")]
1534+
#[allow_internal_unstable(rustc_attrs)]
1535+
#[rustc_builtin_macro]
1536+
#[cfg(not(bootstrap))]
1537+
pub macro autodiff_forward($item:item) {
1538+
/* compiler built-in */
1539+
}
1540+
1541+
/// This macro uses reverse-mode automatic differentiation to generate a new function.
1542+
/// It may only be applied to a function. The new function will compute the derivative
1543+
/// of the function to which the macro was applied.
1544+
///
1545+
/// The expected usage syntax is:
1546+
/// `#[autodiff_reverse(NAME, INPUT_ACTIVITIES, OUTPUT_ACTIVITY)]`
1547+
///
1548+
/// - `NAME`: A string that represents a valid function name.
1549+
/// - `INPUT_ACTIVITIES`: Specifies one valid activity for each input parameter.
1550+
/// - `OUTPUT_ACTIVITY`: Must not be set if the function implicitly returns nothing
1551+
/// (or explicitly returns `-> ()`). Otherwise, it must be set to one of the allowed activities.
15321552
#[unstable(feature = "autodiff", issue = "124509")]
15331553
#[allow_internal_unstable(rustc_attrs)]
15341554
#[rustc_builtin_macro]
1535-
pub macro autodiff($item:item) {
1555+
#[cfg(not(bootstrap))]
1556+
pub macro autodiff_reverse($item:item) {
15361557
/* compiler built-in */
15371558
}
15381559

std/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@
276276
// tidy-alphabetical-start
277277

278278
// stabilization was reverted after it hit beta
279+
#![cfg_attr(not(bootstrap), feature(autodiff))]
279280
#![feature(alloc_error_handler)]
280281
#![feature(allocator_internals)]
281282
#![feature(allow_internal_unsafe)]
282283
#![feature(allow_internal_unstable)]
283284
#![feature(asm_experimental_arch)]
284-
#![feature(autodiff)]
285285
#![feature(cfg_sanitizer_cfi)]
286286
#![feature(cfg_target_thread_local)]
287287
#![feature(cfi_encoding)]
@@ -636,12 +636,15 @@ pub mod simd {
636636
#[doc(inline)]
637637
pub use crate::std_float::StdFloat;
638638
}
639+
639640
#[unstable(feature = "autodiff", issue = "124509")]
641+
#[cfg(not(bootstrap))]
640642
/// This module provides support for automatic differentiation.
641643
pub mod autodiff {
642644
/// This macro handles automatic differentiation.
643-
pub use core::autodiff::autodiff;
645+
pub use core::autodiff::{autodiff_forward, autodiff_reverse};
644646
}
647+
645648
#[stable(feature = "futures_api", since = "1.36.0")]
646649
pub mod task {
647650
//! Types and Traits for working with asynchronous tasks.

0 commit comments

Comments
 (0)