function _createMemoizedConstraintMapGetter(
  instance: TranslationBuilder,
): (hash: PatternHash) => ConstraintKeyToTranslation {
  // Yes this is hand-rolled memoization :(
  // TODO: T37795723 - Pull in a lightweight (not bloated) memoization library
  const _mem = {};

  // $FlowFixMe[missing-this-annot]
  return function getConstraintMap(
    hash: PatternHash,
  ): ConstraintKeyToTranslation {
    if (_mem[hash]) {
      return _mem[hash];
    }

    const constraintMap = {};
    const transData = this._translations[hash];
    if (transData == null || typeof transData === 'string') {
      // No translation? No constraints.
      // $FlowFixMe[prop-missing]
      return (_mem[hash] = constraintMap);
    }

    // For every possible variation combination, create a mapping to its
    // corresponding translation
    transData.translations.forEach(translation => {
      const constraints = {};
      for (const idx in translation.variations) {
        const variation = translation.variations[idx];
        // We prune entries that contain non-default variations
        // for tokens we haven't specified.
        const token = transData.tokens[Number(idx)];
        if (
          // Token variation type not specified
          !this._tokenToMask[token] ||
          // Translated variation type is different than token variation type
          this._tokenToMask[token] !== transData.types[Number(idx)]
        ) {
          // Only add default tokens we haven't specified.
          if (!this._config.isDefaultVariation(variation)) {
            return;
          }
        }
        constraints[token] = variation;
      }
      // A note about fbt:plurals.  They can introduce global token
      // discrepancies between leaf nodes.  Singular translations don't have
      // number tokens, but their plural counterparts can (when showCount =
      // "ifMany" or "yes").  If we are dealing with the singular leaf of an
      // fbt:plural, since it has a unique hash, we can let it masquerade as
      // default: '*', since no such variation actually exists for a
      // non-existent token
      const constraintKeys = [];
      for (const k in this._tokenToMask) {
        constraintKeys.push([k, constraints[k] || '*']);
      }
      this._insertConstraint(
        constraintKeys,
        constraintMap,
        translation.translation,
        0,
      );
    });
    // $FlowFixMe[prop-missing]
    return (_mem[hash] = constraintMap);
  }.bind(instance);
}
Populates our variation constraint map.  The map is of all possible
variation combinations (serialized as a string) to the appropriate
translation.  For example, JavaScript like:

  fbt('Hi ' + fbt.param('user', viewer.name, {gender: viewer.gender}) +
      ', would you like to play ' +
       fbt.param('count', gameCount, {number: true}) +
       ' games of ' + fbt.enum(game,['chess','backgammon','poker']) +
       '?  Click ' + fbt.param('link', <Link  />), 'sample'),

will have variations for the 'user' and 'count' parameters.  Accounting for
all variations in a locale where we don't merge unknown gender into male
and we have the dual number variation, the map will have the following keys
mapping to the corresponding translation.

 user%*:count%*  [default (unknown) - default (other) ]
 user%*:count%4  [default           - one             ]
 user%*:count%20 [default           - few             ]
 user%*:count%24 [default           - other           ]
 user%1:count%*  [male              - default (other) ]
 user%1:count%4  [male              - one             ]
 user%1:count%20 [male              - few             ]
 user%1:count%24 [male              - other           ]
 user%2:count%*  [female            - default (other) ]
 user%2:count%4  [female            - singular        ]
 user%2:count%20 [female            - few             ]
 user%2:count%24 [female            - other           ]
 user%3:count%*  [unknown gender    - default (other) ]
 user%3:count%4  [unknown gender    - singular        ]
 user%3:count%20 [unknown gender    - few             ]
 user%3:count%24 [unknown gender    - other           ]

 Note we have duplicate translations in this map.  As an example, the
 following keys map to the same translation
   'user%*:count%*'  (default - default)
   'user%3:count%*'  (unknown - default)
   'user%3:count%24' (unknown - other)

 These translations are deduped later in getConstrainedTranslation such
 that only the 'user%*:count%*' in our tree is in the JSON map.  i.e.

 {
   // No unknown gender entry exists at this level - we rely on fallback
   '*' => {
     // no plural entry exists at this level
     '*' => {translation},
     ...

   },
   ...
 }