Prepack: Invariant in getIdentifierAndIncrementReferenceCount()

Created on 24 Apr 2018  路  5Comments  路  Source: facebook/prepack

Minimal repro is similar to https://github.com/facebook/prepack/issues/1771 but with a few lines removed.

require("react");

__evaluatePureFunction(function() {

  var fbt;
  var _cachedFbtResults = {};

  fbt = function fbt() {};

  fbt._ = function(table, args) {
    var allSubstitutions = {};
    var pattern = table;
    if (table.__vcg) {
      args = args || [];
    }
    if (args) {
      pattern = this._accessTable(table, allSubstitutions, args, 0);
    }
    var cachedFbt = _cachedFbtResults[pattern];
    var hasSubstitutions;
    if (cachedFbt && !hasSubstitutions) {
      return cachedFbt;
    } else {
      var fbtContent;
      var result;
      if (!hasSubstitutions) {
        _cachedFbtResults[pattern] = result;
      }
      return result;
    }
  };

  fbt._accessTable = function(table, substitutions, args, argsIndex) {
    if (argsIndex >= args.length) {
      return table;
    } else if (table == null) {
      return null;
    }
    var pattern = null;
    var arg = args[argsIndex];
    var tableIndex = arg[0];

    if (!Array.isArray(tableIndex)) {
      table = tableIndex !== null ? table[tableIndex] : table;
      pattern = this._accessTable(table, substitutions, args, argsIndex + 1);
    }
    return pattern;
  };

  function _getNumberVariations(number) {
    var numberType;
    return [numberType, "*"];
  }

  fbt._param = fbt.param = function(label, value, variations) {
    return [null, {}];
  };

  fbt._plural = fbt.plural = function(count, label, value) {
    var variation = _getNumberVariations(count);
    return [variation, []];
  };

  var React = require("react");
  function ViewCount(props) {
    return React.createElement(
      "div",
      fbt._({ "*": "{count} Views", _1: "{count} View" }, [
        fbt._param("count", props.feedback.viewCountReduced),
        fbt._plural(props.feedback.viewCount)
      ])
    );
  }

  __optimizeReactComponentTree(ViewCount);

  module.exports = ViewCount;
});

We hit this invariant:

https://github.com/facebook/prepack/blob/ce6b55916c1a0b9791ef02825accc0b640e7ba24/src/serializer/ResidualHeapValueIdentifiers.js#L75

bug high react compiler

All 5 comments

The invariant failure is a way of saying: the serializer tried to serialize a value that wasn't visited.

Here's a much smaller repro for the same invariant violation; might or might not be the same root cause:

(function () {
  let outer = {};
  function f(x) {
    outer.x = x;
  }
  __optimize(f);
  global.f = f;
  inspect = function() { return true; }
})();

This isn't fixed yet. Still fails for me.

The repro case in the post compiles for me.

screen shot 2018-04-27 at 9 21 52 pm

My bad I hadn鈥檛 rebased

Was this page helpful?
0 / 5 - 0 ratings