Introduce Purity enum for optimizer
Refactor the optimizer to use a Purity enum instead of a boolean for tracking function purity. This allows for a more granular representation of purity: - `Impure`: Functions with side effects. - `SideEffectFree`: Functions without side effects but may not be deterministic (e.g., `now()`, `random()`). - `Pure`: Functions without side effects and are deterministic. This change enhances the optimizer's ability to perform more aggressive optimizations by accurately determining function purity.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::ast::compiler::optimizer::Purity;
|
||||
use crate::ast::environment::Environment;
|
||||
use crate::ast::types::{Signature, StaticType, Value};
|
||||
use chrono::{NaiveDate, NaiveDateTime};
|
||||
@@ -8,7 +9,7 @@ pub fn register(env: &Environment) {
|
||||
ret: StaticType::DateTime,
|
||||
}));
|
||||
|
||||
env.register_native("date", date_ty, true, |args| {
|
||||
env.register_native("date", date_ty, Purity::Pure, |args| {
|
||||
if let Value::Text(s) = &args[0] {
|
||||
// Try parse YYYY-MM-DD
|
||||
if let Ok(dt) = NaiveDate::parse_from_str(s, "%Y-%m-%d") {
|
||||
|
||||
Reference in New Issue
Block a user