fix: suppress optimization in REPL

This commit is contained in:
Shunsuke Shibayama 2023-06-26 00:41:39 +09:00
parent 1832bed6ec
commit ae9648b289
2 changed files with 15 additions and 6 deletions

View file

@ -1,16 +1,25 @@
use erg_common::config::ErgConfig;
use crate::effectcheck::SideEffectChecker;
use crate::hir::*;
use crate::module::SharedCompilerResource;
// use crate::erg_common::traits::Stream;
/// Optimizes a `HIR`.
/// This should not be used in the context of sequential execution (e.g. REPL), since it assumes that the given code is all there is.
/// The optimizer determines the optimization level using `opt_level` in `cfg: ErgConfig`.
#[derive(Debug)]
pub struct HIROptimizer {
cfg: ErgConfig,
shared: SharedCompilerResource,
}
impl HIROptimizer {
pub fn optimize(shared: SharedCompilerResource, hir: HIR) -> HIR {
let mut optimizer = HIROptimizer { shared };
pub fn optimize(cfg: ErgConfig, shared: SharedCompilerResource, hir: HIR) -> HIR {
let mut optimizer = HIROptimizer { cfg, shared };
if optimizer.cfg.opt_level == 0 || optimizer.cfg.input.is_repl() {
return hir;
}
optimizer.eliminate_dead_code(hir)
}