Skip to main content

luaur_compiler/functions/
undo_changes_constant_folding.rs

1use crate::records::constant::Constant;
2use crate::type_aliases::expr_constant_change_log::ExprConstantChangeLog;
3use luaur_ast::records::ast_expr::AstExpr;
4use luaur_common::records::dense_hash_map::DenseHashMap;
5
6pub fn undo_changes_dense_hash_map_ast_expr_constant_expr_constant_change_log(
7    constants: &mut DenseHashMap<*mut AstExpr, Constant>,
8    changes: &ExprConstantChangeLog,
9) {
10    for it in changes.iter().rev() {
11        if it.was_absent {
12            if let Some(old) = constants.find_mut(&it.key) {
13                old.r#type = crate::enums::type_constant_folding::Type::Type_Unknown;
14            }
15        } else {
16            let old = it.old_value;
17            *constants.get_or_insert(it.key) = old;
18        }
19    }
20}