@markw65/monkeyc-optimizer 1.1.49 → 1.1.50

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 CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to the "monkeyc-optimizer" package will be documented in this file.
4
4
 
5
+ ### 1.1.50
6
+
7
+ - Add a diagnostic when an inline function doesn't get removed
8
+ - No diagnostics for String + Symbol, or String + Method, or String + Object, or String + Enum (Fixes #9)
9
+ - Fix a bug in minimizeLocals (Fixes #15)
10
+
5
11
  ### 1.1.49
6
12
 
7
13
  - Fix a bug in cleanupUnusedVars that could cause the wrong variable to be removed
File without changes
package/build/api.cjs CHANGED
@@ -18,47 +18,47 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var api_exports = {};
20
20
  __export(api_exports, {
21
- checkCompilerVersion: () => import_chunk_DZ7YMTUE.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_DZ7YMTUE.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_DZ7YMTUE.createDocumentationMap,
24
- diagnostic: () => import_chunk_DZ7YMTUE.diagnostic,
25
- diagnosticHelper: () => import_chunk_DZ7YMTUE.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_DZ7YMTUE.findNamesInScope,
27
- findUsingForNode: () => import_chunk_DZ7YMTUE.findUsingForNode,
28
- formatAst: () => import_chunk_DZ7YMTUE.formatAst,
29
- formatAstLongLines: () => import_chunk_DZ7YMTUE.formatAstLongLines,
30
- formatScopedName: () => import_chunk_DZ7YMTUE.formatScopedName,
31
- getApiFunctionInfo: () => import_chunk_DZ7YMTUE.getApiFunctionInfo,
32
- getApiMapping: () => import_chunk_DZ7YMTUE.getApiMapping,
33
- getSuperClasses: () => import_chunk_DZ7YMTUE.getSuperClasses,
21
+ checkCompilerVersion: () => import_chunk_6KP65YOB.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_6KP65YOB.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_6KP65YOB.createDocumentationMap,
24
+ diagnostic: () => import_chunk_6KP65YOB.diagnostic,
25
+ diagnosticHelper: () => import_chunk_6KP65YOB.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_6KP65YOB.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_6KP65YOB.findUsingForNode,
28
+ formatAst: () => import_chunk_6KP65YOB.formatAst,
29
+ formatAstLongLines: () => import_chunk_6KP65YOB.formatAstLongLines,
30
+ formatScopedName: () => import_chunk_6KP65YOB.formatScopedName,
31
+ getApiFunctionInfo: () => import_chunk_6KP65YOB.getApiFunctionInfo,
32
+ getApiMapping: () => import_chunk_6KP65YOB.getApiMapping,
33
+ getSuperClasses: () => import_chunk_6KP65YOB.getSuperClasses,
34
34
  hasProperty: () => import_chunk_MBTLUWXR.hasProperty,
35
- isClassVariable: () => import_chunk_DZ7YMTUE.isClassVariable,
36
- isLocal: () => import_chunk_DZ7YMTUE.isLocal,
37
- isLookupCandidate: () => import_chunk_DZ7YMTUE.isLookupCandidate,
38
- isStateNode: () => import_chunk_DZ7YMTUE.isStateNode,
39
- lookupByFullName: () => import_chunk_DZ7YMTUE.lookupByFullName,
40
- lookupNext: () => import_chunk_DZ7YMTUE.lookupNext,
41
- lookupResultContains: () => import_chunk_DZ7YMTUE.lookupResultContains,
42
- lookupWithType: () => import_chunk_DZ7YMTUE.lookupWithType,
43
- makeToyboxLink: () => import_chunk_DZ7YMTUE.makeToyboxLink,
44
- mapVarDeclsByType: () => import_chunk_DZ7YMTUE.mapVarDeclsByType,
45
- markInvokeClassMethod: () => import_chunk_DZ7YMTUE.markInvokeClassMethod,
46
- parseSdkVersion: () => import_chunk_DZ7YMTUE.parseSdkVersion,
47
- resolveDiagnostics: () => import_chunk_DZ7YMTUE.resolveDiagnostics,
48
- resolveDiagnosticsMap: () => import_chunk_DZ7YMTUE.resolveDiagnosticsMap,
49
- sameLookupResult: () => import_chunk_DZ7YMTUE.sameLookupResult,
35
+ isClassVariable: () => import_chunk_6KP65YOB.isClassVariable,
36
+ isLocal: () => import_chunk_6KP65YOB.isLocal,
37
+ isLookupCandidate: () => import_chunk_6KP65YOB.isLookupCandidate,
38
+ isStateNode: () => import_chunk_6KP65YOB.isStateNode,
39
+ lookupByFullName: () => import_chunk_6KP65YOB.lookupByFullName,
40
+ lookupNext: () => import_chunk_6KP65YOB.lookupNext,
41
+ lookupResultContains: () => import_chunk_6KP65YOB.lookupResultContains,
42
+ lookupWithType: () => import_chunk_6KP65YOB.lookupWithType,
43
+ makeToyboxLink: () => import_chunk_6KP65YOB.makeToyboxLink,
44
+ mapVarDeclsByType: () => import_chunk_6KP65YOB.mapVarDeclsByType,
45
+ markInvokeClassMethod: () => import_chunk_6KP65YOB.markInvokeClassMethod,
46
+ parseSdkVersion: () => import_chunk_6KP65YOB.parseSdkVersion,
47
+ resolveDiagnostics: () => import_chunk_6KP65YOB.resolveDiagnostics,
48
+ resolveDiagnosticsMap: () => import_chunk_6KP65YOB.resolveDiagnosticsMap,
49
+ sameLookupResult: () => import_chunk_6KP65YOB.sameLookupResult,
50
50
  traverseAst: () => import_chunk_MBTLUWXR.traverseAst,
51
- variableDeclarationName: () => import_chunk_DZ7YMTUE.variableDeclarationName,
52
- visitReferences: () => import_chunk_DZ7YMTUE.visitReferences,
53
- visit_resources: () => import_chunk_DZ7YMTUE.visit_resources,
54
- visitorNode: () => import_chunk_DZ7YMTUE.visitorNode
51
+ variableDeclarationName: () => import_chunk_6KP65YOB.variableDeclarationName,
52
+ visitReferences: () => import_chunk_6KP65YOB.visitReferences,
53
+ visit_resources: () => import_chunk_6KP65YOB.visit_resources,
54
+ visitorNode: () => import_chunk_6KP65YOB.visitorNode
55
55
  });
56
56
  module.exports = __toCommonJS(api_exports);
57
- var import_chunk_DZ7YMTUE = require("./chunk-DZ7YMTUE.cjs");
57
+ var import_chunk_6KP65YOB = require("./chunk-6KP65YOB.cjs");
58
58
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
59
59
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
60
60
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
61
- (0, import_chunk_DZ7YMTUE.init_api)();
61
+ (0, import_chunk_6KP65YOB.init_api)();
62
62
  // Annotate the CommonJS export names for ESM import in node:
63
63
  0 && (module.exports = {
64
64
  checkCompilerVersion,
@@ -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 chunk_DZ7YMTUE_exports = {};
30
- __export(chunk_DZ7YMTUE_exports, {
29
+ var chunk_6KP65YOB_exports = {};
30
+ __export(chunk_6KP65YOB_exports, {
31
31
  EnumTagsConst: () => EnumTagsConst,
32
32
  LastTypeTag: () => LastTypeTag,
33
33
  ObjectLikeTagsConst: () => ObjectLikeTagsConst,
@@ -133,7 +133,7 @@ __export(chunk_DZ7YMTUE_exports, {
133
133
  visitorNode: () => visitorNode,
134
134
  xml_util_exports: () => xml_util_exports
135
135
  });
136
- module.exports = __toCommonJS(chunk_DZ7YMTUE_exports);
136
+ module.exports = __toCommonJS(chunk_6KP65YOB_exports);
137
137
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
138
138
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
139
139
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
@@ -5828,15 +5828,18 @@ function inliningLooksUseful(func, node) {
5828
5828
  }
5829
5829
  return false;
5830
5830
  }
5831
- function inlineRequested(state, func) {
5832
- const excludeAnnotations = func.node.loc?.source && state.fnMap[func.node.loc?.source]?.excludeAnnotations || {};
5833
- if (func.node.attrs && func.node.attrs.attributes && func.node.attrs.attributes.elements.some(
5831
+ function inlineRequestedNode(state, func) {
5832
+ const excludeAnnotations = func.loc?.source && state.fnMap[func.loc?.source]?.excludeAnnotations || {};
5833
+ if (func.attrs && func.attrs.attributes && func.attrs.attributes.elements.some(
5834
5834
  (attr) => attr.type === "UnaryExpression" && (attr.argument.name === "inline" || attr.argument.name.startsWith("inline_") && !(0, import_chunk_MBTLUWXR.hasProperty)(excludeAnnotations, attr.argument.name.substring(7)))
5835
5835
  )) {
5836
5836
  return true;
5837
5837
  }
5838
5838
  return false;
5839
5839
  }
5840
+ function inlineRequested(state, func) {
5841
+ return inlineRequestedNode(state, func.node);
5842
+ }
5840
5843
  function shouldInline(state, func, call, context) {
5841
5844
  if (state.inlining || (state.localsStack?.length ?? 0) <= 1) {
5842
5845
  return false;
@@ -6430,6 +6433,28 @@ function fixNodeScope(state, lookupNode, nodeStack) {
6430
6433
  }
6431
6434
  return null;
6432
6435
  }
6436
+ function reportFailedInlining(state, ast) {
6437
+ (0, import_chunk_MBTLUWXR.traverseAst)(ast, (node) => {
6438
+ switch (node.type) {
6439
+ case "FunctionDeclaration":
6440
+ if (inlineRequestedNode(state, node)) {
6441
+ if (!state.inlineDiagnostics) {
6442
+ state.inlineDiagnostics = {};
6443
+ }
6444
+ diagnosticHelper(
6445
+ state.inlineDiagnostics,
6446
+ node,
6447
+ `The inline function ${node.id.name} was not removed from the program`,
6448
+ "INFO",
6449
+ void 0
6450
+ );
6451
+ }
6452
+ return false;
6453
+ default:
6454
+ return null;
6455
+ }
6456
+ });
6457
+ }
6433
6458
  var init_inliner = (0, import_chunk_ABYVSU2C.__esm)({
6434
6459
  "src/inliner.ts"() {
6435
6460
  "use strict";
@@ -8355,7 +8380,7 @@ function common_types(left, right, allowed) {
8355
8380
  const types = left.type | right.type;
8356
8381
  let mask = (6 | 120) & allowed;
8357
8382
  if (types & allowed & 256) {
8358
- mask |= 256 | 6 | 128 | 1 | 1024 | 512;
8383
+ mask |= 256 | 6 | 128 | 1 | 1024 | 512 | 131072 | 32768 | 65536 | 2048;
8359
8384
  } else if (types & allowed & 128) {
8360
8385
  mask |= 128;
8361
8386
  }
@@ -14313,7 +14338,7 @@ function minimizeLocals(state, func) {
14313
14338
  case "AssignmentExpression":
14314
14339
  if (info) {
14315
14340
  (0, import_node_assert4.default)(node.left.type === "Identifier");
14316
- if (node.right.type === "Identifier" && node.right.name === info.name) {
14341
+ if (node.right.type === "Identifier" && node.right.name === info.name && node.operator === "=") {
14317
14342
  return (0, import_chunk_MBTLUWXR.withLoc)(
14318
14343
  { type: "Literal", value: null, raw: "null" },
14319
14344
  node,
@@ -16988,6 +17013,9 @@ async function optimizeMonkeyCHelper(fnMap, resourcesMap, manifestXML, config) {
16988
17013
  cleanupAll();
16989
17014
  config.checkCompilerLookupRules = checkLookupRules;
16990
17015
  reportMissingSymbols(state, config);
17016
+ Object.values(fnMap).forEach(
17017
+ ({ ast }) => ast && reportFailedInlining(state, ast)
17018
+ );
16991
17019
  if (state.inlineDiagnostics) {
16992
17020
  if (!state.diagnostics) {
16993
17021
  state.diagnostics = state.inlineDiagnostics;
@@ -28528,7 +28556,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
28528
28556
  const opt_time = await (0, import_chunk_SG7ODKRM.first_modified)(
28529
28557
  Object.values(fnMap).map((v) => v.output)
28530
28558
  );
28531
- if (source_time < opt_time && 1710462159189 < opt_time) {
28559
+ if (source_time < opt_time && 1711236925504 < opt_time) {
28532
28560
  return {
28533
28561
  hasTests,
28534
28562
  diagnostics: prevDiagnostics,
@@ -28567,7 +28595,7 @@ async function generateOneConfig(buildConfig, manifestXML, dependencyFiles, conf
28567
28595
  hasTests: hasTests2,
28568
28596
  diagnostics,
28569
28597
  sdkVersion,
28570
- optimizerVersion: "1.1.49",
28598
+ optimizerVersion: "1.1.50",
28571
28599
  ...Object.fromEntries(
28572
28600
  configOptionsToCheck.map((option) => [option, config[option]])
28573
28601
  )
@@ -18,28 +18,28 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var optimizer_exports = {};
20
20
  __export(optimizer_exports, {
21
- StateNodeAttributes: () => import_chunk_DZ7YMTUE.StateNodeAttributes,
22
- buildOptimizedProject: () => import_chunk_DZ7YMTUE.buildOptimizedProject,
21
+ StateNodeAttributes: () => import_chunk_6KP65YOB.StateNodeAttributes,
22
+ buildOptimizedProject: () => import_chunk_6KP65YOB.buildOptimizedProject,
23
23
  copyRecursiveAsNeeded: () => import_chunk_SG7ODKRM.copyRecursiveAsNeeded,
24
- defaultConfig: () => import_chunk_DZ7YMTUE.defaultConfig,
25
- display: () => import_chunk_DZ7YMTUE.display,
26
- generateOneConfig: () => import_chunk_DZ7YMTUE.generateOneConfig,
27
- generateOptimizedProject: () => import_chunk_DZ7YMTUE.generateOptimizedProject,
28
- getConfig: () => import_chunk_DZ7YMTUE.getConfig,
29
- getProjectAnalysis: () => import_chunk_DZ7YMTUE.getProjectAnalysis,
30
- get_jungle: () => import_chunk_DZ7YMTUE.get_jungle,
31
- isErrorWithLocation: () => import_chunk_DZ7YMTUE.isErrorWithLocation,
32
- launchSimulator: () => import_chunk_DZ7YMTUE.launchSimulator,
33
- manifestProducts: () => import_chunk_DZ7YMTUE.manifestProducts,
34
- mctree: () => import_chunk_DZ7YMTUE.mctree,
35
- simulateProgram: () => import_chunk_DZ7YMTUE.simulateProgram
24
+ defaultConfig: () => import_chunk_6KP65YOB.defaultConfig,
25
+ display: () => import_chunk_6KP65YOB.display,
26
+ generateOneConfig: () => import_chunk_6KP65YOB.generateOneConfig,
27
+ generateOptimizedProject: () => import_chunk_6KP65YOB.generateOptimizedProject,
28
+ getConfig: () => import_chunk_6KP65YOB.getConfig,
29
+ getProjectAnalysis: () => import_chunk_6KP65YOB.getProjectAnalysis,
30
+ get_jungle: () => import_chunk_6KP65YOB.get_jungle,
31
+ isErrorWithLocation: () => import_chunk_6KP65YOB.isErrorWithLocation,
32
+ launchSimulator: () => import_chunk_6KP65YOB.launchSimulator,
33
+ manifestProducts: () => import_chunk_6KP65YOB.manifestProducts,
34
+ mctree: () => import_chunk_6KP65YOB.mctree,
35
+ simulateProgram: () => import_chunk_6KP65YOB.simulateProgram
36
36
  });
37
37
  module.exports = __toCommonJS(optimizer_exports);
38
- var import_chunk_DZ7YMTUE = require("./chunk-DZ7YMTUE.cjs");
38
+ var import_chunk_6KP65YOB = require("./chunk-6KP65YOB.cjs");
39
39
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
40
40
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
41
41
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
42
- (0, import_chunk_DZ7YMTUE.init_optimizer)();
42
+ (0, import_chunk_6KP65YOB.init_optimizer)();
43
43
  // Annotate the CommonJS export names for ESM import in node:
44
44
  0 && (module.exports = {
45
45
  StateNodeAttributes,
@@ -18,25 +18,25 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var sdk_util_exports = {};
20
20
  __export(sdk_util_exports, {
21
- SectionKinds: () => import_chunk_DZ7YMTUE.SectionKinds,
22
- appSupport: () => import_chunk_DZ7YMTUE.appSupport,
23
- connectiq: () => import_chunk_DZ7YMTUE.connectiq,
24
- getDeviceInfo: () => import_chunk_DZ7YMTUE.getDeviceInfo,
25
- getFunctionDocumentation: () => import_chunk_DZ7YMTUE.getFunctionDocumentation,
26
- getLanguages: () => import_chunk_DZ7YMTUE.getLanguages,
27
- getSdkPath: () => import_chunk_DZ7YMTUE.getSdkPath,
28
- isWin: () => import_chunk_DZ7YMTUE.isWin,
29
- optimizeProgram: () => import_chunk_DZ7YMTUE.optimizeProgram,
30
- readPrg: () => import_chunk_DZ7YMTUE.readPrg,
31
- readPrgWithOffsets: () => import_chunk_DZ7YMTUE.readPrgWithOffsets,
32
- xmlUtil: () => import_chunk_DZ7YMTUE.xml_util_exports
21
+ SectionKinds: () => import_chunk_6KP65YOB.SectionKinds,
22
+ appSupport: () => import_chunk_6KP65YOB.appSupport,
23
+ connectiq: () => import_chunk_6KP65YOB.connectiq,
24
+ getDeviceInfo: () => import_chunk_6KP65YOB.getDeviceInfo,
25
+ getFunctionDocumentation: () => import_chunk_6KP65YOB.getFunctionDocumentation,
26
+ getLanguages: () => import_chunk_6KP65YOB.getLanguages,
27
+ getSdkPath: () => import_chunk_6KP65YOB.getSdkPath,
28
+ isWin: () => import_chunk_6KP65YOB.isWin,
29
+ optimizeProgram: () => import_chunk_6KP65YOB.optimizeProgram,
30
+ readPrg: () => import_chunk_6KP65YOB.readPrg,
31
+ readPrgWithOffsets: () => import_chunk_6KP65YOB.readPrgWithOffsets,
32
+ xmlUtil: () => import_chunk_6KP65YOB.xml_util_exports
33
33
  });
34
34
  module.exports = __toCommonJS(sdk_util_exports);
35
- var import_chunk_DZ7YMTUE = require("./chunk-DZ7YMTUE.cjs");
35
+ var import_chunk_6KP65YOB = require("./chunk-6KP65YOB.cjs");
36
36
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
37
37
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
38
38
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
39
- (0, import_chunk_DZ7YMTUE.init_sdk_util)();
39
+ (0, import_chunk_6KP65YOB.init_sdk_util)();
40
40
  // Annotate the CommonJS export names for ESM import in node:
41
41
  0 && (module.exports = {
42
42
  SectionKinds,
@@ -10,4 +10,5 @@ export declare function inlineDiagnostic(state: ProgramStateAnalysis, func: Func
10
10
  export type InlineContext = mctree.ReturnStatement | mctree.IfStatement | mctree.AssignmentExpression | mctree.ExpressionStatement | mctree.VariableDeclarator;
11
11
  export declare function inlineFunction(state: ProgramStateAnalysis, func: FunctionStateNode, call: mctree.CallExpression, context: InlineContext | null): InlineBody | null;
12
12
  export declare function applyTypeIfNeeded(node: mctree.Node): mctree.Node;
13
+ export declare function reportFailedInlining(state: ProgramStateAnalysis, ast: mctree.Program): void;
13
14
  export {};
@@ -21,17 +21,17 @@ __export(worker_thread_exports, {
21
21
  default: () => worker_thread_default
22
22
  });
23
23
  module.exports = __toCommonJS(worker_thread_exports);
24
- var import_chunk_DZ7YMTUE = require("./chunk-DZ7YMTUE.cjs");
24
+ var import_chunk_6KP65YOB = require("./chunk-6KP65YOB.cjs");
25
25
  var import_chunk_SG7ODKRM = require("./chunk-SG7ODKRM.cjs");
26
26
  var import_chunk_MBTLUWXR = require("./chunk-MBTLUWXR.cjs");
27
27
  var import_chunk_ABYVSU2C = require("./chunk-ABYVSU2C.cjs");
28
28
  var import_node_worker_threads = require("node:worker_threads");
29
29
  var require_worker_thread = (0, import_chunk_ABYVSU2C.__commonJS)({
30
30
  "src/worker-thread.ts"() {
31
- (0, import_chunk_DZ7YMTUE.init_worker_task)();
31
+ (0, import_chunk_6KP65YOB.init_worker_task)();
32
32
  if (import_node_worker_threads.parentPort) {
33
33
  import_node_worker_threads.parentPort.on("message", async (task) => {
34
- return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_DZ7YMTUE.performTask)(task));
34
+ return import_node_worker_threads.parentPort.postMessage(await (0, import_chunk_6KP65YOB.performTask)(task));
35
35
  });
36
36
  }
37
37
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markw65/monkeyc-optimizer",
3
3
  "type": "commonjs",
4
- "version": "1.1.49",
4
+ "version": "1.1.50",
5
5
  "description": "Source to source optimizer for Garmin Monkey C code",
6
6
  "main": "build/optimizer.cjs",
7
7
  "types": "build/src/optimizer.d.ts",