rescript-association/reanalyze

DCE reports only on inner value or an example with recursion.

cristianoc opened this issue · 3 comments

let rec subList = (b, e, l) =>
  switch (l) {
  | [] => failwith("subList")
  | [h, ...t] =>
    let tail =
      if (e == 0) {
        [];
      } else {
        subList(b - 1, e - 1, t);
      };
    if (b > 0) {
      tail;
    } else {
      [h, ...tail];
    };
  };

This reports on tail but not on subList.

With this variation, it reports on subList:

let rec subList = (b, e, l) =>
  switch (l) {
  | [] => failwith("subList")
  | [h, ...t] =>
    let tail = () =>
      if (e == 0) {
        [];
      } else {
        subList(b - 1, e - 1, t);
      };
    if (b > 0) {
      tail();
    } else {
      [h, ...tail()];
    };
  };

There's a heuristic not to report on inner function if there's a report on the outer function. It could be the heuristic misfires in this case and considers subList to be inside tail.

The difference between the two version is that tail has side effects in the first version, and no side effects in the second (because it is a function definition).