On 06/26/2014 06:59 AM, David Rajchenbach-Teller wrote:
I would be interested in adding boundary checks and invariant checks
that could be eliminated in opt builds. Is this in the scope of your
project?

No, I don't think so. S2S could certainly do it, but you wouldn't want to use S2S on all browser code in opt builds. Too expensive.

But: there's already a pattern you can use to enable assertions that will be zero-cost if your code runs in IonMonkey! I didn't realize this until you mentioned it. But suppose you start out with this:

    function DEBUG() {
      return false;
    }

    function assert(condition) {
      if (!condition) {
        throw new Error("assertion failed");
      }
    }

Then you can write:

    if (DEBUG()) assert(flowers.areBeautiful());

Now of course `assert(flowers.areBeautiful())` will not execute whether IonMonkey kicks in or not, because DEBUG() returns false.

But when IonMonkey compiles this, it can do even better. First, DEBUG() will be inlined. Then, since the return value is always `false`, the whole if-statement will be optimized away. (Currently, we don't optimize away if-statements that depend on global vars or even consts. Only functions.)

Admittedly this pattern is not quite as pretty as `assert(flowers.areBeautiful())`. Here's why that wouldn't work. JS doesn't have macros. :( Arguments to a function are evaluated before the function is called. This means that if we wrote assertions this way, `flowers.areBeautiful()` would have to be called even in non-debug builds. The language spec requires it. We need the if-statement to get the right debug-only behavior.

-j
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to