asm-js / validator

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

Spec should tighten restrictions on number of parameter type coercions. #68

Closed cscott closed 10 years ago

cscott commented 11 years ago

The spec doesn't explicitly mention in section 5.1 that there must be exactly as many parameter type coercion statements as there are formal parameters. That is, the following is invalid:

function f(x, y) {
  x = x|0;
  x = x|0;
  y = x|0;
  return 42;
}

The other case is a little more obviously invalid (the spec says, "Every parameter in an asm.js function is provided with an explicit type annotation"):

function f(x) {
   return 42;
}

(My asm.js parser initially used a very generous parsing rule which required backtracing and allowed repeated coercions like the first example; only after reading the AsmJS.cpp source did I realize this was unnecessary.)

It should be obvious that

function(x,y) {
  x = x|0, y = y|0;
  return 42;
}

is also invalid.

timmutton commented 11 years ago

It might also be worth mentioning that x |= 0 is also not a valid coercion

ghost commented 10 years ago

I think this is fixed now. Section 6.4 establishes the correspondence between parameters and parameter type annotation by using the same identifier sequence (x...), later saying "by mapping each each parameter x to its corresponding parameter type annotation" and then adding "annotations must appear in the same order as the parameters".