Refactor optimizer with aggressive collapsing
The optimizer has been refactored to separate its phases and introduce more aggressive collapsing capabilities. Phase 2 (Cracking) now focuses on stateless transformations, making it easier to reason about and potentially parallelize. Phase 2.5 (Aggressive Collapsing) has been introduced, enabling optimizations like: - Beta-reduction for lambda literals. - Cracking and inlining for constant closures. - Folding intrinsics for constant arithmetic. - Short-circuiting conditional expressions. These changes aim to improve performance by reducing redundant computations and code bloat. The maximum number of optimization passes has also been increased to 5 to allow for more complex transformations.
This commit is contained in:
+8
-3
@@ -18,12 +18,17 @@ pub struct BenchmarkResult {
|
||||
}
|
||||
|
||||
pub fn run_functional_tests() -> Vec<TestResult> {
|
||||
run_functional_tests_with_level(0)
|
||||
}
|
||||
|
||||
pub fn run_functional_tests_with_level(level: u32) -> Vec<TestResult> {
|
||||
let mut results = Vec::new();
|
||||
let entries = fs::read_dir("examples").unwrap();
|
||||
let output_re = Regex::new(r";; Output: (.*)").unwrap();
|
||||
|
||||
for entry in entries.filter_map(|e| e.ok()) {
|
||||
let env = Environment::new(); // Fresh environment per test file
|
||||
let mut env = Environment::new(); // Fresh environment per test file
|
||||
env.optimization_level = level;
|
||||
let path = entry.path();
|
||||
if path.extension().is_some_and(|ext| ext == "myc") {
|
||||
let content = fs::read_to_string(&path).unwrap();
|
||||
@@ -47,14 +52,14 @@ pub fn run_functional_tests() -> Vec<TestResult> {
|
||||
results.push(TestResult {
|
||||
name,
|
||||
success: false,
|
||||
message: format!("Expected {}, got {}", expected, val_str),
|
||||
message: format!("Level {}: Expected {}, got {}", level, expected, val_str),
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(e) => results.push(TestResult {
|
||||
name,
|
||||
success: false,
|
||||
message: format!("Error: {}", e),
|
||||
message: format!("Level {}: Error: {}", level, e),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user