diff --git a/crates/forge_analyzer/src/definitions.rs b/crates/forge_analyzer/src/definitions.rs index f21d7eb..e2e3b53 100644 --- a/crates/forge_analyzer/src/definitions.rs +++ b/crates/forge_analyzer/src/definitions.rs @@ -1,13 +1,10 @@ #![allow(dead_code, unused)] -use std::hash::Hash; use std::{borrow::Borrow, fmt, mem}; use crate::utils::{calls_method, eq_prop_name}; use forge_file_resolver::{FileResolver, ForgeResolver}; use forge_utils::{create_newtype, FxHashMap}; -use std::collections::{HashMap, HashSet}; -use swc_core::common::pass::define; use itertools::Itertools; use serde::{Deserialize, Serialize}; @@ -187,6 +184,7 @@ pub fn run_resolver( module.visit_with(&mut import_collector); } + // check for required after Definitions pass // This loop runs through the different import modules and corresponding definitions. let defs = Definitions::new( environment @@ -230,61 +228,8 @@ pub fn run_resolver( }; module.visit_with(&mut collector); } - environment -} -// This function is a helper function to run_resolver() 's SSA Form Loop. -// Input: rvalue and hashmap of VarIds that have been updated in the SSA Form Loop. -// Output: new rvalue that has the newest VarId in its operands. -pub fn update_rvalue(rvalue: &Rvalue, updated_vars: &HashMap) -> Rvalue { - let mut new_rvalue = rvalue.clone(); - match rvalue { - Rvalue::Unary(unop, Operand::Var(variable)) => { - let op_var_id = variable.as_var_id().unwrap(); - if updated_vars.contains_key(&op_var_id) { - let updated_var_id = *updated_vars.get(&op_var_id).unwrap(); - let new_operand = Operand::Var(Variable::new(updated_var_id)); - new_rvalue = Rvalue::Unary(*unop, new_operand); - } - } - Rvalue::Bin(binop, operand1, operand2) => { - let mut new_operand_1 = operand1.clone(); - let mut new_operand_2 = operand2.clone(); - if let Operand::Var(variable) = operand1 { - let op_var_id = variable.as_var_id().unwrap(); - if updated_vars.contains_key(&op_var_id) { - let updated_var_id = *updated_vars.get(&op_var_id).unwrap(); - new_operand_1 = Operand::Var(Variable::new(updated_var_id)); - } - } - if let Operand::Var(variable) = operand2 { - let op_var_id = variable.as_var_id().unwrap(); - if updated_vars.contains_key(&op_var_id) { - let updated_var_id = *updated_vars.get(&op_var_id).unwrap(); - new_operand_2 = Operand::Var(Variable::new(updated_var_id)); - } - } - new_rvalue = Rvalue::Bin(*binop, new_operand_1, new_operand_2); - } - Rvalue::Read(Operand::Var(variable)) => { - let op_var_id = variable.as_var_id().unwrap(); - if updated_vars.contains_key(&op_var_id) { - let updated_var_id = *updated_vars.get(&op_var_id).unwrap(); - let new_operand = Operand::Var(Variable::new(updated_var_id)); - new_rvalue = Rvalue::Read(new_operand); - } - } - Rvalue::Call(Operand::Var(variable), vector) => { - let op_var_id = variable.as_var_id().unwrap(); - if updated_vars.contains_key(&op_var_id) { - let updated_var_id = *updated_vars.get(&op_var_id).unwrap(); - let new_operand = Operand::Var(Variable::new(updated_var_id)); - new_rvalue = Rvalue::Call(new_operand, vector.clone()); - } - } - _ => {} - } - new_rvalue + environment } /// this struct is a bit of a hack, because we also use it for diff --git a/crates/forge_analyzer/src/interp.rs b/crates/forge_analyzer/src/interp.rs index a3602b1..f5cd8c1 100644 --- a/crates/forge_analyzer/src/interp.rs +++ b/crates/forge_analyzer/src/interp.rs @@ -644,14 +644,13 @@ impl<'cx, C: Runner<'cx>> Interp<'cx, C> { ) } // push consts into vec if both are consts - (Value::Const(const_value1), Value::Const(const_value2)) => { - self.add_value_with_projection( + (Value::Const(const_value1), Value::Const(const_value2)) => self + .add_value_with_projection( defid_block, varid, Value::Phi(vec![const_value1, const_value2]), projections, - ); - } + ), (Value::Object(exist_var), Value::Object(new_var)) => { // store projection values that are transferred let mut projections_transferred = vec![]; diff --git a/crates/forge_analyzer/src/ir.rs b/crates/forge_analyzer/src/ir.rs index df207ed..36dac88 100644 --- a/crates/forge_analyzer/src/ir.rs +++ b/crates/forge_analyzer/src/ir.rs @@ -16,14 +16,11 @@ use std::slice; use forge_utils::create_newtype; use forge_utils::FxHashMap; -use itertools::Itertools; use smallvec::smallvec; use smallvec::smallvec_inline; use smallvec::SmallVec; -use swc_core::common::SyntaxContext; use swc_core::ecma::ast; use swc_core::ecma::ast::BinaryOp; -use swc_core::ecma::ast::Bool; use swc_core::ecma::ast::JSXText; use swc_core::ecma::ast::Lit; use swc_core::ecma::ast::Null; @@ -140,7 +137,7 @@ pub struct Body { pub blocks: TiVec, pub vars: TiVec, pub values: FxHashMap, - pub ident_to_local: FxHashMap, + ident_to_local: FxHashMap, pub def_id_to_vars: FxHashMap, pub class_instantiations: HashMap, predecessors: OnceCell>>, @@ -344,12 +341,6 @@ impl Body { self.vars.push_and_get_key(kind) } - #[inline] - pub(crate) fn add_insts(&mut self, new_insts: Vec, bb: BasicBlockId) { - let block = self.blocks.get_mut(bb).unwrap(); - block.insts = new_insts; - } - #[inline] pub(crate) fn get_defid_from_var(&self, varid: VarId) -> Option { match self.vars.get(varid)? { diff --git a/test-apps/basic/package.json b/test-apps/basic/package.json index 62ff594..f52c320 100644 --- a/test-apps/basic/package.json +++ b/test-apps/basic/package.json @@ -8,10 +8,12 @@ "validate": "tsc --noEmit --project ./tsconfig.json" }, "devDependencies": { - "@forge/api": "^3.8.0", - "@forge/ui": "^1.11.1", - "@types/node": "^20.14.10", + "@types/node": "20.11.20", "@types/react": "18.2.57", "typescript": "5.3.3" + }, + "dependencies": { + "@forge/api": "3.2.0", + "@forge/ui": "1.11.0" } } \ No newline at end of file