@markw65/monkeyc-optimizer 1.1.33 → 1.1.35

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
@@ -1,938 +1,15 @@
1
1
  # monkeyc-optimizer README
2
2
 
3
- This module is a set of utilities for optimizing Garmin Monkey-C code. Its the engine behind [prettier-extension-monkeyc](https://marketplace.visualstudio.com/items?itemName=markw65.prettier-extension-monkeyc). Its not currently expected to be useful outside of that context but may be extended in future to make it useful in complex projects beyond the scope of that extension.
3
+ This package provides a set of utilities for working with Garmin Monkey-C projects.
4
4
 
5
- ## Release Notes
6
-
7
- #### 1.0.0
8
-
9
- Initial release
10
-
11
- #### 1.0.1
12
-
13
- - Make a better attempt to fix all the negative constants in api.mir
14
- - Make export explicitly do a release build by default.
15
-
16
- #### 1.0.2
17
-
18
- - Better error reporting when something goes wrong internally
19
- - Fix an order dependency when processing imports. Previously, if the import statement was seen before the module being imported, we would fail to properly handle the import.
20
-
21
- ### 1.0.3
22
-
23
- - Split the build into release and debug, so we can exclude code based on (:release) and (:debug)
24
- - Optimize away `if (constant)`, `while (false)` and `constant ? E1 : E2`. Convert `do BODY while(false)` to `BODY`
25
-
26
- ### 1.0.4
27
-
28
- - Fix a bug resulting in a failure to fully optimize constants initialized by constant conditional expressions
29
- - Make the generated .cjs files work better with es modules (vscode doesn't work with es modules, so prettier-extension-monkeyc doesn't care - but for other projects importing this package it improves the behavior)
30
- - Generate separate debug/release jungle files.
31
-
32
- ### 1.0.5
33
-
34
- - Bump to version 1.0.11 of `@markw65/prettier-plugin-monkeyc` to fix an ObjectLiteral parsing issue.
35
-
36
- ### 1.0.6
37
-
38
- - Bump to version 1.0.12 of `@markw65/prettier-plugin-monkeyc` to fix multiple parser bugs
39
- - Add lots of open source projects as tests. For now, just verify that optimizing the sources succeeds, not that the generated source is actually correct.
40
-
41
- ### 1.0.7
42
-
43
- More fixes found via open source projects.
44
-
45
- - Fix parsing of quoted strings in jungle files
46
- - Better error messages from the test framework
47
- - Lazier handling of variables in jungle files
48
- - Fix handling of negative enums that get completely removed
49
- - Fix a bug analyzing empty classes
50
- - Fix a typo that could result in consts being incorrectly eliminated
51
- - Fix an edge case handling local jungle variables
52
- - More test options, and add filters for some of the remote projects
53
- - Try to clean up broken jungles and manifests
54
- - Fix handling of unnamed callees
55
- - Drop unrecognized devices
56
- - Add support for a 'pick-one' device to aid testing
57
- - Add a flag to remote projects to prevent trying to build them (some projects are broken to start with)
58
-
59
- ### 1.0.8
60
-
61
- - Improvements
62
-
63
- - Update to `@markw65/prettier-plugin-monkeyc:1.0.14`
64
- - Parse and respect \<build\> instructions in resource files
65
- - Add minimal barrel support
66
- - Better checking for whether the optimized source is up to date
67
- - Rename locals which would be marked re-declaring
68
-
69
- - Bug Fixes
70
-
71
- - Generate the default jungle dynamically, since sdk/bin/default.jungle is generated lazily, and may not exist in newly installed sdks, or may be out of date after device installations.
72
- - Fix a bug generating language settings in optimized jungle
73
- - Fix a bug introduced by pick-one: don't modify a shared array
74
- - Don't allow src paths to navigate out of the optimized directory
75
- - Fix some windows paths issues
76
-
77
- - Tests
78
- - More parallelism while fetching remote projects for testing
79
- - Add option to build the original project, rather than the optimized one
80
- - Add support for overriding build options on a per project basis
81
- - Add an option so we only 'fix' the manifest when running remote projects
82
- - Check the manifest's application id, and throw in a valid one if necessary
83
- - Allow project specific overrides for the generated monkey.jungle files, and use it to fix some projects
84
- - Add patches for some broken projects
85
-
86
- ### 1.0.9
87
-
88
- - Only generate the parts of the jungle we're going to use
89
- - Also publish sdk-util.cjs
90
- - Bump to `@markw65/prettier-plugin-monkeyc:1.0.15`
91
- - Fixes a bug that dropped attributes on modules
92
- - LiteralIntegerRe should be case insensitive
93
- - Proper fix for promiseAll
94
- - Auto-include barrels.jungle when its present
95
-
96
- ### 1.0.10
97
-
98
- - Add --execute option to test.js to run the projects after building them
99
- - Add support for optimizing barrels
100
- - Add some typing via jsdoc, and turn on ts validation in vscode
101
- - Bump to `@markw65/prettier-plugin-monkeyc:1.0.16` so ts recognizes its exports
102
- - Add [garmin/connectiq-apps](https://github.com/garmin/connectiq-apps) and fix some minor issues it revealed
103
-
104
- ### 1.0.11
105
-
106
- - Improvements
107
-
108
- - Add option to run tests (for projects that have them)
109
- - Add getProjectAnalysis api, to support various language features in `@markw65/prettier-extension-monkeyc`
110
-
111
- - Bug fixes
112
-
113
- - Fix lookup of self/me
114
-
115
- - Code cleanup
116
- - More typing. Check that build options match previous ones before re-using the optimized files
117
- - Move everything over to typescript
118
- - The project was becoming hard to maintain due to too much ad-hoc dynamic typing. This should allow easier/safer refactors and code cleanup.
119
- - Refactoring to make analysis available in prettier-extension-monkeyc
120
- - Generate .d.ts, and drop unneeded paths/resolve.alias
121
- - Pull in a typed version of `@markw65/prettier-plugin-monkeyc`
122
-
123
- ### 1.0.12
124
-
125
- - Fix connectiq and vscode paths on linux, and better error reporting when they're missing
126
-
127
- ### 1.0.13
128
-
129
- - Improvements
130
-
131
- - Add displayName to deviceInfo (for getTargetDevices in prettier-extenion-monkeyc)
132
- - Throw a better error when we fail to read a jungle file
133
- - Don't try to optimize barrel projects
134
-
135
- - Code cleanup
136
-
137
- - Update to `@markw65/prettier-plugin-monkeyc@1.0.20` for mctree fixes
138
- - Enable typescript strict checks
139
- - Turn off synthetic default imports, and fix issues
140
- - Better manifest typing
141
-
142
- - Tests
143
- - Add date/time to test logging
144
-
145
- ### 1.0.14
146
-
147
- - Bug fixes
148
-
149
- - When reading a barrel project with no products, add all products by default
150
- - Only set language specific paths for languages that are supported by the device
151
- - Remove comments that are completely contained within removed nodes
152
-
153
- - Code cleanup
154
- - Upgrade to `@markw65/prettier-plugin-monkeyc@1.0.21` for some typescript fixes
155
- - npm upgrade to pickup ts 4.7.2
156
- - Add types to package exports for ts 4.7.2
157
- - Better handling of program-logic errors
158
-
159
- ### 1.0.15
160
-
161
- - Bug fixes
162
- - Inject the superclass name into the classes namespace
163
- - Separate type vs value lookup, and use the correct one based on context.
164
-
165
- ### 1.0.16
166
-
167
- - Bug fixes
168
-
169
- - Fix off-by-one in removeNodeComments
170
- - Fix lookup to consistently lookup types or values.
171
- - Fix lookup of superclass names
172
-
173
- - New Features
174
-
175
- - Add a simple inliner
176
- - Add support for conditional inlining based on excludeAnnotations
177
-
178
- - Testing
179
- - Add support for @match pragmas to check the optimization results
180
- - Add a test project, with some inlining tests
181
-
182
- ### 1.0.17
183
-
184
- - New Features
185
-
186
- - Extend the inliner to support more complex functions when called in a void context
187
- - Cleanup unused expressions. `0;x;foo.bar;a+b` will all now be optimized away.
188
-
189
- - Testing
190
-
191
- - Rewrite the @match pragma implementation to have access to the next Node in the ast, rather than just the text of the remainder of the line.
192
- - Add tests for the statement inliner, and the unused expression cleanup code.
193
-
194
- - Bug Fixes
195
- - Fix a bug affecting lookup of types, which could cause definitions, references and links to the api docs to be missed in the vscode extension
196
-
197
- ### 1.0.18
198
-
199
- - Bug Fixes
200
- - The new inliner was too agressive at constant propagating literal parameters to their point of use.
201
-
202
- ### 1.0.19
203
-
204
- - Upgrade to `@markw65/prettier-plugin-monkeyc@1.0.22`
205
-
206
- - fixes some minor typing issues for mctree
207
- - special handling for certain parenthesized expressions.
208
-
209
- - Optimizer
210
-
211
- - Handle more unused expressions, add tests, and prettify the OptimizerTests project
212
- - Allow statement-style inlining in assignent and return contexts
213
- - Add diagnostics for failure to inline
214
-
215
- - Tests
216
-
217
- - More tweaks to pragma-checker
218
- - Add launch and task configs for building/running tests
219
-
220
- - Code cleanup
221
- - Properly type the results of JSON.parse
222
- - Switch over to using ParenthesizedExpression for formatAst (depends on `@markw65/prettier-plugin-monkeyc@1.0.22`)
223
-
224
- ### 1.0.20
225
-
226
- - Bug fixes
227
-
228
- - Fix a bug marking unknown callees
229
- - Fix a bug in test.js that didn't notice when tests failed, and fix a failing test
230
-
231
- - Optimizer enhancements
232
-
233
- - Re-run the main optimization step, to properly account for functions that are unused after optimization
234
- - Call the optimizer on 'unused' nodes before returning them
235
-
236
- - Code cleanup
237
- - Called function cleanup
238
-
239
- ### 1.0.21
240
-
241
- - Bug fixes
242
-
243
- - Parameters from the calling function should be treated just line locals when inlining
244
- - Upgrade to `@markw65/prettier-plugin-monkeyc@1.0.24`
245
- - fixes crash with comments following an attribute: `(:foo) /* comment */ function foo() {}`
246
- - Fix issues with recursive inlining
247
-
248
- ### 1.0.22
249
-
250
- - Improvements
251
-
252
- - Major rewrite of the symbol lookup mechanism, to match monkeyc as closely as possible
253
-
254
- - Fix callee lookup to skip local variables
255
- - Fix class lookup to first check all the super classes, then to check the context of each super class
256
- - Fix module lookup to check both the module, and the context of the module
257
- - Inject class and module names into themselves. So that Graphics.Graphics.COLOR_RED works.
258
-
259
- - Add live diagnostics for missing symbols
260
-
261
- - Bug fixes
262
-
263
- - Recognize the the variable in a catch clause is a declaration
264
-
265
- - Breaking change
266
- - By popular demand, reversed the sense of `inline*foo`, so now it inlines when foo is _not_ declared as an excludeAnnotation
267
-
268
- ### 1.0.23
269
-
270
- - Bug Fixes
271
-
272
- - Don't treat parameters to Method types as undeclared variables
273
- - eg `var x as (Method(a as Number, b as Number) as Void)` should not report that `a` and `b` are undeclared
274
-
275
- - Tests
276
- - Various new tests for module/class/local resolution of symbols
277
- - Make tests fail by default if the optimizer reports any undefined symbols, and add `@expects` or `checkInvalidSymbols=WARNING` as needed to prevent test failures.
278
-
279
- ### 1.0.24
280
-
281
- - Bug fix
282
- - The new ast.ts didn't pick up child elements that could be either a string or a node. This resulted in it missing the name in TypeSpecPart.
283
-
284
- ### 1.0.25
285
-
286
- - Bug fix
287
- - estree-types was missing the returnType on FunctionDeclaration. Update to latest prettier-plugin, and fix ast.ts.
288
-
289
- ### 1.0.26
290
-
291
- - Bug fixes
292
- - Use `self.` rather than `ClassName.` to qualify names that would otherwise collide with locals, since that works with both public and private variables
293
- - Fix a bug that caused the inliner to fail to qualify certain names, even if there was a collision with an existing local variables
294
- - Fix some name lookup issues relating to whether the lookup is done as a type or a value.
295
-
296
- ### 1.0.27
297
-
298
- - Bug fixes
299
- - Update to `@markw65/prettier-plugin-monkeyc@1.0.29` to fix certain obscure comment related bugs
300
- - When replacing a node (espcially when inlining), delete any comments contained in the old node.
301
-
302
- ### 1.0.28
303
-
304
- - Bug fixes
305
- - In some circumstances, while inlining, a parameter could be substituted, and then reprocessed. During reprocessing, it would attempt to lookup the replacement symbol, and if that was a local from the calling function it would fail (since an inline function never has access to the caller's locals). Prevent the reprocessing step from happening.
306
-
307
- ### 1.0.29
308
-
309
- - Update to `@markw65/prettier-plugin-monkeyc@1.0.32`
310
-
311
- - Fixes a parser issue where `x as Type ? a : b` would be parsed as `(x as Type?) a : b` which would then be reported as a syntax error.
312
-
313
- - Bug fixes
314
-
315
- - Fix a bug causing literal nodes to be shared. This was harmless prior to the implementation of the PRE pass
316
-
317
- - Code cleanup
318
-
319
- - Add `isStatement` and `isExpression` helpers
320
-
321
- - New features
322
-
323
- - Add constant folding for relational and logical operators
324
- - Allow assignment-scope inlining in variable initializers
325
- - Better cleanup of unused expressions
326
- - Add a size based PRE pass. Currently limited to non-local variables, and literals
327
-
328
- - Testing
329
- - Ignore case of typeCheckLevel option
330
- - Actually run the rest of the expected-to-crash tests
331
- - Better error messages from pragma checker
332
- - Better regex for filtering projects
333
-
334
- ### 1.0.30
335
-
336
- - Less greedy approach to finding candidate sets
337
- - slightly better size reduction when globals maybe modified
338
- - Fix the control flow after the test of a while loop
339
- - one of the edges was in the wrong place, leading to suboptimal solutions in some cases
340
-
341
- Bug Fixes
342
-
343
- - Fix a bug that could lead to the optimizer never completing
344
- - Fix a bug that prevented inlining functions that ended in a BlockStatement
345
- - Fix a bug that could cause nested inlined functions inlined in declarations to not be removed
346
-
347
- ### 1.0.31
348
-
349
- - Bug fixes
350
-
351
- - Use withLocDeep on inline results
352
- - Better tracking of state.inType
353
- - Fix typo setting up the ProgramState
354
- - Fix a glitch with the scope of for-statement variable declarations
355
- - Fix some edge cases with pre
356
- - Remove a check that crippled pre for literals
357
- - I had forgotten to remove some code that I added to debug a problem
358
-
359
- - Code cleanup
360
-
361
- - Move all the global types to optimizer-types.ts, and explicitly import them
362
- - Be more consistent about when assignment/update lhs is traversed
363
- - Rework exposed flag
364
- - Now it only holds the names of symbols (ie `:name`)
365
- - There's a separate list of variables that shouldn't be removed
366
- - There's a separate list of functions that shouldn't be removed
367
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.33](https://github.com/markw65/prettier-plugin-monkeyc#1033)
368
- - Update for BigInt literals, and cleanup folding code
369
-
370
- - New features
371
-
372
- - Support `obj[:key]` as alternate for obj.key in lookup
373
- - `Find References`, and `Rename` will recognize these references now.
374
- - Add an unused variable cleanup pass
375
- - This will delete variables that are completely unreferenced.
376
-
377
- - Analysis/Optimization
378
- - Collect info about what each function may modify and call
379
- - Better analysis of inline function bodies
380
- - Update the StateNodeDecls when renaming locals
381
-
382
- ### 1.0.32
383
-
384
- - Bug fixes
385
- - Fixup the tests to run unoptimized again, and add running unoptimized to the standard test run
386
- - Fix PRE to not merge Numbers and Floats (ie 1 is not the same thing as 1.0), and add a test
387
-
388
- ### 1.0.33
389
-
390
- - New features
391
-
392
- - Tagging a function with (:keep) will prevent the optimizer from removing it, even if it appears to be unused.
393
-
394
- - Bug fixes
395
- - Fix PRE to not merge values with different types. ie Number, Long, Float and Double literals should all be treated separately, even when the compare the same.
396
-
397
- ### 1.0.34
398
-
399
- - Bug fixes
400
-
401
- - Fix parser to allow white space to separate attributes, in addition to comma
402
- - Fix optimizer to respect prettier options when formatting the optimized code
403
-
404
- - Testing
405
- - rewrite test harness in typescript
406
- - fix up tests to work with compiler2 again, and also with compiler2 at -O0
407
-
408
- ### 1.0.35
409
-
410
- - Testing
411
-
412
- - Add a new open source project
413
- - Fixup tests to work with compiler2beta2
414
-
415
- - Bug fixes
416
- - Fixed a bug that caused the optimizer to fail if a top level variable declared in a case statement had an initializer with side effects. This didn't produce incorrect results, the optimizer simply bailed out with an obscure error, and refused to optimize the project.
417
-
418
- ### 1.0.36
419
-
420
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.35](https://github.com/markw65/prettier-plugin-monkeyc#1035).
421
- - Fixes [prettier-plugin-monkeyc#1](https://github.com/markw65/prettier-plugin-monkeyc/issues/1)
422
- - Fixes [monkeyc-optimizer#1](https://github.com/markw65/monkeyc-optimizer/issues/1)
423
-
424
- ### 1.0.37
425
-
426
- - Update the testing framework to launch the simulator before each test run, rather than start it once at the beginning. This is because the latest beta crashes after successfully completing.
427
- - Update launchSimulator to check if the simulator is already running. This avoids lots of screen switching when the simulator is running on a separate desktop.
428
- - Add optimizerVersion and extensionVersion to build-info.json.
429
-
430
- ### 1.0.38
431
-
432
- - Allow inlining the argument to an if-statement, with the same constraints as inlining in assignment context
433
- - Expand `assignment`, `declaration` and `if` contexts to include (recursively) the left operand of any binary operator, the operand of any unary operator, the `test` operand of any conditional operator or the `object` of a member-expression. So now it will inline `inlinableFunction` in:
434
- - `var x = !((inlinableFunction() + 4) == 42 ? foo() : bar());`
435
-
436
- ### 1.0.39
437
-
438
- - Improvements
439
-
440
- - Upgrade to [@markw65/prettier-plugin-monkeyc@1.0.36](https://github.com/markw65/prettier-plugin-monkeyc#1036).
441
- - Upgrade all other npm dependencies to the latest versions, and fix a few issues that showed up as a result.
442
- - Report missing symbols after optimization, rather than before. Results in fewer false negatives. eg Given `if (foo has :bar) { return foo.bar; }`, where the compiler knows that foo.bar doesn't exist, the whole thing will be optimized away, rather than generate a diagnostic that foo.bar doesn't exist.
443
- - Stop reporting `X has :Y` as a missing symbol, even when we know that X does not have Y.
444
- - Implement our own xml parser. This was prompted by wanting to tag the parsed xml with source locations.
445
- - Since we were already parsing all the resource files to look for `<build>` instructions, additionally identify all the symbols that will get generated. This allows us to detect references to undefined resources, and also makes `Goto Definition` just work for things like `Rez.Strings.foo`.
446
-
447
- - Optimizations
448
-
449
- - Optimize has expressions that are guaranteed to be false.
450
-
451
- - Bugs
452
-
453
- - Fix an issue with launchSimulator, which caused it to sometimes not bring the simulator window into focus when it should have done.
454
- - Fix an issue that caused simulateProgram to fail on windows.
455
- - Fix a bug looking up self when not part of a member-expression (this didn't happen until I added optimizations for "has" expressions, in this release)
456
- - Add barrel sources to project analysis. This didn't affect optimization, which already included the sources, but did affect `Goto Definition` etc in the vscode extension, and caused lots of diagnostics about missing symbols.
457
- - ciq-3.2.0 and later devices don't declare "widget" as a supported type, but the compiler does allow you to compile widget projects for them anyway. Fix that when determining the allowable devices in the manifest.
458
- - Don't drop the `x` in `var x = new X();` even if `x` isn't used, because the monkeyc compiler doesn't generate any code for a bare `new X();`.
459
-
460
- - Tests
461
- - Better error reporting in the driver script.
462
- - Handle relative jungle paths correctly.
463
- - Add more tests for strange monkeyc behavior, pre and post compiler2
464
- - Better identification of compilers that support compiler2
5
+ #### Optimization and analysis
465
6
 
466
- ### 1.0.40
7
+ Its primary purpose is to serve as the optimization and analysis engine behind [prettier-extension-monkeyc](https://marketplace.visualstudio.com/items?itemName=markw65.prettier-extension-monkeyc). Although it could be used separately to optimize and analyze Monkey-C projects, most of the API is not expected to be stable (ie it will change as required by `prettier-extension-monkeyc`).
467
8
 
468
- - Improvements
9
+ #### Font analysis
469
10
 
470
- - Upgrade to [@markw65/prettier-plugin-monkeyc@1.0.37](https://github.com/markw65/prettier-plugin-monkeyc#1037).
471
- - Report locations of errors in manifest.xml (rather than just reporting an error somewhere in the file)
472
- - Minor improvements to Goto References etc
473
- - Keep a cache of parsed resource files, and update errors/warnings relating to resources as you type, rather than when the resource file is saved.
474
- - Add diagnostics for known issues in sdk-4.1.6
475
- - Add diagnostics for changes in behavior between compiler1 and compiler2
476
- - Fix lookups to be aware of compiler1 vs compiler2. Add an option to always use compiler1 rules, or always use compiler2 rules.
477
- - Fix lookups in static methods, under a new option that defaults to true.
11
+ It also provides a tool to report information about the builtin fonts on a device. This can be used to compute layouts, or make decisions about whether a given string would fit in a given screen region at build time, rather than at runtime. [More details](https://github.com/markw65/monkeyc-optimizer/wiki/Garmin-Font-Analyzer)
478
12
 
479
- - Testing
480
-
481
- - Fix pragma checker to sort the diagnostics properly
482
- - Allow specifying which test to run on the command line
483
- - Update all tests to work with 4.1.6 and 4.1.7
484
-
485
- - Bug fixes
486
- - Fix optimization of `and` and `or` (alternate names for `&&` and `||`)
487
- - Fix a bug that could sometimes prevent the `has` optimization from kicking in.
488
-
489
- ### 1.0.41
490
-
491
- - Bug fixes
492
- - The fix to avoid visiting definitions from visitReferences was incomplete
493
-
494
- ### 1.0.42
495
-
496
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.38](https://github.com/markw65/prettier-plugin-monkeyc#1038)
497
-
498
- - faster parsing
499
- - supports parsing the attributes in api.mir, including sdk version etc.
500
-
501
- - Performance
502
-
503
- - Using the updated prettier-plugin-monkeyc halves the time spent in the parser
504
- - There was some pathalogical behavior in the jungle processing. For most projects, it was quite fast (under 1s), but the worst project I found took nearly 5 minutes. I fixed a lot of redundant processing, which dropped most projects to under 500ms, with a worst case of 20s.
505
- - I had some caching code to prevent reading the same resource file multiple times, but the cache didn't work properly because an async function ran in between the test of the cache, and the fill of the cache; which meant that lots of threads could test the cache and decide it needed to be filled. Fixed by caching Promises, rather than the promise results. Dropped the worst case 20s down to under 500ms, and the average down below 100ms.
506
- - improved incremental builds (which helps with prettier-extension-monkeyc's live analysis)
507
-
508
- - New features
509
- - Resource files, and manifest.xml generate definitions and references so that prettier-extension-monkeyc can provide Goto Ref/Def between monkeyc, resource, and manifest files.
510
-
511
- ### 1.0.43
512
-
513
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.39](https://github.com/markw65/prettier-plugin-monkeyc#1039)
514
-
515
- - Fixes issues parsing/printing/optimizing NaN
516
-
517
- - Fix issues with windows paths introduced in 1.0.42
518
- - Add Symbols (`:name`) to the list of things the inliner knows are constants
519
- - Propagate `:typecheck(false)` to the caller when inlining
520
- - Fix an issue with bogus undefined symbols being reported against manifest.xml in some projects that use barrels.
521
-
522
- ### 1.0.44
523
-
524
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.40](https://github.com/markw65/prettier-plugin-monkeyc#1040)
525
-
526
- - Fixes location ranges associated with parenthesized expressions
527
- - Fixes parsing of Lang.Char literals
528
-
529
- - Add more parsing of expressions embedded in resource files. This should now be complete, in that the analasis pass should see every symbol definition and reference from anywhere in the project.
530
- - Generalize constant folding to (nearly) all supported types. We don't fold additions between Float or Double and String, because the exact behavior is [buggy and upredictable](https://forums.garmin.com/developer/connect-iq/i/bug-reports/sdk-4-1-7-constant-folds-floats-strings-incorrectly)
531
-
532
- ### 1.0.45
533
-
534
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.41](https://github.com/markw65/prettier-plugin-monkeyc#1041)
535
-
536
- - Fixes a few parser edge cases
537
-
538
- - Bug fixes
539
-
540
- - Fix a bug constant folding == and !=
541
- - Make sure to include all languages, even for devices that don't support them, because they're still supported in settings. Do this in a way that avoids creating warnings.
542
- - Look at all build dependencies when deciding whether to regenerate the optimized files.
543
- - Don't produce errors when "-" is used as the first character of an id in a resource file (although in most cases, this is not a good idea, and will fail at compile time)
544
-
545
- - Improvements
546
- - Better typing for resources
547
- - Refactor PRE
548
- - Improve accuracy of whether or not a function can modify a particular global (resulting in better PRE)
549
-
550
- ### 1.1.0
551
-
552
- - Implements a type analyzer, to enable better optimizations
553
-
554
- - adds options `trustDeclaredTypes` and `propagateTypes`. See https://github.com/markw65/monkeyc-optimizer/wiki/Type-and-Dataflow-analysis
555
-
556
- - Improved optimizations
557
-
558
- - SizeBasedPRE now has finer granularity, making it generally find more opportunities
559
- - Lots of improvements to binary operators, and folding. Subject to suitable type checks,
560
- - `(x + K1) + K2` => `x + (K1 + K2)`
561
- - `(x + K1) + (y + K2)` => `(x + y) + (K1 + K2)`
562
- - `(x + K1) + y` => `(x + y) + K1`, so that `((x + K1) + y) + K2` => `(x + y) + (K1 + K2)`
563
- - `(x + -y)` and `(-y + x)` => `x - y`
564
- - `x + 0` => `x`
565
- - `x * 0` => `0`
566
- - Various boolean optimizations:
567
- - `!x ? y : z` => `x ? z : y`
568
- - `x ? true : false` => `x`
569
- - `x ? false : true` => `!x`
570
- - `x && true` => `x`, `y || false` => `y`
571
- - constant propagation
572
- - `var x = 42; ...; foo(x)` => `...; foo(42)`
573
-
574
- - Bug fixes
575
- - Fixes a bug that could ignore side effects from Method.invoke
576
- - Fixes a crash in the inliner, when trying to inline a function with multiple returns
577
-
578
- ### 1.1.1
579
-
580
- - Fix the package spec to include the new .d.ts files
581
-
582
- ### 1.1.2
583
-
584
- - Fix a couple of edge cases when constant folding == and !=
585
- - Optimize `<boolean> && false`, and `<boolean> || true`, when `<boolean>` has no side effects
586
- - Better optimization of inlined function bodies
587
- - Analyze constants with casts to help with constant propagation
588
- - Ignore widening casts (eg a cast that is given a `Number` and converts it to `Number or String`)
589
- - More accurate deletion of unused constants. Sometimes a constant that was unused after the optimization phase ended, was still considered used because of references that were eventually deleted.
590
-
591
- ### 1.1.3
592
-
593
- - Tweaks and fixes
594
-
595
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.42](https://github.com/markw65/prettier-plugin-monkeyc#1042)
596
- - Fixed an issue that cause inlining in return context to be too conservative
597
- - Update inliner to keep a stack of locations, so that error messages can show exactly where an error occurred, even in the presence of inlining.
598
- - Update diagnostic api to optionally include a uri to more detailing information.
599
-
600
- - Type Analysis
601
-
602
- - Track type info through branch conditions, so that in `if (x != null) { A } else { B }`, the type checker knows that x is not null in A, and it is null in B.
603
- - Added checkers for return types, call arguments, assignments and variable declarations.
604
- - Automatically infer Array and Dictionary types
605
- - Track equivalencies, and use them for various optimizations.
606
- - Add support for "strong" and "weak" type checking.
607
- - Add type analysis to getProgramAnalysis.
608
-
609
- - Optimizations
610
- - Eliminate self-assignments (eg `x = x;`, but also `x = a; y = a; ... y = x;`).
611
- - Eliminate dead stores.
612
- - Replace more expensive accesses by less expensive ones.
613
- - Delete empty else blocks.
614
- - Delete if statements with empty body and no else.
615
-
616
- ### 1.1.4
617
-
618
- - Optimizations
619
-
620
- - Minor tweaks to dead store elimination
621
- - Better type resolution for untyped code
622
-
623
- - Enhancements
624
-
625
- - Retain the type map in the analysis pass, so that it can be used to improve
626
- the results in visitReferences
627
-
628
- - Bug fixes
629
-
630
- - When multiple diagnostics were reported for a single location, all but the last was lost
631
- - Sometimes when evaluating MemberExpressions type-flow would give up too easily, resulting
632
- in unknown types for the object, which then resulted in unexpected error messages from
633
- the type checker, often involving seemingly unrelated classes.
634
- - Inlining history was sometimes lost when further optimizations were performed.
635
-
636
- - Code cleanup
637
- - refactor some of the type code for better type safety
638
- - turn on the eslint rule eqeqeq and fix all the issues
639
-
640
- ### 1.1.5
641
-
642
- - Bug fixes
643
- - Always evaluate a constant's initializer to determine its type
644
- - Fix a bug refining the object type based on the properties it accesses that could lose the type of the object.
645
-
646
- ### 1.1.6
647
-
648
- - Bug fixes
649
- - Fix an issue in restrictByEquality when restricting a union including an Enum, to a specific value of the enum.
650
- - Fix the display of Method types to match the syntax used in MonkeyC.
651
- - Infer the type of `method(:symbol)` by looking up symbol.
652
-
653
- ### 1.1.7
654
-
655
- - Bug fixes
656
- - Fix a problem with inlining that could inadvertently make locals from the callee function appear to belong to the callee's class or module. This could sometimes block optimizations, and also cause confusion for the type checker.
657
-
658
- ### 1.1.8
659
-
660
- - Bug fixes
661
-
662
- - After making a non-modifying change to a variable, update the types of all equivalent variables. eg in `var x = y; if (y != null) { whatever }` we know that x is not null in `whatever`, even though we didn't explicitly test it.
663
- - Fix an issue with `import` and `using`. If an import happened after the definition of an inline function, inlined copies of the function might incorrectly use those imports resulting in finding the wrong symbols. This was rare - most imports happen at the top of the file, and generally an import will simply make something work that would have failed, rather than changing the behavior of something that already works. But I added a test case that exhibits the problem.
664
-
665
- - New features
666
- - Add support for comletion style lookups - find all the names available in the current context that fuzzy match a given string
667
- - Add helpers to read the function documentation from api.debug.xml
668
- - Add an option to visitReferences to only find a specific definition, rather than all definitions for that name in the current scope.
669
-
670
- ### 1.1.9
671
-
672
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.43](https://github.com/markw65/prettier-plugin-monkeyc#1043)
673
-
674
- - Bug fixes
675
-
676
- - fix an interaction between inlining and removing unused local vars that could cause unlimited recursion leading to stack overflow
677
-
678
- - New optimizations
679
- - Adds a `minimizeLocals` pass which runs after `sizeBasedPRE` and attempts to re-use local variables in order to reduce the total number, and hence reduce the stack size.
680
-
681
- ### 1.1.10
682
-
683
- - Bug fixes
684
- - Fix a bug that could cause inlined code to not get fully optimized
685
- - Fix costs for pre of Long and Double constants, so that values that are used twice (rather than 3 times) will be subject to pre
686
- - Fix some issues tracking the contents of Objects. In some circumstances, if two objects could be aliased, an assignment to a field of one of them might not be recognized as affecting the other.
687
- - Don't warn about inlining failing if constant folding succeeds.
688
- - In the vscode extension, in some cases `Go to Definition` worked for a resource (eg a Menu), but then `Go to References` said there were none. This was caused by incorrect source location in the (fake) resource code.
689
-
690
- ### 1.1.11
691
-
692
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.44](https://github.com/markw65/prettier-plugin-monkeyc#1044)
693
-
694
- - Fixes a parser bug relating to Methods returning Void, and a printer bug relating to nested Method declarations.
695
-
696
- - Bug fixes
697
- - Fixes an odd bug that could remove assignments to a global with the same name as an unused local, if the local was declared part way through a block, and the global was used before the declaration of the local.
698
- - Fix some asserts related to complex member expressions that could fire in unusual circumstances
699
- - New features
700
- - Constant fold instanceof expressions
701
- - Add more Toybox functions to sysCallInfo, so the optimizer knows they have no side effects
702
- - Remove top level, side-effect free expressions
703
- - Propagate any :typecheck annotations from inlined functions to their callers
704
- - Fix some issues keeping track of function calls used as arguments to inlined functions, that could result in bogus diagnostics.
705
- - Implement [Single Use Copy Propagation](https://github.com/markw65/monkeyc-optimizer/wiki/Local-variable-elimination#single-use-copy-propagation)
706
-
707
- ### 1.1.12
708
-
709
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.45](https://github.com/markw65/prettier-plugin-monkeyc#1045)
710
- - fixes some bugs that could cause comments to go missing, resulting in an internal error from the formatter
711
- - Streamline some of the data structures used for `Minimise Locals` and `Single Copy Prop` to reduce memory use, and speed things up a little.
712
- - Fix a bug that could cause incorrect copy propagation in loops
713
- - Add support for update assignments in copy propagation (so that `var x = a; x += b; return x` goes to `return a + b`)
714
-
715
- ### 1.1.13
716
-
717
- - Adds a new [Minimize Modules](https://github.com/markw65/monkeyc-optimizer/wiki/Optimizing-module-imports#minimize-modules) pass, which attempts to ensure that every module referenced by the program is imported.
718
-
719
- ### 1.1.14
720
-
721
- - Fixes a bug that could crash the optimizer if it tried to inline a function in a non-local variable's initializer.
722
- - Adds a post build optimizer. This step takes the built .prg file, and optimizes the bytecode. Currently the optimizations are:
723
- - Remove unreachable code
724
- - simplify control flow by removing branches to branches
725
- - Remove empty "finally" handlers (every try/catch gets an empty finally handler)
726
- - Remove stores to dead locals
727
- - Remove side-effect free code that produces an unused result
728
- - Optimize shift left by constant to multiply, since the bytecode is smaller (this seems to be a bug in the garmin tools; they consider shift left and shift right to have an 8-bit argument, but its always zero, and the simulator and devices treat it as a one byte shift instruction, followed by a one byte nop).
729
-
730
- ### 1.1.15
731
-
732
- - Post build optimizer improvements
733
-
734
- - Simplify LogicalExpressions. This generally saves 3 bytes per `&&` or `||`, and also makes them faster
735
- - Adds a simple code sharing pass. If multiple code paths converge to the same point (or leave the function via return) and they end with the same sequence of bytecode, they're merged into one.
736
- - Flips branch-true to branch-false or vice versa if the fall through block has multiple predecessors, and the target block has just one. This often leads to better control flow, reducing the number of "goto" bytecodes required.
737
-
738
- - Source to Source Optimizer improvements
739
- - Adds an `Iterate Optimizer` option that causes the optimizer to keep re-running until it finds nothing to remove. Defaults to false.
740
-
741
- ### 1.1.16
742
-
743
- - Project infrastructure
744
-
745
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.46](https://github.com/markw65/prettier-plugin-monkeyc#1046)
746
- - no functional change.
747
- - switch from webpack to esbuild, for faster builds, and better packaging.
748
- - mark the package as `commonjs` so that prettier-extension-monkeyc can set `moduleResolution: nodenext`
749
-
750
- - Optimizations
751
- - Make local dce smarter
752
- - all locals are dead at function exits
753
- - Make block sharing smarter
754
- - allow partial blocks to be merged
755
- - better heuristics for when its advantageous to merge small blocks
756
- - Better control flow optimizations
757
- - Merge "linear" blocks, where the first has a single successor, and the second has a single predecessor
758
- - Avoid `goto` when the target is fewer than 3 bytes
759
- - Optimize array initialization by using a loop
760
- - Identify arrays that are unused, and make it possible for dce to clean up their initializers.
761
-
762
- ### 1.1.17 (this package is missing two files)
763
-
764
- - Project infrastructure
765
-
766
- - Use worker threads to speed up exporting a .iq file. With an 8 core (16 with hyperthreading) system, my project goes from taking 28 seconds to generate the optimized source to less than 10. It still takes garmin's compiler nearly 3 minutes to compile though.
767
-
768
- - Bug fixes
769
- - When running the post build optimizer, the `*-settings.json` and `*-fit_contributions.json` need to be generated too.
770
-
771
- ### 1.1.18
772
-
773
- - add missing `worker-thread.cjs` and `worker-pool.cjs` files to the package.
774
-
775
- ### 1.1.19
776
-
777
- - Bug fixes
778
-
779
- - Fix "Minimize Modules" in background/glance scopes
780
- - due to a [bug in the monkeyc compiler](https://forums.garmin.com/developer/connect-iq/i/bug-reports/import-rez-or-using-rez-breaks-background-resources), adding "using Rez;" when a resource may be loaded by a background or glance app causes it to crash. This release won't import Rez into anything marked :background or :glance. This fixes [prettier-extension-monkeyc#7](https://github.com/markw65/prettier-extension-monkeyc/issues/7)
781
- - Update background and glance offsets in the program header. I had assumed these offsets were obtained from the symbols, which already get updated, but it turns out they're stored as offsets in the header. This didn't break anything, but it did mean that the background and glance code sizes were unchanged, even though the post build optimizer had in fact made them smaller.
782
-
783
- - Optimizations
784
- - better optimization for arrays whose elements are all initialized to the same value (eg `[42, 42, 42, 42]`)
785
- - more efficient tests for symbols in case statements (ie `case: :foo`)
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.21
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).
814
-
815
- ### 1.1.22
816
-
817
- - Bug fixes
818
-
819
- - [Fixes a bug in Single Use Copy Prop](https://github.com/markw65/prettier-extension-monkeyc/issues/8)
820
-
821
- - Post Build Optimizations
822
- - Updates the array-init optimizations to include `ByteArray`s
823
- - Integrate the array-init optimization with the new interp pass, so that changes made by interp don't interfere with array-init
824
- - Handle more bytecodes in interp
825
- - If an array is initialized to its default value, drop the initializers
826
- - Add an option to [remove argc bytecodes](https://github.com/markw65/monkeyc-optimizer/wiki/Post-Build-Optimizer#remove-argc)
827
-
828
- ### 1.1.23
829
-
830
- No functional change, just fixes a typo that broke the typescript exports.
831
-
832
- ### 1.1.24
833
-
834
- - Bug fixes
835
-
836
- - Conversion of unary `-x` to `0 - x` was too restrictive, causing some missed optimization opportunities
837
-
838
- - Post Build Optimizations
839
- - Added a pass equivalent to `Minimize Locals` in the source-to-source optimizer. This pass can see and re-assign all the locals, so it does better than the source-to-source optimizer. In addition, it maintains the variable mapping, so the debugger still sees the original names. As a result, its probably best to disable the `Minimize Locals` pass if the post build optimizer is enabled.
840
- - Added a pass similar to `Size Based PRE` in the source-to-source optimizer. Currently this only optimizes constants and Symbols, but it has visibility to a lot of things the source-to-source optimizer can't see; so the two passes are complementary. I've added an option in case it causes problems, but it's enabled by default when the post build optimizer is enabled.
841
- - Added various new optimizations to the interp pass:
842
- - Handles a few more byte codes
843
- - Conditional branches that are known to be taken, or known to be not taken are converted to gotos (and the gotos will often be eliminated by re-ordering blocks)
844
- - Conditional branches that would be known to be taken, or known to be not taken if evalated at the end of one of their predecessors will be bypassed from that predecessor. Amongst other things, this converts for and while loops, that can be proven to iterate at least once, into do-while loops.
845
- - Improved the emitter's algorithm for ordering blocks to avoid some more gotos
846
-
847
- ### 1.1.25
848
-
849
- - Bug fixes
850
- - fixes a copy paste error that could cause strange results in the interpreter, possibly leading to incorrect optimizations.
851
-
852
- ### 1.1.26
853
-
854
- - Bug fixes
855
-
856
- - fixes an issue in the post build optimizer which could cause pre variables to be inserted too late in a block that could throw (so that if the variable was used in, or after the catch block, it might not have been set).
857
- - fixes an issue with references in resource files, that could result in some references not being reported to the extension (only affects `Goto References` and `Goto Definition`)
858
- - fixes some issues converting the system function documentation to markdown (for the Hover, Completion and Signature providers in the extension).
859
-
860
- - New features
861
-
862
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.49](https://github.com/markw65/prettier-plugin-monkeyc#1049) (including [#1.0.48](https://github.com/markw65/prettier-plugin-monkeyc#1048) and [#1.0.47](https://github.com/markw65/prettier-plugin-monkeyc#1047))
863
- - adds support for parsing (but not formatting) .mss files
864
- - Adds full support for personalities in `.jungle` and `.mss` files, including reading the per-device `personality.mss` files
865
- - Adds support for `project.typecheck` in `.jungle` files
866
- - Adds support for `project.optimization` in `.jungle` files
867
-
868
- - Tests
869
- - Adds a new project to test `.mss` files, and references to personalities from `.mc` files
870
-
871
- ### 1.1.27
872
-
873
- - Bug fixes
874
-
875
- - Fixes an incorrect type check warning when an assignment to a local was incompatible with the type of a same-named non-local variable. This only affects the warning; it did not result in incorrect optimizations.
876
-
877
- - New features
878
- - Adds a [standalone script](https://github.com/markw65/monkeyc-optimizer/wiki/Garmin-Font-Analyzer) to analyze .cft (font) files.
879
-
880
- ### 1.1.28
881
-
882
- - Bug fixes
883
-
884
- - Fixes an issue in the post build optimizer which could cause a pre-definition to be inserted just prior to an `frpush`, which could result in the wrong value of `self` being passed to a call
885
- - Don't add personality paths to the generated jungle file if the sdk is prior to 4.2.1
886
- - Fixes a bug in the source-to-source optimizer that could incorrectly infer that an `if` block was never entered when the if's comparison was between a primitive type, and a plain `Object`
887
-
888
- - Improved optimizations
889
- - Constant folding between `Char` and types other than `Number` is now handled (previously such comparisons were just left for Garmin's compiler to handle). This works around a [bug in Garmin's optimizer](https://forums.garmin.com/developer/connect-iq/i/bug-reports/the-optimizer-constant-folds-char-comparisons-incorrectly) by (correctly) resolving the comparisons before Garmin's optimizer can do the wrong thing.
890
-
891
- ### 1.1.29
892
-
893
- - Bug fixes
894
-
895
- - Fixes an issue where a value could incorrectly be inferred to be true-ish when its declared type was known to be an object of class type. This is not of itself incorrect, but some Toybox APIs are declared as returning an Object of a class, but may in fact return null - so we can't treat them as non-null.
896
-
897
- - Enhancements
898
- - various methods used by the extension for completion and hover info have been updated to give more accurate results.
899
-
900
- ### 1.1.30
901
-
902
- - Bug fixes
903
- - Fixes an issue where exporting a project that uses barrels could fail.
904
- - Fixes a type analysis bug that could result in the type checker incorrectly thinking two types were disjoint.
905
-
906
- ### 1.1.31
907
-
908
- - Better error reporting when getApiMapping fails
909
- - Update getApiMapping to handle api.mir from sdk-6.2.0
910
- - Update various tests to work with sdk-6.2.0 (including marking one test as an expected failure)
911
- - Add a test to catch the export-project-using-barrels bug that was fixed in 1.1.30
912
-
913
- ### 1.1.32
914
-
915
- - Bug fixes
916
-
917
- - Don't optimize `do { BODY } while (false);` to `{ BODY }` if `BODY` contains `break` or `continue`
918
- - In some circumstances, a comparison between a known `Long` and a known `Char` could be inferred to be false, regardless of the values (eg `42l == '*'` which should be `true`). It would eventually be folded to the correct value, but in some circumstances, an incorrect warning could be issued, or an incorrect optimization could have already been performed.
919
-
920
- - Fixes for sdk-6.2.x
921
-
922
- - sdk-6.2.x fixes [this finally bug](https://forums.garmin.com/developer/connect-iq/i/bug-reports/finally-doesn-t-work-as-expected), so that now all the examples work correctly (ie the `finally` block always executes, as expected, no matter how you exit the `try` or `catch` blocks). I've updated the way the control flow graph is built to match this behavior.
923
-
924
- - sdk-6.2.x fixes [this continue in switch issue](https://forums.garmin.com/developer/connect-iq/i/bug-reports/continue-in-a-switch-statement-behaves-surprisingly), by making `continue` in a `switch` continue the loop containing the switch (or its a compile time error if there's no loop). This matches the behavior of C and C++, for example. I've updated the optimizer to interpret `continue` appropriately, depending on the sdk version.
925
-
926
- ### 1.1.33
927
-
928
- - Update to [@markw65/prettier-plugin-monkeyc@1.0.51](https://github.com/markw65/prettier-plugin-monkeyc#1051)
929
-
930
- - Makes it compatible with prettier@3.0.0
931
-
932
- - Bug fixes
933
-
934
- - Fix a problem that could incorrectly optimize an array-init
935
-
936
- - Optimizations
13
+ ## Release Notes
937
14
 
938
- - Enable the array-init optimization in a few more cases
15
+ See [Change Log](CHANGELOG.md)