You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The autodiff procedural macro correctly evaluates logic contained within the macro but cannot handle previously defined logic. Specifically, invoked functions and undefined method_ calls both fail to provide the system with enough information to process the contained logic.
Example
Writing the logic for the sigmoid function within the macro works.
However, invoking a function (or even non-described methods) fails to evaluate correctly since the parsed input fails to store any meaningful information about the function.
use acme::autodiff;use acme::prelude::sigmoid;fnmain(){let(x, y) = (1_f64,2_f64);assert!(autodiff!(x, sigmoid(x)) != 0.1049935854035065);}
Methods
Traditional macro libraries and methods seem to lack explicit support for engaging with these objects. At initial glance, the problem may require using lower-level Rust libraries to interact with the compiler but support for this is also limited.
Extracting the logic from the SourceFile
One approach would be to use the span of the expression to locate the resource and extract the required information.
Option 2: Rewrite the logic as a #[proc_macro_attribute]
#[gradient]pubfnmultiply<A,B,C>(a:A,b:B) -> CwhereA: std::ops::Mul<B,Output = C>{
a * b
}
By writing a #[proc_macro_attribute] any implemented functions could have a gradient function automatically generated. One of the primary issues with this is that we still run into the issue at hand when any external logic is invoked at any point within the function definition.
Option 3: Create an additional generator which rewrites the function as a closure
The text was updated successfully, but these errors were encountered:
FL03
added
enhancement
New feature or request
rust
Improvements or additions that update the Rust code
macro
Any additions or improvements to procedural macros
labels
Feb 18, 2024
The
autodiff
procedural macro correctly evaluates logic contained within the macro but cannot handle previously defined logic. Specifically, invoked functions and undefined method_ calls both fail to provide the system with enough information to process the contained logic.Example
Writing the logic for the sigmoid function within the macro works.
However, invoking a function (or even non-described methods) fails to evaluate correctly since the parsed input fails to store any meaningful information about the function.
Methods
Traditional macro libraries and methods seem to lack explicit support for engaging with these objects. At initial glance, the problem may require using lower-level Rust libraries to interact with the compiler but support for this is also limited.
Extracting the logic from the SourceFile
One approach would be to use the span of the expression to locate the resource and extract the required information.
Option 2: Rewrite the logic as a
#[proc_macro_attribute]
By writing a
#[proc_macro_attribute]
any implemented functions could have a gradient function automatically generated. One of the primary issues with this is that we still run into the issue at hand when any external logic is invoked at any point within the function definition.Option 3: Create an additional generator which rewrites the function as a closure
The text was updated successfully, but these errors were encountered: