binast / binjs-ref

Reference implementation for the JavaScript Binary AST format
https://binast.github.io/binjs-ref/binjs/index.html
Other
433 stars 38 forks source link

Can we/should we somehow derive a unique, stable-with-time, number for each node, each string enum constant. #187

Open Yoric opened 6 years ago

Yoric commented 6 years ago

Having unique, stable-with-time numeric identifiers for each node and (in a separate namespace) each string enum value would be useful for the following purposes:

  1. if these numbers are standardized, we could entirely avoid shipping interface names, string enum constants, either in static dictionaries or in compressed files;
  2. regardless of standardization, this would give us a simple base for generating a Finite State Machine for decoding token that would keep working even with future versions of the webidl.

Cc @syg . Note that this spec has no real implication on syntax, so would probably be part of the container format.

Yoric commented 6 years ago

So, one way to implement this with or without standardization would simply to have a file that maps each string enum constant to a value, each identifier to a value, possibly with some static analysis/commit hook that ensures that we never remove/alter existing values.

To actually standardize this, we could either manually give a number to each value, with the same guarantee, or come up with a spec to derive the numbers from each successive version of the webidl. For instance:

  1. initially
    • "" (the null interface) is assigned 0;
    • "" (the null string enum) is assigned 0, regardless of string enum;
  2. after each new spec
    • each existing number is maintained;
    • all new interface names are ranked by alphanumerical order and assigned unassigned interface numbers, by increasing order;
    • for each string enum:
      • all new constants are ranked by alphanumerical order and assigned unassigned constant values for this string enum, by increasing order.

The only real drawbacks, I believe, are that: