asm-js / validator

A reference validator for asm.js.
Apache License 2.0
1.78k stars 148 forks source link

Spec's EqualityExpression section does not mention strict equality operators === and !== #71

Open cpeterso opened 11 years ago

cpeterso commented 11 years ago

Are the strict equality operators === and !== implicitly disallowed in "use asm" code or is this just an oversight?

https://github.com/dherman/asm.js/blob/master/html/index.html#L1522

cscott commented 11 years ago

Existing asm.js benchmarks do not use ===. https://hg.mozilla.org/mozilla-central/file/tip/js/src/ion/AsmJS.cpp does not mention PNK_STRICTEQ. I believe the spec is correct as written (that is, == is allowed, === is not).

cscott commented 11 years ago

That said, I wonder why @kripken chose to use == rather than ===. It seems like strict equality would be faster on non-asm.js platforms.

cscott commented 11 years ago

On IRC @kripken enlightened me: The return type of the comparison operators (> <, etc) are defined as int in asm.js. But in JavaScript they are actually boolean values. The type system prevents the booleans from escaping, since int is not a subtype of extern (technically, the boolean can escape into Math.imul, but imul does the appropriate numeric conversion internally, so no harm done). But this requires asm.js to use ==, since 1 == true (but 1 !== true).

Also, == is one character shorter than ===, so using non-strict operators saves code space. @kripken reports that he didn't observe any performance difference between the two operators in practice.

(If you wanted asm.js to use === instead of ==, you'd also have to make the comparison operators return intish instead of int, which would force immediate cast of the boolean.)

This bug could be retitled as, "the spec should briefly discuss the significance of the comparison operator function signatures."

kripken commented 11 years ago

I agree, worth mentioning this in the spec. Good summary in last comment.