Skip to content

Commit 8860e2d

Browse files
committed
Fix repeat block iteration count not being optimizable in yielding loops
1 parent eb0d678 commit 8860e2d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/compiler/iroptimizer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,16 +650,19 @@ class IROptimizer {
650650
* @private
651651
*/
652652
analyzeLoopedStack (stack, state, block, willReevaluateInputs) {
653+
let modified = false;
654+
653655
if (block.yields && !this.ignoreYields) {
654-
let modified = state.clear();
656+
modified = state.clear();
657+
if (willReevaluateInputs) {
658+
modified = this.analyzeInputs(block.inputs, state) || modified;
659+
}
655660
block.entryState = state.clone();
656661
block.exitState = state.clone();
657-
modified = this.analyzeInputs(block.inputs, state) || modified;
658662
return this.analyzeStack(stack, state) || modified;
659663
}
660664

661665
let iterations = 0;
662-
let modified = false;
663666
let keepLooping;
664667
do {
665668
// If we are stuck in an apparent infinite loop, give up and assume the worst.

test/snapshot/__snapshots__/warp-timer/tw-repeat-analysis-doesnt-reanalyze.sb3.tw-snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const b0 = stage.variables["`jEk@4|i[#Fk?(8x)AV.-my variable"];
2121
const b1 = stage.variables["6h7bpiz0`;;x^G1B3(%["];
2222
return function* genXYZ_a () {
2323
b0.value = b1.value.length;
24-
for (var a0 = (+b0.value || 0); a0 >= 0.5; a0--) {
24+
for (var a0 = b0.value; a0 > 0; a0--) {
2525
b0.value = "bwah";
2626
if (isStuck()) yield;
2727
}

0 commit comments

Comments
 (0)