Skip to content

Commit

Permalink
refactor(optim): remove the use of traversedVariables only use refs.c…
Browse files Browse the repository at this point in the history
…hilds
  • Loading branch information
EmileRolley committed Jan 9, 2024
1 parent b92a793 commit a709f57
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions source/optims/constantFolding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit a709f57

Please sign in to comment.