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:
+7
-5
@@ -95,12 +95,13 @@ impl CompilerApp {
|
||||
|
||||
// Reset environment for a fresh run
|
||||
self.env = Environment::new();
|
||||
self.env.optimization_level = 2;
|
||||
|
||||
let res = (|| -> Result<(myc::ast::types::Value, std::time::Duration), String> {
|
||||
let start_run = std::time::Instant::now();
|
||||
let result = if self.debug_enabled {
|
||||
let (res, logs) = self.env.run_debug(&self.source_code)?;
|
||||
|
||||
|
||||
// Batch-truncate logs for GUI performance
|
||||
let mut display_logs = logs;
|
||||
if display_logs.len() > 1000 {
|
||||
@@ -110,9 +111,10 @@ impl CompilerApp {
|
||||
|
||||
for line in &mut display_logs {
|
||||
if line.len() > 255
|
||||
&& let Some((idx, _)) = line.char_indices().nth(255) {
|
||||
line.truncate(idx);
|
||||
line.push_str("...");
|
||||
&& let Some((idx, _)) = line.char_indices().nth(255)
|
||||
{
|
||||
line.truncate(idx);
|
||||
line.push_str("...");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +133,7 @@ impl CompilerApp {
|
||||
Ok((val, d_run)) => {
|
||||
let d_total = start_total.elapsed();
|
||||
let now = chrono::Local::now().format("%H:%M:%S").to_string();
|
||||
|
||||
|
||||
let mut stats = format!(
|
||||
"Execution Successful.\nResult: {}\n\nTotal Duration: {:?}\nFinished at: {}",
|
||||
val, d_total, now,
|
||||
|
||||
Reference in New Issue
Block a user