checkNoDuplicateKeys = (bagEntries, fullCompare, check) => {
  // This fullOrder contains history dependent state. It is specific
  // to this one call and does not survive it.
  // TODO Once all our tooling is ready for `&&=`, the following
  // line should be rewritten using it.
  fullCompare = fullCompare || makeFullOrderComparatorKit().antiComparator;

  // Since the key is more significant than the value (the count),
  // sorting by fullOrder is guaranteed to make duplicate keys
  // adjacent independent of their counts.
  bagEntries = sortByRank(bagEntries, fullCompare);
  const { length } = bagEntries;
  for (let i = 1; i < length; i += 1) {
    const k0 = bagEntries[i - 1][0];
    const k1 = bagEntries[i][0];
    if (fullCompare(k0, k1) === 0) {
      return check(false, X`value has duplicate keys: ${k0}`);
    }
  }
  return true;
}
@template {Key} T
@param {[T,bigint][]} bagEntries
@param {FullCompare | undefined} fullCompare If provided and `bagEntries` is already
known to be sorted by this `fullCompare`, then we should get a memo hit
rather than a resorting. However, currently, we still enumerate the entire
array each time.

TODO: If doing this reduntantly turns out to be expensive, we
could memoize this no-duplicate-keys finding as well, independent
of the `fullOrder` use to reach this finding.
@param {Checker} check
@returns {boolean}