From a709f57a95f0aad603acfa5af05833afb45c82c6 Mon Sep 17 00:00:00 2001 From: Emile Rolley Date: Tue, 9 Jan 2024 16:31:57 +0100 Subject: [PATCH] refactor(optim): remove the use of traversedVariables only use refs.childs --- source/optims/constantFolding.ts | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/source/optims/constantFolding.ts b/source/optims/constantFolding.ts index 5f6cfcc..1a0bedb 100644 --- a/source/optims/constantFolding.ts +++ b/source/optims/constantFolding.ts @@ -390,17 +390,9 @@ function tryToFoldRule( return } - ctx.engine.cache.traversedVariablesStack = [] - const { nodeValue, missingVariables, traversedVariables, unit } = - ctx.engine.evaluateNode(rule) + const { nodeValue, missingVariables, unit } = ctx.engine.evaluateNode(rule) - const traversedVariablesWithoutSelf = traversedVariables.filter( - (dottedName) => dottedName !== ruleName, - ) - - // NOTE(@EmileRolley): we need to evaluate due to possible standalone rule [formule] - // parsed as a [valeur]. - if ('valeur' in rule.rawNode && traversedVariablesWithoutSelf?.length > 0) { + if ('valeur' in rule.rawNode) { rule.rawNode.formule = rule.rawNode.valeur delete rule.rawNode.valeur } @@ -429,16 +421,7 @@ function tryToFoldRule( // it from the [refs]. const childs = ctx.refs.childs.get(ruleName) ?? [] - updateRefCounting( - ctx, - ruleName, - // NOTE(@EmileRolley): for some reason, the [traversedVariables] are not always - // depencies of the rule. Consequently, we need to keep only the ones that are - // in the [childs] list in order to avoid removing rules that are not dependencies. - traversedVariablesWithoutSelf?.filter((v: RuleName) => - childs.includes(v), - ) ?? [], - ) + updateRefCounting(ctx, ruleName, childs) delete ctx.parsedRules[ruleName].rawNode.formule }