@markw65/monkeyc-optimizer 1.1.13 → 1.1.15

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.
@@ -1,4 +1,4 @@
1
- 0 && (module.exports = {buildOptimizedProject,copyRecursiveAsNeeded,defaultConfig,display,generateApiMirTests,generateOptimizedProject,getProjectAnalysis,get_jungle,isErrorWithLocation,launchSimulator,manifestProducts,mctree,simulateProgram});
1
+ 0 && (module.exports = {buildOptimizedProject,copyRecursiveAsNeeded,defaultConfig,display,generateApiMirTests,generateOptimizedProject,getConfig,getProjectAnalysis,get_jungle,isErrorWithLocation,launchSimulator,manifestProducts,mctree,simulateProgram});
2
2
  /******/ (() => { // webpackBootstrap
3
3
  /******/ var __webpack_modules__ = ({
4
4
 
@@ -3416,6 +3416,7 @@ __webpack_require__.d(__webpack_exports__, {
3416
3416
  "display": () => (/* reexport */ display),
3417
3417
  "generateApiMirTests": () => (/* binding */ generateApiMirTests),
3418
3418
  "generateOptimizedProject": () => (/* binding */ generateOptimizedProject),
3419
+ "getConfig": () => (/* binding */ getConfig),
3419
3420
  "getProjectAnalysis": () => (/* binding */ getProjectAnalysis),
3420
3421
  "get_jungle": () => (/* reexport */ get_jungle),
3421
3422
  "isErrorWithLocation": () => (/* binding */ isErrorWithLocation),
@@ -4523,7 +4524,13 @@ async function launchSimulator(force = true) {
4523
4524
  if (!force && (await checkIfSimulatorRunning()))
4524
4525
  return;
4525
4526
  const sdk = await (0,external_sdk_util_cjs_namespaceObject.getSdkPath)();
4526
- const child = (0,external_child_process_namespaceObject.execFile)(external_path_.resolve(sdk, "bin", external_sdk_util_cjs_namespaceObject.isWin ? "simulator" : "connectiq"));
4527
+ const child = force || process.platform !== "darwin"
4528
+ ? (0,external_child_process_namespaceObject.execFile)(external_path_.resolve(sdk, "bin", external_sdk_util_cjs_namespaceObject.isWin ? "simulator" : "connectiq"))
4529
+ : (0,external_child_process_namespaceObject.execFile)("/usr/bin/open", [
4530
+ "-g",
4531
+ "-a",
4532
+ external_path_.resolve(sdk, "bin", "ConnectIQ.App", "Contents/MacOS/simulator"),
4533
+ ]);
4527
4534
  child.unref();
4528
4535
  for (let i = 0;; i++) {
4529
4536
  if (await checkIfSimulatorRunning())
@@ -5380,8 +5387,9 @@ function inlineRequested(state, func) {
5380
5387
  return false;
5381
5388
  }
5382
5389
  function shouldInline(state, func, call, context) {
5383
- if (state.inlining)
5390
+ if (state.inlining || (state.localsStack?.length ?? 0) <= 1) {
5384
5391
  return false;
5392
+ }
5385
5393
  let autoInline = false;
5386
5394
  let inlineAsExpression = false;
5387
5395
  const args = call.arguments;
@@ -15641,33 +15649,6 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
15641
15649
  return result;
15642
15650
  };
15643
15651
  const topLocals = () => state.localsStack[state.localsStack.length - 1];
15644
- /*
15645
- * Might this function be called from somewhere, including
15646
- * callbacks from the api (eg getSettingsView, etc).
15647
- */
15648
- const maybeCalled = (func) => {
15649
- if (!func.body) {
15650
- // this is an api.mir function. It can be called
15651
- return true;
15652
- }
15653
- if ((0,external_api_cjs_namespaceObject.hasProperty)(state.exposed, func.id.name))
15654
- return true;
15655
- if (func.attrs &&
15656
- func.attrs.attributes &&
15657
- func.attrs.attributes.elements.some((attr) => {
15658
- if (attr.type !== "UnaryExpression")
15659
- return false;
15660
- if (attr.argument.type !== "Identifier")
15661
- return false;
15662
- return attr.argument.name === "test";
15663
- })) {
15664
- return true;
15665
- }
15666
- if ((0,external_api_cjs_namespaceObject.hasProperty)(state.calledFunctions, func.id.name)) {
15667
- return (state.calledFunctions[func.id.name].find((f) => f === func) !== null);
15668
- }
15669
- return false;
15670
- };
15671
15652
  /*
15672
15653
  * Does elm (a class) have a maybeCalled function called name,
15673
15654
  * anywhere in its superClass chain.
@@ -15677,7 +15658,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
15677
15658
  elm.superClass.some((sc) => ((0,external_api_cjs_namespaceObject.hasProperty)(sc.decls, name) &&
15678
15659
  sc.decls[name].some((f) => (0,external_api_cjs_namespaceObject.isStateNode)(f) &&
15679
15660
  f.type === "FunctionDeclaration" &&
15680
- maybeCalled(f.node))) ||
15661
+ maybeCalled(state, f.node))) ||
15681
15662
  (sc.superClass && checkInherited(sc, name))));
15682
15663
  const renamer = (idnode) => {
15683
15664
  const ident = idnode.type === "Identifier" ? idnode : idnode.left;
@@ -15878,7 +15859,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
15878
15859
  }
15879
15860
  istate = is;
15880
15861
  }
15881
- if (parent.type === "ClassDeclaration" && !maybeCalled(node)) {
15862
+ if (parent.type === "ClassDeclaration" && !maybeCalled(state, node)) {
15882
15863
  let used = false;
15883
15864
  if (node.id.name === "initialize") {
15884
15865
  used = true;
@@ -16080,15 +16061,31 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
16080
16061
  Object.values(fnMap).forEach((f) => {
16081
16062
  (0,external_api_cjs_namespaceObject.collectNamespaces)(f.ast, state);
16082
16063
  });
16083
- state.usedByName = {};
16084
- state.calledFunctions = {};
16085
- state.exposed = state.nextExposed;
16086
- state.nextExposed = {};
16087
- Object.values(fnMap).forEach((f) => {
16088
- (0,external_api_cjs_namespaceObject.collectNamespaces)(f.ast, state);
16089
- });
16090
- state.exposed = state.nextExposed;
16091
- state.nextExposed = {};
16064
+ const cleanupAll = () => Object.values(fnMap).reduce((changes, f) => {
16065
+ traverseAst(f.ast, undefined, (node) => {
16066
+ const ret = cleanup(state, node, f.ast);
16067
+ if (ret === false) {
16068
+ changes = true;
16069
+ state.removeNodeComments(node, f.ast);
16070
+ }
16071
+ else if (ret) {
16072
+ changes = true;
16073
+ }
16074
+ return ret;
16075
+ });
16076
+ return changes;
16077
+ }, false);
16078
+ do {
16079
+ state.usedByName = {};
16080
+ state.calledFunctions = {};
16081
+ state.exposed = state.nextExposed;
16082
+ state.nextExposed = {};
16083
+ Object.values(fnMap).forEach((f) => {
16084
+ (0,external_api_cjs_namespaceObject.collectNamespaces)(f.ast, state);
16085
+ });
16086
+ state.exposed = state.nextExposed;
16087
+ state.nextExposed = {};
16088
+ } while (cleanupAll() && state.config?.iterateOptimizer);
16092
16089
  delete state.pre;
16093
16090
  delete state.post;
16094
16091
  if (state.config?.minimizeModules ?? true) {
@@ -16097,108 +16094,7 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
16097
16094
  });
16098
16095
  }
16099
16096
  Object.values(state.allFunctions).forEach((fns) => fns.forEach((fn) => sizeBasedPRE(state, fn)));
16100
- const cleanup = (node) => {
16101
- switch (node.type) {
16102
- case "ThisExpression":
16103
- node.text = "self";
16104
- break;
16105
- case "EnumStringBody":
16106
- if (node.members.every((m) => {
16107
- const name = "name" in m ? m.name : m.id.name;
16108
- return ((0,external_api_cjs_namespaceObject.hasProperty)(state.index, name) &&
16109
- !(0,external_api_cjs_namespaceObject.hasProperty)(state.exposed, name) &&
16110
- !(0,external_api_cjs_namespaceObject.hasProperty)(state.usedByName, name));
16111
- })) {
16112
- node.enumType = [
16113
- ...new Set(node.members.map((m) => {
16114
- if (!("init" in m))
16115
- return "Number";
16116
- const [node, type] = getNodeValue(m.init);
16117
- if (!node) {
16118
- throw new Error("Failed to get type for eliminated enum");
16119
- }
16120
- return type;
16121
- })),
16122
- ].join(" or ");
16123
- node.members.splice(0);
16124
- }
16125
- break;
16126
- case "EnumDeclaration":
16127
- if (!node.body.members.length) {
16128
- if (!node.id)
16129
- return false;
16130
- if (!node.body.enumType) {
16131
- throw new Error("Missing enumType on optimized enum");
16132
- }
16133
- return {
16134
- type: "TypedefDeclaration",
16135
- id: node.id,
16136
- ts: {
16137
- type: "UnaryExpression",
16138
- argument: {
16139
- type: "TypeSpecList",
16140
- ts: [
16141
- node.body.enumType,
16142
- ],
16143
- },
16144
- prefix: true,
16145
- operator: " as",
16146
- },
16147
- };
16148
- }
16149
- break;
16150
- case "VariableDeclaration": {
16151
- node.declarations = node.declarations.filter((d) => {
16152
- const name = (0,external_api_cjs_namespaceObject.variableDeclarationName)(d.id);
16153
- return (!(0,external_api_cjs_namespaceObject.hasProperty)(state.index, name) ||
16154
- (0,external_api_cjs_namespaceObject.hasProperty)(state.exposed, name) ||
16155
- (0,external_api_cjs_namespaceObject.hasProperty)(state.usedByName, name));
16156
- });
16157
- if (!node.declarations.length) {
16158
- return false;
16159
- }
16160
- break;
16161
- }
16162
- case "ClassElement":
16163
- if (!node.item) {
16164
- return false;
16165
- }
16166
- break;
16167
- case "FunctionDeclaration":
16168
- if (!maybeCalled(node)) {
16169
- if (node.attrs &&
16170
- node.attrs.attributes &&
16171
- node.attrs.attributes.elements.some((attr) => attr.type === "UnaryExpression" && attr.argument.name === "keep")) {
16172
- break;
16173
- }
16174
- return false;
16175
- }
16176
- break;
16177
- case "ClassDeclaration":
16178
- case "ModuleDeclaration":
16179
- // none of the attributes means anything on classes and
16180
- // modules, and the new compiler complains about some
16181
- // of them. Just drop them all.
16182
- if (node.attrs && node.attrs.access) {
16183
- if (node.attrs.attributes) {
16184
- delete node.attrs.access;
16185
- }
16186
- else {
16187
- delete node.attrs;
16188
- }
16189
- }
16190
- }
16191
- return null;
16192
- };
16193
- Object.entries(fnMap).forEach(([, f]) => {
16194
- traverseAst(f.ast, undefined, (node) => {
16195
- const ret = cleanup(node);
16196
- if (ret === false) {
16197
- state.removeNodeComments(node, f.ast);
16198
- }
16199
- return ret;
16200
- });
16201
- });
16097
+ cleanupAll();
16202
16098
  config.checkCompilerLookupRules = checkLookupRules;
16203
16099
  reportMissingSymbols(state, config);
16204
16100
  if (state.inlineDiagnostics) {
@@ -16224,6 +16120,129 @@ async function optimizeMonkeyC(fnMap, resourcesMap, manifestXML, config) {
16224
16120
  });
16225
16121
  return state.diagnostics;
16226
16122
  }
16123
+ /*
16124
+ * Might this function be called from somewhere, including
16125
+ * callbacks from the api (eg getSettingsView, etc).
16126
+ */
16127
+ function maybeCalled(state, func) {
16128
+ if (!func.body) {
16129
+ // this is an api.mir function. It can be called
16130
+ return true;
16131
+ }
16132
+ if ((0,external_api_cjs_namespaceObject.hasProperty)(state.exposed, func.id.name))
16133
+ return true;
16134
+ if (func.attrs &&
16135
+ func.attrs.attributes &&
16136
+ func.attrs.attributes.elements.some((attr) => {
16137
+ if (attr.type !== "UnaryExpression")
16138
+ return false;
16139
+ if (attr.argument.type !== "Identifier")
16140
+ return false;
16141
+ return attr.argument.name === "test";
16142
+ })) {
16143
+ return true;
16144
+ }
16145
+ if ((0,external_api_cjs_namespaceObject.hasProperty)(state.calledFunctions, func.id.name)) {
16146
+ return state.calledFunctions[func.id.name].find((f) => f === func) !== null;
16147
+ }
16148
+ return false;
16149
+ }
16150
+ function cleanup(state, node, ast) {
16151
+ switch (node.type) {
16152
+ case "ThisExpression":
16153
+ node.text = "self";
16154
+ break;
16155
+ case "EnumStringBody":
16156
+ if (node.members.every((m) => {
16157
+ const name = "name" in m ? m.name : m.id.name;
16158
+ return ((0,external_api_cjs_namespaceObject.hasProperty)(state.index, name) &&
16159
+ !(0,external_api_cjs_namespaceObject.hasProperty)(state.exposed, name) &&
16160
+ !(0,external_api_cjs_namespaceObject.hasProperty)(state.usedByName, name));
16161
+ })) {
16162
+ node.enumType = [
16163
+ ...new Set(node.members.map((m) => {
16164
+ if (!("init" in m))
16165
+ return "Number";
16166
+ const [node, type] = getNodeValue(m.init);
16167
+ if (!node) {
16168
+ throw new Error("Failed to get type for eliminated enum");
16169
+ }
16170
+ return type;
16171
+ })),
16172
+ ].join(" or ");
16173
+ node.members.splice(0);
16174
+ }
16175
+ break;
16176
+ case "EnumDeclaration":
16177
+ if (!node.body.members.length) {
16178
+ if (!node.id)
16179
+ return false;
16180
+ if (!node.body.enumType) {
16181
+ throw new Error("Missing enumType on optimized enum");
16182
+ }
16183
+ state.removeNodeComments(node, ast);
16184
+ return withLocDeep({
16185
+ type: "TypedefDeclaration",
16186
+ id: node.id,
16187
+ ts: {
16188
+ type: "UnaryExpression",
16189
+ argument: {
16190
+ type: "TypeSpecList",
16191
+ ts: [
16192
+ node.body.enumType,
16193
+ ],
16194
+ },
16195
+ prefix: true,
16196
+ operator: " as",
16197
+ },
16198
+ }, node, node);
16199
+ }
16200
+ break;
16201
+ case "VariableDeclarator": {
16202
+ const name = (0,external_api_cjs_namespaceObject.variableDeclarationName)(node.id);
16203
+ return !(0,external_api_cjs_namespaceObject.hasProperty)(state.index, name) ||
16204
+ (0,external_api_cjs_namespaceObject.hasProperty)(state.exposed, name) ||
16205
+ (0,external_api_cjs_namespaceObject.hasProperty)(state.usedByName, name)
16206
+ ? null
16207
+ : false;
16208
+ }
16209
+ case "VariableDeclaration": {
16210
+ if (!node.declarations.length) {
16211
+ return false;
16212
+ }
16213
+ break;
16214
+ }
16215
+ case "ClassElement":
16216
+ if (!node.item) {
16217
+ return false;
16218
+ }
16219
+ break;
16220
+ case "FunctionDeclaration":
16221
+ if (!maybeCalled(state, node)) {
16222
+ if (node.attrs &&
16223
+ node.attrs.attributes &&
16224
+ node.attrs.attributes.elements.some((attr) => attr.type === "UnaryExpression" && attr.argument.name === "keep")) {
16225
+ break;
16226
+ }
16227
+ return false;
16228
+ }
16229
+ break;
16230
+ case "ClassDeclaration":
16231
+ case "ModuleDeclaration":
16232
+ // none of the attributes means anything on classes and
16233
+ // modules, and the new compiler complains about some
16234
+ // of them. Just drop them all.
16235
+ if (node.attrs && node.attrs.access) {
16236
+ if (node.attrs.attributes) {
16237
+ delete node.attrs.access;
16238
+ }
16239
+ else {
16240
+ delete node.attrs;
16241
+ }
16242
+ }
16243
+ }
16244
+ return null;
16245
+ }
16227
16246
  function optimizeCall(istate, node, context) {
16228
16247
  const state = istate.state;
16229
16248
  const [name, results] = state.lookupNonlocal(node.callee);
@@ -16745,6 +16764,7 @@ const configOptionsToCheck = [
16745
16764
  "extensionVersion",
16746
16765
  "typeCheckLevel",
16747
16766
  "covarianceWarnings",
16767
+ "iterateOptimizer",
16748
16768
  ];
16749
16769
  /**
16750
16770
  * @param {BuildConfig} config
@@ -16803,7 +16823,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
16803
16823
  // the oldest optimized file, we don't need to regenerate
16804
16824
  const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(Object.keys(fnMap).concat(dependencyFiles));
16805
16825
  const opt_time = await (0,external_util_cjs_namespaceObject.first_modified)(Object.values(fnMap).map((v) => v.output));
16806
- if (source_time < opt_time && 1676335488374 < opt_time) {
16826
+ if (source_time < opt_time && 1677202119524 < opt_time) {
16807
16827
  return { hasTests, diagnostics: prevDiagnostics };
16808
16828
  }
16809
16829
  }
@@ -16830,7 +16850,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
16830
16850
  return promises_namespaceObject.writeFile(external_path_.join(output, "build-info.json"), JSON.stringify({
16831
16851
  hasTests,
16832
16852
  diagnostics,
16833
- optimizerVersion: "1.1.13",
16853
+ optimizerVersion: "1.1.15",
16834
16854
  ...Object.fromEntries(configOptionsToCheck.map((option) => [option, config[option]])),
16835
16855
  }))
16836
16856
  .then(() => ({ hasTests, diagnostics }));