@@ -486,16 +486,14 @@ struct OnceReduction : public Pass {
486
486
ExpressionManipulator::nop (body);
487
487
continue ;
488
488
}
489
- // The early-exit logic is the first item, followed by the global setting,
490
- // and we've ruled out the case of there being nothing else after those,
491
- // so there are at least 3 items.
492
- assert (list.size () >= 3 );
493
- // We consider the first item in the payload. Anything further would be
494
- // much more difficult to analyze.
495
- auto * payloadStart = list[2 ];
496
- if (auto * call = payloadStart->dynCast <Call>()) {
489
+ if (list.size () != 3 ) {
490
+ // Something non-trivial; too many items for us to consider.
491
+ continue ;
492
+ }
493
+ auto * payload = list[2 ];
494
+ if (auto * call = payload->dynCast <Call>()) {
497
495
if (optInfo.onceFuncs .at (call->target ).is ()) {
498
- // This "once" function immediately calls another. We do not need the
496
+ // All this "once" function does is call another. We do not need the
499
497
// early-exit logic in this one, then, because of the following
500
498
// reasoning. We are comparing these forms:
501
499
//
@@ -504,29 +502,27 @@ struct OnceReduction : public Pass {
504
502
// if (!foo$once) return; // two lines of
505
503
// foo$once = 1; // early-exit code
506
504
// bar();
507
- // ..
508
505
// }
509
506
//
510
507
// to
511
508
//
512
509
// // AFTER
513
510
// function foo() {
514
511
// bar();
515
- // ..
516
512
// }
517
513
//
518
514
// The question is whether different behavior can be observed between
519
515
// those two. There are two cases, when we enter foo:
520
516
//
521
- // 1. foo has been entered before. Then we early-exit in BEFORE, and
517
+ // 1. foo has been called before. Then we early-exit in BEFORE, and
522
518
// in AFTER we call bar which will early-exit (since foo was
523
519
// called, which means bar was at least entered, which set its
524
520
// global; bar might be on the stack, if it called foo, so it has
525
521
// not necessarily fully executed - this is a tricky situation to
526
522
// handle in general, like recursive imports of modules in various
527
523
// languages - but we do know bar has been *entered*, which means
528
524
// the global was set).
529
- // 2. foo has never been entered before. In this case in BEFORE we set
525
+ // 2. foo has never been called before. In this case in BEFORE we set
530
526
// the global and call bar, and in AFTER we also call bar.
531
527
//
532
528
// Thus, the behavior is the same, and we can remove the early-exit
0 commit comments