@markw65/monkeyc-optimizer 1.1.19 → 1.1.21

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/README.md CHANGED
@@ -784,3 +784,30 @@ Bug Fixes
784
784
  - better optimization for arrays whose elements are all initialized to the same value (eg `[42, 42, 42, 42]`)
785
785
  - more efficient tests for symbols in case statements (ie `case: :foo`)
786
786
  - parallelize the post build optimizer when exporting a project
787
+
788
+ ### 1.1.20
789
+
790
+ - Bug fixes
791
+
792
+ - Fix a bug that could cause the optimizer to incorrectly substitute one local for another.
793
+
794
+ - Optimizations
795
+ - Improve dce in the post build optimizer a little, by computing which locals are live out of each block.
796
+
797
+ ### 1.1.20
798
+
799
+ - Bug fixes
800
+
801
+ - fixed a bug that could cause dead-store elimination to delete stores that might be used if an exception was thrown. eg `try { x=1; foo(); x=2; } catch (ex) { System.println(x); x=3; }` could delete the first store to `x`, breaking the println if `foo` actually throws.
802
+
803
+ - Source to Source Optimizations
804
+
805
+ - convert `++` and `--` to `+= 1` and `-= 1`. Garmin's compiler generates exactly the same code for both, but when the `1` is written explicitly, its available for `sizeBasedPRE` to optimize.
806
+ - convert `-x` to `0 - x`. Again, Garmin's compiler generates exactly the same code, but being explicit makes the `0` available to `sizeBasedPRE`.
807
+ - rewrite some optimizations so that `-x` and `0-x` are treated identically. eg `(0-x) + y` => `y - x` (for suitably typed `x` and `y`).
808
+ - optimize `-1 - x` to `~x` (for suitably typed x), saving 5 bytes (or 2 if pre was going to replace the -1 with a local)
809
+
810
+ - Post Build Optimizations
811
+ - Keep better track of exceptional edges in dce, allowing it to be more aggressive.
812
+ - Add a (very simple) bytecode interpreter which keeps track of the values in locals, and on the stack. This allows us to opportunistically replace constants (typically 5+ bytes) with a 2 byte load from a register, or from a stack location. This (together with dce) will form the infrastructure for a future minimize-locals pass.
813
+ - when replacing constants with locals/stack accesses, look for uses of `~`. Eg if the value `2` is in the local `x`, and we need to produce the value `-3`, we can use `~x` (costing 3 bytes, instead of 5).
package/build/api.cjs CHANGED
@@ -18,42 +18,42 @@ 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_O5LFMOIG.checkCompilerVersion,
22
- collectNamespaces: () => import_chunk_O5LFMOIG.collectNamespaces,
23
- createDocumentationMap: () => import_chunk_O5LFMOIG.createDocumentationMap,
24
- diagnostic: () => import_chunk_O5LFMOIG.diagnostic,
25
- diagnosticHelper: () => import_chunk_O5LFMOIG.diagnosticHelper,
26
- findNamesInScope: () => import_chunk_O5LFMOIG.findNamesInScope,
27
- findUsingForNode: () => import_chunk_O5LFMOIG.findUsingForNode,
28
- formatAst: () => import_chunk_O5LFMOIG.formatAst,
29
- formatAstLongLines: () => import_chunk_O5LFMOIG.formatAstLongLines,
30
- getApiFunctionInfo: () => import_chunk_O5LFMOIG.getApiFunctionInfo,
31
- getApiMapping: () => import_chunk_O5LFMOIG.getApiMapping,
32
- getSuperClasses: () => import_chunk_O5LFMOIG.getSuperClasses,
33
- hasProperty: () => import_chunk_O5LFMOIG.hasProperty,
34
- isClassVariable: () => import_chunk_O5LFMOIG.isClassVariable,
35
- isLocal: () => import_chunk_O5LFMOIG.isLocal,
36
- isLookupCandidate: () => import_chunk_O5LFMOIG.isLookupCandidate,
37
- isStateNode: () => import_chunk_O5LFMOIG.isStateNode,
38
- lookupByFullName: () => import_chunk_O5LFMOIG.lookupByFullName,
39
- lookupNext: () => import_chunk_O5LFMOIG.lookupNext,
40
- lookupResultContains: () => import_chunk_O5LFMOIG.lookupResultContains,
41
- lookupWithType: () => import_chunk_O5LFMOIG.lookupWithType,
42
- makeToyboxLink: () => import_chunk_O5LFMOIG.makeToyboxLink,
43
- mapVarDeclsByType: () => import_chunk_O5LFMOIG.mapVarDeclsByType,
44
- markInvokeClassMethod: () => import_chunk_O5LFMOIG.markInvokeClassMethod,
45
- parseSdkVersion: () => import_chunk_O5LFMOIG.parseSdkVersion,
46
- sameLookupResult: () => import_chunk_O5LFMOIG.sameLookupResult,
47
- traverseAst: () => import_chunk_O5LFMOIG.traverseAst,
48
- variableDeclarationName: () => import_chunk_O5LFMOIG.variableDeclarationName,
49
- visitReferences: () => import_chunk_O5LFMOIG.visitReferences,
50
- visit_resources: () => import_chunk_O5LFMOIG.visit_resources,
51
- visitorNode: () => import_chunk_O5LFMOIG.visitorNode
21
+ checkCompilerVersion: () => import_chunk_ZDTW2QRS.checkCompilerVersion,
22
+ collectNamespaces: () => import_chunk_ZDTW2QRS.collectNamespaces,
23
+ createDocumentationMap: () => import_chunk_ZDTW2QRS.createDocumentationMap,
24
+ diagnostic: () => import_chunk_ZDTW2QRS.diagnostic,
25
+ diagnosticHelper: () => import_chunk_ZDTW2QRS.diagnosticHelper,
26
+ findNamesInScope: () => import_chunk_ZDTW2QRS.findNamesInScope,
27
+ findUsingForNode: () => import_chunk_ZDTW2QRS.findUsingForNode,
28
+ formatAst: () => import_chunk_ZDTW2QRS.formatAst,
29
+ formatAstLongLines: () => import_chunk_ZDTW2QRS.formatAstLongLines,
30
+ getApiFunctionInfo: () => import_chunk_ZDTW2QRS.getApiFunctionInfo,
31
+ getApiMapping: () => import_chunk_ZDTW2QRS.getApiMapping,
32
+ getSuperClasses: () => import_chunk_ZDTW2QRS.getSuperClasses,
33
+ hasProperty: () => import_chunk_ZDTW2QRS.hasProperty,
34
+ isClassVariable: () => import_chunk_ZDTW2QRS.isClassVariable,
35
+ isLocal: () => import_chunk_ZDTW2QRS.isLocal,
36
+ isLookupCandidate: () => import_chunk_ZDTW2QRS.isLookupCandidate,
37
+ isStateNode: () => import_chunk_ZDTW2QRS.isStateNode,
38
+ lookupByFullName: () => import_chunk_ZDTW2QRS.lookupByFullName,
39
+ lookupNext: () => import_chunk_ZDTW2QRS.lookupNext,
40
+ lookupResultContains: () => import_chunk_ZDTW2QRS.lookupResultContains,
41
+ lookupWithType: () => import_chunk_ZDTW2QRS.lookupWithType,
42
+ makeToyboxLink: () => import_chunk_ZDTW2QRS.makeToyboxLink,
43
+ mapVarDeclsByType: () => import_chunk_ZDTW2QRS.mapVarDeclsByType,
44
+ markInvokeClassMethod: () => import_chunk_ZDTW2QRS.markInvokeClassMethod,
45
+ parseSdkVersion: () => import_chunk_ZDTW2QRS.parseSdkVersion,
46
+ sameLookupResult: () => import_chunk_ZDTW2QRS.sameLookupResult,
47
+ traverseAst: () => import_chunk_ZDTW2QRS.traverseAst,
48
+ variableDeclarationName: () => import_chunk_ZDTW2QRS.variableDeclarationName,
49
+ visitReferences: () => import_chunk_ZDTW2QRS.visitReferences,
50
+ visit_resources: () => import_chunk_ZDTW2QRS.visit_resources,
51
+ visitorNode: () => import_chunk_ZDTW2QRS.visitorNode
52
52
  });
