@markw65/monkeyc-optimizer 1.1.82 → 1.1.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/build/api.cjs +40 -38
- package/build/{chunk-TLXMWGYI.cjs → chunk-ZWQB5L34.cjs} +1709 -1452
- package/build/optimizer.cjs +18 -18
- package/build/sdk-util.cjs +14 -14
- package/build/src/api.d.ts +2 -1
- package/build/src/optimizer-types.d.ts +2 -1
- package/build/src/type-flow/array-type.d.ts +10 -0
- package/build/src/type-flow/effective-type.d.ts +2 -0
- package/build/src/type-flow/interp-call.d.ts +2 -1
- package/build/src/type-flow/interp.d.ts +1 -0
- package/build/src/type-flow/types.d.ts +2 -11
- package/build/src/type-flow/union-type.d.ts +1 -0
- package/build/worker-thread.cjs +3 -3
- package/package.json +1 -1
|
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_ZWQB5L34_exports = {};
|
|
30
|
+
__export(chunk_ZWQB5L34_exports, {
|
|
31
31
|
EnumTagsConst: () => EnumTagsConst,
|
|
32
32
|
LastTypeTag: () => LastTypeTag,
|
|
33
33
|
ObjectLikeTagsConst: () => ObjectLikeTagsConst,
|
|
@@ -40,6 +40,7 @@ __export(chunk_TLXMWGYI_exports, {
|
|
|
40
40
|
buildConfigDescription: () => buildConfigDescription,
|
|
41
41
|
buildOptimizedProject: () => buildOptimizedProject,
|
|
42
42
|
checkCompilerVersion: () => checkCompilerVersion,
|
|
43
|
+
clearDiagnostics: () => clearDiagnostics,
|
|
43
44
|
collectNamespaces: () => collectNamespaces,
|
|
44
45
|
connectiq: () => connectiq,
|
|
45
46
|
couldBe: () => couldBe,
|
|
@@ -139,7 +140,7 @@ __export(chunk_TLXMWGYI_exports, {
|
|
|
139
140
|
visitorNode: () => visitorNode,
|
|
140
141
|
xml_util_exports: () => xml_util_exports
|
|
141
142
|
});
|
|
142
|
-
module.exports = __toCommonJS(
|
|
143
|
+
module.exports = __toCommonJS(chunk_ZWQB5L34_exports);
|
|
143
144
|
var import_chunk_X7QCZR3F = require("./chunk-X7QCZR3F.cjs");
|
|
144
145
|
var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.cjs");
|
|
145
146
|
var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
|
|
@@ -5728,7 +5729,7 @@ var init_build_config = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
5728
5729
|
},
|
|
5729
5730
|
extraReferenceTypeChecks: {
|
|
5730
5731
|
type: "boolean",
|
|
5731
|
-
|
|
5732
|
+
markdownDescription: "Whether to warn about [unsafe operations on Arrays and Dictionaries](https://github.com/markw65/monkeyc-optimizer/wiki/Extra-Reference-Type-Checks-(prettierMonkeyC.extraReferenceTypeChecks)) that Garmin's compiler allows",
|
|
5732
5733
|
default: true,
|
|
5733
5734
|
scope: "resource"
|
|
5734
5735
|
},
|
|
@@ -6923,8 +6924,8 @@ function pragmaChecker(state, ast, diagnostics) {
|
|
|
6923
6924
|
}
|
|
6924
6925
|
if (node.start && node.start >= (comment.end || Infinity)) {
|
|
6925
6926
|
const { kind, quote, needle } = matchers.shift();
|
|
6927
|
+
const thisComment = comment;
|
|
6926
6928
|
if (kind === "match") {
|
|
6927
|
-
const thisComment = comment;
|
|
6928
6929
|
promise = promise.then(
|
|
6929
6930
|
() => formatAstLongLines(node).then((haystack) => {
|
|
6930
6931
|
haystack = haystack.replace(/([\r\n]|\s)+/g, " ").replace(/\b\w+\s\/\*>([\w.]+)<\*\//g, "$1");
|
|
@@ -6979,7 +6980,7 @@ function pragmaChecker(state, ast, diagnostics) {
|
|
|
6979
6980
|
if (!found) {
|
|
6980
6981
|
diagnostic(
|
|
6981
6982
|
state,
|
|
6982
|
-
|
|
6983
|
+
thisComment,
|
|
6983
6984
|
`Missing error message '${needle}`,
|
|
6984
6985
|
"ERROR"
|
|
6985
6986
|
);
|
|
@@ -7618,745 +7619,312 @@ var init_control_flow = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
7618
7619
|
};
|
|
7619
7620
|
}
|
|
7620
7621
|
});
|
|
7621
|
-
function
|
|
7622
|
-
|
|
7622
|
+
function expandTypedef(t) {
|
|
7623
|
+
const decls = getUnionComponent(
|
|
7624
|
+
t,
|
|
7625
|
+
262144
|
|
7626
|
+
/* Typedef */
|
|
7627
|
+
);
|
|
7628
|
+
const tExpanded = cloneType(t);
|
|
7629
|
+
clearValuesUnder(tExpanded, 262144, true);
|
|
7630
|
+
(0, import_chunk_X7QCZR3F.forEach)(decls, (decl) => unionInto(tExpanded, decl.resolvedType));
|
|
7631
|
+
return tExpanded;
|
|
7623
7632
|
}
|
|
7624
|
-
function
|
|
7625
|
-
|
|
7626
|
-
|
|
7633
|
+
function intersectEnum(t, e) {
|
|
7634
|
+
const enumData = getUnionComponent(
|
|
7635
|
+
e,
|
|
7636
|
+
65536
|
|
7637
|
+
/* Enum */
|
|
7638
|
+
);
|
|
7639
|
+
const e2 = cloneType(e);
|
|
7640
|
+
const i = intersection(t, typeFromEnumValue(enumData));
|
|
7641
|
+
if (e2.value != null) {
|
|
7642
|
+
clearValuesUnder(e2, 65536, true);
|
|
7643
|
+
} else {
|
|
7644
|
+
e2.type &= ~65536;
|
|
7627
7645
|
}
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
to.type = from.type;
|
|
7632
|
-
to.value = from.value;
|
|
7633
|
-
return true;
|
|
7646
|
+
const rest = intersection(t, e2);
|
|
7647
|
+
if (i.type === 0) {
|
|
7648
|
+
return rest;
|
|
7634
7649
|
}
|
|
7635
|
-
const
|
|
7636
|
-
|
|
7637
|
-
|
|
7638
|
-
|
|
7639
|
-
|
|
7640
|
-
|
|
7650
|
+
const result = enumData ? { type: 65536, value: { ...enumData, value: i } } : cloneType(i);
|
|
7651
|
+
unionInto(result, rest);
|
|
7652
|
+
return result;
|
|
7653
|
+
}
|
|
7654
|
+
function intersection(a, b) {
|
|
7655
|
+
if (a.type & 262144 && a.value != null) {
|
|
7656
|
+
return intersection(expandTypedef(a), b);
|
|
7641
7657
|
}
|
|
7642
|
-
if (
|
|
7643
|
-
|
|
7644
|
-
return false;
|
|
7645
|
-
}
|
|
7646
|
-
if (from.value == null) {
|
|
7647
|
-
clearValuesUnder(to, from.type);
|
|
7648
|
-
return true;
|
|
7649
|
-
}
|
|
7650
|
-
return mergeMultiple(to, from, widenDepth);
|
|
7658
|
+
if (b.type & 262144 && b.value != null) {
|
|
7659
|
+
return intersection(a, expandTypedef(b));
|
|
7651
7660
|
}
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
7655
|
-
|
|
7661
|
+
let common = a.type & b.type & ~262144;
|
|
7662
|
+
if (a.type & 32768 && b.type & ObjectLikeTagsConst && getObjectValue(a) == null) {
|
|
7663
|
+
common |= b.type & ObjectLikeTagsConst;
|
|
7664
|
+
}
|
|
7665
|
+
if (b.type & 32768 && a.type & ObjectLikeTagsConst && getObjectValue(b) == null) {
|
|
7666
|
+
common |= a.type & ObjectLikeTagsConst;
|
|
7667
|
+
}
|
|
7668
|
+
if (a.type & 65536 && b.type & EnumTagsConst && !(b.type & 65536)) {
|
|
7669
|
+
return intersectEnum(b, a);
|
|
7670
|
+
}
|
|
7671
|
+
if (b.type & 65536 && a.type & EnumTagsConst && !(a.type & 65536)) {
|
|
7672
|
+
return intersectEnum(a, b);
|
|
7673
|
+
}
|
|
7674
|
+
if (!common) {
|
|
7675
|
+
return {
|
|
7676
|
+
type: 0
|
|
7677
|
+
/* Never */
|
|
7678
|
+
};
|
|
7679
|
+
}
|
|
7680
|
+
if (a.value == null) {
|
|
7681
|
+
if (b.value == null) {
|
|
7682
|
+
return { type: common };
|
|
7656
7683
|
}
|
|
7657
|
-
|
|
7658
|
-
|
|
7684
|
+
const result2 = cloneType(b);
|
|
7685
|
+
clearValuesUnder(result2, b.type & ~common, true);
|
|
7686
|
+
return result2;
|
|
7659
7687
|
}
|
|
7660
|
-
if (
|
|
7661
|
-
|
|
7662
|
-
|
|
7688
|
+
if (b.value == null) {
|
|
7689
|
+
const result2 = cloneType(a);
|
|
7690
|
+
clearValuesUnder(result2, a.type & ~common, true);
|
|
7691
|
+
return result2;
|
|
7663
7692
|
}
|
|
7664
|
-
const tmp = cloneType(from);
|
|
7665
|
-
clearValuesUnder(tmp, to.type);
|
|
7666
|
-
to.type = tmp.type;
|
|
7667
|
-
to.value = tmp.value;
|
|
7668
|
-
return true;
|
|
7669
|
-
}
|
|
7670
|
-
function mergeMultiple(to, from, widenDepth) {
|
|
7671
|
-
const newTags = to.type | from.type;
|
|
7672
|
-
let anyChanged = newTags !== to.type;
|
|
7673
7693
|
let mask = 0;
|
|
7674
7694
|
const result = {};
|
|
7675
|
-
forEachUnionComponent(
|
|
7676
|
-
const
|
|
7677
|
-
if (ac.value
|
|
7678
|
-
if (
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
type: ac.type,
|
|
7682
|
-
avalue: ac.value,
|
|
7683
|
-
bvalue: fromv
|
|
7684
|
-
},
|
|
7685
|
-
widenDepth
|
|
7686
|
-
);
|
|
7687
|
-
if (changed)
|
|
7688
|
-
anyChanged = true;
|
|
7689
|
-
if (value2) {
|
|
7690
|
-
mask |= ac.type;
|
|
7691
|
-
result[ac.type] = value2;
|
|
7692
|
-
}
|
|
7693
|
-
} else if (!(from.type & ac.type)) {
|
|
7694
|
-
mask |= ac.type;
|
|
7695
|
-
result[ac.type] = ac.value;
|
|
7696
|
-
} else {
|
|
7697
|
-
anyChanged = true;
|
|
7698
|
-
}
|
|
7699
|
-
} else if (fromv && !(to.type & ac.type)) {
|
|
7700
|
-
anyChanged = true;
|
|
7695
|
+
forEachUnionComponent(a, common, (ac) => {
|
|
7696
|
+
const bvalue = getUnionComponent(b, ac.type);
|
|
7697
|
+
if (ac.value == null) {
|
|
7698
|
+
if (!bvalue)
|
|
7699
|
+
return;
|
|
7700
|
+
result[ac.type] = bvalue;
|
|
7701
7701
|
mask |= ac.type;
|
|
7702
|
-
|
|
7702
|
+
return;
|
|
7703
|
+
}
|
|
7704
|
+
if (bvalue === null || ac.value === bvalue) {
|
|
7705
|
+
result[ac.type] = ac.value;
|
|
7706
|
+
mask |= ac.type;
|
|
7707
|
+
return;
|
|
7708
|
+
}
|
|
7709
|
+
const ivalue = intersectionValue({
|
|
7710
|
+
type: ac.type,
|
|
7711
|
+
avalue: ac.value,
|
|
7712
|
+
bvalue
|
|
7713
|
+
});
|
|
7714
|
+
if (ivalue != null) {
|
|
7715
|
+
result[ac.type] = ivalue;
|
|
7716
|
+
mask |= ac.type;
|
|
7717
|
+
return;
|
|
7718
|
+
} else {
|
|
7719
|
+
common -= ac.type;
|
|
7703
7720
|
}
|
|
7704
7721
|
});
|
|
7705
|
-
if (!
|
|
7706
|
-
return
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
delete to.value;
|
|
7710
|
-
return true;
|
|
7711
|
-
}
|
|
7712
|
-
if (hasUnionData(newTags)) {
|
|
7713
|
-
to.value = result;
|
|
7714
|
-
to.value.mask = mask;
|
|
7715
|
-
return true;
|
|
7722
|
+
if (!mask)
|
|
7723
|
+
return { type: common };
|
|
7724
|
+
if (hasUnionData(common)) {
|
|
7725
|
+
return { type: common, value: { ...result, mask } };
|
|
7716
7726
|
}
|
|
7717
7727
|
if (mask & mask - 1) {
|
|
7718
|
-
throw new Error(
|
|
7728
|
+
throw new Error(
|
|
7729
|
+
`Mask with non-union data had more than one bit set: ${mask}`
|
|
7730
|
+
);
|
|
7719
7731
|
}
|
|
7720
|
-
|
|
7721
|
-
return true;
|
|
7732
|
+
return { type: common, value: result[mask] };
|
|
7722
7733
|
}
|
|
7723
|
-
function
|
|
7724
|
-
function tryUnion(to, from) {
|
|
7725
|
-
to = cloneType(to);
|
|
7726
|
-
if (unionHelper(to, from, widenDepth + 1))
|
|
7727
|
-
return to;
|
|
7728
|
-
return null;
|
|
7729
|
-
}
|
|
7734
|
+
function intersectionValue(pair) {
|
|
7730
7735
|
switch (pair.type) {
|
|
7731
7736
|
case 1:
|
|
7732
7737
|
case 2:
|
|
7733
7738
|
case 4:
|
|
7734
|
-
|
|
7739
|
+
case 262144:
|
|
7740
|
+
throw new Error(`Unexpected TypeTag '${typeTagName(pair.type)}'`);
|
|
7735
7741
|
case 8:
|
|
7736
7742
|
case 16:
|
|
7737
7743
|
case 32:
|
|
7738
7744
|
case 64:
|
|
7739
|
-
case 128:
|
|
7740
7745
|
case 256:
|
|
7746
|
+
case 128:
|
|
7741
7747
|
case 131072:
|
|
7742
|
-
return
|
|
7743
|
-
case 512:
|
|
7744
|
-
|
|
7745
|
-
return [null, true];
|
|
7746
|
-
}
|
|
7747
|
-
const tupleTypes = /* @__PURE__ */ new Map();
|
|
7748
|
-
const arrayTypes = [];
|
|
7749
|
-
tupleForEach(
|
|
7748
|
+
return pair.avalue === pair.bvalue ? pair.avalue : null;
|
|
7749
|
+
case 512:
|
|
7750
|
+
return tupleMap(
|
|
7750
7751
|
pair.avalue,
|
|
7751
|
-
(
|
|
7752
|
-
|
|
7753
|
-
|
|
7754
|
-
|
|
7755
|
-
|
|
7756
|
-
|
|
7757
|
-
|
|
7758
|
-
|
|
7759
|
-
|
|
7752
|
+
(av) => tupleMap(
|
|
7753
|
+
pair.bvalue,
|
|
7754
|
+
(bv) => {
|
|
7755
|
+
if (av.length !== bv.length)
|
|
7756
|
+
return null;
|
|
7757
|
+
const isect = av.map((t, i) => intersection(t, bv[i]));
|
|
7758
|
+
return isect.some(
|
|
7759
|
+
(t) => t.type === 0
|
|
7760
|
+
/* Never */
|
|
7761
|
+
) ? null : isect;
|
|
7762
|
+
},
|
|
7763
|
+
(bv) => {
|
|
7764
|
+
const isect = av.map((t) => intersection(bv, t));
|
|
7765
|
+
return isect.some(
|
|
7766
|
+
(t) => t.type === 0
|
|
7767
|
+
/* Never */
|
|
7768
|
+
) ? null : isect;
|
|
7769
|
+
},
|
|
7770
|
+
(bv) => bv.length === 0 ? null : bv
|
|
7771
|
+
),
|
|
7772
|
+
(av) => tupleMap(
|
|
7773
|
+
pair.bvalue,
|
|
7774
|
+
(bv) => {
|
|
7775
|
+
const isect = bv.map((t) => intersection(av, t));
|
|
7776
|
+
return isect.some(
|
|
7777
|
+
(t) => t.type === 0
|
|
7778
|
+
/* Never */
|
|
7779
|
+
) ? null : isect;
|
|
7780
|
+
},
|
|
7781
|
+
(bv) => {
|
|
7782
|
+
const atype = intersection(av, bv);
|
|
7783
|
+
return atype.type === 0 ? null : atype;
|
|
7784
|
+
},
|
|
7785
|
+
(bv) => bv.length === 0 ? null : bv
|
|
7786
|
+
),
|
|
7787
|
+
(av) => {
|
|
7788
|
+
const result = av.flat(1);
|
|
7789
|
+
return result.length === 0 ? null : tupleReduce(result);
|
|
7790
|
+
}
|
|
7760
7791
|
);
|
|
7761
|
-
const extraTypes = [];
|
|
7762
|
-
tupleForEach(
|
|
7763
|
-
pair.bvalue,
|
|
7764
|
-
(v) => {
|
|
7765
|
-
const tuples = tupleTypes.get(v.length);
|
|
7766
|
-
if (!tuples?.some(
|
|
7767
|
-
(t) => t.every((at, i) => {
|
|
7768
|
-
const bt = v[i];
|
|
7769
|
-
return subtypeOf(at, bt) && subtypeOf(bt, at);
|
|
7770
|
-
})
|
|
7771
|
-
)) {
|
|
7772
|
-
extraTypes.push(v);
|
|
7773
|
-
}
|
|
7774
|
-
},
|
|
7775
|
-
(v) => {
|
|
7776
|
-
if (!arrayTypes.some((at) => subtypeOf(at, v) && subtypeOf(v, at))) {
|
|
7777
|
-
extraTypes.push(v);
|
|
7778
|
-
}
|
|
7779
|
-
}
|
|
7780
|
-
);
|
|
7781
|
-
if (extraTypes.length) {
|
|
7782
|
-
if (widenDepth >= 0) {
|
|
7783
|
-
return [null, true];
|
|
7784
|
-
}
|
|
7785
|
-
const allTypes = (pair.avalue instanceof Set ? Array.from(pair.avalue) : [pair.avalue]).concat(extraTypes);
|
|
7786
|
-
return [tupleReduce(allTypes), true];
|
|
7787
|
-
}
|
|
7788
|
-
return [pair.avalue, false];
|
|
7789
|
-
}
|
|
7790
7792
|
case 1024: {
|
|
7791
|
-
if (
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
const result = new Map(avalue);
|
|
7799
|
-
let merged = false;
|
|
7800
|
-
result.forEach((av, key2) => {
|
|
7801
|
-
const bv = bvalue.get(key2);
|
|
7802
|
-
if (!bv) {
|
|
7803
|
-
result.delete(key2);
|
|
7804
|
-
merged = true;
|
|
7805
|
-
return;
|
|
7793
|
+
if (!pair.avalue.value) {
|
|
7794
|
+
if (!pair.bvalue.value) {
|
|
7795
|
+
const result = new Map(pair.avalue);
|
|
7796
|
+
pair.bvalue.forEach((bv, key) => {
|
|
7797
|
+
const av = result.get(key);
|
|
7798
|
+
if (av) {
|
|
7799
|
+
bv = intersection(bv, av);
|
|
7806
7800
|
}
|
|
7807
|
-
|
|
7808
|
-
if (unionHelper(av, bv, widenDepth + 1))
|
|
7809
|
-
merged = true;
|
|
7810
|
-
result.set(key2, av);
|
|
7801
|
+
result.set(key, bv);
|
|
7811
7802
|
});
|
|
7812
|
-
return
|
|
7803
|
+
return result;
|
|
7813
7804
|
} else {
|
|
7814
|
-
|
|
7815
|
-
let merged = false;
|
|
7816
|
-
result.forEach((av, key2) => {
|
|
7817
|
-
const keyType = typeFromObjectLiteralKey(key2);
|
|
7818
|
-
if (couldBe(keyType, bvalue.key)) {
|
|
7819
|
-
const bv = tryUnion(av, bvalue.value);
|
|
7820
|
-
if (bv) {
|
|
7821
|
-
result.set(key2, bv);
|
|
7822
|
-
merged = true;
|
|
7823
|
-
}
|
|
7824
|
-
}
|
|
7825
|
-
});
|
|
7826
|
-
return [result, merged];
|
|
7805
|
+
return pair.bvalue;
|
|
7827
7806
|
}
|
|
7828
|
-
} else if (!bvalue.value) {
|
|
7829
|
-
|
|
7830
|
-
let merged = false;
|
|
7831
|
-
result.forEach((bv, key2) => {
|
|
7832
|
-
const keyType = typeFromObjectLiteralKey(key2);
|
|
7833
|
-
if (couldBe(keyType, avalue.key)) {
|
|
7834
|
-
const av = tryUnion(bv, avalue.value);
|
|
7835
|
-
if (av) {
|
|
7836
|
-
result.set(key2, av);
|
|
7837
|
-
merged = true;
|
|
7838
|
-
}
|
|
7839
|
-
}
|
|
7840
|
-
});
|
|
7841
|
-
return [result, merged];
|
|
7842
|
-
}
|
|
7843
|
-
const { key, value: value2 } = avalue;
|
|
7844
|
-
const keyChange = tryUnion(key, bvalue.key);
|
|
7845
|
-
const valueChange = tryUnion(value2, bvalue.value);
|
|
7846
|
-
if (keyChange || valueChange) {
|
|
7847
|
-
return [{ key: keyChange || key, value: valueChange || value2 }, true];
|
|
7807
|
+
} else if (!pair.bvalue.value) {
|
|
7808
|
+
return pair.avalue;
|
|
7848
7809
|
}
|
|
7849
|
-
|
|
7810
|
+
const dkey = intersection(pair.avalue.key, pair.bvalue.key);
|
|
7811
|
+
const dvalue = intersection(pair.avalue.value, pair.bvalue.value);
|
|
7812
|
+
return dkey.type !== 0 && dvalue.type !== 0 ? { key: dkey, value: dvalue } : null;
|
|
7850
7813
|
}
|
|
7851
7814
|
case 2048: {
|
|
7852
7815
|
if (pair.avalue.args.length !== pair.bvalue.args.length)
|
|
7853
|
-
return
|
|
7854
|
-
const
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
)
|
|
7858
|
-
|
|
7816
|
+
return null;
|
|
7817
|
+
const mresult = intersection(pair.avalue.result, pair.bvalue.result);
|
|
7818
|
+
if (mresult.type === 0)
|
|
7819
|
+
return null;
|
|
7820
|
+
const margs = pair.avalue.args.map((aarg, i) => {
|
|
7821
|
+
aarg = cloneType(aarg);
|
|
7822
|
+
unionInto(aarg, pair.bvalue.args[i]);
|
|
7823
|
+
return aarg;
|
|
7824
|
+
});
|
|
7825
|
+
if (margs.some(
|
|
7859
7826
|
(arg) => arg.type === 0
|
|
7860
7827
|
/* Never */
|
|
7861
|
-
))
|
|
7862
|
-
return
|
|
7863
|
-
}
|
|
7864
|
-
const argsChanged = args.some(
|
|
7865
|
-
(arg, i) => !subtypeOf(pair.avalue.args[i], arg)
|
|
7866
|
-
);
|
|
7867
|
-
if (resultChange || argsChanged) {
|
|
7868
|
-
return [{ result: resultChange || pair.avalue.result, args }, true];
|
|
7869
|
-
}
|
|
7870
|
-
return [pair.avalue, false];
|
|
7828
|
+
))
|
|
7829
|
+
return null;
|
|
7830
|
+
return { result: mresult, args: margs };
|
|
7871
7831
|
}
|
|
7872
7832
|
case 4096:
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
case 262144:
|
|
7879
|
-
return mergeStateDecls(pair.avalue, pair.bvalue);
|
|
7880
|
-
case 32768: {
|
|
7881
|
-
let klass = pair.avalue.klass;
|
|
7882
|
-
const [obj, objChanged] = mergeObjectValues(
|
|
7883
|
-
pair.avalue.obj,
|
|
7884
|
-
pair.bvalue.obj,
|
|
7885
|
-
widenDepth
|
|
7833
|
+
case 8192: {
|
|
7834
|
+
const common = /* @__PURE__ */ new Set();
|
|
7835
|
+
(0, import_chunk_X7QCZR3F.forEach)(
|
|
7836
|
+
pair.avalue,
|
|
7837
|
+
(sna) => (0, import_chunk_X7QCZR3F.some)(pair.bvalue, (snb) => sna === snb) && common.add(sna)
|
|
7886
7838
|
);
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
|
|
7839
|
+
if (!common.size)
|
|
7840
|
+
return null;
|
|
7841
|
+
const arr = Array.from(common);
|
|
7842
|
+
return arr.length === 1 ? arr[0] : arr;
|
|
7843
|
+
}
|
|
7844
|
+
case 16384: {
|
|
7845
|
+
const common = /* @__PURE__ */ new Set();
|
|
7846
|
+
(0, import_chunk_X7QCZR3F.forEach)(pair.avalue, (sna) => {
|
|
7847
|
+
const superA = getSuperClasses(sna);
|
|
7848
|
+
(0, import_chunk_X7QCZR3F.forEach)(pair.bvalue, (snb) => {
|
|
7849
|
+
if (sna === snb || superA && superA.has(snb)) {
|
|
7850
|
+
common.add(sna);
|
|
7851
|
+
}
|
|
7852
|
+
const superB = getSuperClasses(snb);
|
|
7853
|
+
if (superB && superB.has(sna)) {
|
|
7854
|
+
common.add(snb);
|
|
7855
|
+
}
|
|
7856
|
+
});
|
|
7857
|
+
});
|
|
7858
|
+
if (!common.size)
|
|
7859
|
+
return null;
|
|
7860
|
+
const arr = Array.from(common);
|
|
7861
|
+
return arr.length === 1 ? arr[0] : arr;
|
|
7862
|
+
}
|
|
7863
|
+
case 32768: {
|
|
7864
|
+
const klass = intersection(pair.avalue.klass, pair.bvalue.klass);
|
|
7865
|
+
const obj = intersectObj(pair.avalue.obj, pair.bvalue.obj);
|
|
7866
|
+
return klass.type !== 16384 || klass.value == null ? null : obj ? { klass, obj } : { klass };
|
|
7896
7867
|
}
|
|
7897
7868
|
case 65536: {
|
|
7898
|
-
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7905
|
-
return [e, true];
|
|
7869
|
+
let enumDecl;
|
|
7870
|
+
if (Array.isArray(pair.avalue.enum)) {
|
|
7871
|
+
const s = new Set(pair.avalue.enum);
|
|
7872
|
+
const enums = [];
|
|
7873
|
+
(0, import_chunk_X7QCZR3F.forEach)(pair.bvalue.enum, (b) => s.has(b) && enums.push(b));
|
|
7874
|
+
if (enums.length) {
|
|
7875
|
+
enumDecl = enums.length === 1 ? enums[0] : enums;
|
|
7906
7876
|
}
|
|
7907
|
-
|
|
7908
|
-
|
|
7909
|
-
if (!toE.value) {
|
|
7910
|
-
return [toE, false];
|
|
7911
|
-
}
|
|
7912
|
-
if (!fromE.value) {
|
|
7913
|
-
delete toE.value;
|
|
7914
|
-
return [toE, true];
|
|
7915
|
-
}
|
|
7916
|
-
const toValue = tryUnion(toE.value, fromE.value);
|
|
7917
|
-
if (toValue) {
|
|
7918
|
-
const e = { enum: toE.enum, value: toValue };
|
|
7919
|
-
return [e, true];
|
|
7877
|
+
} else {
|
|
7878
|
+
(0, import_chunk_X7QCZR3F.some)(pair.bvalue.enum, (b) => b === pair.avalue.enum) && (enumDecl = pair.bvalue.enum);
|
|
7920
7879
|
}
|
|
7921
|
-
|
|
7880
|
+
if (!enumDecl)
|
|
7881
|
+
return null;
|
|
7882
|
+
const enumValue = pair.avalue.value != null ? pair.bvalue.value != null ? intersection(pair.avalue.value, pair.bvalue.value) : pair.avalue.value : pair.bvalue.value;
|
|
7883
|
+
return { enum: enumDecl, value: enumValue };
|
|
7922
7884
|
}
|
|
7923
7885
|
default:
|
|
7924
7886
|
unhandledType(pair);
|
|
7925
7887
|
}
|
|
7926
7888
|
}
|
|
7927
|
-
function
|
|
7928
|
-
if (!to)
|
|
7929
|
-
return
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
return [from, true];
|
|
7933
|
-
}
|
|
7934
|
-
let empty = true;
|
|
7889
|
+
function intersectObj(to, from) {
|
|
7890
|
+
if (!to)
|
|
7891
|
+
return from;
|
|
7892
|
+
if (!from)
|
|
7893
|
+
return to;
|
|
7935
7894
|
let result = to;
|
|
7936
|
-
Object.entries(
|
|
7937
|
-
if (!(0, import_chunk_JDC43A3I.hasProperty)(
|
|
7895
|
+
Object.entries(from).forEach(([key, value2]) => {
|
|
7896
|
+
if (!(0, import_chunk_JDC43A3I.hasProperty)(to, key)) {
|
|
7938
7897
|
if (result === to)
|
|
7939
7898
|
result = { ...result };
|
|
7940
|
-
|
|
7899
|
+
result[key] = value2;
|
|
7941
7900
|
return;
|
|
7942
7901
|
}
|
|
7943
|
-
|
|
7944
|
-
|
|
7945
|
-
|
|
7946
|
-
result = { ...result };
|
|
7947
|
-
result[key] = rep;
|
|
7948
|
-
}
|
|
7949
|
-
empty = false;
|
|
7902
|
+
if (result === to)
|
|
7903
|
+
result = { ...result };
|
|
7904
|
+
result[key] = intersection(to[key], value2);
|
|
7950
7905
|
});
|
|
7951
|
-
|
|
7952
|
-
return [void 0, true];
|
|
7953
|
-
}
|
|
7954
|
-
return [result, result !== to];
|
|
7906
|
+
return result;
|
|
7955
7907
|
}
|
|
7956
|
-
function
|
|
7957
|
-
|
|
7958
|
-
|
|
7959
|
-
|
|
7960
|
-
|
|
7961
|
-
|
|
7962
|
-
|
|
7963
|
-
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7908
|
+
function fixupEnum(a, b_restricted, b) {
|
|
7909
|
+
if (b.type & 65536) {
|
|
7910
|
+
const bvalue = getUnionComponent(
|
|
7911
|
+
b,
|
|
7912
|
+
65536
|
|
7913
|
+
/* Enum */
|
|
7914
|
+
);
|
|
7915
|
+
const br = restrictByEquality(a, typeFromEnumValue(bvalue));
|
|
7916
|
+
if (br.type) {
|
|
7917
|
+
b_restricted = cloneType(b_restricted);
|
|
7918
|
+
unionInto(
|
|
7919
|
+
b_restricted,
|
|
7920
|
+
bvalue ? {
|
|
7921
|
+
type: 65536,
|
|
7922
|
+
value: { ...bvalue, value: br }
|
|
7923
|
+
} : br
|
|
7924
|
+
);
|
|
7971
7925
|
}
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
return [result, changed];
|
|
7975
|
-
}
|
|
7976
|
-
function nonUnionDataMask(tag) {
|
|
7977
|
-
if (tag & tag - 1) {
|
|
7978
|
-
return tag & UnionDataTypeTagsConst || tag & ValueTypeTagsConst;
|
|
7979
|
-
}
|
|
7980
|
-
return tag;
|
|
7981
|
-
}
|
|
7982
|
-
function clearValuesUnder(v, tag, clearTag = false) {
|
|
7983
|
-
const newTag = clearTag ? v.type & ~tag : v.type | tag;
|
|
7984
|
-
tag &= ~SingletonTypeTagsConst;
|
|
7985
|
-
if (!tag || v.value == null) {
|
|
7986
|
-
v.type = newTag;
|
|
7987
|
-
return;
|
|
7988
|
-
}
|
|
7989
|
-
if (tag & ValueTypeTagsConst) {
|
|
7990
|
-
tag |= ValueTypeTagsConst;
|
|
7991
|
-
}
|
|
7992
|
-
if (!hasUnionData(v.type)) {
|
|
7993
|
-
const dataMask = nonUnionDataMask(v.type);
|
|
7994
|
-
if (dataMask & tag) {
|
|
7995
|
-
v.type = newTag;
|
|
7996
|
-
delete v.value;
|
|
7997
|
-
return;
|
|
7998
|
-
}
|
|
7999
|
-
if (dataMask & ValueTypeTagsConst) {
|
|
8000
|
-
delete v.value;
|
|
8001
|
-
v.type = newTag;
|
|
8002
|
-
return;
|
|
8003
|
-
}
|
|
8004
|
-
if (hasUnionData(newTag)) {
|
|
8005
|
-
const mask = v.type & UnionDataTypeTagsConst;
|
|
8006
|
-
v.value = {
|
|
8007
|
-
[mask]: v.value,
|
|
8008
|
-
mask
|
|
8009
|
-
};
|
|
8010
|
-
}
|
|
8011
|
-
v.type = newTag;
|
|
8012
|
-
return;
|
|
8013
|
-
}
|
|
8014
|
-
v.type = newTag;
|
|
8015
|
-
const unionData = v.value;
|
|
8016
|
-
let remain = unionData.mask & ~tag;
|
|
8017
|
-
if (!remain) {
|
|
8018
|
-
delete v.value;
|
|
8019
|
-
return;
|
|
8020
|
-
}
|
|
8021
|
-
const newData = { mask: remain };
|
|
8022
|
-
while (remain) {
|
|
8023
|
-
const next = remain & remain - 1;
|
|
8024
|
-
const bit = remain - next;
|
|
8025
|
-
newData[bit] = unionData[bit];
|
|
8026
|
-
remain = next;
|
|
8027
|
-
}
|
|
8028
|
-
if (!hasUnionData(newTag)) {
|
|
8029
|
-
v.value = newData[newTag & UnionDataTypeTagsConst];
|
|
8030
|
-
} else {
|
|
8031
|
-
v.value = newData;
|
|
8032
|
-
}
|
|
8033
|
-
}
|
|
8034
|
-
var MaxWidenDepth;
|
|
8035
|
-
var init_union_type = (0, import_chunk_ABYVSU2C.__esm)({
|
|
8036
|
-
"src/type-flow/union-type.ts"() {
|
|
8037
|
-
"use strict";
|
|
8038
|
-
(0, import_chunk_JDC43A3I.init_ast)();
|
|
8039
|
-
init_data_flow();
|
|
8040
|
-
(0, import_chunk_X7QCZR3F.init_util)();
|
|
8041
|
-
init_could_be();
|
|
8042
|
-
init_intersection_type();
|
|
8043
|
-
init_sub_type();
|
|
8044
|
-
init_types();
|
|
8045
|
-
MaxWidenDepth = 4;
|
|
8046
|
-
}
|
|
8047
|
-
});
|
|
8048
|
-
function expandTypedef(t) {
|
|
8049
|
-
const decls = getUnionComponent(
|
|
8050
|
-
t,
|
|
8051
|
-
262144
|
|
8052
|
-
/* Typedef */
|
|
8053
|
-
);
|
|
8054
|
-
const tExpanded = cloneType(t);
|
|
8055
|
-
clearValuesUnder(tExpanded, 262144, true);
|
|
8056
|
-
(0, import_chunk_X7QCZR3F.forEach)(decls, (decl) => unionInto(tExpanded, decl.resolvedType));
|
|
8057
|
-
return tExpanded;
|
|
8058
|
-
}
|
|
8059
|
-
function intersectEnum(t, e) {
|
|
8060
|
-
const enumData = getUnionComponent(
|
|
8061
|
-
e,
|
|
8062
|
-
65536
|
|
8063
|
-
/* Enum */
|
|
8064
|
-
);
|
|
8065
|
-
const e2 = cloneType(e);
|
|
8066
|
-
const i = intersection(
|
|
8067
|
-
t,
|
|
8068
|
-
!enumData ? { type: EnumTagsConst } : enumData.value ? enumData.value : enumData.enum?.resolvedType || { type: EnumTagsConst }
|
|
8069
|
-
);
|
|
8070
|
-
if (e2.value != null) {
|
|
8071
|
-
clearValuesUnder(e2, 65536, true);
|
|
8072
|
-
} else {
|
|
8073
|
-
e2.type &= ~65536;
|
|
8074
|
-
}
|
|
8075
|
-
const rest = intersection(t, e2);
|
|
8076
|
-
if (i.type === 0) {
|
|
8077
|
-
return rest;
|
|
8078
|
-
}
|
|
8079
|
-
const result = enumData ? { type: 65536, value: { ...enumData, value: i } } : cloneType(i);
|
|
8080
|
-
unionInto(result, rest);
|
|
8081
|
-
return result;
|
|
8082
|
-
}
|
|
8083
|
-
function intersection(a, b) {
|
|
8084
|
-
if (a.type & 262144 && a.value != null) {
|
|
8085
|
-
return intersection(expandTypedef(a), b);
|
|
8086
|
-
}
|
|
8087
|
-
if (b.type & 262144 && b.value != null) {
|
|
8088
|
-
return intersection(a, expandTypedef(b));
|
|
8089
|
-
}
|
|
8090
|
-
let common = a.type & b.type & ~262144;
|
|
8091
|
-
if (a.type & 32768 && b.type & ObjectLikeTagsConst && getObjectValue(a) == null) {
|
|
8092
|
-
common |= b.type & ObjectLikeTagsConst;
|
|
8093
|
-
}
|
|
8094
|
-
if (b.type & 32768 && a.type & ObjectLikeTagsConst && getObjectValue(b) == null) {
|
|
8095
|
-
common |= a.type & ObjectLikeTagsConst;
|
|
8096
|
-
}
|
|
8097
|
-
if (a.type & 65536 && b.type & EnumTagsConst && !(b.type & 65536)) {
|
|
8098
|
-
return intersectEnum(b, a);
|
|
8099
|
-
}
|
|
8100
|
-
if (b.type & 65536 && a.type & EnumTagsConst && !(a.type & 65536)) {
|
|
8101
|
-
return intersectEnum(a, b);
|
|
8102
|
-
}
|
|
8103
|
-
if (!common) {
|
|
8104
|
-
return {
|
|
8105
|
-
type: 0
|
|
8106
|
-
/* Never */
|
|
8107
|
-
};
|
|
8108
|
-
}
|
|
8109
|
-
if (a.value == null) {
|
|
8110
|
-
if (b.value == null) {
|
|
8111
|
-
return { type: common };
|
|
8112
|
-
}
|
|
8113
|
-
const result2 = cloneType(b);
|
|
8114
|
-
clearValuesUnder(result2, b.type & ~common, true);
|
|
8115
|
-
return result2;
|
|
8116
|
-
}
|
|
8117
|
-
if (b.value == null) {
|
|
8118
|
-
const result2 = cloneType(a);
|
|
8119
|
-
clearValuesUnder(result2, a.type & ~common, true);
|
|
8120
|
-
return result2;
|
|
8121
|
-
}
|
|
8122
|
-
let mask = 0;
|
|
8123
|
-
const result = {};
|
|
8124
|
-
forEachUnionComponent(a, common, (ac) => {
|
|
8125
|
-
const bvalue = getUnionComponent(b, ac.type);
|
|
8126
|
-
if (ac.value == null) {
|
|
8127
|
-
if (!bvalue)
|
|
8128
|
-
return;
|
|
8129
|
-
result[ac.type] = bvalue;
|
|
8130
|
-
mask |= ac.type;
|
|
8131
|
-
return;
|
|
8132
|
-
}
|
|
8133
|
-
if (bvalue === null || ac.value === bvalue) {
|
|
8134
|
-
result[ac.type] = ac.value;
|
|
8135
|
-
mask |= ac.type;
|
|
8136
|
-
return;
|
|
8137
|
-
}
|
|
8138
|
-
const ivalue = intersectionValue({
|
|
8139
|
-
type: ac.type,
|
|
8140
|
-
avalue: ac.value,
|
|
8141
|
-
bvalue
|
|
8142
|
-
});
|
|
8143
|
-
if (ivalue != null) {
|
|
8144
|
-
result[ac.type] = ivalue;
|
|
8145
|
-
mask |= ac.type;
|
|
8146
|
-
return;
|
|
8147
|
-
} else {
|
|
8148
|
-
common -= ac.type;
|
|
8149
|
-
}
|
|
8150
|
-
});
|
|
8151
|
-
if (!mask)
|
|
8152
|
-
return { type: common };
|
|
8153
|
-
if (hasUnionData(common)) {
|
|
8154
|
-
return { type: common, value: { ...result, mask } };
|
|
8155
|
-
}
|
|
8156
|
-
if (mask & mask - 1) {
|
|
8157
|
-
throw new Error(
|
|
8158
|
-
`Mask with non-union data had more than one bit set: ${mask}`
|
|
8159
|
-
);
|
|
8160
|
-
}
|
|
8161
|
-
return { type: common, value: result[mask] };
|
|
8162
|
-
}
|
|
8163
|
-
function intersectionValue(pair) {
|
|
8164
|
-
switch (pair.type) {
|
|
8165
|
-
case 1:
|
|
8166
|
-
case 2:
|
|
8167
|
-
case 4:
|
|
8168
|
-
case 262144:
|
|
8169
|
-
throw new Error(`Unexpected TypeTag '${typeTagName(pair.type)}'`);
|
|
8170
|
-
case 8:
|
|
8171
|
-
case 16:
|
|
8172
|
-
case 32:
|
|
8173
|
-
case 64:
|
|
8174
|
-
case 256:
|
|
8175
|
-
case 128:
|
|
8176
|
-
case 131072:
|
|
8177
|
-
return pair.avalue === pair.bvalue ? pair.avalue : null;
|
|
8178
|
-
case 512:
|
|
8179
|
-
return tupleMap(
|
|
8180
|
-
pair.avalue,
|
|
8181
|
-
(av) => tupleMap(
|
|
8182
|
-
pair.bvalue,
|
|
8183
|
-
(bv) => {
|
|
8184
|
-
if (av.length !== bv.length)
|
|
8185
|
-
return null;
|
|
8186
|
-
const isect = av.map((t, i) => intersection(t, bv[i]));
|
|
8187
|
-
return isect.some(
|
|
8188
|
-
(t) => t.type === 0
|
|
8189
|
-
/* Never */
|
|
8190
|
-
) ? null : isect;
|
|
8191
|
-
},
|
|
8192
|
-
(bv) => {
|
|
8193
|
-
const isect = av.map((t) => intersection(bv, t));
|
|
8194
|
-
return isect.some(
|
|
8195
|
-
(t) => t.type === 0
|
|
8196
|
-
/* Never */
|
|
8197
|
-
) ? null : isect;
|
|
8198
|
-
},
|
|
8199
|
-
(bv) => bv.length === 0 ? null : bv
|
|
8200
|
-
),
|
|
8201
|
-
(av) => tupleMap(
|
|
8202
|
-
pair.bvalue,
|
|
8203
|
-
(bv) => {
|
|
8204
|
-
const isect = bv.map((t) => intersection(av, t));
|
|
8205
|
-
return isect.some(
|
|
8206
|
-
(t) => t.type === 0
|
|
8207
|
-
/* Never */
|
|
8208
|
-
) ? null : isect;
|
|
8209
|
-
},
|
|
8210
|
-
(bv) => {
|
|
8211
|
-
const atype = intersection(av, bv);
|
|
8212
|
-
return atype.type === 0 ? null : atype;
|
|
8213
|
-
},
|
|
8214
|
-
(bv) => bv.length === 0 ? null : bv
|
|
8215
|
-
),
|
|
8216
|
-
(av) => {
|
|
8217
|
-
const result = av.flat(1);
|
|
8218
|
-
return result.length === 0 ? null : tupleReduce(result);
|
|
8219
|
-
}
|
|
8220
|
-
);
|
|
8221
|
-
case 1024: {
|
|
8222
|
-
if (!pair.avalue.value) {
|
|
8223
|
-
if (!pair.bvalue.value) {
|
|
8224
|
-
const result = new Map(pair.avalue);
|
|
8225
|
-
pair.bvalue.forEach((bv, key) => {
|
|
8226
|
-
const av = result.get(key);
|
|
8227
|
-
if (av) {
|
|
8228
|
-
bv = intersection(bv, av);
|
|
8229
|
-
}
|
|
8230
|
-
result.set(key, bv);
|
|
8231
|
-
});
|
|
8232
|
-
return result;
|
|
8233
|
-
} else {
|
|
8234
|
-
return pair.bvalue;
|
|
8235
|
-
}
|
|
8236
|
-
} else if (!pair.bvalue.value) {
|
|
8237
|
-
return pair.avalue;
|
|
8238
|
-
}
|
|
8239
|
-
const dkey = intersection(pair.avalue.key, pair.bvalue.key);
|
|
8240
|
-
const dvalue = intersection(pair.avalue.value, pair.bvalue.value);
|
|
8241
|
-
return dkey.type !== 0 && dvalue.type !== 0 ? { key: dkey, value: dvalue } : null;
|
|
8242
|
-
}
|
|
8243
|
-
case 2048: {
|
|
8244
|
-
if (pair.avalue.args.length !== pair.bvalue.args.length)
|
|
8245
|
-
return null;
|
|
8246
|
-
const mresult = intersection(pair.avalue.result, pair.bvalue.result);
|
|
8247
|
-
if (mresult.type === 0)
|
|
8248
|
-
return null;
|
|
8249
|
-
const margs = pair.avalue.args.map((aarg, i) => {
|
|
8250
|
-
aarg = cloneType(aarg);
|
|
8251
|
-
unionInto(aarg, pair.bvalue.args[i]);
|
|
8252
|
-
return aarg;
|
|
8253
|
-
});
|
|
8254
|
-
if (margs.some(
|
|
8255
|
-
(arg) => arg.type === 0
|
|
8256
|
-
/* Never */
|
|
8257
|
-
))
|
|
8258
|
-
return null;
|
|
8259
|
-
return { result: mresult, args: margs };
|
|
8260
|
-
}
|
|
8261
|
-
case 4096:
|
|
8262
|
-
case 8192: {
|
|
8263
|
-
const common = /* @__PURE__ */ new Set();
|
|
8264
|
-
(0, import_chunk_X7QCZR3F.forEach)(
|
|
8265
|
-
pair.avalue,
|
|
8266
|
-
(sna) => (0, import_chunk_X7QCZR3F.some)(pair.bvalue, (snb) => sna === snb) && common.add(sna)
|
|
8267
|
-
);
|
|
8268
|
-
if (!common.size)
|
|
8269
|
-
return null;
|
|
8270
|
-
const arr = Array.from(common);
|
|
8271
|
-
return arr.length === 1 ? arr[0] : arr;
|
|
8272
|
-
}
|
|
8273
|
-
case 16384: {
|
|
8274
|
-
const common = /* @__PURE__ */ new Set();
|
|
8275
|
-
(0, import_chunk_X7QCZR3F.forEach)(pair.avalue, (sna) => {
|
|
8276
|
-
const superA = getSuperClasses(sna);
|
|
8277
|
-
(0, import_chunk_X7QCZR3F.forEach)(pair.bvalue, (snb) => {
|
|
8278
|
-
if (sna === snb || superA && superA.has(snb)) {
|
|
8279
|
-
common.add(sna);
|
|
8280
|
-
}
|
|
8281
|
-
const superB = getSuperClasses(snb);
|
|
8282
|
-
if (superB && superB.has(sna)) {
|
|
8283
|
-
common.add(snb);
|
|
8284
|
-
}
|
|
8285
|
-
});
|
|
8286
|
-
});
|
|
8287
|
-
if (!common.size)
|
|
8288
|
-
return null;
|
|
8289
|
-
const arr = Array.from(common);
|
|
8290
|
-
return arr.length === 1 ? arr[0] : arr;
|
|
8291
|
-
}
|
|
8292
|
-
case 32768: {
|
|
8293
|
-
const klass = intersection(pair.avalue.klass, pair.bvalue.klass);
|
|
8294
|
-
const obj = intersectObj(pair.avalue.obj, pair.bvalue.obj);
|
|
8295
|
-
return klass.type !== 16384 || klass.value == null ? null : obj ? { klass, obj } : { klass };
|
|
8296
|
-
}
|
|
8297
|
-
case 65536: {
|
|
8298
|
-
if (pair.avalue.enum !== pair.bvalue.enum && pair.avalue.enum && pair.bvalue.enum) {
|
|
8299
|
-
return null;
|
|
8300
|
-
}
|
|
8301
|
-
const enumDecl = pair.avalue.enum || pair.bvalue.enum;
|
|
8302
|
-
if (pair.avalue.value != null) {
|
|
8303
|
-
if (pair.bvalue.value != null) {
|
|
8304
|
-
const value2 = intersection(pair.avalue.value, pair.bvalue.value);
|
|
8305
|
-
const e = { enum: enumDecl, value: value2 };
|
|
8306
|
-
return e;
|
|
8307
|
-
}
|
|
8308
|
-
return pair.avalue.value;
|
|
8309
|
-
}
|
|
8310
|
-
return pair.bvalue;
|
|
8311
|
-
}
|
|
8312
|
-
default:
|
|
8313
|
-
unhandledType(pair);
|
|
8314
|
-
}
|
|
8315
|
-
}
|
|
8316
|
-
function intersectObj(to, from) {
|
|
8317
|
-
if (!to)
|
|
8318
|
-
return from;
|
|
8319
|
-
if (!from)
|
|
8320
|
-
return to;
|
|
8321
|
-
let result = to;
|
|
8322
|
-
Object.entries(from).forEach(([key, value2]) => {
|
|
8323
|
-
if (!(0, import_chunk_JDC43A3I.hasProperty)(to, key)) {
|
|
8324
|
-
if (result === to)
|
|
8325
|
-
result = { ...result };
|
|
8326
|
-
result[key] = value2;
|
|
8327
|
-
return;
|
|
8328
|
-
}
|
|
8329
|
-
if (result === to)
|
|
8330
|
-
result = { ...result };
|
|
8331
|
-
result[key] = intersection(to[key], value2);
|
|
8332
|
-
});
|
|
8333
|
-
return result;
|
|
8334
|
-
}
|
|
8335
|
-
function fixupEnum(a, b_restricted, b) {
|
|
8336
|
-
if (b.type & 65536) {
|
|
8337
|
-
const bvalue = getUnionComponent(
|
|
8338
|
-
b,
|
|
8339
|
-
65536
|
|
8340
|
-
/* Enum */
|
|
8341
|
-
);
|
|
8342
|
-
const br = restrictByEquality(
|
|
8343
|
-
a,
|
|
8344
|
-
bvalue && (bvalue.value || bvalue.enum?.resolvedType) || {
|
|
8345
|
-
type: EnumTagsConst
|
|
8346
|
-
}
|
|
8347
|
-
);
|
|
8348
|
-
if (br.type) {
|
|
8349
|
-
b_restricted = cloneType(b_restricted);
|
|
8350
|
-
unionInto(
|
|
8351
|
-
b_restricted,
|
|
8352
|
-
bvalue ? {
|
|
8353
|
-
type: 65536,
|
|
8354
|
-
value: { ...bvalue, value: br }
|
|
8355
|
-
} : br
|
|
8356
|
-
);
|
|
8357
|
-
}
|
|
8358
|
-
}
|
|
8359
|
-
return b_restricted;
|
|
7926
|
+
}
|
|
7927
|
+
return b_restricted;
|
|
8360
7928
|
}
|
|
8361
7929
|
function restrictExactTypesByEquality(a, b) {
|
|
8362
7930
|
switch (a.type) {
|
|
@@ -8512,12 +8080,7 @@ function restrictExactTypesByEquality(a, b) {
|
|
|
8512
8080
|
case 131072:
|
|
8513
8081
|
return intersection(a, b);
|
|
8514
8082
|
case 65536: {
|
|
8515
|
-
return restrictByEquality(
|
|
8516
|
-
a.value && (a.value.value || a.value.enum?.resolvedType) || {
|
|
8517
|
-
type: EnumTagsConst
|
|
8518
|
-
},
|
|
8519
|
-
b
|
|
8520
|
-
);
|
|
8083
|
+
return restrictByEquality(typeFromEnumValue(a.value), b);
|
|
8521
8084
|
}
|
|
8522
8085
|
case 262144:
|
|
8523
8086
|
return restrictByEquality(
|
|
@@ -8589,182 +8152,449 @@ var init_intersection_type = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
8589
8152
|
init_api();
|
|
8590
8153
|
init_data_flow();
|
|
8591
8154
|
(0, import_chunk_X7QCZR3F.init_util)();
|
|
8155
|
+
init_array_type();
|
|
8592
8156
|
init_could_be();
|
|
8593
8157
|
init_interp();
|
|
8594
8158
|
init_types();
|
|
8595
8159
|
init_union_type();
|
|
8596
8160
|
}
|
|
8597
8161
|
});
|
|
8598
|
-
function
|
|
8599
|
-
|
|
8600
|
-
|
|
8162
|
+
function union(to, from) {
|
|
8163
|
+
const result = cloneType(to);
|
|
8164
|
+
unionHelper(result, from, -Infinity);
|
|
8165
|
+
return result;
|
|
8166
|
+
}
|
|
8167
|
+
function unionInto(to, from) {
|
|
8168
|
+
return unionHelper(to, from, -Infinity);
|
|
8169
|
+
}
|
|
8170
|
+
function unionHelper(to, from, widenDepth) {
|
|
8171
|
+
if (to == null || from == null) {
|
|
8172
|
+
throw new Error("Null");
|
|
8601
8173
|
}
|
|
8602
|
-
if (
|
|
8603
|
-
return
|
|
8174
|
+
if (from.type === 0 || to === from)
|
|
8175
|
+
return false;
|
|
8176
|
+
if (to.type === 0) {
|
|
8177
|
+
to.type = from.type;
|
|
8178
|
+
to.value = from.value;
|
|
8179
|
+
return true;
|
|
8604
8180
|
}
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
-
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
|
|
8614
|
-
},
|
|
8615
|
-
b
|
|
8616
|
-
)) {
|
|
8181
|
+
const newTags = to.type | from.type;
|
|
8182
|
+
if (!(from.type & ~SingletonTypeTagsConst)) {
|
|
8183
|
+
if (newTags === to.type)
|
|
8184
|
+
return false;
|
|
8185
|
+
to.type = newTags;
|
|
8186
|
+
return true;
|
|
8187
|
+
}
|
|
8188
|
+
if (newTags === to.type) {
|
|
8189
|
+
if (to.value === from.value || to.value == null) {
|
|
8617
8190
|
return false;
|
|
8618
8191
|
}
|
|
8619
|
-
if (
|
|
8192
|
+
if (from.value == null) {
|
|
8193
|
+
clearValuesUnder(to, from.type);
|
|
8620
8194
|
return true;
|
|
8621
|
-
const a2 = cloneType(a);
|
|
8622
|
-
clearValuesUnder(a2, 65536, true);
|
|
8623
|
-
return subtypeOf(a2, b);
|
|
8624
|
-
}
|
|
8625
|
-
let common = a.type & b.type;
|
|
8626
|
-
if (common !== a.type) {
|
|
8627
|
-
if (b.type & 32768 && getObjectValue(b) == null) {
|
|
8628
|
-
common |= a.type & ObjectLikeTagsConst;
|
|
8629
8195
|
}
|
|
8630
|
-
|
|
8631
|
-
return false;
|
|
8196
|
+
return mergeMultiple(to, from, widenDepth);
|
|
8632
8197
|
}
|
|
8633
|
-
if (
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
forEachUnionComponent(b, common, (bc) => {
|
|
8637
|
-
const avalue = getUnionComponent(a, bc.type);
|
|
8638
|
-
if (bc.value == null || avalue === bc.value)
|
|
8198
|
+
if (to.value != null) {
|
|
8199
|
+
if (from.value == null) {
|
|
8200
|
+
clearValuesUnder(to, from.type);
|
|
8639
8201
|
return true;
|
|
8640
|
-
if (avalue == null || !subtypeOfValue({ type: bc.type, avalue, bvalue: bc.value })) {
|
|
8641
|
-
result = false;
|
|
8642
|
-
return false;
|
|
8643
8202
|
}
|
|
8203
|
+
mergeMultiple(to, from, widenDepth);
|
|
8204
|
+
return true;
|
|
8205
|
+
}
|
|
8206
|
+
if (from.value == null) {
|
|
8207
|
+
to.type = newTags;
|
|
8644
8208
|
return true;
|
|
8209
|
+
}
|
|
8210
|
+
const tmp = cloneType(from);
|
|
8211
|
+
clearValuesUnder(tmp, to.type);
|
|
8212
|
+
to.type = tmp.type;
|
|
8213
|
+
to.value = tmp.value;
|
|
8214
|
+
return true;
|
|
8215
|
+
}
|
|
8216
|
+
function mergeMultiple(to, from, widenDepth) {
|
|
8217
|
+
const newTags = to.type | from.type;
|
|
8218
|
+
let anyChanged = newTags !== to.type;
|
|
8219
|
+
let mask = 0;
|
|
8220
|
+
const result = {};
|
|
8221
|
+
forEachUnionComponent(to, newTags, (ac) => {
|
|
8222
|
+
const fromv = getUnionComponent(from, ac.type);
|
|
8223
|
+
if (ac.value != null) {
|
|
8224
|
+
if (fromv != null) {
|
|
8225
|
+
const [value2, changed] = ac.value === fromv ? [fromv, false] : mergeSingle(
|
|
8226
|
+
{
|
|
8227
|
+
type: ac.type,
|
|
8228
|
+
avalue: ac.value,
|
|
8229
|
+
bvalue: fromv
|
|
8230
|
+
},
|
|
8231
|
+
widenDepth
|
|
8232
|
+
);
|
|
8233
|
+
if (changed)
|
|
8234
|
+
anyChanged = true;
|
|
8235
|
+
if (value2) {
|
|
8236
|
+
mask |= ac.type;
|
|
8237
|
+
result[ac.type] = value2;
|
|
8238
|
+
}
|
|
8239
|
+
} else if (!(from.type & ac.type)) {
|
|
8240
|
+
mask |= ac.type;
|
|
8241
|
+
result[ac.type] = ac.value;
|
|
8242
|
+
} else {
|
|
8243
|
+
anyChanged = true;
|
|
8244
|
+
}
|
|
8245
|
+
} else if (fromv && !(to.type & ac.type)) {
|
|
8246
|
+
anyChanged = true;
|
|
8247
|
+
mask |= ac.type;
|
|
8248
|
+
result[ac.type] = fromv;
|
|
8249
|
+
}
|
|
8645
8250
|
});
|
|
8646
|
-
|
|
8251
|
+
if (!anyChanged)
|
|
8252
|
+
return false;
|
|
8253
|
+
to.type = newTags;
|
|
8254
|
+
if (!mask) {
|
|
8255
|
+
delete to.value;
|
|
8256
|
+
return true;
|
|
8257
|
+
}
|
|
8258
|
+
if (hasUnionData(newTags)) {
|
|
8259
|
+
to.value = result;
|
|
8260
|
+
to.value.mask = mask;
|
|
8261
|
+
return true;
|
|
8262
|
+
}
|
|
8263
|
+
if (mask & mask - 1) {
|
|
8264
|
+
throw new Error("Union incorrectly produced a UnionData");
|
|
8265
|
+
}
|
|
8266
|
+
to.value = result[mask];
|
|
8267
|
+
return true;
|
|
8647
8268
|
}
|
|
8648
|
-
function
|
|
8269
|
+
function mergeSingle(pair, widenDepth) {
|
|
8270
|
+
function tryUnion(to, from) {
|
|
8271
|
+
to = cloneType(to);
|
|
8272
|
+
if (unionHelper(to, from, widenDepth + 1))
|
|
8273
|
+
return to;
|
|
8274
|
+
return null;
|
|
8275
|
+
}
|
|
8649
8276
|
switch (pair.type) {
|
|
8650
8277
|
case 1:
|
|
8651
8278
|
case 2:
|
|
8652
8279
|
case 4:
|
|
8653
|
-
|
|
8654
|
-
throw new Error(`Unexpected TypeTag '${typeTagName(pair.type)}'`);
|
|
8280
|
+
throw new Error("Unexpected TypeTag in mergeSingle");
|
|
8655
8281
|
case 8:
|
|
8656
8282
|
case 16:
|
|
8657
8283
|
case 32:
|
|
8658
8284
|
case 64:
|
|
8659
|
-
case 256:
|
|
8660
8285
|
case 128:
|
|
8286
|
+
case 256:
|
|
8661
8287
|
case 131072:
|
|
8662
|
-
return
|
|
8288
|
+
return [null, true];
|
|
8663
8289
|
case 512: {
|
|
8664
|
-
|
|
8290
|
+
if (widenDepth > MaxWidenDepth) {
|
|
8291
|
+
return [null, true];
|
|
8292
|
+
}
|
|
8293
|
+
const tupleTypes = /* @__PURE__ */ new Map();
|
|
8294
|
+
const arrayTypes = [];
|
|
8295
|
+
tupleForEach(
|
|
8296
|
+
pair.avalue,
|
|
8297
|
+
(v) => {
|
|
8298
|
+
const t = tupleTypes.get(v.length);
|
|
8299
|
+
if (t) {
|
|
8300
|
+
t.push(v);
|
|
8301
|
+
} else {
|
|
8302
|
+
tupleTypes.set(v.length, [v]);
|
|
8303
|
+
}
|
|
8304
|
+
},
|
|
8305
|
+
(v) => arrayTypes.push(v)
|
|
8306
|
+
);
|
|
8307
|
+
const extraTypes = [];
|
|
8665
8308
|
tupleForEach(
|
|
8666
|
-
pair.
|
|
8667
|
-
(
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
|
|
8677
|
-
return result = some2;
|
|
8309
|
+
pair.bvalue,
|
|
8310
|
+
(v) => {
|
|
8311
|
+
const tuples = tupleTypes.get(v.length);
|
|
8312
|
+
if (!tuples?.some(
|
|
8313
|
+
(t) => t.every((at, i) => {
|
|
8314
|
+
const bt = v[i];
|
|
8315
|
+
return subtypeOf(at, bt) && subtypeOf(bt, at);
|
|
8316
|
+
})
|
|
8317
|
+
)) {
|
|
8318
|
+
extraTypes.push(v);
|
|
8319
|
+
}
|
|
8678
8320
|
},
|
|
8679
|
-
(
|
|
8680
|
-
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
() => {
|
|
8684
|
-
return true;
|
|
8685
|
-
},
|
|
8686
|
-
(bv) => (some2 = subtypeOf(av, bv)) === false
|
|
8687
|
-
);
|
|
8688
|
-
return result = some2;
|
|
8321
|
+
(v) => {
|
|
8322
|
+
if (!arrayTypes.some((at) => subtypeOf(at, v) && subtypeOf(v, at))) {
|
|
8323
|
+
extraTypes.push(v);
|
|
8324
|
+
}
|
|
8689
8325
|
}
|
|
8690
8326
|
);
|
|
8691
|
-
|
|
8327
|
+
if (extraTypes.length) {
|
|
8328
|
+
if (widenDepth >= 0) {
|
|
8329
|
+
return [null, true];
|
|
8330
|
+
}
|
|
8331
|
+
const allTypes = (pair.avalue instanceof Set ? Array.from(pair.avalue) : [pair.avalue]).concat(extraTypes);
|
|
8332
|
+
return [tupleReduce(allTypes), true];
|
|
8333
|
+
}
|
|
8334
|
+
return [pair.avalue, false];
|
|
8692
8335
|
}
|
|
8693
8336
|
case 1024: {
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
|
|
8337
|
+
if (widenDepth > MaxWidenDepth) {
|
|
8338
|
+
return [null, true];
|
|
8339
|
+
}
|
|
8340
|
+
const avalue = pair.avalue;
|
|
8341
|
+
const bvalue = pair.bvalue;
|
|
8342
|
+
if (!avalue.value) {
|
|
8343
|
+
if (!bvalue.value) {
|
|
8344
|
+
const result = new Map(avalue);
|
|
8345
|
+
let merged = false;
|
|
8346
|
+
result.forEach((av, key2) => {
|
|
8347
|
+
const bv = bvalue.get(key2);
|
|
8348
|
+
if (!bv) {
|
|
8349
|
+
result.delete(key2);
|
|
8350
|
+
merged = true;
|
|
8351
|
+
return;
|
|
8352
|
+
}
|
|
8353
|
+
av = cloneType(av);
|
|
8354
|
+
if (unionHelper(av, bv, widenDepth + 1))
|
|
8355
|
+
merged = true;
|
|
8356
|
+
result.set(key2, av);
|
|
8357
|
+
});
|
|
8358
|
+
return [result, merged];
|
|
8359
|
+
} else {
|
|
8360
|
+
const result = new Map(avalue);
|
|
8361
|
+
let merged = false;
|
|
8362
|
+
result.forEach((av, key2) => {
|
|
8363
|
+
const keyType = typeFromObjectLiteralKey(key2);
|
|
8364
|
+
if (couldBe(keyType, bvalue.key)) {
|
|
8365
|
+
const bv = tryUnion(av, bvalue.value);
|
|
8366
|
+
if (bv) {
|
|
8367
|
+
result.set(key2, bv);
|
|
8368
|
+
merged = true;
|
|
8369
|
+
}
|
|
8370
|
+
}
|
|
8701
8371
|
});
|
|
8372
|
+
return [result, merged];
|
|
8702
8373
|
}
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
|
|
8706
|
-
|
|
8707
|
-
const
|
|
8708
|
-
|
|
8374
|
+
} else if (!bvalue.value) {
|
|
8375
|
+
const result = new Map(bvalue);
|
|
8376
|
+
let merged = false;
|
|
8377
|
+
result.forEach((bv, key2) => {
|
|
8378
|
+
const keyType = typeFromObjectLiteralKey(key2);
|
|
8379
|
+
if (couldBe(keyType, avalue.key)) {
|
|
8380
|
+
const av = tryUnion(bv, avalue.value);
|
|
8381
|
+
if (av) {
|
|
8382
|
+
result.set(key2, av);
|
|
8383
|
+
merged = true;
|
|
8384
|
+
}
|
|
8385
|
+
}
|
|
8709
8386
|
});
|
|
8387
|
+
return [result, merged];
|
|
8710
8388
|
}
|
|
8711
|
-
|
|
8389
|
+
const { key, value: value2 } = avalue;
|
|
8390
|
+
const keyChange = tryUnion(key, bvalue.key);
|
|
8391
|
+
const valueChange = tryUnion(value2, bvalue.value);
|
|
8392
|
+
if (keyChange || valueChange) {
|
|
8393
|
+
return [{ key: keyChange || key, value: valueChange || value2 }, true];
|
|
8394
|
+
}
|
|
8395
|
+
return [pair.avalue, false];
|
|
8712
8396
|
}
|
|
8713
8397
|
case 2048: {
|
|
8714
|
-
|
|
8398
|
+
if (pair.avalue.args.length !== pair.bvalue.args.length)
|
|
8399
|
+
return [null, true];
|
|
8400
|
+
const resultChange = tryUnion(pair.avalue.result, pair.bvalue.result);
|
|
8401
|
+
const args = pair.avalue.args.map(
|
|
8402
|
+
(arg, i) => intersection(arg, pair.bvalue.args[i])
|
|
8403
|
+
);
|
|
8404
|
+
if (args.some(
|
|
8405
|
+
(arg) => arg.type === 0
|
|
8406
|
+
/* Never */
|
|
8407
|
+
)) {
|
|
8408
|
+
return [null, true];
|
|
8409
|
+
}
|
|
8410
|
+
const argsChanged = args.some(
|
|
8411
|
+
(arg, i) => !subtypeOf(pair.avalue.args[i], arg)
|
|
8412
|
+
);
|
|
8413
|
+
if (resultChange || argsChanged) {
|
|
8414
|
+
return [{ result: resultChange || pair.avalue.result, args }, true];
|
|
8415
|
+
}
|
|
8416
|
+
return [pair.avalue, false];
|
|
8715
8417
|
}
|
|
8716
8418
|
case 4096:
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
|
|
8419
|
+
return mergeStateDecls(pair.avalue, pair.bvalue);
|
|
8420
|
+
case 8192:
|
|
8421
|
+
return mergeStateDecls(pair.avalue, pair.bvalue);
|
|
8422
|
+
case 16384:
|
|
8423
|
+
return mergeStateDecls(pair.avalue, pair.bvalue);
|
|
8424
|
+
case 262144:
|
|
8425
|
+
return mergeStateDecls(pair.avalue, pair.bvalue);
|
|
8426
|
+
case 32768: {
|
|
8427
|
+
let klass = pair.avalue.klass;
|
|
8428
|
+
const [obj, objChanged] = mergeObjectValues(
|
|
8429
|
+
pair.avalue.obj,
|
|
8430
|
+
pair.bvalue.obj,
|
|
8431
|
+
widenDepth
|
|
8432
|
+
);
|
|
8433
|
+
const klassChanged = tryUnion(klass, pair.bvalue.klass);
|
|
8434
|
+
if (klassChanged || objChanged) {
|
|
8435
|
+
klass = klassChanged || klass;
|
|
8436
|
+
if (obj) {
|
|
8437
|
+
return [{ klass, obj }, true];
|
|
8438
|
+
}
|
|
8439
|
+
return [{ klass }, true];
|
|
8440
|
+
}
|
|
8441
|
+
return [pair.avalue, false];
|
|
8721
8442
|
}
|
|
8722
|
-
case
|
|
8723
|
-
const
|
|
8724
|
-
const
|
|
8725
|
-
|
|
8726
|
-
|
|
8727
|
-
|
|
8728
|
-
|
|
8729
|
-
|
|
8443
|
+
case 65536: {
|
|
8444
|
+
const toE = pair.avalue;
|
|
8445
|
+
const fromE = pair.bvalue;
|
|
8446
|
+
let changed = false;
|
|
8447
|
+
let resultEnum = toE.enum;
|
|
8448
|
+
const s = new Set(
|
|
8449
|
+
Array.isArray(toE.enum) ? toE.enum : [toE.enum]
|
|
8450
|
+
);
|
|
8451
|
+
const size = s.size;
|
|
8452
|
+
(0, import_chunk_X7QCZR3F.forEach)(fromE.enum, (e) => s.add(e));
|
|
8453
|
+
if (size !== s.size) {
|
|
8454
|
+
resultEnum = Array.from(s);
|
|
8455
|
+
changed = true;
|
|
8456
|
+
}
|
|
8457
|
+
let resultValue = toE.value;
|
|
8458
|
+
if (resultValue) {
|
|
8459
|
+
if (fromE.value) {
|
|
8460
|
+
resultValue = cloneType(resultValue);
|
|
8461
|
+
if (unionHelper(resultValue, fromE.value, widenDepth + 1)) {
|
|
8462
|
+
changed = true;
|
|
8730
8463
|
}
|
|
8731
|
-
|
|
8732
|
-
|
|
8733
|
-
|
|
8464
|
+
} else {
|
|
8465
|
+
resultValue = void 0;
|
|
8466
|
+
changed = true;
|
|
8467
|
+
}
|
|
8468
|
+
}
|
|
8469
|
+
if (!changed) {
|
|
8470
|
+
return [toE, false];
|
|
8471
|
+
}
|
|
8472
|
+
return resultValue ? [{ enum: resultEnum, value: resultValue }, changed] : [{ enum: resultEnum }, changed];
|
|
8473
|
+
}
|
|
8474
|
+
default:
|
|
8475
|
+
unhandledType(pair);
|
|
8476
|
+
}
|
|
8477
|
+
}
|
|
8478
|
+
function mergeObjectValues(to, from, widenDepth) {
|
|
8479
|
+
if (!to) {
|
|
8480
|
+
return [to, false];
|
|
8481
|
+
}
|
|
8482
|
+
if (!from) {
|
|
8483
|
+
return [from, true];
|
|
8484
|
+
}
|
|
8485
|
+
let empty = true;
|
|
8486
|
+
let result = to;
|
|
8487
|
+
Object.entries(to).forEach(([key, value2]) => {
|
|
8488
|
+
if (!(0, import_chunk_JDC43A3I.hasProperty)(from, key)) {
|
|
8489
|
+
if (result === to)
|
|
8490
|
+
result = { ...result };
|
|
8491
|
+
delete result[key];
|
|
8492
|
+
return;
|
|
8493
|
+
}
|
|
8494
|
+
const rep = cloneType(value2);
|
|
8495
|
+
if (unionHelper(rep, from[key], widenDepth + 1)) {
|
|
8496
|
+
if (result === to)
|
|
8497
|
+
result = { ...result };
|
|
8498
|
+
result[key] = rep;
|
|
8499
|
+
}
|
|
8500
|
+
empty = false;
|
|
8501
|
+
});
|
|
8502
|
+
if (empty) {
|
|
8503
|
+
return [void 0, true];
|
|
8504
|
+
}
|
|
8505
|
+
return [result, result !== to];
|
|
8506
|
+
}
|
|
8507
|
+
function mergeStateDecls(to, from) {
|
|
8508
|
+
let changed = false;
|
|
8509
|
+
let result = to;
|
|
8510
|
+
(0, import_chunk_X7QCZR3F.forEach)(from, (v) => {
|
|
8511
|
+
if ((0, import_chunk_X7QCZR3F.some)(to, (t) => t === v)) {
|
|
8512
|
+
return;
|
|
8513
|
+
}
|
|
8514
|
+
if (Array.isArray(result)) {
|
|
8515
|
+
if (result === to) {
|
|
8516
|
+
result = [...result, v];
|
|
8517
|
+
} else {
|
|
8518
|
+
result.push(v);
|
|
8519
|
+
}
|
|
8520
|
+
} else {
|
|
8521
|
+
result = [to, v];
|
|
8522
|
+
}
|
|
8523
|
+
changed = true;
|
|
8524
|
+
});
|
|
8525
|
+
return [result, changed];
|
|
8526
|
+
}
|
|
8527
|
+
function nonUnionDataMask(tag) {
|
|
8528
|
+
if (tag & tag - 1) {
|
|
8529
|
+
return tag & UnionDataTypeTagsConst || tag & ValueTypeTagsConst;
|
|
8530
|
+
}
|
|
8531
|
+
return tag;
|
|
8532
|
+
}
|
|
8533
|
+
function clearValuesUnder(v, tag, clearTag = false) {
|
|
8534
|
+
const newTag = clearTag ? v.type & ~tag : v.type | tag;
|
|
8535
|
+
tag &= ~SingletonTypeTagsConst;
|
|
8536
|
+
if (!tag || v.value == null) {
|
|
8537
|
+
v.type = newTag;
|
|
8538
|
+
return;
|
|
8539
|
+
}
|
|
8540
|
+
if (tag & ValueTypeTagsConst) {
|
|
8541
|
+
tag |= ValueTypeTagsConst;
|
|
8542
|
+
}
|
|
8543
|
+
if (!hasUnionData(v.type)) {
|
|
8544
|
+
const dataMask = nonUnionDataMask(v.type);
|
|
8545
|
+
if (dataMask & tag) {
|
|
8546
|
+
v.type = newTag;
|
|
8547
|
+
delete v.value;
|
|
8548
|
+
return;
|
|
8734
8549
|
}
|
|
8735
|
-
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
return
|
|
8550
|
+
if (dataMask & ValueTypeTagsConst) {
|
|
8551
|
+
delete v.value;
|
|
8552
|
+
v.type = newTag;
|
|
8553
|
+
return;
|
|
8739
8554
|
}
|
|
8740
|
-
|
|
8741
|
-
const
|
|
8742
|
-
|
|
8743
|
-
|
|
8555
|
+
if (hasUnionData(newTag)) {
|
|
8556
|
+
const mask = v.type & UnionDataTypeTagsConst;
|
|
8557
|
+
v.value = {
|
|
8558
|
+
[mask]: v.value,
|
|
8559
|
+
mask
|
|
8560
|
+
};
|
|
8744
8561
|
}
|
|
8745
|
-
|
|
8746
|
-
|
|
8562
|
+
v.type = newTag;
|
|
8563
|
+
return;
|
|
8564
|
+
}
|
|
8565
|
+
v.type = newTag;
|
|
8566
|
+
const unionData = v.value;
|
|
8567
|
+
let remain = unionData.mask & ~tag;
|
|
8568
|
+
if (!remain) {
|
|
8569
|
+
delete v.value;
|
|
8570
|
+
return;
|
|
8571
|
+
}
|
|
8572
|
+
const newData = { mask: remain };
|
|
8573
|
+
while (remain) {
|
|
8574
|
+
const next = remain & remain - 1;
|
|
8575
|
+
const bit = remain - next;
|
|
8576
|
+
newData[bit] = unionData[bit];
|
|
8577
|
+
remain = next;
|
|
8578
|
+
}
|
|
8579
|
+
if (!hasUnionData(newTag)) {
|
|
8580
|
+
v.value = newData[newTag & UnionDataTypeTagsConst];
|
|
8581
|
+
} else {
|
|
8582
|
+
v.value = newData;
|
|
8747
8583
|
}
|
|
8748
8584
|
}
|
|
8749
|
-
|
|
8750
|
-
|
|
8751
|
-
|
|
8752
|
-
return Object.entries(b).every(([key, value2]) => {
|
|
8753
|
-
if (!(0, import_chunk_JDC43A3I.hasProperty)(a, key))
|
|
8754
|
-
return false;
|
|
8755
|
-
return subtypeOf(a[key], value2);
|
|
8756
|
-
});
|
|
8757
|
-
}
|
|
8758
|
-
var init_sub_type = (0, import_chunk_ABYVSU2C.__esm)({
|
|
8759
|
-
"src/type-flow/sub-type.ts"() {
|
|
8585
|
+
var MaxWidenDepth;
|
|
8586
|
+
var init_union_type = (0, import_chunk_ABYVSU2C.__esm)({
|
|
8587
|
+
"src/type-flow/union-type.ts"() {
|
|
8760
8588
|
"use strict";
|
|
8761
|
-
|
|
8589
|
+
(0, import_chunk_JDC43A3I.init_ast)();
|
|
8762
8590
|
init_data_flow();
|
|
8763
8591
|
(0, import_chunk_X7QCZR3F.init_util)();
|
|
8592
|
+
init_array_type();
|
|
8764
8593
|
init_could_be();
|
|
8765
8594
|
init_intersection_type();
|
|
8595
|
+
init_sub_type();
|
|
8766
8596
|
init_types();
|
|
8767
|
-
|
|
8597
|
+
MaxWidenDepth = 4;
|
|
8768
8598
|
}
|
|
8769
8599
|
});
|
|
8770
8600
|
function common_types(left, right, allowed) {
|
|
@@ -9395,6 +9225,75 @@ var init_type_flow_util = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
9395
9225
|
init_union_type();
|
|
9396
9226
|
}
|
|
9397
9227
|
});
|
|
9228
|
+
function getEffectiveTrackedType(constraint, tracked) {
|
|
9229
|
+
if (!(constraint.type & 65536) && tracked.type & 65536) {
|
|
9230
|
+
tracked = deEnumerate(tracked);
|
|
9231
|
+
}
|
|
9232
|
+
if (constraint.type & 262144 && constraint.value != null) {
|
|
9233
|
+
return getEffectiveTrackedType(expandTypedef(constraint), tracked);
|
|
9234
|
+
}
|
|
9235
|
+
if (tracked.type & 262144 && tracked.value != null) {
|
|
9236
|
+
return getEffectiveTrackedType(constraint, expandTypedef(tracked));
|
|
9237
|
+
}
|
|
9238
|
+
let common = constraint.type & tracked.type & ~262144;
|
|
9239
|
+
if (tracked.type & 32768 && constraint.type & ObjectLikeTagsConst && getObjectValue(tracked) == null) {
|
|
9240
|
+
common |= constraint.type & ObjectLikeTagsConst;
|
|
9241
|
+
}
|
|
9242
|
+
if (tracked.type & 65536 && constraint.type & EnumTagsConst && !(constraint.type & 65536)) {
|
|
9243
|
+
common |= constraint.type & typeFromEnumValue(getUnionComponent(
|
|
9244
|
+
tracked,
|
|
9245
|
+
65536
|
|
9246
|
+
/* Enum */
|
|
9247
|
+
)).type;
|
|
9248
|
+
}
|
|
9249
|
+
if (!common) {
|
|
9250
|
+
return {
|
|
9251
|
+
type: 0
|
|
9252
|
+
/* Never */
|
|
9253
|
+
};
|
|
9254
|
+
}
|
|
9255
|
+
if (constraint.value == null) {
|
|
9256
|
+
return { type: common };
|
|
9257
|
+
}
|
|
9258
|
+
if (tracked.value == null) {
|
|
9259
|
+
const result2 = cloneType(constraint);
|
|
9260
|
+
clearValuesUnder(result2, constraint.type & ~common, true);
|
|
9261
|
+
return result2;
|
|
9262
|
+
}
|
|
9263
|
+
const result = {
|
|
9264
|
+
type: 0
|
|
9265
|
+
/* Never */
|
|
9266
|
+
};
|
|
9267
|
+
forEachUnionComponent(constraint, common, (ac) => {
|
|
9268
|
+
common &= ~ac.type;
|
|
9269
|
+
if (couldBe(ac, tracked)) {
|
|
9270
|
+
if (ac.type === 512 && ac.value) {
|
|
9271
|
+
const trackedData = getUnionComponent(tracked, ac.type);
|
|
9272
|
+
if (trackedData) {
|
|
9273
|
+
unionInto(result, {
|
|
9274
|
+
type: 512,
|
|
9275
|
+
value: restrictArrayData(ac.value, trackedData)
|
|
9276
|
+
});
|
|
9277
|
+
return;
|
|
9278
|
+
}
|
|
9279
|
+
}
|
|
9280
|
+
unionInto(result, ac);
|
|
9281
|
+
}
|
|
9282
|
+
});
|
|
9283
|
+
unionInto(result, { type: common });
|
|
9284
|
+
return result;
|
|
9285
|
+
}
|
|
9286
|
+
var init_effective_type = (0, import_chunk_ABYVSU2C.__esm)({
|
|
9287
|
+
"src/type-flow/effective-type.ts"() {
|
|
9288
|
+
"use strict";
|
|
9289
|
+
init_array_type();
|
|
9290
|
+
init_could_be();
|
|
9291
|
+
init_interp();
|
|
9292
|
+
init_intersection_type();
|
|
9293
|
+
init_types();
|
|
9294
|
+
init_union_type();
|
|
9295
|
+
}
|
|
9296
|
+
});
|
|
9398
9297
|
function evaluateCall(istate, node, callee, args) {
|
|
9399
9298
|
while (!hasValue(callee) || callee.type !== 8192) {
|
|
9400
9299
|
const name = node.callee.type === "Identifier" ? node.callee : node.callee.type === "MemberExpression" && !node.callee.computed ? node.callee.property : null;
|
|
@@ -9455,7 +9354,7 @@ function checkCallArgs(istate, node, callees, args) {
|
|
|
9455
9354
|
if (object) {
|
|
9456
9355
|
const info = sysCallInfo(istate.state, cur);
|
|
9457
9356
|
if (info) {
|
|
9458
|
-
const result2 = info(istate, cur, object, () => args);
|
|
9357
|
+
const result2 = info(istate, cur, object, () => args, node);
|
|
9459
9358
|
if (result2.argTypes)
|
|
9460
9359
|
argTypes = result2.argTypes;
|
|
9461
9360
|
if (result2.returnType)
|
|
@@ -9499,59 +9398,21 @@ function checkCallArgs(istate, node, callees, args) {
|
|
|
9499
9398
|
paramType = typeFromTypespec(istate.state, param.right, cur.stack);
|
|
9500
9399
|
}
|
|
9501
9400
|
if (checker(arg, paramType)) {
|
|
9502
|
-
if (istate.state.config?.extraReferenceTypeChecks && effects && argEffects
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
paramType,
|
|
9512
|
-
512
|
|
9513
|
-
/* Array */
|
|
9514
|
-
);
|
|
9515
|
-
if (!ptype || !checkArrayCovariance(atype, ptype)) {
|
|
9516
|
-
curDiags.push([
|
|
9517
|
-
node.arguments[i],
|
|
9518
|
-
`Argument ${i + 1} to ${cur.fullName}: passing ${display(
|
|
9519
|
-
arg
|
|
9520
|
-
)} to parameter ${display(paramType)} is not type safe`
|
|
9521
|
-
]);
|
|
9522
|
-
}
|
|
9523
|
-
}
|
|
9524
|
-
}
|
|
9525
|
-
if (arg.type & 1024) {
|
|
9526
|
-
const adata = getUnionComponent(
|
|
9527
|
-
arg,
|
|
9528
|
-
1024
|
|
9529
|
-
/* Dictionary */
|
|
9530
|
-
);
|
|
9531
|
-
if (adata && adata.value) {
|
|
9532
|
-
const pdata = getUnionComponent(
|
|
9533
|
-
paramType,
|
|
9534
|
-
1024
|
|
9535
|
-
/* Dictionary */
|
|
9536
|
-
);
|
|
9537
|
-
if (!pdata || !pdata.value || !subtypeOf(pdata.key, adata.key) || !subtypeOf(pdata.value, adata.value)) {
|
|
9538
|
-
curDiags.push([
|
|
9539
|
-
node.arguments[i],
|
|
9540
|
-
`Argument ${i + 1} to ${cur.fullName}: passing Dictionary<${display(adata.key)}, ${display(
|
|
9541
|
-
adata.value
|
|
9542
|
-
)}> to parameter ${display(
|
|
9543
|
-
pdata ? {
|
|
9544
|
-
type: 1024,
|
|
9545
|
-
value: pdata
|
|
9546
|
-
} : {
|
|
9547
|
-
type: 1024
|
|
9548
|
-
/* Dictionary */
|
|
9549
|
-
}
|
|
9550
|
-
)} is not type safe`
|
|
9551
|
-
]);
|
|
9401
|
+
if (istate.state.config?.extraReferenceTypeChecks !== false && effects && argEffects) {
|
|
9402
|
+
extraReferenceTypeChecks(
|
|
9403
|
+
istate,
|
|
9404
|
+
(sourceType, targetType) => curDiags.push([
|
|
9405
|
+
node.arguments[i],
|
|
9406
|
+
`Argument ${i + 1} to ${cur.fullName}: passing ${sourceType} to parameter ${targetType} is not type safe`,
|
|
9407
|
+
{
|
|
9408
|
+
uri: "https://github.com/markw65/monkeyc-optimizer/wiki/Extra-Reference-Type-Checks-(prettierMonkeyC.extraReferenceTypeChecks)",
|
|
9409
|
+
message: "more info"
|
|
9552
9410
|
}
|
|
9553
|
-
|
|
9554
|
-
|
|
9411
|
+
]),
|
|
9412
|
+
paramType,
|
|
9413
|
+
arg,
|
|
9414
|
+
node.arguments[i]
|
|
9415
|
+
);
|
|
9555
9416
|
}
|
|
9556
9417
|
return;
|
|
9557
9418
|
}
|
|
@@ -9593,7 +9454,7 @@ function checkCallArgs(istate, node, callees, args) {
|
|
|
9593
9454
|
if (istate.typeChecker) {
|
|
9594
9455
|
if (istate.typeChecker === subtypeOf || allDiags.every((diags) => diags.length > 0)) {
|
|
9595
9456
|
allDiags.flat().forEach(
|
|
9596
|
-
(diag) => diagnostic(istate.state, diag[0], diag[1], istate.checkTypes)
|
|
9457
|
+
(diag) => diagnostic(istate.state, diag[0], diag[1], istate.checkTypes, diag[2])
|
|
9597
9458
|
);
|
|
9598
9459
|
}
|
|
9599
9460
|
}
|
|
@@ -9621,6 +9482,16 @@ function sysCallInfo(state, func) {
|
|
|
9621
9482
|
}
|
|
9622
9483
|
return null;
|
|
9623
9484
|
}
|
|
9485
|
+
function getCallObjectConstrainedType(istate, call, trackedType) {
|
|
9486
|
+
if (call.callee.type !== "MemberExpression")
|
|
9487
|
+
return null;
|
|
9488
|
+
const calleeObjNode = call.callee.object;
|
|
9489
|
+
if (calleeObjNode.type !== "Identifier" && calleeObjNode.type !== "MemberExpression") {
|
|
9490
|
+
return null;
|
|
9491
|
+
}
|
|
9492
|
+
const constraint = getLhsConstraint(istate, calleeObjNode);
|
|
9493
|
+
return constraint && getEffectiveTrackedType(constraint, trackedType);
|
|
9494
|
+
}
|
|
9624
9495
|
function getSystemCallTable(state) {
|
|
9625
9496
|
if (systemCallInfo && systemCallVersion === state.sdk) {
|
|
9626
9497
|
return systemCallInfo;
|
|
@@ -9694,7 +9565,7 @@ function getSystemCallTable(state) {
|
|
|
9694
9565
|
}
|
|
9695
9566
|
return ret;
|
|
9696
9567
|
};
|
|
9697
|
-
const arrayAdd = (istate, callee, calleeObj, getArgs) => {
|
|
9568
|
+
const arrayAdd = (istate, callee, calleeObj, getArgs, call) => {
|
|
9698
9569
|
const ret = {};
|
|
9699
9570
|
if (calleeObj.type & 512) {
|
|
9700
9571
|
const adata = getUnionComponent(
|
|
@@ -9703,8 +9574,19 @@ function getSystemCallTable(state) {
|
|
|
9703
9574
|
/* Array */
|
|
9704
9575
|
);
|
|
9705
9576
|
if (adata) {
|
|
9577
|
+
const constraint = getCallObjectConstrainedType(
|
|
9578
|
+
istate,
|
|
9579
|
+
call,
|
|
9580
|
+
calleeObj
|
|
9581
|
+
);
|
|
9582
|
+
const cdata = (constraint && getUnionComponent(
|
|
9583
|
+
constraint,
|
|
9584
|
+
512
|
|
9585
|
+
/* Array */
|
|
9586
|
+
)) ?? adata;
|
|
9706
9587
|
ret.returnType = { type: 512, value: adata };
|
|
9707
9588
|
const args = getArgs();
|
|
9589
|
+
const checker = istate.typeChecker;
|
|
9708
9590
|
if (args.length === 1) {
|
|
9709
9591
|
const arg = args[0];
|
|
9710
9592
|
let hasTuple = false;
|
|
@@ -9712,33 +9594,38 @@ function getSystemCallTable(state) {
|
|
|
9712
9594
|
const relaxed = relaxType(arg);
|
|
9713
9595
|
tupleMap(
|
|
9714
9596
|
adata,
|
|
9715
|
-
(v) =>
|
|
9716
|
-
|
|
9717
|
-
return [...v, relaxed];
|
|
9718
|
-
},
|
|
9719
|
-
(v) => {
|
|
9720
|
-
if (subtypeOf(arg, v))
|
|
9721
|
-
return v;
|
|
9722
|
-
const newAData = cloneType(v);
|
|
9723
|
-
unionInto(newAData, arg);
|
|
9724
|
-
if (!ret.argTypes) {
|
|
9725
|
-
ret.argTypes = [v];
|
|
9726
|
-
} else {
|
|
9727
|
-
ret.argTypes = [intersection(ret.argTypes[0], v)];
|
|
9728
|
-
}
|
|
9729
|
-
return newAData;
|
|
9730
|
-
},
|
|
9597
|
+
(v) => [...v, relaxed],
|
|
9598
|
+
(v) => subtypeOf(arg, v) ? v : union(v, arg),
|
|
9731
9599
|
(v) => {
|
|
9732
9600
|
const newAData = tupleReduce(v);
|
|
9733
9601
|
ret.returnType.value = newAData;
|
|
9734
9602
|
const newObj = cloneType(calleeObj);
|
|
9735
9603
|
setUnionComponent(newObj, 512, newAData);
|
|
9736
9604
|
ret.calleeObj = newObj;
|
|
9737
|
-
if (!ret.argTypes) {
|
|
9738
|
-
ret.argTypes = [relaxed];
|
|
9739
|
-
}
|
|
9740
9605
|
}
|
|
9741
9606
|
);
|
|
9607
|
+
if (checker) {
|
|
9608
|
+
tupleForEach(
|
|
9609
|
+
cdata,
|
|
9610
|
+
() => {
|
|
9611
|
+
hasTuple = true;
|
|
9612
|
+
},
|
|
9613
|
+
(v) => {
|
|
9614
|
+
if (checker(arg, v))
|
|
9615
|
+
return;
|
|
9616
|
+
if (!ret.argTypes) {
|
|
9617
|
+
ret.argTypes = [v];
|
|
9618
|
+
} else {
|
|
9619
|
+
ret.argTypes = [
|
|
9620
|
+
(checker === subtypeOf ? intersection : union)(
|
|
9621
|
+
ret.argTypes[0],
|
|
9622
|
+
v
|
|
9623
|
+
)
|
|
9624
|
+
];
|
|
9625
|
+
}
|
|
9626
|
+
}
|
|
9627
|
+
);
|
|
9628
|
+
}
|
|
9742
9629
|
} else {
|
|
9743
9630
|
const argSubtypes = arg.type & 512 ? getUnionComponent(
|
|
9744
9631
|
arg,
|
|
@@ -9753,26 +9640,13 @@ function getSystemCallTable(state) {
|
|
|
9753
9640
|
return tupleMap(
|
|
9754
9641
|
argSubtypes,
|
|
9755
9642
|
(a) => [...v, ...a],
|
|
9756
|
-
(a) =>
|
|
9757
|
-
const at = cloneType(reducedType(v));
|
|
9758
|
-
unionInto(at, a);
|
|
9759
|
-
return at;
|
|
9760
|
-
},
|
|
9643
|
+
(a) => union(reducedType(v), a),
|
|
9761
9644
|
(a) => a
|
|
9762
9645
|
);
|
|
9763
9646
|
},
|
|
9764
9647
|
(v) => {
|
|
9765
9648
|
const addedType = reducedArrayType(argSubtypes);
|
|
9766
|
-
|
|
9767
|
-
return [v];
|
|
9768
|
-
if (!ret.argTypes) {
|
|
9769
|
-
ret.argTypes = [v];
|
|
9770
|
-
} else {
|
|
9771
|
-
ret.argTypes = [intersection(ret.argTypes[0], v)];
|
|
9772
|
-
}
|
|
9773
|
-
v = cloneType(v);
|
|
9774
|
-
unionInto(v, addedType);
|
|
9775
|
-
return [v];
|
|
9649
|
+
return [subtypeOf(addedType, v) ? v : union(v, addedType)];
|
|
9776
9650
|
},
|
|
9777
9651
|
(va) => {
|
|
9778
9652
|
const newAData = tupleReduce(va.flat());
|
|
@@ -9780,18 +9654,36 @@ function getSystemCallTable(state) {
|
|
|
9780
9654
|
const newObj = cloneType(calleeObj);
|
|
9781
9655
|
setUnionComponent(newObj, 512, newAData);
|
|
9782
9656
|
ret.calleeObj = newObj;
|
|
9783
|
-
if (!ret.argTypes) {
|
|
9784
|
-
ret.argTypes = [
|
|
9785
|
-
{ type: 512, value: argSubtypes }
|
|
9786
|
-
];
|
|
9787
|
-
}
|
|
9788
9657
|
}
|
|
9789
9658
|
);
|
|
9790
|
-
|
|
9659
|
+
if (checker) {
|
|
9660
|
+
tupleForEach(
|
|
9661
|
+
adata,
|
|
9662
|
+
() => {
|
|
9663
|
+
hasTuple = true;
|
|
9664
|
+
},
|
|
9665
|
+
(v) => {
|
|
9666
|
+
const addedType = reducedArrayType(argSubtypes);
|
|
9667
|
+
if (subtypeOf(addedType, v))
|
|
9668
|
+
return;
|
|
9669
|
+
if (!ret.argTypes) {
|
|
9670
|
+
ret.argTypes = [v];
|
|
9671
|
+
} else {
|
|
9672
|
+
ret.argTypes = [
|
|
9673
|
+
(checker === subtypeOf ? intersection : union)(
|
|
9674
|
+
ret.argTypes[0],
|
|
9675
|
+
v
|
|
9676
|
+
)
|
|
9677
|
+
];
|
|
9678
|
+
}
|
|
9679
|
+
}
|
|
9680
|
+
);
|
|
9681
|
+
}
|
|
9682
|
+
} else if (checker) {
|
|
9791
9683
|
tupleForEach(
|
|
9792
|
-
|
|
9684
|
+
cdata,
|
|
9793
9685
|
() => hasTuple = true,
|
|
9794
|
-
() =>
|
|
9686
|
+
() => true
|
|
9795
9687
|
);
|
|
9796
9688
|
}
|
|
9797
9689
|
}
|
|
@@ -10104,6 +9996,7 @@ function getSystemCallTable(state) {
|
|
|
10104
9996
|
}
|
|
10105
9997
|
return results;
|
|
10106
9998
|
};
|
|
9999
|
+
const mathDefault = (istate, callee, calleeObj, getArgs) => mathHelper(istate, callee, calleeObj, getArgs);
|
|
10107
10000
|
systemCallVersion = state.sdk;
|
|
10108
10001
|
return systemCallInfo = expandKeys(state, {
|
|
10109
10002
|
"$.Toybox.Lang.Array.add": arrayAdd,
|
|
@@ -10127,12 +10020,12 @@ function getSystemCallTable(state) {
|
|
|
10127
10020
|
"$.Toybox.Lang.Method.invoke": methodInvoke,
|
|
10128
10021
|
"$.Toybox.Lang.Object.method": method,
|
|
10129
10022
|
"$.Toybox.Lang.*.toNumber": toNumber,
|
|
10130
|
-
"$.Toybox.Math.acos":
|
|
10131
|
-
"$.Toybox.Math.asin":
|
|
10132
|
-
"$.Toybox.Math.atan":
|
|
10133
|
-
"$.Toybox.Math.atan2":
|
|
10023
|
+
"$.Toybox.Math.acos": mathDefault,
|
|
10024
|
+
"$.Toybox.Math.asin": mathDefault,
|
|
10025
|
+
"$.Toybox.Math.atan": mathDefault,
|
|
10026
|
+
"$.Toybox.Math.atan2": mathDefault,
|
|
10134
10027
|
"$.Toybox.Math.ceil": rounder,
|
|
10135
|
-
"$.Toybox.Math.cos":
|
|
10028
|
+
"$.Toybox.Math.cos": mathDefault,
|
|
10136
10029
|
"$.Toybox.Math.floor": rounder,
|
|
10137
10030
|
"$.Toybox.Math.ln": (state2, callee, calleeObj, getArgs) => mathHelper(state2, callee, calleeObj, getArgs, "log"),
|
|
10138
10031
|
"$.Toybox.Math.log": (state2, callee, calleeObj, getArgs) => mathHelper(
|
|
@@ -10142,11 +10035,11 @@ function getSystemCallTable(state) {
|
|
|
10142
10035
|
getArgs,
|
|
10143
10036
|
(x, base) => Math.log(x) / Math.log(base)
|
|
10144
10037
|
),
|
|
10145
|
-
"$.Toybox.Math.pow":
|
|
10038
|
+
"$.Toybox.Math.pow": mathDefault,
|
|
10146
10039
|
"$.Toybox.Math.round": rounder,
|
|
10147
|
-
"$.Toybox.Math.sin":
|
|
10148
|
-
"$.Toybox.Math.sqrt":
|
|
10149
|
-
"$.Toybox.Math.tan":
|
|
10040
|
+
"$.Toybox.Math.sin": mathDefault,
|
|
10041
|
+
"$.Toybox.Math.sqrt": mathDefault,
|
|
10042
|
+
"$.Toybox.Math.tan": mathDefault,
|
|
10150
10043
|
"$.Toybox.Math.toDegrees": (state2, callee, calleeObj, getArgs) => mathHelper(
|
|
10151
10044
|
state2,
|
|
10152
10045
|
callee,
|
|
@@ -10208,6 +10101,88 @@ function expandKeys(state, table) {
|
|
|
10208
10101
|
});
|
|
10209
10102
|
return result;
|
|
10210
10103
|
}
|
|
10104
|
+
function extraReferenceTypeChecks(istate, report, targetType, sourceType, sourceNode) {
|
|
10105
|
+
if (safeReferenceArg(sourceNode)) {
|
|
10106
|
+
return;
|
|
10107
|
+
}
|
|
10108
|
+
let constrainedType = null;
|
|
10109
|
+
const getConstrained = () => {
|
|
10110
|
+
if (!constrainedType) {
|
|
10111
|
+
const constraint = (sourceNode.type === "Identifier" || sourceNode.type === "MemberExpression") && getLhsConstraint(istate, sourceNode);
|
|
10112
|
+
constrainedType = constraint ? getEffectiveTrackedType(constraint, sourceType) : {
|
|
10113
|
+
type: 0
|
|
10114
|
+
/* Never */
|
|
10115
|
+
};
|
|
10116
|
+
}
|
|
10117
|
+
return constrainedType;
|
|
10118
|
+
};
|
|
10119
|
+
const doCheck = (checker) => {
|
|
10120
|
+
const result = checker(sourceType);
|
|
10121
|
+
if (!result)
|
|
10122
|
+
return false;
|
|
10123
|
+
const ct = getConstrained();
|
|
10124
|
+
if (ct.type === 0)
|
|
10125
|
+
return result;
|
|
10126
|
+
return checker(ct);
|
|
10127
|
+
};
|
|
10128
|
+
const arrayReport = doCheck((sourceType2) => {
|
|
10129
|
+
if (sourceType2.type & 512) {
|
|
10130
|
+
const atype = getUnionComponent(
|
|
10131
|
+
sourceType2,
|
|
10132
|
+
512
|
|
10133
|
+
/* Array */
|
|
10134
|
+
);
|
|
10135
|
+
if (atype) {
|
|
10136
|
+
const ptype = getUnionComponent(
|
|
10137
|
+
targetType,
|
|
10138
|
+
512
|
|
10139
|
+
/* Array */
|
|
10140
|
+
);
|
|
10141
|
+
if (!ptype || !checkArrayCovariance(atype, ptype)) {
|
|
10142
|
+
return [display(sourceType2), display(targetType)];
|
|
10143
|
+
}
|
|
10144
|
+
}
|
|
10145
|
+
}
|
|
10146
|
+
return false;
|
|
10147
|
+
});
|
|
10148
|
+
if (arrayReport) {
|
|
10149
|
+
report(...arrayReport);
|
|
10150
|
+
}
|
|
10151
|
+
const dictReport = doCheck((sourceType2) => {
|
|
10152
|
+
if (sourceType2.type & 1024) {
|
|
10153
|
+
const adata = getUnionComponent(
|
|
10154
|
+
sourceType2,
|
|
10155
|
+
1024
|
|
10156
|
+
/* Dictionary */
|
|
10157
|
+
);
|
|
10158
|
+
if (adata && adata.value) {
|
|
10159
|
+
const pdata = getUnionComponent(
|
|
10160
|
+
targetType,
|
|
10161
|
+
1024
|
|
10162
|
+
/* Dictionary */
|
|
10163
|
+
);
|
|
10164
|
+
if (!pdata || !pdata.value || !subtypeOf(pdata.key, adata.key) || !subtypeOf(pdata.value, adata.value)) {
|
|
10165
|
+
return [
|
|
10166
|
+
`Dictionary<${display(adata.key)}, ${display(adata.value)}>`,
|
|
10167
|
+
display(
|
|
10168
|
+
pdata ? {
|
|
10169
|
+
type: 1024,
|
|
10170
|
+
value: pdata
|
|
10171
|
+
} : {
|
|
10172
|
+
type: 1024
|
|
10173
|
+
/* Dictionary */
|
|
10174
|
+
}
|
|
10175
|
+
)
|
|
10176
|
+
];
|
|
10177
|
+
}
|
|
10178
|
+
}
|
|
10179
|
+
}
|
|
10180
|
+
return false;
|
|
10181
|
+
});
|
|
10182
|
+
if (dictReport) {
|
|
10183
|
+
report(...dictReport);
|
|
10184
|
+
}
|
|
10185
|
+
}
|
|
10211
10186
|
var systemCallInfo, systemCallVersion;
|
|
10212
10187
|
var init_interp_call = (0, import_chunk_ABYVSU2C.__esm)({
|
|
10213
10188
|
"src/type-flow/interp-call.ts"() {
|
|
@@ -10215,12 +10190,14 @@ var init_interp_call = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
10215
10190
|
init_api();
|
|
10216
10191
|
init_optimizer_types();
|
|
10217
10192
|
(0, import_chunk_X7QCZR3F.init_util)();
|
|
10193
|
+
init_array_type();
|
|
10218
10194
|
init_interp();
|
|
10219
10195
|
init_intersection_type();
|
|
10220
10196
|
init_sub_type();
|
|
10221
10197
|
init_type_flow_util();
|
|
10222
10198
|
init_types();
|
|
10223
10199
|
init_union_type();
|
|
10200
|
+
init_effective_type();
|
|
10224
10201
|
systemCallInfo = null;
|
|
10225
10202
|
}
|
|
10226
10203
|
});
|
|
@@ -10476,16 +10453,14 @@ function deEnumerate(t) {
|
|
|
10476
10453
|
);
|
|
10477
10454
|
t = cloneType(t);
|
|
10478
10455
|
clearValuesUnder(t, 65536, true);
|
|
10479
|
-
unionInto(
|
|
10480
|
-
t,
|
|
10481
|
-
data && (data.value || data.enum?.resolvedType) || {
|
|
10482
|
-
type: EnumTagsConst
|
|
10483
|
-
}
|
|
10484
|
-
);
|
|
10456
|
+
unionInto(t, typeFromEnumValue(data));
|
|
10485
10457
|
}
|
|
10486
10458
|
return t;
|
|
10487
10459
|
}
|
|
10488
10460
|
function arrayTypeAtIndex(arr, elemType, forStrictAssign, enforceTuples) {
|
|
10461
|
+
if (elemType) {
|
|
10462
|
+
elemType = deEnumerate(elemType);
|
|
10463
|
+
}
|
|
10489
10464
|
const reduce2 = (v) => forStrictAssign ? v.reduce(
|
|
10490
10465
|
(t, c) => t ? intersection(t, c) : c,
|
|
10491
10466
|
null
|
|
@@ -10507,124 +10482,140 @@ function arrayTypeAtIndex(arr, elemType, forStrictAssign, enforceTuples) {
|
|
|
10507
10482
|
}
|
|
10508
10483
|
);
|
|
10509
10484
|
}
|
|
10510
|
-
function
|
|
10485
|
+
function getLhsConstraintHelper(istate, node) {
|
|
10511
10486
|
if (istate.localLvals?.has(node)) {
|
|
10512
|
-
return
|
|
10487
|
+
return [istate.typeMap?.get(node), false];
|
|
10513
10488
|
}
|
|
10514
|
-
let lookupDefs =
|
|
10515
|
-
if (
|
|
10516
|
-
if (
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
|
|
10521
|
-
|
|
10522
|
-
|
|
10523
|
-
|
|
10524
|
-
|
|
10525
|
-
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
const arr = getUnionComponent(
|
|
10533
|
-
object,
|
|
10534
|
-
512
|
|
10535
|
-
/* Array */
|
|
10536
|
-
);
|
|
10537
|
-
if (arr) {
|
|
10538
|
-
result = arrayTypeAtIndex(
|
|
10539
|
-
arr,
|
|
10540
|
-
istate.typeMap.get(node.property) ?? {
|
|
10541
|
-
type: 8,
|
|
10542
|
-
value: arrayLiteralKeyFromExpr(node.property) ?? void 0
|
|
10543
|
-
},
|
|
10544
|
-
strict,
|
|
10545
|
-
istate.state.config?.extraReferenceTypeChecks !== false
|
|
10546
|
-
);
|
|
10547
|
-
}
|
|
10489
|
+
let lookupDefs = istate.state.lookupNonlocal(node)[1];
|
|
10490
|
+
if (!lookupDefs) {
|
|
10491
|
+
if (node.type === "MemberExpression") {
|
|
10492
|
+
if (!istate.typeMap) {
|
|
10493
|
+
throw new Error("Checking types without a typeMap");
|
|
10494
|
+
}
|
|
10495
|
+
const trackedObject = istate.typeMap?.get(node.object);
|
|
10496
|
+
const object = (node.object.type === "Identifier" || node.object.type === "MemberExpression") && getLhsConstraintHelper(istate, node.object)[0] || trackedObject;
|
|
10497
|
+
if (object) {
|
|
10498
|
+
const tracked = trackedObject ?? object;
|
|
10499
|
+
const objType = object.type & tracked.type;
|
|
10500
|
+
if (node.computed) {
|
|
10501
|
+
const strict = istate.typeChecker === subtypeOf;
|
|
10502
|
+
if (strict && objType & ~(512 | 1024 | 32768 | 262144)) {
|
|
10503
|
+
return [{
|
|
10504
|
+
type: 0
|
|
10505
|
+
/* Never */
|
|
10506
|
+
}, true];
|
|
10548
10507
|
}
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
|
|
10508
|
+
if (object.value) {
|
|
10509
|
+
let result = null;
|
|
10510
|
+
if (objType & 512) {
|
|
10511
|
+
let arr = getUnionComponent(
|
|
10512
|
+
object,
|
|
10513
|
+
512
|
|
10514
|
+
/* Array */
|
|
10515
|
+
);
|
|
10516
|
+
if (arr) {
|
|
10517
|
+
if (trackedObject) {
|
|
10518
|
+
const current = getUnionComponent(
|
|
10519
|
+
trackedObject,
|
|
10520
|
+
512
|
|
10521
|
+
/* Array */
|
|
10522
|
+
);
|
|
10523
|
+
if (current) {
|
|
10524
|
+
arr = restrictArrayData(arr, current);
|
|
10525
|
+
}
|
|
10526
|
+
}
|
|
10527
|
+
result = arrayTypeAtIndex(
|
|
10528
|
+
arr,
|
|
10529
|
+
istate.typeMap.get(node.property) ?? {
|
|
10530
|
+
type: 8,
|
|
10531
|
+
value: arrayLiteralKeyFromExpr(node.property) ?? void 0
|
|
10532
|
+
},
|
|
10533
|
+
strict,
|
|
10534
|
+
istate.state.config?.extraReferenceTypeChecks !== false
|
|
10535
|
+
);
|
|
10556
10536
|
}
|
|
10557
|
-
} else {
|
|
10558
|
-
result = value2;
|
|
10559
10537
|
}
|
|
10560
|
-
|
|
10561
|
-
|
|
10562
|
-
|
|
10563
|
-
|
|
10564
|
-
|
|
10565
|
-
|
|
10566
|
-
|
|
10567
|
-
|
|
10568
|
-
if (dict.value) {
|
|
10569
|
-
updateResult(dict.value);
|
|
10538
|
+
const updateResult = (value2) => {
|
|
10539
|
+
if (result) {
|
|
10540
|
+
if (strict) {
|
|
10541
|
+
result = intersection(result, value2);
|
|
10542
|
+
} else {
|
|
10543
|
+
result = cloneType(result);
|
|
10544
|
+
unionInto(result, value2);
|
|
10545
|
+
}
|
|
10570
10546
|
} else {
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10547
|
+
result = value2;
|
|
10548
|
+
}
|
|
10549
|
+
};
|
|
10550
|
+
if (object.type & 1024) {
|
|
10551
|
+
const dict = getUnionComponent(
|
|
10552
|
+
object,
|
|
10553
|
+
1024
|
|
10554
|
+
/* Dictionary */
|
|
10555
|
+
);
|
|
10556
|
+
if (dict) {
|
|
10557
|
+
if (dict.value) {
|
|
10558
|
+
updateResult(dict.value);
|
|
10559
|
+
} else {
|
|
10560
|
+
const keyType = istate.typeMap.get(node.property);
|
|
10561
|
+
const keyStr = keyType ? objectLiteralKeyFromType(keyType) : objectLiteralKeyFromExpr(node.property);
|
|
10562
|
+
if (keyStr) {
|
|
10563
|
+
const value2 = dict.get(keyStr);
|
|
10564
|
+
if (value2 != null) {
|
|
10565
|
+
updateResult(value2);
|
|
10566
|
+
}
|
|
10577
10567
|
}
|
|
10578
10568
|
}
|
|
10579
10569
|
}
|
|
10580
10570
|
}
|
|
10581
|
-
|
|
10582
|
-
|
|
10583
|
-
|
|
10584
|
-
|
|
10585
|
-
|
|
10586
|
-
|
|
10587
|
-
|
|
10588
|
-
|
|
10589
|
-
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
}
|
|
10571
|
+
if (object.type & 32768) {
|
|
10572
|
+
const obj = getUnionComponent(
|
|
10573
|
+
object,
|
|
10574
|
+
32768
|
|
10575
|
+
/* Object */
|
|
10576
|
+
);
|
|
10577
|
+
if (obj && isByteArrayData(obj)) {
|
|
10578
|
+
updateResult({
|
|
10579
|
+
type: 8 | 128
|
|
10580
|
+
/* Char */
|
|
10581
|
+
});
|
|
10582
|
+
}
|
|
10583
|
+
}
|
|
10584
|
+
if (result) {
|
|
10585
|
+
return [result, true];
|
|
10593
10586
|
}
|
|
10594
10587
|
}
|
|
10595
|
-
|
|
10596
|
-
|
|
10597
|
-
}
|
|
10598
|
-
}
|
|
10599
|
-
} else {
|
|
10600
|
-
const [, trueDecls2] = findObjectDeclsByProperty(
|
|
10601
|
-
istate.state,
|
|
10602
|
-
object,
|
|
10603
|
-
node.property
|
|
10604
|
-
);
|
|
10605
|
-
if (trueDecls2) {
|
|
10606
|
-
lookupDefs = lookupNext(
|
|
10588
|
+
} else {
|
|
10589
|
+
const [, trueDecls2] = findObjectDeclsByProperty(
|
|
10607
10590
|
istate.state,
|
|
10608
|
-
|
|
10609
|
-
"decls",
|
|
10591
|
+
object,
|
|
10610
10592
|
node.property
|
|
10611
10593
|
);
|
|
10594
|
+
if (trueDecls2) {
|
|
10595
|
+
lookupDefs = lookupNext(
|
|
10596
|
+
istate.state,
|
|
10597
|
+
[{ parent: null, results: trueDecls2 }],
|
|
10598
|
+
"decls",
|
|
10599
|
+
node.property
|
|
10600
|
+
);
|
|
10601
|
+
}
|
|
10612
10602
|
}
|
|
10613
10603
|
}
|
|
10614
10604
|
}
|
|
10615
10605
|
}
|
|
10616
10606
|
if (!lookupDefs) {
|
|
10617
|
-
[,
|
|
10618
|
-
}
|
|
10619
|
-
if (!lookupDefs) {
|
|
10620
|
-
return null;
|
|
10607
|
+
return [null, false];
|
|
10621
10608
|
}
|
|
10622
10609
|
const trueDecls = lookupDefs.flatMap(
|
|
10623
10610
|
(lookupDef) => lookupDef.results.filter(
|
|
10624
10611
|
(decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && !isLocal(decl)
|
|
10625
10612
|
)
|
|
10626
10613
|
);
|
|
10627
|
-
return trueDecls.length === 0 ? null : typeFromTypeStateNodes(istate.state, trueDecls);
|
|
10614
|
+
return trueDecls.length === 0 ? [null, false] : [typeFromTypeStateNodes(istate.state, trueDecls), true];
|
|
10615
|
+
}
|
|
10616
|
+
function getLhsConstraint(istate, node) {
|
|
10617
|
+
const [constraintType, constrained] = getLhsConstraintHelper(istate, node);
|
|
10618
|
+
return constrained ? constraintType : null;
|
|
10628
10619
|
}
|
|
10629
10620
|
function pushScopedNameType(istate, node, object) {
|
|
10630
10621
|
let embeddedEffects = object ? object.embeddedEffects : false;
|
|
@@ -11159,17 +11150,40 @@ function evaluateNode(istate, node) {
|
|
|
11159
11150
|
if (istate.typeChecker) {
|
|
11160
11151
|
const constraint = getLhsConstraint(istate, node.left);
|
|
11161
11152
|
const actual = istate.stack[istate.stack.length - 1].value;
|
|
11162
|
-
if (constraint
|
|
11163
|
-
|
|
11164
|
-
istate.state
|
|
11165
|
-
|
|
11166
|
-
|
|
11167
|
-
|
|
11168
|
-
|
|
11169
|
-
|
|
11170
|
-
|
|
11171
|
-
|
|
11172
|
-
|
|
11153
|
+
if (constraint) {
|
|
11154
|
+
if (istate.typeChecker(actual, constraint)) {
|
|
11155
|
+
if (istate.state.config?.extraReferenceTypeChecks !== false) {
|
|
11156
|
+
extraReferenceTypeChecks(
|
|
11157
|
+
istate,
|
|
11158
|
+
(sourceType, targetType) => diagnostic(
|
|
11159
|
+
istate.state,
|
|
11160
|
+
node,
|
|
11161
|
+
formatAstLongLines(node.left).then(
|
|
11162
|
+
(nodeStr) => `Unsafe assignment to ${nodeStr}: assigning ${sourceType} to ${targetType} is not type safe`
|
|
11163
|
+
),
|
|
11164
|
+
istate.checkTypes,
|
|
11165
|
+
{
|
|
11166
|
+
uri: "https://github.com/markw65/monkeyc-optimizer/wiki/Extra-Reference-Type-Checks-(prettierMonkeyC.extraReferenceTypeChecks)",
|
|
11167
|
+
message: "more info"
|
|
11168
|
+
}
|
|
11169
|
+
),
|
|
11170
|
+
constraint,
|
|
11171
|
+
actual,
|
|
11172
|
+
node.right
|
|
11173
|
+
);
|
|
11174
|
+
}
|
|
11175
|
+
} else {
|
|
11176
|
+
diagnostic(
|
|
11177
|
+
istate.state,
|
|
11178
|
+
node,
|
|
11179
|
+
formatAstLongLines(node.left).then(
|
|
11180
|
+
(nodeStr) => `Invalid assignment to ${nodeStr}. Expected ${display(
|
|
11181
|
+
constraint
|
|
11182
|
+
)} but got ${display(actual)}`
|
|
11183
|
+
),
|
|
11184
|
+
istate.checkTypes
|
|
11185
|
+
);
|
|
11186
|
+
}
|
|
11173
11187
|
}
|
|
11174
11188
|
}
|
|
11175
11189
|
break;
|
|
@@ -11271,21 +11285,41 @@ function evaluateNode(istate, node) {
|
|
|
11271
11285
|
case "ReturnStatement": {
|
|
11272
11286
|
const value2 = node.argument && popIstate(istate, node.argument);
|
|
11273
11287
|
if (istate.typeChecker) {
|
|
11274
|
-
|
|
11288
|
+
const root = istate.root;
|
|
11289
|
+
if (root?.type !== "FunctionDeclaration") {
|
|
11275
11290
|
throw new Error("ReturnStatement found outside of function");
|
|
11276
11291
|
}
|
|
11277
|
-
if (
|
|
11292
|
+
if (root.node.returnType) {
|
|
11278
11293
|
const returnType = typeFromTypespec(
|
|
11279
11294
|
istate.state,
|
|
11280
|
-
|
|
11281
|
-
|
|
11295
|
+
root.node.returnType.argument,
|
|
11296
|
+
root.stack
|
|
11282
11297
|
);
|
|
11283
11298
|
if (value2) {
|
|
11284
|
-
if (
|
|
11299
|
+
if (istate.typeChecker(value2.value, returnType)) {
|
|
11300
|
+
if (istate.state.config?.extraReferenceTypeChecks !== false) {
|
|
11301
|
+
extraReferenceTypeChecks(
|
|
11302
|
+
istate,
|
|
11303
|
+
(sourceType, targetType) => diagnostic(
|
|
11304
|
+
istate.state,
|
|
11305
|
+
node,
|
|
11306
|
+
`Unsafe return from ${root.fullName}: converting ${sourceType} to ${targetType} is not type safe`,
|
|
11307
|
+
istate.checkTypes,
|
|
11308
|
+
{
|
|
11309
|
+
uri: "https://github.com/markw65/monkeyc-optimizer/wiki/Extra-Reference-Type-Checks-(prettierMonkeyC.extraReferenceTypeChecks)",
|
|
11310
|
+
message: "more info"
|
|
11311
|
+
}
|
|
11312
|
+
),
|
|
11313
|
+
returnType,
|
|
11314
|
+
value2.value,
|
|
11315
|
+
node.argument
|
|
11316
|
+
);
|
|
11317
|
+
}
|
|
11318
|
+
} else {
|
|
11285
11319
|
diagnostic(
|
|
11286
11320
|
istate.state,
|
|
11287
11321
|
node,
|
|
11288
|
-
`Expected ${
|
|
11322
|
+
`Expected ${root.fullName} to return ${display(
|
|
11289
11323
|
returnType
|
|
11290
11324
|
)} but got ${display(value2.value)}`,
|
|
11291
11325
|
istate.checkTypes
|
|
@@ -11412,6 +11446,7 @@ var init_interp = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
11412
11446
|
init_data_flow();
|
|
11413
11447
|
init_optimizer_types();
|
|
11414
11448
|
(0, import_chunk_X7QCZR3F.init_util)();
|
|
11449
|
+
init_array_type();
|
|
11415
11450
|
init_could_be();
|
|
11416
11451
|
init_interp_binary();
|
|
11417
11452
|
init_interp_call();
|
|
@@ -11736,10 +11771,8 @@ function arrayLiteralKeyFromType(k) {
|
|
|
11736
11771
|
return null;
|
|
11737
11772
|
}
|
|
11738
11773
|
function arrayLiteralKeyFromExpr(key) {
|
|
11739
|
-
|
|
11740
|
-
|
|
11741
|
-
}
|
|
11742
|
-
return null;
|
|
11774
|
+
const lit = key.type === "Literal" ? key : (0, import_chunk_JDC43A3I.getNodeValue)(key)[0];
|
|
11775
|
+
return lit && arrayLiteralKeyFromType(typeFromLiteral(lit));
|
|
11743
11776
|
}
|
|
11744
11777
|
function objectLiteralKeyFromExpr(key) {
|
|
11745
11778
|
switch (key.type) {
|
|
@@ -12024,11 +12057,8 @@ function mcExprFromType(type) {
|
|
|
12024
12057
|
if (type.value.value && hasValue(type.value.value)) {
|
|
12025
12058
|
const left = mcExprFromType(type.value.value);
|
|
12026
12059
|
if (left) {
|
|
12027
|
-
|
|
12028
|
-
|
|
12029
|
-
}
|
|
12030
|
-
const enumStr = type.value.enum.fullName.slice(2);
|
|
12031
|
-
if (enumStr === "Toybox.Graphics.ColorValue" && left.type === "Literal" && typeof left.value === "number" && left.value >= 0 && left.value <= 16777215 && /^\d+$/.test(left.raw)) {
|
|
12060
|
+
const enumStrs = (0, import_chunk_X7QCZR3F.map)(type.value.enum, (e) => e.fullName.slice(2));
|
|
12061
|
+
if (enumStrs.length === 1 && enumStrs[0] === "Toybox.Graphics.ColorValue" && left.type === "Literal" && typeof left.value === "number" && left.value >= 0 && left.value <= 16777215 && /^\d+$/.test(left.raw)) {
|
|
12032
12062
|
left.raw = "0x" + `00000${left.value.toString(16)}`.slice(-6);
|
|
12033
12063
|
}
|
|
12034
12064
|
return {
|
|
@@ -12037,7 +12067,7 @@ function mcExprFromType(type) {
|
|
|
12037
12067
|
left,
|
|
12038
12068
|
right: {
|
|
12039
12069
|
type: "TypeSpecList",
|
|
12040
|
-
ts:
|
|
12070
|
+
ts: enumStrs
|
|
12041
12071
|
}
|
|
12042
12072
|
};
|
|
12043
12073
|
}
|
|
@@ -12118,229 +12148,620 @@ function castType(type, target) {
|
|
|
12118
12148
|
result.type = Number(type.value) === 0 ? 2 : 4;
|
|
12119
12149
|
return result;
|
|
12120
12150
|
}
|
|
12121
|
-
}
|
|
12151
|
+
}
|
|
12152
|
+
}
|
|
12153
|
+
return result;
|
|
12154
|
+
}
|
|
12155
|
+
function reducedType(elems) {
|
|
12156
|
+
if (!Array.isArray(elems)) {
|
|
12157
|
+
return elems;
|
|
12158
|
+
}
|
|
12159
|
+
return elems.flat().reduce(
|
|
12160
|
+
(p, t) => {
|
|
12161
|
+
unionInto(p, t);
|
|
12162
|
+
return p;
|
|
12163
|
+
},
|
|
12164
|
+
{
|
|
12165
|
+
type: 0
|
|
12166
|
+
/* Never */
|
|
12167
|
+
}
|
|
12168
|
+
);
|
|
12169
|
+
}
|
|
12170
|
+
function mustBeTrue(arg) {
|
|
12171
|
+
return (arg.type === 8 || arg.type === 16) && arg.value != null && Number(arg.value) !== 0 || (arg.type & TruthyTypes) !== 0 && (arg.type & ~TruthyTypes) === 0;
|
|
12172
|
+
}
|
|
12173
|
+
function mustBeFalse(arg) {
|
|
12174
|
+
return arg.type === 1 || arg.type === 2 || (arg.type === 8 || arg.type === 16) && arg.value != null && Number(arg.value) === 0;
|
|
12175
|
+
}
|
|
12176
|
+
function display(type) {
|
|
12177
|
+
const names = (v, fn) => (0, import_chunk_X7QCZR3F.map)(v, fn).sort().filter((s, i, arr) => !i || s !== arr[i - 1]).join(" or ");
|
|
12178
|
+
const parts = [];
|
|
12179
|
+
const displayOne = (tv) => {
|
|
12180
|
+
switch (tv.type) {
|
|
12181
|
+
case 1:
|
|
12182
|
+
case 2:
|
|
12183
|
+
case 4:
|
|
12184
|
+
throw new Error("Unexpected value for SingletonTypeTag");
|
|
12185
|
+
case 8:
|
|
12186
|
+
case 16:
|
|
12187
|
+
case 32:
|
|
12188
|
+
case 64:
|
|
12189
|
+
return tv.value.toString();
|
|
12190
|
+
case 128:
|
|
12191
|
+
return `'${JSON.stringify(tv.value).slice(1, -1)}'`;
|
|
12192
|
+
case 256:
|
|
12193
|
+
return JSON.stringify(tv.value);
|
|
12194
|
+
case 512:
|
|
12195
|
+
return tupleMap(
|
|
12196
|
+
tv.value,
|
|
12197
|
+
(v) => `[${v.map((t) => display(t)).join(", ")}]`,
|
|
12198
|
+
(v) => `Array<${display(v)}>`,
|
|
12199
|
+
(v) => v.join(" or ")
|
|
12200
|
+
);
|
|
12201
|
+
case 1024:
|
|
12202
|
+
return tv.value.value ? `Dictionary<${display(tv.value.key)}, ${display(tv.value.value)}>` : `{ ${Array.from(tv.value).map(
|
|
12203
|
+
([key, value2]) => `${display(typeFromObjectLiteralKey(key))} as ${display(
|
|
12204
|
+
value2
|
|
12205
|
+
)}`
|
|
12206
|
+
).join(", ")} }`;
|
|
12207
|
+
case 2048:
|
|
12208
|
+
return `Method(${tv.value.args.map((arg, i) => `a${i + 1} as ${display(arg)}`).join(", ")}) as ${display(tv.value.result)}`;
|
|
12209
|
+
case 4096:
|
|
12210
|
+
case 8192:
|
|
12211
|
+
case 16384:
|
|
12212
|
+
case 262144:
|
|
12213
|
+
return names(tv.value, (v) => v.fullName.slice(2));
|
|
12214
|
+
case 32768: {
|
|
12215
|
+
const klass = tv.value.klass;
|
|
12216
|
+
if (!klass.value)
|
|
12217
|
+
return void 0;
|
|
12218
|
+
const obj = tv.value.obj;
|
|
12219
|
+
const ret = displayOne({ type: 16384, value: klass.value });
|
|
12220
|
+
return obj ? `${ret}<{${Object.entries(obj).map(([key, value2]) => `${key}: ${display(value2)}`).join(", ")}}>` : ret;
|
|
12221
|
+
}
|
|
12222
|
+
case 65536: {
|
|
12223
|
+
const v = tv.value;
|
|
12224
|
+
const name = v.enum ? (0, import_chunk_X7QCZR3F.map)(v.enum, (e) => e.fullName.slice(2)).join(" or ") : "";
|
|
12225
|
+
return v.value != null ? `${display(v.value)} as ${name}` : name;
|
|
12226
|
+
}
|
|
12227
|
+
case 131072:
|
|
12228
|
+
return `:${tv.value}`;
|
|
12229
|
+
default:
|
|
12230
|
+
unhandledType(tv);
|
|
12231
|
+
}
|
|
12232
|
+
};
|
|
12233
|
+
let bits = type.type;
|
|
12234
|
+
if (!bits)
|
|
12235
|
+
return "Never";
|
|
12236
|
+
if (bits === 524287 && type.value == null) {
|
|
12237
|
+
return "Any";
|
|
12238
|
+
}
|
|
12239
|
+
while (bits) {
|
|
12240
|
+
const next = bits & bits - 1;
|
|
12241
|
+
const bit = bits - next;
|
|
12242
|
+
if (bit === 2 && next & 4) {
|
|
12243
|
+
parts.push("Boolean");
|
|
12244
|
+
bits = next - 4;
|
|
12245
|
+
continue;
|
|
12246
|
+
}
|
|
12247
|
+
const name = typeTagName(bit);
|
|
12248
|
+
const value2 = getUnionComponent(type, bit);
|
|
12249
|
+
const valueStr = value2 != null && displayOne({ type: bit, value: value2 });
|
|
12250
|
+
if (!valueStr) {
|
|
12251
|
+
parts.push(name);
|
|
12252
|
+
} else if (bit & (32768 | 65536 | 262144 | 131072 | 2048 | 256 | 512 | 1024)) {
|
|
12253
|
+
parts.push(valueStr);
|
|
12254
|
+
} else {
|
|
12255
|
+
parts.push(`${name}<${valueStr}${valueStr.endsWith(">") ? " " : ""}>`);
|
|
12256
|
+
}
|
|
12257
|
+
bits = next;
|
|
12258
|
+
}
|
|
12259
|
+
return parts.join(" or ");
|
|
12260
|
+
}
|
|
12261
|
+
function hasUnionData(tag) {
|
|
12262
|
+
tag &= UnionDataTypeTagsConst;
|
|
12263
|
+
return (tag & tag - 1) !== 0;
|
|
12264
|
+
}
|
|
12265
|
+
function getObjectValue(t) {
|
|
12266
|
+
if (!(t.type & 32768) || t.value == null)
|
|
12267
|
+
return null;
|
|
12268
|
+
if (hasUnionData(t.type)) {
|
|
12269
|
+
return t.value[
|
|
12270
|
+
32768
|
|
12271
|
+
/* Object */
|
|
12272
|
+
];
|
|
12273
|
+
}
|
|
12274
|
+
return t.value;
|
|
12275
|
+
}
|
|
12276
|
+
function forEachUnionComponent(v, bits, fn) {
|
|
12277
|
+
bits &= ~SingletonTypeTagsConst;
|
|
12278
|
+
if (!bits)
|
|
12279
|
+
return;
|
|
12280
|
+
if ((v.type | bits) & UnionDataTypeTagsConst) {
|
|
12281
|
+
bits &= ~ValueTypeTagsConst;
|
|
12282
|
+
} else if (bits & bits - 1) {
|
|
12283
|
+
return;
|
|
12284
|
+
}
|
|
12285
|
+
const hasUnion = hasUnionData(v.type);
|
|
12286
|
+
const unionData = v.value;
|
|
12287
|
+
do {
|
|
12288
|
+
const next = bits & bits - 1;
|
|
12289
|
+
const bit = bits - next;
|
|
12290
|
+
const data = hasUnion ? unionData[bit] : bit & v.type ? v.value : null;
|
|
12291
|
+
if (fn({ type: bit, value: data }) === false)
|
|
12292
|
+
break;
|
|
12293
|
+
bits = next;
|
|
12294
|
+
} while (bits);
|
|
12295
|
+
}
|
|
12296
|
+
function getUnionComponent(v, tag) {
|
|
12297
|
+
if (v.value == null)
|
|
12298
|
+
return null;
|
|
12299
|
+
let bits = v.type & ~SingletonTypeTagsConst;
|
|
12300
|
+
if (!bits)
|
|
12301
|
+
return null;
|
|
12302
|
+
if (bits & bits - 1) {
|
|
12303
|
+
bits &= UnionDataTypeTagsConst;
|
|
12304
|
+
if (!bits) {
|
|
12305
|
+
throw new Error(`Non-exact type had no union bits set`);
|
|
12306
|
+
}
|
|
12307
|
+
}
|
|
12308
|
+
if (bits === tag) {
|
|
12309
|
+
return v.value;
|
|
12310
|
+
} else if (bits & tag) {
|
|
12311
|
+
const unionData = v.value;
|
|
12312
|
+
return unionData[tag] || null;
|
|
12313
|
+
}
|
|
12314
|
+
return null;
|
|
12315
|
+
}
|
|
12316
|
+
function setUnionComponent(v, tag, c) {
|
|
12317
|
+
if (hasUnionData(v.type)) {
|
|
12318
|
+
const value2 = v.value ? { ...v.value } : { mask: 0 };
|
|
12319
|
+
value2[tag] = c;
|
|
12320
|
+
value2.mask |= tag;
|
|
12321
|
+
v.value = value2;
|
|
12322
|
+
} else {
|
|
12323
|
+
v.value = c;
|
|
12324
|
+
}
|
|
12325
|
+
}
|
|
12326
|
+
function getStateNodeDeclsFromType(state, object) {
|
|
12327
|
+
return getStateNodeDeclsWithExactFromType(state, object).map(({ sn }) => sn);
|
|
12328
|
+
}
|
|
12329
|
+
function getStateNodeDeclsWithExactFromType(state, object) {
|
|
12330
|
+
const decls = [];
|
|
12331
|
+
if (object.value != null && object.type & (4096 | 16384 | 32768)) {
|
|
12332
|
+
forEachUnionComponent(
|
|
12333
|
+
object,
|
|
12334
|
+
object.type & (4096 | 16384 | 32768),
|
|
12335
|
+
(type) => {
|
|
12336
|
+
if (type.value == null)
|
|
12337
|
+
return;
|
|
12338
|
+
switch (type.type) {
|
|
12339
|
+
case 32768:
|
|
12340
|
+
if (type.value.klass.type === 16384 && type.value.klass.value) {
|
|
12341
|
+
(0, import_chunk_X7QCZR3F.forEach)(
|
|
12342
|
+
type.value.klass.value,
|
|
12343
|
+
(sn) => decls.push({ sn, exact: false })
|
|
12344
|
+
);
|
|
12345
|
+
}
|
|
12346
|
+
break;
|
|
12347
|
+
case 4096:
|
|
12348
|
+
case 16384:
|
|
12349
|
+
(0, import_chunk_X7QCZR3F.forEach)(type.value, (sn) => decls.push({ sn, exact: true }));
|
|
12350
|
+
break;
|
|
12351
|
+
}
|
|
12352
|
+
}
|
|
12353
|
+
);
|
|
12354
|
+
}
|
|
12355
|
+
let bits = object.type & (ObjectLikeTagsConst | 32768);
|
|
12356
|
+
if (bits & 32768 && getObjectValue(object)) {
|
|
12357
|
+
bits -= 32768;
|
|
12358
|
+
}
|
|
12359
|
+
if (bits) {
|
|
12360
|
+
do {
|
|
12361
|
+
let next = bits & bits - 1;
|
|
12362
|
+
let bit = bits - next;
|
|
12363
|
+
if (bit & 6) {
|
|
12364
|
+
bit = 6;
|
|
12365
|
+
next &= ~6;
|
|
12366
|
+
}
|
|
12367
|
+
const name = `Toybox.Lang.${typeTagName(bit)}`;
|
|
12368
|
+
const sns = lookupByFullName(state, name);
|
|
12369
|
+
sns.forEach((sn) => isStateNode(sn) && decls.push({ sn, exact: true }));
|
|
12370
|
+
bits = next;
|
|
12371
|
+
} while (bits);
|
|
12122
12372
|
}
|
|
12123
|
-
return
|
|
12373
|
+
return decls;
|
|
12124
12374
|
}
|
|
12125
|
-
function
|
|
12126
|
-
|
|
12127
|
-
|
|
12375
|
+
function typeFromEnumValue(arg) {
|
|
12376
|
+
return arg?.value ?? (arg && reducedType(
|
|
12377
|
+
(0, import_chunk_X7QCZR3F.map)(
|
|
12378
|
+
arg.enum,
|
|
12379
|
+
(e) => e.resolvedType ?? {
|
|
12380
|
+
type: EnumTagsConst
|
|
12381
|
+
}
|
|
12382
|
+
)
|
|
12383
|
+
)) ?? {
|
|
12384
|
+
type: EnumTagsConst
|
|
12385
|
+
};
|
|
12386
|
+
}
|
|
12387
|
+
var LastTypeTag, SingletonTypeTagsConst, UnionDataTypeTagsConst, ValueTypeTagsConst, ObjectLikeTagsConst, EnumTagsConst, TruthyTypes;
|
|
12388
|
+
var init_types = (0, import_chunk_ABYVSU2C.__esm)({
|
|
12389
|
+
"src/type-flow/types.ts"() {
|
|
12390
|
+
"use strict";
|
|
12391
|
+
init_api();
|
|
12392
|
+
(0, import_chunk_JDC43A3I.init_ast)();
|
|
12393
|
+
init_data_flow();
|
|
12394
|
+
(0, import_chunk_X7QCZR3F.init_util)();
|
|
12395
|
+
init_array_type();
|
|
12396
|
+
init_interp();
|
|
12397
|
+
init_intersection_type();
|
|
12398
|
+
init_union_type();
|
|
12399
|
+
LastTypeTag = 262144;
|
|
12400
|
+
SingletonTypeTagsConst = 1 | 2 | 4;
|
|
12401
|
+
UnionDataTypeTagsConst = 512 | 1024 | 2048 | 4096 | 8192 | 16384 | 32768 | 65536 | 262144;
|
|
12402
|
+
ValueTypeTagsConst = 8 | 16 | 32 | 64 | 128 | 256 | 131072;
|
|
12403
|
+
ObjectLikeTagsConst = 6 | ValueTypeTagsConst | 512 | 1024 | 2048 | 65536;
|
|
12404
|
+
EnumTagsConst = SingletonTypeTagsConst | ValueTypeTagsConst & ~131072;
|
|
12405
|
+
TruthyTypes = 4 | // TypeTag.Object | // omit because of missing null on various Toybox types
|
|
12406
|
+
4096 | 16384 | 8192;
|
|
12128
12407
|
}
|
|
12129
|
-
|
|
12130
|
-
|
|
12131
|
-
|
|
12132
|
-
|
|
12133
|
-
|
|
12134
|
-
|
|
12135
|
-
type: 0
|
|
12136
|
-
/* Never */
|
|
12408
|
+
});
|
|
12409
|
+
function couldBeHelper(a, b, shallow) {
|
|
12410
|
+
const common = a.type & b.type & ~262144;
|
|
12411
|
+
if (common) {
|
|
12412
|
+
if (a.value == null || b.value == null || a.value === b.value) {
|
|
12413
|
+
return true;
|
|
12137
12414
|
}
|
|
12138
|
-
|
|
12415
|
+
if (common & SingletonTypeTagsConst) {
|
|
12416
|
+
return true;
|
|
12417
|
+
}
|
|
12418
|
+
if (common & ValueTypeTagsConst && common & UnionDataTypeTagsConst) {
|
|
12419
|
+
return true;
|
|
12420
|
+
}
|
|
12421
|
+
let result = false;
|
|
12422
|
+
forEachUnionComponent(a, common, (ac) => {
|
|
12423
|
+
if (ac.value == null) {
|
|
12424
|
+
result = true;
|
|
12425
|
+
return false;
|
|
12426
|
+
}
|
|
12427
|
+
const bvalue = getUnionComponent(b, ac.type);
|
|
12428
|
+
if (bvalue == null || ac.value === bvalue || couldBeValue(
|
|
12429
|
+
{ type: ac.type, avalue: ac.value, bvalue },
|
|
12430
|
+
shallow
|
|
12431
|
+
)) {
|
|
12432
|
+
result = true;
|
|
12433
|
+
return false;
|
|
12434
|
+
}
|
|
12435
|
+
return true;
|
|
12436
|
+
});
|
|
12437
|
+
if (result)
|
|
12438
|
+
return true;
|
|
12439
|
+
}
|
|
12440
|
+
if (a.type & 65536 && b.type & (EnumTagsConst | 65536) || b.type & 65536 && a.type & (EnumTagsConst | 65536)) {
|
|
12441
|
+
return true;
|
|
12442
|
+
}
|
|
12443
|
+
if (a.type & 32768 && b.type & ObjectLikeTagsConst && getObjectValue(a) == null) {
|
|
12444
|
+
return true;
|
|
12445
|
+
}
|
|
12446
|
+
if (b.type & 32768 && a.type & ObjectLikeTagsConst && getObjectValue(b) == null) {
|
|
12447
|
+
return true;
|
|
12448
|
+
}
|
|
12449
|
+
const checkTypedef = (t, other) => {
|
|
12450
|
+
const typedef = getUnionComponent(
|
|
12451
|
+
t,
|
|
12452
|
+
262144
|
|
12453
|
+
/* Typedef */
|
|
12454
|
+
);
|
|
12455
|
+
return typedef && (0, import_chunk_X7QCZR3F.some)(typedef, (td) => {
|
|
12456
|
+
if (!td.resolvedType) {
|
|
12457
|
+
throw new Error(`No resolved type for ${td.fullName} in 'couldBe'`);
|
|
12458
|
+
}
|
|
12459
|
+
return couldBe(td.resolvedType, other);
|
|
12460
|
+
});
|
|
12461
|
+
};
|
|
12462
|
+
if (a.type & 262144 && checkTypedef(a, b)) {
|
|
12463
|
+
return true;
|
|
12464
|
+
}
|
|
12465
|
+
if (b.type & 262144 && checkTypedef(b, a)) {
|
|
12466
|
+
return true;
|
|
12467
|
+
}
|
|
12468
|
+
return false;
|
|
12139
12469
|
}
|
|
12140
|
-
function
|
|
12141
|
-
return (
|
|
12470
|
+
function couldBe(a, b) {
|
|
12471
|
+
return couldBeHelper(a, b, false);
|
|
12142
12472
|
}
|
|
12143
|
-
function
|
|
12144
|
-
|
|
12473
|
+
function couldBeWeak(a, b) {
|
|
12474
|
+
if (a.type === 0 || b.type === 0)
|
|
12475
|
+
return true;
|
|
12476
|
+
return couldBe(a, b);
|
|
12145
12477
|
}
|
|
12146
|
-
function
|
|
12147
|
-
|
|
12148
|
-
|
|
12149
|
-
|
|
12150
|
-
|
|
12151
|
-
|
|
12152
|
-
|
|
12153
|
-
|
|
12154
|
-
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
|
|
12158
|
-
|
|
12159
|
-
|
|
12160
|
-
|
|
12161
|
-
|
|
12162
|
-
|
|
12163
|
-
|
|
12164
|
-
|
|
12165
|
-
|
|
12166
|
-
|
|
12167
|
-
|
|
12168
|
-
|
|
12169
|
-
|
|
12170
|
-
)
|
|
12171
|
-
|
|
12172
|
-
|
|
12173
|
-
|
|
12174
|
-
|
|
12175
|
-
|
|
12176
|
-
|
|
12177
|
-
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
|
|
12183
|
-
|
|
12184
|
-
|
|
12185
|
-
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
|
|
12189
|
-
|
|
12190
|
-
|
|
12191
|
-
|
|
12192
|
-
|
|
12193
|
-
|
|
12194
|
-
|
|
12478
|
+
function couldBeShallow(a, b) {
|
|
12479
|
+
return couldBeHelper(a, b, true);
|
|
12480
|
+
}
|
|
12481
|
+
function couldBeValue(pair, shallow) {
|
|
12482
|
+
switch (pair.type) {
|
|
12483
|
+
case 1:
|
|
12484
|
+
case 2:
|
|
12485
|
+
case 4:
|
|
12486
|
+
case 262144:
|
|
12487
|
+
throw new Error(`Unexpected TypeTag '${typeTagName(pair.type)}'`);
|
|
12488
|
+
case 8:
|
|
12489
|
+
case 16:
|
|
12490
|
+
case 32:
|
|
12491
|
+
case 64:
|
|
12492
|
+
case 256:
|
|
12493
|
+
case 128:
|
|
12494
|
+
case 131072:
|
|
12495
|
+
return pair.avalue === pair.bvalue;
|
|
12496
|
+
case 512: {
|
|
12497
|
+
if (shallow)
|
|
12498
|
+
return true;
|
|
12499
|
+
let result = false;
|
|
12500
|
+
tupleForEach(
|
|
12501
|
+
pair.avalue,
|
|
12502
|
+
(av) => {
|
|
12503
|
+
tupleForEach(
|
|
12504
|
+
pair.bvalue,
|
|
12505
|
+
(bv) => {
|
|
12506
|
+
result = av.length === bv.length && bv.every((b, i) => couldBe(av[i], b));
|
|
12507
|
+
return result === false;
|
|
12508
|
+
},
|
|
12509
|
+
(bv) => {
|
|
12510
|
+
result = av.every((a) => couldBe(a, bv));
|
|
12511
|
+
return result === false;
|
|
12512
|
+
}
|
|
12513
|
+
);
|
|
12514
|
+
return result === false;
|
|
12515
|
+
},
|
|
12516
|
+
(av) => {
|
|
12517
|
+
tupleForEach(
|
|
12518
|
+
pair.bvalue,
|
|
12519
|
+
(bv) => {
|
|
12520
|
+
result = bv.every((b) => couldBe(av, b));
|
|
12521
|
+
return result === false;
|
|
12522
|
+
},
|
|
12523
|
+
(bv) => (result = couldBe(av, bv)) === false
|
|
12524
|
+
);
|
|
12525
|
+
return result === false;
|
|
12526
|
+
}
|
|
12527
|
+
);
|
|
12528
|
+
return result;
|
|
12529
|
+
}
|
|
12530
|
+
case 1024: {
|
|
12531
|
+
if (shallow)
|
|
12532
|
+
return true;
|
|
12533
|
+
if (!pair.avalue.value || !pair.bvalue.value) {
|
|
12534
|
+
return true;
|
|
12195
12535
|
}
|
|
12196
|
-
|
|
12197
|
-
return `:${tv.value}`;
|
|
12198
|
-
default:
|
|
12199
|
-
unhandledType(tv);
|
|
12536
|
+
return couldBe(pair.avalue.key, pair.bvalue.key) && couldBe(pair.avalue.value, pair.bvalue.value);
|
|
12200
12537
|
}
|
|
12201
|
-
|
|
12202
|
-
|
|
12203
|
-
|
|
12204
|
-
|
|
12205
|
-
|
|
12206
|
-
|
|
12207
|
-
|
|
12208
|
-
|
|
12209
|
-
|
|
12210
|
-
|
|
12211
|
-
|
|
12212
|
-
|
|
12213
|
-
|
|
12214
|
-
|
|
12538
|
+
case 2048: {
|
|
12539
|
+
return pair.avalue.args.length === pair.bvalue.args.length && couldBe(pair.avalue.result, pair.bvalue.result) && pair.avalue.args.every((arg, i) => couldBe(arg, pair.bvalue.args[i]));
|
|
12540
|
+
}
|
|
12541
|
+
case 4096:
|
|
12542
|
+
case 8192: {
|
|
12543
|
+
return (0, import_chunk_X7QCZR3F.some)(
|
|
12544
|
+
pair.avalue,
|
|
12545
|
+
(sna) => (0, import_chunk_X7QCZR3F.some)(pair.bvalue, (snb) => sna === snb)
|
|
12546
|
+
);
|
|
12547
|
+
}
|
|
12548
|
+
case 16384: {
|
|
12549
|
+
return (0, import_chunk_X7QCZR3F.some)(pair.avalue, (sna) => {
|
|
12550
|
+
const superA = getSuperClasses(sna);
|
|
12551
|
+
return (0, import_chunk_X7QCZR3F.some)(pair.bvalue, (snb) => {
|
|
12552
|
+
if (sna === snb || superA && superA.has(snb)) {
|
|
12553
|
+
return true;
|
|
12554
|
+
}
|
|
12555
|
+
const superB = getSuperClasses(snb);
|
|
12556
|
+
return superB ? superB.has(sna) : false;
|
|
12557
|
+
});
|
|
12558
|
+
});
|
|
12215
12559
|
}
|
|
12216
|
-
|
|
12217
|
-
|
|
12218
|
-
const valueStr = value2 != null && displayOne({ type: bit, value: value2 });
|
|
12219
|
-
if (!valueStr) {
|
|
12220
|
-
parts.push(name);
|
|
12221
|
-
} else if (bit & (32768 | 65536 | 262144 | 131072 | 2048 | 256 | 512 | 1024)) {
|
|
12222
|
-
parts.push(valueStr);
|
|
12223
|
-
} else {
|
|
12224
|
-
parts.push(`${name}<${valueStr}${valueStr.endsWith(">") ? " " : ""}>`);
|
|
12560
|
+
case 32768: {
|
|
12561
|
+
return couldBe(pair.avalue.klass, pair.bvalue.klass) && (shallow || couldBeObj(pair.avalue.obj, pair.bvalue.obj));
|
|
12225
12562
|
}
|
|
12226
|
-
|
|
12563
|
+
case 65536: {
|
|
12564
|
+
return (!pair.avalue.value || !pair.bvalue.value || couldBe(pair.avalue.value, pair.bvalue.value)) && (0, import_chunk_X7QCZR3F.some)(
|
|
12565
|
+
pair.avalue.enum,
|
|
12566
|
+
(sna) => (0, import_chunk_X7QCZR3F.some)(pair.bvalue.enum, (snb) => sna === snb)
|
|
12567
|
+
);
|
|
12568
|
+
}
|
|
12569
|
+
default:
|
|
12570
|
+
unhandledType(pair);
|
|
12227
12571
|
}
|
|
12228
|
-
return parts.join(" or ");
|
|
12229
12572
|
}
|
|
12230
|
-
function
|
|
12231
|
-
|
|
12232
|
-
|
|
12573
|
+
function couldBeObj(a, b) {
|
|
12574
|
+
if (!a || !b)
|
|
12575
|
+
return true;
|
|
12576
|
+
return Object.entries(a).every(([key, value2]) => {
|
|
12577
|
+
if (!(0, import_chunk_JDC43A3I.hasProperty)(b, key))
|
|
12578
|
+
return true;
|
|
12579
|
+
return couldBe(value2, b[key]);
|
|
12580
|
+
});
|
|
12233
12581
|
}
|
|
12234
|
-
|
|
12235
|
-
|
|
12236
|
-
|
|
12237
|
-
|
|
12238
|
-
|
|
12239
|
-
|
|
12240
|
-
|
|
12241
|
-
|
|
12582
|
+
var init_could_be = (0, import_chunk_ABYVSU2C.__esm)({
|
|
12583
|
+
"src/type-flow/could-be.ts"() {
|
|
12584
|
+
"use strict";
|
|
12585
|
+
init_api();
|
|
12586
|
+
init_data_flow();
|
|
12587
|
+
(0, import_chunk_X7QCZR3F.init_util)();
|
|
12588
|
+
init_array_type();
|
|
12589
|
+
init_types();
|
|
12242
12590
|
}
|
|
12243
|
-
|
|
12244
|
-
|
|
12245
|
-
|
|
12246
|
-
|
|
12247
|
-
if (!bits)
|
|
12248
|
-
return;
|
|
12249
|
-
if ((v.type | bits) & UnionDataTypeTagsConst) {
|
|
12250
|
-
bits &= ~ValueTypeTagsConst;
|
|
12251
|
-
} else if (bits & bits - 1) {
|
|
12252
|
-
return;
|
|
12591
|
+
});
|
|
12592
|
+
function subtypeOf(a, b) {
|
|
12593
|
+
if (a.type & 262144 && a.value != null) {
|
|
12594
|
+
return subtypeOf(expandTypedef(a), b);
|
|
12253
12595
|
}
|
|
12254
|
-
|
|
12255
|
-
|
|
12256
|
-
do {
|
|
12257
|
-
const next = bits & bits - 1;
|
|
12258
|
-
const bit = bits - next;
|
|
12259
|
-
const data = hasUnion ? unionData[bit] : bit & v.type ? v.value : null;
|
|
12260
|
-
if (fn({ type: bit, value: data }) === false)
|
|
12261
|
-
break;
|
|
12262
|
-
bits = next;
|
|
12263
|
-
} while (bits);
|
|
12264
|
-
}
|
|
12265
|
-
function getUnionComponent(v, tag) {
|
|
12266
|
-
if (v.value == null)
|
|
12267
|
-
return null;
|
|
12268
|
-
let bits = v.type & ~SingletonTypeTagsConst;
|
|
12269
|
-
if (!bits)
|
|
12270
|
-
return null;
|
|
12271
|
-
if (bits & bits - 1) {
|
|
12272
|
-
bits &= UnionDataTypeTagsConst;
|
|
12273
|
-
if (!bits) {
|
|
12274
|
-
throw new Error(`Non-exact type had no union bits set`);
|
|
12275
|
-
}
|
|
12596
|
+
if (b.type & 262144 && b.value != null) {
|
|
12597
|
+
return subtypeOf(a, expandTypedef(b));
|
|
12276
12598
|
}
|
|
12277
|
-
if (
|
|
12278
|
-
|
|
12279
|
-
|
|
12280
|
-
|
|
12281
|
-
|
|
12599
|
+
if (a.type & 65536 && !(b.type & 65536) && b.type & EnumTagsConst) {
|
|
12600
|
+
const value2 = getUnionComponent(
|
|
12601
|
+
a,
|
|
12602
|
+
65536
|
|
12603
|
+
/* Enum */
|
|
12604
|
+
);
|
|
12605
|
+
if (!subtypeOf(typeFromEnumValue(value2), b)) {
|
|
12606
|
+
return false;
|
|
12607
|
+
}
|
|
12608
|
+
if (a.type === 65536)
|
|
12609
|
+
return true;
|
|
12610
|
+
const a2 = cloneType(a);
|
|
12611
|
+
clearValuesUnder(a2, 65536, true);
|
|
12612
|
+
return subtypeOf(a2, b);
|
|
12282
12613
|
}
|
|
12283
|
-
|
|
12284
|
-
|
|
12285
|
-
|
|
12286
|
-
|
|
12287
|
-
|
|
12288
|
-
|
|
12289
|
-
|
|
12290
|
-
v.value = value2;
|
|
12291
|
-
} else {
|
|
12292
|
-
v.value = c;
|
|
12614
|
+
let common = a.type & b.type;
|
|
12615
|
+
if (common !== a.type) {
|
|
12616
|
+
if (b.type & 32768 && getObjectValue(b) == null) {
|
|
12617
|
+
common |= a.type & ObjectLikeTagsConst;
|
|
12618
|
+
}
|
|
12619
|
+
if (common !== a.type)
|
|
12620
|
+
return false;
|
|
12293
12621
|
}
|
|
12622
|
+
if (b.value == null)
|
|
12623
|
+
return true;
|
|
12624
|
+
let result = true;
|
|
12625
|
+
forEachUnionComponent(b, common, (bc) => {
|
|
12626
|
+
const avalue = getUnionComponent(a, bc.type);
|
|
12627
|
+
if (bc.value == null || avalue === bc.value)
|
|
12628
|
+
return true;
|
|
12629
|
+
if (avalue == null || !subtypeOfValue({ type: bc.type, avalue, bvalue: bc.value })) {
|
|
12630
|
+
result = false;
|
|
12631
|
+
return false;
|
|
12632
|
+
}
|
|
12633
|
+
return true;
|
|
12634
|
+
});
|
|
12635
|
+
return result;
|
|
12294
12636
|
}
|
|
12295
|
-
function
|
|
12296
|
-
|
|
12297
|
-
|
|
12298
|
-
|
|
12299
|
-
|
|
12300
|
-
|
|
12301
|
-
|
|
12302
|
-
|
|
12303
|
-
|
|
12304
|
-
|
|
12305
|
-
|
|
12306
|
-
|
|
12307
|
-
|
|
12308
|
-
|
|
12309
|
-
|
|
12310
|
-
|
|
12311
|
-
|
|
12312
|
-
|
|
12313
|
-
|
|
12314
|
-
|
|
12315
|
-
|
|
12316
|
-
|
|
12317
|
-
|
|
12318
|
-
(
|
|
12319
|
-
|
|
12637
|
+
function subtypeOfValue(pair) {
|
|
12638
|
+
switch (pair.type) {
|
|
12639
|
+
case 1:
|
|
12640
|
+
case 2:
|
|
12641
|
+
case 4:
|
|
12642
|
+
case 262144:
|
|
12643
|
+
throw new Error(`Unexpected TypeTag '${typeTagName(pair.type)}'`);
|
|
12644
|
+
case 8:
|
|
12645
|
+
case 16:
|
|
12646
|
+
case 32:
|
|
12647
|
+
case 64:
|
|
12648
|
+
case 256:
|
|
12649
|
+
case 128:
|
|
12650
|
+
case 131072:
|
|
12651
|
+
return pair.avalue === pair.bvalue;
|
|
12652
|
+
case 512: {
|
|
12653
|
+
let result = true;
|
|
12654
|
+
tupleForEach(
|
|
12655
|
+
pair.avalue,
|
|
12656
|
+
(av) => {
|
|
12657
|
+
let some2 = false;
|
|
12658
|
+
tupleForEach(
|
|
12659
|
+
pair.bvalue,
|
|
12660
|
+
(bv) => {
|
|
12661
|
+
some2 = av.length === bv.length && bv.every((b, i) => subtypeOf(av[i], b));
|
|
12662
|
+
return some2 === false;
|
|
12663
|
+
},
|
|
12664
|
+
(bv) => (some2 = av.every((a) => subtypeOf(a, bv))) === false
|
|
12665
|
+
);
|
|
12666
|
+
return result = some2;
|
|
12667
|
+
},
|
|
12668
|
+
(av) => {
|
|
12669
|
+
let some2 = false;
|
|
12670
|
+
tupleForEach(
|
|
12671
|
+
pair.bvalue,
|
|
12672
|
+
() => {
|
|
12673
|
+
return true;
|
|
12674
|
+
},
|
|
12675
|
+
(bv) => (some2 = subtypeOf(av, bv)) === false
|
|
12676
|
+
);
|
|
12677
|
+
return result = some2;
|
|
12678
|
+
}
|
|
12679
|
+
);
|
|
12680
|
+
return result;
|
|
12681
|
+
}
|
|
12682
|
+
case 1024: {
|
|
12683
|
+
const adict = pair.avalue;
|
|
12684
|
+
const bdict = pair.bvalue;
|
|
12685
|
+
if (!adict.value) {
|
|
12686
|
+
if (!bdict.value) {
|
|
12687
|
+
return Array.from(adict).every(([key, av]) => {
|
|
12688
|
+
const bv = bdict.get(key);
|
|
12689
|
+
return !bv || subtypeOf(av, bv);
|
|
12690
|
+
});
|
|
12691
|
+
}
|
|
12692
|
+
return false;
|
|
12693
|
+
}
|
|
12694
|
+
if (!bdict.value) {
|
|
12695
|
+
return Array.from(bdict).every(([key, bv]) => {
|
|
12696
|
+
const kt = typeFromObjectLiteralKey(key);
|
|
12697
|
+
return !couldBe(kt, adict.key) || subtypeOf(adict.value, bv);
|
|
12698
|
+
});
|
|
12699
|
+
}
|
|
12700
|
+
return subtypeOf(adict.key, bdict.key) && subtypeOf(adict.value, bdict.value);
|
|
12701
|
+
}
|
|
12702
|
+
case 2048: {
|
|
12703
|
+
return pair.avalue.args.length === pair.bvalue.args.length && subtypeOf(pair.avalue.result, pair.bvalue.result) && pair.avalue.args.every((arg, i) => subtypeOf(pair.bvalue.args[i], arg));
|
|
12704
|
+
}
|
|
12705
|
+
case 4096:
|
|
12706
|
+
case 8192: {
|
|
12707
|
+
const asd = pair.avalue;
|
|
12708
|
+
const bsd = pair.bvalue;
|
|
12709
|
+
return (0, import_chunk_X7QCZR3F.every)(asd, (sna) => (0, import_chunk_X7QCZR3F.some)(bsd, (snb) => sna === snb));
|
|
12710
|
+
}
|
|
12711
|
+
case 16384: {
|
|
12712
|
+
const asd = pair.avalue;
|
|
12713
|
+
const bsd = pair.bvalue;
|
|
12714
|
+
return (0, import_chunk_X7QCZR3F.every)(asd, (sna) => {
|
|
12715
|
+
const superA = getSuperClasses(sna);
|
|
12716
|
+
return (0, import_chunk_X7QCZR3F.some)(bsd, (snb) => {
|
|
12717
|
+
if (sna === snb || superA && superA.has(snb)) {
|
|
12718
|
+
return true;
|
|
12719
|
+
}
|
|
12720
|
+
return false;
|
|
12721
|
+
});
|
|
12722
|
+
});
|
|
12723
|
+
}
|
|
12724
|
+
case 32768: {
|
|
12725
|
+
const aobj = pair.avalue;
|
|
12726
|
+
const bobj = pair.bvalue;
|
|
12727
|
+
return subtypeOf(aobj.klass, bobj.klass) && subtypeOfObj(aobj.obj, bobj.obj);
|
|
12728
|
+
}
|
|
12729
|
+
case 65536: {
|
|
12730
|
+
const aenum = pair.avalue;
|
|
12731
|
+
const benum = pair.bvalue;
|
|
12732
|
+
if (benum.value) {
|
|
12733
|
+
if (!aenum.value || !subtypeOf(aenum.value, benum.value)) {
|
|
12734
|
+
return false;
|
|
12320
12735
|
}
|
|
12321
12736
|
}
|
|
12322
|
-
|
|
12323
|
-
|
|
12324
|
-
|
|
12325
|
-
|
|
12326
|
-
bits -= 32768;
|
|
12327
|
-
}
|
|
12328
|
-
if (bits) {
|
|
12329
|
-
do {
|
|
12330
|
-
let next = bits & bits - 1;
|
|
12331
|
-
let bit = bits - next;
|
|
12332
|
-
if (bit & 6) {
|
|
12333
|
-
bit = 6;
|
|
12334
|
-
next &= ~6;
|
|
12335
|
-
}
|
|
12336
|
-
const name = `Toybox.Lang.${typeTagName(bit)}`;
|
|
12337
|
-
const sns = lookupByFullName(state, name);
|
|
12338
|
-
sns.forEach((sn) => isStateNode(sn) && decls.push({ sn, exact: true }));
|
|
12339
|
-
bits = next;
|
|
12340
|
-
} while (bits);
|
|
12737
|
+
return (0, import_chunk_X7QCZR3F.every)(aenum.enum, (ea) => (0, import_chunk_X7QCZR3F.some)(benum.enum, (eb) => ea === eb));
|
|
12738
|
+
}
|
|
12739
|
+
default:
|
|
12740
|
+
unhandledType(pair);
|
|
12341
12741
|
}
|
|
12342
|
-
return decls;
|
|
12343
12742
|
}
|
|
12743
|
+
function subtypeOfObj(a, b) {
|
|
12744
|
+
if (!a || !b)
|
|
12745
|
+
return true;
|
|
12746
|
+
return Object.entries(b).every(([key, value2]) => {
|
|
12747
|
+
if (!(0, import_chunk_JDC43A3I.hasProperty)(a, key))
|
|
12748
|
+
return false;
|
|
12749
|
+
return subtypeOf(a[key], value2);
|
|
12750
|
+
});
|
|
12751
|
+
}
|
|
12752
|
+
var init_sub_type = (0, import_chunk_ABYVSU2C.__esm)({
|
|
12753
|
+
"src/type-flow/sub-type.ts"() {
|
|
12754
|
+
"use strict";
|
|
12755
|
+
init_api();
|
|
12756
|
+
init_data_flow();
|
|
12757
|
+
(0, import_chunk_X7QCZR3F.init_util)();
|
|
12758
|
+
init_array_type();
|
|
12759
|
+
init_could_be();
|
|
12760
|
+
init_intersection_type();
|
|
12761
|
+
init_types();
|
|
12762
|
+
init_union_type();
|
|
12763
|
+
}
|
|
12764
|
+
});
|
|
12344
12765
|
function tupleForEach(t, tupleFn, arrayFn) {
|
|
12345
12766
|
if (t instanceof Set) {
|
|
12346
12767
|
for (const v of t) {
|
|
@@ -12369,6 +12790,11 @@ function reducedArrayType(t) {
|
|
|
12369
12790
|
}
|
|
12370
12791
|
return reducedType(t);
|
|
12371
12792
|
}
|
|
12793
|
+
function restrictArrayData(constraint, tracked) {
|
|
12794
|
+
const trackedType = { type: 512, value: tracked };
|
|
12795
|
+
const result = (constraint instanceof Set ? Array.from(constraint) : [constraint]).filter((value2) => couldBe({ type: 512, value: value2 }, trackedType));
|
|
12796
|
+
return result.length === 0 ? constraint : result.length === 1 ? result[0] : new Set(result);
|
|
12797
|
+
}
|
|
12372
12798
|
function checkArrayCovariance(arg, param) {
|
|
12373
12799
|
let ok = true;
|
|
12374
12800
|
tupleForEach(
|
|
@@ -12414,205 +12840,12 @@ function checkArrayCovariance(arg, param) {
|
|
|
12414
12840
|
function safeReferenceArg(arg) {
|
|
12415
12841
|
return arg.type === "ArrayExpression" || arg.type === "ObjectExpression" || arg.type === "NewExpression";
|
|
12416
12842
|
}
|
|
12417
|
-
var
|
|
12418
|
-
|
|
12419
|
-
"src/type-flow/types.ts"() {
|
|
12843
|
+
var init_array_type = (0, import_chunk_ABYVSU2C.__esm)({
|
|
12844
|
+
"src/type-flow/array-type.ts"() {
|
|
12420
12845
|
"use strict";
|
|
12421
|
-
init_api();
|
|
12422
|
-
(0, import_chunk_JDC43A3I.init_ast)();
|
|
12423
|
-
init_data_flow();
|
|
12424
|
-
(0, import_chunk_X7QCZR3F.init_util)();
|
|
12425
|
-
init_interp();
|
|
12426
|
-
init_intersection_type();
|
|
12427
|
-
init_union_type();
|
|
12428
12846
|
init_sub_type();
|
|
12429
|
-
LastTypeTag = 262144;
|
|
12430
|
-
SingletonTypeTagsConst = 1 | 2 | 4;
|
|
12431
|
-
UnionDataTypeTagsConst = 512 | 1024 | 2048 | 4096 | 8192 | 16384 | 32768 | 65536 | 262144;
|
|
12432
|
-
ValueTypeTagsConst = 8 | 16 | 32 | 64 | 128 | 256 | 131072;
|
|
12433
|
-
ObjectLikeTagsConst = 6 | ValueTypeTagsConst | 512 | 1024 | 2048 | 65536;
|
|
12434
|
-
EnumTagsConst = SingletonTypeTagsConst | ValueTypeTagsConst & ~131072;
|
|
12435
|
-
TruthyTypes = 4 | // TypeTag.Object | // omit because of missing null on various Toybox types
|
|
12436
|
-
4096 | 16384 | 8192;
|
|
12437
|
-
}
|
|
12438
|
-
});
|
|
12439
|
-
function couldBeHelper(a, b, shallow) {
|
|
12440
|
-
const common = a.type & b.type & ~262144;
|
|
12441
|
-
if (common) {
|
|
12442
|
-
if (a.value == null || b.value == null || a.value === b.value) {
|
|
12443
|
-
return true;
|
|
12444
|
-
}
|
|
12445
|
-
if (common & SingletonTypeTagsConst) {
|
|
12446
|
-
return true;
|
|
12447
|
-
}
|
|
12448
|
-
if (common & ValueTypeTagsConst && common & UnionDataTypeTagsConst) {
|
|
12449
|
-
return true;
|
|
12450
|
-
}
|
|
12451
|
-
let result = false;
|
|
12452
|
-
forEachUnionComponent(a, common, (ac) => {
|
|
12453
|
-
if (ac.value == null) {
|
|
12454
|
-
result = true;
|
|
12455
|
-
return false;
|
|
12456
|
-
}
|
|
12457
|
-
const bvalue = getUnionComponent(b, ac.type);
|
|
12458
|
-
if (bvalue == null || ac.value === bvalue || couldBeValue(
|
|
12459
|
-
{ type: ac.type, avalue: ac.value, bvalue },
|
|
12460
|
-
shallow
|
|
12461
|
-
)) {
|
|
12462
|
-
result = true;
|
|
12463
|
-
return false;
|
|
12464
|
-
}
|
|
12465
|
-
return true;
|
|
12466
|
-
});
|
|
12467
|
-
if (result)
|
|
12468
|
-
return true;
|
|
12469
|
-
}
|
|
12470
|
-
if (a.type & 65536 && b.type & (EnumTagsConst | 65536) || b.type & 65536 && a.type & (EnumTagsConst | 65536)) {
|
|
12471
|
-
return true;
|
|
12472
|
-
}
|
|
12473
|
-
if (a.type & 32768 && b.type & ObjectLikeTagsConst && getObjectValue(a) == null) {
|
|
12474
|
-
return true;
|
|
12475
|
-
}
|
|
12476
|
-
if (b.type & 32768 && a.type & ObjectLikeTagsConst && getObjectValue(b) == null) {
|
|
12477
|
-
return true;
|
|
12478
|
-
}
|
|
12479
|
-
const checkTypedef = (t, other) => {
|
|
12480
|
-
const typedef = getUnionComponent(
|
|
12481
|
-
t,
|
|
12482
|
-
262144
|
|
12483
|
-
/* Typedef */
|
|
12484
|
-
);
|
|
12485
|
-
return typedef && (0, import_chunk_X7QCZR3F.some)(typedef, (td) => {
|
|
12486
|
-
if (!td.resolvedType) {
|
|
12487
|
-
throw new Error(`No resolved type for ${td.fullName} in 'couldBe'`);
|
|
12488
|
-
}
|
|
12489
|
-
return couldBe(td.resolvedType, other);
|
|
12490
|
-
});
|
|
12491
|
-
};
|
|
12492
|
-
if (a.type & 262144 && checkTypedef(a, b)) {
|
|
12493
|
-
return true;
|
|
12494
|
-
}
|
|
12495
|
-
if (b.type & 262144 && checkTypedef(b, a)) {
|
|
12496
|
-
return true;
|
|
12497
|
-
}
|
|
12498
|
-
return false;
|
|
12499
|
-
}
|
|
12500
|
-
function couldBe(a, b) {
|
|
12501
|
-
return couldBeHelper(a, b, false);
|
|
12502
|
-
}
|
|
12503
|
-
function couldBeWeak(a, b) {
|
|
12504
|
-
if (a.type === 0 || b.type === 0)
|
|
12505
|
-
return true;
|
|
12506
|
-
return couldBe(a, b);
|
|
12507
|
-
}
|
|
12508
|
-
function couldBeShallow(a, b) {
|
|
12509
|
-
return couldBeHelper(a, b, true);
|
|
12510
|
-
}
|
|
12511
|
-
function couldBeValue(pair, shallow) {
|
|
12512
|
-
switch (pair.type) {
|
|
12513
|
-
case 1:
|
|
12514
|
-
case 2:
|
|
12515
|
-
case 4:
|
|
12516
|
-
case 262144:
|
|
12517
|
-
throw new Error(`Unexpected TypeTag '${typeTagName(pair.type)}'`);
|
|
12518
|
-
case 8:
|
|
12519
|
-
case 16:
|
|
12520
|
-
case 32:
|
|
12521
|
-
case 64:
|
|
12522
|
-
case 256:
|
|
12523
|
-
case 128:
|
|
12524
|
-
case 131072:
|
|
12525
|
-
return pair.avalue === pair.bvalue;
|
|
12526
|
-
case 512: {
|
|
12527
|
-
if (shallow)
|
|
12528
|
-
return true;
|
|
12529
|
-
let result = false;
|
|
12530
|
-
tupleForEach(
|
|
12531
|
-
pair.avalue,
|
|
12532
|
-
(av) => {
|
|
12533
|
-
tupleForEach(
|
|
12534
|
-
pair.bvalue,
|
|
12535
|
-
(bv) => {
|
|
12536
|
-
result = av.length === bv.length && bv.every((b, i) => couldBe(av[i], b));
|
|
12537
|
-
return result === false;
|
|
12538
|
-
},
|
|
12539
|
-
(bv) => {
|
|
12540
|
-
result = av.every((a) => couldBe(a, bv));
|
|
12541
|
-
return result === false;
|
|
12542
|
-
}
|
|
12543
|
-
);
|
|
12544
|
-
return result === false;
|
|
12545
|
-
},
|
|
12546
|
-
(av) => {
|
|
12547
|
-
tupleForEach(
|
|
12548
|
-
pair.bvalue,
|
|
12549
|
-
(bv) => {
|
|
12550
|
-
result = bv.every((b) => couldBe(av, b));
|
|
12551
|
-
return result === false;
|
|
12552
|
-
},
|
|
12553
|
-
(bv) => (result = couldBe(av, bv)) === false
|
|
12554
|
-
);
|
|
12555
|
-
return result === false;
|
|
12556
|
-
}
|
|
12557
|
-
);
|
|
12558
|
-
return result;
|
|
12559
|
-
}
|
|
12560
|
-
case 1024: {
|
|
12561
|
-
if (shallow)
|
|
12562
|
-
return true;
|
|
12563
|
-
if (!pair.avalue.value || !pair.bvalue.value) {
|
|
12564
|
-
return true;
|
|
12565
|
-
}
|
|
12566
|
-
return couldBe(pair.avalue.key, pair.bvalue.key) && couldBe(pair.avalue.value, pair.bvalue.value);
|
|
12567
|
-
}
|
|
12568
|
-
case 2048: {
|
|
12569
|
-
return pair.avalue.args.length === pair.bvalue.args.length && couldBe(pair.avalue.result, pair.bvalue.result) && pair.avalue.args.every((arg, i) => couldBe(arg, pair.bvalue.args[i]));
|
|
12570
|
-
}
|
|
12571
|
-
case 4096:
|
|
12572
|
-
case 8192: {
|
|
12573
|
-
return (0, import_chunk_X7QCZR3F.some)(
|
|
12574
|
-
pair.avalue,
|
|
12575
|
-
(sna) => (0, import_chunk_X7QCZR3F.some)(pair.bvalue, (snb) => sna === snb)
|
|
12576
|
-
);
|
|
12577
|
-
}
|
|
12578
|
-
case 16384: {
|
|
12579
|
-
return (0, import_chunk_X7QCZR3F.some)(pair.avalue, (sna) => {
|
|
12580
|
-
const superA = getSuperClasses(sna);
|
|
12581
|
-
return (0, import_chunk_X7QCZR3F.some)(pair.bvalue, (snb) => {
|
|
12582
|
-
if (sna === snb || superA && superA.has(snb)) {
|
|
12583
|
-
return true;
|
|
12584
|
-
}
|
|
12585
|
-
const superB = getSuperClasses(snb);
|
|
12586
|
-
return superB ? superB.has(sna) : false;
|
|
12587
|
-
});
|
|
12588
|
-
});
|
|
12589
|
-
}
|
|
12590
|
-
case 32768: {
|
|
12591
|
-
return couldBe(pair.avalue.klass, pair.bvalue.klass) && (shallow || couldBeObj(pair.avalue.obj, pair.bvalue.obj));
|
|
12592
|
-
}
|
|
12593
|
-
case 65536: {
|
|
12594
|
-
return pair.avalue.enum === pair.bvalue.enum && (!pair.avalue.value || !pair.bvalue.value || couldBe(pair.avalue.value, pair.bvalue.value));
|
|
12595
|
-
}
|
|
12596
|
-
default:
|
|
12597
|
-
unhandledType(pair);
|
|
12598
|
-
}
|
|
12599
|
-
}
|
|
12600
|
-
function couldBeObj(a, b) {
|
|
12601
|
-
if (!a || !b)
|
|
12602
|
-
return true;
|
|
12603
|
-
return Object.entries(a).every(([key, value2]) => {
|
|
12604
|
-
if (!(0, import_chunk_JDC43A3I.hasProperty)(b, key))
|
|
12605
|
-
return true;
|
|
12606
|
-
return couldBe(value2, b[key]);
|
|
12607
|
-
});
|
|
12608
|
-
}
|
|
12609
|
-
var init_could_be = (0, import_chunk_ABYVSU2C.__esm)({
|
|
12610
|
-
"src/type-flow/could-be.ts"() {
|
|
12611
|
-
"use strict";
|
|
12612
|
-
init_api();
|
|
12613
|
-
init_data_flow();
|
|
12614
|
-
(0, import_chunk_X7QCZR3F.init_util)();
|
|
12615
12847
|
init_types();
|
|
12848
|
+
init_could_be();
|
|
12616
12849
|
}
|
|
12617
12850
|
});
|
|
12618
12851
|
function cloneAnt(antMap) {
|
|
@@ -13825,7 +14058,8 @@ function propagateTypes(state, root, graph, optimizeEquivalencies, copyPropStore
|
|
|
13825
14058
|
istate,
|
|
13826
14059
|
callee,
|
|
13827
14060
|
calleeObj,
|
|
13828
|
-
() => node.arguments.map((arg) => evaluateExpr(state, arg, typeMap).value)
|
|
14061
|
+
() => node.arguments.map((arg) => evaluateExpr(state, arg, typeMap).value),
|
|
14062
|
+
node
|
|
13829
14063
|
);
|
|
13830
14064
|
if (!result.effectFree) {
|
|
13831
14065
|
effectFree = false;
|
|
@@ -14990,6 +15224,7 @@ var init_type_flow = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
14990
15224
|
init_function_info();
|
|
14991
15225
|
init_inliner();
|
|
14992
15226
|
init_optimizer_types();
|
|
15227
|
+
init_array_type();
|
|
14993
15228
|
init_could_be();
|
|
14994
15229
|
init_dead_store();
|
|
14995
15230
|
init_interp();
|
|
@@ -17182,6 +17417,7 @@ async function analyze(fnMap, resourcesMap, manifestXML, config, allowParseError
|
|
|
17182
17417
|
allClasses: [],
|
|
17183
17418
|
nestedClasses: {},
|
|
17184
17419
|
allModules: /* @__PURE__ */ new Set(),
|
|
17420
|
+
allCached: /* @__PURE__ */ new Set(),
|
|
17185
17421
|
shouldExclude(node) {
|
|
17186
17422
|
if ("attrs" in node && node.attrs && "attributes" in node.attrs && node.attrs.attributes && node.loc?.source) {
|
|
17187
17423
|
const excludeAnnotations = fnMap[node.loc.source].excludeAnnotations;
|
|
@@ -17873,8 +18109,9 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17873
18109
|
if (ret === false) {
|
|
17874
18110
|
changes |= 1;
|
|
17875
18111
|
this.removeNodeComments(node, f.ast);
|
|
18112
|
+
clearDiagnostics(this, node);
|
|
17876
18113
|
} else if (ret) {
|
|
17877
|
-
if (node.type === "EnumDeclaration" && ret.type === "TypedefDeclaration"
|
|
18114
|
+
if (node.type === "EnumDeclaration" && ret.type === "TypedefDeclaration") {
|
|
17878
18115
|
changes |= 2;
|
|
17879
18116
|
} else {
|
|
17880
18117
|
changes |= 1;
|
|
@@ -17883,6 +18120,9 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17883
18120
|
return ret;
|
|
17884
18121
|
};
|
|
17885
18122
|
collectNamespaces(f.ast, state2);
|
|
18123
|
+
if (changes & 2) {
|
|
18124
|
+
state2.allCached?.forEach((t) => delete t.resolvedType);
|
|
18125
|
+
}
|
|
17886
18126
|
return changes;
|
|
17887
18127
|
},
|
|
17888
18128
|
0
|
|
@@ -18074,14 +18314,10 @@ function cleanup(state, node, ast, usedNodes) {
|
|
|
18074
18314
|
(d) => d.type === "EnumDeclaration" && d.node === node
|
|
18075
18315
|
);
|
|
18076
18316
|
if (i >= 0) {
|
|
18077
|
-
const
|
|
18078
|
-
|
|
18079
|
-
|
|
18080
|
-
type: "TypedefDeclaration",
|
|
18081
|
-
node: typedefDecl
|
|
18082
|
-
};
|
|
18317
|
+
const rep = decls[i];
|
|
18318
|
+
rep.type = "TypedefDeclaration";
|
|
18319
|
+
rep.node = typedefDecl;
|
|
18083
18320
|
delete rep.resolvedType;
|
|
18084
|
-
decls.splice(i, 1, rep);
|
|
18085
18321
|
}
|
|
18086
18322
|
}
|
|
18087
18323
|
return typedefDecl;
|
|
@@ -18541,8 +18777,11 @@ function visit_resource_refs(state, doc, e, barrelNames) {
|
|
|
18541
18777
|
loc.start.offset -= name.length;
|
|
18542
18778
|
}
|
|
18543
18779
|
} else {
|
|
18544
|
-
const
|
|
18545
|
-
const
|
|
18780
|
+
const colonPos = name.indexOf(":");
|
|
18781
|
+
const barrel = colonPos < 0 ? "" : name.slice(0, colonPos) + ".";
|
|
18782
|
+
name = name.slice(colonPos + 1);
|
|
18783
|
+
const base = (0, import_chunk_JDC43A3I.makeScopedName)(`${barrel}Rez.Styles`);
|
|
18784
|
+
const idLoc = (0, import_chunk_JDC43A3I.adjustLoc)(loc, colonPos + 1, 0);
|
|
18546
18785
|
idLoc.end = { ...idLoc.start };
|
|
18547
18786
|
idLoc.end.column += name.length;
|
|
18548
18787
|
idLoc.end.offset += name.length;
|
|
@@ -19824,6 +20063,7 @@ function stateFuncs() {
|
|
|
19824
20063
|
if (decl.type === "EnumDeclaration") {
|
|
19825
20064
|
currentEnum = decl;
|
|
19826
20065
|
}
|
|
20066
|
+
this.allCached?.add(decl);
|
|
19827
20067
|
break;
|
|
19828
20068
|
}
|
|
19829
20069
|
case "VariableDeclaration": {
|
|
@@ -19842,19 +20082,21 @@ function stateFuncs() {
|
|
|
19842
20082
|
return;
|
|
19843
20083
|
}
|
|
19844
20084
|
decl.kind = node.kind;
|
|
19845
|
-
|
|
20085
|
+
const vsn = {
|
|
19846
20086
|
type: "VariableDeclarator",
|
|
19847
20087
|
node: decl,
|
|
19848
20088
|
name,
|
|
19849
20089
|
fullName: parent.fullName + "." + name,
|
|
19850
20090
|
stack,
|
|
19851
20091
|
attributes: stateNodeAttrs(node.attrs)
|
|
19852
|
-
}
|
|
20092
|
+
};
|
|
20093
|
+
decls[name].push(vsn);
|
|
19853
20094
|
if (node.kind === "const") {
|
|
19854
20095
|
if (!(0, import_chunk_JDC43A3I.hasProperty)(this.index, name)) {
|
|
19855
20096
|
this.index[name] = [];
|
|
19856
20097
|
}
|
|
19857
20098
|
(0, import_chunk_X7QCZR3F.pushUnique)(this.index[name], parent);
|
|
20099
|
+
this.allCached?.add(vsn);
|
|
19858
20100
|
}
|
|
19859
20101
|
});
|
|
19860
20102
|
break;
|
|
@@ -20384,6 +20626,20 @@ function resolveDiagnosticsMap(diagnosticsMap) {
|
|
|
20384
20626
|
)
|
|
20385
20627
|
).then(() => diagnosticsMap);
|
|
20386
20628
|
}
|
|
20629
|
+
function clearDiagnostics(state, node) {
|
|
20630
|
+
const loc = node.loc;
|
|
20631
|
+
if (!loc?.source)
|
|
20632
|
+
return;
|
|
20633
|
+
const diagnostics = state.diagnostics?.[loc.source];
|
|
20634
|
+
if (!diagnostics)
|
|
20635
|
+
return;
|
|
20636
|
+
for (let i = diagnostics.length; i--; ) {
|
|
20637
|
+
const diagnostic2 = diagnostics[i];
|
|
20638
|
+
if (diagnostic2.loc.start.offset >= loc.start.offset && diagnostic2.loc.end.offset <= loc.end.offset) {
|
|
20639
|
+
diagnostics.splice(i, 1);
|
|
20640
|
+
}
|
|
20641
|
+
}
|
|
20642
|
+
}
|
|
20387
20643
|
function diagnostic(state, node, message, type = "INFO", extra) {
|
|
20388
20644
|
if (!state.diagnostics)
|
|
20389
20645
|
state.diagnostics = {};
|
|
@@ -30406,7 +30662,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
|
|
|
30406
30662
|
const opt_time = await (0, import_chunk_X7QCZR3F.first_modified)(
|
|
30407
30663
|
Object.values(fnMap).map((v) => v.output)
|
|
30408
30664
|
);
|
|
30409
|
-
if (source_time < opt_time &&
|
|
30665
|
+
if (source_time < opt_time && 1733273606476 < opt_time) {
|
|
30410
30666
|
return {
|
|
30411
30667
|
hasTests,
|
|
30412
30668
|
diagnostics: prevDiagnostics,
|
|
@@ -30444,7 +30700,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
|
|
|
30444
30700
|
hasTests: hasTests2,
|
|
30445
30701
|
diagnostics,
|
|
30446
30702
|
sdkVersion,
|
|
30447
|
-
optimizerVersion: "1.1.
|
|
30703
|
+
optimizerVersion: "1.1.84",
|
|
30448
30704
|
...Object.fromEntries(
|
|
30449
30705
|
configOptionsToCheck.map((option) => [option, config[option]])
|
|
30450
30706
|
)
|
|
@@ -31275,6 +31531,7 @@ var init_sdk_util = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
31275
31531
|
buildConfigDescription,
|
|
31276
31532
|
buildOptimizedProject,
|
|
31277
31533
|
checkCompilerVersion,
|
|
31534
|
+
clearDiagnostics,
|
|
31278
31535
|
collectNamespaces,
|
|
31279
31536
|
connectiq,
|
|
31280
31537
|
couldBe,
|