@markw65/monkeyc-optimizer 1.0.34 → 1.0.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 +10 -0
- package/build/api.cjs +27 -10
- package/build/optimizer.cjs +28 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -404,3 +404,13 @@ Bug Fixes
|
|
|
404
404
|
- Testing
|
|
405
405
|
- rewrite test harness in typescript
|
|
406
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.
|
package/build/api.cjs
CHANGED
|
@@ -2920,18 +2920,35 @@ function unused_exprs_cleanupUnusedVars(state, node) {
|
|
|
2920
2920
|
});
|
|
2921
2921
|
if (toRemove) {
|
|
2922
2922
|
const varDeclarations = new Map();
|
|
2923
|
-
|
|
2923
|
+
const stack = [];
|
|
2924
|
+
traverseAst(node, (node) => {
|
|
2924
2925
|
switch (node.type) {
|
|
2926
|
+
case "SwitchCase":
|
|
2927
|
+
stack.push(node.consequent);
|
|
2928
|
+
break;
|
|
2929
|
+
case "BlockStatement":
|
|
2930
|
+
stack.push(node.body);
|
|
2931
|
+
break;
|
|
2932
|
+
}
|
|
2933
|
+
}, (node) => {
|
|
2934
|
+
switch (node.type) {
|
|
2935
|
+
case "SwitchCase":
|
|
2936
|
+
case "BlockStatement":
|
|
2937
|
+
stack.pop();
|
|
2938
|
+
break;
|
|
2925
2939
|
case "VariableDeclaration": {
|
|
2926
2940
|
node.declarations.forEach((decl, i) => {
|
|
2927
2941
|
const name = variableDeclarationName(decl.id);
|
|
2928
2942
|
if (hasProperty(toRemove, name)) {
|
|
2929
|
-
const
|
|
2930
|
-
if (
|
|
2931
|
-
indices.push(i);
|
|
2943
|
+
const info = varDeclarations.get(node);
|
|
2944
|
+
if (info) {
|
|
2945
|
+
info.indices.push(i);
|
|
2932
2946
|
}
|
|
2933
2947
|
else {
|
|
2934
|
-
varDeclarations.set(node,
|
|
2948
|
+
varDeclarations.set(node, {
|
|
2949
|
+
parent: stack[stack.length - 1],
|
|
2950
|
+
indices: [i],
|
|
2951
|
+
});
|
|
2935
2952
|
}
|
|
2936
2953
|
}
|
|
2937
2954
|
});
|
|
@@ -2979,10 +2996,10 @@ function unused_exprs_cleanupUnusedVars(state, node) {
|
|
|
2979
2996
|
}
|
|
2980
2997
|
return null;
|
|
2981
2998
|
});
|
|
2982
|
-
varDeclarations.forEach((
|
|
2999
|
+
varDeclarations.forEach((info, decl) => {
|
|
2983
3000
|
let index = -1;
|
|
2984
|
-
for (let ii = indices.length, j = decl.declarations.length; ii--;) {
|
|
2985
|
-
const i = indices[ii];
|
|
3001
|
+
for (let ii = info.indices.length, j = decl.declarations.length; ii--;) {
|
|
3002
|
+
const i = info.indices[ii];
|
|
2986
3003
|
const vdecl = decl.declarations[i];
|
|
2987
3004
|
const name = variableDeclarationName(vdecl.id);
|
|
2988
3005
|
if (hasProperty(toRemove, name)) {
|
|
@@ -2994,7 +3011,7 @@ function unused_exprs_cleanupUnusedVars(state, node) {
|
|
|
2994
3011
|
continue;
|
|
2995
3012
|
}
|
|
2996
3013
|
if (index < 0) {
|
|
2997
|
-
index = parent.
|
|
3014
|
+
index = info.parent.findIndex((s) => s === decl);
|
|
2998
3015
|
if (index < 0) {
|
|
2999
3016
|
throw new Error(`Failed to find variable declaration for ${variableDeclarationName(vdecl.id)}`);
|
|
3000
3017
|
}
|
|
@@ -3015,7 +3032,7 @@ function unused_exprs_cleanupUnusedVars(state, node) {
|
|
|
3015
3032
|
decl.end = vdecl.start;
|
|
3016
3033
|
}
|
|
3017
3034
|
decl.declarations.splice(i);
|
|
3018
|
-
parent.
|
|
3035
|
+
info.parent.splice(index + 1, 0, ...rep);
|
|
3019
3036
|
j = i;
|
|
3020
3037
|
continue;
|
|
3021
3038
|
}
|
package/build/optimizer.cjs
CHANGED
|
@@ -13614,18 +13614,35 @@ function cleanupUnusedVars(state, node) {
|
|
|
13614
13614
|
});
|
|
13615
13615
|
if (toRemove) {
|
|
13616
13616
|
const varDeclarations = new Map();
|
|
13617
|
-
|
|
13617
|
+
const stack = [];
|
|
13618
|
+
traverseAst(node, (node) => {
|
|
13618
13619
|
switch (node.type) {
|
|
13620
|
+
case "SwitchCase":
|
|
13621
|
+
stack.push(node.consequent);
|
|
13622
|
+
break;
|
|
13623
|
+
case "BlockStatement":
|
|
13624
|
+
stack.push(node.body);
|
|
13625
|
+
break;
|
|
13626
|
+
}
|
|
13627
|
+
}, (node) => {
|
|
13628
|
+
switch (node.type) {
|
|
13629
|
+
case "SwitchCase":
|
|
13630
|
+
case "BlockStatement":
|
|
13631
|
+
stack.pop();
|
|
13632
|
+
break;
|
|
13619
13633
|
case "VariableDeclaration": {
|
|
13620
13634
|
node.declarations.forEach((decl, i) => {
|
|
13621
13635
|
const name = (0,external_api_cjs_namespaceObject.variableDeclarationName)(decl.id);
|
|
13622
13636
|
if (hasProperty(toRemove, name)) {
|
|
13623
|
-
const
|
|
13624
|
-
if (
|
|
13625
|
-
indices.push(i);
|
|
13637
|
+
const info = varDeclarations.get(node);
|
|
13638
|
+
if (info) {
|
|
13639
|
+
info.indices.push(i);
|
|
13626
13640
|
}
|
|
13627
13641
|
else {
|
|
13628
|
-
varDeclarations.set(node,
|
|
13642
|
+
varDeclarations.set(node, {
|
|
13643
|
+
parent: stack[stack.length - 1],
|
|
13644
|
+
indices: [i],
|
|
13645
|
+
});
|
|
13629
13646
|
}
|
|
13630
13647
|
}
|
|
13631
13648
|
});
|
|
@@ -13673,10 +13690,10 @@ function cleanupUnusedVars(state, node) {
|
|
|
13673
13690
|
}
|
|
13674
13691
|
return null;
|
|
13675
13692
|
});
|
|
13676
|
-
varDeclarations.forEach((
|
|
13693
|
+
varDeclarations.forEach((info, decl) => {
|
|
13677
13694
|
let index = -1;
|
|
13678
|
-
for (let ii = indices.length, j = decl.declarations.length; ii--;) {
|
|
13679
|
-
const i = indices[ii];
|
|
13695
|
+
for (let ii = info.indices.length, j = decl.declarations.length; ii--;) {
|
|
13696
|
+
const i = info.indices[ii];
|
|
13680
13697
|
const vdecl = decl.declarations[i];
|
|
13681
13698
|
const name = (0,external_api_cjs_namespaceObject.variableDeclarationName)(vdecl.id);
|
|
13682
13699
|
if (hasProperty(toRemove, name)) {
|
|
@@ -13688,7 +13705,7 @@ function cleanupUnusedVars(state, node) {
|
|
|
13688
13705
|
continue;
|
|
13689
13706
|
}
|
|
13690
13707
|
if (index < 0) {
|
|
13691
|
-
index = parent.
|
|
13708
|
+
index = info.parent.findIndex((s) => s === decl);
|
|
13692
13709
|
if (index < 0) {
|
|
13693
13710
|
throw new Error(`Failed to find variable declaration for ${(0,external_api_cjs_namespaceObject.variableDeclarationName)(vdecl.id)}`);
|
|
13694
13711
|
}
|
|
@@ -13709,7 +13726,7 @@ function cleanupUnusedVars(state, node) {
|
|
|
13709
13726
|
decl.end = vdecl.start;
|
|
13710
13727
|
}
|
|
13711
13728
|
decl.declarations.splice(i);
|
|
13712
|
-
parent.
|
|
13729
|
+
info.parent.splice(index + 1, 0, ...rep);
|
|
13713
13730
|
j = i;
|
|
13714
13731
|
continue;
|
|
13715
13732
|
}
|
|
@@ -15472,7 +15489,7 @@ async function generateOneConfig(buildConfig, dependencyFiles, config) {
|
|
|
15472
15489
|
// the oldest optimized file, we don't need to regenerate
|
|
15473
15490
|
const source_time = await (0,external_util_cjs_namespaceObject.last_modified)(Object.keys(fnMap).concat(dependencyFiles));
|
|
15474
15491
|
const opt_time = await (0,external_util_cjs_namespaceObject.first_modified)(Object.values(fnMap).map((v) => v.output));
|
|
15475
|
-
if (source_time < opt_time &&
|
|
15492
|
+
if (source_time < opt_time && 1662140077916 < opt_time) {
|
|
15476
15493
|
return { hasTests, diagnostics: prevDiagnostics };
|
|
15477
15494
|
}
|
|
15478
15495
|
}
|
package/package.json
CHANGED