53
53
  module.exports = __toCommonJS(api_exports);
54
- var import_chunk_O5LFMOIG = require("./chunk-O5LFMOIG.cjs");
55
- var import_chunk_IAUHYWVN = require("./chunk-IAUHYWVN.cjs");
56
- (0, import_chunk_O5LFMOIG.init_api)();
54
+ var import_chunk_ZDTW2QRS = require("./chunk-ZDTW2QRS.cjs");
55
+ var import_chunk_HHQDDCTP = require("./chunk-HHQDDCTP.cjs");
56
+ (0, import_chunk_ZDTW2QRS.init_api)();
57
57
  // Annotate the CommonJS export names for ESM import in node:
58
58
  0 && (module.exports = {
59
59
  checkCompilerVersion,
@@ -26,8 +26,9 @@ 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_IAUHYWVN_exports = {};
30
- __export(chunk_IAUHYWVN_exports, {
29
+ var chunk_HHQDDCTP_exports = {};
30
+ __export(chunk_HHQDDCTP_exports, {
31
+ GenericQueue: () => GenericQueue,
31
32
  __commonJS: () => __commonJS,
32
33
  __esm: () => __esm,
33
34
  __export: () => __export2,
@@ -40,6 +41,7 @@ __export(chunk_IAUHYWVN_exports, {
40
41
  forEach: () => forEach,
41
42
  globSome: () => globSome,
42
43
  globa: () => globa,
44
+ init_logger: () => init_logger,
43
45
  init_util: () => init_util,
44
46
  last_modified: () => last_modified,
45
47
  log: () => log,
@@ -56,7 +58,7 @@ __export(chunk_IAUHYWVN_exports, {
56
58
  spawnByLine: () => spawnByLine,
57
59
  wouldLog: () => wouldLog
58
60
  });
59
- module.exports = __toCommonJS(chunk_IAUHYWVN_exports);
61
+ module.exports = __toCommonJS(chunk_HHQDDCTP_exports);
60
62
  var child_process = __toESM(require("child_process"));
61
63
  var fsc = __toESM(require("fs"));
62
64
  var fs = __toESM(require("fs/promises"));
@@ -5372,6 +5374,85 @@ var require_out4 = __commonJS({
5372
5374
  module2.exports = FastGlob;
5373
5375
  }
5374
5376
  });
5377
+ var require_priorityqueuejs = __commonJS({
5378
+ "node_modules/priorityqueuejs/index.js"(exports, module2) {
5379
+ module2.exports = PriorityQueue2;
5380
+ function PriorityQueue2(comparator) {
5381
+ this._comparator = comparator || PriorityQueue2.DEFAULT_COMPARATOR;
5382
+ this._elements = [];
5383
+ }
5384
+ PriorityQueue2.DEFAULT_COMPARATOR = function(a, b) {
5385
+ if (typeof a === "number" && typeof b === "number") {
5386
+ return a - b;
5387
+ } else {
5388
+ a = a.toString();
5389
+ b = b.toString();
5390
+ if (a == b)
5391
+ return 0;
5392
+ return a > b ? 1 : -1;
5393
+ }
5394
+ };
5395
+ PriorityQueue2.prototype.isEmpty = function() {
5396
+ return this.size() === 0;
5397
+ };
5398
+ PriorityQueue2.prototype.peek = function() {
5399
+ if (this.isEmpty())
5400
+ throw new Error("PriorityQueue is empty");
5401
+ return this._elements[0];
5402
+ };
5403
+ PriorityQueue2.prototype.deq = function() {
5404
+ var first = this.peek();
5405
+ var last = this._elements.pop();
5406
+ var size = this.size();
5407
+ if (size === 0)
5408
+ return first;
5409
+ this._elements[0] = last;
5410
+ var current = 0;
5411
+ while (current < size) {
5412
+ var largest = current;
5413
+ var left = 2 * current + 1;
5414
+ var right = 2 * current + 2;
5415
+ if (left < size && this._compare(left, largest) >= 0) {
5416
+ largest = left;
5417
+ }
5418
+ if (right < size && this._compare(right, largest) >= 0) {
5419
+ largest = right;
5420
+ }
5421
+ if (largest === current)
5422
+ break;
5423
+ this._swap(largest, current);
5424
+ current = largest;
5425
+ }
5426
+ return first;
5427
+ };
5428
+ PriorityQueue2.prototype.enq = function(element) {
5429
+ var size = this._elements.push(element);
5430
+ var current = size - 1;
5431
+ while (current > 0) {
5432
+ var parent = Math.floor((current - 1) / 2);
5433
+ if (this._compare(current, parent) <= 0)
5434
+ break;
5435
+ this._swap(parent, current);
5436
+ current = parent;
5437
+ }
5438
+ return size;
5439
+ };
5440
+ PriorityQueue2.prototype.size = function() {
5441
+ return this._elements.length;
5442
+ };
5443
+ PriorityQueue2.prototype.forEach = function(fn) {
5444
+ return this._elements.forEach(fn);
5445
+ };
5446
+ PriorityQueue2.prototype._compare = function(a, b) {
5447
+ return this._comparator(this._elements[a], this._elements[b]);
5448
+ };
5449
+ PriorityQueue2.prototype._swap = function(a, b) {
5450
+ var aux = this._elements[a];
5451
+ this._elements[a] = this._elements[b];
5452
+ this._elements[b] = aux;
5453
+ };
5454
+ }
5455
+ });
5375
5456
  function logger(module2, level, message) {
5376
5457
  if (wouldLog(module2, level)) {
5377
5458
  log(message);
@@ -5381,7 +5462,7 @@ function wouldLog(module2, level) {
5381
5462
  if (!loggerSettings) {
5382
5463
  loggerSettings = getLoggerSettings();
5383
5464
  }
5384
- return (loggerSettings.get(module2) ?? 0) >= level + loggerLevelOffset;
5465
+ return (loggerSettings.get(module2) ?? loggerSettings.get("*") ?? 0) >= level + loggerLevelOffset;
5385
5466
  }
5386
5467
  function bumpLogging(module2, amount) {
5387
5468
  if (!module2) {
@@ -5630,11 +5711,33 @@ function popcount(x) {
5630
5711
  x += x >> 16;
5631
5712
  return x & 127;
5632
5713
  }
5633
- var import_fast_glob;
5714
+ var import_fast_glob, import_priorityqueuejs, GenericQueue;
5634
5715
  var init_util = __esm({
5635
5716
  "src/util.ts"() {
5636
5717
  import_fast_glob = __toESM2(require_out4());
5718
+ import_priorityqueuejs = __toESM2(require_priorityqueuejs());
5637
5719
  init_logger();
5720
+ GenericQueue = class {
5721
+ enqueued = /* @__PURE__ */ new Set();
5722
+ queue;
5723
+ constructor(sort) {
5724
+ this.queue = new import_priorityqueuejs.default(sort);
5725
+ }
5726
+ enqueue(block) {
5727
+ if (!this.enqueued.has(block)) {
5728
+ this.enqueued.add(block);
5729
+ this.queue.enq(block);
5730
+ }
5731
+ }
5732
+ dequeue() {
5733
+ const block = this.queue.deq();
5734
+ this.enqueued.delete(block);
5735
+ return block;
5736
+ }
5737
+ empty() {
5738
+ return this.queue.isEmpty();
5739
+ }
5740
+ };
5638
5741
  }
5639
5742
  });
5640
5743
  /*! Bundled license information:
@@ -5687,6 +5790,7 @@ run-parallel/index.js:
5687
5790
  */
5688
5791
  // Annotate the CommonJS export names for ESM import in node:
5689
5792
  0 && (module.exports = {
5793
+ GenericQueue,
5690
5794
  __commonJS,
5691
5795
  __esm,
5692
5796
  __export,
@@ -5699,6 +5803,7 @@ run-parallel/index.js:
5699
5803
  forEach,
5700
5804
  globSome,
5701
5805
  globa,
5806
+ init_logger,
5702
5807
  init_util,
5703
5808
  last_modified,
5704
5809
  log,