Skip to content

Commit

Permalink
refactor: track endo changes
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Feb 28, 2023
1 parent 0e039d9 commit 2870ec2
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 135 deletions.
4 changes: 2 additions & 2 deletions packages/store/src/keys/checkKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ harden(makeCopyBag);
/**
* @template K
* @param {Iterable<K>} elementIter
* @returns {CopySet<K>}
* @returns {CopyBag<K>}
*/
export const makeCopyBagFromElements = elementIter => {
// This fullOrder contains history dependent state. It is specific
Expand Down Expand Up @@ -432,7 +432,7 @@ export const getCopyMapEntries = m => {
const {
payload: { keys, values },
} = m;
const { length } = keys;
const { length } = /** @type {Array} */ (keys);
return Far('CopyMap entries iterable', {
[Symbol.iterator]: () => {
let i = 0;
Expand Down
33 changes: 33 additions & 0 deletions packages/store/src/keys/merge-bag-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ harden(merge);

// We should be able to use this for iterIsSuperset as well.
// The generalization is free.
/**
* @template T
* @param {Iterable<[T,bigint,bigint]>} xyi
* @returns {boolean}
*/
const bagIterIsSuperbag = xyi => {
for (const [_m, xc, yc] of xyi) {
if (xc < yc) {
Expand All @@ -197,6 +202,11 @@ const bagIterIsSuperbag = xyi => {

// We should be able to use this for iterIsDisjoint as well.
// The code is identical.
/**
* @template T
* @param {Iterable<[T,bigint,bigint]>} xyi
* @returns {boolean}
*/
const bagIterIsDisjoint = xyi => {
for (const [_m, xc, yc] of xyi) {
if (xc >= 1n && yc >= 1n) {
Expand All @@ -209,6 +219,11 @@ const bagIterIsDisjoint = xyi => {

// We should be able to use this for iterCompare as well.
// The generalization is free.
/**
* @template T
* @param {Iterable<[T,bigint,bigint]>} xyi
* @returns {KeyComparison}
*/
const bagIterCompare = xyi => {
let loneY = false;
let loneX = false;
Expand Down Expand Up @@ -236,15 +251,27 @@ const bagIterCompare = xyi => {
}
};

/**
* @template T
* @param {[T,bigint,bigint][]} xyi
* @returns {[T,bigint][]}
*/
const bagIterUnion = xyi => {
/** @type {[T,bigint][]} */
const result = [];
for (const [m, xc, yc] of xyi) {
result.push([m, xc + yc]);
}
return result;
};

/**
* @template T
* @param {Iterable<[T,bigint,bigint]>} xyi
* @returns {[T,bigint][]}
*/
const bagIterIntersection = xyi => {
/** @type {[T,bigint][]} */
const result = [];
for (const [m, xc, yc] of xyi) {
const mc = xc <= yc ? xc : yc;
Expand All @@ -253,7 +280,13 @@ const bagIterIntersection = xyi => {
return result;
};

/**
* @template T
* @param {Iterable<[T,bigint,bigint]>} xyi
* @returns {[T,bigint][]}
*/
const bagIterDisjointSubtract = xyi => {
/** @type {[T,bigint][]} */
const result = [];
for (const [m, xc, yc] of xyi) {
const mc = xc - yc;
Expand Down
30 changes: 30 additions & 0 deletions packages/store/src/keys/merge-set-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ const iterIsSuperset = xyi => {
return true;
};

/**
* @template T
* @param {Iterable<[T,bigint,bigint]>} xyi
* @returns {boolean}
*/
const iterIsDisjoint = xyi => {
for (const [_m, xc, yc] of xyi) {
if (xc >= 1n && yc >= 1n) {
Expand All @@ -185,6 +190,11 @@ const iterIsDisjoint = xyi => {
return true;
};

/**
* @template T
* @param {Iterable<[T,bigint,bigint]>} xyi
* @returns {KeyComparison}
*/
const iterCompare = xyi => {
let loneY = false;
let loneX = false;
Expand Down Expand Up @@ -212,6 +222,11 @@ const iterCompare = xyi => {
}
};

/**
* @template T
* @param {Iterable<[T,bigint,bigint]>} xyi
* @returns {T[]}
*/
const iterUnion = xyi => {
const result = [];
for (const [m, xc, yc] of xyi) {
Expand All @@ -227,6 +242,11 @@ const iterUnion = xyi => {
return result;
};

/**
* @template T
* @param {Iterable<[T,bigint,bigint]>} xyi
* @returns {T[]}
*/
const iterDisjointUnion = xyi => {
const result = [];
for (const [m, xc, yc] of xyi) {
Expand All @@ -241,6 +261,11 @@ const iterDisjointUnion = xyi => {
return result;
};

/**
* @template T
* @param {Iterable<[T,bigint,bigint]>} xyi
* @returns {T[]}
*/
const iterIntersection = xyi => {
const result = [];
for (const [m, xc, yc] of xyi) {
Expand All @@ -252,6 +277,11 @@ const iterIntersection = xyi => {
return result;
};

/**
* @template T
* @param {Iterable<[T,bigint,bigint]>} xyi
* @returns {T[]}
*/
const iterDisjointSubtract = xyi => {
const result = [];
for (const [m, xc, yc] of xyi) {
Expand Down
34 changes: 27 additions & 7 deletions packages/store/src/patterns/patternMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ const checkIsWellFormedWithLimit = (
);
};

/**
* @param {unknown} specimen
* @param {number} decimalDigitsLimit
* @param {Checker} check
*/
const checkDecimalDigitsLimit = (specimen, decimalDigitsLimit, check) => {
if (
Math.floor(Math.log10(Math.abs(Number(specimen)))) + 1 <=
Expand Down Expand Up @@ -821,7 +826,10 @@ const makePatternKit = () => {
const { decimalDigitsLimit } = limit(limits);
return (
checkKind(specimen, 'bigint', check) &&
check(specimen >= 0n, X`${specimen} - Must be non-negative`) &&
check(
/** @type {bigint} */ (specimen) >= 0n,
X`${specimen} - Must be non-negative`,
) &&
checkDecimalDigitsLimit(specimen, decimalDigitsLimit, check)
);
},
Expand All @@ -845,7 +853,8 @@ const makePatternKit = () => {
const { stringLengthLimit } = limit(limits);
return (
checkKind(specimen, 'string', check) &&
(specimen.length <= stringLengthLimit ||
// eslint-disable-next-line prettier/prettier -- JSDoc requires these parentheses!
(/** @type {string} */ (specimen).length <= stringLengthLimit ||
check(
false,
X`string ${specimen} must not be bigger than ${stringLengthLimit}`,
Expand Down Expand Up @@ -890,7 +899,7 @@ const makePatternKit = () => {
payload,
harden([]),
check,
'match:bigint payload',
'match:symbol payload',
),

getRankCover: (_matchPayload, _encodePassable) =>
Expand Down Expand Up @@ -1054,7 +1063,8 @@ const makePatternKit = () => {
const { arrayLengthLimit } = limit(limits);
return (
checkKind(specimen, 'copyArray', check) &&
(specimen.length <= arrayLengthLimit ||
// eslint-disable-next-line prettier/prettier -- JSDoc requires these parentheses!
(/** @type {Array} */ (specimen).length <= arrayLengthLimit ||
check(
false,
X`Array length ${specimen.length} must be <= limit ${arrayLengthLimit}`,
Expand All @@ -1081,7 +1091,7 @@ const makePatternKit = () => {
return (
checkKind(specimen, 'copySet', check) &&
check(
specimen.payload.length < numSetElementsLimit,
/** @type {Array} */ (specimen.payload).length < numSetElementsLimit,
X`Set must not have more than ${q(numSetElementsLimit)} elements: ${
specimen.payload.length
}`,
Expand Down Expand Up @@ -1112,7 +1122,8 @@ const makePatternKit = () => {
return (
checkKind(specimen, 'copyBag', check) &&
check(
specimen.payload.length <= numUniqueBagElementsLimit,
/** @type {Array} */ (specimen.payload).length <=
numUniqueBagElementsLimit,
X`Bag must not have more than ${q(
numUniqueBagElementsLimit,
)} unique elements: ${specimen}`,
Expand Down Expand Up @@ -1152,7 +1163,8 @@ const makePatternKit = () => {
return (
checkKind(specimen, 'copyMap', check) &&
check(
specimen.payload.keys.length <= numMapEntriesLimit,
/** @type {Array} */ (specimen.payload.keys).length <=
numMapEntriesLimit,
X`CopyMap must have no more than ${q(
numMapEntriesLimit,
)} entries: ${specimen}`,
Expand Down Expand Up @@ -1254,6 +1266,10 @@ const makePatternKit = () => {
);
},

/**
* @param {Array} splitArray
* @param {Checker} check
*/
checkIsWellFormed: (splitArray, check) => {
if (
passStyleOf(splitArray) === 'copyArray' &&
Expand Down Expand Up @@ -1362,6 +1378,10 @@ const makePatternKit = () => {
);
},

/**
* @param {Array} splitArray
* @param {Checker} check
*/
checkIsWellFormed: (splitArray, check) => {
if (
passStyleOf(splitArray) === 'copyArray' &&
Expand Down
2 changes: 1 addition & 1 deletion packages/store/src/stores/scalarWeakMapStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const makeWeakMapStoreMethods = (
if (isCopyMap(entries)) {
entries = getCopyMapEntries(entries);
}
for (const [key, value] of entries) {
for (const [key, value] of /** @type {Iterable<[K, V]>} */ (entries)) {
// Don't assert that the key either does or does not exist.
assertKVOkToAdd(key, value);
jsmap.set(key, value);
Expand Down
2 changes: 1 addition & 1 deletion packages/store/src/stores/scalarWeakSetStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const makeWeakSetStoreMethods = (
if (isCopySet(keys)) {
keys = getCopySetKeys(keys);
}
for (const key of keys) {
for (const key of /** @type {Iterable<K>} */ (keys)) {
assertKeyOkToAdd(key);
jsset.add(key);
}
Expand Down
Loading

0 comments on commit 2870ec2

Please sign in to comment.