Skip to content

Decision tree #1

@zoltan-mihalyi

Description

@zoltan-mihalyi

Example with variables:

var a = 1, b = 1;
if (x1) {
  a = 2;
  b = 2;
  if (x2) {
    a++;
    b++;
  }
}
if (x3) {
  a = 3;
  b = 3;
}
return a === b; //optimize to true

Example without variables:

(x ? 1 : 0) * 0; // 0, if x has no side effect

The steps to evaluate a === b are:

  • Evaluate a:
    • Find decision points (x1,x2,x3) affecting "a" and build a tree-like data structure.
    • Iterate the tree and create a map of possible values where decision list is the key.
  • Evaluate b like a.
  • Evaluate a === b:
    • Merge the possible values map of "a" and "b".
    • Iterate the merged decision map.
    • Create a new map by evaluating with "a" and "b" values.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions