Skip to main content

optimize

Attribute Macro optimize 

Source
#[optimize]
Expand description

#[preprocessor::optimize] — Function-level attribute macro for compile-time optimization.

Recursively traverses all statements and expressions in the function body, identifies sub-expressions that can be evaluated at compile time, and rewrites them as pre-computed literals.

§Example

#[preprocessor::optimize]
fn compute() -> i32 {
    let x = 1 + 2;  // → let x = 3;
    let y = x * 10; // kept as-is (depends on local variable)
    y
}