@markw65/monkeyc-optimizer 1.1.69 → 1.1.71
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 +13 -0
- package/build/api.cjs +41 -35
- package/build/{chunk-YERUPFGW.cjs → chunk-DI3VCMXL.cjs} +985 -618
- package/build/{chunk-OASVKTK5.cjs → chunk-NHZRKHZO.cjs} +4 -3
- package/build/optimizer.cjs +20 -20
- package/build/sdk-util.cjs +15 -15
- package/build/src/api.d.ts +5 -1
- package/build/src/control-flow.d.ts +3 -2
- package/build/src/data-flow.d.ts +15 -5
- package/build/src/logger.d.ts +1 -1
- package/build/src/optimizer-types.d.ts +7 -5
- package/build/src/type-flow/interp.d.ts +11 -2
- package/build/src/type-flow/module-types.d.ts +3 -0
- package/build/src/type-flow.d.ts +2 -1
- package/build/util.cjs +26 -26
- package/build/worker-thread.cjs +4 -4
- 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_DI3VCMXL_exports = {};
|
|
30
|
+
__export(chunk_DI3VCMXL_exports, {
|
|
31
31
|
EnumTagsConst: () => EnumTagsConst,
|
|
32
32
|
LastTypeTag: () => LastTypeTag,
|
|
33
33
|
ObjectLikeTagsConst: () => ObjectLikeTagsConst,
|
|
@@ -71,6 +71,7 @@ __export(chunk_YERUPFGW_exports, {
|
|
|
71
71
|
getSdkPath: () => getSdkPath,
|
|
72
72
|
getSuperClasses: () => getSuperClasses,
|
|
73
73
|
get_jungle: () => get_jungle,
|
|
74
|
+
handleImportUsing: () => handleImportUsing,
|
|
74
75
|
init_api: () => init_api,
|
|
75
76
|
init_bytecode: () => init_bytecode,
|
|
76
77
|
init_could_be: () => init_could_be,
|
|
@@ -116,6 +117,8 @@ __export(chunk_YERUPFGW_exports, {
|
|
|
116
117
|
parseSdkVersion: () => parseSdkVersion,
|
|
117
118
|
parseXml: () => parseXml,
|
|
118
119
|
performTask: () => performTask,
|
|
120
|
+
popRootNode: () => popRootNode,
|
|
121
|
+
pushRootNode: () => pushRootNode,
|
|
119
122
|
readPrg: () => readPrg,
|
|
120
123
|
readPrgWithOffsets: () => readPrgWithOffsets,
|
|
121
124
|
resolveDiagnostics: () => resolveDiagnostics,
|
|
@@ -135,8 +138,8 @@ __export(chunk_YERUPFGW_exports, {
|
|
|
135
138
|
visitorNode: () => visitorNode,
|
|
136
139
|
xml_util_exports: () => xml_util_exports
|
|
137
140
|
});
|
|
138
|
-
module.exports = __toCommonJS(
|
|
139
|
-
var
|
|
141
|
+
module.exports = __toCommonJS(chunk_DI3VCMXL_exports);
|
|
142
|
+
var import_chunk_NHZRKHZO = require("./chunk-NHZRKHZO.cjs");
|
|
140
143
|
var import_chunk_JDC43A3I = require("./chunk-JDC43A3I.cjs");
|
|
141
144
|
var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
|
|
142
145
|
var import_node_assert = __toESM(require("node:assert"));
|
|
@@ -6065,7 +6068,7 @@ function getArgSafety(state, func, args, requireAll) {
|
|
|
6065
6068
|
const { pre, post, stack } = state;
|
|
6066
6069
|
try {
|
|
6067
6070
|
delete state.pre;
|
|
6068
|
-
state.post = (node)
|
|
6071
|
+
state.post = function(node) {
|
|
6069
6072
|
switch (node.type) {
|
|
6070
6073
|
case "AssignmentExpression":
|
|
6071
6074
|
case "UpdateExpression": {
|
|
@@ -6076,7 +6079,7 @@ function getArgSafety(state, func, args, requireAll) {
|
|
|
6076
6079
|
}
|
|
6077
6080
|
if (modifiedUnknown)
|
|
6078
6081
|
break;
|
|
6079
|
-
const [, results] =
|
|
6082
|
+
const [, results] = this.lookup(v);
|
|
6080
6083
|
if (results) {
|
|
6081
6084
|
results.forEach(
|
|
6082
6085
|
(r) => r.results.forEach(
|
|
@@ -6091,16 +6094,16 @@ function getArgSafety(state, func, args, requireAll) {
|
|
|
6091
6094
|
case "CallExpression":
|
|
6092
6095
|
case "NewExpression":
|
|
6093
6096
|
if (!modifiedUnknown) {
|
|
6094
|
-
const [, results] =
|
|
6097
|
+
const [, results] = this.lookup(
|
|
6095
6098
|
node.callee,
|
|
6096
6099
|
null,
|
|
6097
6100
|
// calls are looked up as non-locals, but new is not
|
|
6098
|
-
node.type === "CallExpression" ? func.stack :
|
|
6101
|
+
node.type === "CallExpression" ? func.stack : this.stack
|
|
6099
6102
|
);
|
|
6100
6103
|
if (!results) {
|
|
6101
6104
|
const callee_name = node.callee.type === "Identifier" ? node.callee : node.callee.type === "MemberExpression" ? isLookupCandidate(node.callee) : null;
|
|
6102
6105
|
if (callee_name) {
|
|
6103
|
-
const callees =
|
|
6106
|
+
const callees = this.allFunctions[callee_name.name];
|
|
6104
6107
|
if (callees) {
|
|
6105
6108
|
callees.forEach((callee) => callsSeen.add(callee));
|
|
6106
6109
|
}
|
|
@@ -6117,7 +6120,7 @@ function getArgSafety(state, func, args, requireAll) {
|
|
|
6117
6120
|
break;
|
|
6118
6121
|
case "Identifier":
|
|
6119
6122
|
if ((0, import_chunk_JDC43A3I.hasProperty)(params, node.name) && !safeArgs[params[node.name]] && (modifiedUnknown || !argDecls[params[node.name]] || modifiedDecls.has(argDecls[params[node.name]]) || Array.from(callsSeen).some(
|
|
6120
|
-
(callee) => functionMayModify(
|
|
6123
|
+
(callee) => functionMayModify(this, callee, argDecls[params[node.name]])
|
|
6121
6124
|
))) {
|
|
6122
6125
|
safeArgs[params[node.name]] = null;
|
|
6123
6126
|
}
|
|
@@ -6274,20 +6277,20 @@ function processInlineBody(state, func, call, root, params) {
|
|
|
6274
6277
|
const replacements = /* @__PURE__ */ new Set();
|
|
6275
6278
|
const lookupStack = func.stack.concat({ sn: func });
|
|
6276
6279
|
try {
|
|
6277
|
-
state.pre = (node)
|
|
6280
|
+
state.pre = function(node) {
|
|
6278
6281
|
if (failed)
|
|
6279
6282
|
return [];
|
|
6280
6283
|
if (replacements.has(node))
|
|
6281
6284
|
return false;
|
|
6282
|
-
const result = pre(
|
|
6285
|
+
const result = pre.call(this, node);
|
|
6283
6286
|
if (!insertedVariableDecls && node.type === "BlockStatement") {
|
|
6284
|
-
fixupLocalsMap(
|
|
6285
|
-
const locals =
|
|
6287
|
+
fixupLocalsMap(this);
|
|
6288
|
+
const locals = this.localsStack[this.localsStack.length - 1];
|
|
6286
6289
|
const declarations = func.node.params.map((param, i) => {
|
|
6287
6290
|
const paramName = variableDeclarationName(param);
|
|
6288
6291
|
if (params[paramName] >= 0)
|
|
6289
6292
|
return null;
|
|
6290
|
-
const name = renameVariable(
|
|
6293
|
+
const name = renameVariable(this, locals, paramName) || paramName;
|
|
6291
6294
|
locals.map[name] = true;
|
|
6292
6295
|
return {
|
|
6293
6296
|
type: "VariableDeclarator",
|
|
@@ -6331,9 +6334,9 @@ function processInlineBody(state, func, call, root, params) {
|
|
|
6331
6334
|
}
|
|
6332
6335
|
return replacement;
|
|
6333
6336
|
};
|
|
6334
|
-
state.post = (node)
|
|
6337
|
+
state.post = function(node) {
|
|
6335
6338
|
if (failed)
|
|
6336
|
-
return post(
|
|
6339
|
+
return post.call(this, node);
|
|
6337
6340
|
let replacement = null;
|
|
6338
6341
|
switch (node.type) {
|
|
6339
6342
|
case "AssignmentExpression":
|
|
@@ -6356,7 +6359,7 @@ function processInlineBody(state, func, call, root, params) {
|
|
|
6356
6359
|
replacement = fixId(node);
|
|
6357
6360
|
break;
|
|
6358
6361
|
}
|
|
6359
|
-
const ret2 = post(replacement || node
|
|
6362
|
+
const ret2 = post.call(this, replacement || node);
|
|
6360
6363
|
return ret2 === false || ret2 ? ret2 : replacement;
|
|
6361
6364
|
};
|
|
6362
6365
|
let ret = state.traverse(root);
|
|
@@ -6914,14 +6917,15 @@ function pragmaChecker(state, ast, diagnostics) {
|
|
|
6914
6917
|
if (node.start && node.start >= (comment.end || Infinity)) {
|
|
6915
6918
|
const { kind, quote, needle } = matchers.shift();
|
|
6916
6919
|
if (kind === "match") {
|
|
6920
|
+
const thisComment = comment;
|
|
6917
6921
|
promise = promise.then(
|
|
6918
|
-
() =>
|
|
6922
|
+
() => formatAstLongLines(node).then((haystack) => {
|
|
6919
6923
|
haystack = haystack.replace(/([\r\n]|\s)+/g, " ").replace(/\b\w+\s\/\*>([\w.]+)<\*\//g, "$1");
|
|
6920
6924
|
if (!matcher(quote, needle, haystack)) {
|
|
6921
6925
|
matcher(quote, needle, haystack);
|
|
6922
6926
|
diagnostic(
|
|
6923
6927
|
state,
|
|
6924
|
-
|
|
6928
|
+
thisComment,
|
|
6925
6929
|
`Didn't find '${needle}' in '${haystack}'`,
|
|
6926
6930
|
"ERROR"
|
|
6927
6931
|
);
|
|
@@ -6990,20 +6994,29 @@ var init_pragma_checker = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
6990
6994
|
(0, import_chunk_JDC43A3I.init_ast)();
|
|
6991
6995
|
}
|
|
6992
6996
|
});
|
|
6993
|
-
function buildReducedGraph(state,
|
|
6997
|
+
function buildReducedGraph(state, root, refsForUpdate, notice) {
|
|
6994
6998
|
const { stack, pre, post } = state;
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
const
|
|
6999
|
+
const localState = new LocalState();
|
|
7000
|
+
const ret = localState.curBlock;
|
|
7001
|
+
const processOne = (rootNode, rootStack) => {
|
|
7002
|
+
localState.push(rootNode);
|
|
7003
|
+
state.stack = [...rootStack];
|
|
7004
|
+
const stmtStack = [rootNode];
|
|
7005
|
+
const testStack = [{ node: rootNode }];
|
|
7001
7006
|
const allEvents = [];
|
|
7002
7007
|
const eventsStack = [];
|
|
7003
7008
|
let tryActive = 0;
|
|
7004
|
-
|
|
7009
|
+
const addEvent = (block, event) => {
|
|
7010
|
+
allEvents.push(event);
|
|
7011
|
+
if (!block.events) {
|
|
7012
|
+
block.events = [event];
|
|
7013
|
+
} else {
|
|
7014
|
+
block.events.push(event);
|
|
7015
|
+
}
|
|
7016
|
+
};
|
|
7017
|
+
state.pre = function(node) {
|
|
7005
7018
|
eventsStack.push(allEvents.length);
|
|
7006
|
-
if (
|
|
7019
|
+
if (localState.unreachable || this.inType && node.type !== "EnumDeclaration") {
|
|
7007
7020
|
return [];
|
|
7008
7021
|
}
|
|
7009
7022
|
if (!localState.curBlock.node && ((0, import_chunk_JDC43A3I.isStatement)(node) || (0, import_chunk_JDC43A3I.isExpression)(node))) {
|
|
@@ -7017,19 +7030,41 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7017
7030
|
stmtStack.push(node);
|
|
7018
7031
|
}
|
|
7019
7032
|
switch (node.type) {
|
|
7033
|
+
case "ImportModule":
|
|
7034
|
+
case "Using":
|
|
7035
|
+
(0, import_chunk_NHZRKHZO.forEach)(
|
|
7036
|
+
notice(node, node, false, () => []),
|
|
7037
|
+
(e) => allEvents.push(e)
|
|
7038
|
+
);
|
|
7039
|
+
return [];
|
|
7040
|
+
case "Program":
|
|
7041
|
+
case "ModuleDeclaration":
|
|
7042
|
+
if (rootNode !== node)
|
|
7043
|
+
return [];
|
|
7044
|
+
(0, import_chunk_NHZRKHZO.forEach)(
|
|
7045
|
+
notice(node, node, false, () => []),
|
|
7046
|
+
(e) => {
|
|
7047
|
+
addEvent(localState.curBlock, e);
|
|
7048
|
+
allEvents.pop();
|
|
7049
|
+
}
|
|
7050
|
+
);
|
|
7051
|
+
return ["body"];
|
|
7052
|
+
case "ClassDeclaration":
|
|
7020
7053
|
case "FunctionDeclaration":
|
|
7054
|
+
if (rootNode !== node)
|
|
7055
|
+
return [];
|
|
7021
7056
|
return ["body"];
|
|
7022
7057
|
case "AttributeList":
|
|
7023
7058
|
return [];
|
|
7024
7059
|
case "SwitchStatement": {
|
|
7025
7060
|
const top = localState.push(node);
|
|
7026
7061
|
top.break = {};
|
|
7027
|
-
|
|
7062
|
+
this.traverse(node.discriminant);
|
|
7028
7063
|
const testBlocks = [];
|
|
7029
7064
|
let defaultSeen = false;
|
|
7030
7065
|
node.cases.forEach((sc, i) => {
|
|
7031
7066
|
if (sc.test) {
|
|
7032
|
-
|
|
7067
|
+
this.traverse(sc.test);
|
|
7033
7068
|
testBlocks[i] = localState.curBlock;
|
|
7034
7069
|
localState.newBlock();
|
|
7035
7070
|
} else {
|
|
@@ -7048,7 +7083,7 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7048
7083
|
localState.curBlock
|
|
7049
7084
|
);
|
|
7050
7085
|
sc.consequent.every((s) => {
|
|
7051
|
-
|
|
7086
|
+
this.traverse(s);
|
|
7052
7087
|
return !localState.unreachable;
|
|
7053
7088
|
});
|
|
7054
7089
|
});
|
|
@@ -7074,13 +7109,13 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7074
7109
|
true: body,
|
|
7075
7110
|
false: top.break
|
|
7076
7111
|
});
|
|
7077
|
-
|
|
7112
|
+
this.traverse(node.test);
|
|
7078
7113
|
localState.unreachable = true;
|
|
7079
7114
|
localState.newBlock(body);
|
|
7080
7115
|
} else {
|
|
7081
7116
|
head = localState.newBlock();
|
|
7082
7117
|
}
|
|
7083
|
-
|
|
7118
|
+
this.traverse(node.body);
|
|
7084
7119
|
if (node.type === "DoWhileStatement") {
|
|
7085
7120
|
localState.newBlock(top.continue);
|
|
7086
7121
|
testStack.push({
|
|
@@ -7088,7 +7123,7 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7088
7123
|
true: head,
|
|
7089
7124
|
false: top.break
|
|
7090
7125
|
});
|
|
7091
|
-
|
|
7126
|
+
this.traverse(node.test);
|
|
7092
7127
|
localState.unreachable = true;
|
|
7093
7128
|
} else if (!localState.unreachable) {
|
|
7094
7129
|
localState.addEdge(localState.curBlock, head);
|
|
@@ -7105,7 +7140,7 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7105
7140
|
localState.addEdge(localState.curBlock, top.throw);
|
|
7106
7141
|
localState.newBlock();
|
|
7107
7142
|
tryActive++;
|
|
7108
|
-
|
|
7143
|
+
this.traverse(node.block);
|
|
7109
7144
|
tryActive--;
|
|
7110
7145
|
delete top.throw;
|
|
7111
7146
|
top.posttry = {};
|
|
@@ -7116,7 +7151,7 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7116
7151
|
localState.unreachable = true;
|
|
7117
7152
|
localState.newBlock(catches);
|
|
7118
7153
|
if (node.handler) {
|
|
7119
|
-
|
|
7154
|
+
this.traverse(node.handler);
|
|
7120
7155
|
if (localState.curBlock.preds) {
|
|
7121
7156
|
localState.terminal("ThrowStatement");
|
|
7122
7157
|
}
|
|
@@ -7125,7 +7160,7 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7125
7160
|
localState.unreachable = true;
|
|
7126
7161
|
localState.newBlock(top.finally);
|
|
7127
7162
|
delete top.finally;
|
|
7128
|
-
|
|
7163
|
+
this.traverse(node.finalizer);
|
|
7129
7164
|
if (!localState.unreachable) {
|
|
7130
7165
|
if (tryFallsThrough) {
|
|
7131
7166
|
localState.addEdge(localState.curBlock, top.posttry);
|
|
@@ -7150,11 +7185,11 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7150
7185
|
}
|
|
7151
7186
|
const next = {};
|
|
7152
7187
|
if (node.param && node.param.type === "BinaryExpression") {
|
|
7153
|
-
|
|
7188
|
+
this.traverse(node.param);
|
|
7154
7189
|
localState.addEdge(localState.curBlock, next);
|
|
7155
7190
|
localState.newBlock();
|
|
7156
7191
|
}
|
|
7157
|
-
|
|
7192
|
+
this.traverse(node.body);
|
|
7158
7193
|
if (!localState.unreachable) {
|
|
7159
7194
|
localState.addEdge(
|
|
7160
7195
|
localState.curBlock,
|
|
@@ -7168,7 +7203,7 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7168
7203
|
case "ForStatement": {
|
|
7169
7204
|
const top = localState.push(node);
|
|
7170
7205
|
if (node.init)
|
|
7171
|
-
|
|
7206
|
+
this.traverse(node.init);
|
|
7172
7207
|
const head = localState.newBlock();
|
|
7173
7208
|
top.break = {};
|
|
7174
7209
|
top.continue = {};
|
|
@@ -7179,14 +7214,14 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7179
7214
|
true: body,
|
|
7180
7215
|
false: top.break
|
|
7181
7216
|
});
|
|
7182
|
-
|
|
7217
|
+
this.traverse(node.test);
|
|
7183
7218
|
localState.unreachable = true;
|
|
7184
7219
|
localState.newBlock(body);
|
|
7185
7220
|
}
|
|
7186
|
-
|
|
7221
|
+
this.traverse(node.body);
|
|
7187
7222
|
localState.newBlock(top.continue);
|
|
7188
7223
|
if (node.update) {
|
|
7189
|
-
|
|
7224
|
+
this.traverse(node.update);
|
|
7190
7225
|
}
|
|
7191
7226
|
if (!localState.unreachable) {
|
|
7192
7227
|
localState.addEdge(localState.curBlock, head);
|
|
@@ -7208,7 +7243,7 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7208
7243
|
true: consequent,
|
|
7209
7244
|
false: alternate
|
|
7210
7245
|
});
|
|
7211
|
-
|
|
7246
|
+
this.traverse(node.test);
|
|
7212
7247
|
localState.unreachable = true;
|
|
7213
7248
|
if (topTest.true) {
|
|
7214
7249
|
testStack.push({ ...topTest, node: node.consequent });
|
|
@@ -7216,7 +7251,7 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7216
7251
|
testStack.push({ node: node.consequent, true: next, false: next });
|
|
7217
7252
|
}
|
|
7218
7253
|
localState.newBlock(consequent);
|
|
7219
|
-
|
|
7254
|
+
this.traverse(node.consequent);
|
|
7220
7255
|
localState.unreachable = true;
|
|
7221
7256
|
if (node.alternate) {
|
|
7222
7257
|
if (topTest.true) {
|
|
@@ -7225,7 +7260,7 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7225
7260
|
testStack.push({ node: node.alternate, true: next, false: next });
|
|
7226
7261
|
}
|
|
7227
7262
|
localState.newBlock(alternate);
|
|
7228
|
-
|
|
7263
|
+
this.traverse(node.alternate);
|
|
7229
7264
|
localState.unreachable = true;
|
|
7230
7265
|
}
|
|
7231
7266
|
if (next.preds) {
|
|
@@ -7252,7 +7287,7 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7252
7287
|
false: right
|
|
7253
7288
|
});
|
|
7254
7289
|
}
|
|
7255
|
-
|
|
7290
|
+
this.traverse(node.left);
|
|
7256
7291
|
localState.unreachable = true;
|
|
7257
7292
|
localState.newBlock(right);
|
|
7258
7293
|
testStack.push({
|
|
@@ -7260,7 +7295,7 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7260
7295
|
true: topTest.true || next,
|
|
7261
7296
|
false: topTest.false || next
|
|
7262
7297
|
});
|
|
7263
|
-
|
|
7298
|
+
this.traverse(node.right);
|
|
7264
7299
|
localState.unreachable = true;
|
|
7265
7300
|
if (next.preds) {
|
|
7266
7301
|
localState.newBlock(next);
|
|
@@ -7279,9 +7314,9 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7279
7314
|
break;
|
|
7280
7315
|
case "UpdateExpression":
|
|
7281
7316
|
if (node.argument.type === "MemberExpression") {
|
|
7282
|
-
|
|
7317
|
+
this.traverse(node.argument.object);
|
|
7283
7318
|
if (node.argument.computed) {
|
|
7284
|
-
|
|
7319
|
+
this.traverse(node.argument.property);
|
|
7285
7320
|
}
|
|
7286
7321
|
}
|
|
7287
7322
|
return [];
|
|
@@ -7290,16 +7325,16 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7290
7325
|
return null;
|
|
7291
7326
|
}
|
|
7292
7327
|
if (node.left.type === "MemberExpression") {
|
|
7293
|
-
|
|
7328
|
+
this.traverse(node.left.object);
|
|
7294
7329
|
if (node.left.computed) {
|
|
7295
|
-
|
|
7330
|
+
this.traverse(node.left.property);
|
|
7296
7331
|
}
|
|
7297
7332
|
}
|
|
7298
7333
|
return ["right"];
|
|
7299
7334
|
case "ThrowStatement":
|
|
7300
7335
|
case "ReturnStatement":
|
|
7301
7336
|
if (node.argument) {
|
|
7302
|
-
|
|
7337
|
+
this.traverse(node.argument);
|
|
7303
7338
|
}
|
|
7304
7339
|
case "BreakStatement":
|
|
7305
7340
|
case "ContinueStatement":
|
|
@@ -7307,29 +7342,21 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7307
7342
|
return [];
|
|
7308
7343
|
case "CallExpression":
|
|
7309
7344
|
if (node.callee.type === "Identifier") {
|
|
7310
|
-
const extra =
|
|
7311
|
-
|
|
7312
|
-
|
|
7345
|
+
const extra = this.stack.splice(rootStack.length);
|
|
7346
|
+
this.traverse(node.callee);
|
|
7347
|
+
this.stack.push(...extra);
|
|
7313
7348
|
return ["arguments"];
|
|
7314
7349
|
}
|
|
7315
7350
|
break;
|
|
7316
7351
|
}
|
|
7317
7352
|
return null;
|
|
7318
7353
|
};
|
|
7319
|
-
|
|
7320
|
-
allEvents.push(event);
|
|
7321
|
-
if (!block.events) {
|
|
7322
|
-
block.events = [event];
|
|
7323
|
-
} else {
|
|
7324
|
-
block.events.push(event);
|
|
7325
|
-
}
|
|
7326
|
-
};
|
|
7327
|
-
state.post = (node) => {
|
|
7354
|
+
state.post = function(node) {
|
|
7328
7355
|
const eventIndex = eventsStack.pop();
|
|
7329
7356
|
const getContainedEvents = () => allEvents.slice(eventIndex);
|
|
7330
7357
|
const curStmt = stmtStack[stmtStack.length - 1];
|
|
7331
7358
|
const topTest = testStack[testStack.length - 1];
|
|
7332
|
-
if (!
|
|
7359
|
+
if (!this.inType && node !== rootNode) {
|
|
7333
7360
|
const throws = tryActive > 0 && (0, import_chunk_JDC43A3I.mayThrow)(node);
|
|
7334
7361
|
const events = notice(node, curStmt, throws, getContainedEvents);
|
|
7335
7362
|
if (throws) {
|
|
@@ -7339,9 +7366,9 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7339
7366
|
);
|
|
7340
7367
|
}
|
|
7341
7368
|
} else {
|
|
7342
|
-
(0,
|
|
7369
|
+
(0, import_chunk_NHZRKHZO.forEach)(events, (e) => e.mayThrow = false);
|
|
7343
7370
|
}
|
|
7344
|
-
(0,
|
|
7371
|
+
(0, import_chunk_NHZRKHZO.forEach)(events, (event) => {
|
|
7345
7372
|
if (event.mayThrow) {
|
|
7346
7373
|
for (let i = localState.stack.length; i--; ) {
|
|
7347
7374
|
const target = localState.stack[i].throw;
|
|
@@ -7396,8 +7423,18 @@ function buildReducedGraph(state, func, refsForUpdate, notice) {
|
|
|
7396
7423
|
}
|
|
7397
7424
|
return null;
|
|
7398
7425
|
};
|
|
7399
|
-
state.traverse(
|
|
7426
|
+
state.traverse(rootNode);
|
|
7400
7427
|
return cleanCfg(ret);
|
|
7428
|
+
};
|
|
7429
|
+
try {
|
|
7430
|
+
if (root.nodes) {
|
|
7431
|
+
root.nodes.forEach(
|
|
7432
|
+
(rootStack, rootNode) => processOne(rootNode, rootStack)
|
|
7433
|
+
);
|
|
7434
|
+
} else {
|
|
7435
|
+
processOne(root.node, root.stack);
|
|
7436
|
+
}
|
|
7437
|
+
return ret;
|
|
7401
7438
|
} finally {
|
|
7402
7439
|
state.pre = pre;
|
|
7403
7440
|
state.post = post;
|
|
@@ -7486,7 +7523,7 @@ var init_control_flow = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
7486
7523
|
"src/control-flow.ts"() {
|
|
7487
7524
|
"use strict";
|
|
7488
7525
|
(0, import_chunk_JDC43A3I.init_ast)();
|
|
7489
|
-
(0,
|
|
7526
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
7490
7527
|
Terminals = {
|
|
7491
7528
|
BreakStatement: "break",
|
|
7492
7529
|
ContinueStatement: "continue",
|
|
@@ -7498,9 +7535,6 @@ var init_control_flow = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
7498
7535
|
info = /* @__PURE__ */ new Map();
|
|
7499
7536
|
curBlock = {};
|
|
7500
7537
|
unreachable = false;
|
|
7501
|
-
constructor(func) {
|
|
7502
|
-
this.push(func);
|
|
7503
|
-
}
|
|
7504
7538
|
push(node) {
|
|
7505
7539
|
const top = { node };
|
|
7506
7540
|
this.stack.push(top);
|
|
@@ -7516,12 +7550,12 @@ var init_control_flow = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
7516
7550
|
if (!from.succs) {
|
|
7517
7551
|
from.succs = [to];
|
|
7518
7552
|
} else {
|
|
7519
|
-
(0,
|
|
7553
|
+
(0, import_chunk_NHZRKHZO.pushUnique)(from.succs, to);
|
|
7520
7554
|
}
|
|
7521
7555
|
if (!to.preds) {
|
|
7522
7556
|
to.preds = [from];
|
|
7523
7557
|
} else {
|
|
7524
|
-
(0,
|
|
7558
|
+
(0, import_chunk_NHZRKHZO.pushUnique)(to.preds, from);
|
|
7525
7559
|
}
|
|
7526
7560
|
}
|
|
7527
7561
|
newBlock(block) {
|
|
@@ -7875,8 +7909,8 @@ function mergeObjectValues(to, from) {
|
|
|
7875
7909
|
function mergeStateDecls(to, from) {
|
|
7876
7910
|
let changed = false;
|
|
7877
7911
|
let result = to;
|
|
7878
|
-
(0,
|
|
7879
|
-
if ((0,
|
|
7912
|
+
(0, import_chunk_NHZRKHZO.forEach)(from, (v) => {
|
|
7913
|
+
if ((0, import_chunk_NHZRKHZO.some)(to, (t) => t === v)) {
|
|
7880
7914
|
return;
|
|
7881
7915
|
}
|
|
7882
7916
|
if (Array.isArray(result)) {
|
|
@@ -8043,7 +8077,7 @@ var init_union_type = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
8043
8077
|
"use strict";
|
|
8044
8078
|
(0, import_chunk_JDC43A3I.init_ast)();
|
|
8045
8079
|
init_data_flow();
|
|
8046
|
-
(0,
|
|
8080
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
8047
8081
|
init_could_be();
|
|
8048
8082
|
init_intersection_type();
|
|
8049
8083
|
init_sub_type();
|
|
@@ -8058,7 +8092,7 @@ function expandTypedef(t) {
|
|
|
8058
8092
|
);
|
|
8059
8093
|
const tExpanded = cloneType(t);
|
|
8060
8094
|
clearValuesUnder(tExpanded, 262144, true);
|
|
8061
|
-
(0,
|
|
8095
|
+
(0, import_chunk_NHZRKHZO.forEach)(decls, (decl) => unionInto(tExpanded, decl.resolvedType));
|
|
8062
8096
|
return tExpanded;
|
|
8063
8097
|
}
|
|
8064
8098
|
function intersectEnum(t, e) {
|
|
@@ -8252,9 +8286,9 @@ function intersectionValue(pair) {
|
|
|
8252
8286
|
case 4096:
|
|
8253
8287
|
case 8192: {
|
|
8254
8288
|
const common = [];
|
|
8255
|
-
(0,
|
|
8289
|
+
(0, import_chunk_NHZRKHZO.forEach)(
|
|
8256
8290
|
pair.avalue,
|
|
8257
|
-
(sna) => (0,
|
|
8291
|
+
(sna) => (0, import_chunk_NHZRKHZO.some)(pair.bvalue, (snb) => sna === snb) && common.push(sna)
|
|
8258
8292
|
);
|
|
8259
8293
|
if (!common.length)
|
|
8260
8294
|
return null;
|
|
@@ -8262,9 +8296,9 @@ function intersectionValue(pair) {
|
|
|
8262
8296
|
}
|
|
8263
8297
|
case 16384: {
|
|
8264
8298
|
const common = [];
|
|
8265
|
-
(0,
|
|
8299
|
+
(0, import_chunk_NHZRKHZO.forEach)(pair.avalue, (sna) => {
|
|
8266
8300
|
const superA = getSuperClasses(sna);
|
|
8267
|
-
(0,
|
|
8301
|
+
(0, import_chunk_NHZRKHZO.forEach)(pair.bvalue, (snb) => {
|
|
8268
8302
|
if (sna === snb || superA && superA.has(snb)) {
|
|
8269
8303
|
common.push(sna);
|
|
8270
8304
|
}
|
|
@@ -8510,7 +8544,7 @@ function restrictExactTypesByEquality(a, b) {
|
|
|
8510
8544
|
}
|
|
8511
8545
|
case 262144:
|
|
8512
8546
|
return restrictByEquality(
|
|
8513
|
-
(0,
|
|
8547
|
+
(0, import_chunk_NHZRKHZO.reduce)(
|
|
8514
8548
|
a.value,
|
|
8515
8549
|
(cur, decl) => {
|
|
8516
8550
|
unionInto(cur, decl.resolvedType);
|
|
@@ -8577,7 +8611,7 @@ var init_intersection_type = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
8577
8611
|
"use strict";
|
|
8578
8612
|
init_api();
|
|
8579
8613
|
init_data_flow();
|
|
8580
|
-
(0,
|
|
8614
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
8581
8615
|
init_could_be();
|
|
8582
8616
|
init_interp();
|
|
8583
8617
|
init_types();
|
|
@@ -8691,14 +8725,14 @@ function subtypeOfValue(pair) {
|
|
|
8691
8725
|
case 8192: {
|
|
8692
8726
|
const asd = pair.avalue;
|
|
8693
8727
|
const bsd = pair.bvalue;
|
|
8694
|
-
return (0,
|
|
8728
|
+
return (0, import_chunk_NHZRKHZO.some)(asd, (sna) => (0, import_chunk_NHZRKHZO.some)(bsd, (snb) => sna === snb));
|
|
8695
8729
|
}
|
|
8696
8730
|
case 16384: {
|
|
8697
8731
|
const asd = pair.avalue;
|
|
8698
8732
|
const bsd = pair.bvalue;
|
|
8699
|
-
return (0,
|
|
8733
|
+
return (0, import_chunk_NHZRKHZO.every)(asd, (sna) => {
|
|
8700
8734
|
const superA = getSuperClasses(sna);
|
|
8701
|
-
return (0,
|
|
8735
|
+
return (0, import_chunk_NHZRKHZO.some)(bsd, (snb) => {
|
|
8702
8736
|
if (sna === snb || superA && superA.has(snb)) {
|
|
8703
8737
|
return true;
|
|
8704
8738
|
}
|
|
@@ -8734,7 +8768,7 @@ var init_sub_type = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
8734
8768
|
"use strict";
|
|
8735
8769
|
init_api();
|
|
8736
8770
|
init_data_flow();
|
|
8737
|
-
(0,
|
|
8771
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
8738
8772
|
init_could_be();
|
|
8739
8773
|
init_intersection_type();
|
|
8740
8774
|
init_types();
|
|
@@ -9155,13 +9189,13 @@ function isTypeStateKey(decl) {
|
|
|
9155
9189
|
return Array.isArray(decl) || decl.type !== "MemberDecl" && decl.type !== "Unknown";
|
|
9156
9190
|
}
|
|
9157
9191
|
function declIsLocal(decl) {
|
|
9158
|
-
return (0,
|
|
9192
|
+
return (0, import_chunk_NHZRKHZO.some)(
|
|
9159
9193
|
decl,
|
|
9160
9194
|
(d) => d.type === "BinaryExpression" || d.type === "Identifier" || d.type === "VariableDeclarator" && isLocal(d)
|
|
9161
9195
|
);
|
|
9162
9196
|
}
|
|
9163
9197
|
function declIsNonLocal(decl) {
|
|
9164
|
-
return (0,
|
|
9198
|
+
return (0, import_chunk_NHZRKHZO.some)(decl, (d) => d.type === "VariableDeclarator" && !isLocal(d));
|
|
9165
9199
|
}
|
|
9166
9200
|
function localDeclName(decl) {
|
|
9167
9201
|
if (Array.isArray(decl))
|
|
@@ -9174,12 +9208,12 @@ function localDeclName(decl) {
|
|
|
9174
9208
|
case "VariableDeclarator":
|
|
9175
9209
|
return variableDeclarationName(decl.node.id);
|
|
9176
9210
|
}
|
|
9177
|
-
throw new
|
|
9211
|
+
throw new import_chunk_NHZRKHZO.AwaitedError(
|
|
9178
9212
|
declFullName(decl).then((declStr) => `Invalid local decl: ${declStr}`)
|
|
9179
9213
|
);
|
|
9180
9214
|
}
|
|
9181
9215
|
function tsKey(key) {
|
|
9182
|
-
return `${(0,
|
|
9216
|
+
return `${(0, import_chunk_NHZRKHZO.map)(key, (k) => {
|
|
9183
9217
|
if (k.type === "Literal") {
|
|
9184
9218
|
return k.raw;
|
|
9185
9219
|
} else if (isStateNode(k)) {
|
|
@@ -9198,24 +9232,36 @@ function sourceLocation(loc) {
|
|
|
9198
9232
|
return loc ? `${loc.source || "??"}:${loc.start.line}:${loc.start.column}` : "??";
|
|
9199
9233
|
}
|
|
9200
9234
|
function printBlockHeader(block) {
|
|
9201
|
-
(0,
|
|
9235
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
9202
9236
|
block.order,
|
|
9203
9237
|
`(${block.node?.loc?.source || "??"}:${block.node?.loc?.start.line || "??"})`,
|
|
9204
9238
|
`Preds: ${(block.preds || []).map((block2) => block2.order).join(", ")}`
|
|
9205
9239
|
);
|
|
9206
9240
|
}
|
|
9241
|
+
function printImp(event) {
|
|
9242
|
+
switch (event.node.type) {
|
|
9243
|
+
case "ImportModule":
|
|
9244
|
+
case "Using":
|
|
9245
|
+
return formatAstLongLines(event.node.id).then(
|
|
9246
|
+
(id) => `${event.node.type} ${id}`
|
|
9247
|
+
);
|
|
9248
|
+
case "ModuleDeclaration":
|
|
9249
|
+
case "Program":
|
|
9250
|
+
return event.node.type;
|
|
9251
|
+
}
|
|
9252
|
+
}
|
|
9207
9253
|
function describeEvent(event) {
|
|
9208
9254
|
if (event.type === "exn")
|
|
9209
9255
|
return Promise.resolve("exn:");
|
|
9210
9256
|
return Promise.resolve(
|
|
9211
|
-
event.type === "flw" || event.type === "mod" || !Array.isArray(event.decl) && (event.decl.type === "MemberDecl" || event.decl.type === "Unknown") ?
|
|
9257
|
+
event.type === "imp" ? printImp(event) : event.type === "flw" || event.type === "mod" || !Array.isArray(event.decl) && (event.decl.type === "MemberDecl" || event.decl.type === "Unknown") ? formatAstLongLines(event.node) : event.decl ? declFullName(event.decl) : "??"
|
|
9212
9258
|
).then((desc) => `${event.type}: ${desc}`);
|
|
9213
9259
|
}
|
|
9214
9260
|
function printBlockEvents(block, extra) {
|
|
9215
|
-
(0,
|
|
9216
|
-
(0,
|
|
9261
|
+
(0, import_chunk_NHZRKHZO.log)("Events:");
|
|
9262
|
+
(0, import_chunk_NHZRKHZO.forEach)(
|
|
9217
9263
|
block.events,
|
|
9218
|
-
(event) => (0,
|
|
9264
|
+
(event) => (0, import_chunk_NHZRKHZO.log)(
|
|
9219
9265
|
describeEvent(event).then(
|
|
9220
9266
|
(eventStr) => ` ${eventStr} ${extra ? extra(event) : ""}`
|
|
9221
9267
|
)
|
|
@@ -9223,7 +9269,7 @@ function printBlockEvents(block, extra) {
|
|
|
9223
9269
|
);
|
|
9224
9270
|
}
|
|
9225
9271
|
function printBlockTrailer(block) {
|
|
9226
|
-
(0,
|
|
9272
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
9227
9273
|
`Succs: ${(block.succs || []).map((block2) => block2.order).join(", ")} ExSucc: ${block.exsucc ? block.exsucc.order : ""}`
|
|
9228
9274
|
);
|
|
9229
9275
|
}
|
|
@@ -9355,7 +9401,7 @@ var init_type_flow_util = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
9355
9401
|
"use strict";
|
|
9356
9402
|
init_api();
|
|
9357
9403
|
init_data_flow();
|
|
9358
|
-
(0,
|
|
9404
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
9359
9405
|
init_intersection_type();
|
|
9360
9406
|
init_sub_type();
|
|
9361
9407
|
init_types();
|
|
@@ -9377,7 +9423,7 @@ function evaluateCall(istate, node, callee, args) {
|
|
|
9377
9423
|
istate.typeChecker && diagnostic(
|
|
9378
9424
|
istate.state,
|
|
9379
9425
|
node,
|
|
9380
|
-
|
|
9426
|
+
formatAstLongLines(node.callee).then(
|
|
9381
9427
|
(calleeStr) => `'${calleeStr}' is not callable`
|
|
9382
9428
|
),
|
|
9383
9429
|
istate.checkTypes
|
|
@@ -9391,25 +9437,25 @@ function evaluateCall(istate, node, callee, args) {
|
|
|
9391
9437
|
}
|
|
9392
9438
|
function calleeObjectType(istate, callee) {
|
|
9393
9439
|
if (callee.type === "MemberExpression") {
|
|
9394
|
-
return istate.typeMap?.get(callee.object)
|
|
9440
|
+
return istate.typeMap?.get(callee.object) ?? istate.frpushType ?? {
|
|
9395
9441
|
type: 524287
|
|
9396
9442
|
/* Any */
|
|
9397
9443
|
};
|
|
9398
9444
|
}
|
|
9399
|
-
if (callee.type === "Identifier" && istate.
|
|
9400
|
-
const
|
|
9401
|
-
const [{ sn: self }] =
|
|
9445
|
+
if (callee.type === "Identifier" && istate.root) {
|
|
9446
|
+
const root = istate.root;
|
|
9447
|
+
const [{ sn: self }] = root.stack.slice(-1);
|
|
9402
9448
|
return typeFromTypeStateNode(
|
|
9403
9449
|
istate.state,
|
|
9404
9450
|
self,
|
|
9405
|
-
(
|
|
9451
|
+
(root.attributes & 8) !== 0 || self.type !== "ClassDeclaration"
|
|
9406
9452
|
);
|
|
9407
9453
|
}
|
|
9408
9454
|
return null;
|
|
9409
9455
|
}
|
|
9410
9456
|
function checkCallArgs(istate, node, callees, args) {
|
|
9411
9457
|
const allDiags = [];
|
|
9412
|
-
const resultType = (0,
|
|
9458
|
+
const resultType = (0, import_chunk_NHZRKHZO.reduce)(
|
|
9413
9459
|
callees,
|
|
9414
9460
|
(result, cur) => {
|
|
9415
9461
|
const curDiags = [];
|
|
@@ -9568,7 +9614,7 @@ function isOverride(cur, funcs) {
|
|
|
9568
9614
|
const cls = cur.stack?.[cur.stack.length - 1]?.sn;
|
|
9569
9615
|
if (cls?.type === "ClassDeclaration" && cls.superClasses) {
|
|
9570
9616
|
const supers = getSuperClasses(cls);
|
|
9571
|
-
if (supers && (0,
|
|
9617
|
+
if (supers && (0, import_chunk_NHZRKHZO.some)(funcs, (func) => {
|
|
9572
9618
|
if (func === cur)
|
|
9573
9619
|
return false;
|
|
9574
9620
|
const fcls = func.stack?.[func.stack.length - 1].sn;
|
|
@@ -9590,6 +9636,75 @@ function getSystemCallTable(state) {
|
|
|
9590
9636
|
if (systemCallInfo && systemCallVersion === state.sdk) {
|
|
9591
9637
|
return systemCallInfo;
|
|
9592
9638
|
}
|
|
9639
|
+
const toNumber = (state2, callee, calleeObj, getArgs) => {
|
|
9640
|
+
const ret = { effectFree: true };
|
|
9641
|
+
if (isExact(calleeObj)) {
|
|
9642
|
+
if (calleeObj.type === 8) {
|
|
9643
|
+
const args = getArgs();
|
|
9644
|
+
if (args.length === 0) {
|
|
9645
|
+
ret.returnType = calleeObj;
|
|
9646
|
+
}
|
|
9647
|
+
} else if (hasValue(calleeObj)) {
|
|
9648
|
+
switch (calleeObj.type) {
|
|
9649
|
+
case 1:
|
|
9650
|
+
return {};
|
|
9651
|
+
case 2:
|
|
9652
|
+
ret.returnType = { type: 8, value: 0 };
|
|
9653
|
+
break;
|
|
9654
|
+
case 4:
|
|
9655
|
+
ret.returnType = { type: 8, value: 1 };
|
|
9656
|
+
break;
|
|
9657
|
+
case 16:
|
|
9658
|
+
ret.returnType = {
|
|
9659
|
+
type: 8,
|
|
9660
|
+
value: Number(calleeObj.value) & -1
|
|
9661
|
+
};
|
|
9662
|
+
break;
|
|
9663
|
+
case 32:
|
|
9664
|
+
case 64:
|
|
9665
|
+
ret.returnType = {
|
|
9666
|
+
type: 8,
|
|
9667
|
+
value: Math.max(
|
|
9668
|
+
-134217728,
|
|
9669
|
+
Math.min(
|
|
9670
|
+
2147483647,
|
|
9671
|
+
calleeObj.value >= 0 ? Math.floor(calleeObj.value) : Math.ceil(calleeObj.value)
|
|
9672
|
+
)
|
|
9673
|
+
)
|
|
9674
|
+
};
|
|
9675
|
+
break;
|
|
9676
|
+
case 128:
|
|
9677
|
+
ret.returnType = {
|
|
9678
|
+
type: 8,
|
|
9679
|
+
value: calleeObj.value.charCodeAt(0)
|
|
9680
|
+
};
|
|
9681
|
+
break;
|
|
9682
|
+
case 256: {
|
|
9683
|
+
const value2 = parseInt(calleeObj.value, 10);
|
|
9684
|
+
ret.returnType = isNaN(value2) ? {
|
|
9685
|
+
type: 1
|
|
9686
|
+
/* Null */
|
|
9687
|
+
} : {
|
|
9688
|
+
type: 8,
|
|
9689
|
+
value: value2
|
|
9690
|
+
};
|
|
9691
|
+
break;
|
|
9692
|
+
}
|
|
9693
|
+
case 512:
|
|
9694
|
+
case 1024:
|
|
9695
|
+
case 2048:
|
|
9696
|
+
case 4096:
|
|
9697
|
+
case 8192:
|
|
9698
|
+
case 16384:
|
|
9699
|
+
case 32768:
|
|
9700
|
+
case 65536:
|
|
9701
|
+
case 131072:
|
|
9702
|
+
case 262144:
|
|
9703
|
+
}
|
|
9704
|
+
}
|
|
9705
|
+
}
|
|
9706
|
+
return ret;
|
|
9707
|
+
};
|
|
9593
9708
|
const arrayAdd = (state2, callee, calleeObj, getArgs) => {
|
|
9594
9709
|
const ret = {};
|
|
9595
9710
|
if (calleeObj.type & 512) {
|
|
@@ -9979,6 +10094,7 @@ function getSystemCallTable(state) {
|
|
|
9979
10094
|
"$.Toybox.Lang.Dictionary.values": dictionaryValues,
|
|
9980
10095
|
"$.Toybox.Lang.Method.invoke": methodInvoke,
|
|
9981
10096
|
"$.Toybox.Lang.Object.method": method,
|
|
10097
|
+
"$.Toybox.Lang.*.toNumber": toNumber,
|
|
9982
10098
|
"$.Toybox.Math.acos": mathHelper,
|
|
9983
10099
|
"$.Toybox.Math.asin": mathHelper,
|
|
9984
10100
|
"$.Toybox.Math.atan": mathHelper,
|
|
@@ -10064,14 +10180,14 @@ var systemCallInfo, systemCallVersion;
|
|
|
10064
10180
|
var init_interp_call = (0, import_chunk_ABYVSU2C.__esm)({
|
|
10065
10181
|
"src/type-flow/interp-call.ts"() {
|
|
10066
10182
|
"use strict";
|
|
10067
|
-
init_optimizer_types();
|
|
10068
10183
|
init_api();
|
|
10069
|
-
(
|
|
10184
|
+
init_optimizer_types();
|
|
10185
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
10070
10186
|
init_interp();
|
|
10071
10187
|
init_sub_type();
|
|
10188
|
+
init_type_flow_util();
|
|
10072
10189
|
init_types();
|
|
10073
10190
|
init_union_type();
|
|
10074
|
-
init_type_flow_util();
|
|
10075
10191
|
systemCallInfo = null;
|
|
10076
10192
|
}
|
|
10077
10193
|
});
|
|
@@ -10224,42 +10340,54 @@ function preEvaluate(istate, node) {
|
|
|
10224
10340
|
return ["init"];
|
|
10225
10341
|
case "CatchClause":
|
|
10226
10342
|
return ["body"];
|
|
10343
|
+
case "TypedefDeclaration":
|
|
10344
|
+
return [];
|
|
10227
10345
|
}
|
|
10228
10346
|
return null;
|
|
10229
10347
|
}
|
|
10230
|
-
function evaluate(istate,
|
|
10348
|
+
function evaluate(istate, root) {
|
|
10231
10349
|
let skipNode = null;
|
|
10232
|
-
const post = (
|
|
10233
|
-
if (istate.pre &&
|
|
10234
|
-
const rep = istate.pre(
|
|
10350
|
+
const post = (node) => {
|
|
10351
|
+
if (istate.pre && node !== skipNode) {
|
|
10352
|
+
const rep = istate.pre(node);
|
|
10235
10353
|
if (rep)
|
|
10236
10354
|
return rep;
|
|
10237
10355
|
}
|
|
10238
|
-
evaluateNode(istate,
|
|
10239
|
-
if (skipNode ===
|
|
10356
|
+
evaluateNode(istate, node);
|
|
10357
|
+
if (skipNode === node) {
|
|
10240
10358
|
skipNode = null;
|
|
10241
10359
|
return null;
|
|
10242
10360
|
}
|
|
10243
|
-
return istate.post ? istate.post(
|
|
10361
|
+
return istate.post ? istate.post(node) : null;
|
|
10244
10362
|
};
|
|
10245
|
-
const pre = (
|
|
10246
|
-
const ret2 = preEvaluate(istate,
|
|
10363
|
+
const pre = (node) => {
|
|
10364
|
+
const ret2 = preEvaluate(istate, node);
|
|
10247
10365
|
if (ret2)
|
|
10248
10366
|
return ret2;
|
|
10249
|
-
switch (
|
|
10367
|
+
switch (node.type) {
|
|
10368
|
+
case "ImportModule":
|
|
10369
|
+
case "Using":
|
|
10370
|
+
handleImportUsing(istate.state, node);
|
|
10371
|
+
return false;
|
|
10372
|
+
case "FunctionDeclaration":
|
|
10373
|
+
case "ModuleDeclaration":
|
|
10374
|
+
case "ClassDeclaration":
|
|
10375
|
+
if (node !== root)
|
|
10376
|
+
return false;
|
|
10377
|
+
break;
|
|
10250
10378
|
case "AssignmentExpression":
|
|
10251
|
-
skipNode =
|
|
10379
|
+
skipNode = node.left;
|
|
10252
10380
|
break;
|
|
10253
10381
|
case "UpdateExpression":
|
|
10254
|
-
skipNode =
|
|
10382
|
+
skipNode = node.argument;
|
|
10255
10383
|
break;
|
|
10256
10384
|
}
|
|
10257
10385
|
return null;
|
|
10258
10386
|
};
|
|
10259
|
-
(0, import_chunk_JDC43A3I.traverseAst)(
|
|
10387
|
+
(0, import_chunk_JDC43A3I.traverseAst)(root, pre, post);
|
|
10260
10388
|
const ret = istate.stack.pop();
|
|
10261
|
-
if ((0, import_chunk_JDC43A3I.isExpression)(
|
|
10262
|
-
if (!ret ||
|
|
10389
|
+
if ((0, import_chunk_JDC43A3I.isExpression)(root)) {
|
|
10390
|
+
if (!ret || root !== ret.node) {
|
|
10263
10391
|
throw new Error("evaluate failed to produce a value for an expression");
|
|
10264
10392
|
}
|
|
10265
10393
|
}
|
|
@@ -10455,6 +10583,7 @@ function getLhsConstraint(istate, node) {
|
|
|
10455
10583
|
}
|
|
10456
10584
|
function pushScopedNameType(istate, node, object) {
|
|
10457
10585
|
let embeddedEffects = object ? object.embeddedEffects : false;
|
|
10586
|
+
istate.frpushType = object?.value;
|
|
10458
10587
|
let result;
|
|
10459
10588
|
if (istate.typeMap) {
|
|
10460
10589
|
result = istate.typeMap.get(node);
|
|
@@ -10577,7 +10706,7 @@ function evaluateNode(istate, node) {
|
|
|
10577
10706
|
diagnostic(
|
|
10578
10707
|
istate.state,
|
|
10579
10708
|
node,
|
|
10580
|
-
|
|
10709
|
+
formatAstLongLines(
|
|
10581
10710
|
left.value.type === 1 ? node.right : node.left
|
|
10582
10711
|
).then(
|
|
10583
10712
|
(nodeStr) => `This comparison seems redundant because ${nodeStr} should never be null`
|
|
@@ -10736,7 +10865,7 @@ function evaluateNode(istate, node) {
|
|
|
10736
10865
|
const si = state.stack[i].sn;
|
|
10737
10866
|
if (si.type === "ClassDeclaration") {
|
|
10738
10867
|
const klass = { type: 16384, value: si };
|
|
10739
|
-
if ((istate.
|
|
10868
|
+
if ((istate.root?.attributes || 0) & 8) {
|
|
10740
10869
|
return klass;
|
|
10741
10870
|
} else {
|
|
10742
10871
|
return { type: 32768, value: { klass } };
|
|
@@ -10952,7 +11081,7 @@ function evaluateNode(istate, node) {
|
|
|
10952
11081
|
diagnostic(
|
|
10953
11082
|
istate.state,
|
|
10954
11083
|
node,
|
|
10955
|
-
|
|
11084
|
+
formatAstLongLines(node.left).then(
|
|
10956
11085
|
(nodeStr) => `Invalid assignment to ${nodeStr}. Expected ${display(
|
|
10957
11086
|
constraint
|
|
10958
11087
|
)} but got ${display(actual)}`
|
|
@@ -11039,8 +11168,8 @@ function evaluateNode(istate, node) {
|
|
|
11039
11168
|
istate.state,
|
|
11040
11169
|
node,
|
|
11041
11170
|
Promise.all([
|
|
11042
|
-
|
|
11043
|
-
|
|
11171
|
+
formatAstLongLines(node.id.left),
|
|
11172
|
+
formatAstLongLines(node.id.right)
|
|
11044
11173
|
]).then(
|
|
11045
11174
|
([leftStr, rightStr]) => `Invalid initializer for ${leftStr}. Expected ${rightStr} but got ${display(
|
|
11046
11175
|
init.value
|
|
@@ -11063,21 +11192,21 @@ function evaluateNode(istate, node) {
|
|
|
11063
11192
|
case "ReturnStatement": {
|
|
11064
11193
|
const value2 = node.argument && popIstate(istate, node.argument);
|
|
11065
11194
|
if (istate.typeChecker) {
|
|
11066
|
-
if (
|
|
11195
|
+
if (istate.root?.type !== "FunctionDeclaration") {
|
|
11067
11196
|
throw new Error("ReturnStatement found outside of function");
|
|
11068
11197
|
}
|
|
11069
|
-
if (istate.
|
|
11198
|
+
if (istate.root.node.returnType) {
|
|
11070
11199
|
const returnType = typeFromTypespec(
|
|
11071
11200
|
istate.state,
|
|
11072
|
-
istate.
|
|
11073
|
-
istate.
|
|
11201
|
+
istate.root.node.returnType.argument,
|
|
11202
|
+
istate.root.stack
|
|
11074
11203
|
);
|
|
11075
11204
|
if (value2) {
|
|
11076
11205
|
if (!istate.typeChecker(value2.value, returnType)) {
|
|
11077
11206
|
diagnostic(
|
|
11078
11207
|
istate.state,
|
|
11079
11208
|
node,
|
|
11080
|
-
`Expected ${istate.
|
|
11209
|
+
`Expected ${istate.root.fullName} to return ${display(
|
|
11081
11210
|
returnType
|
|
11082
11211
|
)} but got ${display(value2.value)}`,
|
|
11083
11212
|
istate.checkTypes
|
|
@@ -11191,7 +11320,7 @@ function mustBeIdentical(a, b) {
|
|
|
11191
11320
|
return false;
|
|
11192
11321
|
}
|
|
11193
11322
|
function isByteArrayData(objectData) {
|
|
11194
|
-
return objectData.klass.value && (0,
|
|
11323
|
+
return objectData.klass.value && (0, import_chunk_NHZRKHZO.every)(
|
|
11195
11324
|
objectData.klass.value,
|
|
11196
11325
|
(klass) => klass.fullName === "$.Toybox.Lang.ByteArray"
|
|
11197
11326
|
);
|
|
@@ -11203,7 +11332,7 @@ var init_interp = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
11203
11332
|
(0, import_chunk_JDC43A3I.init_ast)();
|
|
11204
11333
|
init_data_flow();
|
|
11205
11334
|
init_optimizer_types();
|
|
11206
|
-
(0,
|
|
11335
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
11207
11336
|
init_could_be();
|
|
11208
11337
|
init_interp_binary();
|
|
11209
11338
|
init_interp_call();
|
|
@@ -11310,7 +11439,7 @@ function resolveEnum(e) {
|
|
|
11310
11439
|
unionInto(
|
|
11311
11440
|
result,
|
|
11312
11441
|
next.type === "EnumStringMember" && next.init?.type === "Literal" ? typeFromLiteral(next.init) : {
|
|
11313
|
-
type: 8
|
|
11442
|
+
type: next.type === "EnumStringMember" && next.init ? EnumTagsConst : 8
|
|
11314
11443
|
/* Number */
|
|
11315
11444
|
}
|
|
11316
11445
|
);
|
|
@@ -11408,10 +11537,7 @@ function typeFromTypeStateNode(state, sn, classVsObj) {
|
|
|
11408
11537
|
};
|
|
11409
11538
|
case "EnumStringMember": {
|
|
11410
11539
|
const e = state.enumMap?.get(sn);
|
|
11411
|
-
const value2 = sn.init?.type === "Literal" ? typeFromLiteral(sn.init) : e ? resolveEnum(e) : {
|
|
11412
|
-
type: 8 | 16
|
|
11413
|
-
/* Long */
|
|
11414
|
-
};
|
|
11540
|
+
const value2 = sn.init?.type === "Literal" ? typeFromLiteral(sn.init) : sn.resolvedType ?? (e ? resolveEnum(e) : { type: EnumTagsConst });
|
|
11415
11541
|
return { type: 65536, value: { enum: e, value: value2 } };
|
|
11416
11542
|
}
|
|
11417
11543
|
case "TypedefDeclaration": {
|
|
@@ -11434,7 +11560,7 @@ function typeFromTypeStateNode(state, sn, classVsObj) {
|
|
|
11434
11560
|
);
|
|
11435
11561
|
if (value2) {
|
|
11436
11562
|
const a = [];
|
|
11437
|
-
(0,
|
|
11563
|
+
(0, import_chunk_NHZRKHZO.forEach)(value2, (v) => {
|
|
11438
11564
|
if (v !== sn)
|
|
11439
11565
|
a.push(v);
|
|
11440
11566
|
});
|
|
@@ -11658,7 +11784,9 @@ function typeFromSingleTypeSpec(state, type, stack) {
|
|
|
11658
11784
|
diagnostic(
|
|
11659
11785
|
state,
|
|
11660
11786
|
id,
|
|
11661
|
-
|
|
11787
|
+
formatAstLongLines(id).then(
|
|
11788
|
+
(idStr) => `Unable to resolve type ${idStr}`
|
|
11789
|
+
),
|
|
11662
11790
|
level || "WARNING"
|
|
11663
11791
|
);
|
|
11664
11792
|
}
|
|
@@ -11926,7 +12054,7 @@ function mustBeFalse(arg) {
|
|
|
11926
12054
|
return arg.type === 1 || arg.type === 2 || (arg.type === 8 || arg.type === 16) && arg.value != null && Number(arg.value) === 0;
|
|
11927
12055
|
}
|
|
11928
12056
|
function display(type) {
|
|
11929
|
-
const names = (v, fn) => (0,
|
|
12057
|
+
const names = (v, fn) => (0, import_chunk_NHZRKHZO.map)(v, fn).sort().filter((s, i, arr) => !i || s !== arr[i - 1]).join(" or ");
|
|
11930
12058
|
const parts = [];
|
|
11931
12059
|
const displayOne = (tv) => {
|
|
11932
12060
|
switch (tv.type) {
|
|
@@ -12124,13 +12252,13 @@ var LastTypeTag, SingletonTypeTagsConst, UnionDataTypeTagsConst, ValueTypeTagsCo
|
|
|
12124
12252
|
var init_types = (0, import_chunk_ABYVSU2C.__esm)({
|
|
12125
12253
|
"src/type-flow/types.ts"() {
|
|
12126
12254
|
"use strict";
|
|
12127
|
-
init_data_flow();
|
|
12128
12255
|
init_api();
|
|
12129
12256
|
(0, import_chunk_JDC43A3I.init_ast)();
|
|
12130
|
-
(
|
|
12257
|
+
init_data_flow();
|
|
12258
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
12131
12259
|
init_interp();
|
|
12132
|
-
init_union_type();
|
|
12133
12260
|
init_intersection_type();
|
|
12261
|
+
init_union_type();
|
|
12134
12262
|
LastTypeTag = 262144;
|
|
12135
12263
|
SingletonTypeTagsConst = 1 | 2 | 4;
|
|
12136
12264
|
UnionDataTypeTagsConst = 512 | 1024 | 2048 | 4096 | 8192 | 16384 | 32768 | 65536 | 262144;
|
|
@@ -12187,7 +12315,7 @@ function couldBeHelper(a, b, shallow) {
|
|
|
12187
12315
|
262144
|
|
12188
12316
|
/* Typedef */
|
|
12189
12317
|
);
|
|
12190
|
-
return typedef && (0,
|
|
12318
|
+
return typedef && (0, import_chunk_NHZRKHZO.some)(typedef, (td) => {
|
|
12191
12319
|
if (!td.resolvedType) {
|
|
12192
12320
|
throw new Error(`No resolved type for ${td.fullName} in 'couldBe'`);
|
|
12193
12321
|
}
|
|
@@ -12259,15 +12387,15 @@ function couldBeValue(pair, shallow) {
|
|
|
12259
12387
|
}
|
|
12260
12388
|
case 4096:
|
|
12261
12389
|
case 8192: {
|
|
12262
|
-
return (0,
|
|
12390
|
+
return (0, import_chunk_NHZRKHZO.some)(
|
|
12263
12391
|
pair.avalue,
|
|
12264
|
-
(sna) => (0,
|
|
12392
|
+
(sna) => (0, import_chunk_NHZRKHZO.some)(pair.bvalue, (snb) => sna === snb)
|
|
12265
12393
|
);
|
|
12266
12394
|
}
|
|
12267
12395
|
case 16384: {
|
|
12268
|
-
return (0,
|
|
12396
|
+
return (0, import_chunk_NHZRKHZO.some)(pair.avalue, (sna) => {
|
|
12269
12397
|
const superA = getSuperClasses(sna);
|
|
12270
|
-
return (0,
|
|
12398
|
+
return (0, import_chunk_NHZRKHZO.some)(pair.bvalue, (snb) => {
|
|
12271
12399
|
if (sna === snb || superA && superA.has(snb)) {
|
|
12272
12400
|
return true;
|
|
12273
12401
|
}
|
|
@@ -12300,7 +12428,7 @@ var init_could_be = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
12300
12428
|
"use strict";
|
|
12301
12429
|
init_api();
|
|
12302
12430
|
init_data_flow();
|
|
12303
|
-
(0,
|
|
12431
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
12304
12432
|
init_types();
|
|
12305
12433
|
}
|
|
12306
12434
|
});
|
|
@@ -12407,7 +12535,7 @@ function findDeadStores(func, graph, nodeEquivs, findCopyPropCandidates, logThis
|
|
|
12407
12535
|
}
|
|
12408
12536
|
addAnt(curState.partiallyAnticipated, key, node);
|
|
12409
12537
|
if (logThisRun) {
|
|
12410
|
-
(0,
|
|
12538
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
12411
12539
|
` antrefs: ${curState.partiallyAnticipated.get(key) !== false} ${curState.anticipated.get(key) !== false}`
|
|
12412
12540
|
);
|
|
12413
12541
|
}
|
|
@@ -12430,7 +12558,7 @@ function findDeadStores(func, graph, nodeEquivs, findCopyPropCandidates, logThis
|
|
|
12430
12558
|
const curState = cloneState(blockStates[top.order]);
|
|
12431
12559
|
if (logThisRun) {
|
|
12432
12560
|
printBlockHeader(top);
|
|
12433
|
-
curState.dead.forEach((decl) => (0,
|
|
12561
|
+
curState.dead.forEach((decl) => (0, import_chunk_NHZRKHZO.log)(` - anticipated: ${tsKey(decl)}`));
|
|
12434
12562
|
}
|
|
12435
12563
|
if (top.events) {
|
|
12436
12564
|
for (let i = top.events.length; i--; ) {
|
|
@@ -12442,12 +12570,12 @@ function findDeadStores(func, graph, nodeEquivs, findCopyPropCandidates, logThis
|
|
|
12442
12570
|
case "ref":
|
|
12443
12571
|
if (isTypeStateKey(event.decl)) {
|
|
12444
12572
|
if (logThisRun) {
|
|
12445
|
-
(0,
|
|
12573
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
12446
12574
|
describeEvent(event).then(
|
|
12447
12575
|
(eventStr) => `${eventStr} (${sourceLocation(event.node.loc)})`
|
|
12448
12576
|
)
|
|
12449
12577
|
);
|
|
12450
|
-
(0,
|
|
12578
|
+
(0, import_chunk_NHZRKHZO.log)(` kill => ${tsKey(event.decl)}`);
|
|
12451
12579
|
}
|
|
12452
12580
|
copyPropRef(curState, event.decl, event.node);
|
|
12453
12581
|
curState.dead.delete(event.decl);
|
|
@@ -12456,7 +12584,7 @@ function findDeadStores(func, graph, nodeEquivs, findCopyPropCandidates, logThis
|
|
|
12456
12584
|
case "def":
|
|
12457
12585
|
if (isTypeStateKey(event.decl) && (event.node.type !== "VariableDeclarator" || event.node.init)) {
|
|
12458
12586
|
if (logThisRun) {
|
|
12459
|
-
(0,
|
|
12587
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
12460
12588
|
describeEvent(event).then(
|
|
12461
12589
|
(eventStr) => `${eventStr} (${sourceLocation(event.node.loc)})`
|
|
12462
12590
|
)
|
|
@@ -12472,7 +12600,7 @@ function findDeadStores(func, graph, nodeEquivs, findCopyPropCandidates, logThis
|
|
|
12472
12600
|
const pant = curState.partiallyAnticipated.get(event.decl);
|
|
12473
12601
|
if (pant) {
|
|
12474
12602
|
if (logThisRun) {
|
|
12475
|
-
(0,
|
|
12603
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
12476
12604
|
` is copy-prop-candidate ${curState.anticipated?.get(event.decl) === pant}`
|
|
12477
12605
|
);
|
|
12478
12606
|
}
|
|
@@ -12504,7 +12632,7 @@ function findDeadStores(func, graph, nodeEquivs, findCopyPropCandidates, logThis
|
|
|
12504
12632
|
if (assignNode) {
|
|
12505
12633
|
curState.dead.add(event.decl);
|
|
12506
12634
|
if (logThisRun) {
|
|
12507
|
-
(0,
|
|
12635
|
+
(0, import_chunk_NHZRKHZO.log)(` anticipated => ${tsKey(event.decl)}`);
|
|
12508
12636
|
}
|
|
12509
12637
|
} else if (event.node.type === "UpdateExpression") {
|
|
12510
12638
|
copyPropRef(curState, event.decl, event.node.argument);
|
|
@@ -12515,7 +12643,7 @@ function findDeadStores(func, graph, nodeEquivs, findCopyPropCandidates, logThis
|
|
|
12515
12643
|
if (isTypeStateKey(event.decl)) {
|
|
12516
12644
|
curState.dead.add(event.decl);
|
|
12517
12645
|
if (logThisRun) {
|
|
12518
|
-
(0,
|
|
12646
|
+
(0, import_chunk_NHZRKHZO.log)(` anticipated => ${tsKey(event.decl)}`);
|
|
12519
12647
|
}
|
|
12520
12648
|
}
|
|
12521
12649
|
break;
|
|
@@ -12578,10 +12706,10 @@ function eliminateDeadStores(state, func, graph, logThisRun) {
|
|
|
12578
12706
|
if (!deadStores.size)
|
|
12579
12707
|
return { changes: false, copyPropStores };
|
|
12580
12708
|
if (logThisRun) {
|
|
12581
|
-
(0,
|
|
12709
|
+
(0, import_chunk_NHZRKHZO.log)("====== Dead Stores =====");
|
|
12582
12710
|
deadStores.forEach(
|
|
12583
|
-
(dead) => (dead.type === "AssignmentExpression" || dead.type === "UpdateExpression" || dead.type === "VariableDeclarator") && (0,
|
|
12584
|
-
|
|
12711
|
+
(dead) => (dead.type === "AssignmentExpression" || dead.type === "UpdateExpression" || dead.type === "VariableDeclarator") && (0, import_chunk_NHZRKHZO.log)(
|
|
12712
|
+
formatAstLongLines(dead).then(
|
|
12585
12713
|
(deadStr) => `${deadStr} (${sourceLocation(dead.loc)})`
|
|
12586
12714
|
)
|
|
12587
12715
|
)
|
|
@@ -12635,47 +12763,50 @@ var init_dead_store = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
12635
12763
|
init_control_flow();
|
|
12636
12764
|
init_data_flow();
|
|
12637
12765
|
init_inliner();
|
|
12638
|
-
(0,
|
|
12766
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
12639
12767
|
init_minimize_locals();
|
|
12640
12768
|
init_type_flow_util();
|
|
12641
12769
|
}
|
|
12642
12770
|
});
|
|
12643
|
-
function loggingEnabledFor(env,
|
|
12771
|
+
function loggingEnabledFor(env, root) {
|
|
12644
12772
|
const pattern = process.env[env];
|
|
12645
12773
|
if (!pattern)
|
|
12646
12774
|
return false;
|
|
12647
12775
|
const match = pattern.match(/^\/(.*)\/(i?)$/);
|
|
12648
12776
|
if (match) {
|
|
12649
|
-
return new RegExp(match[1], match[2]).test(
|
|
12777
|
+
return new RegExp(match[1], match[2]).test(root.fullName);
|
|
12650
12778
|
}
|
|
12651
|
-
return pattern ===
|
|
12779
|
+
return pattern === root.fullName;
|
|
12652
12780
|
}
|
|
12653
|
-
function buildTypeInfo(state,
|
|
12654
|
-
if (!
|
|
12781
|
+
function buildTypeInfo(state, root, optimizeEquivalencies) {
|
|
12782
|
+
if (!root.node?.body || !root.stack)
|
|
12655
12783
|
return;
|
|
12656
|
-
const logThisRun = logging && loggingEnabledFor("TYPEFLOW_FUNC",
|
|
12784
|
+
const logThisRun = logging && loggingEnabledFor("TYPEFLOW_FUNC", root);
|
|
12657
12785
|
while (true) {
|
|
12658
|
-
const { graph } = buildDataFlowGraph(state,
|
|
12786
|
+
const { graph } = buildDataFlowGraph(state, root, () => false, false, true);
|
|
12659
12787
|
let copyPropStores;
|
|
12660
|
-
if (optimizeEquivalencies) {
|
|
12661
|
-
const
|
|
12662
|
-
if (
|
|
12788
|
+
if (optimizeEquivalencies && root.type === "FunctionDeclaration") {
|
|
12789
|
+
const result = eliminateDeadStores(state, root, graph, logThisRun);
|
|
12790
|
+
if (result.changes) {
|
|
12663
12791
|
continue;
|
|
12664
12792
|
}
|
|
12665
|
-
if (
|
|
12666
|
-
copyPropStores =
|
|
12793
|
+
if (result.copyPropStores.size) {
|
|
12794
|
+
copyPropStores = result.copyPropStores;
|
|
12667
12795
|
}
|
|
12668
12796
|
}
|
|
12669
|
-
const
|
|
12670
|
-
|
|
12671
|
-
|
|
12797
|
+
const stack = root.stack.slice();
|
|
12798
|
+
pushRootNode(stack, root);
|
|
12799
|
+
const { istate, redo } = propagateTypes(
|
|
12800
|
+
{ ...state, stack },
|
|
12801
|
+
root,
|
|
12672
12802
|
graph,
|
|
12673
12803
|
optimizeEquivalencies,
|
|
12674
12804
|
copyPropStores,
|
|
12675
12805
|
logThisRun
|
|
12676
12806
|
);
|
|
12677
|
-
|
|
12678
|
-
|
|
12807
|
+
popRootNode(stack, root);
|
|
12808
|
+
if (!redo) {
|
|
12809
|
+
return istate;
|
|
12679
12810
|
}
|
|
12680
12811
|
}
|
|
12681
12812
|
}
|
|
@@ -13000,13 +13131,13 @@ function typeStateEntry(value2, key) {
|
|
|
13000
13131
|
return `${tsKey(key)} = ${display(value2.curType)}`;
|
|
13001
13132
|
}
|
|
13002
13133
|
function printBlockState(block, state, indent = "") {
|
|
13003
|
-
(0,
|
|
13134
|
+
(0, import_chunk_NHZRKHZO.log)(indent + "State:");
|
|
13004
13135
|
if (!state) {
|
|
13005
|
-
(0,
|
|
13136
|
+
(0, import_chunk_NHZRKHZO.log)(indent + "Not visited!");
|
|
13006
13137
|
return;
|
|
13007
13138
|
}
|
|
13008
13139
|
state.map.forEach((value2, key) => {
|
|
13009
|
-
(0,
|
|
13140
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
13010
13141
|
`${indent} - ${typeStateEntry(value2, key)}${value2.equivSet ? ` [(${Array.from(value2.equivSet).map(tsKey).join(", ")})]` : ""}`
|
|
13011
13142
|
);
|
|
13012
13143
|
});
|
|
@@ -13104,18 +13235,18 @@ function updateAffected(blockState, objectType, baseDecl, assignedPath, affected
|
|
|
13104
13235
|
}
|
|
13105
13236
|
});
|
|
13106
13237
|
}
|
|
13107
|
-
function propagateTypes(state,
|
|
13238
|
+
function propagateTypes(state, root, graph, optimizeEquivalencies, copyPropStores, logThisRun) {
|
|
13108
13239
|
const order = getPostOrder(graph).reverse();
|
|
13109
13240
|
const queue = new DataflowQueue();
|
|
13110
|
-
const isStatic = !!(
|
|
13111
|
-
const klass =
|
|
13241
|
+
const isStatic = !!(root.attributes & 8);
|
|
13242
|
+
const klass = root.stack?.[root.stack?.length - 1].sn;
|
|
13112
13243
|
const selfClassDecl = klass && klass.type === "ClassDeclaration" ? klass : null;
|
|
13113
|
-
const uninitClassDecls = selfClassDecl &&
|
|
13114
|
-
Object.values(selfClassDecl.decls).
|
|
13115
|
-
(decls) => decls.
|
|
13244
|
+
const uninitClassDecls = selfClassDecl && root.name === "initialize" && selfClassDecl.decls ? new Set(
|
|
13245
|
+
Object.values(selfClassDecl.decls).flatMap(
|
|
13246
|
+
(decls) => decls.filter(
|
|
13116
13247
|
(decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && !decl.node.init
|
|
13117
13248
|
)
|
|
13118
|
-
)
|
|
13249
|
+
)
|
|
13119
13250
|
) : null;
|
|
13120
13251
|
order.forEach((block, i) => {
|
|
13121
13252
|
block.order = i;
|
|
@@ -13213,7 +13344,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13213
13344
|
type: 0
|
|
13214
13345
|
/* Never */
|
|
13215
13346
|
};
|
|
13216
|
-
(0,
|
|
13347
|
+
(0, import_chunk_NHZRKHZO.forEach)(avalue, (v) => unionInto(n, v));
|
|
13217
13348
|
next = n;
|
|
13218
13349
|
}
|
|
13219
13350
|
} else {
|
|
@@ -13318,7 +13449,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13318
13449
|
}
|
|
13319
13450
|
if (!isStatic && selfClassDecl) {
|
|
13320
13451
|
const baseObj = getObjectValue(baseElem.type);
|
|
13321
|
-
if (baseObj && baseObj.klass.type === 16384 && (0,
|
|
13452
|
+
if (baseObj && baseObj.klass.type === 16384 && (0, import_chunk_NHZRKHZO.some)(
|
|
13322
13453
|
baseObj.klass.value,
|
|
13323
13454
|
(cls) => cls === selfClassDecl || getSuperClasses(cls)?.has(selfClassDecl) || getSuperClasses(selfClassDecl)?.has(cls) || false
|
|
13324
13455
|
)) {
|
|
@@ -13363,7 +13494,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13363
13494
|
return [cur, updateAny];
|
|
13364
13495
|
}
|
|
13365
13496
|
function typeConstraint(decls, blockState) {
|
|
13366
|
-
return (0,
|
|
13497
|
+
return (0, import_chunk_NHZRKHZO.reduce)(
|
|
13367
13498
|
decls,
|
|
13368
13499
|
(cur, decl) => {
|
|
13369
13500
|
if (decl.type === "Identifier" || decl.type === "BinaryExpression") {
|
|
@@ -13453,15 +13584,17 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13453
13584
|
}
|
|
13454
13585
|
const blockStates = [];
|
|
13455
13586
|
const typeMap = /* @__PURE__ */ new Map();
|
|
13587
|
+
const dependencies = /* @__PURE__ */ new Map();
|
|
13456
13588
|
const istate = {
|
|
13457
13589
|
state,
|
|
13458
13590
|
typeMap,
|
|
13459
13591
|
stack: [],
|
|
13460
|
-
|
|
13592
|
+
root,
|
|
13593
|
+
dependencies
|
|
13461
13594
|
};
|
|
13462
|
-
const modifiableDecl = (decls, callees) => (0,
|
|
13595
|
+
const modifiableDecl = (decls, callees) => (0, import_chunk_NHZRKHZO.some)(
|
|
13463
13596
|
decls,
|
|
13464
|
-
(decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && !isLocal(decl) && (!callees || (0,
|
|
13597
|
+
(decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && !isLocal(decl) && (!callees || (0, import_chunk_NHZRKHZO.some)(callees, (callee) => functionMayModify(state, callee, decl)))
|
|
13465
13598
|
);
|
|
13466
13599
|
const mergeSuccState = (top, curState) => {
|
|
13467
13600
|
top.succs?.forEach((succ) => {
|
|
@@ -13470,7 +13603,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13470
13603
|
}
|
|
13471
13604
|
if (mergeTypeState(blockStates, succ.order, curState, nodeCopyProp)) {
|
|
13472
13605
|
if (logThisRun) {
|
|
13473
|
-
(0,
|
|
13606
|
+
(0, import_chunk_NHZRKHZO.log)(`re-merge: ${top.order} -> ${succ.order}`);
|
|
13474
13607
|
}
|
|
13475
13608
|
queue.enqueue(succ);
|
|
13476
13609
|
}
|
|
@@ -13480,7 +13613,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13480
13613
|
const calleeObj = getStateType(curState, calleeObjDecl);
|
|
13481
13614
|
let calleeResult = null;
|
|
13482
13615
|
let effectFree = true;
|
|
13483
|
-
(0,
|
|
13616
|
+
(0, import_chunk_NHZRKHZO.forEach)(callees, (callee) => {
|
|
13484
13617
|
const info = sysCallInfo(istate.state, callee);
|
|
13485
13618
|
if (!info) {
|
|
13486
13619
|
effectFree = false;
|
|
@@ -13757,7 +13890,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13757
13890
|
});
|
|
13758
13891
|
} else {
|
|
13759
13892
|
if (logThisRun) {
|
|
13760
|
-
(0,
|
|
13893
|
+
(0, import_chunk_NHZRKHZO.log)(` Flow (true): merge to ${trueSucc.order || -1}`);
|
|
13761
13894
|
printBlockState(top, sTrue || curState, " >true ");
|
|
13762
13895
|
}
|
|
13763
13896
|
if (mergeTypeState(
|
|
@@ -13767,7 +13900,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13767
13900
|
nodeCopyProp
|
|
13768
13901
|
)) {
|
|
13769
13902
|
if (logThisRun) {
|
|
13770
|
-
(0,
|
|
13903
|
+
(0, import_chunk_NHZRKHZO.log)(`re-merge: ${top.order} -> ${trueSucc.order}`);
|
|
13771
13904
|
}
|
|
13772
13905
|
queue.enqueue(trueSucc);
|
|
13773
13906
|
}
|
|
@@ -13779,7 +13912,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13779
13912
|
});
|
|
13780
13913
|
} else {
|
|
13781
13914
|
if (logThisRun) {
|
|
13782
|
-
(0,
|
|
13915
|
+
(0, import_chunk_NHZRKHZO.log)(` Flow (false): merge to: ${falseSucc.order || -1}`);
|
|
13783
13916
|
printBlockState(top, sFalse || curState, " >false ");
|
|
13784
13917
|
}
|
|
13785
13918
|
if (mergeTypeState(
|
|
@@ -13789,7 +13922,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13789
13922
|
nodeCopyProp
|
|
13790
13923
|
)) {
|
|
13791
13924
|
if (logThisRun) {
|
|
13792
|
-
(0,
|
|
13925
|
+
(0, import_chunk_NHZRKHZO.log)(`re-merge: ${top.order} -> ${falseSucc.order}`);
|
|
13793
13926
|
}
|
|
13794
13927
|
queue.enqueue(falseSucc);
|
|
13795
13928
|
}
|
|
@@ -13814,6 +13947,21 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13814
13947
|
}
|
|
13815
13948
|
validateTypeState(curState);
|
|
13816
13949
|
switch (event.type) {
|
|
13950
|
+
case "imp":
|
|
13951
|
+
switch (event.node.type) {
|
|
13952
|
+
case "ImportModule":
|
|
13953
|
+
case "Using":
|
|
13954
|
+
handleImportUsing(istate.state, event.node);
|
|
13955
|
+
break;
|
|
13956
|
+
case "ModuleDeclaration":
|
|
13957
|
+
case "Program":
|
|
13958
|
+
if (event.stack) {
|
|
13959
|
+
istate.state.stack = event.stack;
|
|
13960
|
+
istate.state.stack = istate.state.stackClone();
|
|
13961
|
+
}
|
|
13962
|
+
break;
|
|
13963
|
+
}
|
|
13964
|
+
break;
|
|
13817
13965
|
case "kil": {
|
|
13818
13966
|
const curEntry = getStateEntry(curState, event.decl);
|
|
13819
13967
|
if (curEntry.equivSet) {
|
|
@@ -13864,7 +14012,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13864
14012
|
}
|
|
13865
14013
|
}
|
|
13866
14014
|
if (logThisRun) {
|
|
13867
|
-
(0,
|
|
14015
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
13868
14016
|
describeEvent(event).then(
|
|
13869
14017
|
(eventStr) => ` ${eventStr} == ${display(curEntry.curType)}`
|
|
13870
14018
|
)
|
|
@@ -13874,7 +14022,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13874
14022
|
}
|
|
13875
14023
|
case "mod": {
|
|
13876
14024
|
if (logThisRun) {
|
|
13877
|
-
(0,
|
|
14025
|
+
(0, import_chunk_NHZRKHZO.log)(describeEvent(event).then((eventStr) => ` ${eventStr}`));
|
|
13878
14026
|
}
|
|
13879
14027
|
modInterference(curState, event, true, (callees, calleeObj) => {
|
|
13880
14028
|
clearRelatedCopyPropEvents(curState, null, nodeCopyProp);
|
|
@@ -13890,7 +14038,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13890
14038
|
);
|
|
13891
14039
|
}
|
|
13892
14040
|
}
|
|
13893
|
-
if (nodeCopyProp.size && event.node.type === "CallExpression" && (0,
|
|
14041
|
+
if (nodeCopyProp.size && event.node.type === "CallExpression" && (0, import_chunk_NHZRKHZO.some)(callees, (callee) => inlineRequested(state, callee))) {
|
|
13894
14042
|
event.node.arguments.forEach((arg) => {
|
|
13895
14043
|
const def = nodeCopyProp.get(arg);
|
|
13896
14044
|
if (def && nodeCopyProp.get(def) !== false) {
|
|
@@ -13902,7 +14050,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13902
14050
|
let calleeEffects;
|
|
13903
14051
|
curState.map.forEach((tsv, decl) => {
|
|
13904
14052
|
let type = tsv.curType;
|
|
13905
|
-
if ((type.value == null || !(type.type & (32768 | 512 | 1024))) && !(0,
|
|
14053
|
+
if ((type.value == null || !(type.type & (32768 | 512 | 1024))) && !(0, import_chunk_NHZRKHZO.some)(decl, (d) => d.type === "VariableDeclarator" && !isLocal(d))) {
|
|
13906
14054
|
return;
|
|
13907
14055
|
}
|
|
13908
14056
|
if (modifiableDecl(decl, callees)) {
|
|
@@ -13917,7 +14065,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13917
14065
|
curState.map.set(decl, {
|
|
13918
14066
|
curType: typeConstraint(decl, curState)
|
|
13919
14067
|
});
|
|
13920
|
-
} else if (type.type & (32768 | 512 | 1024) && (calleeEffects == null ? calleeEffects = !callees || !(0,
|
|
14068
|
+
} else if (type.type & (32768 | 512 | 1024) && (calleeEffects == null ? calleeEffects = !callees || !(0, import_chunk_NHZRKHZO.every)(callees, (callee) => callee.info === false) : calleeEffects)) {
|
|
13921
14069
|
if (type.value != null && type.type & 32768) {
|
|
13922
14070
|
const odata = getObjectValue(tsv.curType);
|
|
13923
14071
|
if (odata?.obj) {
|
|
@@ -13973,7 +14121,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13973
14121
|
delete before.copyPropItem;
|
|
13974
14122
|
}
|
|
13975
14123
|
}
|
|
13976
|
-
const expr = event.node.type === "VariableDeclarator" ? event.node.init || null : event.node;
|
|
14124
|
+
const expr = event.node.type === "VariableDeclarator" || event.node.type === "EnumStringMember" ? event.node.init || null : event.node;
|
|
13977
14125
|
const type = expr ? evaluate(istate, expr).value : {
|
|
13978
14126
|
type: 524287
|
|
13979
14127
|
/* Any */
|
|
@@ -13985,7 +14133,15 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13985
14133
|
2
|
|
13986
14134
|
/* Reassign */
|
|
13987
14135
|
);
|
|
13988
|
-
|
|
14136
|
+
if (type.type !== 524287) {
|
|
14137
|
+
if (event.node.type === "EnumStringMember" || event.node.type === "VariableDeclarator" && event.node.kind === "const") {
|
|
14138
|
+
(0, import_chunk_NHZRKHZO.forEach)(
|
|
14139
|
+
event.decl,
|
|
14140
|
+
(decl) => (decl.type === "VariableDeclarator" ? decl.node === event.node : decl === event.node) && (decl.resolvedType = type)
|
|
14141
|
+
);
|
|
14142
|
+
}
|
|
14143
|
+
}
|
|
14144
|
+
(0, import_chunk_NHZRKHZO.some)(event.decl, (decl) => {
|
|
13989
14145
|
if (decl.type !== "VariableDeclarator" || decl.node.kind !== "var" || !isClassVariable(decl)) {
|
|
13990
14146
|
return false;
|
|
13991
14147
|
}
|
|
@@ -13993,7 +14149,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
13993
14149
|
if (affected) {
|
|
13994
14150
|
const objType = typeFromTypeStateNodes(
|
|
13995
14151
|
istate.state,
|
|
13996
|
-
(0,
|
|
14152
|
+
(0, import_chunk_NHZRKHZO.map)(
|
|
13997
14153
|
event.decl,
|
|
13998
14154
|
(decl2) => decl2.type === "VariableDeclarator" && decl2.stack[decl2.stack.length - 1].sn
|
|
13999
14155
|
).filter(
|
|
@@ -14014,7 +14170,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14014
14170
|
});
|
|
14015
14171
|
if (wasComputedDecl) {
|
|
14016
14172
|
curState.map.forEach((value2, decls) => {
|
|
14017
|
-
if ((0,
|
|
14173
|
+
if ((0, import_chunk_NHZRKHZO.some)(
|
|
14018
14174
|
decls,
|
|
14019
14175
|
(decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && !isLocal(decl)
|
|
14020
14176
|
)) {
|
|
@@ -14060,14 +14216,14 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14060
14216
|
}
|
|
14061
14217
|
if (!copyPropCandidate.ant || // If the ref isn't anticipated, we can't propagate it
|
|
14062
14218
|
// in case it has side effects.
|
|
14063
|
-
(0,
|
|
14219
|
+
(0, import_chunk_NHZRKHZO.some)(
|
|
14064
14220
|
event2.calleeDecl,
|
|
14065
14221
|
(callee) => callee.type === "FunctionDeclaration" && inlineRequested(state, callee)
|
|
14066
14222
|
)) {
|
|
14067
14223
|
return false;
|
|
14068
14224
|
}
|
|
14069
14225
|
}
|
|
14070
|
-
if (!event2.decl || isTypeStateKey(event2.decl) && (0,
|
|
14226
|
+
if (!event2.decl || isTypeStateKey(event2.decl) && (0, import_chunk_NHZRKHZO.some)(
|
|
14071
14227
|
event2.decl,
|
|
14072
14228
|
(decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" || decl.type === "BinaryExpression" || decl.type === "Identifier"
|
|
14073
14229
|
)) {
|
|
@@ -14106,13 +14262,13 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14106
14262
|
}
|
|
14107
14263
|
}
|
|
14108
14264
|
if (uninitClassDecls?.size) {
|
|
14109
|
-
(0,
|
|
14265
|
+
(0, import_chunk_NHZRKHZO.forEach)(
|
|
14110
14266
|
event.decl,
|
|
14111
14267
|
(decl) => uninitClassDecls.has(decl) && curState.inited?.add(decl)
|
|
14112
14268
|
);
|
|
14113
14269
|
}
|
|
14114
14270
|
if (logThisRun) {
|
|
14115
|
-
(0,
|
|
14271
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14116
14272
|
describeEvent(event).then(
|
|
14117
14273
|
(eventStr) => ` ${eventStr} := ${display(type)}`
|
|
14118
14274
|
)
|
|
@@ -14130,7 +14286,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14130
14286
|
);
|
|
14131
14287
|
}
|
|
14132
14288
|
if (logThisRun) {
|
|
14133
|
-
(0,
|
|
14289
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14134
14290
|
describeEvent(event).then(
|
|
14135
14291
|
(eventStr) => ` ${eventStr} : ${!Array.isArray(event.left) && event.left.type === "MemberDecl" ? `${display(
|
|
14136
14292
|
curState.map.get(event.left.base)?.curType || {
|
|
@@ -14152,18 +14308,20 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14152
14308
|
const head = blockStates[0];
|
|
14153
14309
|
if (uninitClassDecls?.size)
|
|
14154
14310
|
head.inited = /* @__PURE__ */ new Set();
|
|
14155
|
-
|
|
14156
|
-
|
|
14157
|
-
|
|
14158
|
-
|
|
14159
|
-
|
|
14160
|
-
type:
|
|
14161
|
-
|
|
14162
|
-
|
|
14163
|
-
|
|
14164
|
-
|
|
14165
|
-
|
|
14166
|
-
|
|
14311
|
+
if (root.type === "FunctionDeclaration") {
|
|
14312
|
+
root.node.params.forEach((param) => {
|
|
14313
|
+
setStateEvent(
|
|
14314
|
+
head,
|
|
14315
|
+
param,
|
|
14316
|
+
param.type === "BinaryExpression" ? typeFromTypespec(state, param.right) : {
|
|
14317
|
+
type: 524287
|
|
14318
|
+
/* Any */
|
|
14319
|
+
},
|
|
14320
|
+
0
|
|
14321
|
+
/* None */
|
|
14322
|
+
);
|
|
14323
|
+
});
|
|
14324
|
+
}
|
|
14167
14325
|
queue.enqueue(order[0]);
|
|
14168
14326
|
while (!queue.empty()) {
|
|
14169
14327
|
const top = queue.dequeue();
|
|
@@ -14188,8 +14346,8 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14188
14346
|
}
|
|
14189
14347
|
if (!successorsHandled) {
|
|
14190
14348
|
if (logThisRun) {
|
|
14191
|
-
(0,
|
|
14192
|
-
` merge to: ${(0,
|
|
14349
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14350
|
+
` merge to: ${(0, import_chunk_NHZRKHZO.map)(
|
|
14193
14351
|
top.succs,
|
|
14194
14352
|
(succ) => succ.order || -1
|
|
14195
14353
|
).join(", ")}`
|
|
@@ -14210,6 +14368,40 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14210
14368
|
(0, import_node_assert3.default)(nodeCopyProp.get(value2) === key);
|
|
14211
14369
|
}
|
|
14212
14370
|
});
|
|
14371
|
+
order.forEach(
|
|
14372
|
+
(block) => block.events?.forEach((event) => {
|
|
14373
|
+
if (event.type !== "ref")
|
|
14374
|
+
return;
|
|
14375
|
+
(0, import_chunk_NHZRKHZO.forEach)(event.decl, (decl) => {
|
|
14376
|
+
if (decl.type === "VariableDeclarator" && decl.node.kind === "const" && (!decl.resolvedType || !hasValue(decl.resolvedType))) {
|
|
14377
|
+
const root2 = decl.stack.at(-1)?.sn;
|
|
14378
|
+
if (!root2 || root2.type !== "ModuleDeclaration" && root2.type !== "ClassDeclaration" && root2.type !== "Program") {
|
|
14379
|
+
return;
|
|
14380
|
+
}
|
|
14381
|
+
const dep = dependencies.get(root2);
|
|
14382
|
+
dependencies.set(
|
|
14383
|
+
root2,
|
|
14384
|
+
(dep ?? 0) | 1
|
|
14385
|
+
/* Type */
|
|
14386
|
+
);
|
|
14387
|
+
} else if (decl.type === "EnumStringMember" && decl.init && decl.init.type !== "Literal") {
|
|
14388
|
+
const e = state.enumMap?.get(decl);
|
|
14389
|
+
if (!e)
|
|
14390
|
+
return;
|
|
14391
|
+
const root2 = e.stack.at(-1)?.sn;
|
|
14392
|
+
if (!root2 || root2.type !== "ModuleDeclaration" && root2.type !== "ClassDeclaration" && root2.type !== "Program") {
|
|
14393
|
+
return;
|
|
14394
|
+
}
|
|
14395
|
+
const dep = dependencies.get(root2);
|
|
14396
|
+
dependencies.set(
|
|
14397
|
+
root2,
|
|
14398
|
+
(dep ?? 0) | 1
|
|
14399
|
+
/* Type */
|
|
14400
|
+
);
|
|
14401
|
+
}
|
|
14402
|
+
});
|
|
14403
|
+
})
|
|
14404
|
+
);
|
|
14213
14405
|
if (logThisRun) {
|
|
14214
14406
|
order.forEach((block) => {
|
|
14215
14407
|
printBlockHeader(block);
|
|
@@ -14220,25 +14412,25 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14220
14412
|
);
|
|
14221
14413
|
printBlockTrailer(block);
|
|
14222
14414
|
});
|
|
14223
|
-
(0,
|
|
14415
|
+
(0, import_chunk_NHZRKHZO.log)("====== TypeMap =====");
|
|
14224
14416
|
typeMap.forEach((value2, key) => {
|
|
14225
|
-
(0,
|
|
14226
|
-
|
|
14417
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14418
|
+
formatAstLongLines(key).then(
|
|
14227
14419
|
(keyStr) => `${keyStr} = ${display(value2)} ${key.loc && key.loc.source ? ` (${sourceLocation(key.loc)})` : ""}`
|
|
14228
14420
|
)
|
|
14229
14421
|
);
|
|
14230
14422
|
});
|
|
14231
|
-
(0,
|
|
14423
|
+
(0, import_chunk_NHZRKHZO.log)("====== EquivMap =====");
|
|
14232
14424
|
nodeEquivs.forEach((value2, key) => {
|
|
14233
|
-
(0,
|
|
14234
|
-
|
|
14425
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14426
|
+
formatAstLongLines(key).then(
|
|
14235
14427
|
(keyStr) => `${keyStr} = [${value2.equiv.map(
|
|
14236
14428
|
(equiv) => tsKey(equiv)
|
|
14237
14429
|
)}] ${key.loc && key.loc.source ? ` (${sourceLocation(key.loc)})` : ""}`
|
|
14238
14430
|
)
|
|
14239
14431
|
);
|
|
14240
14432
|
});
|
|
14241
|
-
(0,
|
|
14433
|
+
(0, import_chunk_NHZRKHZO.log)("====== Copy Prop =====");
|
|
14242
14434
|
nodeCopyProp.forEach((value2, key) => {
|
|
14243
14435
|
(0, import_node_assert3.default)(value2 !== false);
|
|
14244
14436
|
if (key.type === "VariableDeclarator" || key.type === "AssignmentExpression") {
|
|
@@ -14248,20 +14440,22 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14248
14440
|
value2.type === "VariableDeclarator" && value2.init || value2.type === "AssignmentExpression"
|
|
14249
14441
|
);
|
|
14250
14442
|
const node = value2.type === "VariableDeclarator" ? value2.init : value2.right;
|
|
14251
|
-
(0,
|
|
14252
|
-
|
|
14443
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14444
|
+
formatAstLongLines(key).then(
|
|
14253
14445
|
(keyStr) => formatAstLongLines(node).then(
|
|
14254
14446
|
(nodeStr) => `${keyStr} = [${nodeStr}] ${key.loc && key.loc.source ? ` (${sourceLocation(key.loc)})` : ""}`
|
|
14255
14447
|
)
|
|
14256
14448
|
)
|
|
14257
14449
|
);
|
|
14258
14450
|
});
|
|
14259
|
-
|
|
14260
|
-
|
|
14261
|
-
|
|
14451
|
+
if (root.nodes) {
|
|
14452
|
+
root.nodes.forEach((stack, node) => (0, import_chunk_NHZRKHZO.log)(formatAstLongLines(node)));
|
|
14453
|
+
} else {
|
|
14454
|
+
(0, import_chunk_NHZRKHZO.log)(formatAstLongLines(root.node));
|
|
14455
|
+
}
|
|
14262
14456
|
if (copyPropStores) {
|
|
14263
14457
|
copyPropStores.forEach(({ ref, ant }, node) => {
|
|
14264
|
-
(0,
|
|
14458
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14265
14459
|
formatAstLongLines(node).then(
|
|
14266
14460
|
(nodeStr) => `copy-prop-store: ${nodeStr}${ant ? "!" : ""} => ${nodeCopyProp.get(node) !== ref ? "Failed" : "Success"}`
|
|
14267
14461
|
)
|
|
@@ -14269,16 +14463,16 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14269
14463
|
});
|
|
14270
14464
|
}
|
|
14271
14465
|
}
|
|
14272
|
-
if (optimizeEquivalencies) {
|
|
14466
|
+
if (root.type === "FunctionDeclaration" && optimizeEquivalencies) {
|
|
14273
14467
|
if (!nodeEquivs.size && !selfAssignments.size && !nodeCopyProp.size) {
|
|
14274
|
-
return { istate, nodeEquivs };
|
|
14468
|
+
return { istate, nodeEquivs, redo: false };
|
|
14275
14469
|
}
|
|
14276
14470
|
if (logThisRun) {
|
|
14277
14471
|
if (selfAssignments.size) {
|
|
14278
|
-
(0,
|
|
14472
|
+
(0, import_chunk_NHZRKHZO.log)("====== Self Assignments =====");
|
|
14279
14473
|
selfAssignments.forEach(
|
|
14280
|
-
(self) => (0,
|
|
14281
|
-
|
|
14474
|
+
(self) => (0, import_chunk_NHZRKHZO.log)(
|
|
14475
|
+
formatAstLongLines(self).then(
|
|
14282
14476
|
(selfStr) => `${selfStr} (${sourceLocation(self.loc)})`
|
|
14283
14477
|
)
|
|
14284
14478
|
)
|
|
@@ -14318,7 +14512,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14318
14512
|
})
|
|
14319
14513
|
);
|
|
14320
14514
|
(0, import_chunk_JDC43A3I.traverseAst)(
|
|
14321
|
-
|
|
14515
|
+
root.node.body,
|
|
14322
14516
|
(node) => {
|
|
14323
14517
|
if (node.type === "AssignmentExpression" && node.operator !== "=" && nodeCopyProp.has(node.left)) {
|
|
14324
14518
|
const left = (0, import_chunk_JDC43A3I.cloneDeep)(node.left);
|
|
@@ -14342,7 +14536,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14342
14536
|
if (copyNode) {
|
|
14343
14537
|
if (node.type === "AssignmentExpression") {
|
|
14344
14538
|
if (logThisRun) {
|
|
14345
|
-
(0,
|
|
14539
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14346
14540
|
formatAstLongLines(node).then(
|
|
14347
14541
|
(nodeStr) => `Killing copy-prop assignment ${nodeStr}`
|
|
14348
14542
|
)
|
|
@@ -14357,7 +14551,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14357
14551
|
if (node.type === "VariableDeclarator") {
|
|
14358
14552
|
(0, import_node_assert3.default)(node.init);
|
|
14359
14553
|
if (logThisRun) {
|
|
14360
|
-
(0,
|
|
14554
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14361
14555
|
formatAstLongLines(node).then(
|
|
14362
14556
|
(nodeStr) => `Killing copy-prop variable initialization ${nodeStr}`
|
|
14363
14557
|
)
|
|
@@ -14378,7 +14572,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14378
14572
|
right: copyNode.right
|
|
14379
14573
|
};
|
|
14380
14574
|
if (logThisRun) {
|
|
14381
|
-
(0,
|
|
14575
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14382
14576
|
formatAstLongLines(node).then(
|
|
14383
14577
|
(nodeStr) => formatAstLongLines(replacement2).then(
|
|
14384
14578
|
(repStr) => `copy-prop ${nodeStr} => ${repStr}`
|
|
@@ -14391,7 +14585,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14391
14585
|
const init = copyNode.init;
|
|
14392
14586
|
(0, import_node_assert3.default)(init);
|
|
14393
14587
|
if (logThisRun) {
|
|
14394
|
-
(0,
|
|
14588
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14395
14589
|
formatAstLongLines(node).then(
|
|
14396
14590
|
(nodeStr) => formatAstLongLines(init).then(
|
|
14397
14591
|
(initStr) => `copy-prop ${nodeStr} => ${initStr}`
|
|
@@ -14405,8 +14599,8 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14405
14599
|
}
|
|
14406
14600
|
if (selfAssignments.has(node)) {
|
|
14407
14601
|
if (logThisRun) {
|
|
14408
|
-
(0,
|
|
14409
|
-
|
|
14602
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14603
|
+
formatAstLongLines(node).then(
|
|
14410
14604
|
(nodeStr) => `Deleting self assignment: ${nodeStr} (${sourceLocation(
|
|
14411
14605
|
node.loc
|
|
14412
14606
|
)})`
|
|
@@ -14449,7 +14643,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14449
14643
|
}, curInfo);
|
|
14450
14644
|
if (rep === curInfo)
|
|
14451
14645
|
return null;
|
|
14452
|
-
const name = (0,
|
|
14646
|
+
const name = (0, import_chunk_NHZRKHZO.reduce)(
|
|
14453
14647
|
rep.decl,
|
|
14454
14648
|
(cur, decl) => decl.type === "VariableDeclarator" ? decl.name : cur,
|
|
14455
14649
|
null
|
|
@@ -14457,8 +14651,8 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14457
14651
|
if (!name)
|
|
14458
14652
|
return null;
|
|
14459
14653
|
if (logThisRun) {
|
|
14460
|
-
(0,
|
|
14461
|
-
|
|
14654
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14655
|
+
formatAstLongLines(node).then(
|
|
14462
14656
|
(nodeStr) => `Replacing ${nodeStr} with ${name} at ${sourceLocation(
|
|
14463
14657
|
node.loc
|
|
14464
14658
|
)}`
|
|
@@ -14476,7 +14670,7 @@ function propagateTypes(state, func, graph, optimizeEquivalencies, copyPropStore
|
|
|
14476
14670
|
return {
|
|
14477
14671
|
istate,
|
|
14478
14672
|
nodeEquivs,
|
|
14479
|
-
redo: optimizeEquivalencies && nodeCopyProp.size
|
|
14673
|
+
redo: optimizeEquivalencies && nodeCopyProp.size !== 0
|
|
14480
14674
|
};
|
|
14481
14675
|
}
|
|
14482
14676
|
function updateByAssocPath(path7, property, update) {
|
|
@@ -14588,7 +14782,7 @@ var init_type_flow = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
14588
14782
|
init_type_flow_util();
|
|
14589
14783
|
init_types();
|
|
14590
14784
|
init_union_type();
|
|
14591
|
-
(0,
|
|
14785
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
14592
14786
|
logging = true;
|
|
14593
14787
|
missingNullWorkaround = true;
|
|
14594
14788
|
}
|
|
@@ -14640,9 +14834,9 @@ function minimizeLocals(state, func) {
|
|
|
14640
14834
|
if (!didMerge)
|
|
14641
14835
|
return;
|
|
14642
14836
|
if (logThisRun) {
|
|
14643
|
-
(0,
|
|
14837
|
+
(0, import_chunk_NHZRKHZO.log)(`>>> Merging locals in ${func.fullName}`);
|
|
14644
14838
|
merge.forEach(
|
|
14645
|
-
(merged) => merged.length > 1 && (0,
|
|
14839
|
+
(merged) => merged.length > 1 && (0, import_chunk_NHZRKHZO.log)(` - merging ${merged.map((k) => tsKey(k)).join(" | ")}`)
|
|
14646
14840
|
);
|
|
14647
14841
|
}
|
|
14648
14842
|
const remap = /* @__PURE__ */ new Map();
|
|
@@ -14912,7 +15106,7 @@ var init_minimize_locals = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
14912
15106
|
(0, import_chunk_JDC43A3I.init_ast)();
|
|
14913
15107
|
init_control_flow();
|
|
14914
15108
|
init_type_flow();
|
|
14915
|
-
(0,
|
|
15109
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
14916
15110
|
init_variable_renamer();
|
|
14917
15111
|
init_type_flow_util();
|
|
14918
15112
|
}
|
|
@@ -14923,12 +15117,12 @@ function logAntState(s, decl) {
|
|
|
14923
15117
|
defs2++;
|
|
14924
15118
|
return defs2;
|
|
14925
15119
|
}, 0);
|
|
14926
|
-
(0,
|
|
15120
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14927
15121
|
declFullName(decl).then(
|
|
14928
15122
|
(declStr) => ` - ${declStr}: ${candidateCost(s)} bytes, ${s.ant.size - defs} refs, ${defs} defs, ${s.live ? "" : "!"}live, ${s.isIsolated ? "" : "!"}isolated`
|
|
14929
15123
|
)
|
|
14930
15124
|
);
|
|
14931
|
-
(0,
|
|
15125
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
14932
15126
|
` - members: ${Array.from(s.members).map(([block, live]) => block.order + (live ? "t" : "f")).join(", ")}`
|
|
14933
15127
|
);
|
|
14934
15128
|
}
|
|
@@ -14945,7 +15139,7 @@ async function sizeBasedPRE(state, func) {
|
|
|
14945
15139
|
const candidates = computeAttributes(state, head);
|
|
14946
15140
|
if (candidates) {
|
|
14947
15141
|
if (logging2) {
|
|
14948
|
-
(0,
|
|
15142
|
+
(0, import_chunk_NHZRKHZO.log)(`Found ${candidates.size} candidates in ${func.fullName}`);
|
|
14949
15143
|
logAntDecls(candidates);
|
|
14950
15144
|
}
|
|
14951
15145
|
const nodeMap = /* @__PURE__ */ new Map();
|
|
@@ -15038,7 +15232,7 @@ function buildPREGraph(state, func) {
|
|
|
15038
15232
|
const event = block.events[i];
|
|
15039
15233
|
switch (event.type) {
|
|
15040
15234
|
case "ref":
|
|
15041
|
-
if ((0,
|
|
15235
|
+
if ((0, import_chunk_NHZRKHZO.some)(
|
|
15042
15236
|
event.decl,
|
|
15043
15237
|
(decl) => decl.type === "Literal" || decl.type === "VariableDeclarator" && decl.node.kind === "const"
|
|
15044
15238
|
)) {
|
|
@@ -15056,7 +15250,7 @@ function buildPREGraph(state, func) {
|
|
|
15056
15250
|
defs.add(event.decl);
|
|
15057
15251
|
break;
|
|
15058
15252
|
case "mod":
|
|
15059
|
-
if (event.callees && (0,
|
|
15253
|
+
if (event.callees && (0, import_chunk_NHZRKHZO.every)(event.callees, (callee) => callee.info === false)) {
|
|
15060
15254
|
block.events.splice(i, 1);
|
|
15061
15255
|
break;
|
|
15062
15256
|
}
|
|
@@ -15215,21 +15409,21 @@ function computeAttributes(state, head) {
|
|
|
15215
15409
|
});
|
|
15216
15410
|
if (logging2) {
|
|
15217
15411
|
order.forEach((block) => {
|
|
15218
|
-
(0,
|
|
15412
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
15219
15413
|
block.order,
|
|
15220
15414
|
`(${block.node ? block.node.loc?.start.line : "??"})`,
|
|
15221
15415
|
`Preds: ${(block.preds || []).map((block2) => block2.order).join(", ")}`
|
|
15222
15416
|
);
|
|
15223
15417
|
if (block.events) {
|
|
15224
15418
|
block.events.forEach(
|
|
15225
|
-
(event) => event.type !== "exn" && (0,
|
|
15419
|
+
(event) => event.type !== "exn" && (0, import_chunk_NHZRKHZO.log)(
|
|
15226
15420
|
Promise.resolve(
|
|
15227
|
-
event.decl ? declFullName(event.decl) : event.node ?
|
|
15421
|
+
event.decl ? declFullName(event.decl) : event.node ? formatAstLongLines(event.node) : "??"
|
|
15228
15422
|
).then((eventDetails) => ` ${event.type}: ${eventDetails}`)
|
|
15229
15423
|
)
|
|
15230
15424
|
);
|
|
15231
15425
|
}
|
|
15232
|
-
(0,
|
|
15426
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
15233
15427
|
`Succs: ${(block.succs || []).map((block2) => block2.order).join(", ")} ExSucc: ${block.exsucc ? block.exsucc.order : ""}`
|
|
15234
15428
|
);
|
|
15235
15429
|
});
|
|
@@ -15297,7 +15491,7 @@ function computeAttributes(state, head) {
|
|
|
15297
15491
|
}
|
|
15298
15492
|
case "mod": {
|
|
15299
15493
|
curState.forEach((candidates, decls) => {
|
|
15300
|
-
if ((0,
|
|
15494
|
+
if ((0, import_chunk_NHZRKHZO.some)(
|
|
15301
15495
|
decls,
|
|
15302
15496
|
(decl) => decl.type === "VariableDeclarator" && decl.node.kind === "var" && candidates.live && (!event.callees || event.callees.some(
|
|
15303
15497
|
(callee) => functionMayModify(state, callee, decl)
|
|
@@ -15339,7 +15533,7 @@ function computeAttributes(state, head) {
|
|
|
15339
15533
|
}
|
|
15340
15534
|
blockStates[top.order] = curState;
|
|
15341
15535
|
if (logging2) {
|
|
15342
|
-
(0,
|
|
15536
|
+
(0, import_chunk_NHZRKHZO.log)(`Updated block ${top.order}`);
|
|
15343
15537
|
logAntDecls(curState);
|
|
15344
15538
|
}
|
|
15345
15539
|
if (top.preds) {
|
|
@@ -15441,8 +15635,8 @@ function applyReplacements(func, nodeMap, declMap) {
|
|
|
15441
15635
|
}
|
|
15442
15636
|
const name = declMap.get(event.decl);
|
|
15443
15637
|
if (!name) {
|
|
15444
|
-
throw new
|
|
15445
|
-
|
|
15638
|
+
throw new import_chunk_NHZRKHZO.AwaitedError(
|
|
15639
|
+
formatAstLongLines(node).then(
|
|
15446
15640
|
(targetStr) => `No replacement found for "${targetStr}"`
|
|
15447
15641
|
)
|
|
15448
15642
|
);
|
|
@@ -15463,8 +15657,8 @@ function applyReplacements(func, nodeMap, declMap) {
|
|
|
15463
15657
|
const target = node.type === "AssignmentExpression" ? node.left : node.argument;
|
|
15464
15658
|
const name = declMap.get(event.decl);
|
|
15465
15659
|
if (!name) {
|
|
15466
|
-
throw new
|
|
15467
|
-
|
|
15660
|
+
throw new import_chunk_NHZRKHZO.AwaitedError(
|
|
15661
|
+
formatAstLongLines(target).then(
|
|
15468
15662
|
(targetStr) => `No replacement found for "${targetStr}"`
|
|
15469
15663
|
)
|
|
15470
15664
|
);
|
|
@@ -15526,14 +15720,14 @@ function applyReplacements(func, nodeMap, declMap) {
|
|
|
15526
15720
|
const decl = event.decl;
|
|
15527
15721
|
const name = declMap.get(decl);
|
|
15528
15722
|
if (!name) {
|
|
15529
|
-
throw new
|
|
15723
|
+
throw new import_chunk_NHZRKHZO.AwaitedError(
|
|
15530
15724
|
declFullName(decl).then(
|
|
15531
15725
|
(declStr) => `No replacement found for "${declStr}"`
|
|
15532
15726
|
)
|
|
15533
15727
|
);
|
|
15534
15728
|
}
|
|
15535
15729
|
if (!event.id) {
|
|
15536
|
-
throw new
|
|
15730
|
+
throw new import_chunk_NHZRKHZO.AwaitedError(
|
|
15537
15731
|
declFullName(decl).then(
|
|
15538
15732
|
(declStr) => `Missing id for mod event for "${declStr}"`
|
|
15539
15733
|
)
|
|
@@ -15598,7 +15792,7 @@ var init_pre = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
15598
15792
|
init_data_flow();
|
|
15599
15793
|
init_function_info();
|
|
15600
15794
|
init_minimize_locals();
|
|
15601
|
-
(0,
|
|
15795
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
15602
15796
|
logging2 = false;
|
|
15603
15797
|
LocalRefCost = 2;
|
|
15604
15798
|
}
|
|
@@ -15608,8 +15802,8 @@ function minimizeModules(ast, state) {
|
|
|
15608
15802
|
try {
|
|
15609
15803
|
const replacementMap = /* @__PURE__ */ new Map();
|
|
15610
15804
|
const conflictingNames = /* @__PURE__ */ new Set();
|
|
15611
|
-
state.pre = (node)
|
|
15612
|
-
if (
|
|
15805
|
+
state.pre = function(node) {
|
|
15806
|
+
if (this.inType)
|
|
15613
15807
|
return null;
|
|
15614
15808
|
switch (node.type) {
|
|
15615
15809
|
case "ModuleDeclaration":
|
|
@@ -15640,18 +15834,18 @@ function minimizeModules(ast, state) {
|
|
|
15640
15834
|
let toReplace = null;
|
|
15641
15835
|
let module2 = null;
|
|
15642
15836
|
let addImport = false;
|
|
15643
|
-
let [, results] =
|
|
15837
|
+
let [, results] = this.lookupValue(current, null);
|
|
15644
15838
|
let i = 0;
|
|
15645
15839
|
for (; results && results.length === 1 && results[0].results.length === 1 && (results[0].results[0].type === "Program" || results[0].results[0].type === "ClassDeclaration" || results[0].results[0].type === "ModuleDeclaration"); i++) {
|
|
15646
|
-
if (current.type === "Identifier" && results[0].results[0].type === "ModuleDeclaration" && isImportCandidate(results[0].results[0],
|
|
15647
|
-
const directResults = i ?
|
|
15840
|
+
if (current.type === "Identifier" && results[0].results[0].type === "ModuleDeclaration" && isImportCandidate(results[0].results[0], this.stack)) {
|
|
15841
|
+
const directResults = i ? this.lookupValue(current, null) : results;
|
|
15648
15842
|
if (directResults && directResults.length === 1 && directResults[0].results.length === 1 && directResults[0].results[0] === results[0].results[0]) {
|
|
15649
15843
|
toReplace = i ? parts[i - 1] : current;
|
|
15650
15844
|
module2 = results[0].results[0];
|
|
15651
15845
|
if (findUsingForNode(
|
|
15652
|
-
|
|
15653
|
-
|
|
15654
|
-
|
|
15846
|
+
this,
|
|
15847
|
+
this.stack,
|
|
15848
|
+
this.stack.length - 1,
|
|
15655
15849
|
current
|
|
15656
15850
|
) === directResults[0].results[0]) {
|
|
15657
15851
|
addImport = false;
|
|
@@ -15667,7 +15861,7 @@ function minimizeModules(ast, state) {
|
|
|
15667
15861
|
if (i === parts.length)
|
|
15668
15862
|
break;
|
|
15669
15863
|
current = parts[i].property;
|
|
15670
|
-
results = lookupNext(
|
|
15864
|
+
results = lookupNext(this, results, "decls", current);
|
|
15671
15865
|
}
|
|
15672
15866
|
if (toReplace) {
|
|
15673
15867
|
(0, import_node_assert5.default)(module2);
|
|
@@ -15683,6 +15877,7 @@ function minimizeModules(ast, state) {
|
|
|
15683
15877
|
}
|
|
15684
15878
|
return null;
|
|
15685
15879
|
};
|
|
15880
|
+
delete state.post;
|
|
15686
15881
|
collectNamespaces(ast, state);
|
|
15687
15882
|
const mappedNames = /* @__PURE__ */ new Map();
|
|
15688
15883
|
replacementMap.forEach((value2, key) => {
|
|
@@ -15969,7 +16164,7 @@ function beforeEvaluate(istate, node) {
|
|
|
15969
16164
|
break;
|
|
15970
16165
|
}
|
|
15971
16166
|
const id = node.right.argument;
|
|
15972
|
-
if ((0,
|
|
16167
|
+
if ((0, import_chunk_NHZRKHZO.every)(left.value.value, (m) => {
|
|
15973
16168
|
if ((0, import_chunk_JDC43A3I.hasProperty)(m.decls, id.name))
|
|
15974
16169
|
return false;
|
|
15975
16170
|
return istate.state.lookup({
|
|
@@ -16415,7 +16610,7 @@ var init_optimize = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
16415
16610
|
(0, import_chunk_JDC43A3I.init_ast)();
|
|
16416
16611
|
init_inliner();
|
|
16417
16612
|
init_type_flow();
|
|
16418
|
-
(0,
|
|
16613
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
16419
16614
|
init_interp();
|
|
16420
16615
|
init_interp_binary();
|
|
16421
16616
|
init_types();
|
|
@@ -16762,6 +16957,7 @@ async function analyze(fnMap, resourcesMap, manifestXML, config, allowParseError
|
|
|
16762
16957
|
config,
|
|
16763
16958
|
allFunctions: {},
|
|
16764
16959
|
allClasses: [],
|
|
16960
|
+
allModules: /* @__PURE__ */ new Set(),
|
|
16765
16961
|
shouldExclude(node) {
|
|
16766
16962
|
if ("attrs" in node && node.attrs && "attributes" in node.attrs && node.attrs.attributes && node.loc?.source) {
|
|
16767
16963
|
const excludeAnnotations = fnMap[node.loc.source].excludeAnnotations;
|
|
@@ -16786,26 +16982,28 @@ async function analyze(fnMap, resourcesMap, manifestXML, config, allowParseError
|
|
|
16786
16982
|
}
|
|
16787
16983
|
return false;
|
|
16788
16984
|
},
|
|
16789
|
-
pre(node
|
|
16985
|
+
pre(node) {
|
|
16790
16986
|
switch (node.type) {
|
|
16791
16987
|
case "FunctionDeclaration":
|
|
16792
16988
|
case "ModuleDeclaration":
|
|
16793
16989
|
case "ClassDeclaration": {
|
|
16794
|
-
const scope =
|
|
16795
|
-
scope.stack =
|
|
16990
|
+
const scope = this.top().sn;
|
|
16991
|
+
scope.stack = this.stackClone().slice(0, -1);
|
|
16796
16992
|
if (scope.type === "FunctionDeclaration") {
|
|
16797
16993
|
if (markApi && node.loc?.source === "api.mir") {
|
|
16798
16994
|
node.body = null;
|
|
16799
|
-
scope.info = getApiFunctionInfo(
|
|
16995
|
+
scope.info = getApiFunctionInfo(this, scope);
|
|
16800
16996
|
}
|
|
16801
|
-
const allFuncs =
|
|
16997
|
+
const allFuncs = this.allFunctions;
|
|
16802
16998
|
if (!(0, import_chunk_JDC43A3I.hasProperty)(allFuncs, scope.name)) {
|
|
16803
16999
|
allFuncs[scope.name] = [scope];
|
|
16804
17000
|
} else {
|
|
16805
17001
|
allFuncs[scope.name].push(scope);
|
|
16806
17002
|
}
|
|
16807
17003
|
} else if (scope.type === "ClassDeclaration") {
|
|
16808
|
-
|
|
17004
|
+
this.allClasses.push(scope);
|
|
17005
|
+
} else if (scope.type === "ModuleDeclaration") {
|
|
17006
|
+
this.allModules.add(scope);
|
|
16809
17007
|
}
|
|
16810
17008
|
break;
|
|
16811
17009
|
}
|
|
@@ -16864,7 +17062,7 @@ function reportMissingSymbols(state, config) {
|
|
|
16864
17062
|
diagnostic(
|
|
16865
17063
|
state,
|
|
16866
17064
|
node,
|
|
16867
|
-
|
|
17065
|
+
formatAstLongLines(node).then(
|
|
16868
17066
|
(nodeStr) => `The expression ${nodeStr} will fail at runtime using sdk-4.1.6`
|
|
16869
17067
|
),
|
|
16870
17068
|
compiler2DiagnosticType
|
|
@@ -16880,7 +17078,9 @@ function reportMissingSymbols(state, config) {
|
|
|
16880
17078
|
diagnostic(
|
|
16881
17079
|
state,
|
|
16882
17080
|
node,
|
|
16883
|
-
|
|
17081
|
+
formatAstLongLines(node).then(
|
|
17082
|
+
(nodeStr) => `Undefined symbol ${nodeStr}`
|
|
17083
|
+
),
|
|
16884
17084
|
diagnosticType
|
|
16885
17085
|
);
|
|
16886
17086
|
return false;
|
|
@@ -16990,11 +17190,11 @@ function markFunctionCalled(state, func) {
|
|
|
16990
17190
|
state.calledFunctions[func.id.name] = [func];
|
|
16991
17191
|
return;
|
|
16992
17192
|
}
|
|
16993
|
-
(0,
|
|
17193
|
+
(0, import_chunk_NHZRKHZO.pushUnique)(state.calledFunctions[func.id.name], func);
|
|
16994
17194
|
}
|
|
16995
17195
|
function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
|
|
16996
17196
|
return optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config).catch(
|
|
16997
|
-
(ex) => Promise.reject(ex instanceof
|
|
17197
|
+
(ex) => Promise.reject(ex instanceof import_chunk_NHZRKHZO.AwaitedError ? ex.resolve() : ex)
|
|
16998
17198
|
);
|
|
16999
17199
|
}
|
|
17000
17200
|
async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
@@ -17025,21 +17225,21 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17025
17225
|
}
|
|
17026
17226
|
return result;
|
|
17027
17227
|
};
|
|
17028
|
-
const topLocals = () =>
|
|
17029
|
-
const checkInherited = (elm, name) => elm.superClass === true || elm.superClass != null && elm.superClass.some(
|
|
17228
|
+
const topLocals = (state2) => state2.localsStack[state2.localsStack.length - 1];
|
|
17229
|
+
const checkInherited = (state2, elm, name) => elm.superClass === true || elm.superClass != null && elm.superClass.some(
|
|
17030
17230
|
(sc) => (0, import_chunk_JDC43A3I.hasProperty)(sc.decls, name) && sc.decls[name].some(
|
|
17031
|
-
(f) => isStateNode(f) && f.type === "FunctionDeclaration" && maybeCalled(
|
|
17032
|
-
) || sc.superClass && checkInherited(sc, name)
|
|
17231
|
+
(f) => isStateNode(f) && f.type === "FunctionDeclaration" && maybeCalled(state2, f.node)
|
|
17232
|
+
) || sc.superClass && checkInherited(state2, sc, name)
|
|
17033
17233
|
);
|
|
17034
|
-
const renamer = (idNode) => {
|
|
17234
|
+
const renamer = (state2, idNode) => {
|
|
17035
17235
|
const ident = idNode.type === "Identifier" ? idNode : idNode.left;
|
|
17036
|
-
const locals = topLocals();
|
|
17236
|
+
const locals = topLocals(state2);
|
|
17037
17237
|
const { map: map2 } = locals;
|
|
17038
17238
|
if (map2) {
|
|
17039
17239
|
const declName2 = ident.name;
|
|
17040
|
-
const name = renameVariable(
|
|
17240
|
+
const name = renameVariable(state2, locals, declName2);
|
|
17041
17241
|
if (name) {
|
|
17042
|
-
const [, results] =
|
|
17242
|
+
const [, results] = state2.lookupValue(ident);
|
|
17043
17243
|
if (!results) {
|
|
17044
17244
|
throw new Error(
|
|
17045
17245
|
`Didn't find local ${declName2} which needed renaming`
|
|
@@ -17094,7 +17294,7 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17094
17294
|
gistate.checkTypes = state.config?.checkTypes || "WARNING";
|
|
17095
17295
|
}
|
|
17096
17296
|
let istate = gistate;
|
|
17097
|
-
state.pre = (node)
|
|
17297
|
+
state.pre = function(node) {
|
|
17098
17298
|
const ret = preEvaluate(istate, node);
|
|
17099
17299
|
switch (node.type) {
|
|
17100
17300
|
case "EnumDeclaration":
|
|
@@ -17104,20 +17304,23 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17104
17304
|
case "EnumStringMember":
|
|
17105
17305
|
return ["init"];
|
|
17106
17306
|
case "ForStatement": {
|
|
17107
|
-
const map2 = topLocals().map;
|
|
17307
|
+
const map2 = topLocals(this).map;
|
|
17108
17308
|
if (map2) {
|
|
17109
|
-
|
|
17309
|
+
this.localsStack.push({ node, map: { ...map2 } });
|
|
17110
17310
|
}
|
|
17111
17311
|
break;
|
|
17112
17312
|
}
|
|
17113
17313
|
case "VariableDeclarator": {
|
|
17114
|
-
renamer(node.id);
|
|
17314
|
+
renamer(this, node.id);
|
|
17115
17315
|
break;
|
|
17116
17316
|
}
|
|
17117
17317
|
case "CatchClause":
|
|
17118
17318
|
if (node.param) {
|
|
17119
|
-
|
|
17120
|
-
|
|
17319
|
+
this.localsStack.push({
|
|
17320
|
+
node,
|
|
17321
|
+
map: { ...topLocals(this).map || {} }
|
|
17322
|
+
});
|
|
17323
|
+
renamer(this, node.param);
|
|
17121
17324
|
}
|
|
17122
17325
|
break;
|
|
17123
17326
|
case "BinaryExpression":
|
|
@@ -17126,13 +17329,13 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17126
17329
|
}
|
|
17127
17330
|
break;
|
|
17128
17331
|
case "Identifier": {
|
|
17129
|
-
const map2 = topLocals().map;
|
|
17332
|
+
const map2 = topLocals(this).map;
|
|
17130
17333
|
if ((0, import_chunk_JDC43A3I.hasProperty)(map2, node.name)) {
|
|
17131
17334
|
const name = map2[node.name];
|
|
17132
17335
|
if (typeof name === "string") {
|
|
17133
17336
|
renameIdentifier(node, name);
|
|
17134
17337
|
}
|
|
17135
|
-
const [, results] =
|
|
17338
|
+
const [, results] = this.lookupValue(node);
|
|
17136
17339
|
if (results) {
|
|
17137
17340
|
if (results.length !== 1 || results[0].results.length !== 1) {
|
|
17138
17341
|
throw new Error(`Local ${node.name} had multiple lookup results`);
|
|
@@ -17159,7 +17362,7 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17159
17362
|
case "UpdateExpression": {
|
|
17160
17363
|
const lhs = node.type === "AssignmentExpression" ? node.left : node.argument;
|
|
17161
17364
|
if (lhs.type === "Identifier") {
|
|
17162
|
-
const map2 = topLocals().map;
|
|
17365
|
+
const map2 = topLocals(this).map;
|
|
17163
17366
|
if (map2) {
|
|
17164
17367
|
if ((0, import_chunk_JDC43A3I.hasProperty)(map2, lhs.name)) {
|
|
17165
17368
|
const name = map2[lhs.name];
|
|
@@ -17169,12 +17372,12 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17169
17372
|
}
|
|
17170
17373
|
}
|
|
17171
17374
|
} else if (lhs.type === "MemberExpression") {
|
|
17172
|
-
const object =
|
|
17375
|
+
const object = this.traverse(lhs.object);
|
|
17173
17376
|
if (object) {
|
|
17174
17377
|
lhs.object = object;
|
|
17175
17378
|
}
|
|
17176
17379
|
if (!isLookupCandidate(lhs)) {
|
|
17177
|
-
const property =
|
|
17380
|
+
const property = this.traverse(lhs.property);
|
|
17178
17381
|
if (property) {
|
|
17179
17382
|
lhs.property = property;
|
|
17180
17383
|
}
|
|
@@ -17183,9 +17386,9 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17183
17386
|
return node.type === "AssignmentExpression" ? ["right"] : [];
|
|
17184
17387
|
}
|
|
17185
17388
|
case "BlockStatement": {
|
|
17186
|
-
const map2 = topLocals().map;
|
|
17389
|
+
const map2 = topLocals(this).map;
|
|
17187
17390
|
if (map2) {
|
|
17188
|
-
|
|
17391
|
+
this.localsStack.push({
|
|
17189
17392
|
node,
|
|
17190
17393
|
map: { ...map2 }
|
|
17191
17394
|
});
|
|
@@ -17195,34 +17398,34 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17195
17398
|
case "FunctionDeclaration": {
|
|
17196
17399
|
const map2 = {};
|
|
17197
17400
|
node.params && node.params.forEach((p) => map2[variableDeclarationName(p)] = true);
|
|
17198
|
-
|
|
17199
|
-
const [{ sn: parent }, { sn: self }] =
|
|
17200
|
-
if (
|
|
17401
|
+
this.localsStack.push({ node, map: map2 });
|
|
17402
|
+
const [{ sn: parent }, { sn: self }] = this.stack.slice(-2);
|
|
17403
|
+
if (this.currentFunction) {
|
|
17201
17404
|
throw new Error(
|
|
17202
|
-
`Nested functions: ${self.fullName} was activated during processing of ${
|
|
17405
|
+
`Nested functions: ${self.fullName} was activated during processing of ${this.currentFunction.fullName}`
|
|
17203
17406
|
);
|
|
17204
17407
|
}
|
|
17205
|
-
|
|
17206
|
-
const is = !
|
|
17408
|
+
this.currentFunction = self;
|
|
17409
|
+
const is = !this.config?.propagateTypes || node.attrs?.attributes?.elements.find(
|
|
17207
17410
|
(attr) => attr.type === "UnaryExpression" && attr.argument.name === "noConstProp"
|
|
17208
|
-
) ? null : buildTypeInfo(
|
|
17411
|
+
) ? null : buildTypeInfo(this, this.currentFunction, true);
|
|
17209
17412
|
if (is) {
|
|
17210
|
-
is.state =
|
|
17211
|
-
if (
|
|
17413
|
+
is.state = this;
|
|
17414
|
+
if (this.config?.checkTypes !== "OFF" && this.config?.trustDeclaredTypes) {
|
|
17212
17415
|
is.typeChecker = gistate.typeChecker;
|
|
17213
|
-
is.checkTypes =
|
|
17416
|
+
is.checkTypes = this.config?.checkTypes || "WARNING";
|
|
17214
17417
|
}
|
|
17215
17418
|
istate = is;
|
|
17216
17419
|
}
|
|
17217
|
-
if (parent.type === "ClassDeclaration" && !maybeCalled(
|
|
17420
|
+
if (parent.type === "ClassDeclaration" && !maybeCalled(this, node)) {
|
|
17218
17421
|
let used = false;
|
|
17219
17422
|
if (node.id.name === "initialize") {
|
|
17220
17423
|
used = true;
|
|
17221
17424
|
} else if (parent.superClass) {
|
|
17222
|
-
used = checkInherited(parent, node.id.name);
|
|
17425
|
+
used = checkInherited(this, parent, node.id.name);
|
|
17223
17426
|
}
|
|
17224
17427
|
if (used) {
|
|
17225
|
-
markFunctionCalled(
|
|
17428
|
+
markFunctionCalled(this, node);
|
|
17226
17429
|
}
|
|
17227
17430
|
}
|
|
17228
17431
|
return ["body"];
|
|
@@ -17233,10 +17436,10 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17233
17436
|
}
|
|
17234
17437
|
return ret;
|
|
17235
17438
|
};
|
|
17236
|
-
state.post = (node)
|
|
17237
|
-
const locals = topLocals();
|
|
17439
|
+
state.post = function(node) {
|
|
17440
|
+
const locals = topLocals(this);
|
|
17238
17441
|
if (locals.node === node) {
|
|
17239
|
-
|
|
17442
|
+
this.localsStack.pop();
|
|
17240
17443
|
}
|
|
17241
17444
|
const opt = optimizeNode(istate, node);
|
|
17242
17445
|
if (opt != null) {
|
|
@@ -17247,28 +17450,28 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17247
17450
|
if (node.body && evaluateFunction(istate, node, null) !== false) {
|
|
17248
17451
|
node.optimizable = true;
|
|
17249
17452
|
}
|
|
17250
|
-
if (!
|
|
17453
|
+
if (!this.currentFunction) {
|
|
17251
17454
|
throw new Error(
|
|
17252
|
-
`Finished function ${
|
|
17455
|
+
`Finished function ${this.top().sn.fullName}, but it was not marked current`
|
|
17253
17456
|
);
|
|
17254
17457
|
}
|
|
17255
|
-
|
|
17256
|
-
delete
|
|
17257
|
-
delete
|
|
17458
|
+
this.currentFunction.info = this.currentFunction.next_info || false;
|
|
17459
|
+
delete this.currentFunction.next_info;
|
|
17460
|
+
delete this.currentFunction;
|
|
17258
17461
|
if (istate.stack.length) {
|
|
17259
17462
|
throw new Error("Stack was not empty");
|
|
17260
17463
|
}
|
|
17261
17464
|
istate = gistate;
|
|
17262
17465
|
if (again) {
|
|
17263
17466
|
again = false;
|
|
17264
|
-
const top =
|
|
17265
|
-
|
|
17266
|
-
|
|
17467
|
+
const top = this.stack.pop();
|
|
17468
|
+
this.traverse(node);
|
|
17469
|
+
this.stack.push(top);
|
|
17267
17470
|
}
|
|
17268
17471
|
break;
|
|
17269
17472
|
case "BlockStatement":
|
|
17270
17473
|
case "ForStatement":
|
|
17271
|
-
if (locals.map && cleanupUnusedVars(
|
|
17474
|
+
if (locals.map && cleanupUnusedVars(this, node) && !this.inlining) {
|
|
17272
17475
|
again = true;
|
|
17273
17476
|
}
|
|
17274
17477
|
break;
|
|
@@ -17285,29 +17488,26 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17285
17488
|
}
|
|
17286
17489
|
break;
|
|
17287
17490
|
case "Identifier":
|
|
17288
|
-
if ((0, import_chunk_JDC43A3I.hasProperty)(
|
|
17289
|
-
|
|
17491
|
+
if ((0, import_chunk_JDC43A3I.hasProperty)(this.index, node.name)) {
|
|
17492
|
+
this.usedByName[node.name] = true;
|
|
17290
17493
|
}
|
|
17291
17494
|
break;
|
|
17292
17495
|
case "MemberExpression": {
|
|
17293
17496
|
const property = isLookupCandidate(node);
|
|
17294
17497
|
if (property) {
|
|
17295
|
-
if ((0, import_chunk_JDC43A3I.hasProperty)(
|
|
17296
|
-
|
|
17498
|
+
if ((0, import_chunk_JDC43A3I.hasProperty)(this.index, property.name)) {
|
|
17499
|
+
this.usedByName[property.name] = true;
|
|
17297
17500
|
}
|
|
17298
17501
|
}
|
|
17299
17502
|
break;
|
|
17300
17503
|
}
|
|
17301
17504
|
case "NewExpression":
|
|
17302
|
-
if (
|
|
17303
|
-
const [, results] =
|
|
17505
|
+
if (this.currentFunction) {
|
|
17506
|
+
const [, results] = this.lookup(node.callee);
|
|
17304
17507
|
if (results) {
|
|
17305
|
-
recordCalledFuncs(
|
|
17306
|
-
state.currentFunction,
|
|
17307
|
-
findCalleesForNew(results)
|
|
17308
|
-
);
|
|
17508
|
+
recordCalledFuncs(this.currentFunction, findCalleesForNew(results));
|
|
17309
17509
|
} else {
|
|
17310
|
-
recordModifiedUnknown(
|
|
17510
|
+
recordModifiedUnknown(this.currentFunction);
|
|
17311
17511
|
}
|
|
17312
17512
|
}
|
|
17313
17513
|
break;
|
|
@@ -17315,11 +17515,11 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17315
17515
|
return optimizeCallHelper(istate, node, null);
|
|
17316
17516
|
}
|
|
17317
17517
|
case "VariableDeclaration": {
|
|
17318
|
-
const locals2 = topLocals();
|
|
17518
|
+
const locals2 = topLocals(this);
|
|
17319
17519
|
if (!locals2.map) {
|
|
17320
17520
|
if (again) {
|
|
17321
17521
|
again = false;
|
|
17322
|
-
|
|
17522
|
+
this.traverse(node);
|
|
17323
17523
|
}
|
|
17324
17524
|
break;
|
|
17325
17525
|
}
|
|
@@ -17378,12 +17578,12 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17378
17578
|
if (call) {
|
|
17379
17579
|
let ok = false;
|
|
17380
17580
|
if (node.expression.left.type === "Identifier") {
|
|
17381
|
-
if ((0, import_chunk_JDC43A3I.hasProperty)(topLocals().map, node.expression.left.type)) {
|
|
17581
|
+
if ((0, import_chunk_JDC43A3I.hasProperty)(topLocals(this).map, node.expression.left.type)) {
|
|
17382
17582
|
ok = true;
|
|
17383
17583
|
}
|
|
17384
17584
|
}
|
|
17385
17585
|
if (!ok && node.expression.operator === "=") {
|
|
17386
|
-
const [, result] =
|
|
17586
|
+
const [, result] = this.lookup(node.expression.left);
|
|
17387
17587
|
ok = !!result;
|
|
17388
17588
|
}
|
|
17389
17589
|
if (ok) {
|
|
@@ -17391,7 +17591,7 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17391
17591
|
}
|
|
17392
17592
|
}
|
|
17393
17593
|
} else {
|
|
17394
|
-
return unused(
|
|
17594
|
+
return unused(this, node.expression, true);
|
|
17395
17595
|
}
|
|
17396
17596
|
break;
|
|
17397
17597
|
case "UpdateExpression": {
|
|
@@ -17406,17 +17606,17 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17406
17606
|
delete n.prefix;
|
|
17407
17607
|
}
|
|
17408
17608
|
case "AssignmentExpression":
|
|
17409
|
-
if (
|
|
17609
|
+
if (this.currentFunction) {
|
|
17410
17610
|
const lhs = node.type === "AssignmentExpression" ? node.left : node.argument;
|
|
17411
|
-
const [, results] =
|
|
17611
|
+
const [, results] = this.lookup(lhs);
|
|
17412
17612
|
if (results) {
|
|
17413
|
-
recordModifiedDecls(
|
|
17613
|
+
recordModifiedDecls(this.currentFunction, results);
|
|
17414
17614
|
} else {
|
|
17415
17615
|
const id = lhs.type === "Identifier" ? lhs : isLookupCandidate(lhs);
|
|
17416
17616
|
if (id) {
|
|
17417
|
-
recordModifiedName(
|
|
17617
|
+
recordModifiedName(this.currentFunction, id.name);
|
|
17418
17618
|
} else {
|
|
17419
|
-
recordModifiedUnknown(
|
|
17619
|
+
recordModifiedUnknown(this.currentFunction);
|
|
17420
17620
|
}
|
|
17421
17621
|
}
|
|
17422
17622
|
}
|
|
@@ -17433,22 +17633,22 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17433
17633
|
Changes2[Changes2["Some"] = 1] = "Some";
|
|
17434
17634
|
Changes2[Changes2["Force"] = 2] = "Force";
|
|
17435
17635
|
})(Changes || (Changes = {}));
|
|
17436
|
-
const cleanupAll = () => {
|
|
17437
|
-
const usedDecls = findRezRefs(
|
|
17438
|
-
const pre =
|
|
17439
|
-
const post =
|
|
17636
|
+
const cleanupAll = (state2) => {
|
|
17637
|
+
const usedDecls = findRezRefs(state2);
|
|
17638
|
+
const pre = state2.pre;
|
|
17639
|
+
const post = state2.post;
|
|
17440
17640
|
try {
|
|
17441
|
-
delete
|
|
17641
|
+
delete state2.pre;
|
|
17442
17642
|
return Object.values(fnMap).reduce(
|
|
17443
17643
|
(changes, f) => {
|
|
17444
|
-
|
|
17644
|
+
state2.post = function(node) {
|
|
17445
17645
|
if (usedDecls.has(node)) {
|
|
17446
17646
|
return null;
|
|
17447
17647
|
}
|
|
17448
|
-
const ret = cleanup(
|
|
17648
|
+
const ret = cleanup(this, node, f.ast, usedDecls);
|
|
17449
17649
|
if (ret === false) {
|
|
17450
17650
|
changes |= 1;
|
|
17451
|
-
|
|
17651
|
+
this.removeNodeComments(node, f.ast);
|
|
17452
17652
|
} else if (ret) {
|
|
17453
17653
|
if (node.type === "EnumDeclaration" && ret.type === "TypedefDeclaration" && ret.ts.argument.ts.length > 1) {
|
|
17454
17654
|
changes |= 2;
|
|
@@ -17458,15 +17658,15 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17458
17658
|
}
|
|
17459
17659
|
return ret;
|
|
17460
17660
|
};
|
|
17461
|
-
collectNamespaces(f.ast,
|
|
17661
|
+
collectNamespaces(f.ast, state2);
|
|
17462
17662
|
return changes;
|
|
17463
17663
|
},
|
|
17464
17664
|
0
|
|
17465
17665
|
/* None */
|
|
17466
17666
|
);
|
|
17467
17667
|
} finally {
|
|
17468
|
-
|
|
17469
|
-
|
|
17668
|
+
state2.pre = pre;
|
|
17669
|
+
state2.post = post;
|
|
17470
17670
|
}
|
|
17471
17671
|
};
|
|
17472
17672
|
while (true) {
|
|
@@ -17479,7 +17679,7 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17479
17679
|
});
|
|
17480
17680
|
state.exposed = state.nextExposed;
|
|
17481
17681
|
state.nextExposed = {};
|
|
17482
|
-
const changes = cleanupAll();
|
|
17682
|
+
const changes = cleanupAll(state);
|
|
17483
17683
|
if (changes & 2 || changes & 1 && state.config?.iterateOptimizer) {
|
|
17484
17684
|
continue;
|
|
17485
17685
|
}
|
|
@@ -17499,7 +17699,7 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
|
|
|
17499
17699
|
),
|
|
17500
17700
|
Promise.resolve()
|
|
17501
17701
|
);
|
|
17502
|
-
cleanupAll();
|
|
17702
|
+
cleanupAll(state);
|
|
17503
17703
|
config.checkCompilerLookupRules = checkLookupRules;
|
|
17504
17704
|
reportMissingSymbols(state, config);
|
|
17505
17705
|
Object.values(fnMap).forEach(
|
|
@@ -17760,7 +17960,7 @@ var init_mc_rewrite = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
17760
17960
|
init_sub_type();
|
|
17761
17961
|
init_types();
|
|
17762
17962
|
init_unused_exprs();
|
|
17763
|
-
(0,
|
|
17963
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
17764
17964
|
init_variable_renamer();
|
|
17765
17965
|
}
|
|
17766
17966
|
});
|
|
@@ -18211,10 +18411,10 @@ function add_one_resource(state, doc, module2, e, barrelNames) {
|
|
|
18211
18411
|
{
|
|
18212
18412
|
type: "VariableDeclarator",
|
|
18213
18413
|
kind: "var",
|
|
18214
|
-
id: {
|
|
18414
|
+
id: id2 && !init ? {
|
|
18215
18415
|
type: "BinaryExpression",
|
|
18216
18416
|
operator: "as",
|
|
18217
|
-
left: (0, import_chunk_JDC43A3I.makeIdentifier)(id2
|
|
18417
|
+
left: (0, import_chunk_JDC43A3I.makeIdentifier)(id2.value.value, loc),
|
|
18218
18418
|
right: {
|
|
18219
18419
|
type: "TypeSpecList",
|
|
18220
18420
|
ts: [
|
|
@@ -18226,7 +18426,7 @@ function add_one_resource(state, doc, module2, e, barrelNames) {
|
|
|
18226
18426
|
}
|
|
18227
18427
|
]
|
|
18228
18428
|
}
|
|
18229
|
-
},
|
|
18429
|
+
} : (0, import_chunk_JDC43A3I.makeIdentifier)(id2 ? id2.value.value : "*invalid*", loc),
|
|
18230
18430
|
init
|
|
18231
18431
|
},
|
|
18232
18432
|
outer
|
|
@@ -18466,7 +18666,7 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
|
|
|
18466
18666
|
};
|
|
18467
18667
|
const { pre, post } = state;
|
|
18468
18668
|
try {
|
|
18469
|
-
state.pre = (node)
|
|
18669
|
+
state.pre = function(node) {
|
|
18470
18670
|
if (filter && !filter(node))
|
|
18471
18671
|
return [];
|
|
18472
18672
|
switch (node.type) {
|
|
@@ -18491,7 +18691,7 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
|
|
|
18491
18691
|
);
|
|
18492
18692
|
}
|
|
18493
18693
|
}
|
|
18494
|
-
} else if (
|
|
18694
|
+
} else if (this.inType && node.operator === "as") {
|
|
18495
18695
|
return ["right"];
|
|
18496
18696
|
}
|
|
18497
18697
|
break;
|
|
@@ -18519,13 +18719,13 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
|
|
|
18519
18719
|
break;
|
|
18520
18720
|
}
|
|
18521
18721
|
case "MethodDefinition": {
|
|
18522
|
-
if (!
|
|
18722
|
+
if (!this.inType) {
|
|
18523
18723
|
throw new Error("Method definition outside of type!");
|
|
18524
18724
|
}
|
|
18525
18725
|
if (node.params) {
|
|
18526
18726
|
node.params.forEach((param) => {
|
|
18527
18727
|
if (param.type === "BinaryExpression") {
|
|
18528
|
-
|
|
18728
|
+
this.traverse(param.right);
|
|
18529
18729
|
}
|
|
18530
18730
|
});
|
|
18531
18731
|
}
|
|
@@ -18556,7 +18756,7 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
|
|
|
18556
18756
|
visitDef(node.id, node);
|
|
18557
18757
|
}
|
|
18558
18758
|
if (node.id.type === "BinaryExpression") {
|
|
18559
|
-
|
|
18759
|
+
this.traverse(node.id.right);
|
|
18560
18760
|
}
|
|
18561
18761
|
return ["init"];
|
|
18562
18762
|
case "EnumDeclaration":
|
|
@@ -18570,7 +18770,7 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
|
|
|
18570
18770
|
case "EnumStringMember": {
|
|
18571
18771
|
if (!filter || filter(node.id)) {
|
|
18572
18772
|
checkResults(
|
|
18573
|
-
[node.id.name, [{ parent:
|
|
18773
|
+
[node.id.name, [{ parent: this.top().sn, results: [node] }]],
|
|
18574
18774
|
node
|
|
18575
18775
|
);
|
|
18576
18776
|
}
|
|
@@ -18580,7 +18780,7 @@ function visitReferences(state, ast, name, defn, callback, includeDefs = false,
|
|
|
18580
18780
|
if (includeDefs)
|
|
18581
18781
|
break;
|
|
18582
18782
|
if (node.param && node.param.type !== "Identifier") {
|
|
18583
|
-
|
|
18783
|
+
this.traverse(node.param.right);
|
|
18584
18784
|
}
|
|
18585
18785
|
return ["body"];
|
|
18586
18786
|
}
|
|
@@ -18627,6 +18827,28 @@ function checkCompilerVersion(version, sdkVer) {
|
|
|
18627
18827
|
}
|
|
18628
18828
|
return sdkVer <= v2;
|
|
18629
18829
|
}
|
|
18830
|
+
function pushRootNode(stack, root) {
|
|
18831
|
+
if (root.type === "Program")
|
|
18832
|
+
return;
|
|
18833
|
+
const sn = root.stack?.at(-1)?.sn?.decls?.[root.name]?.find(
|
|
18834
|
+
(sn2) => sn2.type === root.type && (root.nodes != null || sn2.node === root.node)
|
|
18835
|
+
);
|
|
18836
|
+
if (!sn) {
|
|
18837
|
+
throw new Error(`Invalid stack for node ${root.fullName}`);
|
|
18838
|
+
}
|
|
18839
|
+
if (root.nodes) {
|
|
18840
|
+
sn.node = root.node;
|
|
18841
|
+
}
|
|
18842
|
+
stack.push({ sn });
|
|
18843
|
+
}
|
|
18844
|
+
function popRootNode(stack, root) {
|
|
18845
|
+
if (root.type === "Program")
|
|
18846
|
+
return;
|
|
18847
|
+
if (stack.at(-1)?.sn.node !== root.node) {
|
|
18848
|
+
throw new Error(`Invalid stack for node ${root.fullName}`);
|
|
18849
|
+
}
|
|
18850
|
+
stack.pop();
|
|
18851
|
+
}
|
|
18630
18852
|
async function getApiMapping(state, resourcesMap, manifestXML) {
|
|
18631
18853
|
const parser = import_prettier_plugin_monkeyc4.default.parsers.monkeyc;
|
|
18632
18854
|
const sdk = await getSdkPath();
|
|
@@ -18670,7 +18892,7 @@ async function getApiMapping(state, resourcesMap, manifestXML) {
|
|
|
18670
18892
|
throw `Negative constant ${fixup} was not a Literal`;
|
|
18671
18893
|
}
|
|
18672
18894
|
if (typeof init.value !== "number") {
|
|
18673
|
-
(0,
|
|
18895
|
+
(0, import_chunk_NHZRKHZO.log)(`Negative fixup ${fixup} was not a number!`);
|
|
18674
18896
|
} else if (init.value > 0) {
|
|
18675
18897
|
init.value = -init.value;
|
|
18676
18898
|
init.raw = "-" + init.raw;
|
|
@@ -18760,11 +18982,11 @@ function sameStateNodeDecl(a, b) {
|
|
|
18760
18982
|
function sameLookupDefinition(a, b) {
|
|
18761
18983
|
return (
|
|
18762
18984
|
// sameStateNodeDecl(a.parent, b.parent) &&
|
|
18763
|
-
(0,
|
|
18985
|
+
(0, import_chunk_NHZRKHZO.sameArrays)(a.results, b.results, (ar, br) => sameStateNodeDecl(ar, br))
|
|
18764
18986
|
);
|
|
18765
18987
|
}
|
|
18766
18988
|
function sameLookupResult(a, b) {
|
|
18767
|
-
return (0,
|
|
18989
|
+
return (0, import_chunk_NHZRKHZO.sameArrays)(a, b, sameLookupDefinition);
|
|
18768
18990
|
}
|
|
18769
18991
|
function declKey(decl) {
|
|
18770
18992
|
return isStateNode(decl) ? decl.type === "ModuleDeclaration" ? decl.fullName : decl.node : decl;
|
|
@@ -18967,7 +19189,7 @@ function lookup(state, decls, node, name, maybeStack, nonlocal, ignoreImports) {
|
|
|
18967
19189
|
diagnostic(
|
|
18968
19190
|
state,
|
|
18969
19191
|
node,
|
|
18970
|
-
|
|
19192
|
+
formatAstLongLines(node).then(
|
|
18971
19193
|
(nodeStr) => `${nodeStr} is ambiguous and exists in multiple imported modules [${imp.map(({ name: name2 }) => name2).join(", ")}]`
|
|
18972
19194
|
),
|
|
18973
19195
|
state.config?.checkInvalidSymbols || "WARNING"
|
|
@@ -18983,7 +19205,7 @@ function lookup(state, decls, node, name, maybeStack, nonlocal, ignoreImports) {
|
|
|
18983
19205
|
diagnostic(
|
|
18984
19206
|
state,
|
|
18985
19207
|
node,
|
|
18986
|
-
|
|
19208
|
+
formatAstLongLines(node).then(
|
|
18987
19209
|
(nodeStr) => `${nodeStr} will only be found when compiled with compiler2 at -O1 or above`
|
|
18988
19210
|
),
|
|
18989
19211
|
state.config?.checkCompilerLookupRules || "WARNING",
|
|
@@ -19059,6 +19281,27 @@ function lookupWithType(state, node, typeMap, nonLocal = false, stack = null) {
|
|
|
19059
19281
|
}
|
|
19060
19282
|
return results;
|
|
19061
19283
|
}
|
|
19284
|
+
function handleImportUsing(state, node) {
|
|
19285
|
+
const parent = { ...state.stack.pop() };
|
|
19286
|
+
state.stack.push(parent);
|
|
19287
|
+
parent.usings = parent.usings ? { ...parent.usings } : {};
|
|
19288
|
+
const name = node.type === "Using" && node.as && node.as.name || (node.id.type === "Identifier" ? node.id.name : node.id.property.name);
|
|
19289
|
+
const using = { node };
|
|
19290
|
+
parent.usings[name] = using;
|
|
19291
|
+
if (node.type === "ImportModule") {
|
|
19292
|
+
if (!parent.imports) {
|
|
19293
|
+
parent.imports = [using];
|
|
19294
|
+
} else {
|
|
19295
|
+
parent.imports = parent.imports.slice();
|
|
19296
|
+
const index = parent.imports.findIndex(
|
|
19297
|
+
(using2) => (using2.node.id.type === "Identifier" ? using2.node.id.name : using2.node.id.property.name) === name
|
|
19298
|
+
);
|
|
19299
|
+
if (index >= 0)
|
|
19300
|
+
parent.imports.splice(index, 1);
|
|
19301
|
+
parent.imports.push(using);
|
|
19302
|
+
}
|
|
19303
|
+
}
|
|
19304
|
+
}
|
|
19062
19305
|
function stateFuncs() {
|
|
19063
19306
|
let currentEnum = null;
|
|
19064
19307
|
return {
|
|
@@ -19116,7 +19359,7 @@ function stateFuncs() {
|
|
|
19116
19359
|
switch (node.type) {
|
|
19117
19360
|
case "MemberExpression": {
|
|
19118
19361
|
if (isLookupCandidate(node)) {
|
|
19119
|
-
return (this.pre && this.pre(node
|
|
19362
|
+
return (this.pre && this.pre(node)) ?? ["object"];
|
|
19120
19363
|
}
|
|
19121
19364
|
break;
|
|
19122
19365
|
}
|
|
@@ -19132,6 +19375,9 @@ function stateFuncs() {
|
|
|
19132
19375
|
throw new Error("Unexpected stack length for Program node");
|
|
19133
19376
|
}
|
|
19134
19377
|
this.stack[0].sn.node = node;
|
|
19378
|
+
if (this.rezAst !== node && !this.stack[0].sn.nodes?.has(node) && node.loc?.source !== "api.mir") {
|
|
19379
|
+
this.stack[0].sn.nodes?.set(node, this.stackClone());
|
|
19380
|
+
}
|
|
19135
19381
|
break;
|
|
19136
19382
|
case "TypeSpecList":
|
|
19137
19383
|
case "TypeSpecPart":
|
|
@@ -19139,25 +19385,7 @@ function stateFuncs() {
|
|
|
19139
19385
|
break;
|
|
19140
19386
|
case "ImportModule":
|
|
19141
19387
|
case "Using": {
|
|
19142
|
-
|
|
19143
|
-
this.stack.push(parent);
|
|
19144
|
-
parent.usings = parent.usings ? { ...parent.usings } : {};
|
|
19145
|
-
const name = node.type === "Using" && node.as && node.as.name || (node.id.type === "Identifier" ? node.id.name : node.id.property.name);
|
|
19146
|
-
const using = { node };
|
|
19147
|
-
parent.usings[name] = using;
|
|
19148
|
-
if (node.type === "ImportModule") {
|
|
19149
|
-
if (!parent.imports) {
|
|
19150
|
-
parent.imports = [using];
|
|
19151
|
-
} else {
|
|
19152
|
-
parent.imports = parent.imports.slice();
|
|
19153
|
-
const index = parent.imports.findIndex(
|
|
19154
|
-
(using2) => (using2.node.id.type === "Identifier" ? using2.node.id.name : using2.node.id.property.name) === name
|
|
19155
|
-
);
|
|
19156
|
-
if (index >= 0)
|
|
19157
|
-
parent.imports.splice(index, 1);
|
|
19158
|
-
parent.imports.push(using);
|
|
19159
|
-
}
|
|
19160
|
-
}
|
|
19388
|
+
handleImportUsing(this, node);
|
|
19161
19389
|
break;
|
|
19162
19390
|
}
|
|
19163
19391
|
case "CatchClause":
|
|
@@ -19217,9 +19445,21 @@ function stateFuncs() {
|
|
|
19217
19445
|
if (!parent.decls)
|
|
19218
19446
|
parent.decls = {};
|
|
19219
19447
|
if ((0, import_chunk_JDC43A3I.hasProperty)(parent.decls, name)) {
|
|
19220
|
-
|
|
19448
|
+
if (node.type === "ModuleDeclaration") {
|
|
19449
|
+
const e2 = parent.decls[name].find(
|
|
19450
|
+
(d) => isStateNode(d) && d.type === "ModuleDeclaration"
|
|
19451
|
+
);
|
|
19452
|
+
if (e2 != null) {
|
|
19453
|
+
e2.node = node;
|
|
19454
|
+
if (!e2.nodes.has(node) && node.loc?.source && /\.mc$/.test(node.loc?.source)) {
|
|
19455
|
+
e2.nodes.set(node, this.stackClone().slice(0, -1));
|
|
19456
|
+
}
|
|
19457
|
+
this.top().sn = e2;
|
|
19458
|
+
break;
|
|
19459
|
+
}
|
|
19460
|
+
}
|
|
19221
19461
|
const e = parent.decls[name].find(
|
|
19222
|
-
(d) => isStateNode(d) && d
|
|
19462
|
+
(d) => isStateNode(d) && d.node === elm.node
|
|
19223
19463
|
);
|
|
19224
19464
|
if (e != null) {
|
|
19225
19465
|
e.node = node;
|
|
@@ -19243,6 +19483,15 @@ function stateFuncs() {
|
|
|
19243
19483
|
parent.type_decls[name] = [];
|
|
19244
19484
|
}
|
|
19245
19485
|
parent.type_decls[name].push(elm);
|
|
19486
|
+
if (elm.type === "ModuleDeclaration") {
|
|
19487
|
+
elm.nodes = /* @__PURE__ */ new Map();
|
|
19488
|
+
if (node.loc?.source !== "api.mir") {
|
|
19489
|
+
elm.nodes.set(
|
|
19490
|
+
node,
|
|
19491
|
+
this.stackClone().slice(0, -1)
|
|
19492
|
+
);
|
|
19493
|
+
}
|
|
19494
|
+
}
|
|
19246
19495
|
}
|
|
19247
19496
|
break;
|
|
19248
19497
|
}
|
|
@@ -19317,7 +19566,7 @@ function stateFuncs() {
|
|
|
19317
19566
|
if (!(0, import_chunk_JDC43A3I.hasProperty)(this.index, name)) {
|
|
19318
19567
|
this.index[name] = [];
|
|
19319
19568
|
}
|
|
19320
|
-
(0,
|
|
19569
|
+
(0, import_chunk_NHZRKHZO.pushUnique)(this.index[name], parent);
|
|
19321
19570
|
}
|
|
19322
19571
|
});
|
|
19323
19572
|
break;
|
|
@@ -19372,7 +19621,7 @@ function stateFuncs() {
|
|
|
19372
19621
|
if (!(0, import_chunk_JDC43A3I.hasProperty)(values, name)) {
|
|
19373
19622
|
values[name] = [];
|
|
19374
19623
|
}
|
|
19375
|
-
if ((0,
|
|
19624
|
+
if ((0, import_chunk_NHZRKHZO.pushUnique)(values[name], m) && currentEnum) {
|
|
19376
19625
|
if (!this.enumMap)
|
|
19377
19626
|
this.enumMap = /* @__PURE__ */ new Map();
|
|
19378
19627
|
this.enumMap.set(m, currentEnum);
|
|
@@ -19380,13 +19629,13 @@ function stateFuncs() {
|
|
|
19380
19629
|
if (!(0, import_chunk_JDC43A3I.hasProperty)(this.index, name)) {
|
|
19381
19630
|
this.index[name] = [];
|
|
19382
19631
|
}
|
|
19383
|
-
(0,
|
|
19632
|
+
(0, import_chunk_NHZRKHZO.pushUnique)(this.index[name], parent);
|
|
19384
19633
|
});
|
|
19385
19634
|
break;
|
|
19386
19635
|
}
|
|
19387
19636
|
}
|
|
19388
19637
|
if (this.pre)
|
|
19389
|
-
return this.pre(node
|
|
19638
|
+
return this.pre(node);
|
|
19390
19639
|
} catch (e) {
|
|
19391
19640
|
handleException(this, node, e);
|
|
19392
19641
|
}
|
|
@@ -19400,7 +19649,7 @@ function stateFuncs() {
|
|
|
19400
19649
|
} else {
|
|
19401
19650
|
const type = node.type;
|
|
19402
19651
|
if (this.post)
|
|
19403
|
-
ret = this.post(node
|
|
19652
|
+
ret = this.post(node);
|
|
19404
19653
|
switch (type) {
|
|
19405
19654
|
case "EnumDeclaration":
|
|
19406
19655
|
currentEnum = null;
|
|
@@ -19455,11 +19704,13 @@ function collectNamespaces(ast, stateIn) {
|
|
|
19455
19704
|
name: "$",
|
|
19456
19705
|
fullName: "$",
|
|
19457
19706
|
node: void 0,
|
|
19707
|
+
nodes: /* @__PURE__ */ new Map(),
|
|
19458
19708
|
attributes: 0
|
|
19459
19709
|
/* NONE */
|
|
19460
19710
|
}
|
|
19461
19711
|
}
|
|
19462
19712
|
];
|
|
19713
|
+
state.stack[0].sn.stack = [state.stack[0]];
|
|
19463
19714
|
}
|
|
19464
19715
|
if (!state.lookupRules) {
|
|
19465
19716
|
const rules = state?.config?.compilerLookupRules || "DEFAULT";
|
|
@@ -19472,7 +19723,11 @@ function collectNamespaces(ast, stateIn) {
|
|
|
19472
19723
|
}
|
|
19473
19724
|
}
|
|
19474
19725
|
}
|
|
19475
|
-
|
|
19726
|
+
if (!state.traverse) {
|
|
19727
|
+
state.diagnostics = {};
|
|
19728
|
+
state.inlineDiagnostics = {};
|
|
19729
|
+
Object.assign(state, stateFuncs());
|
|
19730
|
+
}
|
|
19476
19731
|
state.inType = 0;
|
|
19477
19732
|
state.traverse(ast);
|
|
19478
19733
|
if (state.inType) {
|
|
@@ -19509,6 +19764,7 @@ function formatAst(node, monkeyCSource = null, options = null) {
|
|
|
19509
19764
|
...options || {},
|
|
19510
19765
|
parser: "monkeyc-json",
|
|
19511
19766
|
plugins: [import_prettier_plugin_monkeyc4.default],
|
|
19767
|
+
pluginSearchDirs: false,
|
|
19512
19768
|
endOfLine: "lf"
|
|
19513
19769
|
})
|
|
19514
19770
|
);
|
|
@@ -19570,6 +19826,23 @@ function formatScopedName(node) {
|
|
|
19570
19826
|
return `${formatScopedName(node.object)}.${node.property.name}`;
|
|
19571
19827
|
}
|
|
19572
19828
|
function formatAstLongLines(node) {
|
|
19829
|
+
const filter = (s) => s.type !== "ClassDeclaration" && s.type !== "ModuleDeclaration" && s.type !== "FunctionDeclaration";
|
|
19830
|
+
switch (node.type) {
|
|
19831
|
+
case "ClassDeclaration":
|
|
19832
|
+
node = { ...node };
|
|
19833
|
+
node.body = { ...node.body };
|
|
19834
|
+
node.body.body = node.body.body.filter((c) => filter(c.item));
|
|
19835
|
+
break;
|
|
19836
|
+
case "ModuleDeclaration":
|
|
19837
|
+
node = { ...node };
|
|
19838
|
+
node.body = { ...node.body };
|
|
19839
|
+
node.body.body = node.body.body.filter(filter);
|
|
19840
|
+
break;
|
|
19841
|
+
case "Program":
|
|
19842
|
+
node = { ...node };
|
|
19843
|
+
node.body = node.body.filter(filter);
|
|
19844
|
+
break;
|
|
19845
|
+
}
|
|
19573
19846
|
return formatAst(node, null, { printWidth: 1e4 });
|
|
19574
19847
|
}
|
|
19575
19848
|
async function createDocumentationMap(functionDocumentation) {
|
|
@@ -19712,7 +19985,7 @@ function findUsing(state, stack, using) {
|
|
|
19712
19985
|
diagnostic(
|
|
19713
19986
|
state,
|
|
19714
19987
|
using.node.id,
|
|
19715
|
-
|
|
19988
|
+
formatAstLongLines(using.node.id).then(
|
|
19716
19989
|
(nodeStr) => `Unable to resolve import of ${nodeStr}`
|
|
19717
19990
|
),
|
|
19718
19991
|
state.config?.checkInvalidSymbols || "WARNING"
|
|
@@ -19881,7 +20154,7 @@ var init_api = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
19881
20154
|
init_sdk_util();
|
|
19882
20155
|
init_type_flow_util();
|
|
19883
20156
|
init_types();
|
|
19884
|
-
(0,
|
|
20157
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
19885
20158
|
init_visitor();
|
|
19886
20159
|
}
|
|
19887
20160
|
});
|
|
@@ -19900,11 +20173,11 @@ async function declFullName(decl) {
|
|
|
19900
20173
|
case "BinaryExpression":
|
|
19901
20174
|
return decl.left.name;
|
|
19902
20175
|
case "EnumStringMember":
|
|
19903
|
-
return decl.init ? `${decl.id.name}:${await
|
|
20176
|
+
return decl.init ? `${decl.id.name}:${await formatAstLongLines(decl.init)}` : decl.id.name;
|
|
19904
20177
|
case "MemberDecl":
|
|
19905
20178
|
return `${await declFullName(decl.base)}->${decl.path.join(".")}`;
|
|
19906
20179
|
case "Unknown":
|
|
19907
|
-
return `Unknown:${await
|
|
20180
|
+
return `Unknown:${await formatAstLongLines(decl.node)}`;
|
|
19908
20181
|
default:
|
|
19909
20182
|
unhandledType(decl);
|
|
19910
20183
|
}
|
|
@@ -19935,7 +20208,7 @@ function unhandledType(node) {
|
|
|
19935
20208
|
`Unhandled expression type: ${node.type}`
|
|
19936
20209
|
);
|
|
19937
20210
|
}
|
|
19938
|
-
function buildDataFlowGraph(state,
|
|
20211
|
+
function buildDataFlowGraph(state, root, wantsLiteral, trackInsertionPoints, wantsAllRefs) {
|
|
19939
20212
|
const uniqueDeclMap = /* @__PURE__ */ new Map();
|
|
19940
20213
|
const lookupDefToDecl = (results) => {
|
|
19941
20214
|
const decls = results.reduce(
|
|
@@ -19965,7 +20238,7 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
|
|
|
19965
20238
|
return decls;
|
|
19966
20239
|
}
|
|
19967
20240
|
if (canon.length !== decls.length || !canon.every((v, i) => v === decls[i])) {
|
|
19968
|
-
throw new
|
|
20241
|
+
throw new import_chunk_NHZRKHZO.AwaitedError(
|
|
19969
20242
|
declFullName(canon).then(
|
|
19970
20243
|
(canonStr) => `Canonical representation of ${canonStr} did not match`
|
|
19971
20244
|
)
|
|
@@ -19999,7 +20272,7 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
|
|
|
19999
20272
|
}
|
|
20000
20273
|
const decl = lookupDefToDecl(results);
|
|
20001
20274
|
if (decl && path7.length) {
|
|
20002
|
-
if (wantsAllRefs && (0,
|
|
20275
|
+
if (wantsAllRefs && (0, import_chunk_NHZRKHZO.every)(
|
|
20003
20276
|
decl,
|
|
20004
20277
|
(d) => d.type === "VariableDeclarator" || d.type === "BinaryExpression" || d.type === "Identifier"
|
|
20005
20278
|
)) {
|
|
@@ -20035,7 +20308,7 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
|
|
|
20035
20308
|
identifiers,
|
|
20036
20309
|
graph: buildReducedGraph(
|
|
20037
20310
|
state,
|
|
20038
|
-
|
|
20311
|
+
root,
|
|
20039
20312
|
wantsAllRefs,
|
|
20040
20313
|
(node, stmt, mayThrow2, getContainedEvents) => {
|
|
20041
20314
|
if (mayThrow2 === 1) {
|
|
@@ -20051,7 +20324,7 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
|
|
|
20051
20324
|
}
|
|
20052
20325
|
const v = liveDefs.get(def);
|
|
20053
20326
|
if (!v || !v.has(node)) {
|
|
20054
|
-
throw new
|
|
20327
|
+
throw new import_chunk_NHZRKHZO.AwaitedError(
|
|
20055
20328
|
Promise.resolve(def ? declFullName(def) : "null").then(
|
|
20056
20329
|
(defStr) => `No stmt in liveDef for ${defStr}`
|
|
20057
20330
|
)
|
|
@@ -20065,7 +20338,7 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
|
|
|
20065
20338
|
}
|
|
20066
20339
|
if (wantsAllRefs) {
|
|
20067
20340
|
const scope = state.top().sn;
|
|
20068
|
-
if (scope.node === node && scope.type === "BlockStatement" && scope.decls && state.stack.length - 2 !==
|
|
20341
|
+
if (scope.node === node && scope.type === "BlockStatement" && scope.decls && state.stack.length - 2 !== root.stack?.length) {
|
|
20069
20342
|
return Object.values(scope.decls).map((value2) => {
|
|
20070
20343
|
const decl = lookupDefToDecl([
|
|
20071
20344
|
{ parent: null, results: value2 }
|
|
@@ -20075,6 +20348,20 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
|
|
|
20075
20348
|
}
|
|
20076
20349
|
}
|
|
20077
20350
|
switch (node.type) {
|
|
20351
|
+
case "ImportModule":
|
|
20352
|
+
case "Using":
|
|
20353
|
+
return { type: "imp", node, mayThrow: false };
|
|
20354
|
+
case "ModuleDeclaration":
|
|
20355
|
+
case "Program":
|
|
20356
|
+
if (root.node === node || root.nodes?.has(node)) {
|
|
20357
|
+
return {
|
|
20358
|
+
type: "imp",
|
|
20359
|
+
node,
|
|
20360
|
+
stack: state.stackClone(),
|
|
20361
|
+
mayThrow: false
|
|
20362
|
+
};
|
|
20363
|
+
}
|
|
20364
|
+
break;
|
|
20078
20365
|
case "BinaryExpression":
|
|
20079
20366
|
case "UnaryExpression":
|
|
20080
20367
|
case "SizedArrayExpression":
|
|
@@ -20109,7 +20396,7 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
|
|
|
20109
20396
|
const decls = findDecl(node);
|
|
20110
20397
|
if (!decls)
|
|
20111
20398
|
break;
|
|
20112
|
-
if (trackInsertionPoints && (0,
|
|
20399
|
+
if (trackInsertionPoints && (0, import_chunk_NHZRKHZO.some)(decls, (decl) => {
|
|
20113
20400
|
if (decl.type === "VariableDeclarator") {
|
|
20114
20401
|
const defStmts = decl.node.kind === "var" && liveDefs.get(null) || liveDefs.get(decl);
|
|
20115
20402
|
if (defStmts) {
|
|
@@ -20127,6 +20414,22 @@ function buildDataFlowGraph(state, func, wantsLiteral, trackInsertionPoints, wan
|
|
|
20127
20414
|
mayThrow: mayThrow2
|
|
20128
20415
|
};
|
|
20129
20416
|
}
|
|
20417
|
+
case "EnumStringMember": {
|
|
20418
|
+
if (node.init && node.init.type !== "Literal") {
|
|
20419
|
+
const decl = findDecl(node.id);
|
|
20420
|
+
if (decl) {
|
|
20421
|
+
liveDef(decl, stmt);
|
|
20422
|
+
const def = {
|
|
20423
|
+
type: "def",
|
|
20424
|
+
node,
|
|
20425
|
+
decl,
|
|
20426
|
+
mayThrow: mayThrow2
|
|
20427
|
+
};
|
|
20428
|
+
return def;
|
|
20429
|
+
}
|
|
20430
|
+
}
|
|
20431
|
+
break;
|
|
20432
|
+
}
|
|
20130
20433
|
case "VariableDeclarator": {
|
|
20131
20434
|
const decl = findDecl(
|
|
20132
20435
|
node.id.type === "BinaryExpression" ? node.id.left : node.id
|
|
@@ -20360,8 +20663,8 @@ var init_data_flow = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
20360
20663
|
init_control_flow();
|
|
20361
20664
|
init_function_info();
|
|
20362
20665
|
init_type_flow_util();
|
|
20363
|
-
(0,
|
|
20364
|
-
DataflowQueue = class extends
|
|
20666
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
20667
|
+
DataflowQueue = class extends import_chunk_NHZRKHZO.GenericQueue {
|
|
20365
20668
|
constructor() {
|
|
20366
20669
|
super((b, a) => (a.order || 0) - (b.order || 0));
|
|
20367
20670
|
}
|
|
@@ -21156,7 +21459,7 @@ function computeJsrMap(func) {
|
|
|
21156
21459
|
}
|
|
21157
21460
|
function postOrderPropagate(func, preBlock, processBc, postBlock, merge) {
|
|
21158
21461
|
const order = /* @__PURE__ */ new Map();
|
|
21159
|
-
const queue = new
|
|
21462
|
+
const queue = new import_chunk_NHZRKHZO.GenericQueue(
|
|
21160
21463
|
(b, a) => order.get(a) - order.get(b)
|
|
21161
21464
|
);
|
|
21162
21465
|
postOrderTraverse2(func, (block) => {
|
|
@@ -21215,7 +21518,7 @@ function rpoPropagate(func, preBlock, processBc, postBlock, merge) {
|
|
|
21215
21518
|
});
|
|
21216
21519
|
blocks.reverse().forEach((block, i) => order.set(block, i));
|
|
21217
21520
|
}
|
|
21218
|
-
const queue = new
|
|
21521
|
+
const queue = new import_chunk_NHZRKHZO.GenericQueue(
|
|
21219
21522
|
(b, a) => order.get(a) - order.get(b)
|
|
21220
21523
|
);
|
|
21221
21524
|
queue.enqueue(func.blocks.get(func.offset));
|
|
@@ -21269,7 +21572,7 @@ function rpoPropagate(func, preBlock, processBc, postBlock, merge) {
|
|
|
21269
21572
|
var init_cflow = (0, import_chunk_ABYVSU2C.__esm)({
|
|
21270
21573
|
"src/readprg/cflow.ts"() {
|
|
21271
21574
|
"use strict";
|
|
21272
|
-
(0,
|
|
21575
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
21273
21576
|
init_opcodes();
|
|
21274
21577
|
}
|
|
21275
21578
|
});
|
|
@@ -21732,12 +22035,12 @@ function interpFunc(func, context) {
|
|
|
21732
22035
|
const selfStores = /* @__PURE__ */ new Set();
|
|
21733
22036
|
const liveInState = /* @__PURE__ */ new Map();
|
|
21734
22037
|
const replacements = /* @__PURE__ */ new Map();
|
|
21735
|
-
const interpLogging = (0,
|
|
22038
|
+
const interpLogging = (0, import_chunk_NHZRKHZO.wouldLog)("interp", 1);
|
|
21736
22039
|
if (interpLogging) {
|
|
21737
|
-
if ((0,
|
|
21738
|
-
(0,
|
|
21739
|
-
} else if ((0,
|
|
21740
|
-
(0,
|
|
22040
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("interp", 7)) {
|
|
22041
|
+
(0, import_chunk_NHZRKHZO.setBanner)(functionBanner(func, context, "interp"));
|
|
22042
|
+
} else if ((0, import_chunk_NHZRKHZO.wouldLog)("interp", 3)) {
|
|
22043
|
+
(0, import_chunk_NHZRKHZO.setBanner)(
|
|
21741
22044
|
() => `+++++++++++++ interp-prepare ${func.name} ++++++++++++++`
|
|
21742
22045
|
);
|
|
21743
22046
|
}
|
|
@@ -21771,20 +22074,20 @@ function interpFunc(func, context) {
|
|
|
21771
22074
|
func,
|
|
21772
22075
|
(block) => {
|
|
21773
22076
|
if (interpLogging) {
|
|
21774
|
-
(0,
|
|
22077
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
21775
22078
|
"interp",
|
|
21776
22079
|
3,
|
|
21777
22080
|
`${offsetToString(block.offset)}: ${block.bytecodes[0]?.lineNum ? lineInfoToString(block.bytecodes[0]?.lineNum, context) : ""}
|
|
21778
22081
|
${interpStateToString(liveInState.get(block.offset))}`
|
|
21779
22082
|
);
|
|
21780
|
-
(0,
|
|
22083
|
+
(0, import_chunk_NHZRKHZO.logger)("interp", 9, () => blockToString(block, context));
|
|
21781
22084
|
}
|
|
21782
22085
|
return cloneState2(liveInState.get(block.offset));
|
|
21783
22086
|
},
|
|
21784
22087
|
(block, bc, localState) => {
|
|
21785
22088
|
if (interpLogging) {
|
|
21786
|
-
if ((0,
|
|
21787
|
-
(0,
|
|
22089
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("interp", 8)) {
|
|
22090
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
21788
22091
|
`${interpStateToString(localState)}
|
|
21789
22092
|
${bytecodeToString(
|
|
21790
22093
|
bc,
|
|
@@ -21949,14 +22252,14 @@ function interpFunc(func, context) {
|
|
|
21949
22252
|
if (!mergeInto(localState, succState))
|
|
21950
22253
|
return false;
|
|
21951
22254
|
if (interpLogging) {
|
|
21952
|
-
(0,
|
|
22255
|
+
(0, import_chunk_NHZRKHZO.logger)("interp", 3, `Re-Merge to ${offsetToString(succBlock.offset)}`);
|
|
21953
22256
|
}
|
|
21954
22257
|
return true;
|
|
21955
22258
|
}
|
|
21956
22259
|
);
|
|
21957
22260
|
if (interpLogging) {
|
|
21958
|
-
if ((0,
|
|
21959
|
-
(0,
|
|
22261
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("interp", 5)) {
|
|
22262
|
+
(0, import_chunk_NHZRKHZO.setBanner)(
|
|
21960
22263
|
functionBanner(func, context, "interp", (block, footer) => {
|
|
21961
22264
|
if (footer)
|
|
21962
22265
|
return "";
|
|
@@ -21964,44 +22267,44 @@ function interpFunc(func, context) {
|
|
|
21964
22267
|
})
|
|
21965
22268
|
);
|
|
21966
22269
|
} else {
|
|
21967
|
-
(0,
|
|
22270
|
+
(0, import_chunk_NHZRKHZO.setBanner)(() => `=============== interp ${func.name} ==============`);
|
|
21968
22271
|
}
|
|
21969
22272
|
if (equivSets.size) {
|
|
21970
|
-
(0,
|
|
22273
|
+
(0, import_chunk_NHZRKHZO.log)(`====== equivSets =====`);
|
|
21971
22274
|
equivSets.forEach(
|
|
21972
|
-
(value2, key) => (0,
|
|
22275
|
+
(value2, key) => (0, import_chunk_NHZRKHZO.log)(
|
|
21973
22276
|
`L${key.arg} === ${Array.from(value2).sort().join(" ")} ${key.lineNum ? lineInfoToString(key.lineNum, context) : ""}`
|
|
21974
22277
|
)
|
|
21975
22278
|
);
|
|
21976
22279
|
}
|
|
21977
22280
|
if (selfStores.size) {
|
|
21978
|
-
(0,
|
|
22281
|
+
(0, import_chunk_NHZRKHZO.log)(`====== selfStores =====`);
|
|
21979
22282
|
selfStores.forEach(
|
|
21980
|
-
(value2) => (0,
|
|
22283
|
+
(value2) => (0, import_chunk_NHZRKHZO.log)(`${bytecodeToString(value2, symbolTable)}`)
|
|
21981
22284
|
);
|
|
21982
22285
|
}
|
|
21983
22286
|
if (replacements.size) {
|
|
21984
|
-
(0,
|
|
22287
|
+
(0, import_chunk_NHZRKHZO.log)(`====== replacements =====`);
|
|
21985
22288
|
replacements.forEach(
|
|
21986
22289
|
(blockRep) => blockRep.forEach(
|
|
21987
|
-
(rep, bc) => (0,
|
|
22290
|
+
(rep, bc) => (0, import_chunk_NHZRKHZO.log)(
|
|
21988
22291
|
`${bytecodeToString(bc, symbolTable)} => ${rep.invert ? "~" : ""}${bytecodeToString(rep, symbolTable)} ${bc.lineNum ? lineInfoToString(bc.lineNum, context) : ""}`
|
|
21989
22292
|
)
|
|
21990
22293
|
)
|
|
21991
22294
|
);
|
|
21992
22295
|
}
|
|
21993
22296
|
if (resolvedBranches.size) {
|
|
21994
|
-
(0,
|
|
22297
|
+
(0, import_chunk_NHZRKHZO.log)(`====== resolved branches =====`);
|
|
21995
22298
|
resolvedBranches.forEach(
|
|
21996
|
-
(isTaken, block) => (0,
|
|
22299
|
+
(isTaken, block) => (0, import_chunk_NHZRKHZO.log)(
|
|
21997
22300
|
`block ${offsetToString(block.offset)} is ${isTaken ? "always" : "never"} taken`
|
|
21998
22301
|
)
|
|
21999
22302
|
);
|
|
22000
22303
|
}
|
|
22001
22304
|
if (branchRedirects.size) {
|
|
22002
|
-
(0,
|
|
22305
|
+
(0, import_chunk_NHZRKHZO.log)(`====== redirected branches =====`);
|
|
22003
22306
|
branchRedirects.forEach(
|
|
22004
|
-
({ to, from }, block) => (0,
|
|
22307
|
+
({ to, from }, block) => (0, import_chunk_NHZRKHZO.log)(
|
|
22005
22308
|
`block ${offsetToString(
|
|
22006
22309
|
block.offset
|
|
22007
22310
|
)} redirects from ${offsetToString(from)} to ${offsetToString(to)}${safeBranchBlocks.get(from) ? ` popping ${safeBranchBlocks.get(from)}` : ""}`
|
|
@@ -22064,7 +22367,7 @@ function interpFunc(func, context) {
|
|
|
22064
22367
|
}
|
|
22065
22368
|
});
|
|
22066
22369
|
if (interpLogging)
|
|
22067
|
-
(0,
|
|
22370
|
+
(0, import_chunk_NHZRKHZO.setBanner)(null);
|
|
22068
22371
|
return {
|
|
22069
22372
|
liveInState,
|
|
22070
22373
|
equivSets,
|
|
@@ -22114,7 +22417,7 @@ var init_interp2 = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
22114
22417
|
"src/readprg/interp.ts"() {
|
|
22115
22418
|
"use strict";
|
|
22116
22419
|
init_interp_binary();
|
|
22117
|
-
(0,
|
|
22420
|
+
(0, import_chunk_NHZRKHZO.init_logger)();
|
|
22118
22421
|
init_interp();
|
|
22119
22422
|
init_types();
|
|
22120
22423
|
init_union_type();
|
|
@@ -22226,7 +22529,7 @@ function optimizeArrayInit(func, block, index, context, interpState) {
|
|
|
22226
22529
|
i = found;
|
|
22227
22530
|
}
|
|
22228
22531
|
if (initType && (block.bytecodes[index].op === 20 ? initType.type === 1 : initType.type === 8 && initType.value === 0)) {
|
|
22229
|
-
(0,
|
|
22532
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
22230
22533
|
"array-init",
|
|
22231
22534
|
1,
|
|
22232
22535
|
() => `${func.name}: Removing initialization of default initialized ${putvStarts.length} element array init at block ${offsetToString(
|
|
@@ -22263,7 +22566,7 @@ function optimizeArrayInit(func, block, index, context, interpState) {
|
|
|
22263
22566
|
convertAputv(offset - 1);
|
|
22264
22567
|
}
|
|
22265
22568
|
}
|
|
22266
|
-
(0,
|
|
22569
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
22267
22570
|
"array-init",
|
|
22268
22571
|
1,
|
|
22269
22572
|
() => `${func.name}: Optimizing unused ${putvStarts.length} element array init at block ${offsetToString(
|
|
@@ -22272,8 +22575,8 @@ function optimizeArrayInit(func, block, index, context, interpState) {
|
|
|
22272
22575
|
block.bytecodes[index].offset
|
|
22273
22576
|
)}`
|
|
22274
22577
|
);
|
|
22275
|
-
if ((0,
|
|
22276
|
-
(0,
|
|
22578
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("array-init", 5)) {
|
|
22579
|
+
(0, import_chunk_NHZRKHZO.log)(blockToString(block, context));
|
|
22277
22580
|
}
|
|
22278
22581
|
return true;
|
|
22279
22582
|
}
|
|
@@ -22313,7 +22616,7 @@ function optimizeArrayInit(func, block, index, context, interpState) {
|
|
|
22313
22616
|
if (putvStarts.length < 3)
|
|
22314
22617
|
return false;
|
|
22315
22618
|
tryLocal(3);
|
|
22316
|
-
(0,
|
|
22619
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
22317
22620
|
"array-init",
|
|
22318
22621
|
1,
|
|
22319
22622
|
() => `${func.name}: Optimizing ${putvStarts.length} element array init with constant initializer ${bytecodeToString(
|
|
@@ -22339,7 +22642,7 @@ function optimizeArrayInit(func, block, index, context, interpState) {
|
|
|
22339
22642
|
block.bytecodes[index + 1].arg = putvStarts.length;
|
|
22340
22643
|
}
|
|
22341
22644
|
}
|
|
22342
|
-
(0,
|
|
22645
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
22343
22646
|
"array-init",
|
|
22344
22647
|
5,
|
|
22345
22648
|
() => `index: ${index}, i: ${i}
|
|
@@ -22392,7 +22695,7 @@ ${blockToString(block, context)}`
|
|
|
22392
22695
|
for (let i2 = putvStarts.length; i2-- > 1; ) {
|
|
22393
22696
|
block.bytecodes.splice(putvStarts[i2], 2);
|
|
22394
22697
|
}
|
|
22395
|
-
(0,
|
|
22698
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
22396
22699
|
"array-init",
|
|
22397
22700
|
1,
|
|
22398
22701
|
() => `${func.name}: Optimizing ${putvStarts.length} element array init at block ${offsetToString(
|
|
@@ -22451,15 +22754,15 @@ var init_array_init = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
22451
22754
|
"src/readprg/array-init.ts"() {
|
|
22452
22755
|
"use strict";
|
|
22453
22756
|
init_types();
|
|
22454
|
-
(0,
|
|
22757
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
22455
22758
|
init_bytecode();
|
|
22456
22759
|
init_interp2();
|
|
22457
22760
|
init_opcodes();
|
|
22458
22761
|
}
|
|
22459
22762
|
});
|
|
22460
22763
|
function localDCE(func, context) {
|
|
22461
|
-
if ((0,
|
|
22462
|
-
(0,
|
|
22764
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("dce", 5)) {
|
|
22765
|
+
(0, import_chunk_NHZRKHZO.setBanner)(
|
|
22463
22766
|
functionBanner(
|
|
22464
22767
|
func,
|
|
22465
22768
|
context,
|
|
@@ -22492,7 +22795,7 @@ function localDCE(func, context) {
|
|
|
22492
22795
|
};
|
|
22493
22796
|
func.blocks.forEach((block) => {
|
|
22494
22797
|
const reportPopv = (i, item, kill) => {
|
|
22495
|
-
(0,
|
|
22798
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
22496
22799
|
"dce",
|
|
22497
22800
|
2,
|
|
22498
22801
|
() => `${func.name}: Convert ${i}:${bytecodeToString(
|
|
@@ -22507,7 +22810,7 @@ function localDCE(func, context) {
|
|
|
22507
22810
|
);
|
|
22508
22811
|
};
|
|
22509
22812
|
const reportNop = (item) => {
|
|
22510
|
-
(0,
|
|
22813
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
22511
22814
|
"dce",
|
|
22512
22815
|
2,
|
|
22513
22816
|
() => `${func.name}: Kill ${item.deps.map(
|
|
@@ -22526,7 +22829,7 @@ function localDCE(func, context) {
|
|
|
22526
22829
|
case 19: {
|
|
22527
22830
|
const liveLocal = dceInfo.locals.has(bytecode.arg);
|
|
22528
22831
|
if (!liveLocal && (bytecode.arg || context.config.allowForbiddenOpts)) {
|
|
22529
|
-
(0,
|
|
22832
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
22530
22833
|
"dce",
|
|
22531
22834
|
2,
|
|
22532
22835
|
() => `${func.name}: Killing store to unused local ${bytecode.arg} at ${offsetToString(block.offset)}:${i}`
|
|
@@ -22686,10 +22989,10 @@ function localDCE(func, context) {
|
|
|
22686
22989
|
(bc) => bc.op !== 0
|
|
22687
22990
|
/* nop */
|
|
22688
22991
|
);
|
|
22689
|
-
(0,
|
|
22992
|
+
(0, import_chunk_NHZRKHZO.logger)("dce", 3, functionBanner(func, context, "local-dce-end"));
|
|
22690
22993
|
}
|
|
22691
22994
|
});
|
|
22692
|
-
(0,
|
|
22995
|
+
(0, import_chunk_NHZRKHZO.setBanner)(null);
|
|
22693
22996
|
return anyChanges;
|
|
22694
22997
|
}
|
|
22695
22998
|
function computeLiveLocals(func) {
|
|
@@ -22740,7 +23043,7 @@ var init_dce = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
22740
23043
|
"src/readprg/dce.ts"() {
|
|
22741
23044
|
"use strict";
|
|
22742
23045
|
init_data_flow();
|
|
22743
|
-
(0,
|
|
23046
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
22744
23047
|
init_bytecode();
|
|
22745
23048
|
init_cflow();
|
|
22746
23049
|
init_opcodes();
|
|
@@ -22780,7 +23083,7 @@ function minimizeLocals2(func, equivSets, context) {
|
|
|
22780
23083
|
const splitRanges = computeSplitRanges(func, equivSets);
|
|
22781
23084
|
const locals = mergeSplitRanges(splitRanges);
|
|
22782
23085
|
const numLocals = Math.max(...Array.from(splitRanges.keys())) + 1;
|
|
22783
|
-
(0,
|
|
23086
|
+
(0, import_chunk_NHZRKHZO.logger)("locals", 10, functionBanner(func, context, "Minimize Locals"));
|
|
22784
23087
|
let argc = func.argc ?? null;
|
|
22785
23088
|
const colors = /* @__PURE__ */ new Map();
|
|
22786
23089
|
const merge = [];
|
|
@@ -22847,15 +23150,15 @@ function minimizeLocals2(func, equivSets, context) {
|
|
|
22847
23150
|
}
|
|
22848
23151
|
}
|
|
22849
23152
|
}
|
|
22850
|
-
if ((0,
|
|
22851
|
-
if (!(0,
|
|
22852
|
-
(0,
|
|
23153
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("locals", 1)) {
|
|
23154
|
+
if (!(0, import_chunk_NHZRKHZO.wouldLog)("locals", 10)) {
|
|
23155
|
+
(0, import_chunk_NHZRKHZO.logger)("locals", 5, functionBanner(func, context, "Minimize Locals"));
|
|
22853
23156
|
}
|
|
22854
|
-
(0,
|
|
23157
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
22855
23158
|
`>>> Merging locals in ${func.name} (in: ${numLocals} => out: ${merge.length})`
|
|
22856
23159
|
);
|
|
22857
23160
|
merge.slice().sort((a, b) => (colors.get(a[0]) ?? 0) - (colors.get(b[0]) ?? 0)).forEach(
|
|
22858
|
-
(merged) => (0,
|
|
23161
|
+
(merged) => (0, import_chunk_NHZRKHZO.log)(
|
|
22859
23162
|
` ${colors.get(merged[0])} - ${merged.map((k) => bytecodeToString(k, context.symbolTable)).join(" | ")}`
|
|
22860
23163
|
)
|
|
22861
23164
|
);
|
|
@@ -23154,7 +23457,7 @@ function mergeSplitRanges(splitRanges) {
|
|
|
23154
23457
|
var init_locals = (0, import_chunk_ABYVSU2C.__esm)({
|
|
23155
23458
|
"src/readprg/locals.ts"() {
|
|
23156
23459
|
"use strict";
|
|
23157
|
-
(0,
|
|
23460
|
+
(0, import_chunk_NHZRKHZO.init_logger)();
|
|
23158
23461
|
init_bytecode();
|
|
23159
23462
|
init_cflow();
|
|
23160
23463
|
init_opcodes();
|
|
@@ -23267,16 +23570,16 @@ function sizeBasedPRE2(func, context) {
|
|
|
23267
23570
|
delete bc.arg;
|
|
23268
23571
|
return bc;
|
|
23269
23572
|
};
|
|
23270
|
-
if ((0,
|
|
23271
|
-
if ((0,
|
|
23272
|
-
(0,
|
|
23573
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("pre", 1)) {
|
|
23574
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("pre", 5)) {
|
|
23575
|
+
(0, import_chunk_NHZRKHZO.log)(functionBanner(func, context, "PRE")());
|
|
23273
23576
|
} else {
|
|
23274
|
-
(0,
|
|
23577
|
+
(0, import_chunk_NHZRKHZO.log)(`================ PRE : ${func.name} ================
|
|
23275
23578
|
`);
|
|
23276
23579
|
}
|
|
23277
23580
|
insertionBlocks.forEach((o, key) => {
|
|
23278
23581
|
const bcs = canonicalMap.get(key);
|
|
23279
|
-
(0,
|
|
23582
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
23280
23583
|
`Replacing ${bcs.size} instances of ${bytecodeToString(
|
|
23281
23584
|
bcs.values().next().value,
|
|
23282
23585
|
context.symbolTable
|
|
@@ -23359,13 +23662,13 @@ function sizeBasedPRE2(func, context) {
|
|
|
23359
23662
|
bytecode(1, insertionBlocks.size)
|
|
23360
23663
|
);
|
|
23361
23664
|
}
|
|
23362
|
-
(0,
|
|
23665
|
+
(0, import_chunk_NHZRKHZO.logger)("pre", 5, functionBanner(func, context, "post-PRE"));
|
|
23363
23666
|
return true;
|
|
23364
23667
|
}
|
|
23365
23668
|
var init_pre2 = (0, import_chunk_ABYVSU2C.__esm)({
|
|
23366
23669
|
"src/readprg/pre.ts"() {
|
|
23367
23670
|
"use strict";
|
|
23368
|
-
(0,
|
|
23671
|
+
(0, import_chunk_NHZRKHZO.init_logger)();
|
|
23369
23672
|
init_bytecode();
|
|
23370
23673
|
init_cflow();
|
|
23371
23674
|
init_opcodes();
|
|
@@ -23398,9 +23701,9 @@ function blockSharing(func, context) {
|
|
|
23398
23701
|
if (!any)
|
|
23399
23702
|
return false;
|
|
23400
23703
|
any = false;
|
|
23401
|
-
const logging3 = (0,
|
|
23402
|
-
if (logging3 && (0,
|
|
23403
|
-
(0,
|
|
23704
|
+
const logging3 = (0, import_chunk_NHZRKHZO.wouldLog)("sharing", 1);
|
|
23705
|
+
if (logging3 && (0, import_chunk_NHZRKHZO.wouldLog)("sharing", 10)) {
|
|
23706
|
+
(0, import_chunk_NHZRKHZO.setBanner)(functionBanner(func, context, "sharing"));
|
|
23404
23707
|
}
|
|
23405
23708
|
candidates.forEach((blocks) => {
|
|
23406
23709
|
while (blocks.size > 1) {
|
|
@@ -23536,9 +23839,9 @@ function blockSharing(func, context) {
|
|
|
23536
23839
|
block2.offset
|
|
23537
23840
|
)})` : `block(${offsetToString(block2.offset)})`;
|
|
23538
23841
|
};
|
|
23539
|
-
(0,
|
|
23540
|
-
if ((0,
|
|
23541
|
-
(0,
|
|
23842
|
+
(0, import_chunk_NHZRKHZO.log)(`Sharing ${showBlock(block)} with ${showBlock(target)}`);
|
|
23843
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("sharing", 5)) {
|
|
23844
|
+
(0, import_chunk_NHZRKHZO.log)(blockToString(target, context));
|
|
23542
23845
|
}
|
|
23543
23846
|
}
|
|
23544
23847
|
if (target.bytecodes.length > length2) {
|
|
@@ -23565,13 +23868,13 @@ function blockSharing(func, context) {
|
|
|
23565
23868
|
});
|
|
23566
23869
|
}
|
|
23567
23870
|
});
|
|
23568
|
-
(0,
|
|
23871
|
+
(0, import_chunk_NHZRKHZO.setBanner)(null);
|
|
23569
23872
|
return any;
|
|
23570
23873
|
}
|
|
23571
23874
|
var init_sharing = (0, import_chunk_ABYVSU2C.__esm)({
|
|
23572
23875
|
"src/readprg/sharing.ts"() {
|
|
23573
23876
|
"use strict";
|
|
23574
|
-
(0,
|
|
23877
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
23575
23878
|
init_bytecode();
|
|
23576
23879
|
init_opcodes();
|
|
23577
23880
|
}
|
|
@@ -23635,7 +23938,7 @@ function doArrayInits(func, liveInState, context) {
|
|
|
23635
23938
|
}
|
|
23636
23939
|
function simpleOpts(func, context) {
|
|
23637
23940
|
const equalsSym = 8388787;
|
|
23638
|
-
const logging3 = (0,
|
|
23941
|
+
const logging3 = (0, import_chunk_NHZRKHZO.wouldLog)("optimize", 5);
|
|
23639
23942
|
return Array.from(func.blocks.values()).reduce((changes, block) => {
|
|
23640
23943
|
for (let i = block.bytecodes.length; i--; ) {
|
|
23641
23944
|
const cur = block.bytecodes[i];
|
|
@@ -23643,7 +23946,7 @@ function simpleOpts(func, context) {
|
|
|
23643
23946
|
block.bytecodes.splice(i, 1);
|
|
23644
23947
|
changes = true;
|
|
23645
23948
|
if (logging3) {
|
|
23646
|
-
(0,
|
|
23949
|
+
(0, import_chunk_NHZRKHZO.log)(`${func.name}: deleting ${bytecodeToString(cur, null)}`);
|
|
23647
23950
|
}
|
|
23648
23951
|
} else if (cur.op === 74 && context.config.removeArgc && context.config.allowForbiddenOpts) {
|
|
23649
23952
|
const arg = cur.arg.incsp;
|
|
@@ -23652,7 +23955,7 @@ function simpleOpts(func, context) {
|
|
|
23652
23955
|
incsp.arg = arg;
|
|
23653
23956
|
changes = true;
|
|
23654
23957
|
if (logging3) {
|
|
23655
|
-
(0,
|
|
23958
|
+
(0, import_chunk_NHZRKHZO.log)(`${func.name}: argcincsp => incsp`);
|
|
23656
23959
|
}
|
|
23657
23960
|
} else if (i && cur.op === 39 && cur.arg === equalsSym) {
|
|
23658
23961
|
changes = equalSymbolToEq(block, i) || changes;
|
|
@@ -23663,7 +23966,7 @@ function simpleOpts(func, context) {
|
|
|
23663
23966
|
if (!shift && prev.op === 37) {
|
|
23664
23967
|
block.bytecodes.splice(i - 1, 2);
|
|
23665
23968
|
changes = true;
|
|
23666
|
-
logging3 && (0,
|
|
23969
|
+
logging3 && (0, import_chunk_NHZRKHZO.log)(`${func.name}: deleting no-op shift (${shift})`);
|
|
23667
23970
|
continue;
|
|
23668
23971
|
}
|
|
23669
23972
|
if (shift === 1n && prev.op === 37) {
|
|
@@ -23673,7 +23976,7 @@ function simpleOpts(func, context) {
|
|
|
23673
23976
|
const add = cur;
|
|
23674
23977
|
add.op = 3;
|
|
23675
23978
|
delete add.arg;
|
|
23676
|
-
logging3 && (0,
|
|
23979
|
+
logging3 && (0, import_chunk_NHZRKHZO.log)(`${func.name}: converting "ipush 1; shlv" to "dup 0; addv"`);
|
|
23677
23980
|
continue;
|
|
23678
23981
|
}
|
|
23679
23982
|
if (shift < (prev.op === 49 ? 64n : 31n)) {
|
|
@@ -23683,7 +23986,7 @@ function simpleOpts(func, context) {
|
|
|
23683
23986
|
} else {
|
|
23684
23987
|
prev.arg = BigInt.asIntN(64, mul);
|
|
23685
23988
|
}
|
|
23686
|
-
logging3 && (0,
|
|
23989
|
+
logging3 && (0, import_chunk_NHZRKHZO.log)(
|
|
23687
23990
|
`${func.name}: converting shlv(${shift}) to mulv(${prev.arg})`
|
|
23688
23991
|
);
|
|
23689
23992
|
changes = true;
|
|
@@ -23697,14 +24000,14 @@ function simpleOpts(func, context) {
|
|
|
23697
24000
|
func.blocks.get(block.taken).preds.delete(block.offset);
|
|
23698
24001
|
delete block.taken;
|
|
23699
24002
|
changes = true;
|
|
23700
|
-
logging3 && (0,
|
|
24003
|
+
logging3 && (0, import_chunk_NHZRKHZO.log)(`${func.name}: deleting empty finally handler`);
|
|
23701
24004
|
} else if (isCondBranch(cur.op)) {
|
|
23702
24005
|
const next = func.blocks.get(block.next);
|
|
23703
24006
|
const taken = func.blocks.get(block.taken);
|
|
23704
24007
|
if (next.preds.size > 1 && taken.preds.size === 1) {
|
|
23705
24008
|
const newOp = cur.op === 40 ? 41 : 40;
|
|
23706
24009
|
if (logging3) {
|
|
23707
|
-
(0,
|
|
24010
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
23708
24011
|
`${func.name}: converting ${Opcodes[cur.op]} to ${Opcodes[newOp]}`
|
|
23709
24012
|
);
|
|
23710
24013
|
}
|
|
@@ -23717,7 +24020,7 @@ function simpleOpts(func, context) {
|
|
|
23717
24020
|
const isBool = i >= 2 && isBoolOp(block.bytecodes[i - 2].op);
|
|
23718
24021
|
if (next.next === block.taken && next.taken == null && taken.bytecodes.length === 1 && isCondBranch(taken.bytecodes[0].op) && next.bytecodes.length > 1 && next.bytecodes[next.bytecodes.length - 1].op === (cur.op === 41 ? 7 : 8) && (isBool || next.bytecodes.length > 2 && isBoolOp(next.bytecodes[next.bytecodes.length - 2].op)) && next.preds?.size === 1 && taken.preds?.size === 2) {
|
|
23719
24022
|
if (logging3) {
|
|
23720
|
-
(0,
|
|
24023
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
23721
24024
|
`${func.name}: simplifying ${next.bytecodes[next.bytecodes.length - 1].op === 7 ? "'&&'" : "'||'"} at ${offsetToString(block.offset)}:${offsetToString(
|
|
23722
24025
|
next.offset
|
|
23723
24026
|
)}:${offsetToString(taken.offset)}:`
|
|
@@ -23734,7 +24037,7 @@ function simpleOpts(func, context) {
|
|
|
23734
24037
|
changes = true;
|
|
23735
24038
|
} else if (taken.next === block.next && taken.taken == null && next.bytecodes.length === 1 && isCondBranch(next.bytecodes[0].op) && taken.bytecodes.length > 1 && taken.bytecodes[taken.bytecodes.length - 1].op === (cur.op === 40 ? 7 : 8) && (isBool || taken.bytecodes.length > 2 && isBoolOp(taken.bytecodes[taken.bytecodes.length - 2].op)) && next.preds?.size === 2 && taken.preds?.size === 1) {
|
|
23736
24039
|
if (logging3) {
|
|
23737
|
-
(0,
|
|
24040
|
+
(0, import_chunk_NHZRKHZO.log)(
|
|
23738
24041
|
`${func.name}: simplifying ${taken.bytecodes[taken.bytecodes.length - 1].op === 7 ? "'&&'" : "'||'"} at ${offsetToString(block.offset)}:${offsetToString(
|
|
23739
24042
|
taken.offset
|
|
23740
24043
|
)}:${offsetToString(next.offset)}:`
|
|
@@ -23782,7 +24085,7 @@ function equalSymbolToEq(block, equalsIndex) {
|
|
|
23782
24085
|
op: 26,
|
|
23783
24086
|
offset: invokem.offset
|
|
23784
24087
|
});
|
|
23785
|
-
(0,
|
|
24088
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
23786
24089
|
"optimize",
|
|
23787
24090
|
1,
|
|
23788
24091
|
`Replacing <thing>.equals(:symbol) with <thing> eq :symbol at ${offsetToString(
|
|
@@ -23842,7 +24145,7 @@ function removeUnreachableCatches(func, context) {
|
|
|
23842
24145
|
const next = func.blocks.get(block.next);
|
|
23843
24146
|
if (block.try === next.try) {
|
|
23844
24147
|
if (next.preds.size === 1) {
|
|
23845
|
-
(0,
|
|
24148
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
23846
24149
|
"cfg",
|
|
23847
24150
|
1,
|
|
23848
24151
|
() => `${func.name}: ${offsetToString(
|
|
@@ -23865,7 +24168,7 @@ function removeUnreachableCatches(func, context) {
|
|
|
23865
24168
|
delete next.preds;
|
|
23866
24169
|
removeBlock(func, next.offset);
|
|
23867
24170
|
} else if (next.next == null && next.bytecodes.length < 3 && next.bytecodes.reduce((size, bc) => size + opcodeSize(bc.op), 0) < 3 && countFallthroughPreds(func, next) > 1) {
|
|
23868
|
-
(0,
|
|
24171
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
23869
24172
|
"cfg",
|
|
23870
24173
|
1,
|
|
23871
24174
|
() => `${func.name}: ${offsetToString(
|
|
@@ -23890,7 +24193,7 @@ function removeUnreachableCatches(func, context) {
|
|
|
23890
24193
|
switch (last.op) {
|
|
23891
24194
|
case 41:
|
|
23892
24195
|
case 40:
|
|
23893
|
-
(0,
|
|
24196
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
23894
24197
|
"cfg",
|
|
23895
24198
|
1,
|
|
23896
24199
|
() => `${func.name}: killing no-op ${bytecodeToString(
|
|
@@ -23913,7 +24216,7 @@ function removeUnreachableCatches(func, context) {
|
|
|
23913
24216
|
for (let i = block.try.length; i--; ) {
|
|
23914
24217
|
const handler = block.try[i].handler;
|
|
23915
24218
|
if (!func.blocks.get(handler)?.preds?.size) {
|
|
23916
|
-
(0,
|
|
24219
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
23917
24220
|
"cfg",
|
|
23918
24221
|
1,
|
|
23919
24222
|
`${func.name}: killing unused try-catch at ${offsetToString(
|
|
@@ -23930,8 +24233,8 @@ function removeUnreachableCatches(func, context) {
|
|
|
23930
24233
|
});
|
|
23931
24234
|
}
|
|
23932
24235
|
function cleanCfg2(func, context) {
|
|
23933
|
-
if ((0,
|
|
23934
|
-
(0,
|
|
24236
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("cfg", 10)) {
|
|
24237
|
+
(0, import_chunk_NHZRKHZO.setBanner)(functionBanner(func, context, "sharing"));
|
|
23935
24238
|
}
|
|
23936
24239
|
removeNoOpBlocks(func);
|
|
23937
24240
|
removeUnreachableCatches(func, context);
|
|
@@ -23946,12 +24249,12 @@ function cleanCfg2(func, context) {
|
|
|
23946
24249
|
(0, import_node_assert12.default)(!block.preds?.size);
|
|
23947
24250
|
func.blocks.delete(block.offset);
|
|
23948
24251
|
});
|
|
23949
|
-
(0,
|
|
24252
|
+
(0, import_chunk_NHZRKHZO.setBanner)(null);
|
|
23950
24253
|
}
|
|
23951
24254
|
var init_optimize2 = (0, import_chunk_ABYVSU2C.__esm)({
|
|
23952
24255
|
"src/readprg/optimize.ts"() {
|
|
23953
24256
|
"use strict";
|
|
23954
|
-
(0,
|
|
24257
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
23955
24258
|
init_array_init();
|
|
23956
24259
|
init_bytecode();
|
|
23957
24260
|
init_cflow();
|
|
@@ -24566,21 +24869,21 @@ function optimizeBytecode(context) {
|
|
|
24566
24869
|
functions.forEach(callback);
|
|
24567
24870
|
return;
|
|
24568
24871
|
}
|
|
24569
|
-
(0,
|
|
24872
|
+
(0, import_chunk_NHZRKHZO.bumpLogging)(null, 10);
|
|
24570
24873
|
functions.forEach((func) => {
|
|
24571
24874
|
if (loggerFunc.test(func.name ?? "<null>")) {
|
|
24572
|
-
(0,
|
|
24875
|
+
(0, import_chunk_NHZRKHZO.bumpLogging)(null, -10);
|
|
24573
24876
|
callback(func);
|
|
24574
|
-
(0,
|
|
24877
|
+
(0, import_chunk_NHZRKHZO.bumpLogging)(null, 10);
|
|
24575
24878
|
return;
|
|
24576
24879
|
}
|
|
24577
24880
|
callback(func);
|
|
24578
24881
|
});
|
|
24579
|
-
(0,
|
|
24882
|
+
(0, import_chunk_NHZRKHZO.bumpLogging)(null, -10);
|
|
24580
24883
|
};
|
|
24581
|
-
if ((0,
|
|
24884
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("list-input", 1)) {
|
|
24582
24885
|
forEachFunction(
|
|
24583
|
-
(func) => (0,
|
|
24886
|
+
(func) => (0, import_chunk_NHZRKHZO.wouldLog)("list-input", 1) && printFunction(func, context)
|
|
24584
24887
|
);
|
|
24585
24888
|
}
|
|
24586
24889
|
forEachFunction((func) => optimizeFunc(func, context));
|
|
@@ -24598,7 +24901,7 @@ function optimizeBytecode(context) {
|
|
|
24598
24901
|
forEachFunction((func) => {
|
|
24599
24902
|
if (!func.name)
|
|
24600
24903
|
return;
|
|
24601
|
-
(0,
|
|
24904
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
24602
24905
|
"bytecode",
|
|
24603
24906
|
5,
|
|
24604
24907
|
`${func.name}: ${offset.toString(16)} ${offset - func.offset}`
|
|
@@ -24607,7 +24910,7 @@ function optimizeBytecode(context) {
|
|
|
24607
24910
|
});
|
|
24608
24911
|
const { offsetMap } = updateInfo;
|
|
24609
24912
|
offsetMap.set(code.byteLength, offset);
|
|
24610
|
-
(0,
|
|
24913
|
+
(0, import_chunk_NHZRKHZO.logger)(
|
|
24611
24914
|
"bytecode",
|
|
24612
24915
|
1,
|
|
24613
24916
|
`${context.filepath}: code size: ${context.sections[
|
|
@@ -24619,9 +24922,9 @@ function optimizeBytecode(context) {
|
|
|
24619
24922
|
].length - offset}`
|
|
24620
24923
|
);
|
|
24621
24924
|
fixSectionSize(-1059145026, context.sections, offset);
|
|
24622
|
-
if ((0,
|
|
24925
|
+
if ((0, import_chunk_NHZRKHZO.wouldLog)("list-output", 1)) {
|
|
24623
24926
|
forEachFunction(
|
|
24624
|
-
(func) => (0,
|
|
24927
|
+
(func) => (0, import_chunk_NHZRKHZO.wouldLog)("list-output", 1) && printFunction(func, context)
|
|
24625
24928
|
);
|
|
24626
24929
|
}
|
|
24627
24930
|
fixupHeader(context, updateInfo);
|
|
@@ -24711,7 +25014,7 @@ ${functionToString(
|
|
|
24711
25014
|
---------------- ${func.name} ----------------`;
|
|
24712
25015
|
}
|
|
24713
25016
|
function printFunction(func, context) {
|
|
24714
|
-
(0,
|
|
25017
|
+
(0, import_chunk_NHZRKHZO.log)(functionToString(func, context));
|
|
24715
25018
|
}
|
|
24716
25019
|
function functionToString(func, context, extra) {
|
|
24717
25020
|
const parts = [];
|
|
@@ -25142,7 +25445,7 @@ var init_bytecode = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
25142
25445
|
"use strict";
|
|
25143
25446
|
(0, import_chunk_JDC43A3I.init_ast)();
|
|
25144
25447
|
init_sdk_util();
|
|
25145
|
-
(0,
|
|
25448
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
25146
25449
|
init_data();
|
|
25147
25450
|
init_emit();
|
|
25148
25451
|
init_exceptions();
|
|
@@ -25428,10 +25731,10 @@ async function build_project(product, options, lineCallback) {
|
|
|
25428
25731
|
].flat();
|
|
25429
25732
|
if (!returnCommand) {
|
|
25430
25733
|
const handlers = [
|
|
25431
|
-
lineCallback || ((line) => (0,
|
|
25734
|
+
lineCallback || ((line) => (0, import_chunk_NHZRKHZO.log)(line)),
|
|
25432
25735
|
(line) => console.error(line)
|
|
25433
25736
|
];
|
|
25434
|
-
await (0,
|
|
25737
|
+
await (0, import_chunk_NHZRKHZO.spawnByLine)(exe, args, handlers, {
|
|
25435
25738
|
cwd: workspace
|
|
25436
25739
|
});
|
|
25437
25740
|
}
|
|
@@ -25441,7 +25744,7 @@ var init_build = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
25441
25744
|
"src/build.ts"() {
|
|
25442
25745
|
"use strict";
|
|
25443
25746
|
init_sdk_util();
|
|
25444
|
-
(0,
|
|
25747
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
25445
25748
|
}
|
|
25446
25749
|
});
|
|
25447
25750
|
var require_ms = (0, import_chunk_ABYVSU2C.__commonJS)({
|
|
@@ -28408,7 +28711,7 @@ async function resolve_literals(qualifier, default_source, deviceInfo, cache) {
|
|
|
28408
28711
|
);
|
|
28409
28712
|
if (!(0, import_chunk_JDC43A3I.hasProperty)(cache.resolvedPaths, resolved)) {
|
|
28410
28713
|
if (/[*?[\]{}]/.test(resolved)) {
|
|
28411
|
-
cache.resolvedPaths[resolved] = (0,
|
|
28714
|
+
cache.resolvedPaths[resolved] = (0, import_chunk_NHZRKHZO.globSome)(resolved, () => true);
|
|
28412
28715
|
} else {
|
|
28413
28716
|
cache.resolvedPaths[resolved] = fs5.stat(resolved).then(
|
|
28414
28717
|
() => true,
|
|
@@ -28487,12 +28790,12 @@ async function read_resource_files(targets, cache) {
|
|
|
28487
28790
|
if (!(0, import_chunk_JDC43A3I.hasProperty)(resourceGroupPromises, key)) {
|
|
28488
28791
|
resourceGroupPromises[key] = Promise.all(
|
|
28489
28792
|
p.qualifier.resourcePath.map(
|
|
28490
|
-
(pattern) => (0,
|
|
28793
|
+
(pattern) => (0, import_chunk_NHZRKHZO.globa)(pattern, { mark: true })
|
|
28491
28794
|
)
|
|
28492
28795
|
).then(
|
|
28493
28796
|
(patterns) => Promise.all(
|
|
28494
28797
|
patterns.flat().map(
|
|
28495
|
-
(path7) => path7.endsWith("/") ? (0,
|
|
28798
|
+
(path7) => path7.endsWith("/") ? (0, import_chunk_NHZRKHZO.globa)(`${path7}**/*.xml`, { mark: true }) : path7
|
|
28496
28799
|
)
|
|
28497
28800
|
)
|
|
28498
28801
|
).then(
|
|
@@ -28552,7 +28855,7 @@ async function find_build_instructions_in_resource(file, rez, buildDependencies)
|
|
|
28552
28855
|
const sourceExcludes = excludes.map((e) => e.file?.value.value).filter((f) => f != null).map((f) => path2.resolve(dir, f).replace(/\\/g, "/"));
|
|
28553
28856
|
const filePatterns = excludes.map((e) => e.dir?.value.value).filter((f) => f != null).map((f) => path2.join(dir, f, "**", "*.mc").replace(/\\/g, "/"));
|
|
28554
28857
|
if (filePatterns.length) {
|
|
28555
|
-
const files = (await Promise.all(filePatterns.map((p) => (0,
|
|
28858
|
+
const files = (await Promise.all(filePatterns.map((p) => (0, import_chunk_NHZRKHZO.globa)(p)))).flat();
|
|
28556
28859
|
sourceExcludes.push(...files);
|
|
28557
28860
|
}
|
|
28558
28861
|
const excludeAnnotations = excludes.map((e) => e.annotation?.value.value).filter((f) => f != null);
|
|
@@ -28729,15 +29032,15 @@ function identify_optimizer_groups(targets, options) {
|
|
|
28729
29032
|
function find_barrels(barrelPath, buildDependencies) {
|
|
28730
29033
|
return (Array.isArray(barrelPath) ? (
|
|
28731
29034
|
// This is a sublist. The barrel has more than one jungle file.
|
|
28732
|
-
Promise.all(barrelPath.map((path7) => (0,
|
|
29035
|
+
Promise.all(barrelPath.map((path7) => (0, import_chunk_NHZRKHZO.globa)(path7, { mark: true }))).then(
|
|
28733
29036
|
(paths) => [
|
|
28734
29037
|
paths.flat().filter((path7) => path7.endsWith(".jungle")).join(";")
|
|
28735
29038
|
]
|
|
28736
29039
|
)
|
|
28737
|
-
) : (0,
|
|
29040
|
+
) : (0, import_chunk_NHZRKHZO.globa)(barrelPath, { mark: true }).then(
|
|
28738
29041
|
(paths) => Promise.all(
|
|
28739
29042
|
paths.map(
|
|
28740
|
-
(path7) => path7.endsWith("/") ? (0,
|
|
29043
|
+
(path7) => path7.endsWith("/") ? (0, import_chunk_NHZRKHZO.globa)(`${path7}**/*.barrel`) : path7
|
|
28741
29044
|
)
|
|
28742
29045
|
)
|
|
28743
29046
|
).then(
|
|
@@ -28745,7 +29048,7 @@ function find_barrels(barrelPath, buildDependencies) {
|
|
|
28745
29048
|
(path7) => path7.endsWith(".jungle") || path7.endsWith(".barrel")
|
|
28746
29049
|
)
|
|
28747
29050
|
)).then((paths) => {
|
|
28748
|
-
(0,
|
|
29051
|
+
(0, import_chunk_NHZRKHZO.forEach)(
|
|
28749
29052
|
barrelPath,
|
|
28750
29053
|
(path7) => /[*?[\]{}]/.test(path7) || (buildDependencies[path7] = true)
|
|
28751
29054
|
);
|
|
@@ -29022,7 +29325,7 @@ var init_jungles = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
29022
29325
|
init_api();
|
|
29023
29326
|
init_manifest();
|
|
29024
29327
|
init_sdk_util();
|
|
29025
|
-
(0,
|
|
29328
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
29026
29329
|
depth = 0;
|
|
29027
29330
|
}
|
|
29028
29331
|
});
|
|
@@ -29050,7 +29353,7 @@ async function launchSimulator(force = true) {
|
|
|
29050
29353
|
await new Promise((r) => setTimeout(r, 200));
|
|
29051
29354
|
}
|
|
29052
29355
|
} catch (e) {
|
|
29053
|
-
(0,
|
|
29356
|
+
(0, import_chunk_NHZRKHZO.log)(e);
|
|
29054
29357
|
}
|
|
29055
29358
|
}
|
|
29056
29359
|
function checkIfSimulatorRunning() {
|
|
@@ -29081,10 +29384,10 @@ function simulateProgram(prg, device, test = false, logger2) {
|
|
|
29081
29384
|
}
|
|
29082
29385
|
}
|
|
29083
29386
|
return getSdkPath().then(
|
|
29084
|
-
(sdk) => (0,
|
|
29387
|
+
(sdk) => (0, import_chunk_NHZRKHZO.spawnByLine)(
|
|
29085
29388
|
path3.resolve(sdk, "bin", isWin ? "monkeydo.bat" : "monkeydo"),
|
|
29086
29389
|
args,
|
|
29087
|
-
logger2 || ((line) => (0,
|
|
29390
|
+
logger2 || ((line) => (0, import_chunk_NHZRKHZO.log)(line))
|
|
29088
29391
|
).then(() => {
|
|
29089
29392
|
return;
|
|
29090
29393
|
})
|
|
@@ -29094,7 +29397,107 @@ var init_launch = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
29094
29397
|
"src/launch.ts"() {
|
|
29095
29398
|
"use strict";
|
|
29096
29399
|
init_sdk_util();
|
|
29097
|
-
(0,
|
|
29400
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
29401
|
+
}
|
|
29402
|
+
});
|
|
29403
|
+
async function analyze_module_types(state) {
|
|
29404
|
+
if (!state.config?.propagateTypes || !state.config.trustDeclaredTypes || state.config.checkTypes === "OFF") {
|
|
29405
|
+
return null;
|
|
29406
|
+
}
|
|
29407
|
+
const typeChecker = state.config.strictTypeCheck?.toLowerCase() === "on" ? subtypeOf : couldBeWeak;
|
|
29408
|
+
const checkTypes = state.config?.checkTypes || "WARNING";
|
|
29409
|
+
const rootList = [
|
|
29410
|
+
state.stack[0].sn,
|
|
29411
|
+
...state.allModules,
|
|
29412
|
+
...state.allClasses
|
|
29413
|
+
];
|
|
29414
|
+
const modulesSet = new Set(rootList);
|
|
29415
|
+
const typeMap = /* @__PURE__ */ new Map();
|
|
29416
|
+
const moduleMap = /* @__PURE__ */ new Map();
|
|
29417
|
+
const dependencies = /* @__PURE__ */ new Map();
|
|
29418
|
+
for (const module2 of modulesSet) {
|
|
29419
|
+
modulesSet.delete(module2);
|
|
29420
|
+
const istate = buildTypeInfo(state, module2, false);
|
|
29421
|
+
await (0, import_chunk_NHZRKHZO.log)();
|
|
29422
|
+
if (istate?.typeMap) {
|
|
29423
|
+
moduleMap.set(module2, istate);
|
|
29424
|
+
istate.dependencies?.forEach((flags, other) => {
|
|
29425
|
+
if (other === module2)
|
|
29426
|
+
return;
|
|
29427
|
+
const depMap = dependencies.get(other);
|
|
29428
|
+
if (depMap) {
|
|
29429
|
+
depMap.set(module2, (depMap.get(module2) ?? 0) | flags);
|
|
29430
|
+
} else {
|
|
29431
|
+
dependencies.set(other, /* @__PURE__ */ new Map([[module2, flags]]));
|
|
29432
|
+
}
|
|
29433
|
+
});
|
|
29434
|
+
let changes = false;
|
|
29435
|
+
let promise = null;
|
|
29436
|
+
istate.typeMap?.forEach((value2, key) => {
|
|
29437
|
+
const old = typeMap.get(key);
|
|
29438
|
+
if (!old) {
|
|
29439
|
+
changes = true;
|
|
29440
|
+
} else if (!subtypeOf(value2, old)) {
|
|
29441
|
+
if (promise)
|
|
29442
|
+
return;
|
|
29443
|
+
promise = formatAstLongLines(key).then((nodeStr) => {
|
|
29444
|
+
throw new Error(
|
|
29445
|
+
`New type for ${nodeStr} was not a subtype. Old: ${display(
|
|
29446
|
+
old
|
|
29447
|
+
)} vs New: ${display(value2)}`
|
|
29448
|
+
);
|
|
29449
|
+
});
|
|
29450
|
+
} else if (!changes && !subtypeOf(old, value2)) {
|
|
29451
|
+
changes = true;
|
|
29452
|
+
}
|
|
29453
|
+
typeMap.set(key, value2);
|
|
29454
|
+
});
|
|
29455
|
+
promise && await promise;
|
|
29456
|
+
if (changes) {
|
|
29457
|
+
const depMap = dependencies.get(module2);
|
|
29458
|
+
depMap?.forEach((flags, other) => {
|
|
29459
|
+
if (flags & 1) {
|
|
29460
|
+
modulesSet.add(other);
|
|
29461
|
+
}
|
|
29462
|
+
});
|
|
29463
|
+
}
|
|
29464
|
+
}
|
|
29465
|
+
}
|
|
29466
|
+
rootList.push(...Object.values(state.allFunctions).flat());
|
|
29467
|
+
for (const root of rootList) {
|
|
29468
|
+
const istate = moduleMap.get(root) ?? buildTypeInfo(state, root, false);
|
|
29469
|
+
if (istate) {
|
|
29470
|
+
istate.typeChecker = typeChecker;
|
|
29471
|
+
istate.checkTypes = checkTypes;
|
|
29472
|
+
if (root.nodes) {
|
|
29473
|
+
const saved = istate.state.stack;
|
|
29474
|
+
root.nodes.forEach((stack, node) => {
|
|
29475
|
+
istate.state.stack = stack.slice();
|
|
29476
|
+
pushRootNode(istate.state.stack, root);
|
|
29477
|
+
evaluate(istate, node);
|
|
29478
|
+
popRootNode(istate.state.stack, root);
|
|
29479
|
+
});
|
|
29480
|
+
istate.state.stack = saved;
|
|
29481
|
+
} else {
|
|
29482
|
+
pushRootNode(istate.state.stack, root);
|
|
29483
|
+
evaluate(istate, root.node);
|
|
29484
|
+
popRootNode(istate.state.stack, root);
|
|
29485
|
+
}
|
|
29486
|
+
istate.typeMap?.forEach((value2, key) => typeMap.set(key, value2));
|
|
29487
|
+
}
|
|
29488
|
+
}
|
|
29489
|
+
return typeMap;
|
|
29490
|
+
}
|
|
29491
|
+
var init_module_types = (0, import_chunk_ABYVSU2C.__esm)({
|
|
29492
|
+
"src/type-flow/module-types.ts"() {
|
|
29493
|
+
"use strict";
|
|
29494
|
+
init_api();
|
|
29495
|
+
init_type_flow();
|
|
29496
|
+
init_could_be();
|
|
29497
|
+
init_interp();
|
|
29498
|
+
init_sub_type();
|
|
29499
|
+
init_types();
|
|
29500
|
+
(0, import_chunk_NHZRKHZO.init_logger)();
|
|
29098
29501
|
}
|
|
29099
29502
|
});
|
|
29100
29503
|
function relative_path_no_dotdot(relative2) {
|
|
@@ -29115,7 +29518,7 @@ async function getCodeWorkspaceSettings(folder) {
|
|
|
29115
29518
|
let curDir = folder;
|
|
29116
29519
|
try {
|
|
29117
29520
|
while (curDir) {
|
|
29118
|
-
const code_workspaces = await (0,
|
|
29521
|
+
const code_workspaces = await (0, import_chunk_NHZRKHZO.globa)(
|
|
29119
29522
|
path4.resolve(curDir, "*.code-workspace"),
|
|
29120
29523
|
{ onlyFiles: true }
|
|
29121
29524
|
);
|
|
@@ -29243,7 +29646,7 @@ async function createLocalBarrels(targets, options) {
|
|
|
29243
29646
|
optBarrelDir
|
|
29244
29647
|
};
|
|
29245
29648
|
return promise2.then(
|
|
29246
|
-
() => (0,
|
|
29649
|
+
() => (0, import_chunk_NHZRKHZO.copyRecursiveAsNeeded)(
|
|
29247
29650
|
rawBarrelDir,
|
|
29248
29651
|
optBarrelDir,
|
|
29249
29652
|
(src) => !src.endsWith(".mc")
|
|
@@ -29544,7 +29947,7 @@ async function filesFromPaths(workspace, buildDir, inPaths, extension) {
|
|
|
29544
29947
|
const filter = buildDir.startsWith(workspace);
|
|
29545
29948
|
const paths = (await Promise.all(
|
|
29546
29949
|
inPaths?.map(
|
|
29547
|
-
(pattern) => (0,
|
|
29950
|
+
(pattern) => (0, import_chunk_NHZRKHZO.globa)(pattern, { cwd: workspace, mark: true }).then(
|
|
29548
29951
|
(paths2) => paths2.map((p) => ({
|
|
29549
29952
|
path: p,
|
|
29550
29953
|
filter: filter && /^\*\*[\\/]\*.mc$/i.test(path4.relative(workspace, pattern))
|
|
@@ -29554,7 +29957,7 @@ async function filesFromPaths(workspace, buildDir, inPaths, extension) {
|
|
|
29554
29957
|
)).flat();
|
|
29555
29958
|
const files = await Promise.all(
|
|
29556
29959
|
paths.map(
|
|
29557
|
-
(result) => result.path.endsWith("/") ? (0,
|
|
29960
|
+
(result) => result.path.endsWith("/") ? (0, import_chunk_NHZRKHZO.globa)(`${result.path}**/*${extension}`, {
|
|
29558
29961
|
cwd: workspace,
|
|
29559
29962
|
mark: true
|
|
29560
29963
|
}).then(
|
|
@@ -29677,7 +30080,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
|
|
|
29677
30080
|
})
|
|
29678
30081
|
);
|
|
29679
30082
|
}
|
|
29680
|
-
const actualOptimizedFiles = (await (0,
|
|
30083
|
+
const actualOptimizedFiles = (await (0, import_chunk_NHZRKHZO.globa)(path4.join(output, "**", "*.mc"), { mark: true })).filter((file) => !file.endsWith("/")).sort();
|
|
29681
30084
|
const {
|
|
29682
30085
|
hasTests,
|
|
29683
30086
|
diagnostics: prevDiagnostics,
|
|
@@ -29693,13 +30096,13 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
|
|
|
29693
30096
|
const sdk = await getSdkPath();
|
|
29694
30097
|
const match = sdk.match(/-(\d+\.\d+\.\d+)/);
|
|
29695
30098
|
if ((match && parseSdkVersion(match[1])) === prevSdkVersion) {
|
|
29696
|
-
const source_time = await (0,
|
|
30099
|
+
const source_time = await (0, import_chunk_NHZRKHZO.last_modified)(
|
|
29697
30100
|
Object.keys(fnMap).concat(dependencyFiles)
|
|
29698
30101
|
);
|
|
29699
|
-
const opt_time = await (0,
|
|
30102
|
+
const opt_time = await (0, import_chunk_NHZRKHZO.first_modified)(
|
|
29700
30103
|
Object.values(fnMap).map((v) => v.output)
|
|
29701
30104
|
);
|
|
29702
|
-
if (source_time < opt_time &&
|
|
30105
|
+
if (source_time < opt_time && 1721695353078 < opt_time) {
|
|
29703
30106
|
return {
|
|
29704
30107
|
hasTests,
|
|
29705
30108
|
diagnostics: prevDiagnostics,
|
|
@@ -29737,7 +30140,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
|
|
|
29737
30140
|
hasTests: hasTests2,
|
|
29738
30141
|
diagnostics,
|
|
29739
30142
|
sdkVersion,
|
|
29740
|
-
optimizerVersion: "1.1.
|
|
30143
|
+
optimizerVersion: "1.1.71",
|
|
29741
30144
|
...Object.fromEntries(
|
|
29742
30145
|
configOptionsToCheck.map((option) => [option, config[option]])
|
|
29743
30146
|
)
|
|
@@ -29751,7 +30154,7 @@ function getProjectAnalysis(targets, analysis, manifestXML, options) {
|
|
|
29751
30154
|
return getConfig(options).then(
|
|
29752
30155
|
(options2) => getProjectAnalysisHelper(targets, analysis, manifestXML, options2)
|
|
29753
30156
|
).catch(
|
|
29754
|
-
(ex) => Promise.reject(ex instanceof
|
|
30157
|
+
(ex) => Promise.reject(ex instanceof import_chunk_NHZRKHZO.AwaitedError ? ex.resolve() : ex)
|
|
29755
30158
|
);
|
|
29756
30159
|
}
|
|
29757
30160
|
async function getProjectAnalysisHelper(targets, analysis, manifestXML, options) {
|
|
@@ -29849,49 +30252,12 @@ async function getFnMapAnalysis(fnMap, resourcesMap, manifestXML, options) {
|
|
|
29849
30252
|
if (Object.values(fnMap).every(({ ast }) => ast != null)) {
|
|
29850
30253
|
reportMissingSymbols(state, options);
|
|
29851
30254
|
}
|
|
29852
|
-
|
|
29853
|
-
if (state.config?.propagateTypes && state.config.trustDeclaredTypes && state.config.checkTypes !== "OFF") {
|
|
29854
|
-
const gistate = {
|
|
29855
|
-
state,
|
|
29856
|
-
stack: [],
|
|
29857
|
-
typeChecker: state.config.strictTypeCheck?.toLowerCase() === "on" ? subtypeOf : couldBeWeak,
|
|
29858
|
-
checkTypes: state.config?.checkTypes || "WARNING"
|
|
29859
|
-
};
|
|
29860
|
-
state.pre = (node) => {
|
|
29861
|
-
switch (node.type) {
|
|
29862
|
-
case "FunctionDeclaration": {
|
|
29863
|
-
const self = state.top().sn;
|
|
29864
|
-
const istate = buildTypeInfo(state, self, false);
|
|
29865
|
-
if (istate) {
|
|
29866
|
-
istate.state = state;
|
|
29867
|
-
istate.typeChecker = gistate.typeChecker;
|
|
29868
|
-
istate.checkTypes = gistate.checkTypes;
|
|
29869
|
-
evaluate(istate, node.body);
|
|
29870
|
-
if (istate.typeMap) {
|
|
29871
|
-
if (typeMap == null) {
|
|
29872
|
-
typeMap = istate.typeMap;
|
|
29873
|
-
} else {
|
|
29874
|
-
istate.typeMap.forEach(
|
|
29875
|
-
(value2, key) => typeMap.set(key, value2)
|
|
29876
|
-
);
|
|
29877
|
-
}
|
|
29878
|
-
}
|
|
29879
|
-
}
|
|
29880
|
-
return [];
|
|
29881
|
-
}
|
|
29882
|
-
}
|
|
29883
|
-
return null;
|
|
29884
|
-
};
|
|
29885
|
-
Object.values(state.fnMap).forEach((f) => {
|
|
29886
|
-
f.ast && collectNamespaces(f.ast, state);
|
|
29887
|
-
});
|
|
29888
|
-
delete state.pre;
|
|
29889
|
-
}
|
|
30255
|
+
const typeMap = await analyze_module_types(state);
|
|
29890
30256
|
const diagnostics = state.diagnostics && await resolveDiagnosticsMap(state.diagnostics);
|
|
29891
30257
|
if (state.config?.checkBuildPragmas) {
|
|
29892
|
-
Object.entries(fnMap).forEach(
|
|
29893
|
-
pragmaChecker(state, f.ast, diagnostics?.[name])
|
|
29894
|
-
|
|
30258
|
+
Object.entries(fnMap).forEach(
|
|
30259
|
+
([name, f]) => f.ast && pragmaChecker(state, f.ast, diagnostics?.[name])
|
|
30260
|
+
);
|
|
29895
30261
|
}
|
|
29896
30262
|
return { fnMap, state, typeMap };
|
|
29897
30263
|
}
|
|
@@ -29907,11 +30273,9 @@ var init_optimizer = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
29907
30273
|
init_mc_rewrite();
|
|
29908
30274
|
init_pragma_checker();
|
|
29909
30275
|
init_sdk_util();
|
|
29910
|
-
init_type_flow();
|
|
29911
|
-
init_could_be();
|
|
29912
30276
|
init_interp();
|
|
29913
|
-
|
|
29914
|
-
(0,
|
|
30277
|
+
init_module_types();
|
|
30278
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
29915
30279
|
init_worker_pool();
|
|
29916
30280
|
init_optimizer_types();
|
|
29917
30281
|
init_types();
|
|
@@ -29971,7 +30335,7 @@ async function performTask(task) {
|
|
|
29971
30335
|
throw new Error(`Invalid task type ${type}`);
|
|
29972
30336
|
}
|
|
29973
30337
|
return Promise.resolve(handler(task.data)).then(
|
|
29974
|
-
(result) =>
|
|
30338
|
+
(result) => import_chunk_NHZRKHZO.logPromise.then(() => result)
|
|
29975
30339
|
);
|
|
29976
30340
|
}
|
|
29977
30341
|
var workerTaskHandlers;
|
|
@@ -29981,7 +30345,7 @@ var init_worker_task = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
29981
30345
|
init_optimizer();
|
|
29982
30346
|
init_readprg();
|
|
29983
30347
|
init_sdk_util();
|
|
29984
|
-
(0,
|
|
30348
|
+
(0, import_chunk_NHZRKHZO.init_logger)();
|
|
29985
30349
|
workerTaskHandlers = {
|
|
29986
30350
|
buildOptimizedProject(data) {
|
|
29987
30351
|
return buildOptimizedProject(data.product, data.options);
|
|
@@ -30199,7 +30563,7 @@ async function optimizeProgram(filepath, devKey, output, config) {
|
|
|
30199
30563
|
}
|
|
30200
30564
|
function optimizeProgramBuffer(filepath, view, debugXml, apiDebugXml, key, config) {
|
|
30201
30565
|
const { sections } = readPrgWithOffsets(view);
|
|
30202
|
-
(0,
|
|
30566
|
+
(0, import_chunk_NHZRKHZO.logger)("readprg", 5, sections);
|
|
30203
30567
|
const symbolTable = new SymbolTable();
|
|
30204
30568
|
if ((0, import_chunk_JDC43A3I.hasProperty)(sections, 1461170197 .toString())) {
|
|
30205
30569
|
symbolTable.parse(sections[
|
|
@@ -30499,7 +30863,7 @@ var init_readprg = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
30499
30863
|
init_signer();
|
|
30500
30864
|
init_symbols();
|
|
30501
30865
|
init_sdk_util();
|
|
30502
|
-
(0,
|
|
30866
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
30503
30867
|
init_worker_pool();
|
|
30504
30868
|
}
|
|
30505
30869
|
});
|
|
@@ -30511,7 +30875,7 @@ function getSdkPath() {
|
|
|
30511
30875
|
});
|
|
30512
30876
|
}
|
|
30513
30877
|
async function getDeviceInfo() {
|
|
30514
|
-
const files = await (0,
|
|
30878
|
+
const files = await (0, import_chunk_NHZRKHZO.globa)(`${connectiq}/Devices/*/compiler.json`);
|
|
30515
30879
|
if (!files.length) {
|
|
30516
30880
|
throw new Error(
|
|
30517
30881
|
`No devices found at '${connectiq}/Devices'. Check your sdk is correctly installed`
|
|
@@ -30579,7 +30943,7 @@ async function getFunctionDocumentation() {
|
|
|
30579
30943
|
var isWin, appSupport, connectiq;
|
|
30580
30944
|
var init_sdk_util = (0, import_chunk_ABYVSU2C.__esm)({
|
|
30581
30945
|
"src/sdk-util.ts"() {
|
|
30582
|
-
(0,
|
|
30946
|
+
(0, import_chunk_NHZRKHZO.init_util)();
|
|
30583
30947
|
init_xml_util();
|
|
30584
30948
|
init_readprg();
|
|
30585
30949
|
init_bytecode();
|
|
@@ -30634,6 +30998,7 @@ var init_sdk_util = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
30634
30998
|
getSdkPath,
|
|
30635
30999
|
getSuperClasses,
|
|
30636
31000
|
get_jungle,
|
|
31001
|
+
handleImportUsing,
|
|
30637
31002
|
init_api,
|
|
30638
31003
|
init_bytecode,
|
|
30639
31004
|
init_could_be,
|
|
@@ -30679,6 +31044,8 @@ var init_sdk_util = (0, import_chunk_ABYVSU2C.__esm)({
|
|
|
30679
31044
|
parseSdkVersion,
|
|
30680
31045
|
parseXml,
|
|
30681
31046
|
performTask,
|
|
31047
|
+
popRootNode,
|
|
31048
|
+
pushRootNode,
|
|
30682
31049
|
readPrg,
|
|
30683
31050
|
readPrgWithOffsets,
|
|
30684
31051
|
resolveDiagnostics,
|