asm-js / validator

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

undefined cannot "flow freely" but can "escape" #108

Open ghost opened 9 years ago

ghost commented 9 years ago

It seems as though some of the wording in section 2.1 of the specification is slightly imprecise or lacking:

The light boxes represent arbitrary JavaScript values that may flow freely between asm.js code and external JavaScript code.

The dark boxes represent types that are disallowed from escaping into external (i.e., non-asm.js) JavaScript code.

(Emphasis added.)

It follows that a value type whose values may not "flow freely between asm.js code and external JavaScript", but are also not "disallowed from escaping into external [...] JavaScript", cannot be not be depicted by a light or dark node in the subtyping DAG. Now, the only value of type void is undefined, which "asm.js is not allowed to make use of" (section 2.1.1), ruling out a light node. But undefined is allowed to escape into external JavaScript, at least in the intuitive sense that a void function may be exported, such as in the following valid module:

function M() {
  "use asm"
  function f(){}
  return f
}
console.log(M()())  // undefined

Since void functions may "only be called for effect" (section 2.1.1), I presume that there is some technical sense in which undefined does not actually "escape". If so, I think that this should be clarified in the specification, as it is otherwise unclear why void is depicted by a dark node.