Why use numbers for enum values? #69
Comments
I agree that this is weird. The reason is to support asm.js, which does not have strings. Now, at present, at least in Firefox and in the companion asm.js spec, futexWait and futexWake can't be called directly from asm.js but that's really a hack. So the original reason is still valid, I think. However, I also think it's likely that futexes will be replaced by the proposed synchronics, and as a result of that I think these values can be removed altogether, as the synchronic operations don't have any return values. To be continued; leaving the issue open until synchronics make some progress. |
In Issue #77, both @pizlonator and @domenic also objected to the current form. Given the broad resistance and the fact that the futex ops can't be accessed from asm.js currently, I'll change this to use strings -- if the futexes stay in the spec. |
Great to hear. FYI the idiomatic form is lowercase in ES. ES hasn't had to deal with multi-word enums yet, but in the web platform we've settled on dash delimited. So: |
@domenic, which of the following two designs would be most reasonable / in keeping with current practice:
|
Definitely the latter. |
OK. +1 from me. @binji, any concerns / opinions? Proposed spec change (we assume futexWakeOrRequeue goes away as discussed elsewhere):
|
What does that mean for eventually calling |
That's right, it would basically prevent calling futexWait from asm.js. Since futexWait is really quite expensive already I've struck the general attitude that that's not a big deal. A couple of thoughts:
But if you feel otherwise this is a good time to argue... EDIT: corrected typo. |
Hacking asm.js to support string literals would be pretty nasty, I bet. @flagxor what do you think? I don't have a good idea of how much slower futexWait would be. But I suppose you're right, as soon as you hit futexWait you're already on the slow path, so perhaps this doesn't matter too much if you add an additional function call and interned string comparison. |
Nasty, to be sure. It would really have to be worth it, performance-wise. It'd be wrong to take this as the final arbiter, but here's the C code that's currently used by Emscripten to wait for events: This waits for 10000 iterations for a value to change before it starts looping around futexWait (here wrapped as the asm.js FFI callout emscripten_futex_wait), and then it either does a lot of other things before futexWaiting or makes a single futexWait call. |
@flagxor Brad, any last concerns about this change vis-a-vis asm.js? |
So this would be pretty nasty to graft as-as into Asm.js What about a numeric conversion operation, and then require the callsites to be: |
@flagxor, your last suggestion would work OK, I expect. As I wrote earlier, in Firefox we can't even call the futex methods from asm.js currently. There's a discussion going on over in Issue #87, depending on the outcome there the discussion here may be moot (either because the signature of futexWait changes or because the introduction of a fast-spin primitive puts futexWait on an even more remote slow path and the callout to JS might matter even less). So I'll hold off on the change in this issue until that one is closer to resolution. |
…ckwards and forwards compatible way, see tc39/proposal-ecmascript-sharedmem#69.
http://tc39.github.io/ecmascript_sharedmem/shmem.html#AtomicsObjectValueProps says:
For JavaScript, this seems a bizarre choice. Literal strings are interned. Why not just use the strings 'OK', 'NOTEQUAL', and 'TIMEDOUT'?
The text was updated successfully, but these errors were encountered: